Skip to content

Commit ef541d8

Browse files
chore(utxo-core): update verify function
TICKET: BTC-2047
1 parent a520165 commit ef541d8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

modules/utxo-core/src/paygo/psbt/PayGoUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as utxolib from '@bitgo/utxo-lib';
2-
import * as bitcoinMessage from 'bitcoinjs-message';
32
import { checkForOutput } from 'bip174/src/lib/utils';
43

4+
import { verifyMessage } from '../../bip32utils';
5+
56
import {
67
ErrorMultiplePayGoProof,
78
ErrorMultiplePayGoProofAtPsbtIndex,
@@ -45,7 +46,7 @@ export function verifyPayGoAddressProof(
4546
psbt: utxolib.bitgo.UtxoPsbt,
4647
outputIndex: number,
4748
uuid: string,
48-
msg?: Buffer
49+
verificationPubkey: Buffer
4950
): void {
5051
const psbtOutputs = checkForOutput(psbt.data.outputs, outputIndex);
5152
const stored = utxolib.bitgo.getProprietaryKeyValuesFromUnknownKeyValues(psbtOutputs, {
@@ -75,7 +76,7 @@ export function verifyPayGoAddressProof(
7576
// We construct our message <ENTROPY><ADDRESS><UUID>
7677
const message = Buffer.concat([entropy, Buffer.from(addressFromOutput), Buffer.from(uuid)]);
7778

78-
if (!bitcoinMessage.verify(message, addressFromOutput, signature, utxolib.networks.bitcoin.messagePrefix)) {
79+
if (!verifyMessage(message.toString(), verificationPubkey, signature, utxolib.networks.bitcoin)) {
7980
throw new ErrorPayGoAddressProofFailedVerification();
8081
}
8182
}

modules/utxo-core/test/paygo/psbt/PayGoUtils.ts

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

44
import * as utxolib from '@bitgo/utxo-lib';
5-
import * as bitcoinMessage from 'bitcoinjs-message';
65
import { decodeProprietaryKey } from 'bip174/src/lib/proprietaryKeyVal';
76
import { KeyValue } from 'bip174/src/lib/interfaces';
87
import { checkForOutput } from 'bip174/src/lib/utils';
@@ -15,7 +14,7 @@ import {
1514
} from '../../../src/paygo/psbt/PayGoUtils';
1615
import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils';
1716
import { parseVaspProof } from '../../../src/testutil/parseVaspProof';
18-
// import { signMessage } from '../../../src/bip32utils';
17+
import { signMessage } from '../../../src/bip32utils';
1918

2019
// To construct our PSBTs
2120
const network = utxolib.networks.bitcoin;
@@ -54,7 +53,7 @@ const addressProofMsgBuffer = parseVaspProof(addressProofBuffer);
5453
const addressProofEntropy = addressProofMsgBuffer.subarray(0, 65);
5554

5655
// signature with the given msg addressProofBuffer
57-
const sig = bitcoinMessage.sign(addressProofMsgBuffer, attestationPrvKey!, true);
56+
const sig = signMessage(addressProofMsgBuffer.toString(), attestationPrvKey!, network);
5857

5958
function getTestPsbt() {
6059
return utxolib.testutil.constructPsbt(psbtInputs, psbtOutputs, network, rootWalletKeys, 'unsigned');
@@ -82,7 +81,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
8281
const proofInPsbt = getPaygoProprietaryKey(output.unknownKeyVals!);
8382
assert(proofInPsbt.length === 1);
8483
assert.throws(
85-
() => verifyPayGoAddressProof(psbt, 0, '00000000-0000-0000-0000-000000000001'),
84+
() => verifyPayGoAddressProof(psbt, 0, '00000000-0000-0000-0000-000000000001', attestationPubKey),
8685
(e: any) => e.message === 'Cannot verify the paygo address signature with the provided pubkey.'
8786
);
8887
});
@@ -92,7 +91,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
9291
psbt.addOutput({ script: utxolib.address.toOutputScript(addressToVerify, network), value: BigInt(10000) });
9392
const outputIndex = psbt.data.outputs.length - 1;
9493
addPayGoAddressProof(psbt, outputIndex, sig, addressProofEntropy);
95-
verifyPayGoAddressProof(psbt, outputIndex, nilUUID, Buffer.from(addressToVerify));
94+
verifyPayGoAddressProof(psbt, outputIndex, nilUUID, attestationPubKey);
9695
});
9796

9897
it('should throw an error if there are multiple PayGo proprietary keys in the PSBT', () => {
@@ -105,7 +104,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
105104
assert(proofInPsbt.length !== 0);
106105
assert(proofInPsbt.length > 1);
107106
assert.throws(
108-
() => verifyPayGoAddressProof(psbt, outputIndex, nilUUID),
107+
() => verifyPayGoAddressProof(psbt, outputIndex, nilUUID, attestationPubKey),
109108
(e: any) => e.message === 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.'
110109
);
111110
});
@@ -115,7 +114,7 @@ describe('verifyPaygoAddressProof', () => {
115114
it('should throw an error if there is no PayGo address in PSBT', () => {
116115
const psbt = getTestPsbt();
117116
assert.throws(
118-
() => verifyPayGoAddressProof(psbt, 0, nilUUID),
117+
() => verifyPayGoAddressProof(psbt, 0, nilUUID, attestationPubKey),
119118
(e: any) => e.message === 'There is no paygo address proof encoded in the PSBT at output 0.'
120119
);
121120
});

0 commit comments

Comments
 (0)