Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/abstract-utxo/src/recovery/backupKeyRecovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export interface RecoverParams {
recoveryProvider?: RecoveryProvider;
/** Satoshi per byte */
feeRate?: number;
/** Block height used to select the Zcash consensus branch ID. */
blockHeight?: number;
/**
* Transaction lock time (nLockTime). Set before signing — it is part of the sighash.
* Used for ECX replay-protection sweeps (e.g. 499_999_999) and other custom lock-time needs.
Expand Down Expand Up @@ -270,6 +272,8 @@ export interface RecoverWithUnspentsParams {
krsFee?: bigint;
/** KRS fee address (required if krsFee > 0) */
krsFeeAddress?: string;
/** Block height used to select the Zcash consensus branch ID. */
blockHeight?: number;
/** Transaction lock time (nLockTime), set on the PSBT before signing */
lockTime?: number;
/** Input sequence number applied to every input */
Expand Down Expand Up @@ -313,6 +317,7 @@ export function backupKeyRecoveryWithWalletUnspents(
recoveryDestination: recoveryDestination,
keyRecoveryServiceFee: krsFee ?? BigInt(0),
keyRecoveryServiceFeeAddress: krsFeeAddress,
blockHeight: params.blockHeight,
lockTime: params.lockTime,
sequence: params.sequence,
});
Expand Down Expand Up @@ -565,6 +570,7 @@ export async function backupKeyRecovery(
feeRateSatVB,
krsFee,
krsFeeAddress,
blockHeight: params.blockHeight,
lockTime: params.lockTime,
sequence: params.sequence,
},
Expand Down
20 changes: 20 additions & 0 deletions modules/abstract-utxo/test/unit/recovery/backupKeyRecovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ function runWithScriptTypes(scriptTypes: ScriptType2Of3[]) {
}

describe('Backup Key Recovery PSBT', function () {
it('uses the supplied post-NU6.2 block height for Zcash', function () {
const { walletKeys: externalWallet } = createWasmWalletKeys('external');
const recoveryDestination = getWalletAddress('zec', externalWallet);
const unspent = toUnspent({ scriptType: 'p2sh', value: BigInt(1e8) }, 0, 'zec', wasmWalletKeys);

const psbt = backupKeyRecoveryWithWalletUnspents(
'zec',
{
walletKeys: wasmWalletKeys,
keys: [userPrivkey, backupPrivkey, wasmWalletKeys.bitgoKey()],
recoveryDestination,
feeRateSatVB: 1,
blockHeight: 3_364_600,
},
[unspent]
);

assert.strictEqual((psbt as fixedScriptWallet.ZcashBitGoPsbt).consensusBranchId, 0x5437f330);
});

// compatible with all coins
runWithScriptTypes(['p2sh']);

Expand Down
Loading