@btc-vision/transaction 1.0.112 → 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 +15 -4
- package/browser/keypair/EcKeyPair.d.ts +15 -12
- package/browser/keypair/Wallet.d.ts +12 -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/signer/TweakedSigner.d.ts +2 -2
- 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/FundingTransaction.d.ts +2 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +6 -7
- 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/transaction/shared/TweakedTransaction.d.ts +8 -7
- 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 +15 -4
- package/build/keypair/AddressVerificator.js +79 -3
- package/build/keypair/EcKeyPair.d.ts +15 -12
- package/build/keypair/EcKeyPair.js +61 -9
- package/build/keypair/Wallet.d.ts +12 -5
- package/build/keypair/Wallet.js +19 -5
- 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/signer/TweakedSigner.d.ts +2 -2
- package/build/signer/TweakedSigner.js +1 -1
- 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/CustomScriptTransaction.js +3 -3
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +10 -6
- package/build/transaction/builders/FundingTransaction.d.ts +2 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
- package/build/transaction/builders/TransactionBuilder.d.ts +6 -7
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +4 -3
- 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/transaction/shared/TweakedTransaction.d.ts +8 -7
- package/build/transaction/shared/TweakedTransaction.js +1 -1
- 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 +4 -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 +149 -6
- package/src/keypair/EcKeyPair.ts +146 -47
- package/src/keypair/Wallet.ts +72 -15
- 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/signer/TweakedSigner.ts +3 -2
- 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 +10 -10
- package/src/transaction/builders/DeploymentTransaction.ts +23 -9
- package/src/transaction/builders/FundingTransaction.ts +2 -1
- package/src/transaction/builders/MultiSignTransaction.ts +10 -7
- package/src/transaction/builders/SharedInteractionTransaction.ts +5 -5
- package/src/transaction/builders/TransactionBuilder.ts +26 -17
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +10 -4
- package/src/transaction/builders/UnwrapTransaction.ts +5 -19
- package/src/transaction/builders/WrapTransaction.ts +7 -13
- 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/transaction/shared/TweakedTransaction.ts +12 -12
- 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
|
@@ -3,7 +3,6 @@ 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
|
-
import { ABICoder, BinaryWriter, Selector } from '@btc-vision/bsi-binary';
|
|
7
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
8
7
|
import { Network, Payment, payments, Psbt } from 'bitcoinjs-lib';
|
|
9
8
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
@@ -17,6 +16,9 @@ import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
|
17
16
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
18
17
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
19
18
|
import { Features } from '../../generators/Features.js';
|
|
19
|
+
import { ABICoder } from '../../abi/ABICoder.js';
|
|
20
|
+
import { Selector } from '../../utils/types.js';
|
|
21
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
20
22
|
|
|
21
23
|
const abiCoder: ABICoder = new ABICoder();
|
|
22
24
|
const numsPoint: Buffer = Buffer.from(
|
|
@@ -109,7 +111,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
109
111
|
this.contractSecret = this.generateSecret();
|
|
110
112
|
|
|
111
113
|
this.calldataGenerator = new CalldataGenerator(
|
|
112
|
-
this.signer.publicKey,
|
|
114
|
+
Buffer.from(this.signer.publicKey),
|
|
113
115
|
this.scriptSignerXOnlyPubKey(),
|
|
114
116
|
this.network,
|
|
115
117
|
);
|
|
@@ -140,22 +142,6 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
140
142
|
return Buffer.from(bufWriter.getBuffer());
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
/*public tweakScalarPoints(): Uint8Array {
|
|
144
|
-
const key: Uint8Array = (this.signer as ECPairInterface).privateKey as Uint8Array;
|
|
145
|
-
//const r = bitcoin.crypto.sha256(Buffer.from('WTF_IS_OP_NET!', 'utf-8'));
|
|
146
|
-
const rG = ecc.pointMultiply(
|
|
147
|
-
Buffer.from(this.internalPubKeyToXOnly()), //EcKeyPair.fromPrivateKey(r).publicKey.subarray(1)
|
|
148
|
-
key,
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (!rG) throw new Error('Failed to tweak rG');
|
|
152
|
-
|
|
153
|
-
const tweaked = ecc.pointAdd(this.numsPoint, rG);
|
|
154
|
-
if (!tweaked) throw new Error('Failed to tweak rG');
|
|
155
|
-
|
|
156
|
-
return Buffer.from(tweaked);
|
|
157
|
-
}*/
|
|
158
|
-
|
|
159
145
|
/**
|
|
160
146
|
* @description Signs the transaction
|
|
161
147
|
* @public
|
|
@@ -372,7 +358,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
372
358
|
|
|
373
359
|
return [
|
|
374
360
|
this.contractSecret,
|
|
375
|
-
toXOnly(this.signer.publicKey),
|
|
361
|
+
toXOnly(Buffer.from(this.signer.publicKey)),
|
|
376
362
|
input.tapScriptSig[0].signature,
|
|
377
363
|
input.tapScriptSig[1].signature,
|
|
378
364
|
];
|
|
@@ -4,15 +4,15 @@ import { PsbtOutputExtendedAddress, TapLeafScript } from '../interfaces/Tap.js';
|
|
|
4
4
|
import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
5
|
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
6
6
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
7
|
-
import { ABICoder, Address, BinaryWriter, Selector } from '@btc-vision/bsi-binary';
|
|
8
|
-
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
9
|
-
import { ECPairInterface } from 'ecpair';
|
|
10
7
|
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
11
8
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
12
|
-
import { AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
13
9
|
import { Network } from 'bitcoinjs-lib';
|
|
14
10
|
import { P2TR_MS } from '../shared/P2TR_MS.js';
|
|
15
11
|
import { currentConsensusConfig } from '../../consensus/ConsensusConfig.js';
|
|
12
|
+
import { Selector } from '../../utils/types.js';
|
|
13
|
+
import { ABICoder } from '../../abi/ABICoder.js';
|
|
14
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
15
|
+
import { Address } from '../../keypair/Address.js';
|
|
16
16
|
|
|
17
17
|
const abiCoder: ABICoder = new ABICoder();
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
32
32
|
* @private
|
|
33
33
|
* @readonly
|
|
34
34
|
*/
|
|
35
|
-
public readonly vault:
|
|
35
|
+
public readonly vault: string;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* The amount to wrap
|
|
@@ -92,13 +92,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const receiver: Address =
|
|
96
|
-
parameters.receiver ||
|
|
97
|
-
TransactionBuilder.getFrom(
|
|
98
|
-
parameters.from,
|
|
99
|
-
parameters.signer as ECPairInterface,
|
|
100
|
-
parameters.network,
|
|
101
|
-
);
|
|
95
|
+
const receiver: Address = parameters.receiver || new Address(parameters.signer.publicKey);
|
|
102
96
|
|
|
103
97
|
parameters.calldata = WrapTransaction.generateMintCalldata(
|
|
104
98
|
parameters.amount,
|
|
@@ -151,7 +145,7 @@ export class WrapTransaction extends SharedInteractionTransaction<TransactionTyp
|
|
|
151
145
|
if (!amount) throw new Error('Amount is required');
|
|
152
146
|
if (!to) throw new Error('To address is required');
|
|
153
147
|
|
|
154
|
-
if (!
|
|
148
|
+
if (!to.isValid(network)) {
|
|
155
149
|
throw new Error(
|
|
156
150
|
`Oops! The address ${to} is not a valid P2TR address! If you wrap at this address, your funds will be lost!`,
|
|
157
151
|
);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
4
3
|
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
4
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
5
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
6
|
import { PsbtOutputExtended } from './Tap.js';
|
|
7
|
+
import { Address } from '../../keypair/Address.js';
|
|
8
8
|
|
|
9
9
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
10
|
-
readonly from?:
|
|
11
|
-
readonly to?:
|
|
10
|
+
readonly from?: string;
|
|
11
|
+
readonly to?: string;
|
|
12
|
+
|
|
12
13
|
utxos: UTXO[];
|
|
13
14
|
|
|
14
15
|
nonWitnessUtxo?: Buffer;
|
|
@@ -39,13 +40,13 @@ export interface IInteractionParameters
|
|
|
39
40
|
extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
40
41
|
readonly calldata: Buffer;
|
|
41
42
|
|
|
42
|
-
readonly to:
|
|
43
|
+
readonly to: string;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
|
|
46
|
-
readonly to?:
|
|
47
|
+
readonly to?: string;
|
|
48
|
+
readonly from: string;
|
|
47
49
|
|
|
48
|
-
readonly from: Address;
|
|
49
50
|
readonly amount: bigint;
|
|
50
51
|
readonly receiver?: Address;
|
|
51
52
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { Network, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
|
|
3
2
|
import { PsbtInputExtended, PsbtOutputExtended } from '../interfaces/Tap.js';
|
|
4
3
|
import { ITweakedTransactionData, TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
@@ -10,7 +9,7 @@ export interface PsbtTransactionData extends ITweakedTransactionData {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export interface IWBTCUTXODocument {
|
|
13
|
-
readonly vault:
|
|
12
|
+
readonly vault: string;
|
|
14
13
|
readonly blockId: bigint;
|
|
15
14
|
|
|
16
15
|
readonly hash: string;
|
|
@@ -21,8 +20,8 @@ export interface IWBTCUTXODocument {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export interface VaultUTXOs {
|
|
24
|
-
readonly vault:
|
|
25
|
-
readonly publicKeys:
|
|
23
|
+
readonly vault: string;
|
|
24
|
+
readonly publicKeys: string[];
|
|
26
25
|
readonly minimum: number;
|
|
27
26
|
readonly utxos: IWBTCUTXODocument[];
|
|
28
27
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Network, networks } from 'bitcoinjs-lib';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
4
3
|
import { MultiSignParameters, MultiSignTransaction } from '../builders/MultiSignTransaction.js';
|
|
5
4
|
|
|
@@ -9,14 +8,14 @@ export class P2TR_MS {
|
|
|
9
8
|
* @param {Buffer[]} pubKeys - The public keys to use
|
|
10
9
|
* @param {number} minimumSignatureRequired - The minimum number of signatures required
|
|
11
10
|
* @param {Network} network - The network to use
|
|
12
|
-
* @returns {
|
|
11
|
+
* @returns {string} - The generated address
|
|
13
12
|
* @throws {Error} - If the address cannot be generated
|
|
14
13
|
*/
|
|
15
14
|
public static generateMultiSigAddress(
|
|
16
15
|
pubKeys: Buffer[],
|
|
17
16
|
minimumSignatureRequired: number,
|
|
18
17
|
network: Network = networks.bitcoin,
|
|
19
|
-
):
|
|
18
|
+
): string {
|
|
20
19
|
const publicKeys: Buffer[] = EcKeyPair.verifyPubKeys(pubKeys, network);
|
|
21
20
|
if (publicKeys.length !== pubKeys.length) throw new Error(`Contains invalid public keys`);
|
|
22
21
|
|
|
@@ -11,7 +11,7 @@ import { ChainId } from '../../network/ChainId.js';
|
|
|
11
11
|
import { varuint } from 'bitcoinjs-lib/src/bufferutils.js';
|
|
12
12
|
|
|
13
13
|
export interface ITweakedTransactionData {
|
|
14
|
-
readonly signer: Signer;
|
|
14
|
+
readonly signer: Signer | ECPairInterface;
|
|
15
15
|
readonly network: Network;
|
|
16
16
|
readonly chainId?: ChainId;
|
|
17
17
|
readonly nonWitnessUtxo?: Buffer;
|
|
@@ -34,11 +34,11 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
34
34
|
/**
|
|
35
35
|
* @description Was the transaction signed?
|
|
36
36
|
*/
|
|
37
|
-
protected signer: Signer;
|
|
37
|
+
protected signer: Signer | ECPairInterface;
|
|
38
38
|
/**
|
|
39
39
|
* @description Tweaked signer
|
|
40
40
|
*/
|
|
41
|
-
protected tweakedSigner?:
|
|
41
|
+
protected tweakedSigner?: ECPairInterface;
|
|
42
42
|
/**
|
|
43
43
|
* @description The network of the transaction
|
|
44
44
|
*/
|
|
@@ -190,7 +190,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
190
190
|
transaction: Psbt,
|
|
191
191
|
input: PsbtInput,
|
|
192
192
|
i: number,
|
|
193
|
-
signer: Signer,
|
|
193
|
+
signer: Signer | ECPairInterface,
|
|
194
194
|
sighashTypes: number[],
|
|
195
195
|
): void {
|
|
196
196
|
if (sighashTypes && sighashTypes[0]) input.sighashType = sighashTypes[0];
|
|
@@ -336,9 +336,9 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
336
336
|
/**
|
|
337
337
|
* Returns the signer key.
|
|
338
338
|
* @protected
|
|
339
|
-
* @returns {Signer}
|
|
339
|
+
* @returns {Signer | ECPairInterface}
|
|
340
340
|
*/
|
|
341
|
-
protected getSignerKey(): Signer {
|
|
341
|
+
protected getSignerKey(): Signer | ECPairInterface {
|
|
342
342
|
return this.signer;
|
|
343
343
|
}
|
|
344
344
|
|
|
@@ -354,7 +354,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
354
354
|
transaction: Psbt,
|
|
355
355
|
input: PsbtInput,
|
|
356
356
|
i: number,
|
|
357
|
-
signer?: Signer,
|
|
357
|
+
signer?: Signer | ECPairInterface,
|
|
358
358
|
): Promise<void> {
|
|
359
359
|
const signHash =
|
|
360
360
|
this.sighashTypes && this.sighashTypes.length
|
|
@@ -367,7 +367,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
367
367
|
if (input.tapInternalKey) {
|
|
368
368
|
if (!this.tweakedSigner) this.tweakSigner();
|
|
369
369
|
|
|
370
|
-
let tweakedSigner:
|
|
370
|
+
let tweakedSigner: ECPairInterface | undefined;
|
|
371
371
|
if (signer !== this.signer) {
|
|
372
372
|
tweakedSigner = this.getTweakedSigner(true, signer);
|
|
373
373
|
} else {
|
|
@@ -481,7 +481,7 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
481
481
|
* @returns {Buffer}
|
|
482
482
|
*/
|
|
483
483
|
protected internalPubKeyToXOnly(): Buffer {
|
|
484
|
-
return toXOnly(this.signer.publicKey);
|
|
484
|
+
return toXOnly(Buffer.from(this.signer.publicKey));
|
|
485
485
|
}
|
|
486
486
|
|
|
487
487
|
/**
|
|
@@ -507,12 +507,12 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
507
507
|
/**
|
|
508
508
|
* Get the tweaked signer
|
|
509
509
|
* @private
|
|
510
|
-
* @returns {
|
|
510
|
+
* @returns {ECPairInterface} The tweaked signer
|
|
511
511
|
*/
|
|
512
512
|
protected getTweakedSigner(
|
|
513
513
|
useTweakedHash: boolean = false,
|
|
514
|
-
signer: Signer = this.signer,
|
|
515
|
-
):
|
|
514
|
+
signer: Signer | ECPairInterface = this.signer,
|
|
515
|
+
): ECPairInterface | undefined {
|
|
516
516
|
const settings: TweakSettings = {
|
|
517
517
|
network: this.network,
|
|
518
518
|
};
|
|
@@ -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(
|