@btc-vision/transaction 1.0.41 → 1.0.44
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/opnet.d.ts +3 -0
- package/browser/transaction/TransactionFactory.d.ts +3 -3
- package/browser/transaction/browser/BrowserSigner.d.ts +9 -0
- package/browser/transaction/browser/BrowserSignerBase.d.ts +18 -0
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +35 -0
- package/browser/transaction/browser/types/Unisat.d.ts +54 -0
- package/browser/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +4 -4
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/browser/transaction/builders/TransactionBuilder.d.ts +10 -9
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +3 -3
- 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 -0
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -4
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/contracts/wBTC.js +1 -1
- package/build/opnet.d.ts +3 -0
- package/build/opnet.js +3 -0
- package/build/tests/adaptPSBT.js +1 -1
- package/build/tests/deploy.js +1 -2
- package/build/tests/deployMotoRegStep1.d.ts +1 -0
- package/build/tests/deployMotoRegStep1.js +85 -0
- package/build/tests/deployReg.js +2 -2
- package/build/tests/factory/createPairReg.js +6 -77
- package/build/tests/gen.js +6 -17
- package/build/tests/interaction.d.ts +5 -0
- package/build/tests/interaction.js +62 -0
- package/build/tests/mineReg.js +1 -4
- package/build/tests/moto/airdropToken.d.ts +1 -0
- package/build/tests/moto/airdropToken.js +21 -0
- package/build/tests/moto/allowance.d.ts +1 -0
- package/build/tests/moto/allowance.js +5 -0
- package/build/tests/moto/approve.d.ts +1 -0
- package/build/tests/moto/approve.js +6 -0
- package/build/tests/moto/approveWBTC.d.ts +1 -0
- package/build/tests/moto/approveWBTC.js +12 -0
- package/build/tests/moto/balanceOf.d.ts +1 -0
- package/build/tests/moto/balanceOf.js +13 -0
- package/build/tests/motoswap/airdropToken.d.ts +11 -0
- package/build/tests/motoswap/airdropToken.js +36 -0
- package/build/tests/motoswap/deployMoto.d.ts +4 -0
- package/build/tests/motoswap/deployMoto.js +87 -0
- package/build/tests/motoswap/deployMotoRegStep1.d.ts +1 -0
- package/build/tests/motoswap/deployMotoRegStep1.js +91 -0
- package/build/tests/motoswap/deployMotoRegStep2.d.ts +1 -0
- package/build/tests/motoswap/deployMotoRegStep2.js +91 -0
- package/build/tests/motoswap/deployStep1.d.ts +1 -0
- package/build/tests/motoswap/deployStep1.js +5 -0
- package/build/tests/motoswap/deployStep2.d.ts +1 -0
- package/build/tests/motoswap/deployStep2.js +5 -0
- package/build/tests/motoswap/deployStep3.d.ts +1 -0
- package/build/tests/motoswap/deployStep3.js +5 -0
- package/build/tests/motoswap/interaction.d.ts +3 -0
- package/build/tests/motoswap/interaction.js +63 -0
- package/build/tests/motoswap/routerAddLiquidity.d.ts +11 -0
- package/build/tests/motoswap/routerAddLiquidity.js +36 -0
- package/build/tests/multisign.js +1 -1
- package/build/tests/shared/Utils.d.ts +2 -0
- package/build/tests/shared/Utils.js +9 -0
- package/build/tests/shared/interaction.d.ts +5 -0
- package/build/tests/shared/interaction.js +76 -0
- package/build/tests/shared/tokens.d.ts +6 -0
- package/build/tests/shared/tokens.js +5 -0
- package/build/tests/stakeReg.js +1 -1
- package/build/tests/test.js +1 -1
- package/build/tests/testReg.js +1 -1
- package/build/tests/tokens.d.ts +6 -0
- package/build/tests/tokens.js +5 -0
- package/build/tests/transfer.js +1 -1
- package/build/tests/wbtc/approve.d.ts +1 -0
- package/build/tests/wbtc/approve.js +6 -0
- package/build/tests/wbtc/approveWBTC.d.ts +1 -0
- package/build/tests/wbtc/approveWBTC.js +12 -0
- package/build/tests/wbtc/massWrapReg.d.ts +1 -0
- package/build/tests/wbtc/massWrapReg.js +105 -0
- package/build/tests/wbtc/transferReg.d.ts +1 -0
- package/build/tests/wbtc/transferReg.js +16 -0
- package/build/tests/wbtc/unStakeReg.d.ts +1 -0
- package/build/tests/wbtc/unStakeReg.js +72 -0
- package/build/tests/wbtc/unwrapReg.d.ts +1 -0
- package/build/tests/wbtc/unwrapReg.js +60 -0
- package/build/tests/wbtc/unwrapRegSegwit.d.ts +1 -0
- package/build/tests/wbtc/unwrapRegSegwit.js +83 -0
- package/build/tests/wbtc/withdrawalRequestReg.d.ts +1 -0
- package/build/tests/wbtc/withdrawalRequestReg.js +71 -0
- package/build/tests/wbtc/wrapReg.d.ts +1 -0
- package/build/tests/wbtc/wrapReg.js +69 -0
- package/build/tests/wbtc/wrapTest.d.ts +1 -0
- package/build/tests/wbtc/wrapTest.js +66 -0
- package/build/tests/writers/allowance.d.ts +3 -0
- package/build/tests/writers/allowance.js +10 -0
- package/build/tests/writers/approve.d.ts +4 -0
- package/build/tests/writers/approve.js +11 -0
- package/build/transaction/TransactionFactory.d.ts +3 -3
- package/build/transaction/TransactionFactory.js +41 -38
- package/build/transaction/browser/BrowserSigner.d.ts +11 -0
- package/build/transaction/browser/BrowserSigner.js +10 -0
- package/build/transaction/browser/BrowserSignerBase.d.ts +18 -0
- package/build/transaction/browser/BrowserSignerBase.js +3 -0
- package/build/transaction/browser/extensions/Unisat.d.ts +54 -0
- package/build/transaction/browser/extensions/Unisat.js +11 -0
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +35 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +150 -0
- package/build/transaction/browser/types/Unisat.d.ts +54 -0
- package/build/transaction/browser/types/Unisat.js +11 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/build/transaction/builders/DeploymentTransaction.js +4 -4
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/FundingTransaction.js +2 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +4 -4
- package/build/transaction/builders/MultiSignTransaction.js +7 -7
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.js +6 -6
- package/build/transaction/builders/TransactionBuilder.d.ts +10 -9
- package/build/transaction/builders/TransactionBuilder.js +29 -22
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +3 -3
- package/build/transaction/builders/UnwrapSegwitTransaction.js +10 -10
- package/build/transaction/builders/UnwrapTransaction.d.ts +2 -2
- package/build/transaction/builders/UnwrapTransaction.js +9 -6
- package/build/transaction/builders/WrapTransaction.d.ts +1 -1
- package/build/transaction/builders/WrapTransaction.js +2 -2
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/build/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/build/transaction/processor/PsbtTransaction.js +2 -2
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -4
- package/build/transaction/shared/TweakedTransaction.js +59 -23
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/metadata/contracts/wBTC.ts +1 -1
- package/src/opnet.ts +81 -76
- package/src/transaction/TransactionFactory.ts +52 -44
- package/src/transaction/browser/BrowserSignerBase.ts +44 -0
- package/src/transaction/browser/extensions/UnisatSigner.ts +218 -0
- package/src/transaction/browser/types/Unisat.ts +77 -0
- package/src/transaction/builders/DeploymentTransaction.ts +4 -4
- package/src/transaction/builders/FundingTransaction.ts +40 -40
- package/src/transaction/builders/MultiSignTransaction.ts +9 -17
- package/src/transaction/builders/SharedInteractionTransaction.ts +368 -368
- package/src/transaction/builders/TransactionBuilder.ts +637 -632
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +365 -362
- package/src/transaction/builders/UnwrapTransaction.ts +503 -499
- package/src/transaction/builders/WrapTransaction.ts +346 -346
- package/src/transaction/interfaces/ITransactionParameters.ts +55 -54
- package/src/transaction/processor/PsbtTransaction.ts +192 -192
- package/src/transaction/shared/TweakedTransaction.ts +109 -56
|
@@ -43,7 +43,7 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
43
43
|
bufWriter.writeU256(amount);
|
|
44
44
|
return Buffer.from(bufWriter.getBuffer());
|
|
45
45
|
}
|
|
46
|
-
signPSBT() {
|
|
46
|
+
async signPSBT() {
|
|
47
47
|
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
48
48
|
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
49
49
|
}
|
|
@@ -53,16 +53,16 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
53
53
|
if (this.signed)
|
|
54
54
|
throw new Error('Transaction is already signed');
|
|
55
55
|
this.signed = true;
|
|
56
|
-
this.buildTransaction();
|
|
56
|
+
await this.buildTransaction();
|
|
57
57
|
this.ignoreSignatureError();
|
|
58
|
-
this.mergeVaults(this.vaultUTXOs);
|
|
59
|
-
const builtTx = this.internalBuildTransaction(this.transaction);
|
|
58
|
+
await this.mergeVaults(this.vaultUTXOs);
|
|
59
|
+
const builtTx = await this.internalBuildTransaction(this.transaction);
|
|
60
60
|
if (builtTx) {
|
|
61
61
|
return this.transaction;
|
|
62
62
|
}
|
|
63
63
|
throw new Error('Could not sign transaction');
|
|
64
64
|
}
|
|
65
|
-
mergeVaults(input) {
|
|
65
|
+
async mergeVaults(input) {
|
|
66
66
|
const firstVault = input[0];
|
|
67
67
|
if (!firstVault) {
|
|
68
68
|
throw new Error('No vaults provided');
|
|
@@ -85,10 +85,10 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
85
85
|
value: Number(this.amount),
|
|
86
86
|
});
|
|
87
87
|
for (const vault of input) {
|
|
88
|
-
this.addVaultInputs(vault);
|
|
88
|
+
await this.addVaultInputs(vault);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
internalBuildTransaction(transaction) {
|
|
91
|
+
async internalBuildTransaction(transaction) {
|
|
92
92
|
if (transaction.data.inputs.length === 0) {
|
|
93
93
|
const inputs = this.getInputs();
|
|
94
94
|
const outputs = this.getOutputs();
|
|
@@ -100,7 +100,7 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
100
100
|
transaction.addOutputs(outputs);
|
|
101
101
|
}
|
|
102
102
|
try {
|
|
103
|
-
this.signInputs(transaction);
|
|
103
|
+
await this.signInputs(transaction);
|
|
104
104
|
if (this.finalized) {
|
|
105
105
|
this.transactionFee = BigInt(transaction.getFee());
|
|
106
106
|
}
|
|
@@ -150,7 +150,7 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
150
150
|
}
|
|
151
151
|
this.addInput(input);
|
|
152
152
|
}
|
|
153
|
-
addVaultInputs(vault, firstSigner = this.signer) {
|
|
153
|
+
async addVaultInputs(vault, firstSigner = this.signer) {
|
|
154
154
|
const p2wshOutput = this.generateMultiSignRedeemScript(vault.publicKeys, vault.minimum);
|
|
155
155
|
for (const utxo of vault.utxos) {
|
|
156
156
|
const inputIndex = this.transaction.inputCount;
|
|
@@ -158,7 +158,7 @@ export class UnwrapSegwitTransaction extends SharedInteractionTransaction {
|
|
|
158
158
|
if (firstSigner) {
|
|
159
159
|
this.log(`Signing input ${inputIndex} with ${firstSigner.publicKey.toString('hex')}`);
|
|
160
160
|
try {
|
|
161
|
-
this.signInput(this.transaction, this.transaction.data.inputs[inputIndex], inputIndex, this.signer);
|
|
161
|
+
await this.signInput(this.transaction, this.transaction.data.inputs[inputIndex], inputIndex, this.signer);
|
|
162
162
|
this.log(`Signed input ${inputIndex} with ${firstSigner.publicKey.toString('hex')}`);
|
|
163
163
|
}
|
|
164
164
|
catch (e) {
|
|
@@ -20,7 +20,7 @@ export declare class UnwrapTransaction extends SharedInteractionTransaction<Tran
|
|
|
20
20
|
private readonly calculatedSignHash;
|
|
21
21
|
constructor(parameters: IUnwrapParameters);
|
|
22
22
|
static generateBurnCalldata(amount: bigint): Buffer;
|
|
23
|
-
signPSBT(): Psbt
|
|
23
|
+
signPSBT(): Promise<Psbt>;
|
|
24
24
|
getRefund(): bigint;
|
|
25
25
|
getFeeLossOrRefund(): bigint;
|
|
26
26
|
protected mergeVaults(): void;
|
|
@@ -35,7 +35,7 @@ export declare class UnwrapTransaction extends SharedInteractionTransaction<Tran
|
|
|
35
35
|
redeem: Payment;
|
|
36
36
|
};
|
|
37
37
|
protected getScriptSolution(input: PsbtInput): Buffer[];
|
|
38
|
-
protected internalBuildTransaction(transaction: Psbt): boolean
|
|
38
|
+
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
39
39
|
private addVaultUTXO;
|
|
40
40
|
private addVaultInputs;
|
|
41
41
|
private calculateOutputLeftAmountFromVaults;
|
|
@@ -53,17 +53,17 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
53
53
|
bufWriter.writeU256(amount);
|
|
54
54
|
return Buffer.from(bufWriter.getBuffer());
|
|
55
55
|
}
|
|
56
|
-
signPSBT() {
|
|
56
|
+
async signPSBT() {
|
|
57
57
|
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
58
58
|
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
59
59
|
}
|
|
60
60
|
if (!this.vaultUTXOs.length) {
|
|
61
61
|
throw new Error('No vault UTXOs provided');
|
|
62
62
|
}
|
|
63
|
-
this.buildTransaction();
|
|
63
|
+
await this.buildTransaction();
|
|
64
64
|
this.ignoreSignatureError();
|
|
65
65
|
this.mergeVaults();
|
|
66
|
-
const builtTx = this.internalBuildTransaction(this.transaction);
|
|
66
|
+
const builtTx = await this.internalBuildTransaction(this.transaction);
|
|
67
67
|
if (builtTx) {
|
|
68
68
|
return this.transaction;
|
|
69
69
|
}
|
|
@@ -91,7 +91,10 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
91
91
|
if (!bestVault) {
|
|
92
92
|
throw new Error('No vaults provided');
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
if (outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
95
|
+
throw new Error('Output left amount is below the minimum amount');
|
|
96
|
+
}
|
|
97
|
+
let hasConsolidation = outputLeftAmount > currentConsensusConfig.VAULT_MINIMUM_AMOUNT &&
|
|
95
98
|
outputLeftAmount - currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT !== 0n;
|
|
96
99
|
if (hasConsolidation) {
|
|
97
100
|
this.success(`Consolidating output with ${outputLeftAmount} sat.`);
|
|
@@ -179,7 +182,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
179
182
|
input.tapScriptSig[1].signature,
|
|
180
183
|
];
|
|
181
184
|
}
|
|
182
|
-
internalBuildTransaction(transaction) {
|
|
185
|
+
async internalBuildTransaction(transaction) {
|
|
183
186
|
if (transaction.data.inputs.length === 0) {
|
|
184
187
|
const inputs = this.getInputs();
|
|
185
188
|
const outputs = this.getOutputs();
|
|
@@ -192,7 +195,7 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
192
195
|
}
|
|
193
196
|
try {
|
|
194
197
|
try {
|
|
195
|
-
this.signInputs(transaction);
|
|
198
|
+
await this.signInputs(transaction);
|
|
196
199
|
}
|
|
197
200
|
catch (e) {
|
|
198
201
|
console.log(e);
|
|
@@ -22,7 +22,7 @@ export declare class WrapTransaction extends SharedInteractionTransaction<Transa
|
|
|
22
22
|
constructor(parameters: IWrapParameters);
|
|
23
23
|
private static generateMintCalldata;
|
|
24
24
|
verifyPublicKeysConstraints(generation: WrappedGeneration): boolean;
|
|
25
|
-
protected buildTransaction(): void
|
|
25
|
+
protected buildTransaction(): Promise<void>;
|
|
26
26
|
private verifyRequiredValue;
|
|
27
27
|
private addVaultOutput;
|
|
28
28
|
private generateVaultAddress;
|
|
@@ -81,7 +81,7 @@ export class WrapTransaction extends SharedInteractionTransaction {
|
|
|
81
81
|
}
|
|
82
82
|
return true;
|
|
83
83
|
}
|
|
84
|
-
buildTransaction() {
|
|
84
|
+
async buildTransaction() {
|
|
85
85
|
if (!this.to)
|
|
86
86
|
throw new Error('To address is required');
|
|
87
87
|
const selectedRedeem = !!this.scriptSigner
|
|
@@ -108,7 +108,7 @@ export class WrapTransaction extends SharedInteractionTransaction {
|
|
|
108
108
|
address: this.to,
|
|
109
109
|
});
|
|
110
110
|
this.addVaultOutput();
|
|
111
|
-
this.addRefundOutput(amountSpent +
|
|
111
|
+
await this.addRefundOutput(amountSpent +
|
|
112
112
|
this.amount +
|
|
113
113
|
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT);
|
|
114
114
|
}
|
|
@@ -36,7 +36,7 @@ export declare class PsbtTransaction extends TweakedTransaction {
|
|
|
36
36
|
toHex(): string;
|
|
37
37
|
addInput(input: PsbtInputExtended): void;
|
|
38
38
|
addOutput(output: PsbtOutputExtended): void;
|
|
39
|
-
attemptSignAllInputs(): boolean
|
|
39
|
+
attemptSignAllInputs(): Promise<boolean>;
|
|
40
40
|
attemptFinalizeInputs(n?: number): boolean;
|
|
41
41
|
getPSBT(): Psbt;
|
|
42
42
|
private getTotalOutputAmount;
|
|
@@ -56,12 +56,12 @@ export class PsbtTransaction extends TweakedTransaction {
|
|
|
56
56
|
return;
|
|
57
57
|
this.transaction.addOutput(output);
|
|
58
58
|
}
|
|
59
|
-
attemptSignAllInputs() {
|
|
59
|
+
async attemptSignAllInputs() {
|
|
60
60
|
let signed = false;
|
|
61
61
|
for (let i = 0; i < this.transaction.data.inputs.length; i++) {
|
|
62
62
|
const input = this.transaction.data.inputs[i];
|
|
63
63
|
try {
|
|
64
|
-
this.signInput(this.transaction, input, i, this.signer);
|
|
64
|
+
await this.signInput(this.transaction, input, i, this.signer);
|
|
65
65
|
signed = true;
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
@@ -28,10 +28,12 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
28
28
|
protected sequence: number;
|
|
29
29
|
protected tapLeafScript: TapLeafScript | null;
|
|
30
30
|
protected nonWitnessUtxo?: Buffer;
|
|
31
|
+
protected readonly isBrowser: boolean;
|
|
31
32
|
protected regenerated: boolean;
|
|
32
33
|
protected ignoreSignatureErrors: boolean;
|
|
33
34
|
protected constructor(data: ITweakedTransactionData);
|
|
34
35
|
static readScriptWitnessToWitnessStack(buffer: Buffer): Buffer[];
|
|
36
|
+
static preEstimateTaprootTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numWitnessElements: bigint, witnessElementSize: bigint, emptyWitness: bigint, taprootControlWitnessSize?: bigint, taprootScriptSize?: bigint): bigint;
|
|
35
37
|
protected static signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer, sighashTypes: number[]): void;
|
|
36
38
|
protected static calculateSignHash(sighashTypes: number[]): number;
|
|
37
39
|
ignoreSignatureError(): void;
|
|
@@ -41,15 +43,14 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
41
43
|
disableRBF(): void;
|
|
42
44
|
getTweakerHash(): Buffer | undefined;
|
|
43
45
|
preEstimateTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numSignatures: bigint, numPubkeys: bigint): bigint;
|
|
44
|
-
static preEstimateTaprootTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numWitnessElements: bigint, witnessElementSize: bigint, emptyWitness: bigint, taprootControlWitnessSize?: bigint, taprootScriptSize?: bigint): bigint;
|
|
45
46
|
protected generateTapData(): Payment;
|
|
46
47
|
protected generateScriptAddress(): Payment;
|
|
47
48
|
protected getSignerKey(): Signer;
|
|
48
|
-
protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer?: Signer): void
|
|
49
|
-
protected signInputs(transaction: Psbt): void
|
|
49
|
+
protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer?: Signer): Promise<void>;
|
|
50
|
+
protected signInputs(transaction: Psbt): Promise<void>;
|
|
50
51
|
protected internalPubKeyToXOnly(): Buffer;
|
|
51
52
|
protected internalInit(): void;
|
|
52
53
|
protected tweakSigner(): void;
|
|
53
|
-
protected getTweakedSigner(useTweakedHash?: boolean, signer?: Signer): Signer;
|
|
54
|
+
protected getTweakedSigner(useTweakedHash?: boolean, signer?: Signer): Signer | undefined;
|
|
54
55
|
protected generatePsbtInputExtended(utxo: UTXO, i: number): PsbtInputExtended;
|
|
55
56
|
}
|
|
@@ -23,6 +23,7 @@ export class TweakedTransaction extends Logger {
|
|
|
23
23
|
sequence = TransactionSequence.REPLACE_BY_FEE;
|
|
24
24
|
tapLeafScript = null;
|
|
25
25
|
nonWitnessUtxo;
|
|
26
|
+
isBrowser = false;
|
|
26
27
|
regenerated = false;
|
|
27
28
|
ignoreSignatureErrors = false;
|
|
28
29
|
constructor(data) {
|
|
@@ -30,6 +31,7 @@ export class TweakedTransaction extends Logger {
|
|
|
30
31
|
this.signer = data.signer;
|
|
31
32
|
this.network = data.network;
|
|
32
33
|
this.nonWitnessUtxo = data.nonWitnessUtxo;
|
|
34
|
+
this.isBrowser = typeof window !== 'undefined';
|
|
33
35
|
}
|
|
34
36
|
static readScriptWitnessToWitnessStack(buffer) {
|
|
35
37
|
let offset = 0;
|
|
@@ -57,6 +59,21 @@ export class TweakedTransaction extends Logger {
|
|
|
57
59
|
}
|
|
58
60
|
return readVector();
|
|
59
61
|
}
|
|
62
|
+
static preEstimateTaprootTransactionFees(feeRate, numInputs, numOutputs, numWitnessElements, witnessElementSize, emptyWitness, taprootControlWitnessSize = 32n, taprootScriptSize = 139n) {
|
|
63
|
+
const txHeaderSize = 10n;
|
|
64
|
+
const inputBaseSize = 41n;
|
|
65
|
+
const outputSize = 68n;
|
|
66
|
+
const taprootWitnessBaseSize = 1n;
|
|
67
|
+
const baseTxSize = txHeaderSize + inputBaseSize * numInputs + outputSize * numOutputs;
|
|
68
|
+
const witnessSize = numInputs * taprootWitnessBaseSize +
|
|
69
|
+
numWitnessElements * witnessElementSize +
|
|
70
|
+
taprootControlWitnessSize * numInputs +
|
|
71
|
+
taprootScriptSize * numInputs +
|
|
72
|
+
emptyWitness;
|
|
73
|
+
const weight = baseTxSize * 3n + (baseTxSize + witnessSize);
|
|
74
|
+
const vSize = weight / 4n;
|
|
75
|
+
return vSize * feeRate;
|
|
76
|
+
}
|
|
60
77
|
static signInput(transaction, input, i, signer, sighashTypes) {
|
|
61
78
|
if (sighashTypes && sighashTypes[0])
|
|
62
79
|
input.sighashType = sighashTypes[0];
|
|
@@ -114,21 +131,6 @@ export class TweakedTransaction extends Logger {
|
|
|
114
131
|
const vSize = weight / 4n;
|
|
115
132
|
return vSize * feeRate;
|
|
116
133
|
}
|
|
117
|
-
static preEstimateTaprootTransactionFees(feeRate, numInputs, numOutputs, numWitnessElements, witnessElementSize, emptyWitness, taprootControlWitnessSize = 32n, taprootScriptSize = 139n) {
|
|
118
|
-
const txHeaderSize = 10n;
|
|
119
|
-
const inputBaseSize = 41n;
|
|
120
|
-
const outputSize = 68n;
|
|
121
|
-
const taprootWitnessBaseSize = 1n;
|
|
122
|
-
const baseTxSize = txHeaderSize + inputBaseSize * numInputs + outputSize * numOutputs;
|
|
123
|
-
const witnessSize = numInputs * taprootWitnessBaseSize +
|
|
124
|
-
numWitnessElements * witnessElementSize +
|
|
125
|
-
taprootControlWitnessSize * numInputs +
|
|
126
|
-
taprootScriptSize * numInputs +
|
|
127
|
-
emptyWitness;
|
|
128
|
-
const weight = baseTxSize * 3n + (baseTxSize + witnessSize);
|
|
129
|
-
const vSize = weight / 4n;
|
|
130
|
-
return vSize * feeRate;
|
|
131
|
-
}
|
|
132
134
|
generateTapData() {
|
|
133
135
|
return {
|
|
134
136
|
internalPubkey: this.internalPubKeyToXOnly(),
|
|
@@ -144,15 +146,15 @@ export class TweakedTransaction extends Logger {
|
|
|
144
146
|
getSignerKey() {
|
|
145
147
|
return this.signer;
|
|
146
148
|
}
|
|
147
|
-
signInput(transaction, input, i, signer) {
|
|
149
|
+
async signInput(transaction, input, i, signer) {
|
|
148
150
|
const signHash = this.sighashTypes && this.sighashTypes.length
|
|
149
151
|
? [TweakedTransaction.calculateSignHash(this.sighashTypes)]
|
|
150
152
|
: undefined;
|
|
153
|
+
signer = signer || this.getSignerKey();
|
|
154
|
+
let testedTap = false;
|
|
151
155
|
if (input.tapInternalKey) {
|
|
152
156
|
if (!this.tweakedSigner)
|
|
153
157
|
this.tweakSigner();
|
|
154
|
-
if (!this.tweakedSigner)
|
|
155
|
-
throw new Error('Tweaked signer is required');
|
|
156
158
|
let tweakedSigner;
|
|
157
159
|
if (signer !== this.signer) {
|
|
158
160
|
tweakedSigner = this.getTweakedSigner(true, signer);
|
|
@@ -160,19 +162,50 @@ export class TweakedTransaction extends Logger {
|
|
|
160
162
|
else {
|
|
161
163
|
tweakedSigner = this.tweakedSigner;
|
|
162
164
|
}
|
|
163
|
-
|
|
165
|
+
if (tweakedSigner) {
|
|
166
|
+
testedTap = true;
|
|
167
|
+
try {
|
|
168
|
+
if ('signTaprootInput' in signer) {
|
|
169
|
+
return await signer.signTaprootInput(transaction, i, signHash);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
transaction.signTaprootInput(i, tweakedSigner, undefined, signHash);
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
catch (e) { }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
if ('signInput' in signer) {
|
|
181
|
+
return await signer.signInput(transaction, i, signHash);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
transaction.signInput(i, signer, signHash);
|
|
185
|
+
}
|
|
164
186
|
}
|
|
165
|
-
|
|
166
|
-
|
|
187
|
+
catch (e) {
|
|
188
|
+
if (!testedTap) {
|
|
189
|
+
if ('signTaprootInput' in signer) {
|
|
190
|
+
return await signer.signTaprootInput(transaction, i, signHash);
|
|
191
|
+
}
|
|
192
|
+
else if (this.tweakedSigner) {
|
|
193
|
+
transaction.signTaprootInput(i, this.tweakedSigner, undefined, signHash);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
167
199
|
}
|
|
168
200
|
}
|
|
169
|
-
signInputs(transaction) {
|
|
201
|
+
async signInputs(transaction) {
|
|
170
202
|
for (let i = 0; i < transaction.data.inputs.length; i++) {
|
|
171
203
|
let input = transaction.data.inputs[i];
|
|
172
204
|
try {
|
|
173
|
-
this.signInput(transaction, input, i);
|
|
205
|
+
await this.signInput(transaction, input, i);
|
|
174
206
|
}
|
|
175
207
|
catch (e) {
|
|
208
|
+
console.log(e);
|
|
176
209
|
this.log(`Failed to sign input ${i}: ${e.stack}`);
|
|
177
210
|
}
|
|
178
211
|
}
|
|
@@ -203,6 +236,9 @@ export class TweakedTransaction extends Logger {
|
|
|
203
236
|
if (useTweakedHash) {
|
|
204
237
|
settings.tweakHash = this.getTweakerHash();
|
|
205
238
|
}
|
|
239
|
+
if (!('privateKey' in signer)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
206
242
|
return TweakedSigner.tweakSigner(signer, settings);
|
|
207
243
|
}
|
|
208
244
|
generatePsbtInputExtended(utxo, i) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"author": "BlobMaster41",
|
|
5
5
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
6
6
|
"engines": {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
93
93
|
"@bitcoinerlab/secp256k1": "^1.1.1",
|
|
94
|
-
"@btc-vision/bsi-binary": "^1.0.
|
|
94
|
+
"@btc-vision/bsi-binary": "^1.0.26",
|
|
95
95
|
"@btc-vision/bsi-bitcoin-rpc": "^1.0.20",
|
|
96
96
|
"@btc-vision/bsi-common": "^1.0.14",
|
|
97
97
|
"@btc-vision/logger": "^1.0.2",
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.44';
|
|
@@ -34,7 +34,7 @@ export class wBTC extends ContractBaseMetadata {
|
|
|
34
34
|
case networks.bitcoin.bech32:
|
|
35
35
|
return 'unknown';
|
|
36
36
|
case networks.regtest.bech32:
|
|
37
|
-
return '
|
|
37
|
+
return 'bcrt1q99qtptumw027cw8w274tqzd564q66u537vn0lh';
|
|
38
38
|
case networks.testnet.bech32:
|
|
39
39
|
return 'tb1qj58a6yf4pez426nqvf8wyu6ssggcajw8kr44vy';
|
|
40
40
|
default:
|
package/src/opnet.ts
CHANGED
|
@@ -1,76 +1,81 @@
|
|
|
1
|
-
export { version } from './_version.js';
|
|
2
|
-
|
|
3
|
-
/** Bytecode */
|
|
4
|
-
export * from './bytecode/Compressor.js';
|
|
5
|
-
|
|
6
|
-
/** Generators */
|
|
7
|
-
export * from './generators/Generator.js';
|
|
8
|
-
export * from './generators/builders/CalldataGenerator.js';
|
|
9
|
-
export * from './generators/builders/DeploymentGenerator.js';
|
|
10
|
-
export * from './generators/Features.js';
|
|
11
|
-
|
|
12
|
-
/** Address */
|
|
13
|
-
export * from './generators/AddressGenerator.js';
|
|
14
|
-
export * from './verification/TapscriptVerificator.js';
|
|
15
|
-
|
|
16
|
-
/** Key Pair */
|
|
17
|
-
export * from './keypair/EcKeyPair.js';
|
|
18
|
-
export * from './keypair/Wallet.js';
|
|
19
|
-
export * from './keypair/interfaces/IWallet.js';
|
|
20
|
-
export * from './keypair/AddressVerificator.js';
|
|
21
|
-
|
|
22
|
-
/** Metadata */
|
|
23
|
-
export * from './metadata/contracts/wBTC.js';
|
|
24
|
-
export * from './metadata/ContractBaseMetadata.js';
|
|
25
|
-
|
|
26
|
-
/** Network */
|
|
27
|
-
export * from './network/NetworkInformation.js';
|
|
28
|
-
|
|
29
|
-
/** Signer */
|
|
30
|
-
export * from './signer/TweakedSigner.js';
|
|
31
|
-
|
|
32
|
-
/** Transaction */
|
|
33
|
-
export * from './transaction/TransactionFactory.js';
|
|
34
|
-
export * from './transaction/interfaces/ITransactionParameters.js';
|
|
35
|
-
export * from './transaction/interfaces/Tap.js';
|
|
36
|
-
export * from './transaction/enums/TransactionType.js';
|
|
37
|
-
|
|
38
|
-
/** Builders */
|
|
39
|
-
export * from './transaction/builders/InteractionTransaction.js';
|
|
40
|
-
export * from './transaction/builders/FundingTransaction.js';
|
|
41
|
-
export * from './transaction/builders/TransactionBuilder.js';
|
|
42
|
-
export * from './transaction/builders/WrapTransaction.js';
|
|
43
|
-
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
44
|
-
export * from './transaction/builders/DeploymentTransaction.js';
|
|
45
|
-
|
|
46
|
-
/** wBTC */
|
|
47
|
-
export * from './wbtc/WrappedGenerationParameters.js';
|
|
48
|
-
export * from './wbtc/Generate.js';
|
|
49
|
-
|
|
50
|
-
/** Utils */
|
|
51
|
-
export * from './utils/BitcoinUtils.js';
|
|
52
|
-
|
|
53
|
-
/** UTXO */
|
|
54
|
-
export * from './utxo/interfaces/IUTXO.js';
|
|
55
|
-
export * from './utxo/OPNetLimitedProvider.js';
|
|
56
|
-
|
|
57
|
-
/** Processor */
|
|
58
|
-
export * from './transaction/processor/PsbtTransaction.js';
|
|
59
|
-
|
|
60
|
-
/** Shared */
|
|
61
|
-
export * from './transaction/shared/TweakedTransaction.js';
|
|
62
|
-
export * from './utxo/interfaces/BroadcastResponse.js';
|
|
63
|
-
export * from './transaction/psbt/PSBTTypes.js';
|
|
64
|
-
|
|
65
|
-
export * from './transaction/builders/MultiSignTransaction.js';
|
|
66
|
-
export * from './generators/builders/MultiSignGenerator.js';
|
|
67
|
-
|
|
68
|
-
export * from './transaction/shared/P2TR_MS.js';
|
|
69
|
-
export * from './transaction/builders/UnwrapTransaction.js';
|
|
70
|
-
|
|
71
|
-
export * from './wbtc/UnwrapGeneration.js';
|
|
72
|
-
|
|
73
|
-
/** Consensus */
|
|
74
|
-
export * from './consensus/ConsensusConfig.js';
|
|
75
|
-
export * from './consensus/Consensus.js';
|
|
76
|
-
export * from './consensus/metadata/RoswellConsensus.js';
|
|
1
|
+
export { version } from './_version.js';
|
|
2
|
+
|
|
3
|
+
/** Bytecode */
|
|
4
|
+
export * from './bytecode/Compressor.js';
|
|
5
|
+
|
|
6
|
+
/** Generators */
|
|
7
|
+
export * from './generators/Generator.js';
|
|
8
|
+
export * from './generators/builders/CalldataGenerator.js';
|
|
9
|
+
export * from './generators/builders/DeploymentGenerator.js';
|
|
10
|
+
export * from './generators/Features.js';
|
|
11
|
+
|
|
12
|
+
/** Address */
|
|
13
|
+
export * from './generators/AddressGenerator.js';
|
|
14
|
+
export * from './verification/TapscriptVerificator.js';
|
|
15
|
+
|
|
16
|
+
/** Key Pair */
|
|
17
|
+
export * from './keypair/EcKeyPair.js';
|
|
18
|
+
export * from './keypair/Wallet.js';
|
|
19
|
+
export * from './keypair/interfaces/IWallet.js';
|
|
20
|
+
export * from './keypair/AddressVerificator.js';
|
|
21
|
+
|
|
22
|
+
/** Metadata */
|
|
23
|
+
export * from './metadata/contracts/wBTC.js';
|
|
24
|
+
export * from './metadata/ContractBaseMetadata.js';
|
|
25
|
+
|
|
26
|
+
/** Network */
|
|
27
|
+
export * from './network/NetworkInformation.js';
|
|
28
|
+
|
|
29
|
+
/** Signer */
|
|
30
|
+
export * from './signer/TweakedSigner.js';
|
|
31
|
+
|
|
32
|
+
/** Transaction */
|
|
33
|
+
export * from './transaction/TransactionFactory.js';
|
|
34
|
+
export * from './transaction/interfaces/ITransactionParameters.js';
|
|
35
|
+
export * from './transaction/interfaces/Tap.js';
|
|
36
|
+
export * from './transaction/enums/TransactionType.js';
|
|
37
|
+
|
|
38
|
+
/** Builders */
|
|
39
|
+
export * from './transaction/builders/InteractionTransaction.js';
|
|
40
|
+
export * from './transaction/builders/FundingTransaction.js';
|
|
41
|
+
export * from './transaction/builders/TransactionBuilder.js';
|
|
42
|
+
export * from './transaction/builders/WrapTransaction.js';
|
|
43
|
+
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
44
|
+
export * from './transaction/builders/DeploymentTransaction.js';
|
|
45
|
+
|
|
46
|
+
/** wBTC */
|
|
47
|
+
export * from './wbtc/WrappedGenerationParameters.js';
|
|
48
|
+
export * from './wbtc/Generate.js';
|
|
49
|
+
|
|
50
|
+
/** Utils */
|
|
51
|
+
export * from './utils/BitcoinUtils.js';
|
|
52
|
+
|
|
53
|
+
/** UTXO */
|
|
54
|
+
export * from './utxo/interfaces/IUTXO.js';
|
|
55
|
+
export * from './utxo/OPNetLimitedProvider.js';
|
|
56
|
+
|
|
57
|
+
/** Processor */
|
|
58
|
+
export * from './transaction/processor/PsbtTransaction.js';
|
|
59
|
+
|
|
60
|
+
/** Shared */
|
|
61
|
+
export * from './transaction/shared/TweakedTransaction.js';
|
|
62
|
+
export * from './utxo/interfaces/BroadcastResponse.js';
|
|
63
|
+
export * from './transaction/psbt/PSBTTypes.js';
|
|
64
|
+
|
|
65
|
+
export * from './transaction/builders/MultiSignTransaction.js';
|
|
66
|
+
export * from './generators/builders/MultiSignGenerator.js';
|
|
67
|
+
|
|
68
|
+
export * from './transaction/shared/P2TR_MS.js';
|
|
69
|
+
export * from './transaction/builders/UnwrapTransaction.js';
|
|
70
|
+
|
|
71
|
+
export * from './wbtc/UnwrapGeneration.js';
|
|
72
|
+
|
|
73
|
+
/** Consensus */
|
|
74
|
+
export * from './consensus/ConsensusConfig.js';
|
|
75
|
+
export * from './consensus/Consensus.js';
|
|
76
|
+
export * from './consensus/metadata/RoswellConsensus.js';
|
|
77
|
+
|
|
78
|
+
/** Custom signers */
|
|
79
|
+
export * from './transaction/browser/BrowserSignerBase.js';
|
|
80
|
+
export * from './transaction/browser/extensions/UnisatSigner.js';
|
|
81
|
+
export * from './transaction/browser/types/Unisat.js';
|