Skip to content

Commit 3c35f37

Browse files
OttoAllmendingerllm-git
andcommitted
feat(utxo-core): allow Buffer message type in signMessage/verifyMessage
Updates the BIP32 utility functions to accept both string and Buffer types as message input, enhancing flexibility when working with different data formats. Issue: BTC-0 Co-authored-by: llm-git <[email protected]>
1 parent b07644c commit 3c35f37

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

modules/utxo-core/src/bip32utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BIP32Interface } from '@bitgo/utxo-lib';
66
* @see {bitcoinMessage.sign}
77
*/
88
export function signMessage(
9-
message: string,
9+
message: string | Buffer,
1010
privateKey: BIP32Interface | Buffer,
1111
network: { messagePrefix: string }
1212
): Buffer {
@@ -28,7 +28,7 @@ export function signMessage(
2828
* @see {bitcoinMessage.verify}
2929
*/
3030
export function verifyMessage(
31-
message: string,
31+
message: string | Buffer,
3232
publicKey: BIP32Interface | Buffer,
3333
signature: Buffer,
3434
network: { messagePrefix: string }

modules/utxo-core/test/bip32utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ describe('bip32utils', function () {
1111
}
1212
it('signMessage/verifyMessage', function () {
1313
const keys = getSeedBuffers(4).map((seed) => utxolib.bip32.fromSeed(seed));
14-
const messages = ['hello', 'goodbye'];
14+
const messages = ['hello', 'goodbye', Buffer.from('\x01\x02\x03'), Buffer.from('')];
1515
keys.forEach((key) => {
1616
messages.forEach((message) => {
1717
const signature = signMessage(message, key, utxolib.networks.bitcoin);
1818

1919
keys.forEach((otherKey) => {
2020
messages.forEach((otherMessage) => {
21+
const expectValid = message === otherMessage && key === otherKey;
22+
assert.strictEqual(verifyMessage(otherMessage, otherKey, signature, utxolib.networks.bitcoin), expectValid);
2123
assert.strictEqual(
22-
verifyMessage(otherMessage, otherKey, signature, utxolib.networks.bitcoin),
23-
message === otherMessage && key === otherKey
24+
verifyMessage(Buffer.from(otherMessage), otherKey, signature, utxolib.networks.bitcoin),
25+
expectValid
2426
);
2527
});
2628
});

0 commit comments

Comments
 (0)