Sharing LogicSig - Algorand
Sharing LogicSig
post by AlgoPete92 on Mar 9, 2021
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.
post by JasonW on Mar 9, 2021
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
post by AlgoPete92 on Mar 9, 2021
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.
post by JasonW on Mar 9, 2021
If you have stored it as a byte array like
// 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
post by AlgoPete92 on Mar 9, 2021
Thank you, this was what I was searching for