@btc-vision/transaction 1.0.119 → 1.0.121
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/buffer/BinaryWriter.d.ts +1 -1
- package/browser/generators/AddressGenerator.d.ts +1 -1
- package/browser/generators/Generator.d.ts +1 -1
- package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
- package/browser/generators/builders/CustomGenerator.d.ts +1 -1
- package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +3 -6
- package/browser/keypair/AddressVerificator.d.ts +1 -1
- package/browser/keypair/EcKeyPair.d.ts +2 -2
- package/browser/keypair/Wallet.d.ts +1 -1
- package/browser/metadata/ContractBaseMetadata.d.ts +1 -1
- package/browser/metadata/contracts/wBTC.d.ts +1 -1
- package/browser/signer/TweakedSigner.d.ts +1 -1
- package/browser/transaction/TransactionFactory.d.ts +1 -1
- package/browser/transaction/browser/BrowserSignerBase.d.ts +1 -1
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +1 -1
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +2 -2
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/browser/transaction/builders/TransactionBuilder.d.ts +1 -1
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +2 -2
- package/browser/transaction/builders/UnwrapTransaction.d.ts +2 -2
- package/browser/transaction/builders/WrapTransaction.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/browser/transaction/interfaces/Tap.d.ts +1 -1
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +1 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/browser/verification/TapscriptVerificator.d.ts +2 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryWriter.d.ts +1 -1
- package/build/buffer/BinaryWriter.js +4 -5
- package/build/generators/AddressGenerator.d.ts +1 -1
- package/build/generators/AddressGenerator.js +2 -2
- package/build/generators/Features.js +1 -1
- package/build/generators/Generator.d.ts +1 -1
- package/build/generators/Generator.js +2 -2
- package/build/generators/builders/CalldataGenerator.d.ts +1 -1
- package/build/generators/builders/CalldataGenerator.js +1 -1
- package/build/generators/builders/CustomGenerator.d.ts +1 -1
- package/build/generators/builders/CustomGenerator.js +1 -1
- package/build/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/build/generators/builders/DeploymentGenerator.js +1 -1
- package/build/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
- package/build/generators/builders/LegacyCalldataGenerator.js +1 -1
- package/build/generators/builders/MultiSignGenerator.js +2 -2
- package/build/keypair/Address.d.ts +3 -6
- package/build/keypair/Address.js +29 -25
- package/build/keypair/AddressVerificator.d.ts +1 -1
- package/build/keypair/AddressVerificator.js +1 -1
- package/build/keypair/EcKeyPair.d.ts +2 -2
- package/build/keypair/EcKeyPair.js +17 -10
- package/build/keypair/Wallet.d.ts +1 -1
- package/build/keypair/Wallet.js +3 -3
- package/build/metadata/ContractBaseMetadata.d.ts +1 -1
- package/build/metadata/ContractBaseMetadata.js +1 -1
- package/build/metadata/contracts/wBTC.d.ts +1 -1
- package/build/metadata/contracts/wBTC.js +1 -1
- package/build/signer/TweakedSigner.d.ts +1 -1
- package/build/signer/TweakedSigner.js +3 -3
- package/build/transaction/TransactionFactory.d.ts +1 -1
- package/build/transaction/browser/BrowserSignerBase.d.ts +1 -1
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +1 -1
- package/build/transaction/browser/extensions/UnisatSigner.js +1 -1
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/build/transaction/builders/CustomScriptTransaction.js +2 -2
- package/build/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/build/transaction/builders/DeploymentTransaction.js +2 -2
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +2 -2
- package/build/transaction/builders/MultiSignTransaction.js +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.js +2 -2
- package/build/transaction/builders/TransactionBuilder.d.ts +1 -1
- package/build/transaction/builders/TransactionBuilder.js +2 -2
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +2 -2
- package/build/transaction/builders/UnwrapSegwitTransaction.js +1 -1
- package/build/transaction/builders/UnwrapTransaction.d.ts +2 -2
- package/build/transaction/builders/UnwrapTransaction.js +2 -2
- package/build/transaction/builders/WrapTransaction.d.ts +1 -1
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/transaction/interfaces/Tap.d.ts +1 -1
- package/build/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/build/transaction/processor/PsbtTransaction.js +1 -1
- package/build/transaction/shared/P2TR_MS.d.ts +1 -1
- package/build/transaction/shared/P2TR_MS.js +1 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +1 -1
- package/build/transaction/shared/TweakedTransaction.js +3 -3
- package/build/utils/BitcoinUtils.js +1 -5
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/build/verification/TapscriptVerificator.d.ts +2 -2
- package/build/verification/TapscriptVerificator.js +2 -2
- package/gulpfile.js +1 -1
- package/package.json +21 -21
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryWriter.ts +5 -6
- package/src/generators/AddressGenerator.ts +2 -2
- package/src/generators/Features.ts +1 -1
- package/src/generators/Generator.ts +2 -2
- package/src/generators/builders/CalldataGenerator.ts +2 -2
- package/src/generators/builders/CustomGenerator.ts +1 -1
- package/src/generators/builders/DeploymentGenerator.ts +1 -1
- package/src/generators/builders/LegacyCalldataGenerator.ts +1 -1
- package/src/generators/builders/MultiSignGenerator.ts +2 -2
- package/src/keypair/Address.ts +43 -40
- package/src/keypair/AddressVerificator.ts +1 -1
- package/src/keypair/EcKeyPair.ts +22 -14
- package/src/keypair/Wallet.ts +3 -6
- package/src/metadata/ContractBaseMetadata.ts +1 -1
- package/src/metadata/contracts/wBTC.ts +1 -1
- package/src/signer/TweakedSigner.ts +3 -3
- package/src/transaction/TransactionFactory.ts +2 -2
- package/src/transaction/browser/BrowserSignerBase.ts +1 -1
- package/src/transaction/browser/extensions/UnisatSigner.ts +1 -1
- package/src/transaction/builders/CustomScriptTransaction.ts +3 -3
- package/src/transaction/builders/DeploymentTransaction.ts +3 -3
- package/src/transaction/builders/FundingTransaction.ts +1 -1
- package/src/transaction/builders/InteractionTransaction.ts +1 -1
- package/src/transaction/builders/MultiSignTransaction.ts +3 -3
- package/src/transaction/builders/SharedInteractionTransaction.ts +3 -3
- package/src/transaction/builders/TransactionBuilder.ts +2 -2
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +2 -2
- package/src/transaction/builders/UnwrapTransaction.ts +3 -3
- package/src/transaction/builders/WrapTransaction.ts +2 -2
- package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
- package/src/transaction/interfaces/Tap.ts +1 -1
- package/src/transaction/processor/PsbtTransaction.ts +1 -1
- package/src/transaction/shared/P2TR_MS.ts +1 -1
- package/src/transaction/shared/TweakedTransaction.ts +3 -3
- package/src/utils/BitcoinUtils.ts +3 -7
- package/src/utxo/OPNetLimitedProvider.ts +1 -1
- package/src/verification/TapscriptVerificator.ts +3 -3
- package/webpack.config.js +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Network, networks } from '
|
|
2
|
-
import { toXOnly } from '
|
|
1
|
+
import { Network, networks } from '@btc-vision/bitcoin';
|
|
2
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
3
3
|
|
|
4
4
|
/** Bitcoin Script Generator */
|
|
5
5
|
export abstract class Generator {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { crypto, Network, networks, opcodes, script } from '
|
|
1
|
+
import { crypto, Network, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
4
4
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
@@ -99,7 +99,7 @@ export class CalldataGenerator extends Generator {
|
|
|
99
99
|
|
|
100
100
|
Generator.MAGIC,
|
|
101
101
|
];
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
// write pub keys, when requested.
|
|
104
104
|
if (vaultPublicKeys.length > 0) {
|
|
105
105
|
const pubKeyBuffer = CalldataGenerator.getPubKeyAsBuffer(vaultPublicKeys, this.network);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Network, networks, opcodes, script } from '
|
|
1
|
+
import { Network, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
4
4
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { opcodes, script } from '
|
|
2
|
-
import { toXOnly } from '
|
|
1
|
+
import { opcodes, script } from '@btc-vision/bitcoin';
|
|
2
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a bitcoin script for a multisign interaction
|
package/src/keypair/Address.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import { Network } from '
|
|
1
|
+
import { Network } from '@btc-vision/bitcoin';
|
|
2
2
|
import { EcKeyPair } from './EcKeyPair.js';
|
|
3
3
|
import { ECPairInterface } from 'ecpair';
|
|
4
4
|
import { ADDRESS_BYTE_LENGTH } from '../utils/types.js';
|
|
5
5
|
import { AddressVerificator } from './AddressVerificator.js';
|
|
6
|
-
import { toXOnly } from '
|
|
6
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
7
7
|
|
|
8
|
+
const hexPattern = /^[0-9a-fA-F]+$/;
|
|
9
|
+
const isHexadecimal = (input: string): boolean => {
|
|
10
|
+
return hexPattern.test(input);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Objects of type "Address" are the representation of tweaked public keys. They can be converted to different address formats.
|
|
15
|
+
* @category KeyPair
|
|
16
|
+
*/
|
|
8
17
|
export class Address extends Uint8Array {
|
|
9
|
-
private isP2TROnly: boolean = false;
|
|
10
18
|
#p2tr: string | undefined;
|
|
11
19
|
#network: Network | undefined;
|
|
12
|
-
#
|
|
20
|
+
#originalPublicKey: Uint8Array | undefined;
|
|
21
|
+
#keyPair: ECPairInterface | undefined;
|
|
13
22
|
|
|
14
23
|
public constructor(bytes?: ArrayLike<number>) {
|
|
15
24
|
super(bytes?.length || ADDRESS_BYTE_LENGTH);
|
|
@@ -21,25 +30,24 @@ export class Address extends Uint8Array {
|
|
|
21
30
|
this.set(bytes);
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
/**
|
|
34
|
+
* If available, this will return the original public key associated with the address.
|
|
35
|
+
* @returns {Uint8Array} The original public key used to create the address.
|
|
36
|
+
*/
|
|
37
|
+
public get originalPublicKey(): Uint8Array | undefined {
|
|
38
|
+
return this.#originalPublicKey;
|
|
39
|
+
}
|
|
25
40
|
|
|
26
41
|
/**
|
|
27
42
|
* Get the key pair for the address
|
|
43
|
+
* @description This is only for internal use. Please use address.tweakedBytes instead.
|
|
28
44
|
*/
|
|
29
|
-
|
|
30
|
-
if (!this
|
|
45
|
+
private get keyPair(): ECPairInterface {
|
|
46
|
+
if (!this.#keyPair) {
|
|
31
47
|
throw new Error('Public key not set for address');
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
return this
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get the tweaked bytes
|
|
39
|
-
* @returns {Uint8Array} The tweaked bytes
|
|
40
|
-
*/
|
|
41
|
-
public get tweakedBytes(): Uint8Array {
|
|
42
|
-
return this.#tweakedBytes || this;
|
|
50
|
+
return this.#keyPair;
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
public static dead(): Address {
|
|
@@ -62,6 +70,12 @@ export class Address extends Uint8Array {
|
|
|
62
70
|
pubKey = pubKey.slice(2);
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
if (!isHexadecimal(pubKey)) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
'You must only pass public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
65
79
|
return new Address(Buffer.from(pubKey, 'hex'));
|
|
66
80
|
}
|
|
67
81
|
|
|
@@ -91,15 +105,14 @@ export class Address extends Uint8Array {
|
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
public equals(a: Address): boolean {
|
|
94
|
-
const b = this
|
|
95
|
-
const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
|
|
108
|
+
const b: Address = this as Address;
|
|
96
109
|
|
|
97
|
-
if (
|
|
110
|
+
if (a.length !== b.length) {
|
|
98
111
|
return false;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
for (let i = 0; i < b.length; i++) {
|
|
102
|
-
if (b[i] !==
|
|
115
|
+
if (b[i] !== a[i]) {
|
|
103
116
|
return false;
|
|
104
117
|
}
|
|
105
118
|
}
|
|
@@ -112,13 +125,11 @@ export class Address extends Uint8Array {
|
|
|
112
125
|
* @returns {boolean} If bigger
|
|
113
126
|
*/
|
|
114
127
|
public lessThan(a: Address): boolean {
|
|
115
|
-
|
|
116
|
-
const b = this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array);
|
|
117
|
-
const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
|
|
128
|
+
const b: Address = this as Address;
|
|
118
129
|
|
|
119
130
|
for (let i = 0; i < 32; i++) {
|
|
120
131
|
const thisByte = b[i];
|
|
121
|
-
const aByte =
|
|
132
|
+
const aByte = a[i];
|
|
122
133
|
|
|
123
134
|
if (thisByte < aByte) {
|
|
124
135
|
return true; // this is less than a
|
|
@@ -136,12 +147,11 @@ export class Address extends Uint8Array {
|
|
|
136
147
|
*/
|
|
137
148
|
public greaterThan(a: Address): boolean {
|
|
138
149
|
// Compare the two addresses byte-by-byte, treating them as big-endian uint256
|
|
139
|
-
const b = this
|
|
140
|
-
const c = a.isP2TROnly ? a : (a.#tweakedBytes as Uint8Array);
|
|
150
|
+
const b = this as Address;
|
|
141
151
|
|
|
142
152
|
for (let i = 0; i < 32; i++) {
|
|
143
153
|
const thisByte = b[i];
|
|
144
|
-
const aByte =
|
|
154
|
+
const aByte = a[i];
|
|
145
155
|
|
|
146
156
|
if (thisByte > aByte) {
|
|
147
157
|
return true; // this is greater than a
|
|
@@ -164,23 +174,19 @@ export class Address extends Uint8Array {
|
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
if (publicKey.length === 32) {
|
|
167
|
-
this.isP2TROnly = true;
|
|
168
|
-
|
|
169
177
|
const buf = Buffer.alloc(32);
|
|
170
178
|
buf.set(publicKey);
|
|
171
179
|
|
|
172
180
|
super.set(publicKey);
|
|
173
181
|
} else {
|
|
174
|
-
this
|
|
182
|
+
this.#originalPublicKey = Uint8Array.from(publicKey);
|
|
183
|
+
this.#keyPair = EcKeyPair.fromPublicKey(this.#originalPublicKey);
|
|
175
184
|
|
|
176
|
-
|
|
177
|
-
Buffer.from(
|
|
178
|
-
EcKeyPair.tweakPublicKey(this._keyPair.publicKey.toString('hex')),
|
|
179
|
-
'hex',
|
|
180
|
-
),
|
|
185
|
+
const tweakedBytes = toXOnly(
|
|
186
|
+
EcKeyPair.tweakPublicKey(Buffer.from(this.#originalPublicKey)),
|
|
181
187
|
);
|
|
182
188
|
|
|
183
|
-
super.set(
|
|
189
|
+
super.set(tweakedBytes);
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
192
|
|
|
@@ -237,10 +243,7 @@ export class Address extends Uint8Array {
|
|
|
237
243
|
return this.#p2tr;
|
|
238
244
|
}
|
|
239
245
|
|
|
240
|
-
const p2trAddy: string | undefined = EcKeyPair.tweakedPubKeyBufferToAddress(
|
|
241
|
-
this.isP2TROnly ? this : (this.#tweakedBytes as Uint8Array),
|
|
242
|
-
network,
|
|
243
|
-
);
|
|
246
|
+
const p2trAddy: string | undefined = EcKeyPair.tweakedPubKeyBufferToAddress(this, network);
|
|
244
247
|
|
|
245
248
|
if (p2trAddy) {
|
|
246
249
|
this.#network = network;
|
package/src/keypair/EcKeyPair.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
2
2
|
import bip32, { BIP32API, BIP32Factory, BIP32Interface } from 'bip32';
|
|
3
|
-
import { address, initEccLib, Network, networks, payments, Signer } from '
|
|
4
|
-
import { toXOnly } from '
|
|
3
|
+
import { address, initEccLib, Network, networks, payments, Signer } from '@btc-vision/bitcoin';
|
|
4
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
5
5
|
import { ECPairAPI, ECPairFactory, ECPairInterface } from 'ecpair';
|
|
6
6
|
import { IWallet } from './interfaces/IWallet.js';
|
|
7
|
-
import { CURVE, Point
|
|
8
|
-
import { taggedHash } from '
|
|
7
|
+
import { CURVE, ProjectivePoint as Point } from '@noble/secp256k1';
|
|
8
|
+
import { taggedHash } from '@btc-vision/bitcoin/src/crypto.js';
|
|
9
9
|
|
|
10
10
|
initEccLib(ecc);
|
|
11
11
|
|
|
12
12
|
const BIP32factory = typeof bip32 === 'function' ? bip32 : BIP32Factory;
|
|
13
|
-
|
|
14
13
|
if (!BIP32factory) {
|
|
15
14
|
throw new Error('Failed to load BIP32 library');
|
|
16
15
|
}
|
|
17
16
|
|
|
17
|
+
const mod = (a: bigint, b: bigint): bigint => {
|
|
18
|
+
const result = a % b;
|
|
19
|
+
return result >= 0n ? result : result + b;
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
/**
|
|
19
23
|
* Class for handling EC key pairs
|
|
20
24
|
* @class EcKeyPair
|
|
@@ -212,20 +216,24 @@ export class EcKeyPair {
|
|
|
212
216
|
|
|
213
217
|
/**
|
|
214
218
|
* Tweak a public key
|
|
215
|
-
* @param {string} compressedPubKeyHex - The compressed public key hex string
|
|
216
|
-
* @returns {
|
|
219
|
+
* @param {string | Buffer} compressedPubKeyHex - The compressed public key hex string
|
|
220
|
+
* @returns {Buffer} - The tweaked public key hex string
|
|
217
221
|
* @throws {Error} - If the public key cannot be tweaked
|
|
218
222
|
*/
|
|
219
|
-
public static tweakPublicKey(compressedPubKeyHex: string):
|
|
220
|
-
if (compressedPubKeyHex.startsWith('0x')) {
|
|
223
|
+
public static tweakPublicKey(compressedPubKeyHex: string | Buffer): Buffer {
|
|
224
|
+
if (typeof compressedPubKeyHex === 'string' && compressedPubKeyHex.startsWith('0x')) {
|
|
221
225
|
compressedPubKeyHex = compressedPubKeyHex.slice(2);
|
|
222
226
|
}
|
|
223
227
|
|
|
228
|
+
if (typeof compressedPubKeyHex !== 'string') {
|
|
229
|
+
compressedPubKeyHex = compressedPubKeyHex.toString('hex');
|
|
230
|
+
}
|
|
231
|
+
|
|
224
232
|
// Convert the compressed public key hex string to a Point on the curve
|
|
225
233
|
let P = Point.fromHex(compressedPubKeyHex);
|
|
226
234
|
|
|
227
235
|
// Ensure the point has an even y-coordinate
|
|
228
|
-
if (
|
|
236
|
+
if ((P.y & 1n) !== 0n) {
|
|
229
237
|
// Negate the point to get an even y-coordinate
|
|
230
238
|
P = P.negate();
|
|
231
239
|
}
|
|
@@ -235,13 +243,13 @@ export class EcKeyPair {
|
|
|
235
243
|
|
|
236
244
|
// Compute the tweak t = H_tapTweak(x)
|
|
237
245
|
const tHash = taggedHash('TapTweak', Buffer.from(x));
|
|
238
|
-
const t =
|
|
246
|
+
const t = mod(BigInt('0x' + Buffer.from(tHash).toString('hex')), CURVE.n);
|
|
239
247
|
|
|
240
248
|
// Compute Q = P + t*G (where G is the generator point)
|
|
241
|
-
const Q = P.add(Point.BASE.
|
|
249
|
+
const Q = P.add(Point.BASE.mul(t));
|
|
242
250
|
|
|
243
251
|
// Return the tweaked public key in compressed form (hex string)
|
|
244
|
-
return Q.
|
|
252
|
+
return Buffer.from(Q.toRawBytes(true));
|
|
245
253
|
}
|
|
246
254
|
|
|
247
255
|
/**
|
|
@@ -417,6 +425,6 @@ export class EcKeyPair {
|
|
|
417
425
|
const privKey = fromSeed.privateKey;
|
|
418
426
|
if (!privKey) throw new Error('Failed to generate key pair');
|
|
419
427
|
|
|
420
|
-
return this.ECPair.fromPrivateKey(privKey, { network });
|
|
428
|
+
return this.ECPair.fromPrivateKey(Buffer.from(privKey), { network });
|
|
421
429
|
}
|
|
422
430
|
}
|
package/src/keypair/Wallet.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IWallet } from './interfaces/IWallet.js';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { EcKeyPair } from './EcKeyPair.js';
|
|
4
|
-
import { Network, networks } from '
|
|
5
|
-
import { toXOnly } from '
|
|
4
|
+
import { Network, networks } from '@btc-vision/bitcoin';
|
|
5
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
6
6
|
import { Address } from './Address.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -68,10 +68,7 @@ export class Wallet {
|
|
|
68
68
|
this._legacy = EcKeyPair.getLegacyAddress(this._keypair, this.network);
|
|
69
69
|
this._segwitLegacy = EcKeyPair.getLegacySegwitAddress(this._keypair, this.network);
|
|
70
70
|
|
|
71
|
-
this._tweakedKey =
|
|
72
|
-
EcKeyPair.tweakPublicKey(this._keypair.publicKey.toString('hex')),
|
|
73
|
-
'hex',
|
|
74
|
-
);
|
|
71
|
+
this._tweakedKey = EcKeyPair.tweakPublicKey(this._keypair.publicKey.toString('hex'));
|
|
75
72
|
|
|
76
73
|
this._bufferPubKey = this._keypair.publicKey;
|
|
77
74
|
this._address = new Address(this._keypair.publicKey);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Network, networks } from '
|
|
1
|
+
import { Network, networks } from '@btc-vision/bitcoin';
|
|
2
2
|
import { ChainId } from '../../network/ChainId.js';
|
|
3
3
|
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
4
4
|
import { WBTC_ADDRESS_FRACTAL, WBTC_ADDRESS_REGTEST, WBTC_ADDRESS_TESTNET } from '../tokens.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
2
|
-
import { initEccLib, Network, Signer } from '
|
|
3
|
-
import { tapTweakHash } from '
|
|
4
|
-
import { toXOnly } from '
|
|
2
|
+
import { initEccLib, Network, Signer } from '@btc-vision/bitcoin';
|
|
3
|
+
import { tapTweakHash } from '@btc-vision/bitcoin/src/payments/bip341.js';
|
|
4
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
5
5
|
import { ECPairInterface } from 'ecpair';
|
|
6
6
|
import { EcKeyPair } from '../keypair/EcKeyPair.js';
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Psbt, Transaction } from '
|
|
2
|
-
import { Output } from '
|
|
1
|
+
import { Psbt, Transaction } from '@btc-vision/bitcoin';
|
|
2
|
+
import { Output } from '@btc-vision/bitcoin/src/transaction.js';
|
|
3
3
|
import { currentConsensus, currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
4
4
|
import { wBTC } from '../metadata/contracts/wBTC.js';
|
|
5
5
|
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Network, networks, Psbt, TapScriptSig } from '
|
|
1
|
+
import { Network, networks, Psbt, TapScriptSig } from '@btc-vision/bitcoin';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
|
|
4
4
|
import { CustomKeypair } from '../BrowserSignerBase.js';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Taptree } from '
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
4
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
|
-
import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer, Stack } from '
|
|
5
|
+
import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer, Stack } from '@btc-vision/bitcoin';
|
|
6
6
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
7
7
|
import { CustomGenerator } from '../../generators/builders/CustomGenerator.js';
|
|
8
8
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
9
9
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
10
10
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
11
|
-
import { toXOnly } from '
|
|
11
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
12
12
|
import { ECPairInterface } from 'ecpair';
|
|
13
13
|
|
|
14
14
|
export interface ICustomTransactionParameters extends SharedInteractionParameters {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
2
|
import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
|
-
import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer } from '
|
|
3
|
+
import { crypto as bitCrypto, Payment, Psbt, PsbtInput, Signer } from '@btc-vision/bitcoin';
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
|
-
import { Taptree } from '
|
|
5
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
6
6
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
7
7
|
import { DeploymentGenerator } from '../../generators/builders/DeploymentGenerator.js';
|
|
8
|
-
import { toXOnly } from '
|
|
8
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
9
9
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
10
10
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
11
11
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
2
|
import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
|
-
import { Signer } from '
|
|
3
|
+
import { Signer } from '@btc-vision/bitcoin';
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
5
|
import { ECPairInterface } from 'ecpair';
|
|
6
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Taptree } from '
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
4
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
script,
|
|
10
10
|
Signer,
|
|
11
11
|
TapScriptSig,
|
|
12
|
-
} from '
|
|
13
|
-
import { Taptree } from '
|
|
12
|
+
} from '@btc-vision/bitcoin';
|
|
13
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
14
14
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
15
15
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
16
16
|
import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
17
17
|
import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
|
|
18
18
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
19
|
-
import { toXOnly } from '
|
|
19
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
20
20
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
21
21
|
import { ECPairInterface } from 'ecpair';
|
|
22
22
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { address, Payment, Psbt, PsbtInput, Signer } from '
|
|
2
|
-
import { Taptree } from '
|
|
1
|
+
import { address, Payment, Psbt, PsbtInput, Signer } from '@btc-vision/bitcoin';
|
|
2
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
3
3
|
import { ECPairInterface } from 'ecpair';
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
5
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -8,7 +8,7 @@ import { SharedInteractionParameters } from '../interfaces/ITransactionParameter
|
|
|
8
8
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
9
9
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
10
10
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
11
|
-
import { toXOnly } from '
|
|
11
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Shared interaction transaction
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
script,
|
|
9
9
|
Signer,
|
|
10
10
|
Transaction,
|
|
11
|
-
} from '
|
|
12
|
-
import { varuint } from '
|
|
11
|
+
} from '@btc-vision/bitcoin';
|
|
12
|
+
import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
|
|
13
13
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
14
14
|
import { UpdateInput } from '../interfaces/Tap.js';
|
|
15
15
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Taptree } from '
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
4
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
5
5
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
6
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
7
|
-
import { payments, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer } from '
|
|
7
|
+
import { payments, Psbt, PsbtInputExtended, PsbtOutputExtended, Signer } from '@btc-vision/bitcoin';
|
|
8
8
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
9
9
|
import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
10
10
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Taptree } from '
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { IUnwrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
4
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
PsbtInput,
|
|
13
13
|
PsbtInputExtended,
|
|
14
14
|
PsbtOutputExtended,
|
|
15
|
-
} from '
|
|
15
|
+
} from '@btc-vision/bitcoin';
|
|
16
16
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
17
17
|
import { IWBTCUTXODocument, PsbtTransaction, VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
18
18
|
import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
|
|
19
19
|
import { MultiSignTransaction } from './MultiSignTransaction.js';
|
|
20
|
-
import { toXOnly } from '
|
|
20
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
21
21
|
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
22
22
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
23
23
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Taptree } from '
|
|
1
|
+
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
2
2
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
3
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
4
|
import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
@@ -6,7 +6,7 @@ import { SharedInteractionTransaction } from './SharedInteractionTransaction.js'
|
|
|
6
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
7
7
|
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
8
8
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
9
|
-
import { Network, PsbtOutputExtendedAddress } from '
|
|
9
|
+
import { Network, PsbtOutputExtendedAddress } from '@btc-vision/bitcoin';
|
|
10
10
|
import { P2TR_MS } from '../shared/P2TR_MS.js';
|
|
11
11
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
12
12
|
import { Selector } from '../../utils/types.js';
|
|
@@ -4,7 +4,7 @@ import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
|
4
4
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
5
5
|
import { ChainId } from '../../network/ChainId.js';
|
|
6
6
|
import { Address } from '../../keypair/Address.js';
|
|
7
|
-
import { PsbtOutputExtended } from '
|
|
7
|
+
import { PsbtOutputExtended } from '@btc-vision/bitcoin';
|
|
8
8
|
|
|
9
9
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
10
10
|
readonly from?: string;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
PsbtOutputExtended,
|
|
6
6
|
Signer,
|
|
7
7
|
Transaction,
|
|
8
|
-
} from '
|
|
8
|
+
} from '@btc-vision/bitcoin';
|
|
9
9
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
10
10
|
|
|
11
11
|
export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
@@ -13,15 +13,15 @@ import {
|
|
|
13
13
|
script,
|
|
14
14
|
Signer,
|
|
15
15
|
Transaction,
|
|
16
|
-
} from '
|
|
16
|
+
} from '@btc-vision/bitcoin';
|
|
17
17
|
import { TweakedSigner, TweakSettings } from '../../signer/TweakedSigner.js';
|
|
18
18
|
import { ECPairInterface } from 'ecpair';
|
|
19
|
-
import { toXOnly } from '
|
|
19
|
+
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
20
20
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
21
21
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
22
22
|
import { AddressTypes, AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
23
23
|
import { ChainId } from '../../network/ChainId.js';
|
|
24
|
-
import { varuint } from '
|
|
24
|
+
import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
|
|
25
25
|
|
|
26
26
|
export interface ITweakedTransactionData {
|
|
27
27
|
readonly signer: Signer | ECPairInterface;
|
|
@@ -37,13 +37,9 @@ export class BitcoinUtils {
|
|
|
37
37
|
|
|
38
38
|
return Buffer.from(array);
|
|
39
39
|
} else {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
randomValues.push(Math.floor(Math.random() * 256));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return Buffer.from(randomValues);
|
|
40
|
+
throw new Error(
|
|
41
|
+
'No secure random number generator available. Please upgrade your environment.',
|
|
42
|
+
);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|