From daf42cb84808382bb49ff52428d4966541d0554e Mon Sep 17 00:00:00 2001 From: Evan Zheng Date: Wed, 19 Jul 2023 11:54:20 -0700 Subject: [PATCH] feat(bitgo): add example to sanitize unwitnessed txn from cardano cli EA-658 --- .../js/ada/sanitize-unwitnessed-pledge-txn.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/js/ada/sanitize-unwitnessed-pledge-txn.js diff --git a/examples/js/ada/sanitize-unwitnessed-pledge-txn.js b/examples/js/ada/sanitize-unwitnessed-pledge-txn.js new file mode 100644 index 0000000000..ced2aafb5e --- /dev/null +++ b/examples/js/ada/sanitize-unwitnessed-pledge-txn.js @@ -0,0 +1,33 @@ +// There are known serialization inconsistencies between the cardano-cli and nodejs libraries. As a workaround, ADA pledge txn +// needs to be re-serialized using the nodejs library before witnessed by node key and then submitted to BitGo pledge endpoint. +// This script helps to re-serialize the pledge txn using the nodejs library. +const fs = require('fs'); +const BitGoJS = require('bitgo'); +const { Transaction } = require('@bitgo/sdk-coin-ada'); +const bitgo = new BitGoJS.BitGo({ env: 'test' }); +const coin = 'tada'; +const basecoin = bitgo.coin(coin); + +const unwitnessedTxCborHex = 'replaced by CBOR hex of unwitnessed tx from cardano-cli'; + +const tx = new Transaction(basecoin); +tx.fromRawTransaction(unwitnessedTxCborHex); +const sanitizedUnwitnessedTxn = tx.toBroadcastFormat(); + +const unwitnessedTxn = JSON.stringify( + { + type: 'Unwitnessed Tx BabbageEra', + description: 'Ledger Cddl Format', + cborHex: sanitizedUnwitnessedTxn, + }, + null, + 4 +); + +fs.writeFile('sanitized_unwitnessed_pledge_txn.tx', unwitnessedTxn, (err) => { + if (err) { + console.error('Error writing to sanitized txn.', err); + } else { + console.log('Successfully saved to sanitized txn.'); + } +});