@btc-vision/transaction 1.1.16 → 1.2.0
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/crypto/crypto-browser.d.ts +2 -2
- package/browser/index.js +1 -1
- package/browser/index.js.LICENSE.txt +2 -0
- package/browser/keypair/Address.d.ts +10 -0
- package/browser/keypair/Secp256k1PointDeriver.d.ts +16 -0
- package/browser/opnet.d.ts +2 -0
- package/browser/signer/SignerUtils.d.ts +5 -0
- package/browser/transaction/ContractAddress.d.ts +6 -0
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +3 -4
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -6
- package/browser/utxo/interfaces/IUTXO.d.ts +1 -0
- package/browser/verification/TapscriptVerificator.d.ts +1 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryReader.js +2 -2
- package/build/buffer/BinaryWriter.js +1 -1
- package/build/generators/AddressGenerator.js +1 -2
- package/build/generators/Generator.js +1 -2
- package/build/generators/builders/CalldataGenerator.js +1 -1
- package/build/generators/builders/LegacyCalldataGenerator.js +1 -1
- package/build/generators/builders/MultiSignGenerator.js +1 -2
- package/build/keypair/Address.d.ts +10 -0
- package/build/keypair/Address.js +76 -7
- package/build/keypair/AddressVerificator.js +5 -2
- package/build/keypair/EcKeyPair.js +3 -4
- package/build/keypair/MessageSigner.js +1 -2
- package/build/keypair/Secp256k1PointDeriver.d.ts +16 -0
- package/build/keypair/Secp256k1PointDeriver.js +80 -0
- package/build/keypair/Wallet.js +1 -2
- package/build/opnet.d.ts +2 -0
- package/build/opnet.js +2 -0
- package/build/signer/SignerUtils.d.ts +5 -0
- package/build/signer/SignerUtils.js +40 -0
- package/build/signer/TweakedSigner.js +1 -3
- package/build/transaction/ContractAddress.d.ts +6 -0
- package/build/transaction/ContractAddress.js +12 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +5 -33
- package/build/transaction/browser/extensions/XverseSigner.js +5 -49
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/build/transaction/builders/CustomScriptTransaction.js +1 -2
- package/build/transaction/builders/DeploymentTransaction.js +2 -2
- package/build/transaction/builders/FundingTransaction.js +6 -1
- package/build/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +3 -4
- package/build/transaction/builders/MultiSignTransaction.js +1 -2
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
- package/build/transaction/builders/SharedInteractionTransaction.js +1 -2
- package/build/transaction/builders/TransactionBuilder.js +14 -3
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -6
- package/build/transaction/shared/TweakedTransaction.js +121 -94
- package/build/utils/BitcoinUtils.js +4 -4
- package/build/utils/BufferHelper.js +1 -1
- package/build/utxo/OPNetLimitedProvider.js +1 -0
- package/build/utxo/interfaces/IUTXO.d.ts +1 -0
- package/build/verification/TapscriptVerificator.d.ts +1 -2
- package/build/verification/TapscriptVerificator.js +1 -2
- package/package.json +9 -12
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryReader.ts +2 -2
- package/src/buffer/BinaryWriter.ts +1 -1
- package/src/generators/AddressGenerator.ts +1 -2
- package/src/generators/Generator.ts +1 -2
- package/src/generators/builders/CalldataGenerator.ts +5 -1
- package/src/generators/builders/LegacyCalldataGenerator.ts +5 -1
- package/src/generators/builders/MultiSignGenerator.ts +1 -2
- package/src/keypair/Address.ts +106 -10
- package/src/keypair/AddressVerificator.ts +6 -2
- package/src/keypair/EcKeyPair.ts +14 -5
- package/src/keypair/MessageSigner.ts +1 -2
- package/src/keypair/Secp256k1PointDeriver.ts +170 -0
- package/src/keypair/Wallet.ts +1 -2
- package/src/opnet.ts +2 -0
- package/src/signer/SignerUtils.ts +66 -0
- package/src/signer/TweakedSigner.ts +1 -3
- package/src/transaction/ContractAddress.ts +13 -0
- package/src/transaction/TransactionFactory.ts +4 -258
- package/src/transaction/browser/extensions/UnisatSigner.ts +5 -41
- package/src/transaction/browser/extensions/XverseSigner.ts +9 -69
- package/src/transaction/builders/CustomScriptTransaction.ts +10 -3
- package/src/transaction/builders/DeploymentTransaction.ts +13 -3
- package/src/transaction/builders/FundingTransaction.ts +7 -2
- package/src/transaction/builders/InteractionTransaction.ts +1 -1
- package/src/transaction/builders/MultiSignTransaction.ts +2 -2
- package/src/transaction/builders/SharedInteractionTransaction.ts +1 -3
- package/src/transaction/builders/TransactionBuilder.ts +14 -2
- package/src/transaction/shared/TweakedTransaction.ts +186 -123
- package/src/utils/BitcoinUtils.ts +4 -4
- package/src/utils/BufferHelper.ts +1 -1
- package/src/utxo/OPNetLimitedProvider.ts +1 -0
- package/src/utxo/interfaces/IUTXO.ts +2 -0
- package/src/verification/TapscriptVerificator.ts +9 -3
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Logger } from '@btc-vision/logger';
|
|
2
|
-
import { address as bitAddress, crypto as bitCrypto, getFinalScripts, opcodes, payments, script, } from '@btc-vision/bitcoin';
|
|
2
|
+
import { address as bitAddress, crypto as bitCrypto, getFinalScripts, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, opcodes, payments, script, toXOnly, varuint, } from '@btc-vision/bitcoin';
|
|
3
3
|
import { TweakedSigner } from '../../signer/TweakedSigner.js';
|
|
4
|
-
import {
|
|
5
|
-
import { AddressTypes, AddressVerificator } from '../../keypair/AddressVerificator.js';
|
|
6
|
-
import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
|
|
7
|
-
import * as bscript from '@btc-vision/bitcoin/src/script.js';
|
|
4
|
+
import { canSignNonTaprootInput, isTaprootInput, pubkeyInScript, } from '../../signer/SignerUtils.js';
|
|
8
5
|
export var TransactionSequence;
|
|
9
6
|
(function (TransactionSequence) {
|
|
10
7
|
TransactionSequence[TransactionSequence["REPLACE_BY_FEE"] = 4294967293] = "REPLACE_BY_FEE";
|
|
@@ -154,36 +151,42 @@ export class TweakedTransaction extends Logger {
|
|
|
154
151
|
getSignerKey() {
|
|
155
152
|
return this.signer;
|
|
156
153
|
}
|
|
157
|
-
async signInput(transaction, input, i, signer, reverse = false) {
|
|
154
|
+
async signInput(transaction, input, i, signer, reverse = false, errored = false) {
|
|
158
155
|
const publicKey = signer.publicKey;
|
|
159
|
-
let isTaproot =
|
|
156
|
+
let isTaproot = isTaprootInput(input);
|
|
160
157
|
if (reverse) {
|
|
161
158
|
isTaproot = !isTaproot;
|
|
162
159
|
}
|
|
163
160
|
let signed = false;
|
|
161
|
+
let didError = false;
|
|
164
162
|
if (isTaproot) {
|
|
165
163
|
try {
|
|
166
164
|
await this.attemptSignTaproot(transaction, input, i, signer, publicKey);
|
|
167
165
|
signed = true;
|
|
168
166
|
}
|
|
169
167
|
catch (e) {
|
|
170
|
-
this.error(`Failed to sign Taproot script path input ${i}: ${e}`);
|
|
168
|
+
this.error(`Failed to sign Taproot script path input ${i} (reverse: ${reverse}): ${e.message}`);
|
|
169
|
+
didError = true;
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
else {
|
|
174
|
-
if (!reverse ?
|
|
173
|
+
if (!reverse ? canSignNonTaprootInput(input, publicKey) : true) {
|
|
175
174
|
try {
|
|
176
175
|
await this.signNonTaprootInput(signer, transaction, i);
|
|
177
176
|
signed = true;
|
|
178
177
|
}
|
|
179
178
|
catch (e) {
|
|
180
|
-
this.error(`Failed to sign non-Taproot input ${i}: ${e}`);
|
|
179
|
+
this.error(`Failed to sign non-Taproot input ${i}: ${e.stack}`);
|
|
180
|
+
didError = true;
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
if (!signed) {
|
|
185
|
+
if (didError && errored) {
|
|
186
|
+
throw new Error(`Failed to sign input ${i} with the provided signer.`);
|
|
187
|
+
}
|
|
185
188
|
try {
|
|
186
|
-
await this.signInput(transaction, input, i, signer, true);
|
|
189
|
+
await this.signInput(transaction, input, i, signer, true, didError);
|
|
187
190
|
}
|
|
188
191
|
catch {
|
|
189
192
|
throw new Error(`Cannot sign input ${i} with the provided signer.`);
|
|
@@ -296,51 +299,127 @@ export class TweakedTransaction extends Logger {
|
|
|
296
299
|
}
|
|
297
300
|
return;
|
|
298
301
|
}
|
|
302
|
+
generateP2SHP2PKHRedeemScript(inputAddr) {
|
|
303
|
+
const pubkey = Buffer.isBuffer(this.signer.publicKey)
|
|
304
|
+
? this.signer.publicKey
|
|
305
|
+
: Buffer.from(this.signer.publicKey, 'hex');
|
|
306
|
+
const w = payments.p2wpkh({
|
|
307
|
+
pubkey: pubkey,
|
|
308
|
+
network: this.network,
|
|
309
|
+
});
|
|
310
|
+
const p = payments.p2sh({
|
|
311
|
+
redeem: w,
|
|
312
|
+
network: this.network,
|
|
313
|
+
});
|
|
314
|
+
const address = p.address;
|
|
315
|
+
const redeemScript = p.redeem?.output;
|
|
316
|
+
if (!redeemScript) {
|
|
317
|
+
throw new Error('Failed to generate P2SH-P2WPKH redeem script');
|
|
318
|
+
}
|
|
319
|
+
if (address === inputAddr && p.redeem && p.redeem.output && p.output) {
|
|
320
|
+
return {
|
|
321
|
+
redeemScript: p.redeem.output,
|
|
322
|
+
outputScript: p.output,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
299
327
|
generatePsbtInputExtended(utxo, i) {
|
|
328
|
+
const script = Buffer.from(utxo.scriptPubKey.hex, 'hex');
|
|
300
329
|
const input = {
|
|
301
330
|
hash: utxo.transactionId,
|
|
302
331
|
index: utxo.outputIndex,
|
|
303
332
|
sequence: this.sequence,
|
|
304
333
|
witnessUtxo: {
|
|
305
334
|
value: Number(utxo.value),
|
|
306
|
-
script
|
|
335
|
+
script,
|
|
307
336
|
},
|
|
308
337
|
};
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
338
|
+
if (isP2PKH(script)) {
|
|
339
|
+
if (utxo.nonWitnessUtxo) {
|
|
340
|
+
input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
|
|
341
|
+
? utxo.nonWitnessUtxo
|
|
342
|
+
: Buffer.from(utxo.nonWitnessUtxo, 'hex');
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
throw new Error('Missing nonWitnessUtxo for P2PKH UTXO');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if (isP2WPKH(script)) {
|
|
349
|
+
}
|
|
350
|
+
else if (isP2WSHScript(script)) {
|
|
351
|
+
if (!utxo.witnessScript) {
|
|
352
|
+
throw new Error('Missing witnessScript for P2WSH UTXO');
|
|
353
|
+
}
|
|
354
|
+
input.witnessScript = Buffer.isBuffer(utxo.witnessScript)
|
|
355
|
+
? utxo.witnessScript
|
|
356
|
+
: Buffer.from(utxo.witnessScript, 'hex');
|
|
357
|
+
}
|
|
358
|
+
else if (isP2SHScript(script)) {
|
|
359
|
+
let redeemScriptBuf;
|
|
360
|
+
if (utxo.redeemScript) {
|
|
361
|
+
redeemScriptBuf = Buffer.isBuffer(utxo.redeemScript)
|
|
362
|
+
? utxo.redeemScript
|
|
363
|
+
: Buffer.from(utxo.redeemScript, 'hex');
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
if (!utxo.scriptPubKey.address) {
|
|
367
|
+
throw new Error('Missing redeemScript and no address to regenerate it for P2SH UTXO');
|
|
368
|
+
}
|
|
369
|
+
const legacyScripts = this.generateP2SHP2PKHRedeemScript(utxo.scriptPubKey.address);
|
|
370
|
+
if (!legacyScripts) {
|
|
371
|
+
throw new Error('Missing redeemScript for P2SH UTXO and unable to regenerate');
|
|
319
372
|
}
|
|
373
|
+
redeemScriptBuf = legacyScripts.redeemScript;
|
|
320
374
|
}
|
|
321
|
-
|
|
322
|
-
|
|
375
|
+
input.redeemScript = redeemScriptBuf;
|
|
376
|
+
const payment = payments.p2sh({ redeem: { output: input.redeemScript } });
|
|
377
|
+
if (!payment.redeem) {
|
|
378
|
+
throw new Error('Failed to extract redeem script from P2SH UTXO');
|
|
379
|
+
}
|
|
380
|
+
const redeemOutput = payment.redeem.output;
|
|
381
|
+
if (!redeemOutput) {
|
|
382
|
+
throw new Error('Failed to extract redeem output from P2SH UTXO');
|
|
383
|
+
}
|
|
384
|
+
if (utxo.nonWitnessUtxo) {
|
|
385
|
+
input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
|
|
386
|
+
? utxo.nonWitnessUtxo
|
|
387
|
+
: Buffer.from(utxo.nonWitnessUtxo, 'hex');
|
|
388
|
+
}
|
|
389
|
+
if (isP2WPKH(redeemOutput)) {
|
|
390
|
+
delete input.nonWitnessUtxo;
|
|
391
|
+
}
|
|
392
|
+
else if (isP2WSHScript(redeemOutput)) {
|
|
393
|
+
delete input.nonWitnessUtxo;
|
|
394
|
+
if (!input.witnessScript) {
|
|
395
|
+
throw new Error('Missing witnessScript for P2SH-P2WSH UTXO');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
delete input.witnessUtxo;
|
|
323
400
|
}
|
|
324
401
|
}
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
402
|
+
else if (isP2TR(script)) {
|
|
403
|
+
if (this.sighashTypes) {
|
|
404
|
+
const inputSign = TweakedTransaction.calculateSignHash(this.sighashTypes);
|
|
405
|
+
if (inputSign)
|
|
406
|
+
input.sighashType = inputSign;
|
|
407
|
+
}
|
|
408
|
+
this.tweakSigner();
|
|
409
|
+
input.tapInternalKey = this.internalPubKeyToXOnly();
|
|
410
|
+
}
|
|
411
|
+
else if (isP2PK(script) || isP2MS(script)) {
|
|
412
|
+
if (utxo.nonWitnessUtxo) {
|
|
413
|
+
input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
|
|
414
|
+
? utxo.nonWitnessUtxo
|
|
415
|
+
: Buffer.from(utxo.nonWitnessUtxo, 'hex');
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
throw new Error('Missing nonWitnessUtxo for P2PK or P2MS UTXO');
|
|
338
419
|
}
|
|
339
420
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (inputSign)
|
|
343
|
-
input.sighashType = inputSign;
|
|
421
|
+
else {
|
|
422
|
+
this.error(`Unknown or unsupported script type for output: ${utxo.scriptPubKey.hex}`);
|
|
344
423
|
}
|
|
345
424
|
if (this.tapLeafScript) {
|
|
346
425
|
input.tapLeafScript = [this.tapLeafScript];
|
|
@@ -348,11 +427,6 @@ export class TweakedTransaction extends Logger {
|
|
|
348
427
|
if (i === 0 && this.nonWitnessUtxo) {
|
|
349
428
|
input.nonWitnessUtxo = this.nonWitnessUtxo;
|
|
350
429
|
}
|
|
351
|
-
if (utxo.scriptPubKey.address &&
|
|
352
|
-
AddressVerificator.isValidP2TRAddress(utxo.scriptPubKey.address, this.network)) {
|
|
353
|
-
this.tweakSigner();
|
|
354
|
-
input.tapInternalKey = this.internalPubKeyToXOnly();
|
|
355
|
-
}
|
|
356
430
|
return input;
|
|
357
431
|
}
|
|
358
432
|
async signInputsWalletBased(transaction) {
|
|
@@ -389,60 +463,13 @@ export class TweakedTransaction extends Logger {
|
|
|
389
463
|
isTaprootScriptSpend(input, publicKey) {
|
|
390
464
|
if (input.tapLeafScript && input.tapLeafScript.length > 0) {
|
|
391
465
|
for (const tapLeafScript of input.tapLeafScript) {
|
|
392
|
-
if (
|
|
466
|
+
if (pubkeyInScript(publicKey, tapLeafScript.script)) {
|
|
393
467
|
return true;
|
|
394
468
|
}
|
|
395
469
|
}
|
|
396
470
|
}
|
|
397
471
|
return false;
|
|
398
472
|
}
|
|
399
|
-
isTaprootInput(input) {
|
|
400
|
-
if (input.tapInternalKey || input.tapKeySig || input.tapScriptSig || input.tapLeafScript) {
|
|
401
|
-
return true;
|
|
402
|
-
}
|
|
403
|
-
if (input.witnessUtxo) {
|
|
404
|
-
const script = input.witnessUtxo.script;
|
|
405
|
-
return script.length === 34 && script[0] === opcodes.OP_1 && script[1] === 0x20;
|
|
406
|
-
}
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
canSignNonTaprootInput(input, publicKey) {
|
|
410
|
-
const script = this.getInputRelevantScript(input);
|
|
411
|
-
if (script) {
|
|
412
|
-
return this.pubkeyInScript(publicKey, script);
|
|
413
|
-
}
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
getInputRelevantScript(input) {
|
|
417
|
-
if (input.redeemScript) {
|
|
418
|
-
return input.redeemScript;
|
|
419
|
-
}
|
|
420
|
-
if (input.witnessScript) {
|
|
421
|
-
return input.witnessScript;
|
|
422
|
-
}
|
|
423
|
-
if (input.witnessUtxo) {
|
|
424
|
-
return input.witnessUtxo.script;
|
|
425
|
-
}
|
|
426
|
-
if (input.nonWitnessUtxo) {
|
|
427
|
-
return null;
|
|
428
|
-
}
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
|
-
pubkeyInScript(pubkey, script) {
|
|
432
|
-
return this.pubkeyPositionInScript(pubkey, script) !== -1;
|
|
433
|
-
}
|
|
434
|
-
pubkeyPositionInScript(pubkey, script) {
|
|
435
|
-
const pubkeyHash = bitCrypto.hash160(pubkey);
|
|
436
|
-
const pubkeyXOnly = toXOnly(pubkey);
|
|
437
|
-
const decompiled = bscript.decompile(script);
|
|
438
|
-
if (decompiled === null)
|
|
439
|
-
throw new Error('Unknown script error');
|
|
440
|
-
return decompiled.findIndex((element) => {
|
|
441
|
-
if (typeof element === 'number')
|
|
442
|
-
return false;
|
|
443
|
-
return (element.equals(pubkey) || element.equals(pubkeyHash) || element.equals(pubkeyXOnly));
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
473
|
async signTaprootInput(signer, transaction, i, tapLeafHash) {
|
|
447
474
|
if ('signTaprootInput' in signer) {
|
|
448
475
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
2
|
export class BitcoinUtils {
|
|
3
3
|
static btcToSatoshi(btc) {
|
|
4
4
|
return BigInt(btc * 100000000);
|
|
@@ -15,13 +15,13 @@ export class BitcoinUtils {
|
|
|
15
15
|
window.crypto.getRandomValues(array);
|
|
16
16
|
return Buffer.from(array);
|
|
17
17
|
}
|
|
18
|
-
else if (crypto && typeof crypto.getRandomValues === 'function') {
|
|
18
|
+
else if (globalThis.crypto && typeof globalThis.crypto.getRandomValues === 'function') {
|
|
19
19
|
const array = new Uint8Array(length);
|
|
20
|
-
crypto.getRandomValues(array);
|
|
20
|
+
globalThis.crypto.getRandomValues(array);
|
|
21
21
|
return Buffer.from(array);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
console.log(`No secure random number generator available. Please upgrade your environment.`, globalThis.window.crypto, crypto);
|
|
24
|
+
console.log(`No secure random number generator available. Please upgrade your environment.`, globalThis.window.crypto, globalThis.crypto);
|
|
25
25
|
throw new Error('No secure random number generator available. Please upgrade your environment.');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -13,7 +13,7 @@ export class BufferHelper {
|
|
|
13
13
|
return buffer;
|
|
14
14
|
}
|
|
15
15
|
static uint8ArrayToHex(input) {
|
|
16
|
-
return Buffer.from(input, 0, input.byteLength).toString('hex');
|
|
16
|
+
return Buffer.from(input.buffer, 0, input.byteLength).toString('hex');
|
|
17
17
|
}
|
|
18
18
|
static hexToUint8Array(input) {
|
|
19
19
|
if (input.startsWith('0x')) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import { Taptree } from '@btc-vision/bitcoin/src/types.js';
|
|
1
|
+
import { Network, Taptree } from '@btc-vision/bitcoin';
|
|
3
2
|
export interface ContractAddressVerificationParams {
|
|
4
3
|
readonly deployerPubKey: Buffer;
|
|
5
4
|
readonly contractSaltPubKey: Buffer;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { crypto as bitCrypto, networks, payments } from '@btc-vision/bitcoin';
|
|
2
|
-
import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
|
|
1
|
+
import { crypto as bitCrypto, networks, payments, toXOnly, } from '@btc-vision/bitcoin';
|
|
3
2
|
import { DeploymentGenerator } from '../generators/builders/DeploymentGenerator.js';
|
|
4
3
|
import { TransactionBuilder } from '../transaction/builders/TransactionBuilder.js';
|
|
5
4
|
import { Address } from '../keypair/Address.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/transaction",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"author": "BlobMaster41",
|
|
6
6
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
7
7
|
"engines": {
|
|
@@ -63,9 +63,6 @@
|
|
|
63
63
|
"browserBuild": "webpack --mode production",
|
|
64
64
|
"docs": "typedoc --out docs --exclude 'src/tests/*.ts' --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/tests/test.ts --exclude src/index.ts src"
|
|
65
65
|
},
|
|
66
|
-
"peerDependencies": {
|
|
67
|
-
"@btc-vision/bitcoin": "^6.3.0"
|
|
68
|
-
},
|
|
69
66
|
"devDependencies": {
|
|
70
67
|
"@babel/core": "^7.26.0",
|
|
71
68
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
@@ -74,7 +71,7 @@
|
|
|
74
71
|
"@babel/preset-flow": "^7.25.9",
|
|
75
72
|
"@babel/preset-react": "^7.25.9",
|
|
76
73
|
"@babel/preset-typescript": "^7.26.0",
|
|
77
|
-
"@types/node": "^22.
|
|
74
|
+
"@types/node": "^22.10.2",
|
|
78
75
|
"@types/sha.js": "^2.4.4",
|
|
79
76
|
"eslint": "^9.14.0",
|
|
80
77
|
"gulp": "^5.0.0",
|
|
@@ -85,16 +82,14 @@
|
|
|
85
82
|
"prettier": "^3.3.3",
|
|
86
83
|
"stream-browserify": "^3.0.0",
|
|
87
84
|
"stream-http": "^3.2.0",
|
|
88
|
-
"typedoc": "^0.
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"webpack": "^5.96.1",
|
|
92
|
-
"webpack-cli": "^5.1.4"
|
|
85
|
+
"typedoc": "^0.27.6",
|
|
86
|
+
"typescript-eslint": "^8.19.0",
|
|
87
|
+
"webpack-cli": "^6.0.1"
|
|
93
88
|
},
|
|
94
89
|
"dependencies": {
|
|
95
90
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
96
91
|
"@bitcoinerlab/secp256k1": "^1.1.1",
|
|
97
|
-
"@btc-vision/bitcoin": "^6.3.
|
|
92
|
+
"@btc-vision/bitcoin": "^6.3.2",
|
|
98
93
|
"@btc-vision/bsi-bitcoin-rpc": "^1.0.29",
|
|
99
94
|
"@btc-vision/logger": "^1.0.6",
|
|
100
95
|
"@eslint/js": "^9.14.0",
|
|
@@ -105,6 +100,7 @@
|
|
|
105
100
|
"babel-preset-react": "^6.24.1",
|
|
106
101
|
"babelify": "^10.0.0",
|
|
107
102
|
"bech32": "^2.0.0",
|
|
103
|
+
"bip174": "^2.1.1",
|
|
108
104
|
"bip32": "^5.0.0-rc.0",
|
|
109
105
|
"browserify-zlib": "^0.2.0",
|
|
110
106
|
"buffer": "^6.0.3",
|
|
@@ -116,6 +112,7 @@
|
|
|
116
112
|
"sha.js": "^2.4.11",
|
|
117
113
|
"ts-loader": "^9.5.1",
|
|
118
114
|
"ts-node": "^10.9.2",
|
|
119
|
-
"typescript": "^5.
|
|
115
|
+
"typescript": "^5.7.2",
|
|
116
|
+
"webpack": "^5.97.1"
|
|
120
117
|
}
|
|
121
118
|
}
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.18';
|
|
@@ -17,7 +17,7 @@ export class BinaryReader {
|
|
|
17
17
|
private currentOffset: i32 = 0;
|
|
18
18
|
|
|
19
19
|
constructor(bytes: BufferLike) {
|
|
20
|
-
this.buffer = new DataView(bytes.buffer);
|
|
20
|
+
this.buffer = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public static stringCompare(a: string, b: string): number {
|
|
@@ -37,7 +37,7 @@ export class BinaryReader {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
public setBuffer(bytes: BufferLike): void {
|
|
40
|
-
this.buffer = new DataView(bytes.buffer);
|
|
40
|
+
this.buffer = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
41
41
|
|
|
42
42
|
this.currentOffset = 0;
|
|
43
43
|
}
|
|
@@ -354,7 +354,7 @@ export class BinaryWriter {
|
|
|
354
354
|
buf[i] = this.buffer.getUint8(i);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
this.buffer = new DataView(buf.buffer);
|
|
357
|
+
this.buffer = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
private getDefaultBuffer(length: number = 0): DataView {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { bech32, bech32m } from 'bech32';
|
|
2
|
-
import { initEccLib, Network } from '@btc-vision/bitcoin';
|
|
2
|
+
import { initEccLib, Network, ripemd160 } from '@btc-vision/bitcoin';
|
|
3
3
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
4
|
-
import { ripemd160 } from '@btc-vision/bitcoin/src/crypto.js';
|
|
5
4
|
|
|
6
5
|
initEccLib(ecc);
|
|
7
6
|
|
|
@@ -78,7 +78,11 @@ export class CalldataGenerator extends Generator {
|
|
|
78
78
|
this.senderFirstByte,
|
|
79
79
|
opcodes.OP_TOALTSTACK,
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
Buffer.from(
|
|
82
|
+
'060373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c6c4bc8c9ae26ed8f9831e3da372fbd26eaa48e9b788d1692b9d6f18393c58fc4',
|
|
83
|
+
'hex',
|
|
84
|
+
),
|
|
85
|
+
//this.xSenderPubKey,
|
|
82
86
|
opcodes.OP_CHECKSIGVERIFY,
|
|
83
87
|
|
|
84
88
|
this.contractSaltPubKey,
|
|
@@ -69,7 +69,11 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
69
69
|
if (!dataChunks.length) throw new Error('No data chunks found');
|
|
70
70
|
|
|
71
71
|
let compiledData = [
|
|
72
|
-
this.senderPubKey,
|
|
72
|
+
//this.senderPubKey,
|
|
73
|
+
Buffer.from(
|
|
74
|
+
'060373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c6c4bc8c9ae26ed8f9831e3da372fbd26eaa48e9b788d1692b9d6f18393c58fc4',
|
|
75
|
+
'hex',
|
|
76
|
+
),
|
|
73
77
|
opcodes.OP_CHECKSIGVERIFY,
|
|
74
78
|
|
|
75
79
|
contractSecret,
|