@btc-vision/transaction 1.2.4 → 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.
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +10 -1
- package/browser/transaction/browser/Web3Provider.d.ts +3 -3
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
- package/browser/transaction/browser/extensions/XverseSigner.d.ts +2 -1
- package/browser/transaction/browser/types/Unisat.d.ts +5 -0
- package/browser/transaction/browser/types/Xverse.d.ts +10 -6
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryWriter.js +6 -6
- package/build/transaction/TransactionFactory.d.ts +10 -1
- package/build/transaction/TransactionFactory.js +28 -6
- package/build/transaction/browser/Web3Provider.d.ts +3 -3
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
- package/build/transaction/browser/extensions/UnisatSigner.js +6 -1
- package/build/transaction/browser/extensions/XverseSigner.d.ts +2 -1
- package/build/transaction/browser/extensions/XverseSigner.js +17 -0
- package/build/transaction/browser/types/Unisat.d.ts +5 -0
- package/build/transaction/browser/types/Unisat.js +5 -0
- package/build/transaction/browser/types/Xverse.d.ts +10 -6
- package/build/transaction/browser/types/Xverse.js +5 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryWriter.ts +6 -6
- package/src/transaction/TransactionFactory.ts +55 -9
- package/src/transaction/browser/Web3Provider.ts +3 -3
- package/src/transaction/browser/extensions/UnisatSigner.ts +10 -3
- package/src/transaction/browser/extensions/XverseSigner.ts +31 -1
- package/src/transaction/browser/types/Unisat.ts +8 -1
- package/src/transaction/browser/types/Xverse.ts +23 -13
|
@@ -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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
}
|