Skip to content

Commit 68e6032

Browse files
chore(utxo-core): generated index.ts and moved test function
TICKET: BTC-2150
1 parent 5fd10d6 commit 68e6032

File tree

9 files changed

+53
-139
lines changed

9 files changed

+53
-139
lines changed

modules/utxo-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * as bip65 from './bip65';
22
export * as descriptor from './descriptor';
33
export * as testutil from './testutil';
4+
export * as paygo from './paygo';
45
export * from './dustThreshold';
56
export * from './Output';
67
export * from './xOnlyPubkey';
7-
export * from './paygo/ExtractAddressPayGoAttestation';

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 * as utxolib from '@bitgo/utxo-lib';
3+
import { varuint } from '@bitgo/utxo-lib';
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 = utxolib.varuint.varuint.decode(message, offset);
35+
const varInt = varuint.varuint.decode(message, offset);
3636
assert(varInt);
3737
offset += 1;
3838

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ExtractAddressPayGoAttestation';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import crypto from 'crypto';
2+
3+
import { varuint } from '@bitgo/utxo-lib';
4+
/** We have a mirrored function similar to our hsm that generates our Bitcoin signed
5+
* message so that we can use for testing. This creates a random entropy as well using
6+
* the nilUUID structure to construct our uuid buffer and given our address we can
7+
* directly encode it into our message.
8+
*
9+
* @param attestationPrvKey
10+
* @param uuid
11+
* @param address
12+
* @returns
13+
*/
14+
export function generatePayGoAttestationProof(uuid: string, address: Buffer): Buffer {
15+
// <0x18Bitcoin Signed Message:\n
16+
const prefixByte = Buffer.from([0x18]);
17+
const prefixMessage = Buffer.from('Bitcoin Signed Message:\n');
18+
const prefixBuffer = Buffer.concat([prefixByte, prefixMessage]);
19+
20+
// <ENTROPY>
21+
const entropyLength = 64;
22+
const entropy = crypto.randomBytes(entropyLength);
23+
24+
// <UUID>
25+
const uuidBuffer = Buffer.from(uuid);
26+
const uuidBufferLength = uuidBuffer.length;
27+
28+
// <ADDRESS>
29+
const addressBufferLength = address.length;
30+
31+
// <VARINT_LENGTH>
32+
const msgLength = entropyLength + addressBufferLength + uuidBufferLength;
33+
const msgLengthBuffer = varuint.varuint.encode(msgLength);
34+
35+
// <0x18Bitcoin Signed Message:\n<LENGTH><ENTROPY><ADDRESS><UUID>
36+
const proofMessage = Buffer.concat([prefixBuffer, msgLengthBuffer, entropy, address, uuidBuffer]);
37+
38+
// we sign this with the priv key
39+
// don't know what sign function to call. Since this is just a mirrored function don't know if we need
40+
// to include this part.
41+
// const signedMsg = sign(attestationPrvKey, proofMessage);
42+
return proofMessage;
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './fixtures.utils';
22
export * from './key.utils';
33
export * from './toPlainObject.utils';
4+
export * from './generatePayGoAttestationProof.utils';

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

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

3-
import * as utxolib from '@bitgo/utxo-lib';
4-
5-
import { extractAddressBufferFromPayGoAttestationProof } from '../../src/paygo/ExtractAddressPayGoAttestation';
3+
import { extractAddressBufferFromPayGoAttestationProof } from '../../src/paygo';
4+
import { generatePayGoAttestationProof } from '../../src/testutil';
65

76
const addressFromPubKeyBase58 = 'bitgoAddressToExtract';
87
const bufferAddressPubKeyB58 = Buffer.from(addressFromPubKeyBase58);
98

109
describe('extractAddressBufferFromPayGoAttestationProof', () => {
1110
it('should extractAddressBufferFromPayGoAttestationProof properly', () => {
12-
const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof(
11+
const paygoAttestationProof = generatePayGoAttestationProof(
1312
'00000000-0000-0000-0000-000000000000',
1413
bufferAddressPubKeyB58
1514
);
@@ -18,7 +17,7 @@ describe('extractAddressBufferFromPayGoAttestationProof', () => {
1817
});
1918

2019
it('should extract the paygo address paygo attestation proof given a non nilUUID', () => {
21-
const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof(
20+
const paygoAttestationProof = generatePayGoAttestationProof(
2221
'12345678-1234-4567-6890-231928472123',
2322
bufferAddressPubKeyB58
2423
);
@@ -27,7 +26,7 @@ describe('extractAddressBufferFromPayGoAttestationProof', () => {
2726
});
2827

2928
it('should not extract the correct address given a uuid of wrong format', () => {
30-
const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof(
29+
const paygoAttestationProof = generatePayGoAttestationProof(
3130
'000000000000000-000000-0000000-000000-0000000000000000',
3231
bufferAddressPubKeyB58
3332
);

modules/utxo-lib/src/bitgo/ExtractAddressPayGoAttestation.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as assert from 'assert';
2-
import { varuint } from 'bitcoinjs-lib/src/bufferutils';
3-
import * as crypto from 'crypto';
42

53
import {
64
createOutputScriptP2shP2pk,
@@ -285,44 +283,3 @@ export function verifyFullySignedSignatures(
285283
}
286284
});
287285
}
288-
289-
/** We have a mirrored function similar to our hsm that generates our Bitcoin signed
290-
* message so that we can use for testing. This creates a random entropy as well using
291-
* the nilUUID structure to construct our uuid buffer and given our address we can
292-
* directly encode it into our message.
293-
*
294-
* @param attestationPrvKey
295-
* @param uuid
296-
* @param address
297-
* @returns
298-
*/
299-
export function generatePayGoAttestationProof(uuid: string, address: Buffer): Buffer {
300-
// <0x18Bitcoin Signed Message:\n
301-
const prefixByte = Buffer.from([0x18]);
302-
const prefixMessage = Buffer.from('Bitcoin Signed Message:\n');
303-
const prefixBuffer = Buffer.concat([prefixByte, prefixMessage]);
304-
305-
// <ENTROPY>
306-
const entropyLength = 64;
307-
const entropy = crypto.randomBytes(entropyLength);
308-
309-
// <UUID>
310-
const uuidBuffer = Buffer.from(uuid);
311-
const uuidBufferLength = uuidBuffer.length;
312-
313-
// <ADDRESS>
314-
const addressBufferLength = address.length;
315-
316-
// <VARINT_LENGTH>
317-
const msgLength = entropyLength + addressBufferLength + uuidBufferLength;
318-
const msgLengthBuffer = varuint.encode(msgLength);
319-
320-
// <0x18Bitcoin Signed Message:\n<LENGTH><ENTROPY><ADDRESS><UUID>
321-
const proofMessage = Buffer.concat([prefixBuffer, msgLengthBuffer, entropy, address, uuidBuffer]);
322-
323-
// we sign this with the priv key
324-
// don't know what sign function to call. Since this is just a mirrored function don't know if we need
325-
// to include this part.
326-
// const signedMsg = sign(attestationPrvKey, proofMessage);
327-
return proofMessage;
328-
}

modules/utxo-lib/test/bitgo/ExtractAddressPayGoAttestation.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)