From 568970f11508a6e49e4ec45f6c996573de32505d Mon Sep 17 00:00:00 2001 From: Smrecz Date: Wed, 30 Oct 2024 15:59:34 +0100 Subject: [PATCH 1/3] UTXO signing secret deduplication --- .../blockchain/btc-based/src/lib/nested/btc-based.tx.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts b/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts index 861809123..f82f9bfd1 100644 --- a/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts +++ b/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts @@ -140,7 +140,7 @@ export const btcBasedTransactions = ( totalOutputs += item.satoshis } try { - const privateKeysToSign = [] + const privateKeysToSign = new Set() for (const item of body.fromAddress) { if (totalInputs >= totalOutputs) { @@ -163,12 +163,12 @@ export const btcBasedTransactions = ( }), ]) - if ('signatureId' in item) privateKeysToSign.push(item.signatureId) - else if ('privateKey' in item) privateKeysToSign.push(item.privateKey) + if ('signatureId' in item) privateKeysToSign.add(item.signatureId) + else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } } - return privateKeysToSign + return Array.from(privateKeysToSign) } catch (e: any) { if (e instanceof SdkError) { throw e From 36a3d24b51f8d32f70197fc3567436e73add735d Mon Sep 17 00:00:00 2001 From: Smrecz Date: Wed, 30 Oct 2024 16:09:05 +0100 Subject: [PATCH 2/3] UTXO signing secret deduplication adjustments --- package.json | 2 +- packages/blockchain/doge/src/lib/doge.sdk.tx.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f2c02ceab..b09462e34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tatumio", - "version": "2.2.86", + "version": "2.2.87", "license": "MIT", "repository": "https://github.com/tatumio/tatum-js", "scripts": { diff --git a/packages/blockchain/doge/src/lib/doge.sdk.tx.ts b/packages/blockchain/doge/src/lib/doge.sdk.tx.ts index 6257674f6..1c0bb7e63 100644 --- a/packages/blockchain/doge/src/lib/doge.sdk.tx.ts +++ b/packages/blockchain/doge/src/lib/doge.sdk.tx.ts @@ -51,7 +51,7 @@ export const dogeTransactions = ( transaction.to(item.address, amount) } - const privateKeysToSign = [] + const privateKeysToSign = new Set() if ('fromUTXO' in body) { for (const item of body.fromUTXO) { const satoshis = amountUtils.toSatoshis(item.value) @@ -64,8 +64,8 @@ export const dogeTransactions = ( satoshis, }), ]) - if ('signatureId' in item) privateKeysToSign.push(item.signatureId) - else if ('privateKey' in item) privateKeysToSign.push(item.privateKey) + if ('signatureId' in item) privateKeysToSign.add(item.signatureId) + else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } } else if ('fromAddress' in body) { for (const item of body.fromAddress) { @@ -89,8 +89,8 @@ export const dogeTransactions = ( }), ]) - if ('signatureId' in item) privateKeysToSign.push(item.signatureId) - else if ('privateKey' in item) privateKeysToSign.push(item.privateKey) + if ('signatureId' in item) privateKeysToSign.add(item.signatureId) + else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } } } From 8d6f725d9dc575a513196a72e9a7043899ec3ddb Mon Sep 17 00:00:00 2001 From: Smrecz Date: Wed, 30 Oct 2024 16:25:54 +0100 Subject: [PATCH 3/3] UTXO signing secret deduplication adjustments 2 --- .../blockchain/doge/src/lib/doge.sdk.tx.ts | 9 ++++---- .../btc-based/src/lib/nested/btc-based.tx.ts | 21 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/blockchain/doge/src/lib/doge.sdk.tx.ts b/packages/blockchain/doge/src/lib/doge.sdk.tx.ts index 1c0bb7e63..a1812261c 100644 --- a/packages/blockchain/doge/src/lib/doge.sdk.tx.ts +++ b/packages/blockchain/doge/src/lib/doge.sdk.tx.ts @@ -88,10 +88,9 @@ export const dogeTransactions = ( satoshis, }), ]) - - if ('signatureId' in item) privateKeysToSign.add(item.signatureId) - else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } + if ('signatureId' in item) privateKeysToSign.add(item.signatureId) + else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } } @@ -110,9 +109,9 @@ export const dogeTransactions = ( return JSON.stringify(transaction) } - for (const pk of privateKeysToSign) { + privateKeysToSign.forEach((pk) => { transaction.sign(PrivateKey.fromWIF(pk)) - } + }) return transaction.serialize() } catch (e: any) { diff --git a/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts b/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts index f82f9bfd1..ae3e87e75 100644 --- a/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts +++ b/packages/shared/blockchain/btc-based/src/lib/nested/btc-based.tx.ts @@ -129,7 +129,7 @@ export const btcBasedTransactions = ( transaction: BtcBasedTransaction, body: BtcFromAddressTypes | LtcFromAddressTypes, options: BtcBasedTxOptions, - ): Promise> => { + ): Promise> => { if (body.fromAddress.length === 0 && !options.skipAllChecks) { throw new BtcBasedSdkError(SdkErrorCode.BTC_BASED_NO_INPUTS) } @@ -162,13 +162,12 @@ export const btcBasedTransactions = ( satoshis: amountUtils.toSatoshis(utxo.value), }), ]) - - if ('signatureId' in item) privateKeysToSign.add(item.signatureId) - else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } + if ('signatureId' in item) privateKeysToSign.add(item.signatureId) + else if ('privateKey' in item) privateKeysToSign.add(item.privateKey) } - return Array.from(privateKeysToSign) + return privateKeysToSign } catch (e: any) { if (e instanceof SdkError) { throw e @@ -205,13 +204,13 @@ export const btcBasedTransactions = ( transaction: Transaction, body: BtcFromUtxoTypes | LtcFromUtxoTypes, options: BtcBasedTxOptions, - ): Promise> => { + ): Promise> => { if (body.fromUTXO.length === 0 && !options.skipAllChecks) { throw new BtcBasedSdkError(SdkErrorCode.BTC_BASED_NO_INPUTS) } try { - const privateKeysToSign = [] + const privateKeysToSign = new Set() const utxos: BtcUTXO[] = [] const filteredUtxos = await getUtxoBatch(getChain(options), body) @@ -233,8 +232,8 @@ export const btcBasedTransactions = ( }), ]) - if ('signatureId' in utxoItem) privateKeysToSign.push(utxoItem.signatureId) - else if ('privateKey' in utxoItem) privateKeysToSign.push(utxoItem.privateKey) + if ('signatureId' in utxoItem) privateKeysToSign.add(utxoItem.signatureId) + else if ('privateKey' in utxoItem) privateKeysToSign.add(utxoItem.privateKey) } if (!options.skipAllChecks) { @@ -325,7 +324,7 @@ export const btcBasedTransactions = ( ): Promise { try { const tx: BtcBasedTransaction = new createTransaction() - let privateKeysToSign: string[] = [] + let privateKeysToSign = new Set() if (body.changeAddress) { tx.change(body.changeAddress) @@ -359,7 +358,7 @@ export const btcBasedTransactions = ( } } - new Set(privateKeysToSign).forEach((key) => { + privateKeysToSign.forEach((key) => { tx.sign(new createPrivateKey(key)) })