diff --git a/examples/create-account-with-thresholdkey.js b/examples/create-account-with-thresholdkey.js index ff918badf..7ea0461cc 100644 --- a/examples/create-account-with-thresholdkey.js +++ b/examples/create-account-with-thresholdkey.js @@ -39,7 +39,7 @@ async function main() { const client = Client.forName(process.env.HEDERA_NETWORK); client.setOperator(operatorId, operatorKey); - + // Set logger const infoLogger = new Logger(LogLevel.Info); client.setLogger(infoLogger); diff --git a/examples/multi-node-multi-signature-remove.js b/examples/multi-node-multi-signature-remove.js index f5216c9aa..66cc9c4e6 100644 --- a/examples/multi-node-multi-signature-remove.js +++ b/examples/multi-node-multi-signature-remove.js @@ -1,4 +1,3 @@ -/* import { Client, PrivateKey, @@ -21,14 +20,14 @@ let bobKey; * @description Create a transaction with multiple nodes and multiple signatures * and remove one of the signatures from the transaction then add it back */ -/* + async function main() { /** * * Step 1: Create Client * */ -/* + if ( process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null || @@ -49,7 +48,7 @@ async function main() { * Step 2: Create keys for two users * */ -/* + aliceKey = PrivateKey.generate(); bobKey = PrivateKey.generate(); @@ -60,7 +59,7 @@ async function main() { * Step 3: Create an account with the keyList * */ -/* + const createAccountTransaction = new AccountCreateTransaction() .setInitialBalance(new Hbar(2)) .setKey(keyList); @@ -73,7 +72,7 @@ async function main() { * Step 4: Create a transfer transaction with multiple nodes * */ -/* + const transferTransaction = new TransferTransaction() .addHbarTransfer(createReceipt.accountId, new Hbar(-1)) .addHbarTransfer("0.0.3", new Hbar(1)) @@ -91,7 +90,7 @@ async function main() { * & Collect multiple signatures (Uint8Array[]) from one key * */ -/* + const transferTransactionBytes = transferTransaction.toBytes(); const aliceSignatures = aliceKey.signTransaction(transferTransaction); @@ -103,7 +102,6 @@ async function main() { * & Add the previously collected signatures * */ -/* const signedTransaction = Transaction.fromBytes(transferTransactionBytes); signedTransaction.addSignature(aliceKey.publicKey, aliceSignatures); @@ -115,6 +113,7 @@ async function main() { console.log( "Alice Signatures =>", aliceSignatures.map((aliceSig) => + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument PrivateKey.fromBytes(aliceSig).toStringDer(), ), ); @@ -122,6 +121,7 @@ async function main() { console.log( "Bob Signatures =>", bobSignatures.map((bobSig) => + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument PrivateKey.fromBytes(bobSig).toStringDer(), ), ); @@ -138,14 +138,13 @@ async function main() { * Step 7: Remove the signatures for Alice from the transaction * */ -/* const removedAliceSignatures = signedTransaction.removeSignature( aliceKey.publicKey, ); console.log("\nREMOVED Alice signatures below: \n"); - if (Array.isArray(aliceSignatures) && Array.isArray(bobSignatures)) { + if (Array.isArray(removedAliceSignatures)) { console.log( "Alice removed signatures =>", removedAliceSignatures.map((aliceSig) => @@ -160,26 +159,6 @@ async function main() { console.log("\n\nSignatures left in the transaction: "); console.log(signaturesInTheTransactionAfter); - /** - * - * Step 8: Add the removed signature back to the transaction - * - */ -/* - signedTransaction.addSignature(aliceKey.publicKey, removedAliceSignatures); - - /** - * - * Step 9: Execute and take the receipt - * - */ -/* - const result = await signedTransaction.execute(client); - - const receipt = await result.getReceipt(client); - - console.log(`\n \nTransaction status: ${receipt.status.toString()}`); - client.close(); } @@ -190,10 +169,9 @@ void main(); * @param {Transaction} signedTransaction - The signed transaction object containing the list of signed transactions. * @returns {string[]} An array of signatures in DER format. */ -/* const getAllSignaturesFromTransaction = (signedTransaction) => { /** @type {string[]} */ -/* + const signatures = []; signedTransaction._signedTransactions.list.forEach((transaction) => { @@ -218,4 +196,3 @@ const getAllSignaturesFromTransaction = (signedTransaction) => { return signatures; }; -*/ diff --git a/examples/multi-node-multi-signature-removeAll.js b/examples/multi-node-multi-signature-removeAll.js index 9bf79ca9d..9fe5c57e4 100644 --- a/examples/multi-node-multi-signature-removeAll.js +++ b/examples/multi-node-multi-signature-removeAll.js @@ -1,4 +1,4 @@ -/* +/* eslint-disable ie11/no-loop-func */ import { Client, PrivateKey, @@ -17,18 +17,17 @@ dotenv.config(); let aliceKey; let bobKey; +const NODES = [new AccountId(3), new AccountId(4), new AccountId(5)]; /** * @description Create a transaction with multiple nodes and multiple signatures * and remove all of the signatures from the transaction */ -/* async function main() { /** * * Step 1: Create Client * */ -/* if ( process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null || @@ -49,7 +48,6 @@ async function main() { * Step 2: Create keys for two users * */ -/* aliceKey = PrivateKey.generate(); bobKey = PrivateKey.generate(); @@ -63,7 +61,6 @@ async function main() { * Step 3: Create an account with the keyList * */ -/* const createAccountTransaction = new AccountCreateTransaction() .setInitialBalance(new Hbar(2)) .setKey(keyList); @@ -76,16 +73,11 @@ async function main() { * Step 4: Create a transfer transaction with multiple nodes * */ -/* const transferTransaction = new TransferTransaction() .addHbarTransfer(createReceipt.accountId, new Hbar(-1)) .addHbarTransfer("0.0.3", new Hbar(1)) // Set multiple nodes - .setNodeAccountIds([ - new AccountId(3), - new AccountId(4), - new AccountId(5), - ]) + .setNodeAccountIds(NODES) .freezeWith(client); /** @@ -94,7 +86,6 @@ async function main() { * & Collect multiple signatures (Uint8Array[]) from one key * */ -/* const transferTransactionBytes = transferTransaction.toBytes(); const aliceSignatures = aliceKey.signTransaction(transferTransaction); @@ -106,7 +97,6 @@ async function main() { * & Add the previously collected signatures * */ -/* const signedTransaction = Transaction.fromBytes(transferTransactionBytes); signedTransaction.addSignature(aliceKey.publicKey, aliceSignatures); @@ -115,19 +105,22 @@ async function main() { console.log("\nADDED users signatures below: \n"); if (Array.isArray(aliceSignatures) && Array.isArray(bobSignatures)) { - console.log( + /*console.log( "Alice Signatures =>", aliceSignatures.map((aliceSig) => + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument PrivateKey.fromBytes(aliceSig).toStringDer(), - ), - ); - + ), + );*/ + /* console.log( "Bob Signatures =>", bobSignatures.map((bobSig) => + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument PrivateKey.fromBytes(bobSig).toStringDer(), ), ); + */ } const signaturesInTheTransactionBefore = @@ -141,7 +134,6 @@ async function main() { * Step 7: Remove all signatures from the transaction and add them back * */ -/* const allSignaturesRemoved = signedTransaction.removeAllSignatures(); const signaturesInTheTransactionAfter = @@ -162,21 +154,7 @@ async function main() { }), ); } - - // Add the removed signatures back - signedTransaction.addSignature(publicKey, signatures); } - /** - * - * Step 8: Execute and take the receipt - * - */ -/* - const result = await signedTransaction.execute(client); - - const receipt = await result.getReceipt(client); - - console.log(`\n \nTransaction status: ${receipt.status.toString()}`); client.close(); } @@ -188,10 +166,10 @@ void main(); * @param {Transaction} signedTransaction - The signed transaction object containing the list of signed transactions. * @returns {string[]} An array of signatures in DER format. */ -/* + const getAllSignaturesFromTransaction = (signedTransaction) => { /** @type {string[]} */ -/* + const signatures = []; signedTransaction._signedTransactions.list.forEach((transaction) => { @@ -216,4 +194,3 @@ const getAllSignaturesFromTransaction = (signedTransaction) => { return signatures; }; -*/ diff --git a/examples/multi-node-multi-signature.js b/examples/multi-node-multi-signature.js index d43410b20..aa36d0b4c 100644 --- a/examples/multi-node-multi-signature.js +++ b/examples/multi-node-multi-signature.js @@ -1,4 +1,3 @@ -/* import { Client, PrivateKey, @@ -14,20 +13,16 @@ import dotenv from "dotenv"; dotenv.config(); -let aliceKey; -let bobKey; - /** * @description Create a transaction with multiple nodes and multiple signatures */ -/* async function main() { /** * * Step 1: Create Client * */ -/* + if ( process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null || @@ -48,9 +43,9 @@ async function main() { * Step 2: Create keys for two users * */ -/* - aliceKey = PrivateKey.generate(); - bobKey = PrivateKey.generate(); + + const aliceKey = PrivateKey.generate(); + const bobKey = PrivateKey.generate(); const keyList = new KeyList([aliceKey.publicKey, bobKey.publicKey]); @@ -59,7 +54,7 @@ async function main() { * Step 3: Create an account with the keyList * */ -/* + const createAccountTransaction = new AccountCreateTransaction() .setInitialBalance(new Hbar(2)) .setKey(keyList); @@ -72,7 +67,6 @@ async function main() { * Step 4: Create a transfer transaction with multiple nodes * */ -/* const transferTransaction = new TransferTransaction() .addHbarTransfer(createReceipt.accountId, new Hbar(-1)) .addHbarTransfer("0.0.3", new Hbar(1)) @@ -90,7 +84,7 @@ async function main() { * & Collect multiple signatures (Uint8Array[]) from one key * */ -/* + const transferTransactionBytes = transferTransaction.toBytes(); const aliceSignatures = aliceKey.signTransaction(transferTransaction); @@ -102,7 +96,7 @@ async function main() { * & Add the previously collected signatures * */ -/* + const signedTransaction = Transaction.fromBytes(transferTransactionBytes); signedTransaction.addSignature(aliceKey.publicKey, aliceSignatures); @@ -110,21 +104,23 @@ async function main() { console.log("ADDED users signatures below: \n"); - if (Array.isArray(aliceSignatures) && Array.isArray(bobSignatures)) { - console.log( - "Alice Signatures =>", - aliceSignatures.map((aliceSig) => - PrivateKey.fromBytes(aliceSig).toStringDer(), - ), - ); + const aliceFlatSigs = aliceSignatures.getFlatSignatureList(); + console.log( + "Alice Signatures =>", + aliceFlatSigs.map((aliceSig) => { + const aliceSigBytes = aliceSig.get(aliceKey.publicKey); + return PrivateKey.fromBytes(aliceSigBytes).toStringDer(); + }), + ); - console.log( - "Bob Signatures =>", - bobSignatures.map((bobSig) => - PrivateKey.fromBytes(bobSig).toStringDer(), - ), - ); - } + const bobFlatSigs = bobSignatures.getFlatSignatureList(); + console.log( + "Bob Signatures =>", + bobFlatSigs.map((bobSig) => { + const bobSigBytes = bobSig.get(bobKey.publicKey); + return PrivateKey.fromBytes(bobSigBytes).toStringDer(); + }), + ); const signaturesInTheTransactionBefore = getAllSignaturesFromTransaction(signedTransaction); @@ -137,7 +133,7 @@ async function main() { * Step 7: Execute and take the receipt * */ -/* + const result = await signedTransaction.execute(client); const receipt = await result.getReceipt(client); @@ -154,10 +150,10 @@ void main(); * @param {Transaction} signedTransaction - The signed transaction object containing the list of signed transactions. * @returns {string[]} An array of signatures in DER format. */ -/* + const getAllSignaturesFromTransaction = (signedTransaction) => { /** @type {string[]} */ -/* + const signatures = []; signedTransaction._signedTransactions.list.forEach((transaction) => { @@ -182,4 +178,3 @@ const getAllSignaturesFromTransaction = (signedTransaction) => { return signatures; }; -*/ diff --git a/examples/multi-sig-offline.js b/examples/multi-sig-offline.js index ac9f05cb8..62b29a743 100644 --- a/examples/multi-sig-offline.js +++ b/examples/multi-sig-offline.js @@ -1,4 +1,3 @@ -/* import { Client, PrivateKey, @@ -15,11 +14,9 @@ import dotenv from "dotenv"; dotenv.config(); /** @type {PrivateKey | undefined} */ -/* let user1Key; /** @type {PrivateKey | undefined} */ -/* let user2Key; async function main() { @@ -71,8 +68,8 @@ async function main() { const transactionToExecute = Transaction.fromBytes(transactionBytes); // ask users to sign and return signature - const user1Signature = user1Signs(transactionBytes); - const user2Signature = user2Signs(transactionBytes); + const user1Signature = user1Key.signTransaction(transferTransaction); + const user2Signature = user2Key.signTransaction(transferTransaction); try { // recreate the transaction from bytes @@ -90,25 +87,4 @@ async function main() { client.close(); } -/** - * @param {Uint8Array} transactionBytes - * @returns {Uint8Array | Uint8Array[]} - */ -/* -function user1Signs(transactionBytes) { - const transaction = Transaction.fromBytes(transactionBytes); - return user1Key.signTransaction(transaction); -} - -/** - * @param {Uint8Array} transactionBytes - * @returns {Uint8Array | Uint8Array[]} - */ -/* -function user2Signs(transactionBytes) { - const transaction = Transaction.fromBytes(transactionBytes); - return user2Key.signTransaction(transaction); -} - void main(); -*/ diff --git a/examples/token-reject.js b/examples/token-reject.js index cad9db09c..0a9e37d5f 100644 --- a/examples/token-reject.js +++ b/examples/token-reject.js @@ -185,13 +185,12 @@ async function main() { // reject NFTs back to treasury const rejectFlowResponse = await ( - await ( - new TokenRejectFlow() - .setOwnerId(receiverAccountId) - .setNftIds(nftSerialIds) - .freezeWith(client) - .sign(receiverPrivateKey) - ).execute(client) + await new TokenRejectFlow() + .setOwnerId(receiverAccountId) + .setNftIds(nftSerialIds) + .freezeWith(client) + .sign(receiverPrivateKey) + .execute(client) ).getReceipt(client); const tokenRejectStatus = tokenRejectResponse.status.toString();