Skip to content

Commit da0fe48

Browse files
chore(utxo-core): fixed pr on error class and JSDocs
TICKET: BTC-2047
1 parent ae1ebea commit da0fe48

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
export class ErrorNoPayGoProof extends Error {
1+
export class PayGoError extends Error {
2+
constructor(message: string) {
3+
super(message);
4+
this.name = this.constructor.name;
5+
}
6+
}
7+
8+
export class ErrorNoPayGoProof extends PayGoError {
29
constructor(public outputIndex: number) {
310
super(`There is no paygo address proof encoded in the PSBT at output ${outputIndex}.`);
411
}
512
}
613

7-
export class ErrorMultiplePayGoProof extends Error {
14+
export class ErrorMultiplePayGoProof extends PayGoError {
815
constructor() {
916
super('There are multiple paygo address proofs encoded in the PSBT. Something went wrong.');
1017
}
1118
}
1219

13-
export class ErrorPayGoAddressProofFailedVerification extends Error {
20+
export class ErrorPayGoAddressProofFailedVerification extends PayGoError {
1421
constructor() {
1522
super('Cannot verify the paygo address signature with the provided pubkey.');
1623
}
1724
}
1825

19-
export class ErrorOutputIndexOutOfBounds extends Error {
26+
export class ErrorOutputIndexOutOfBounds extends PayGoError {
2027
constructor(public outputIndex: number) {
2128
super(`Output index ${outputIndex} is out of bounds for PSBT outputs.`);
2229
}
2330
}
2431

25-
export class ErrorMultiplePayGoProofAtPsbtIndex extends Error {
32+
export class ErrorMultiplePayGoProofAtPsbtIndex extends PayGoError {
2633
constructor(public outputIndex: number) {
2734
super(`There are multiple PayGo addresses in the PSBT output ${outputIndex}.`);
2835
}

modules/utxo-core/src/testutil/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export * from './fixtures.utils';
22
export * from './key.utils';
33
export * from './toPlainObject.utils';
44
export * from './generatePayGoAttestationProof.utils';
5-
export * from './parseVaspProof';
5+
export * from './trimMessagePrefix';

modules/utxo-core/src/testutil/parseVaspProof.ts renamed to modules/utxo-core/src/testutil/trimMessagePrefix.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import * as utxolib from '@bitgo/utxo-lib';
22

33
/** We receive a proof in the form:
44
* 0x18Bitcoin Signed Message:\n<varint_length><ENTROPY><ADDRESS><UUID>
5-
* and when verifying our message in our PayGo utils we want to only verify
6-
* the message portion of our proof. This helps to pare our proof in that format,
7-
* and returns a Buffer.
5+
* and when verifying our message we want to exclude the 0x18Bitcoin Signed Message:\n<varint_length>
6+
* of the proof so that we are left with the entropy address and uuid as our message.
7+
* This is what we are going to be verifying.
88
*
99
* @param proof
1010
* @returns
1111
*/
12-
export function parseVaspProof(proof: Buffer): Buffer {
12+
export function trimMessagePrefix(proof: Buffer): Buffer {
1313
const prefix = '\u0018Bitcoin Signed Message:\n';
1414
if (proof.toString().startsWith(prefix)) {
1515
proof = proof.slice(Buffer.from(prefix).length);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
verifyPayGoAddressProof,
1414
} from '../../../src/paygo/psbt/payGoAddressProof';
1515
import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils';
16-
import { parseVaspProof } from '../../../src/testutil/parseVaspProof';
16+
import { trimMessagePrefix } from '../../../src/testutil/trimMessagePrefix';
1717
import { signMessage } from '../../../src/bip32utils';
1818
import { NIL_UUID } from '../../../src/paygo/attestation';
1919

@@ -46,7 +46,7 @@ export const addressToVerify = utxolib.address.toBase58Check(
4646

4747
// this should be retuning a Buffer
4848
export const addressProofBuffer = generatePayGoAttestationProof(NIL_UUID, Buffer.from(addressToVerify));
49-
export const addressProofMsgBuffer = parseVaspProof(addressProofBuffer);
49+
export const addressProofMsgBuffer = trimMessagePrefix(addressProofBuffer);
5050
// We know that that the entropy is a set 64 bytes.
5151
export const addressProofEntropy = addressProofMsgBuffer.subarray(0, 65);
5252

0 commit comments

Comments
 (0)