From e224ca306608e9618d080fdb623db09307a91910 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Tue, 15 Aug 2023 13:49:08 +0200 Subject: [PATCH 1/3] feat(sdk-core): extend build param codec Issue: BTC-368 --- .../sdk-core/src/bitgo/wallet/BuildParams.ts | 127 +++++++++++------- .../bitgo/wallet/SendTransactionRequest.ts | 2 +- .../bitgo/wallet/SendTransactionRequest.ts | 18 ++- 3 files changed, 95 insertions(+), 52 deletions(-) diff --git a/modules/sdk-core/src/bitgo/wallet/BuildParams.ts b/modules/sdk-core/src/bitgo/wallet/BuildParams.ts index 41b705b640..2cfb7186dc 100644 --- a/modules/sdk-core/src/bitgo/wallet/BuildParams.ts +++ b/modules/sdk-core/src/bitgo/wallet/BuildParams.ts @@ -12,66 +12,93 @@ export const BuildParamsUTXO = t.partial({ cpfpTxIds: t.unknown, unspents: t.unknown, minValue: t.unknown, + minConfirms: t.unknown, maxValue: t.unknown, targetWalletUnspents: t.unknown, /* unspent selection strategy */ strategy: t.unknown, + strategyAllowFallback: t.unknown, noSplitChange: t.unknown, + smallestChangeSplitSize: t.unknown, enforceMinConfirmsForChange: t.unknown, /* legacy or psbt */ txFormat: t.unknown, + maxChangeOutputs: t.unknown, }); -export const BuildParams = t.intersection([ - BuildParamsUTXO, - t.partial({ - apiVersion: t.unknown, - consolidateAddresses: t.unknown, - feeRate: t.unknown, - gasLimit: t.unknown, - gasPrice: t.unknown, - hopParams: t.unknown, - idfSignedTimestamp: t.unknown, - idfUserId: t.unknown, - idfVersion: t.unknown, - instant: t.unknown, - lastLedgerSequence: t.unknown, - ledgerSequenceDelta: t.unknown, - maxFee: t.unknown, - maxFeeRate: t.unknown, - memo: t.unknown, - transferId: t.unknown, - message: t.unknown, - minConfirms: t.unknown, - numBlocks: t.unknown, - nonce: t.unknown, - pendingApprovalId: t.unknown, - preview: t.unknown, - previewPendingTxs: t.unknown, - receiveAddress: t.unknown, - recipients: t.unknown, - reservation: t.unknown, - sequenceId: t.unknown, - sourceChain: t.unknown, - destinationChain: t.unknown, - trustlines: t.unknown, - type: t.unknown, - nonParticipation: t.unknown, - validFromBlock: t.unknown, - validToBlock: t.unknown, - messageKey: t.unknown, - stakingOptions: t.unknown, - eip1559: t.unknown, - keyregTxBase64: t.unknown, - closeRemainderTo: t.unknown, - tokenName: t.unknown, - enableTokens: t.unknown, - // param to set emergency flag on a custodial transaction. - // This transaction should be performed in less than 1 hour or it will fail. - emergency: t.unknown, - }), -]); +export const BuildParamsStacks = t.partial({ + contractName: t.unknown, + functionName: t.unknown, + functionArgs: t.unknown, +}); -export type BuildParams = t.TypeOf; +export const BuildParamsOffchain = t.partial({ + idfSignedTimestamp: t.unknown, + idfVersion: t.unknown, + idfUserId: t.unknown, +}); +export const BuildParams = t.exact( + t.intersection([ + BuildParamsUTXO, + BuildParamsStacks, + BuildParamsOffchain, + t.partial({ + apiVersion: t.unknown, + consolidateAddresses: t.unknown, + consolidateId: t.unknown, + comment: t.unknown, + delayMs: t.unknown, + fee: t.unknown, + feeRate: t.unknown, + feeMultiplier: t.unknown, + enableTokens: t.unknown, + gasLimit: t.unknown, + gasPrice: t.unknown, + hopParams: t.unknown, + instant: t.unknown, + lastLedgerSequence: t.unknown, + ledgerSequenceDelta: t.unknown, + maxFee: t.unknown, + maxFeeRate: t.unknown, + memo: t.unknown, + transferId: t.unknown, + message: t.unknown, + numBlocks: t.unknown, + nonce: t.unknown, + pendingApprovalId: t.unknown, + preview: t.unknown, + previewPendingTxs: t.unknown, + senderAddress: t.unknown, + receiveAddress: t.unknown, + recipients: t.unknown, + reservation: t.unknown, + refundOptions: t.unknown, + sequenceId: t.unknown, + sourceChain: t.unknown, + destinationChain: t.unknown, + trustlines: t.unknown, + type: t.unknown, + timeBounds: t.unknown, + startTime: t.unknown, + stateProofKey: t.unknown, + nonParticipation: t.unknown, + validFromBlock: t.unknown, + validToBlock: t.unknown, + messageKey: t.unknown, + stakingParams: t.unknown, + stakingOptions: t.unknown, + unstakingOptions: t.unknown, + eip1559: t.unknown, + keyregTxBase64: t.unknown, + closeRemainderTo: t.unknown, + tokenName: t.unknown, + // param to set emergency flag on a custodial transaction. + // This transaction should be performed in less than 1 hour or it will fail. + emergency: t.unknown, + }), + ]) +); + +export type BuildParams = t.TypeOf; export const buildParamKeys = getCodecProperties(BuildParams); diff --git a/modules/sdk-core/src/bitgo/wallet/SendTransactionRequest.ts b/modules/sdk-core/src/bitgo/wallet/SendTransactionRequest.ts index 587536a1eb..18c71271be 100644 --- a/modules/sdk-core/src/bitgo/wallet/SendTransactionRequest.ts +++ b/modules/sdk-core/src/bitgo/wallet/SendTransactionRequest.ts @@ -16,7 +16,7 @@ export const SendTransactionRequest = t.exact( invoice: t.unknown, videoApprovers: t.array(t.unknown), }), - BuildParams, + BuildParams.type, ]) ); diff --git a/modules/sdk-core/test/unit/bitgo/wallet/SendTransactionRequest.ts b/modules/sdk-core/test/unit/bitgo/wallet/SendTransactionRequest.ts index 999f26766d..47b2ba1728 100644 --- a/modules/sdk-core/test/unit/bitgo/wallet/SendTransactionRequest.ts +++ b/modules/sdk-core/test/unit/bitgo/wallet/SendTransactionRequest.ts @@ -5,9 +5,25 @@ import { getCodecProperties } from '../../../../src/bitgo/utils/codecProps'; describe('SendTransactionRequest', function () { it('has expected property count', function () { - assert.strictEqual(getCodecProperties(BuildParams).length, 54); + assert.strictEqual(getCodecProperties(BuildParams).length, 72); }); + it('enforces codec', function () { + assert.deepStrictEqual( + BuildParams.encode({ + addressType: 'p2sh', + txFormat: 'psbt', + comment: 'foo', + unknown: 'bar', + } as any), + { + addressType: 'p2sh', + txFormat: 'psbt', + comment: 'foo', + // drops unknown properties + } + ); + assert.deepStrictEqual(SendTransactionRequest.encode({ txHex: '00' }), { txHex: '00' }); assert.deepStrictEqual(SendTransactionRequest.encode({ txHex: '00', addressType: 'p2sh', bar: 'omit' } as any), { txHex: '00', From a9fab813f27cdb40123c49b01570ecb6b9a67d91 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Tue, 15 Aug 2023 15:55:12 +0200 Subject: [PATCH 2/3] feat(sdk-core): use BuildParams codec in Wallet.accelerateTransaction Issue: BTC-368 --- modules/sdk-core/src/bitgo/wallet/BuildParams.ts | 2 +- modules/sdk-core/src/bitgo/wallet/wallet.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/sdk-core/src/bitgo/wallet/BuildParams.ts b/modules/sdk-core/src/bitgo/wallet/BuildParams.ts index 2cfb7186dc..c973642168 100644 --- a/modules/sdk-core/src/bitgo/wallet/BuildParams.ts +++ b/modules/sdk-core/src/bitgo/wallet/BuildParams.ts @@ -47,7 +47,7 @@ export const BuildParams = t.exact( apiVersion: t.unknown, consolidateAddresses: t.unknown, consolidateId: t.unknown, - comment: t.unknown, + comment: t.string, delayMs: t.unknown, fee: t.unknown, feeRate: t.unknown, diff --git a/modules/sdk-core/src/bitgo/wallet/wallet.ts b/modules/sdk-core/src/bitgo/wallet/wallet.ts index 964cbe0d5c..4a137c556c 100644 --- a/modules/sdk-core/src/bitgo/wallet/wallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/wallet.ts @@ -94,7 +94,7 @@ import { getTxRequest } from '../tss'; import { Hash } from 'crypto'; import { ofcTokens } from '@bitgo/statics'; import { SendTransactionRequest } from './SendTransactionRequest'; -import { buildParamKeys } from './BuildParams'; +import { buildParamKeys, BuildParams } from './BuildParams'; import { postWithCodec } from '../utils/postWithCodec'; const debug = require('debug')('bitgo:v2:wallet'); @@ -1923,10 +1923,10 @@ export class Wallet implements IWallet { params.recipients = []; - // We must pass the build params through to submit in case the CPFP tx ever has to be rebuilt. - const submitParams = Object.assign(params, await this.prebuildAndSignTransaction(params)); - delete (submitParams as any).wallet; - return await this.submitTransaction(submitParams); + return await this.submitTransaction({ + ...(await this.prebuildAndSignTransaction(params)), + ...BuildParams.encode(params), + }); } /** From a3edcc3725570d65154d541a932025bc3ad4416b Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Mon, 21 Aug 2023 11:16:09 +0200 Subject: [PATCH 3/3] fix: remove .nvmrc file It pointed to some ancient v8 version Issue: BTC-368 --- modules/bitgo/.nvmrc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 modules/bitgo/.nvmrc diff --git a/modules/bitgo/.nvmrc b/modules/bitgo/.nvmrc deleted file mode 100644 index 5debbed219..0000000000 --- a/modules/bitgo/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -lts/carbon