Skip to content

Commit

Permalink
Merge pull request #3741 from BitGo/EA-658-sanitize-script
Browse files Browse the repository at this point in the history
feat(bitgo): add example to sanitize unwitnessed txn from cardano cli
  • Loading branch information
evanzbitgo committed Jul 19, 2023
2 parents 45cb0cf + daf42cb commit c74e335
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/js/ada/sanitize-unwitnessed-pledge-txn.js
Original file line number Diff line number Diff line change
@@ -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.');
}
});

0 comments on commit c74e335

Please sign in to comment.