Multisigi transaction from Java to Javascript

Hi there,
I have a client A that uses the JavaSDK to produce a multisig address composed by the account A and B and a signed transaction. The transaction is signed by A only.

A wants to send the transaction to the backend B, so B can sign it and send to the blockchain.

A sends to B this JSON:

{“multiSigAccount”:{
“publicKeys”:[“wFJi8oEISKHen0LDeEk+yXD3zHQNeultuTF+xVbnQzw=”,
“dRQsIsSYbCE4YhxNGMFV0ykS1WBvrl5O7vX+3SvjDy0=”],
“threshold”:2,
“version”:1},
“signedTransaction”:{
“msig”:{
“subsig”:[{“pk”:“wFJi8oEISKHen0LDeEk+yXD3zHQNeultuTF+xVbnQzw=”,
“s”:“jNxed0mD+7jPAP7sGBIEq0hBoVk5RJ8+l9GxMypISMI+dKwWeiGGNse2vsCBjrqR860sfJsuC4py23dxDdUFBg==”},{“pk”:“dRQsIsSYbCE4YhxNGMFV0ykS1WBvrl5O7vX+3SvjDy0=”,
“s”:“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==”}],
“thr”:2,
“v”:1},
“txn”:{“close”:“NcSelNBbzNvQC5PSu0I8yJvwTjdPxlSerO8UI+5T6Ic=”,
“fee”:1000,
“fv”:9061117,
“gen”:“testnet-v1.0”,
“gh”:“SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=”,
“lv”:9062117,
“note”:“2VB7ImRpYWdub3Npc0tleXMiOlsiWUJKR0Y0VUJCQkVLRFhVN0lMQlhRU0o2WkZZUFBURFVCVjVPUzNOWkdGN01LVlhISU02RUxNWUxZVSJdfQ==”,
“rcv”:“NcSelNBbzNvQC5PSu0I8yJvwTjdPxlSerO8UI+5T6Ic=”,
“snd”:“bQFchr8rr7rK8BjoH3qAmh3oQYq1ELXjZSIfkQeLRII=”,
“type”:“pay”}}}

Now B has to parse the json to reconstruct all the objects he needs to complete the transaction and send it to the blockchain.

How can i achieve this in JavascriptSDK? Is there some JSON parser that i can use? Thanks!

It is usually simplest to serialize all the data in msgpack, instead of JSON.

You should be able to use the transaction method .bytes() (https://github.com/algorand/java-algorand-sdk/blob/develop/src/main/java/com/algorand/algosdk/transaction/Transaction.java#L1202) to serialize the transaction in Java.

Then, in JS, you can use https://github.com/algorand/js-algorand-sdk/blob/3999aa43fc3d945b38419339c593bb5fd72e49c6/src/main.js#L195, if you just need to append a multisig signature.
You can also use algosdk.decodeObj to decode the transaction, followed by https://github.com/algorand/js-algorand-sdk/blob/3999aa43fc3d945b38419339c593bb5fd72e49c6/src/transaction.js#L141

1 Like