@qntx/wallet-worker 0.13.0 → 0.14.1
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/README.md +38 -3
- package/dist/kernel.manifest.json +30 -20
- package/dist/kernel.node.js +35206 -6807
- package/dist/kernel.worker.js +37113 -8695
- package/dist/{node-k5etevb7.js → node-2mp4qyt2.js} +72 -63
- package/dist/node.mjs +46 -22
- package/dist/node.mjs.map +1 -1
- package/dist/{signer-h69ffzx5.js → signer-pydq66hv.js} +1 -1
- package/dist/{worker-k5etevb7.js → worker-2mp4qyt2.js} +72 -63
- package/package.json +13 -17
|
@@ -28,6 +28,9 @@ function abytes(value, length, title = "") {
|
|
|
28
28
|
throw new TypeError(message);
|
|
29
29
|
throw new RangeError(message);
|
|
30
30
|
}
|
|
31
|
+
function copyBytes(bytes) {
|
|
32
|
+
return Uint8Array.from(abytes(bytes));
|
|
33
|
+
}
|
|
31
34
|
function ahash(h) {
|
|
32
35
|
if (typeof h !== "function" || typeof h.create !== "function")
|
|
33
36
|
throw new TypeError("expected hash wrapped by utils.createHasher");
|
|
@@ -61,6 +64,9 @@ function aoutput(out, instance) {
|
|
|
61
64
|
throw new RangeError('"output" expected length >= ' + min);
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
function u8(arr) {
|
|
68
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
69
|
+
}
|
|
64
70
|
function u32(arr) {
|
|
65
71
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
66
72
|
}
|
|
@@ -82,6 +88,7 @@ var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).bu
|
|
|
82
88
|
function byteSwap(word) {
|
|
83
89
|
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
84
90
|
}
|
|
91
|
+
var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
85
92
|
function byteSwap32(arr) {
|
|
86
93
|
for (let i = 0;i < arr.length; i++) {
|
|
87
94
|
arr[i] = byteSwap(arr[i]);
|
|
@@ -252,6 +259,8 @@ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
|
252
259
|
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
253
260
|
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
254
261
|
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
262
|
+
var rotr32H = (_h, l) => l;
|
|
263
|
+
var rotr32L = (h, _l) => h;
|
|
255
264
|
function add(Ah, Al, Bh, Bl) {
|
|
256
265
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
257
266
|
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
@@ -849,7 +858,7 @@ function bytesToNumberBE(bytes) {
|
|
|
849
858
|
return hexToNumber(bytesToHex(bytes));
|
|
850
859
|
}
|
|
851
860
|
function bytesToNumberLE(bytes) {
|
|
852
|
-
return hexToNumber(bytesToHex(
|
|
861
|
+
return hexToNumber(bytesToHex(copyBytes2(abytes(bytes)).reverse()));
|
|
853
862
|
}
|
|
854
863
|
function numberToBytesBE(n, len) {
|
|
855
864
|
anumber(len);
|
|
@@ -875,7 +884,7 @@ function equalBytes(a, b) {
|
|
|
875
884
|
diff |= a[i] ^ b[i];
|
|
876
885
|
return diff === 0;
|
|
877
886
|
}
|
|
878
|
-
function
|
|
887
|
+
function copyBytes2(bytes) {
|
|
879
888
|
return Uint8Array.from(abytes2(bytes));
|
|
880
889
|
}
|
|
881
890
|
function asciiToBytes(ascii) {
|
|
@@ -2854,7 +2863,7 @@ function schnorrGetPublicKey(secretKey) {
|
|
|
2854
2863
|
}
|
|
2855
2864
|
function schnorrSign(message, secretKey, auxRand = randomBytes(32)) {
|
|
2856
2865
|
const { Fn, BASE } = Pointk1;
|
|
2857
|
-
const m =
|
|
2866
|
+
const m = copyBytes2(abytes2(message, undefined, "message"));
|
|
2858
2867
|
const { bytes: px, scalar: d } = schnorrGetExtPubKey(secretKey);
|
|
2859
2868
|
const a = abytes2(auxRand, 32, "auxRand");
|
|
2860
2869
|
const t = Fn.toBytes(d ^ num(taggedHash("BIP0340/aux", a)));
|
|
@@ -3729,7 +3738,7 @@ var MASTER_SECRET = /* @__PURE__ */ (() => {
|
|
|
3729
3738
|
var BITCOIN_VERSIONS = { private: 76066276, public: 76067358 };
|
|
3730
3739
|
var HARDENED_OFFSET = 2147483648;
|
|
3731
3740
|
var MAX_DEPTH = 255;
|
|
3732
|
-
var
|
|
3741
|
+
var hash1602 = (data) => ripemd160(sha256(data));
|
|
3733
3742
|
var fromU32 = (data) => createView(data).getUint32(0, false);
|
|
3734
3743
|
var toU32 = (n, title = "number") => {
|
|
3735
3744
|
if (typeof n !== "number")
|
|
@@ -3866,7 +3875,7 @@ class HDKey {
|
|
|
3866
3875
|
} else {
|
|
3867
3876
|
throw new Error("HDKey: no public or private key provided");
|
|
3868
3877
|
}
|
|
3869
|
-
this._pubHash =
|
|
3878
|
+
this._pubHash = hash1602(this._publicKey);
|
|
3870
3879
|
}
|
|
3871
3880
|
derive(path) {
|
|
3872
3881
|
if (!/^[mM]'?/.test(path)) {
|
|
@@ -4005,7 +4014,7 @@ var validateFieldName = (name, label) => {
|
|
|
4005
4014
|
if (restrictedKeys.has(name))
|
|
4006
4015
|
throw new Error(`${label} ${name} is reserved`);
|
|
4007
4016
|
};
|
|
4008
|
-
function
|
|
4017
|
+
function equalBytes3(a, b) {
|
|
4009
4018
|
if (a.length !== b.length)
|
|
4010
4019
|
return false;
|
|
4011
4020
|
for (let i = 0;i < a.length; i++)
|
|
@@ -4045,13 +4054,13 @@ function equal(a, b) {
|
|
|
4045
4054
|
const aBytes = isBytes4(a);
|
|
4046
4055
|
const bBytes = isBytes4(b);
|
|
4047
4056
|
if (aBytes || bBytes)
|
|
4048
|
-
return aBytes && bBytes &&
|
|
4057
|
+
return aBytes && bBytes && equalBytes3(a, b);
|
|
4049
4058
|
return a === b;
|
|
4050
4059
|
}
|
|
4051
4060
|
function isBytes4(a) {
|
|
4052
4061
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
4053
4062
|
}
|
|
4054
|
-
function
|
|
4063
|
+
function concatBytes4(...arrays) {
|
|
4055
4064
|
let sum = 0;
|
|
4056
4065
|
for (let i = 0;i < arrays.length; i++) {
|
|
4057
4066
|
const a = arrays[i];
|
|
@@ -4082,11 +4091,11 @@ function isNum(num) {
|
|
|
4082
4091
|
}
|
|
4083
4092
|
var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
4084
4093
|
var utils = /* @__PURE__ */ Object.freeze({
|
|
4085
|
-
equalBytes:
|
|
4094
|
+
equalBytes: equalBytes3,
|
|
4086
4095
|
isBytes: isBytes4,
|
|
4087
4096
|
isCoder,
|
|
4088
4097
|
checkBounds,
|
|
4089
|
-
concatBytes:
|
|
4098
|
+
concatBytes: concatBytes4,
|
|
4090
4099
|
createView: createView2,
|
|
4091
4100
|
isPlainObject
|
|
4092
4101
|
});
|
|
@@ -5103,7 +5112,7 @@ var flag = (flagValue, xor = false) => {
|
|
|
5103
5112
|
decodeStream: (r) => {
|
|
5104
5113
|
let hasFlag = r.leftBytes >= marker.length;
|
|
5105
5114
|
if (hasFlag) {
|
|
5106
|
-
hasFlag =
|
|
5115
|
+
hasFlag = equalBytes3(r.bytes(marker.length, true), marker);
|
|
5107
5116
|
if (hasFlag)
|
|
5108
5117
|
r.bytes(marker.length);
|
|
5109
5118
|
}
|
|
@@ -5259,7 +5268,7 @@ function array(len, inner) {
|
|
|
5259
5268
|
inner.encodeStream(w, elm);
|
|
5260
5269
|
if (terminator && terminator.length <= _w.pos - startPos) {
|
|
5261
5270
|
const data = _w.finish(false).subarray(startPos, _w.pos);
|
|
5262
|
-
if (
|
|
5271
|
+
if (equalBytes3(data.subarray(0, terminator.length), terminator))
|
|
5263
5272
|
throw _w.err(`array: inner element encoding same as separator. elm=${elm} data=${data}`);
|
|
5264
5273
|
}
|
|
5265
5274
|
_w.exitField();
|
|
@@ -5285,7 +5294,7 @@ function array(len, inner) {
|
|
|
5285
5294
|
}
|
|
5286
5295
|
} else if (terminator) {
|
|
5287
5296
|
for (let i = 0;; i++) {
|
|
5288
|
-
if (
|
|
5297
|
+
if (equalBytes3(r.bytes(terminator.length, true), terminator)) {
|
|
5289
5298
|
r.bytes(terminator.length);
|
|
5290
5299
|
break;
|
|
5291
5300
|
}
|
|
@@ -5350,11 +5359,11 @@ var _0n8 = /* @__PURE__ */ BigInt(0);
|
|
|
5350
5359
|
var _2n5 = /* @__PURE__ */ BigInt(2);
|
|
5351
5360
|
var hasEven2 = (y) => y % _2n5 === _0n8;
|
|
5352
5361
|
var isBytes5 = /* @__PURE__ */ (() => utils.isBytes)();
|
|
5353
|
-
var
|
|
5354
|
-
var
|
|
5362
|
+
var concatBytes3 = /* @__PURE__ */ (() => utils.concatBytes)();
|
|
5363
|
+
var equalBytes2 = /* @__PURE__ */ (() => utils.equalBytes)();
|
|
5355
5364
|
var sha2562 = /* @__PURE__ */ (() => sha256)();
|
|
5356
|
-
var
|
|
5357
|
-
var sha256x2 = (...msgs) => sha2562(sha2562(
|
|
5365
|
+
var hash160 = (msg) => ripemd160(sha2562(msg));
|
|
5366
|
+
var sha256x2 = (...msgs) => sha2562(sha2562(concatBytes3(...msgs)));
|
|
5358
5367
|
var pubSchnorr = (priv) => schnorr.getPublicKey(priv);
|
|
5359
5368
|
var pubECDSA = (privateKey, isCompressed) => secp256k1.getPublicKey(privateKey, isCompressed);
|
|
5360
5369
|
var LOW_R_BOUND = /* @__PURE__ */ (() => CURVE_ORDER / _2n5)();
|
|
@@ -6308,7 +6317,7 @@ function mergeKeyMap(psbtEnum, val, cur, allowedFields, unknown = "strip", propr
|
|
|
6308
6317
|
let current = _cur[k];
|
|
6309
6318
|
if (typeof current === "string")
|
|
6310
6319
|
current = vC.decode(hex.decode(current));
|
|
6311
|
-
if (!
|
|
6320
|
+
if (!equalBytes2(vC.encode(res[k]), vC.encode(current)))
|
|
6312
6321
|
throw new Error(`Cannot change signed field=${k}`);
|
|
6313
6322
|
}
|
|
6314
6323
|
}
|
|
@@ -6360,7 +6369,7 @@ function combineKeyMap(psbtEnum, current, other, unknown = "strip", proprietary
|
|
|
6360
6369
|
a = valueCoder.decode(hex.decode(a));
|
|
6361
6370
|
if (typeof b === "string")
|
|
6362
6371
|
b = valueCoder.decode(hex.decode(b));
|
|
6363
|
-
if (!
|
|
6372
|
+
if (!equalBytes2(valueCoder.encode(a), valueCoder.encode(b)))
|
|
6364
6373
|
throw new Error(`Cannot combine conflicting field=${k}`);
|
|
6365
6374
|
}
|
|
6366
6375
|
return mergeKeyMap(psbtEnum, _other, _current, undefined, unknown, proprietary);
|
|
@@ -6372,7 +6381,7 @@ var RawPSBTV2 = /* @__PURE__ */ (() => Object.freeze(validate(_RawPSBTV2, valida
|
|
|
6372
6381
|
var P2A_PROGRAM = /* @__PURE__ */ Uint8Array.from([78, 115]);
|
|
6373
6382
|
var OutP2A = {
|
|
6374
6383
|
encode(from) {
|
|
6375
|
-
if (from.length !== 2 || from[0] !== 1 || !isBytes5(from[1]) || !
|
|
6384
|
+
if (from.length !== 2 || from[0] !== 1 || !isBytes5(from[1]) || !equalBytes2(from[1], P2A_PROGRAM))
|
|
6376
6385
|
return;
|
|
6377
6386
|
return { type: "p2a", script: Script.encode(from) };
|
|
6378
6387
|
},
|
|
@@ -6603,13 +6612,13 @@ var _WitnessOutScript = /* @__PURE__ */ (() => Object.freeze(wrap({
|
|
|
6603
6612
|
decodeStream: (r) => {
|
|
6604
6613
|
const raw = r.bytes(r.leftBytes);
|
|
6605
6614
|
const out = OutScript.decode(raw);
|
|
6606
|
-
if (out && (out.type === "p2a" || out.type === "wpkh" || out.type === "wsh" || out.type === "tr") && !
|
|
6615
|
+
if (out && (out.type === "p2a" || out.type === "wpkh" || out.type === "wsh" || out.type === "tr") && !equalBytes2(raw, OutScript.encode(out)))
|
|
6607
6616
|
throw new Error("OutScript: non-canonical witness program");
|
|
6608
6617
|
return out;
|
|
6609
6618
|
}
|
|
6610
6619
|
})))();
|
|
6611
6620
|
function checkWSH(s, witnessScript) {
|
|
6612
|
-
if (!
|
|
6621
|
+
if (!equalBytes2(s.hash, sha2562(witnessScript)))
|
|
6613
6622
|
throw new Error("checkScript: wsh wrong witnessScript hash");
|
|
6614
6623
|
const w = OutScript.decode(witnessScript);
|
|
6615
6624
|
if (w.type === "tr" || w.type === "tr_ns" || w.type === "tr_ms")
|
|
@@ -6627,7 +6636,7 @@ function checkScript(script, redeemScript, witnessScript) {
|
|
|
6627
6636
|
if (redeemScript) {
|
|
6628
6637
|
if (s.type !== "sh")
|
|
6629
6638
|
throw new Error("checkScript: redeemScript without P2SH");
|
|
6630
|
-
if (!
|
|
6639
|
+
if (!equalBytes2(s.hash, hash160(redeemScript)))
|
|
6631
6640
|
throw new Error("checkScript: sh wrong redeemScript hash");
|
|
6632
6641
|
r = _WitnessOutScript.decode(redeemScript);
|
|
6633
6642
|
if (r?.type === "tr" || r?.type === "tr_ns" || r?.type === "tr_ms")
|
|
@@ -6656,7 +6665,7 @@ function checkScript(script, redeemScript, witnessScript) {
|
|
|
6656
6665
|
var p2pkh = (publicKey, network = NETWORK) => {
|
|
6657
6666
|
if (!isValidPubkey(publicKey, PubT.ecdsa))
|
|
6658
6667
|
throw new Error("P2PKH: invalid publicKey");
|
|
6659
|
-
const hash =
|
|
6668
|
+
const hash = hash160(publicKey);
|
|
6660
6669
|
return {
|
|
6661
6670
|
type: "pkh",
|
|
6662
6671
|
script: OutScript.encode({ type: "pkh", hash }),
|
|
@@ -6669,7 +6678,7 @@ var checkCanonicalScript = (script, name, allowNonCanonicalScript) => {
|
|
|
6669
6678
|
return;
|
|
6670
6679
|
const decoded = Script.decode(script);
|
|
6671
6680
|
const nonMinimalNumber = decoded.some((op) => isBytes5(op) && op.length === 1 && (1 <= op[0] && op[0] <= 16 || op[0] === 129));
|
|
6672
|
-
if (nonMinimalNumber || !
|
|
6681
|
+
if (nonMinimalNumber || !equalBytes2(script, Script.encode(decoded))) {
|
|
6673
6682
|
const wrapper = name === "redeemScript" ? "P2SH" : "P2WSH";
|
|
6674
6683
|
throw new Error(`${wrapper}: non-canonical ${name}`);
|
|
6675
6684
|
}
|
|
@@ -6683,7 +6692,7 @@ var p2sh = (child, network = NETWORK, allowNonCanonicalScript = false) => {
|
|
|
6683
6692
|
if (cs.length > MAX_SCRIPT_BYTE_LENGTH)
|
|
6684
6693
|
throw new Error(`P2SH: redeemScript exceeds ${MAX_SCRIPT_BYTE_LENGTH}-byte push limit: len=${cs.length}`);
|
|
6685
6694
|
checkCanonicalScript(cs, "redeemScript", allowNonCanonicalScript);
|
|
6686
|
-
const hash =
|
|
6695
|
+
const hash = hash160(cs);
|
|
6687
6696
|
const out = { type: "sh", hash };
|
|
6688
6697
|
const script = OutScript.encode(out);
|
|
6689
6698
|
const address = Address(network).encode(out);
|
|
@@ -6712,7 +6721,7 @@ var p2wpkh = (publicKey, network = NETWORK) => {
|
|
|
6712
6721
|
throw new Error("P2WPKH: invalid publicKey");
|
|
6713
6722
|
if (publicKey.length === 65)
|
|
6714
6723
|
throw new Error("P2WPKH: uncompressed public key");
|
|
6715
|
-
const hash =
|
|
6724
|
+
const hash = hash160(publicKey);
|
|
6716
6725
|
return {
|
|
6717
6726
|
type: "wpkh",
|
|
6718
6727
|
script: OutScript.encode({ type: "wpkh", hash }),
|
|
@@ -6745,9 +6754,9 @@ function checkTaprootScript(script, internalPubKey, allowUnknownOutputs = false,
|
|
|
6745
6754
|
const outms = out;
|
|
6746
6755
|
if (!allowUnknownOutputs && outms.pubkeys) {
|
|
6747
6756
|
for (const p of outms.pubkeys) {
|
|
6748
|
-
if (
|
|
6757
|
+
if (equalBytes2(p, taprootNumsKey()))
|
|
6749
6758
|
throw new Error("Unspendable taproot key in leaf script");
|
|
6750
|
-
if (
|
|
6759
|
+
if (equalBytes2(p, internalPubKey)) {
|
|
6751
6760
|
throw new Error("Using P2TR with leaf script with same key as internal key is not supported");
|
|
6752
6761
|
}
|
|
6753
6762
|
}
|
|
@@ -6814,7 +6823,7 @@ function taprootHashTree(tree, internalPubKey, allowUnknownOutputs = false, cust
|
|
|
6814
6823
|
validateObject2(tree, {}, {}, "tree");
|
|
6815
6824
|
const version = tree.leafVersion;
|
|
6816
6825
|
const { script: leafScript } = tree;
|
|
6817
|
-
if (tree.tapLeafScript || tree.tapMerkleRoot && !
|
|
6826
|
+
if (tree.tapLeafScript || tree.tapMerkleRoot && !equalBytes2(tree.tapMerkleRoot, EMPTY))
|
|
6818
6827
|
throw new Error("P2TR: tapRoot leafScript cannot have tree");
|
|
6819
6828
|
const script = typeof leafScript === "string" ? hex.decode(leafScript) : abytes2(leafScript, undefined, "tree.script");
|
|
6820
6829
|
checkTaprootScript(script, internalPubKey, allowUnknownOutputs, customScripts);
|
|
@@ -6869,7 +6878,7 @@ function p2tr(internalPubKey, tree, network = NETWORK, allowUnknownOutputs = fal
|
|
|
6869
6878
|
internalKey: pubKey,
|
|
6870
6879
|
merklePath: l.path
|
|
6871
6880
|
};
|
|
6872
|
-
tapLeafScript.push([controlBlock,
|
|
6881
|
+
tapLeafScript.push([controlBlock, concatBytes3(l.script, new Uint8Array([version]))]);
|
|
6873
6882
|
return { ...l, controlBlock: TaprootControlBlock.encode(controlBlock) };
|
|
6874
6883
|
});
|
|
6875
6884
|
return {
|
|
@@ -6908,7 +6917,7 @@ function programToWitness(version, data, network = NETWORK) {
|
|
|
6908
6917
|
return coder.encode(network.bech32, [version].concat(coder.toWords(data)));
|
|
6909
6918
|
}
|
|
6910
6919
|
function formatKey(hashed, prefix) {
|
|
6911
|
-
return base58check2.encode(
|
|
6920
|
+
return base58check2.encode(concatBytes3(Uint8Array.from(prefix), hashed));
|
|
6912
6921
|
}
|
|
6913
6922
|
function Address(network = NETWORK) {
|
|
6914
6923
|
validateObject2(network, {}, {}, "network");
|
|
@@ -6957,7 +6966,7 @@ function Address(network = NETWORK) {
|
|
|
6957
6966
|
return { type: "wpkh", hash: data };
|
|
6958
6967
|
else if (version === 1 && data.length === 32)
|
|
6959
6968
|
return { type: "tr", pubkey: data };
|
|
6960
|
-
else if (version === 1 &&
|
|
6969
|
+
else if (version === 1 && equalBytes2(data, P2A_PROGRAM))
|
|
6961
6970
|
return { type: "p2a", script: Script.encode([1, data]) };
|
|
6962
6971
|
else
|
|
6963
6972
|
throw new Error("Unknown witness program");
|
|
@@ -7019,7 +7028,7 @@ var stripCodeSeparator = (script) => {
|
|
|
7019
7028
|
return script;
|
|
7020
7029
|
if (start < script.length)
|
|
7021
7030
|
out.push(script.subarray(start));
|
|
7022
|
-
return out.length ?
|
|
7031
|
+
return out.length ? concatBytes3(...out) : EMPTY;
|
|
7023
7032
|
};
|
|
7024
7033
|
var DEFAULT_VERSION = 2;
|
|
7025
7034
|
var DEFAULT_LOCKTIME = 0;
|
|
@@ -7057,7 +7066,7 @@ var SigHash = /* @__PURE__ */ (() => Object.freeze({
|
|
|
7057
7066
|
}))();
|
|
7058
7067
|
var SigHashNames = /* @__PURE__ */ (() => Object.freeze(reverseObject(SigHash)))();
|
|
7059
7068
|
function getTaprootKeys(privKey, pubKey, internalKey, merkleRoot = EMPTY) {
|
|
7060
|
-
if (
|
|
7069
|
+
if (equalBytes2(internalKey, pubKey)) {
|
|
7061
7070
|
privKey = taprootTweakPrivKey(privKey, merkleRoot);
|
|
7062
7071
|
pubKey = pubSchnorr(privKey);
|
|
7063
7072
|
}
|
|
@@ -7224,7 +7233,7 @@ function checkTaprootInputCommitments(input, prevScript) {
|
|
|
7224
7233
|
}
|
|
7225
7234
|
const checkOutputKey = (internalKey, merkleRoot, parity) => {
|
|
7226
7235
|
const [outputKey, outputParity] = taprootTweakPubkey(internalKey, merkleRoot);
|
|
7227
|
-
if (!
|
|
7236
|
+
if (!equalBytes2(outputKey, output.pubkey))
|
|
7228
7237
|
throw new Error("validateInput: Taproot commitment does not match previous output");
|
|
7229
7238
|
if (parity !== undefined && outputParity !== parity)
|
|
7230
7239
|
throw new Error("validateInput: Taproot control-block parity does not match previous output");
|
|
@@ -7238,9 +7247,9 @@ function checkTaprootInputCommitments(input, prevScript) {
|
|
|
7238
7247
|
merkleRoot = compareBytes(sibling, merkleRoot) === -1 ? tagSchnorr("TapBranch", sibling, merkleRoot) : tagSchnorr("TapBranch", merkleRoot, sibling);
|
|
7239
7248
|
}
|
|
7240
7249
|
checkOutputKey(controlBlock.internalKey, merkleRoot, controlBlock.version & 1);
|
|
7241
|
-
if (input.tapInternalKey && !
|
|
7250
|
+
if (input.tapInternalKey && !equalBytes2(input.tapInternalKey, controlBlock.internalKey))
|
|
7242
7251
|
throw new Error("validateInput: tapInternalKey does not match Taproot control block");
|
|
7243
|
-
if (input.tapMerkleRoot && !
|
|
7252
|
+
if (input.tapMerkleRoot && !equalBytes2(input.tapMerkleRoot, merkleRoot))
|
|
7244
7253
|
throw new Error("validateInput: tapMerkleRoot does not match Taproot control block");
|
|
7245
7254
|
}
|
|
7246
7255
|
}
|
|
@@ -7302,7 +7311,7 @@ function validateInput(i, disableScriptCheck = false) {
|
|
|
7302
7311
|
if (_i.index > last)
|
|
7303
7312
|
throw new Error(`validateInput: index(${_i.index}) not in nonWitnessUtxo`);
|
|
7304
7313
|
prevOut = _i.nonWitnessUtxo.outputs[_i.index];
|
|
7305
|
-
if (_i.witnessUtxo && (!
|
|
7314
|
+
if (_i.witnessUtxo && (!equalBytes2(_i.witnessUtxo.script, prevOut.script) || _i.witnessUtxo.amount !== prevOut.amount))
|
|
7306
7315
|
throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo");
|
|
7307
7316
|
if (_i.txid) {
|
|
7308
7317
|
const outputs = _i.nonWitnessUtxo.outputs;
|
|
@@ -7853,7 +7862,7 @@ class Transaction {
|
|
|
7853
7862
|
if (signatures?.length && nextLockTime !== this.lockTime)
|
|
7854
7863
|
throw new Error("Tx has signed inputs, cannot change lockTime");
|
|
7855
7864
|
const current = this.inputs[idx];
|
|
7856
|
-
const transactionChanged = current.index !== normalized.index || def(current.sequence, DEFAULT_SEQUENCE) !== def(normalized.sequence, DEFAULT_SEQUENCE) || (current.txid === undefined ? normalized.txid !== undefined : normalized.txid === undefined || !
|
|
7865
|
+
const transactionChanged = current.index !== normalized.index || def(current.sequence, DEFAULT_SEQUENCE) !== def(normalized.sequence, DEFAULT_SEQUENCE) || (current.txid === undefined ? normalized.txid !== undefined : normalized.txid === undefined || !equalBytes2(current.txid, normalized.txid)) || nextLockTime !== this.lockTime;
|
|
7857
7866
|
if (transactionChanged)
|
|
7858
7867
|
this.requireTxModifiable(1, "inputs");
|
|
7859
7868
|
this.inputs[idx] = normalized;
|
|
@@ -7918,7 +7927,7 @@ class Transaction {
|
|
|
7918
7927
|
}
|
|
7919
7928
|
const current = this.outputs[idx];
|
|
7920
7929
|
const normalized = cloneDeep(this.normalizeOutput(output, current, allowedFields));
|
|
7921
|
-
const transactionChanged = current.amount !== normalized.amount || (current.script === undefined ? normalized.script !== undefined : normalized.script === undefined || !
|
|
7930
|
+
const transactionChanged = current.amount !== normalized.amount || (current.script === undefined ? normalized.script !== undefined : normalized.script === undefined || !equalBytes2(current.script, normalized.script));
|
|
7922
7931
|
if (transactionChanged)
|
|
7923
7932
|
this.requireTxModifiable(2, "outputs");
|
|
7924
7933
|
this.outputs[idx] = normalized;
|
|
@@ -8026,10 +8035,10 @@ class Transaction {
|
|
|
8026
8035
|
amount.map(U64LE.encode),
|
|
8027
8036
|
prevOutScript.map(VarBytes.encode),
|
|
8028
8037
|
inputs.map((i) => U32LE.encode(i.sequence))
|
|
8029
|
-
].map((i) => sha2562(
|
|
8038
|
+
].map((i) => sha2562(concatBytes3(...i))));
|
|
8030
8039
|
}
|
|
8031
8040
|
if (outType === SignatureHash.ALL) {
|
|
8032
|
-
out.push(sha2562(
|
|
8041
|
+
out.push(sha2562(concatBytes3(...outputs.map(RawOutput.encode))));
|
|
8033
8042
|
}
|
|
8034
8043
|
const spendType = (annex ? 1 : 0) | (leafScript ? 2 : 0);
|
|
8035
8044
|
out.push(new Uint8Array([spendType]));
|
|
@@ -8058,22 +8067,22 @@ class Transaction {
|
|
|
8058
8067
|
const canSign = (privateKey) => {
|
|
8059
8068
|
if (inputType.txType === "taproot") {
|
|
8060
8069
|
const pubKey = pubSchnorr(privateKey);
|
|
8061
|
-
if (input.tapInternalKey &&
|
|
8070
|
+
if (input.tapInternalKey && equalBytes2(pubKey, input.tapInternalKey))
|
|
8062
8071
|
return true;
|
|
8063
8072
|
if (!input.tapLeafScript)
|
|
8064
8073
|
return false;
|
|
8065
8074
|
for (const [_, leaf] of input.tapLeafScript) {
|
|
8066
8075
|
for (const op of Script.decode(leaf.subarray(0, -1))) {
|
|
8067
|
-
if (isBytes5(op) &&
|
|
8076
|
+
if (isBytes5(op) && equalBytes2(op, pubKey))
|
|
8068
8077
|
return true;
|
|
8069
8078
|
}
|
|
8070
8079
|
}
|
|
8071
8080
|
return false;
|
|
8072
8081
|
}
|
|
8073
8082
|
const pubKey = pubECDSA(privateKey);
|
|
8074
|
-
const pubKeyHash =
|
|
8083
|
+
const pubKeyHash = hash160(pubKey);
|
|
8075
8084
|
for (const op of Script.decode(inputType.lastScript)) {
|
|
8076
|
-
if (isBytes5(op) && (
|
|
8085
|
+
if (isBytes5(op) && (equalBytes2(op, pubKey) || equalBytes2(op, pubKeyHash)))
|
|
8077
8086
|
return true;
|
|
8078
8087
|
}
|
|
8079
8088
|
return false;
|
|
@@ -8087,7 +8096,7 @@ class Transaction {
|
|
|
8087
8096
|
let s = root;
|
|
8088
8097
|
for (const i of row.path)
|
|
8089
8098
|
s = s.deriveChild(i);
|
|
8090
|
-
if (!
|
|
8099
|
+
if (!equalBytes2(pubKey(s), row.pubKey))
|
|
8091
8100
|
throw new Error(`${label}: wrong pubKey`);
|
|
8092
8101
|
if (!s.privateKey)
|
|
8093
8102
|
throw new Error(`${label}: no privateKey`);
|
|
@@ -8142,9 +8151,9 @@ class Transaction {
|
|
|
8142
8151
|
if (input.tapInternalKey) {
|
|
8143
8152
|
const { pubKey, privKey } = getTaprootKeys(privateKey, schnorrPub, input.tapInternalKey, merkleRoot);
|
|
8144
8153
|
const [taprootPubKey, _] = taprootTweakPubkey(input.tapInternalKey, merkleRoot);
|
|
8145
|
-
if (
|
|
8154
|
+
if (equalBytes2(taprootPubKey, pubKey)) {
|
|
8146
8155
|
const hash = this.preimageWitnessV1(idx, prevOutScript, sighash, amount);
|
|
8147
|
-
const sig =
|
|
8156
|
+
const sig = concatBytes3(signSchnorr(hash, privKey, _auxRand), sighash !== SignatureHash.DEFAULT ? new Uint8Array([sighash]) : EMPTY);
|
|
8148
8157
|
this.updateInput(idx, { tapKeySig: sig }, true);
|
|
8149
8158
|
signed = true;
|
|
8150
8159
|
}
|
|
@@ -8156,11 +8165,11 @@ class Transaction {
|
|
|
8156
8165
|
const scriptDecoded = Script.decode(script);
|
|
8157
8166
|
const ver = _script[_script.length - 1];
|
|
8158
8167
|
const hash = tapLeafHash(script, ver);
|
|
8159
|
-
const pos = scriptDecoded.findIndex((i) => isBytes5(i) &&
|
|
8168
|
+
const pos = scriptDecoded.findIndex((i) => isBytes5(i) && equalBytes2(i, schnorrPub));
|
|
8160
8169
|
if (pos === -1)
|
|
8161
8170
|
continue;
|
|
8162
8171
|
const msg = this.preimageWitnessV1(idx, prevOutScript, sighash, amount, undefined, script, ver);
|
|
8163
|
-
const sig =
|
|
8172
|
+
const sig = concatBytes3(signSchnorr(msg, privateKey, _auxRand), sighash !== SignatureHash.DEFAULT ? new Uint8Array([sighash]) : EMPTY);
|
|
8164
8173
|
this.updateInput(idx, { tapScriptSig: [[{ pubKey: schnorrPub, leafHash: hash }, sig]] }, true);
|
|
8165
8174
|
signed = true;
|
|
8166
8175
|
}
|
|
@@ -8171,9 +8180,9 @@ class Transaction {
|
|
|
8171
8180
|
} else {
|
|
8172
8181
|
const pubKey = pubECDSA(privateKey);
|
|
8173
8182
|
let hasPubkey = false;
|
|
8174
|
-
const pubKeyHash =
|
|
8183
|
+
const pubKeyHash = hash160(pubKey);
|
|
8175
8184
|
for (const i of Script.decode(inputType.lastScript)) {
|
|
8176
|
-
if (isBytes5(i) && (
|
|
8185
|
+
if (isBytes5(i) && (equalBytes2(i, pubKey) || equalBytes2(i, pubKeyHash)))
|
|
8177
8186
|
hasPubkey = true;
|
|
8178
8187
|
}
|
|
8179
8188
|
if (!hasPubkey)
|
|
@@ -8190,7 +8199,7 @@ class Transaction {
|
|
|
8190
8199
|
throw new Error(`Transaction/sign: unknown tx type: ${inputType.txType}`);
|
|
8191
8200
|
const sig = signECDSA(hash, privateKey, this.opts.lowR);
|
|
8192
8201
|
this.updateInput(idx, {
|
|
8193
|
-
partialSig: [[pubKey,
|
|
8202
|
+
partialSig: [[pubKey, concatBytes3(sig, new Uint8Array([sighash]))]]
|
|
8194
8203
|
}, true);
|
|
8195
8204
|
}
|
|
8196
8205
|
return true;
|
|
@@ -8229,7 +8238,7 @@ class Transaction {
|
|
|
8229
8238
|
const ver = _script[_script.length - 1];
|
|
8230
8239
|
const outScript = OutScript.decode(script);
|
|
8231
8240
|
const hash = tapLeafHash(script, ver);
|
|
8232
|
-
const scriptSig = input.tapScriptSig.filter((i) =>
|
|
8241
|
+
const scriptSig = input.tapScriptSig.filter((i) => equalBytes2(i[0].leafHash, hash));
|
|
8233
8242
|
let signatures = [];
|
|
8234
8243
|
let witness;
|
|
8235
8244
|
if (outScript.type === "tr_ms") {
|
|
@@ -8237,7 +8246,7 @@ class Transaction {
|
|
|
8237
8246
|
const pubkeys = outScript.pubkeys;
|
|
8238
8247
|
let added = 0;
|
|
8239
8248
|
for (const pub of pubkeys) {
|
|
8240
|
-
const sigIdx = scriptSig.findIndex((i) =>
|
|
8249
|
+
const sigIdx = scriptSig.findIndex((i) => equalBytes2(i[0].pubKey, pub));
|
|
8241
8250
|
if (added === m || sigIdx === -1) {
|
|
8242
8251
|
signatures.push(EMPTY);
|
|
8243
8252
|
continue;
|
|
@@ -8249,7 +8258,7 @@ class Transaction {
|
|
|
8249
8258
|
continue;
|
|
8250
8259
|
} else if (outScript.type === "tr_ns") {
|
|
8251
8260
|
for (const pub of outScript.pubkeys) {
|
|
8252
|
-
const sigIdx = scriptSig.findIndex((i) =>
|
|
8261
|
+
const sigIdx = scriptSig.findIndex((i) => equalBytes2(i[0].pubKey, pub));
|
|
8253
8262
|
if (sigIdx === -1)
|
|
8254
8263
|
continue;
|
|
8255
8264
|
signatures.push(scriptSig[sigIdx][1]);
|
|
@@ -8259,7 +8268,7 @@ class Transaction {
|
|
|
8259
8268
|
} else if (outScript.type === "unknown" && this.opts.allowUnknownInputs) {
|
|
8260
8269
|
const scriptDecoded = Script.decode(script);
|
|
8261
8270
|
signatures = scriptSig.map(([{ pubKey }, signature]) => {
|
|
8262
|
-
const pos = scriptDecoded.findIndex((i) => isBytes5(i) &&
|
|
8271
|
+
const pos = scriptDecoded.findIndex((i) => isBytes5(i) && equalBytes2(i, pubKey));
|
|
8263
8272
|
if (pos === -1)
|
|
8264
8273
|
throw new Error("finalize/taproot: cannot find position of pubkey in script");
|
|
8265
8274
|
return { signature, pos };
|
|
@@ -8317,7 +8326,7 @@ class Transaction {
|
|
|
8317
8326
|
const pubkeys = inputType.last.pubkeys;
|
|
8318
8327
|
let signatures = [];
|
|
8319
8328
|
for (const pub of pubkeys) {
|
|
8320
|
-
const sign = input.partialSig.find((s) =>
|
|
8329
|
+
const sign = input.partialSig.find((s) => equalBytes2(pub, s[0]));
|
|
8321
8330
|
if (!sign)
|
|
8322
8331
|
continue;
|
|
8323
8332
|
signatures.push(sign[1]);
|
|
@@ -8399,7 +8408,7 @@ class Transaction {
|
|
|
8399
8408
|
}
|
|
8400
8409
|
}
|
|
8401
8410
|
const unsignedTx = this.unsignedTx;
|
|
8402
|
-
if (!
|
|
8411
|
+
if (!equalBytes2(unsignedTx, other.unsignedTx))
|
|
8403
8412
|
throw new Error(`Transaction/combine: different unsigned tx`);
|
|
8404
8413
|
let txModifiable;
|
|
8405
8414
|
if (thisV2 && otherV2) {
|
|
@@ -8476,7 +8485,7 @@ class Transaction {
|
|
|
8476
8485
|
candidate.outputs = outputs;
|
|
8477
8486
|
if ((!thisV2 || !otherV2) && candidate.isPSBTv2())
|
|
8478
8487
|
candidate.global.txModifiable = candidate.txModifiable;
|
|
8479
|
-
if (!
|
|
8488
|
+
if (!equalBytes2(candidate.unsignedTx, unsignedTx))
|
|
8480
8489
|
throw new Error("Transaction/combine: combined unsigned tx differs");
|
|
8481
8490
|
this.global = candidate.global;
|
|
8482
8491
|
this.inputs = candidate.inputs;
|
|
@@ -8488,4 +8497,4 @@ class Transaction {
|
|
|
8488
8497
|
}
|
|
8489
8498
|
}
|
|
8490
8499
|
|
|
8491
|
-
export { anumber, abool, abytes, ahash, aexists, aoutput, u32, clean, createView, rotl, swap32IfBE, bytesToHex, hexToBytes, asyncLoop, utf8ToBytes, kdfInputToBytes, concatBytes, checkOpts, createHasher, randomBytes, split, sha256, sha512, abytes2, bytesToHex2, concatBytes2, hexToBytes2, isBytes, randomBytes2, abool2, asafenumber, bytesToNumberBE, bytesToNumberLE, numberToBytesBE, numberToBytesLE, equalBytes,
|
|
8500
|
+
export { anumber, abool, abytes, copyBytes, ahash, aexists, aoutput, u8, u32, clean, createView, rotl, swap8IfBE, swap32IfBE, bytesToHex, hexToBytes, nextTick, asyncLoop, utf8ToBytes, kdfInputToBytes, concatBytes, checkOpts, createHasher, randomBytes, split, fromNumH, fromNumL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, add, add3L, add3H, sha256, sha512, abytes2, bytesToHex2, concatBytes2, hexToBytes2, isBytes, randomBytes2, abool2, asafenumber, bytesToNumberBE, bytesToNumberLE, numberToBytesBE, numberToBytesLE, equalBytes, copyBytes2, aInRange, validateObject, mod, pow2, isNegativeLE, FpLegendre, validatePointCons, normalizeZ, ScalarMultiplier, createCurveFields, createKeygen, hmac, secp256k1, schnorr, base64, base64urlnopad, base58, createBase58check, bech32, ripemd160, HDKey, concatBytes3, equalBytes2, hash160, tagSchnorr, taprootTweakPrivKey, taprootTweakPubkey, NETWORK, TEST_NETWORK, ScriptNum, Script, RawTx, OutScript, p2pkh, p2sh, p2wpkh, taprootListToTree, p2tr, Address, SigHash, getPrevOut, getInputType, Transaction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qntx/wallet-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Web Worker and worker_threads hosts for @qntx/wallet",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nostr",
|
|
@@ -46,14 +46,16 @@
|
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "vp run @qntx/wallet#build && vp pack && bun build --target node --splitting --outdir dist --entry-naming \"kernel.[name].js\" src/worker/node.ts && bun build --target browser --splitting --outdir dist --entry-naming \"kernel.[name].js\" src/worker/worker.ts && bun scripts/copy-spark-wasm.ts && bun scripts/kernel-manifest.ts",
|
|
49
|
-
"test": "vp test",
|
|
50
|
-
"test:
|
|
49
|
+
"test": "vp test --project node",
|
|
50
|
+
"test:web": "vp test --project web",
|
|
51
|
+
"coverage": "vp test --coverage",
|
|
51
52
|
"test:browser": "playwright test --config tests/browser/playwright.config.ts",
|
|
52
53
|
"smoke:hermes": "vp run @qntx/wallet#build && bun scripts/hermes-smoke.ts",
|
|
53
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.src.json && tsc --noEmit -p src/browser/tsconfig.json && tsc --noEmit -p src/worker/tsconfig.json && tsc --noEmit -p tests/browser/page/tsconfig.json",
|
|
54
|
-
"check:pkg": "bun run build && publint && attw --pack . --profile esm-only",
|
|
54
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.src.json && tsc --noEmit -p src/browser/tsconfig.json && tsc --noEmit -p src/worker/tsconfig.json && tsc --noEmit -p tests/browser/page/tsconfig.json && tsc --noEmit -p tests/web/tsconfig.json",
|
|
55
|
+
"check:pkg": "bun run build && bun ../../scripts/check-api.ts . && publint && attw --pack . --profile esm-only",
|
|
55
56
|
"pack:local": "bun run build && bun pm pack",
|
|
56
|
-
"test:consumer": "bun scripts/consumer-smoke.ts"
|
|
57
|
+
"test:consumer": "bun scripts/consumer-smoke.ts",
|
|
58
|
+
"consumer:lock": "bun scripts/consumer-lock.ts"
|
|
57
59
|
},
|
|
58
60
|
"dependencies": {
|
|
59
61
|
"@noble/hashes": "2.4.0",
|
|
@@ -63,28 +65,22 @@
|
|
|
63
65
|
"@arethetypeswrong/cli": "0.18.5",
|
|
64
66
|
"@noble/hashes": "2.4.0",
|
|
65
67
|
"@playwright/test": "1.64.1",
|
|
66
|
-
"@qntx/nostr": "0.
|
|
68
|
+
"@qntx/nostr": "0.16.0",
|
|
67
69
|
"@qntx/spark": "0.5.2",
|
|
68
70
|
"@qntx/spark-wasm": "0.5.2",
|
|
69
71
|
"@qntx/tsconfig": "1.0.1",
|
|
70
|
-
"@qntx/wallet": "0.
|
|
71
|
-
"@qntx/wallet-kernel": "0.
|
|
72
|
+
"@qntx/wallet": "0.14.1",
|
|
73
|
+
"@qntx/wallet-kernel": "0.14.1",
|
|
72
74
|
"@scure/base": "2.4.0",
|
|
73
75
|
"@scure/btc-signer": "2.4.1",
|
|
74
76
|
"@types/node": "26.6.6",
|
|
77
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
75
78
|
"publint": "0.3.25",
|
|
76
79
|
"typescript": "7.0.2",
|
|
77
80
|
"vite-plus": "1.4.0"
|
|
78
81
|
},
|
|
79
82
|
"peerDependencies": {
|
|
80
|
-
"@qntx/wallet": "0.
|
|
81
|
-
},
|
|
82
|
-
"devEngines": {
|
|
83
|
-
"packageManager": {
|
|
84
|
-
"name": "bun",
|
|
85
|
-
"version": "1.4.0",
|
|
86
|
-
"onFail": "ignore"
|
|
87
|
-
}
|
|
83
|
+
"@qntx/wallet": "0.14.1"
|
|
88
84
|
},
|
|
89
85
|
"engines": {
|
|
90
86
|
"node": ">=20.19.0"
|