@btc-vision/wallet-sdk 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,7 +38,7 @@ export declare abstract class IKeyringBase<T extends BaseKeyringOptions> extends
38
38
  verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
39
39
  signData(publicKey: string, data: string, type?: 'ecdsa' | 'schnorr'): string;
40
40
  abstract getAccounts(): string[];
41
- signMessage(publicKey: string, text: string): string;
41
+ signMessage(publicKey: string, message: string | Buffer): string;
42
42
  exportAccount(publicKey: string): string | undefined;
43
43
  signTransaction(psbt: Psbt, inputs: {
44
44
  index: number;
@@ -33,9 +33,9 @@ export class IKeyringBase extends EventEmitter {
33
33
  throw new Error('Not support type');
34
34
  }
35
35
  }
36
- signMessage(publicKey, text) {
36
+ signMessage(publicKey, message) {
37
37
  const keyPair = this._getPrivateKeyFor(publicKey);
38
- return signMessageOfDeterministicECDSA(keyPair, text);
38
+ return signMessageOfDeterministicECDSA(keyPair, message);
39
39
  }
40
40
  exportAccount(publicKey) {
41
41
  const wallet = this._getWalletForAccount(publicKey);
@@ -76,7 +76,7 @@ export declare class KeystoneKeyring extends IKeyringBase<DeserializeOptionKeyst
76
76
  cbor: string;
77
77
  }>;
78
78
  parseSignMsgUr(type: string, cbor: string): Promise<import("@keystonehq/keystone-sdk").BtcSignature>;
79
- signMessage(publicKey: string, text: string): string;
79
+ signMessage(publicKey: string, message: string | Buffer): string;
80
80
  verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
81
81
  }
82
82
  export {};
@@ -309,7 +309,7 @@ export class KeystoneKeyring extends IKeyringBase {
309
309
  return keystoneSDK.btc.parseSignature(new UR(Buffer.from(cbor, 'hex'), type));
310
310
  }
311
311
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
312
- signMessage(publicKey, text) {
312
+ signMessage(publicKey, message) {
313
313
  return 'Signing Message with Keystone should use genSignMsgUr and parseSignMsgUr';
314
314
  }
315
315
  async verifyMessage(publicKey, text, sig) {
@@ -2,7 +2,7 @@ import * as bitcoin from '@btc-vision/bitcoin';
2
2
  import { NetworkType } from '../network';
3
3
  import { AbstractWallet } from '../wallet';
4
4
  export declare function genPsbtOfBIP322Simple({ message, address, networkType }: {
5
- message: string;
5
+ message: string | Buffer;
6
6
  address: string;
7
7
  networkType: NetworkType;
8
8
  }): bitcoin.Psbt;
@@ -11,7 +11,7 @@ export declare function getSignatureFromPsbtOfBIP322Simple(psbt: bitcoin.Psbt):
11
11
  * reference: https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
12
12
  */
13
13
  export declare function signMessageOfBIP322Simple({ message, address, networkType, wallet }: {
14
- message: string;
14
+ message: string | Buffer;
15
15
  address: string;
16
16
  networkType: NetworkType;
17
17
  wallet: AbstractWallet;
@@ -8,7 +8,8 @@ function bip0322_hash(message) {
8
8
  const { sha256 } = bitcoin.crypto;
9
9
  const tag = 'BIP0322-signed-message';
10
10
  const tagHash = sha256(Buffer.from(tag));
11
- const result = sha256(Buffer.concat([tagHash, tagHash, Buffer.from(message)]));
11
+ const messageBuffer = typeof message === 'string' ? Buffer.from(message, 'utf8') : message;
12
+ const result = sha256(Buffer.concat([tagHash, tagHash, messageBuffer]));
12
13
  return result.toString('hex');
13
14
  }
14
15
  export function genPsbtOfBIP322Simple({ message, address, networkType }) {
@@ -43,9 +44,11 @@ export function genPsbtOfBIP322Simple({ message, address, networkType }) {
43
44
  export function getSignatureFromPsbtOfBIP322Simple(psbt) {
44
45
  const txToSign = psbt.extractTransaction();
45
46
  function encodeVarString(b) {
46
- return Buffer.concat([encode(b.byteLength), b]);
47
+ const { buffer: vb } = encode(b.length);
48
+ return Buffer.concat([Buffer.from(vb), b]);
47
49
  }
48
- const len = encode(txToSign.ins[0].witness.length).buffer;
50
+ const { buffer: varintBuf } = encode(txToSign.ins[0].witness.length);
51
+ const len = Buffer.from(varintBuf);
49
52
  const result = Buffer.concat([len, ...txToSign.ins[0].witness.map((w) => encodeVarString(w))]);
50
53
  const signature = result.toString('base64');
51
54
  return signature;
@@ -1,2 +1,2 @@
1
1
  import { ECPairInterface } from '../bitcoin-core';
2
- export declare function signMessageOfDeterministicECDSA(ecpair: ECPairInterface, message: string): string;
2
+ export declare function signMessageOfDeterministicECDSA(ecpair: ECPairInterface, message: string | Buffer): string;
@@ -30,7 +30,7 @@ function varintBufNum(n) {
30
30
  }
31
31
  function magicHash(message) {
32
32
  const prefix1 = varintBufNum(MAGIC_BYTES.length);
33
- const messageBuffer = Buffer.from(message);
33
+ const messageBuffer = typeof message === 'string' ? Buffer.from(message) : message;
34
34
  const prefix2 = varintBufNum(messageBuffer.length);
35
35
  const buf = Buffer.concat([prefix1, MAGIC_BYTES, prefix2, messageBuffer]);
36
36
  return bitcoin.crypto.hash256(buf);
@@ -2,5 +2,5 @@ import { bitcoin } from '../bitcoin-core';
2
2
  import { SignPsbtOptions } from '../types';
3
3
  export interface AbstractWallet {
4
4
  signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
5
- signMessage(text: string, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
5
+ signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
6
6
  }
@@ -18,6 +18,6 @@ export declare class EstimateWallet implements AbstractWallet {
18
18
  getNetworkType(): NetworkType;
19
19
  signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
20
20
  getPublicKey(): Promise<string>;
21
- signMessage(text: string, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
21
+ signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
22
22
  private formatOptionsToSignInputs;
23
23
  }
@@ -76,10 +76,10 @@ export class EstimateWallet {
76
76
  const pubkeys = await this.keyring.getAccounts();
77
77
  return pubkeys[0];
78
78
  }
79
- async signMessage(text, type) {
79
+ async signMessage(message, type) {
80
80
  if (type === 'bip322-simple') {
81
81
  return await signMessageOfBIP322Simple({
82
- message: text,
82
+ message,
83
83
  address: this.address,
84
84
  networkType: this.networkType,
85
85
  wallet: this
@@ -87,7 +87,7 @@ export class EstimateWallet {
87
87
  }
88
88
  else {
89
89
  const pubkey = await this.getPublicKey();
90
- return await this.keyring.signMessage(pubkey, text);
90
+ return this.keyring.signMessage(pubkey, message);
91
91
  }
92
92
  }
93
93
  async formatOptionsToSignInputs(_psbt, options) {
@@ -17,7 +17,7 @@ export declare class LocalWallet implements AbstractWallet {
17
17
  getNetworkType(): NetworkType;
18
18
  signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
19
19
  getPublicKey(): string;
20
- signMessage(text: string, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
20
+ signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
21
21
  signData(data: string, type?: 'ecdsa' | 'schnorr'): Promise<string>;
22
22
  private formatOptionsToSignInputs;
23
23
  }
@@ -82,10 +82,10 @@ export class LocalWallet {
82
82
  const pubkeys = this.keyring.getAccounts();
83
83
  return pubkeys[0];
84
84
  }
85
- async signMessage(text, type) {
85
+ async signMessage(message, type) {
86
86
  if (type === 'bip322-simple') {
87
87
  return await signMessageOfBIP322Simple({
88
- message: text,
88
+ message,
89
89
  address: this.address,
90
90
  networkType: this.networkType,
91
91
  wallet: this
@@ -93,7 +93,7 @@ export class LocalWallet {
93
93
  }
94
94
  else {
95
95
  const pubkey = this.getPublicKey();
96
- return this.keyring.signMessage(pubkey, text);
96
+ return this.keyring.signMessage(pubkey, message);
97
97
  }
98
98
  }
99
99
  async signData(data, type = 'ecdsa') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/wallet-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "OP_WALLET SDK",
5
5
  "keywords": [
6
6
  "bitcoin",