Sharing LogicSig

Hi there,

I’m trying to implement an ASA trading application using the JavaSDK. This application uses Atomic Transfers to make sure that the buyer makes his payment transaction, and the seller actually transfers the asset (both succeed or both fail). My problem is that the payment transaction should be normally signed by the buyer (no problem here) while the asset transfer transaction should be signed through a logicSig created by the seller of the assets. On that purpose I need a way to share this logicSig with the buyer, in order to enable him to sign the asset transfer transaction of the atomic transfer. Is there a way to achieve this? Saving the logicSig to a file would be nice.

The DEX example does this same thing using JavaScript. I save the file to a server. Its probably better to encrypt it but you can use it as a starting point. Algorand Developer Portal
The DEX example first takes a template TEAL program and replaces some values, compiles it, signs the logic creating a signed LogicSig and this is saved to a file on the server. smart-contracts/dex.js at master · algorand/smart-contracts · GitHub
Let me know if you need help converting to Java. You can start by looking at these examples. Algorand Developer Docs

In this code line:

→ let b64encoded = btoa(String.fromCharCode.apply(null, lsig.toByte()));

you extract the logic signature bytes, but I can’t find such a method for the LogicSignature object in the JavaSDK. I suppose it should be something like " lsig.getBytes() " for Java.

If you have stored it as a byte array like :slight_smile:

        // check serialization
        byte[] outBytes = Encoder.encodeToMsgPack(lsig);

you should be able to load it like

        LogicsigSignature lsig1 = Encoder.decodeFromMsgPack(outBytes, LogicsigSignature.class);
        assertThat(lsig).isEqualTo(lsig1);

See java-algorand-sdk/TestLogicsigSignature.java at develop · algorand/java-algorand-sdk · GitHub

1 Like

Thank you, this was what I was searching for :grinning:

1 Like