@btc-vision/transaction 1.0.113 → 1.0.114
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/abi/ABICoder.d.ts +31 -0
- package/browser/buffer/BinaryReader.d.ts +37 -0
- package/browser/buffer/BinaryWriter.d.ts +46 -0
- package/browser/deterministic/AddressMap.d.ts +10 -0
- package/browser/deterministic/AddressSet.d.ts +13 -0
- package/browser/deterministic/DeterministicMap.d.ts +17 -0
- package/browser/deterministic/DeterministicSet.d.ts +13 -0
- package/browser/deterministic/Map.d.ts +14 -0
- package/browser/event/NetEvent.d.ts +5 -0
- package/browser/generators/AddressGenerator.d.ts +3 -0
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +23 -0
- package/browser/keypair/AddressVerificator.d.ts +1 -2
- package/browser/keypair/EcKeyPair.d.ts +9 -9
- package/browser/keypair/Wallet.d.ts +11 -5
- package/browser/metadata/ContractBaseMetadata.d.ts +3 -4
- package/browser/metadata/contracts/wBTC.d.ts +2 -3
- package/browser/metadata/tokens.d.ts +1 -1
- package/browser/opnet.d.ts +11 -0
- package/browser/transaction/TransactionFactory.d.ts +6 -6
- package/browser/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/browser/transaction/browser/types/Unisat.d.ts +2 -3
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/browser/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/browser/transaction/builders/MultiSignTransaction.d.ts +4 -5
- package/browser/transaction/builders/TransactionBuilder.d.ts +5 -6
- package/browser/transaction/builders/WrapTransaction.d.ts +2 -2
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/browser/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -2
- package/browser/utils/BufferHelper.d.ts +11 -0
- package/browser/utils/types.d.ts +12 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +31 -0
- package/build/abi/ABICoder.js +137 -0
- package/build/buffer/BinaryReader.d.ts +37 -0
- package/build/buffer/BinaryReader.js +192 -0
- package/build/buffer/BinaryWriter.d.ts +46 -0
- package/build/buffer/BinaryWriter.js +258 -0
- package/build/deterministic/AddressMap.d.ts +10 -0
- package/build/deterministic/AddressMap.js +46 -0
- package/build/deterministic/AddressSet.d.ts +13 -0
- package/build/deterministic/AddressSet.js +44 -0
- package/build/deterministic/DeterministicMap.d.ts +17 -0
- package/build/deterministic/DeterministicMap.js +83 -0
- package/build/deterministic/DeterministicSet.d.ts +13 -0
- package/build/deterministic/DeterministicSet.js +46 -0
- package/build/deterministic/Map.d.ts +14 -0
- package/build/deterministic/Map.js +56 -0
- package/build/event/NetEvent.d.ts +5 -0
- package/build/event/NetEvent.js +6 -0
- package/build/generators/AddressGenerator.d.ts +3 -0
- package/build/generators/AddressGenerator.js +8 -1
- package/build/keypair/Address.d.ts +23 -0
- package/build/keypair/Address.js +129 -0
- package/build/keypair/AddressVerificator.d.ts +1 -2
- package/build/keypair/AddressVerificator.js +7 -2
- package/build/keypair/EcKeyPair.d.ts +9 -9
- package/build/keypair/EcKeyPair.js +9 -2
- package/build/keypair/Wallet.d.ts +11 -5
- package/build/keypair/Wallet.js +14 -1
- package/build/metadata/ContractBaseMetadata.d.ts +3 -4
- package/build/metadata/contracts/wBTC.d.ts +2 -3
- package/build/metadata/contracts/wBTC.js +4 -6
- package/build/metadata/tokens.d.ts +1 -1
- package/build/metadata/tokens.js +19 -15
- package/build/opnet.d.ts +11 -0
- package/build/opnet.js +11 -0
- package/build/transaction/TransactionFactory.d.ts +6 -6
- package/build/transaction/TransactionFactory.js +3 -2
- package/build/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/build/transaction/browser/types/Unisat.d.ts +2 -3
- package/build/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +6 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +4 -5
- package/build/transaction/builders/TransactionBuilder.d.ts +5 -6
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +2 -1
- package/build/transaction/builders/WrapTransaction.d.ts +2 -2
- package/build/transaction/builders/WrapTransaction.js +5 -6
- package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/build/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/build/transaction/shared/P2TR_MS.d.ts +1 -2
- package/build/utils/BufferHelper.d.ts +11 -0
- package/build/utils/BufferHelper.js +50 -0
- package/build/utils/types.d.ts +12 -0
- package/build/utils/types.js +1 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/utxo/OPNetLimitedProvider.js +1 -1
- package/build/verification/TapscriptVerificator.js +3 -2
- package/package.json +3 -2
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +158 -0
- package/src/buffer/BinaryReader.ts +260 -0
- package/src/buffer/BinaryWriter.ts +331 -0
- package/src/deterministic/AddressMap.ts +57 -0
- package/src/deterministic/AddressSet.ts +62 -0
- package/src/deterministic/DeterministicMap.ts +88 -0
- package/src/deterministic/DeterministicSet.ts +56 -0
- package/src/deterministic/Map.ts +66 -0
- package/src/event/NetEvent.ts +6 -0
- package/src/generators/AddressGenerator.ts +15 -1
- package/src/keypair/Address.ts +235 -0
- package/src/keypair/AddressVerificator.ts +9 -5
- package/src/keypair/EcKeyPair.ts +39 -37
- package/src/keypair/Wallet.ts +61 -12
- package/src/metadata/ContractBaseMetadata.ts +3 -4
- package/src/metadata/contracts/wBTC.ts +8 -9
- package/src/metadata/tokens.ts +21 -16
- package/src/opnet.ts +13 -0
- package/src/transaction/TransactionFactory.ts +11 -10
- package/src/transaction/browser/BrowserSignerBase.ts +3 -4
- package/src/transaction/browser/extensions/UnisatSigner.ts +6 -7
- package/src/transaction/browser/types/Unisat.ts +2 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +4 -5
- package/src/transaction/builders/DeploymentTransaction.ts +17 -4
- package/src/transaction/builders/MultiSignTransaction.ts +4 -5
- package/src/transaction/builders/TransactionBuilder.ts +8 -9
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +3 -1
- package/src/transaction/builders/UnwrapTransaction.ts +3 -17
- package/src/transaction/builders/WrapTransaction.ts +7 -8
- package/src/transaction/interfaces/ITransactionParameters.ts +7 -6
- package/src/transaction/processor/PsbtTransaction.ts +3 -4
- package/src/transaction/shared/P2TR_MS.ts +2 -3
- package/src/utils/BufferHelper.ts +71 -0
- package/src/utils/types.ts +19 -0
- package/src/utxo/OPNetLimitedProvider.ts +3 -8
- package/src/verification/TapscriptVerificator.ts +4 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { MemorySlotPointer } from './types.js';
|
|
2
|
+
|
|
3
|
+
export class BufferHelper {
|
|
4
|
+
public static readonly EXPECTED_BUFFER_LENGTH: number = 32;
|
|
5
|
+
|
|
6
|
+
public static bufferToUint8Array(buffer: Buffer | Uint8Array): Uint8Array {
|
|
7
|
+
if (Buffer.isBuffer(buffer)) {
|
|
8
|
+
const length: number = buffer.byteLength;
|
|
9
|
+
const arrayBuffer: ArrayBuffer = new ArrayBuffer(length);
|
|
10
|
+
|
|
11
|
+
const view: Uint8Array = new Uint8Array(arrayBuffer);
|
|
12
|
+
for (let i = 0; i < length; ++i) {
|
|
13
|
+
view[i] = buffer[i];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return view;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return buffer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static uint8ArrayToHex(input: Uint8Array): string {
|
|
23
|
+
return Buffer.from(input, 0, input.byteLength).toString('hex');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static hexToUint8Array(input: string): Uint8Array {
|
|
27
|
+
if (input.startsWith('0x')) {
|
|
28
|
+
input = input.substring(2); // Remove the '0x' prefix
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (input.length % 2 !== 0) {
|
|
32
|
+
input = '0' + input; // Pad with a leading zero if the length is odd
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const length = input.length / 2;
|
|
36
|
+
const buffer = new Uint8Array(length);
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < length; i++) {
|
|
39
|
+
// Use substring(i * 2, i * 2 + 2) to replace substr(i * 2, 2)
|
|
40
|
+
buffer[i] = parseInt(input.substring(i * 2, i * 2 + 2), 16);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return buffer;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static pointerToUint8Array(pointer: MemorySlotPointer): Uint8Array {
|
|
47
|
+
const pointerHex = pointer.toString(16).padStart(64, '0');
|
|
48
|
+
|
|
49
|
+
return BufferHelper.hexToUint8Array(pointerHex);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static uint8ArrayToPointer(input: Uint8Array): MemorySlotPointer {
|
|
53
|
+
const hex = BufferHelper.uint8ArrayToHex(input);
|
|
54
|
+
|
|
55
|
+
return BigInt('0x' + hex);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public static valueToUint8Array(value: bigint): Uint8Array {
|
|
59
|
+
const valueHex = value.toString(16).padStart(64, '0');
|
|
60
|
+
|
|
61
|
+
return BufferHelper.hexToUint8Array(valueHex);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static uint8ArrayToValue(input: Uint8Array): bigint {
|
|
65
|
+
const hex = BufferHelper.uint8ArrayToHex(input);
|
|
66
|
+
|
|
67
|
+
if (!hex) return BigInt(0);
|
|
68
|
+
|
|
69
|
+
return BigInt('0x' + hex);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DeterministicMap } from '../deterministic/DeterministicMap.js';
|
|
2
|
+
|
|
3
|
+
export const ADDRESS_BYTE_LENGTH: number = 32;
|
|
4
|
+
|
|
5
|
+
export type MemorySlotPointer = bigint;
|
|
6
|
+
|
|
7
|
+
export type BufferLike = Uint8Array | Buffer;
|
|
8
|
+
|
|
9
|
+
export type MemorySlotData<T> = T;
|
|
10
|
+
export type PointerStorage = DeterministicMap<MemorySlotPointer, MemorySlotData<bigint>>;
|
|
11
|
+
|
|
12
|
+
export type i32 = number;
|
|
13
|
+
export type u8 = number;
|
|
14
|
+
export type u16 = number;
|
|
15
|
+
export type u32 = number;
|
|
16
|
+
|
|
17
|
+
export type u64 = bigint;
|
|
18
|
+
|
|
19
|
+
export type Selector = number;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { Network } from 'bitcoinjs-lib';
|
|
3
2
|
import { currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
4
|
-
import { IFundingTransactionParameters, TransactionFactory, Wallet } from '../opnet.js';
|
|
3
|
+
import { Address, IFundingTransactionParameters, TransactionFactory, Wallet } from '../opnet.js';
|
|
5
4
|
import { UnwrappedGenerationParameters, WrappedGenerationParameters } from '../wbtc/Generate.js';
|
|
6
5
|
import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
|
|
7
6
|
import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
|
|
@@ -249,7 +248,6 @@ export class OPNetLimitedProvider {
|
|
|
249
248
|
|
|
250
249
|
const url: string = `${this.opnetAPIUrl}/api/v1/${this.rpc}`;
|
|
251
250
|
|
|
252
|
-
//try {
|
|
253
251
|
const resp: Response = await fetch(url, params);
|
|
254
252
|
if (!resp.ok) {
|
|
255
253
|
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
@@ -274,9 +272,6 @@ export class OPNetLimitedProvider {
|
|
|
274
272
|
}
|
|
275
273
|
|
|
276
274
|
return result;
|
|
277
|
-
//} catch (e) {
|
|
278
|
-
// throw e;
|
|
279
|
-
//}
|
|
280
275
|
}
|
|
281
276
|
|
|
282
277
|
/**
|
|
@@ -305,7 +300,7 @@ export class OPNetLimitedProvider {
|
|
|
305
300
|
/**
|
|
306
301
|
* Fetches the wrap parameters from the OPNET node
|
|
307
302
|
* @param {bigint} amount - The amount to wrap
|
|
308
|
-
* @param {
|
|
303
|
+
* @param {string} receiver - The receiver address
|
|
309
304
|
* @returns {Promise<UnwrapGeneration | undefined>} - The wrap parameters fetched
|
|
310
305
|
* @throws {Error} - If wrap parameters could not be fetched
|
|
311
306
|
*/
|
|
@@ -323,7 +318,7 @@ export class OPNetLimitedProvider {
|
|
|
323
318
|
throw new Error('Invalid receiver address');
|
|
324
319
|
}
|
|
325
320
|
|
|
326
|
-
const params = [1, amount.toString(), receiver];
|
|
321
|
+
const params = [1, amount.toString(), receiver.toHex()];
|
|
327
322
|
const result = await this.rpcMethod('btc_generate', params);
|
|
328
323
|
|
|
329
324
|
if (!result) {
|
|
@@ -3,7 +3,7 @@ import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
|
3
3
|
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
4
4
|
import { DeploymentGenerator } from '../generators/builders/DeploymentGenerator.js';
|
|
5
5
|
import { TransactionBuilder } from '../transaction/builders/TransactionBuilder.js';
|
|
6
|
-
import {
|
|
6
|
+
import { Address } from '../keypair/Address.js';
|
|
7
7
|
|
|
8
8
|
export interface ContractAddressVerificationParams {
|
|
9
9
|
readonly deployerPubKey: Buffer;
|
|
@@ -70,7 +70,9 @@ export class TapscriptVerificator {
|
|
|
70
70
|
saltHash,
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
const address = new Address(virtualAddress);
|
|
74
|
+
|
|
75
|
+
return address.p2tr(network);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
public static generateAddressFromScript(
|