Skip to content

Commit 46ce6c5

Browse files
chore(utxo-lib): cleaned up index.ts export and psbt formatting
TICKET: BTC-2150
1 parent 68e6032 commit 46ce6c5

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

modules/utxo-core/src/paygo/ExtractAddressPayGoAttestation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'assert';
22

3-
import { varuint } from '@bitgo/utxo-lib';
3+
import { varuint } from 'bitcoinjs-lib/src/bufferutils';
44

55
// The signed address will always have the following structure:
66
// 0x18Bitcoin Signed Message:\n<varint_length><ENTROPY><ADDRESS><UUID>
@@ -32,7 +32,7 @@ export function extractAddressBufferFromPayGoAttestationProof(message: Buffer):
3232

3333
// we decode the varint of the message which is uint32
3434
// https://en.bitcoin.it/wiki/Protocol_documentation
35-
const varInt = varuint.varuint.decode(message, offset);
35+
const varInt = varuint.decode(message, offset);
3636
assert(varInt);
3737
offset += 1;
3838

modules/utxo-core/src/testutil/generatePayGoAttestationProof.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import crypto from 'crypto';
22

3-
import { varuint } from '@bitgo/utxo-lib';
3+
import { varuint } from 'bitcoinjs-lib/src/bufferutils';
44
/** We have a mirrored function similar to our hsm that generates our Bitcoin signed
55
* message so that we can use for testing. This creates a random entropy as well using
66
* the nilUUID structure to construct our uuid buffer and given our address we can
@@ -30,7 +30,7 @@ export function generatePayGoAttestationProof(uuid: string, address: Buffer): Bu
3030

3131
// <VARINT_LENGTH>
3232
const msgLength = entropyLength + addressBufferLength + uuidBufferLength;
33-
const msgLengthBuffer = varuint.varuint.encode(msgLength);
33+
const msgLengthBuffer = varuint.encode(msgLength);
3434

3535
// <0x18Bitcoin Signed Message:\n<LENGTH><ENTROPY><ADDRESS><UUID>
3636
const proofMessage = Buffer.concat([prefixBuffer, msgLengthBuffer, entropy, address, uuidBuffer]);

modules/utxo-lib/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export * from 'bitcoinjs-lib';
22

3-
export * as varuint from 'bitcoinjs-lib/src/bufferutils';
4-
53
export * as bitgo from './bitgo';
64

75
export * as address from './address';

modules/utxo-lib/src/testutil/psbt.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ export function toUnspent(
7777
rootWalletKeys: RootWalletKeys
7878
): Unspent<bigint> {
7979
if (input.scriptType === 'p2shP2pk') {
80-
return mockReplayProtectionUnspent(network, input.value, {
81-
key: rootWalletKeys['user'],
82-
vout: index,
83-
});
80+
return mockReplayProtectionUnspent(network, input.value, { key: rootWalletKeys['user'], vout: index });
8481
} else {
8582
const chain = getInternalChainCode(input.scriptType === 'taprootKeyPathSpend' ? 'p2trMusig2' : input.scriptType);
8683
return mockWalletUnspent(network, input.value, {
@@ -98,10 +95,7 @@ export function toUnspent(
9895
* user and backup as signer and cosigner respectively for p2trMusig2.
9996
* user and bitgo as signer and cosigner respectively for other input script types.
10097
*/
101-
export function getSigners(inputType: InputScriptType): {
102-
signerName: KeyName;
103-
cosignerName?: KeyName;
104-
} {
98+
export function getSigners(inputType: InputScriptType): { signerName: KeyName; cosignerName?: KeyName } {
10599
return {
106100
signerName: 'user',
107101
cosignerName: inputType === 'p2shP2pk' ? undefined : inputType === 'p2trMusig2' ? 'backup' : 'bitgo',
@@ -144,10 +138,7 @@ export function signPsbtInput(
144138
if (sign === 'fullsigned' && cosignerName && input.scriptType !== 'p2shP2pk') {
145139
signPsbt(
146140
psbt,
147-
() =>
148-
psbt.signInputHD(inputIndex, rootWalletKeys[cosignerName], {
149-
deterministic,
150-
}),
141+
() => psbt.signInputHD(inputIndex, rootWalletKeys[cosignerName], { deterministic }),
151142
skipNonWitnessUtxo
152143
);
153144
}
@@ -170,11 +161,7 @@ export function signAllPsbtInputs(
170161
): void {
171162
const { signers, deterministic, skipNonWitnessUtxo } = params ?? {};
172163
inputs.forEach((input, inputIndex) => {
173-
signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, {
174-
signers,
175-
deterministic,
176-
skipNonWitnessUtxo,
177-
});
164+
signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, { signers, deterministic, skipNonWitnessUtxo });
178165
});
179166
}
180167

@@ -208,9 +195,7 @@ export function constructPsbt(
208195
} else {
209196
const { redeemScript } = createOutputScriptP2shP2pk(rootWalletKeys[signerName].publicKey);
210197
assert(redeemScript);
211-
addReplayProtectionUnspentToPsbt(psbt, u, redeemScript, {
212-
skipNonWitnessUtxo,
213-
});
198+
addReplayProtectionUnspentToPsbt(psbt, u, redeemScript, { skipNonWitnessUtxo });
214199
}
215200
});
216201

@@ -239,17 +224,10 @@ export function constructPsbt(
239224
psbt.setAllInputsMusig2NonceHD(rootWalletKeys['user']);
240225
psbt.setAllInputsMusig2NonceHD(rootWalletKeys['bitgo'], { deterministic });
241226

242-
signAllPsbtInputs(psbt, inputs, rootWalletKeys, 'halfsigned', {
243-
signers,
244-
skipNonWitnessUtxo,
245-
});
227+
signAllPsbtInputs(psbt, inputs, rootWalletKeys, 'halfsigned', { signers, skipNonWitnessUtxo });
246228

247229
if (sign === 'fullsigned') {
248-
signAllPsbtInputs(psbt, inputs, rootWalletKeys, sign, {
249-
signers,
250-
deterministic,
251-
skipNonWitnessUtxo,
252-
});
230+
signAllPsbtInputs(psbt, inputs, rootWalletKeys, sign, { signers, deterministic, skipNonWitnessUtxo });
253231
}
254232

255233
return psbt;

0 commit comments

Comments
 (0)