@btc-vision/transaction 1.2.5 → 1.2.6

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.
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Unisat } from '../types/Unisat.js';
3
+ import { SignatureType, Unisat } from '../types/Unisat.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  unisat?: Unisat;
@@ -21,6 +21,7 @@ export declare class UnisatSigner extends CustomKeypair {
21
21
  _network: Network | undefined;
22
22
  get network(): Network;
23
23
  get unisat(): Unisat;
24
+ signData(data: Buffer, type: SignatureType): Promise<Buffer>;
24
25
  init(): Promise<void>;
25
26
  getPublicKey(): Buffer;
26
27
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Xverse } from '../types/Xverse.js';
3
+ import { SigningProtocol, Xverse } from '../types/Xverse.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  BitcoinProvider?: Xverse;
@@ -21,6 +21,7 @@ export declare class XverseSigner extends CustomKeypair {
21
21
  get network(): Network;
22
22
  get BitcoinProvider(): Xverse;
23
23
  init(): Promise<void>;
24
+ signData(data: Buffer, address: string, protocol: SigningProtocol): Promise<Buffer>;
24
25
  getPublicKey(): Buffer;
25
26
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
26
27
  signSchnorr(_hash: Buffer): Buffer;
@@ -27,6 +27,10 @@ export declare enum MessageType {
27
27
  ecdsa = "ecdsa",
28
28
  bip322 = "bip322-simple"
29
29
  }
30
+ export declare enum SignatureType {
31
+ ecdsa = "ecdsa",
32
+ schnorr = "schnorr"
33
+ }
30
34
  interface ToSignInputBase {
31
35
  readonly index: number;
32
36
  readonly sighashTypes?: number[];
@@ -60,6 +64,7 @@ export interface Unisat {
60
64
  getPublicKey(): Promise<string>;
61
65
  getBalance(): Promise<Balance>;
62
66
  signMessage(message: string, type?: MessageType): Promise<string>;
67
+ signData(hex: string, type?: SignatureType): Promise<string>;
63
68
  pushTx(options: {
64
69
  rawtx: string;
65
70
  }): Promise<string>;
@@ -76,18 +76,22 @@ interface SignedTransactionResult {
76
76
  txid: string;
77
77
  raw: string;
78
78
  }
79
+ export declare enum SigningProtocol {
80
+ ECDSA = "ECDSA",
81
+ BIP322 = "BIP322"
82
+ }
79
83
  export interface Xverse {
80
- request(method: string, params: unknown): Promise<XverseRPCResponse>;
81
- request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
82
- request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
83
- request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
84
- request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
85
84
  addListener: (event: string, callback: (...args: unknown[]) => void) => void;
86
85
  createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
87
86
  createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
88
87
  sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
89
- signMessage: (message: string) => Promise<SignedMessageResult>;
88
+ signMessage: (address: string, message: string, protocol: SigningProtocol) => Promise<SignedMessageResult>;
90
89
  signMultipleTransactions: (transactions: BtcTransaction[]) => Promise<SignedTransactionResult[]>;
91
90
  signTransaction: (transaction: BtcTransaction) => Promise<SignedTransactionResult>;
91
+ request(method: string, params: unknown): Promise<XverseRPCResponse>;
92
+ request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
93
+ request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
94
+ request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
95
+ request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
92
96
  }
93
97
  export {};
@@ -1 +1 @@
1
- export declare const version = "1.2.5";
1
+ export declare const version = "1.2.6";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.5';
1
+ export const version = '1.2.6';
@@ -208,7 +208,10 @@ export class TransactionFactory {
208
208
  return null;
209
209
  }
210
210
  const opnet = window.opnet.web3;
211
- const interaction = await opnet.signInteraction(interactionParameters);
211
+ const interaction = await opnet.signInteraction({
212
+ ...interactionParameters,
213
+ signer: undefined,
214
+ });
212
215
  if (!interaction) {
213
216
  throw new Error('Could not sign interaction transaction.');
214
217
  }
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Unisat } from '../types/Unisat.js';
3
+ import { SignatureType, Unisat } from '../types/Unisat.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  unisat?: Unisat;
@@ -21,6 +21,7 @@ export declare class UnisatSigner extends CustomKeypair {
21
21
  _network: Network | undefined;
22
22
  get network(): Network;
23
23
  get unisat(): Unisat;
24
+ signData(data: Buffer, type: SignatureType): Promise<Buffer>;
24
25
  init(): Promise<void>;
25
26
  getPublicKey(): Buffer;
26
27
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
@@ -1,4 +1,4 @@
1
- import { crypto as bitCrypto, script as bitScript, networks, Psbt, toXOnly, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitCrypto, networks, Psbt, script as bitScript, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
3
3
  import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
4
4
  import { CustomKeypair } from '../BrowserSignerBase.js';
@@ -48,6 +48,11 @@ export class UnisatSigner extends CustomKeypair {
48
48
  }
49
49
  return module;
50
50
  }
51
+ async signData(data, type) {
52
+ const str = data.toString('hex');
53
+ const signature = await this.unisat.signData(str, type);
54
+ return Buffer.from(signature, 'hex');
55
+ }
51
56
  async init() {
52
57
  if (this.isInitialized) {
53
58
  return;
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Xverse } from '../types/Xverse.js';
3
+ import { SigningProtocol, Xverse } from '../types/Xverse.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  BitcoinProvider?: Xverse;
@@ -21,6 +21,7 @@ export declare class XverseSigner extends CustomKeypair {
21
21
  get network(): Network;
22
22
  get BitcoinProvider(): Xverse;
23
23
  init(): Promise<void>;
24
+ signData(data: Buffer, address: string, protocol: SigningProtocol): Promise<Buffer>;
24
25
  getPublicKey(): Buffer;
25
26
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
26
27
  signSchnorr(_hash: Buffer): Buffer;
@@ -71,6 +71,23 @@ export class XverseSigner extends CustomKeypair {
71
71
  this._addresses = [this._p2wpkh, this._p2tr];
72
72
  this.isInitialized = true;
73
73
  }
74
+ async signData(data, address, protocol) {
75
+ if (!this.isInitialized) {
76
+ throw new Error('UnisatSigner not initialized');
77
+ }
78
+ const callSign = await this.BitcoinProvider.request('signMessage', {
79
+ address,
80
+ message: data.toString(),
81
+ protocol,
82
+ });
83
+ if ('error' in callSign)
84
+ throw new Error(callSign.error.message);
85
+ const res = callSign.result;
86
+ if (!res.signature) {
87
+ throw new Error('Signature not found');
88
+ }
89
+ return Buffer.from(res.signature, 'hex');
90
+ }
74
91
  getPublicKey() {
75
92
  if (!this.isInitialized) {
76
93
  throw new Error('UnisatSigner not initialized');
@@ -27,6 +27,10 @@ export declare enum MessageType {
27
27
  ecdsa = "ecdsa",
28
28
  bip322 = "bip322-simple"
29
29
  }
30
+ export declare enum SignatureType {
31
+ ecdsa = "ecdsa",
32
+ schnorr = "schnorr"
33
+ }
30
34
  interface ToSignInputBase {
31
35
  readonly index: number;
32
36
  readonly sighashTypes?: number[];
@@ -60,6 +64,7 @@ export interface Unisat {
60
64
  getPublicKey(): Promise<string>;
61
65
  getBalance(): Promise<Balance>;
62
66
  signMessage(message: string, type?: MessageType): Promise<string>;
67
+ signData(hex: string, type?: SignatureType): Promise<string>;
63
68
  pushTx(options: {
64
69
  rawtx: string;
65
70
  }): Promise<string>;
@@ -19,3 +19,8 @@ export var MessageType;
19
19
  MessageType["ecdsa"] = "ecdsa";
20
20
  MessageType["bip322"] = "bip322-simple";
21
21
  })(MessageType || (MessageType = {}));
22
+ export var SignatureType;
23
+ (function (SignatureType) {
24
+ SignatureType["ecdsa"] = "ecdsa";
25
+ SignatureType["schnorr"] = "schnorr";
26
+ })(SignatureType || (SignatureType = {}));
@@ -76,18 +76,22 @@ interface SignedTransactionResult {
76
76
  txid: string;
77
77
  raw: string;
78
78
  }
79
+ export declare enum SigningProtocol {
80
+ ECDSA = "ECDSA",
81
+ BIP322 = "BIP322"
82
+ }
79
83
  export interface Xverse {
80
- request(method: string, params: unknown): Promise<XverseRPCResponse>;
81
- request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
82
- request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
83
- request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
84
- request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
85
84
  addListener: (event: string, callback: (...args: unknown[]) => void) => void;
86
85
  createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
87
86
  createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
88
87
  sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
89
- signMessage: (message: string) => Promise<SignedMessageResult>;
88
+ signMessage: (address: string, message: string, protocol: SigningProtocol) => Promise<SignedMessageResult>;
90
89
  signMultipleTransactions: (transactions: BtcTransaction[]) => Promise<SignedTransactionResult[]>;
91
90
  signTransaction: (transaction: BtcTransaction) => Promise<SignedTransactionResult>;
91
+ request(method: string, params: unknown): Promise<XverseRPCResponse>;
92
+ request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
93
+ request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
94
+ request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
95
+ request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
92
96
  }
93
97
  export {};
@@ -4,3 +4,8 @@ export var XverseNetwork;
4
4
  XverseNetwork["testnet"] = "testnet";
5
5
  XverseNetwork["signet"] = "Signet";
6
6
  })(XverseNetwork || (XverseNetwork = {}));
7
+ export var SigningProtocol;
8
+ (function (SigningProtocol) {
9
+ SigningProtocol["ECDSA"] = "ECDSA";
10
+ SigningProtocol["BIP322"] = "BIP322";
11
+ })(SigningProtocol || (SigningProtocol = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.2.5",
4
+ "version": "1.2.6",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.5';
1
+ export const version = '1.2.6';
@@ -397,7 +397,13 @@ export class TransactionFactory {
397
397
  }
398
398
 
399
399
  const opnet = window.opnet.web3;
400
- const interaction = await opnet.signInteraction(interactionParameters);
400
+ const interaction = await opnet.signInteraction({
401
+ ...interactionParameters,
402
+
403
+ // @ts-expect-error no, this is ok
404
+ signer: undefined,
405
+ });
406
+
401
407
  if (!interaction) {
402
408
  throw new Error('Could not sign interaction transaction.');
403
409
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  crypto as bitCrypto,
3
- script as bitScript,
4
3
  Network,
5
4
  networks,
6
5
  Psbt,
6
+ script as bitScript,
7
7
  TapScriptSig,
8
8
  toXOnly,
9
9
  } from '@btc-vision/bitcoin';
@@ -12,7 +12,7 @@ import { ECPairInterface } from 'ecpair';
12
12
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
13
13
  import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
14
14
  import { CustomKeypair } from '../BrowserSignerBase.js';
15
- import { PsbtSignatureOptions, Unisat, UnisatNetwork } from '../types/Unisat.js';
15
+ import { PsbtSignatureOptions, SignatureType, Unisat, UnisatNetwork } from '../types/Unisat.js';
16
16
 
17
17
  declare global {
18
18
  interface Window {
@@ -91,11 +91,18 @@ export class UnisatSigner extends CustomKeypair {
91
91
  return module;
92
92
  }
93
93
 
94
+ public async signData(data: Buffer, type: SignatureType): Promise<Buffer> {
95
+ const str = data.toString('hex');
96
+ const signature = await this.unisat.signData(str, type);
97
+
98
+ return Buffer.from(signature, 'hex');
99
+ }
100
+
94
101
  public async init(): Promise<void> {
95
102
  if (this.isInitialized) {
96
103
  return;
97
104
  }
98
-
105
+
99
106
  const network = await this.unisat.getNetwork();
100
107
  switch (network) {
101
108
  case UnisatNetwork.mainnet:
@@ -9,7 +9,7 @@ import {
9
9
  } from '../../../signer/SignerUtils.js';
10
10
  import { CustomKeypair } from '../BrowserSignerBase.js';
11
11
  import { PsbtSignatureOptions } from '../types/Unisat.js';
12
- import { Xverse } from '../types/Xverse.js';
12
+ import { SigningProtocol, Xverse } from '../types/Xverse.js';
13
13
 
14
14
  declare global {
15
15
  interface Window {
@@ -123,6 +123,36 @@ export class XverseSigner extends CustomKeypair {
123
123
  this.isInitialized = true;
124
124
  }
125
125
 
126
+ public async signData(
127
+ data: Buffer,
128
+ address: string,
129
+ protocol: SigningProtocol,
130
+ ): Promise<Buffer> {
131
+ if (!this.isInitialized) {
132
+ throw new Error('UnisatSigner not initialized');
133
+ }
134
+
135
+ const callSign = await this.BitcoinProvider.request('signMessage', {
136
+ address,
137
+ message: data.toString(),
138
+ protocol,
139
+ });
140
+
141
+ if ('error' in callSign) throw new Error(callSign.error.message);
142
+
143
+ const res = callSign.result as {
144
+ signature: string;
145
+ messageHash: string;
146
+ address: string;
147
+ };
148
+
149
+ if (!res.signature) {
150
+ throw new Error('Signature not found');
151
+ }
152
+
153
+ return Buffer.from(res.signature, 'hex');
154
+ }
155
+
126
156
  public getPublicKey(): Buffer {
127
157
  if (!this.isInitialized) {
128
158
  throw new Error('UnisatSigner not initialized');
@@ -33,6 +33,11 @@ export enum MessageType {
33
33
  bip322 = 'bip322-simple',
34
34
  }
35
35
 
36
+ export enum SignatureType {
37
+ ecdsa = 'ecdsa',
38
+ schnorr = 'schnorr',
39
+ }
40
+
36
41
  interface ToSignInputBase {
37
42
  readonly index: number;
38
43
  readonly sighashTypes?: number[];
@@ -56,7 +61,7 @@ export interface PsbtSignatureOptions {
56
61
 
57
62
  export interface Unisat {
58
63
  web3?: Web3Provider;
59
-
64
+
60
65
  disconnect: () => void;
61
66
  connect: () => void;
62
67
 
@@ -82,6 +87,8 @@ export interface Unisat {
82
87
 
83
88
  signMessage(message: string, type?: MessageType): Promise<string>;
84
89
 
90
+ signData(hex: string, type?: SignatureType): Promise<string>;
91
+
85
92
  pushTx(options: { rawtx: string }): Promise<string>;
86
93
 
87
94
  signPsbt(psbtHex: string, psbtOptions: PsbtSignatureOptions): Promise<string>;
@@ -93,26 +93,36 @@ interface SignedTransactionResult {
93
93
  raw: string;
94
94
  }
95
95
 
96
- export interface Xverse {
97
- request(method: string, params: unknown): Promise<XverseRPCResponse>;
98
- request(
99
- method: 'wallet_connect' | 'wallet_getAccount',
100
- params: null,
101
- ): Promise<XverseRPCGetAccountResponse>;
102
- request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
103
- request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
104
- request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
96
+ export enum SigningProtocol {
97
+ ECDSA = 'ECDSA',
98
+ BIP322 = 'BIP322',
99
+ }
105
100
 
101
+ export interface Xverse {
106
102
  addListener: (event: string, callback: (...args: unknown[]) => void) => void;
107
-
108
103
  createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
109
104
  createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
110
-
111
105
  sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
112
-
113
- signMessage: (message: string) => Promise<SignedMessageResult>;
106
+ signMessage: (
107
+ address: string,
108
+ message: string,
109
+ protocol: SigningProtocol,
110
+ ) => Promise<SignedMessageResult>;
114
111
  signMultipleTransactions: (
115
112
  transactions: BtcTransaction[],
116
113
  ) => Promise<SignedTransactionResult[]>;
117
114
  signTransaction: (transaction: BtcTransaction) => Promise<SignedTransactionResult>;
115
+
116
+ request(method: string, params: unknown): Promise<XverseRPCResponse>;
117
+
118
+ request(
119
+ method: 'wallet_connect' | 'wallet_getAccount',
120
+ params: null,
121
+ ): Promise<XverseRPCGetAccountResponse>;
122
+
123
+ request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
124
+
125
+ request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
126
+
127
+ request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
118
128
  }