@btc-vision/transaction 1.8.0-beta.5 → 1.8.0-beta.7
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/btc-vision-bitcoin.js +181 -178
- package/browser/index.js +51 -51
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { B as H, p as Yt, m as wi, s as at, c as O, b as ve, L as
|
|
2
|
-
import {
|
|
3
|
-
import { s as
|
|
1
|
+
import { B as H, p as Yt, m as wi, s as at, c as O, b as ve, L as Ce, d as Rt, a as bt, e as ce, Y as De, f as mi } from "./vendors.js";
|
|
2
|
+
import { T as bi, o as b, v as k, s as y, F as v, S as ut, J as nt, B as P, z as f, A as Ai, a as g, I as X, W as Ii, d as Ti, l as Jt, U as D, V as C, i as Ei, b as Pi, E as vi, c as Re, p as Oi, C as V, e as te, f as K, r as Ui, N as Oe, g as ki, R as Bi, H as Ue, h as _i, L as ke, _ as Li, j as Ki, P as xi, k as Ci, m as Fe, x as B, q as ee } from "./btc-vision-bitcoin.js";
|
|
3
|
+
import { s as Di, m as Ri, b as Fi } from "./noble-curves.js";
|
|
4
4
|
import { w as Gt, d as Zt, f as Mi, x as Ni } from "./noble-hashes.js";
|
|
5
5
|
const Nt = Symbol;
|
|
6
6
|
typeof Nt.dispose != "symbol" && (Nt.dispose = /* @__PURE__ */ Symbol.for("Symbol.dispose"));
|
|
@@ -52,7 +52,7 @@ bi($i);
|
|
|
52
52
|
const Me = typeof ve == "function" ? ve : O.BIP32Factory;
|
|
53
53
|
if (!Me)
|
|
54
54
|
throw new Error("Failed to load BIP32 library");
|
|
55
|
-
const ht =
|
|
55
|
+
const ht = Di.Point, Xi = ht.Fn.ORDER, Yi = new Uint8Array([84, 97, 112, 84, 119, 101, 97, 107]), _e = Gt(Yi);
|
|
56
56
|
function Gi(n) {
|
|
57
57
|
return Gt(Mi(_e, _e, n));
|
|
58
58
|
}
|
|
@@ -2566,13 +2566,13 @@ class ue extends j {
|
|
|
2566
2566
|
this.xSenderPubKey,
|
|
2567
2567
|
f.OP_DUP,
|
|
2568
2568
|
f.OP_HASH256,
|
|
2569
|
-
|
|
2569
|
+
D.hash256(this.xSenderPubKey),
|
|
2570
2570
|
f.OP_EQUALVERIFY,
|
|
2571
2571
|
f.OP_CHECKSIGVERIFY,
|
|
2572
2572
|
this.contractSaltPubKey,
|
|
2573
2573
|
f.OP_CHECKSIGVERIFY,
|
|
2574
2574
|
f.OP_HASH160,
|
|
2575
|
-
|
|
2575
|
+
D.hash160(e),
|
|
2576
2576
|
f.OP_EQUALVERIFY,
|
|
2577
2577
|
f.OP_DEPTH,
|
|
2578
2578
|
f.OP_1,
|
|
@@ -2665,13 +2665,13 @@ class le extends j {
|
|
|
2665
2665
|
this.xSenderPubKey,
|
|
2666
2666
|
f.OP_DUP,
|
|
2667
2667
|
f.OP_HASH256,
|
|
2668
|
-
|
|
2668
|
+
D.hash256(this.xSenderPubKey),
|
|
2669
2669
|
f.OP_EQUALVERIFY,
|
|
2670
2670
|
f.OP_CHECKSIGVERIFY,
|
|
2671
2671
|
this.contractSaltPubKey,
|
|
2672
2672
|
f.OP_CHECKSIGVERIFY,
|
|
2673
2673
|
f.OP_HASH256,
|
|
2674
|
-
|
|
2674
|
+
D.hash256(e),
|
|
2675
2675
|
f.OP_EQUALVERIFY,
|
|
2676
2676
|
f.OP_DEPTH,
|
|
2677
2677
|
f.OP_1,
|
|
@@ -2689,7 +2689,7 @@ class le extends j {
|
|
|
2689
2689
|
].flat();
|
|
2690
2690
|
}
|
|
2691
2691
|
}
|
|
2692
|
-
class T extends
|
|
2692
|
+
class T extends Ce {
|
|
2693
2693
|
/**
|
|
2694
2694
|
* Maximum chunk size per Bitcoin P2WSH stack item limit.
|
|
2695
2695
|
* See policy.h: MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80
|
|
@@ -2873,8 +2873,8 @@ class T extends De {
|
|
|
2873
2873
|
if (!i || i.length !== t.length)
|
|
2874
2874
|
return !1;
|
|
2875
2875
|
for (let r = 0; r < t.length; r++) {
|
|
2876
|
-
const s =
|
|
2877
|
-
if (!
|
|
2876
|
+
const s = D.hash160(t[r]);
|
|
2877
|
+
if (!C(i[r], s))
|
|
2878
2878
|
return !1;
|
|
2879
2879
|
}
|
|
2880
2880
|
return !0;
|
|
@@ -2907,7 +2907,7 @@ class T extends De {
|
|
|
2907
2907
|
* HASH160 = RIPEMD160(SHA256(data))
|
|
2908
2908
|
*/
|
|
2909
2909
|
hashChunk(t) {
|
|
2910
|
-
return
|
|
2910
|
+
return D.hash160(t);
|
|
2911
2911
|
}
|
|
2912
2912
|
/**
|
|
2913
2913
|
* Generate a hash-committed witness script for multiple data chunks.
|
|
@@ -3063,7 +3063,7 @@ class sr extends j {
|
|
|
3063
3063
|
this.senderPubKey,
|
|
3064
3064
|
f.OP_DUP,
|
|
3065
3065
|
f.OP_HASH256,
|
|
3066
|
-
|
|
3066
|
+
D.hash256(this.senderPubKey),
|
|
3067
3067
|
f.OP_EQUALVERIFY,
|
|
3068
3068
|
f.OP_CHECKSIGVERIFY,
|
|
3069
3069
|
e,
|
|
@@ -3101,12 +3101,12 @@ class _t {
|
|
|
3101
3101
|
);
|
|
3102
3102
|
const r = Jt(1);
|
|
3103
3103
|
r[0] = e, t = t.filter(
|
|
3104
|
-
(h, p, d) => p === d.findIndex((w) =>
|
|
3104
|
+
(h, p, d) => p === d.findIndex((w) => C(h, w))
|
|
3105
3105
|
), t = t.sort((h, p) => Ei(h, p));
|
|
3106
3106
|
let s = !1;
|
|
3107
3107
|
const o = t.map((h) => {
|
|
3108
3108
|
const p = v(h);
|
|
3109
|
-
return i && !s && (s =
|
|
3109
|
+
return i && !s && (s = C(i, p)), p;
|
|
3110
3110
|
});
|
|
3111
3111
|
i && !s && o.push(i);
|
|
3112
3112
|
const c = [
|
|
@@ -3233,11 +3233,11 @@ class rt {
|
|
|
3233
3233
|
if (!a || a.length === 0)
|
|
3234
3234
|
return !1;
|
|
3235
3235
|
const c = a[a.length - 1];
|
|
3236
|
-
return
|
|
3236
|
+
return C(c, e);
|
|
3237
3237
|
}
|
|
3238
3238
|
static getContractSeed(t, e, i) {
|
|
3239
|
-
const r =
|
|
3240
|
-
return
|
|
3239
|
+
const r = D.hash256(e), s = ut([t, i, r]);
|
|
3240
|
+
return D.hash256(s);
|
|
3241
3241
|
}
|
|
3242
3242
|
static generateAddressFromScript(t, e) {
|
|
3243
3243
|
const i = t.network || b.bitcoin, r = {
|
|
@@ -3304,7 +3304,7 @@ function $e(n) {
|
|
|
3304
3304
|
}
|
|
3305
3305
|
class nr {
|
|
3306
3306
|
sha256(t) {
|
|
3307
|
-
return
|
|
3307
|
+
return D.sha256(t);
|
|
3308
3308
|
}
|
|
3309
3309
|
async trySignSchnorrWithOPWallet(t) {
|
|
3310
3310
|
const e = this.getOPWallet();
|
|
@@ -3935,7 +3935,7 @@ class lr extends we {
|
|
|
3935
3935
|
}
|
|
3936
3936
|
if (!h && u.tapInternalKey) {
|
|
3937
3937
|
const d = u.tapInternalKey, w = v(this.publicKey);
|
|
3938
|
-
|
|
3938
|
+
C(d, w) && (h = !0, p = !0);
|
|
3939
3939
|
}
|
|
3940
3940
|
} else ye(u, this.publicKey) && (h = !0, p = !1);
|
|
3941
3941
|
return h ? {
|
|
@@ -3955,7 +3955,7 @@ class lr extends we {
|
|
|
3955
3955
|
hasAlreadySignedTapScriptSig(t) {
|
|
3956
3956
|
for (let e = 0; e < t.length; e++) {
|
|
3957
3957
|
const i = t[e], r = new Uint8Array(i.pubkey);
|
|
3958
|
-
if (
|
|
3958
|
+
if (C(r, this.publicKey) && i.signature)
|
|
3959
3959
|
return !0;
|
|
3960
3960
|
}
|
|
3961
3961
|
return !1;
|
|
@@ -3963,7 +3963,7 @@ class lr extends we {
|
|
|
3963
3963
|
hasAlreadyPartialSig(t) {
|
|
3964
3964
|
for (let e = 0; e < t.length; e++) {
|
|
3965
3965
|
const i = t[e], r = new Uint8Array(i.pubkey);
|
|
3966
|
-
if (
|
|
3966
|
+
if (C(r, this.publicKey) && i.signature)
|
|
3967
3967
|
return !0;
|
|
3968
3968
|
}
|
|
3969
3969
|
return !1;
|
|
@@ -4000,7 +4000,7 @@ class lr extends we {
|
|
|
4000
4000
|
const i = [];
|
|
4001
4001
|
for (let r = 0; r < e.length; r++) {
|
|
4002
4002
|
const s = e[r];
|
|
4003
|
-
t.find((a) =>
|
|
4003
|
+
t.find((a) => C(a.pubkey, s.pubkey)) || i.push(s);
|
|
4004
4004
|
}
|
|
4005
4005
|
return i;
|
|
4006
4006
|
}
|
|
@@ -4009,9 +4009,9 @@ function hr(n, t) {
|
|
|
4009
4009
|
return dr(n, t) !== -1;
|
|
4010
4010
|
}
|
|
4011
4011
|
function dr(n, t) {
|
|
4012
|
-
const e =
|
|
4012
|
+
const e = D.hash160(n), i = v(n), r = P.decompile(t);
|
|
4013
4013
|
if (r === null) throw new Error("Unknown script error");
|
|
4014
|
-
return r.findIndex((s) => typeof s == "number" ? !1 : s instanceof Uint8Array && (
|
|
4014
|
+
return r.findIndex((s) => typeof s == "number" ? !1 : s instanceof Uint8Array && (C(s, n) || C(s, e) || C(s, i)));
|
|
4015
4015
|
}
|
|
4016
4016
|
function Ze(n) {
|
|
4017
4017
|
return new Map(n);
|
|
@@ -4034,7 +4034,7 @@ function gr(n) {
|
|
|
4034
4034
|
getPrivateKey() {
|
|
4035
4035
|
if (!n.privateKey)
|
|
4036
4036
|
throw new Error("Signer does not have a private key");
|
|
4037
|
-
return
|
|
4037
|
+
return De(n.privateKey);
|
|
4038
4038
|
},
|
|
4039
4039
|
sign(t, e) {
|
|
4040
4040
|
return n.sign(t, e);
|
|
@@ -4052,7 +4052,7 @@ function Je(n, t) {
|
|
|
4052
4052
|
getPrivateKey() {
|
|
4053
4053
|
if (!t.privateKey)
|
|
4054
4054
|
throw new Error("Tweaked signer does not have a private key");
|
|
4055
|
-
return
|
|
4055
|
+
return De(t.privateKey);
|
|
4056
4056
|
},
|
|
4057
4057
|
sign(e, i) {
|
|
4058
4058
|
return t.sign(e, i);
|
|
@@ -4089,7 +4089,7 @@ function ne(n) {
|
|
|
4089
4089
|
return o(n), t;
|
|
4090
4090
|
}
|
|
4091
4091
|
var ti = /* @__PURE__ */ ((n) => (n[n.REPLACE_BY_FEE = 4294967293] = "REPLACE_BY_FEE", n[n.FINAL = 4294967295] = "FINAL", n))(ti || {}), ei = /* @__PURE__ */ ((n) => (n[n.BLOCKS = 0] = "BLOCKS", n[n.TIMESTAMPS = 1] = "TIMESTAMPS", n))(ei || {});
|
|
4092
|
-
class jt extends
|
|
4092
|
+
class jt extends Ce {
|
|
4093
4093
|
logColor = "#00ffe1";
|
|
4094
4094
|
finalized = !1;
|
|
4095
4095
|
/**
|
|
@@ -4633,13 +4633,13 @@ class jt extends De {
|
|
|
4633
4633
|
}).output;
|
|
4634
4634
|
}
|
|
4635
4635
|
generateP2SHRedeemScriptLegacy(t) {
|
|
4636
|
-
const e =
|
|
4636
|
+
const e = D.hash160(this.signer.publicKey), i = P.compile([
|
|
4637
4637
|
f.OP_DUP,
|
|
4638
4638
|
f.OP_HASH160,
|
|
4639
4639
|
e,
|
|
4640
4640
|
f.OP_EQUALVERIFY,
|
|
4641
4641
|
f.OP_CHECKSIG
|
|
4642
|
-
]), r =
|
|
4642
|
+
]), r = D.hash160(i), s = P.compile([
|
|
4643
4643
|
f.OP_HASH160,
|
|
4644
4644
|
r,
|
|
4645
4645
|
f.OP_EQUAL
|
|
@@ -4732,7 +4732,7 @@ class jt extends De {
|
|
|
4732
4732
|
this.addressRotationEnabled ? s.tapInternalKey = this.internalPubKeyToXOnlyForInput(e) : (this.tweakSigner(), s.tapInternalKey = this.internalPubKeyToXOnly());
|
|
4733
4733
|
} else if (Ki(r))
|
|
4734
4734
|
this.anchorInputIndices.add(e), s.isPayToAnchor = !0;
|
|
4735
|
-
else if (xi(r) ||
|
|
4735
|
+
else if (xi(r) || Ci(r))
|
|
4736
4736
|
if (t.nonWitnessUtxo)
|
|
4737
4737
|
s.nonWitnessUtxo = t.nonWitnessUtxo instanceof Uint8Array ? t.nonWitnessUtxo : y(t.nonWitnessUtxo);
|
|
4738
4738
|
else
|
|
@@ -5292,7 +5292,7 @@ class A extends jt {
|
|
|
5292
5292
|
throw new Error("Output value is 0 and no script provided");
|
|
5293
5293
|
if (i.script.length < 2)
|
|
5294
5294
|
throw new Error("Output script is too short");
|
|
5295
|
-
if (i.script[0] !== f.OP_RETURN && !
|
|
5295
|
+
if (i.script[0] !== f.OP_RETURN && !C(i.script, oe))
|
|
5296
5296
|
throw new Error(
|
|
5297
5297
|
"Output script must start with OP_RETURN or be an ANCHOR when value is 0"
|
|
5298
5298
|
);
|
|
@@ -5397,14 +5397,14 @@ class A extends jt {
|
|
|
5397
5397
|
if (S && S.length >= 4) {
|
|
5398
5398
|
const I = S[0], F = S[S.length - 1];
|
|
5399
5399
|
if (typeof I == "number" && I >= f.OP_1 && F === f.OP_CHECKMULTISIG) {
|
|
5400
|
-
const xt = I - f.OP_1 + 1,
|
|
5401
|
-
for (let
|
|
5402
|
-
|
|
5400
|
+
const xt = I - f.OP_1 + 1, Ct = [];
|
|
5401
|
+
for (let Dt = 0; Dt < xt; Dt++)
|
|
5402
|
+
Ct.push(s);
|
|
5403
5403
|
return {
|
|
5404
5404
|
finalScriptWitness: A.witnessStackToScriptWitness([
|
|
5405
5405
|
new Uint8Array(0),
|
|
5406
5406
|
// OP_0 due to multisig bug
|
|
5407
|
-
...
|
|
5407
|
+
...Ct,
|
|
5408
5408
|
d.witnessScript
|
|
5409
5409
|
])
|
|
5410
5410
|
};
|
|
@@ -6085,7 +6085,7 @@ class zt extends A {
|
|
|
6085
6085
|
* @private
|
|
6086
6086
|
*/
|
|
6087
6087
|
getContractSeed() {
|
|
6088
|
-
return
|
|
6088
|
+
return D.hash256(this.randomBytes);
|
|
6089
6089
|
}
|
|
6090
6090
|
/**
|
|
6091
6091
|
* Finalize the transaction
|
|
@@ -6701,8 +6701,8 @@ class wt extends A {
|
|
|
6701
6701
|
getContractSeed() {
|
|
6702
6702
|
if (!this.bytecode)
|
|
6703
6703
|
throw new Error("Bytecode is required");
|
|
6704
|
-
const t = this.internalPubKeyToXOnly(), e =
|
|
6705
|
-
return
|
|
6704
|
+
const t = this.internalPubKeyToXOnly(), e = D.hash256(this.randomBytes), i = D.hash256(this.bytecode), r = ut([t, e, i]);
|
|
6705
|
+
return D.hash256(r);
|
|
6706
6706
|
}
|
|
6707
6707
|
/**
|
|
6708
6708
|
* Finalize the transaction
|
|
@@ -7776,8 +7776,8 @@ class ri {
|
|
|
7776
7776
|
{ ...t, optionalInputs: i },
|
|
7777
7777
|
wt,
|
|
7778
7778
|
async (xt) => {
|
|
7779
|
-
const
|
|
7780
|
-
return
|
|
7779
|
+
const Ct = await xt.estimateTransactionFees(), Dt = this.getPriorityFee(t), Si = xt.getOptionalOutputValue();
|
|
7780
|
+
return Ct + Dt + Si;
|
|
7781
7781
|
},
|
|
7782
7782
|
"Deployment"
|
|
7783
7783
|
);
|
|
@@ -8165,7 +8165,7 @@ class _ extends A {
|
|
|
8165
8165
|
if (super({
|
|
8166
8166
|
...t,
|
|
8167
8167
|
signer: E.fromPrivateKey(
|
|
8168
|
-
|
|
8168
|
+
D.sha256(new TextEncoder().encode("aaaaaaaa"))
|
|
8169
8169
|
),
|
|
8170
8170
|
priorityFee: 0n,
|
|
8171
8171
|
gasSatFee: 0n
|
|
@@ -8206,7 +8206,7 @@ class _ extends A {
|
|
|
8206
8206
|
if (!(o.length < 3))
|
|
8207
8207
|
for (let a = 0; a < o.length - 2; a += 3) {
|
|
8208
8208
|
const c = o[a + 2];
|
|
8209
|
-
if (
|
|
8209
|
+
if (C(c, e)) {
|
|
8210
8210
|
i = !0;
|
|
8211
8211
|
break;
|
|
8212
8212
|
}
|
|
@@ -8281,7 +8281,7 @@ class _ extends A {
|
|
|
8281
8281
|
for (const u of r) {
|
|
8282
8282
|
let l = !1;
|
|
8283
8283
|
for (const h of e.tapScriptSig)
|
|
8284
|
-
|
|
8284
|
+
C(h.pubkey, v(u)) && (o.push(h.signature), l = !0);
|
|
8285
8285
|
l || o.push(new Uint8Array(0));
|
|
8286
8286
|
}
|
|
8287
8287
|
o = o.reverse();
|
|
@@ -9334,7 +9334,7 @@ class dt {
|
|
|
9334
9334
|
* Calculate SHA-1 hash
|
|
9335
9335
|
*/
|
|
9336
9336
|
static sha1(t) {
|
|
9337
|
-
return
|
|
9337
|
+
return D.sha1(t);
|
|
9338
9338
|
}
|
|
9339
9339
|
/**
|
|
9340
9340
|
* Calculate mining preimage
|
|
@@ -9378,7 +9378,7 @@ class dt {
|
|
|
9378
9378
|
t.publicKey.toBuffer(),
|
|
9379
9379
|
t.salt
|
|
9380
9380
|
), s = this.sha1(r);
|
|
9381
|
-
if (!
|
|
9381
|
+
if (!C(s, t.solution) || this.countMatchingBits(s, i.targetHash) !== t.difficulty)
|
|
9382
9382
|
return !1;
|
|
9383
9383
|
const a = t.epochNumber * this.BLOCKS_PER_EPOCH, c = a + this.BLOCKS_PER_EPOCH - 1n;
|
|
9384
9384
|
return !(i.startBlock !== a || i.endBlock !== c);
|
|
@@ -9413,7 +9413,7 @@ class dt {
|
|
|
9413
9413
|
i.toBuffer(),
|
|
9414
9414
|
s
|
|
9415
9415
|
), u = this.sha1(c);
|
|
9416
|
-
if (!
|
|
9416
|
+
if (!C(u, r) || this.countMatchingBits(u, a.targetHash) !== o)
|
|
9417
9417
|
return !1;
|
|
9418
9418
|
const h = e * this.BLOCKS_PER_EPOCH, p = h + this.BLOCKS_PER_EPOCH - 1n;
|
|
9419
9419
|
return !(a.startBlock !== h || a.endBlock !== p);
|
|
@@ -10832,7 +10832,7 @@ class Tr extends we {
|
|
|
10832
10832
|
}
|
|
10833
10833
|
if (!p && l.tapInternalKey) {
|
|
10834
10834
|
const w = l.tapInternalKey, S = v(this.publicKey);
|
|
10835
|
-
|
|
10835
|
+
C(w, S) && (p = !0, d = !0);
|
|
10836
10836
|
}
|
|
10837
10837
|
} else ye(l, this.publicKey) && (p = !0, d = !1);
|
|
10838
10838
|
return p ? {
|
|
@@ -10859,7 +10859,7 @@ class Tr extends we {
|
|
|
10859
10859
|
hasAlreadySignedTapScriptSig(t) {
|
|
10860
10860
|
for (let e = 0; e < t.length; e++) {
|
|
10861
10861
|
const i = t[e], r = new Uint8Array(i.pubkey);
|
|
10862
|
-
if (
|
|
10862
|
+
if (C(r, this.publicKey) && i.signature)
|
|
10863
10863
|
return !0;
|
|
10864
10864
|
}
|
|
10865
10865
|
return !1;
|
|
@@ -10867,7 +10867,7 @@ class Tr extends we {
|
|
|
10867
10867
|
hasAlreadyPartialSig(t) {
|
|
10868
10868
|
for (let e = 0; e < t.length; e++) {
|
|
10869
10869
|
const i = t[e], r = new Uint8Array(i.pubkey);
|
|
10870
|
-
if (
|
|
10870
|
+
if (C(r, this.publicKey) && i.signature)
|
|
10871
10871
|
return !0;
|
|
10872
10872
|
}
|
|
10873
10873
|
return !1;
|
|
@@ -10909,7 +10909,7 @@ class Tr extends we {
|
|
|
10909
10909
|
const i = [];
|
|
10910
10910
|
for (let r = 0; r < e.length; r++) {
|
|
10911
10911
|
const s = e[r];
|
|
10912
|
-
t.find((a) =>
|
|
10912
|
+
t.find((a) => C(a.pubkey, s.pubkey)) || i.push(s);
|
|
10913
10913
|
}
|
|
10914
10914
|
return i;
|
|
10915
10915
|
}
|