Skip to content

Commit 4ebd0b1

Browse files
chore(utxo-core): moved bip32utils to utxo-core, re-export sdk-core
TICKET: BTC-2210
1 parent 799ed35 commit 4ebd0b1

File tree

5 files changed

+59
-50
lines changed

5 files changed

+59
-50
lines changed

modules/sdk-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@bitgo/sjcl": "^1.0.1",
4444
"@bitgo/statics": "^54.3.0",
4545
"@bitgo/utxo-lib": "^11.5.0",
46+
"@bitgo/utxo-core": "^1.9.1",
4647
"@noble/curves": "1.8.1",
4748
"@stablelib/hex": "^1.0.0",
4849
"@types/superagent": "4.1.15",
Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,3 @@
1-
import * as utxolib from '@bitgo/utxo-lib';
2-
import * as _ from 'lodash';
3-
import * as bitcoinMessage from 'bitcoinjs-message';
4-
import { BIP32Interface } from '@bitgo/utxo-lib';
5-
/**
6-
* bip32-aware wrapper around bitcoin-message package
7-
* @see {bitcoinMessage.sign}
8-
*/
9-
export function signMessage(
10-
message: string,
11-
privateKey: BIP32Interface | Buffer,
12-
network: { messagePrefix: string }
13-
): Buffer {
14-
if (!Buffer.isBuffer(privateKey)) {
15-
privateKey = privateKey.privateKey as Buffer;
16-
if (!privateKey) {
17-
throw new Error(`must provide privateKey`);
18-
}
19-
}
20-
if (!_.isObject(network) || !_.isString(network.messagePrefix)) {
21-
throw new Error(`invalid argument 'network'`);
22-
}
23-
const compressed = true;
24-
return bitcoinMessage.sign(message, privateKey, compressed, network.messagePrefix);
25-
}
1+
import { signMessage, verifyMessage } from '@bitgo/utxo-core';
262

27-
/**
28-
* bip32-aware wrapper around bitcoin-message package
29-
* @see {bitcoinMessage.verify}
30-
*/
31-
export function verifyMessage(
32-
message: string,
33-
publicKey: BIP32Interface | Buffer,
34-
signature: Buffer,
35-
network: { messagePrefix: string }
36-
): boolean {
37-
if (!Buffer.isBuffer(publicKey)) {
38-
publicKey = publicKey.publicKey;
39-
}
40-
if (!_.isObject(network) || !_.isString(network.messagePrefix)) {
41-
throw new Error(`invalid argument 'network'`);
42-
}
43-
44-
const address = utxolib.address.toBase58Check(
45-
utxolib.crypto.hash160(publicKey),
46-
utxolib.networks.bitcoin.pubKeyHash,
47-
utxolib.networks.bitcoin
48-
);
49-
return bitcoinMessage.verify(message, address, signature, network.messagePrefix);
50-
}
3+
export { signMessage, verifyMessage };

modules/utxo-core/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
"@bitgo/unspents": "^0.48.1",
5555
"@bitgo/utxo-lib": "^11.5.0",
5656
"@bitgo/wasm-miniscript": "2.0.0-beta.7",
57-
"bip174": "npm:@bitgo-forks/[email protected]"
57+
"bip174": "npm:@bitgo-forks/[email protected]",
58+
"lodash": "^4.17.15"
59+
},
60+
"devDependencies": {
61+
"@types/lodash": "^4.14.151"
5862
},
5963
"gitHead": "18e460ddf02de2dbf13c2aa243478188fb539f0c"
6064
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as utxolib from '@bitgo/utxo-lib';
2+
import * as _ from 'lodash';
3+
import * as bitcoinMessage from 'bitcoinjs-message';
4+
import { BIP32Interface } from '@bitgo/utxo-lib';
5+
/**
6+
* bip32-aware wrapper around bitcoin-message package
7+
* @see {bitcoinMessage.sign}
8+
*/
9+
export function signMessage(
10+
message: string,
11+
privateKey: BIP32Interface | Buffer,
12+
network: { messagePrefix: string }
13+
): Buffer {
14+
if (!Buffer.isBuffer(privateKey)) {
15+
privateKey = privateKey.privateKey as Buffer;
16+
if (!privateKey) {
17+
throw new Error(`must provide privateKey`);
18+
}
19+
}
20+
if (!_.isObject(network) || !_.isString(network.messagePrefix)) {
21+
throw new Error(`invalid argument 'network'`);
22+
}
23+
const compressed = true;
24+
return bitcoinMessage.sign(message, privateKey, compressed, network.messagePrefix);
25+
}
26+
27+
/**
28+
* bip32-aware wrapper around bitcoin-message package
29+
* @see {bitcoinMessage.verify}
30+
*/
31+
export function verifyMessage(
32+
message: string,
33+
publicKey: BIP32Interface | Buffer,
34+
signature: Buffer,
35+
network: { messagePrefix: string }
36+
): boolean {
37+
if (!Buffer.isBuffer(publicKey)) {
38+
publicKey = publicKey.publicKey;
39+
}
40+
if (!_.isObject(network) || !_.isString(network.messagePrefix)) {
41+
throw new Error(`invalid argument 'network'`);
42+
}
43+
44+
const address = utxolib.address.toBase58Check(
45+
utxolib.crypto.hash160(publicKey),
46+
utxolib.networks.bitcoin.pubKeyHash,
47+
utxolib.networks.bitcoin
48+
);
49+
return bitcoinMessage.verify(message, address, signature, network.messagePrefix);
50+
}

modules/utxo-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * as bip65 from './bip65';
22
export * as descriptor from './descriptor';
33
export * as testutil from './testutil';
44
export * as paygo from './paygo';
5+
export * from './bip32utils';
56
export * from './dustThreshold';
67
export * from './Output';
78
export * from './xOnlyPubkey';

0 commit comments

Comments
 (0)