@qntx/wallet-worker 0.10.0 → 0.12.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/dist/browser.mjs +13 -10
- package/dist/browser.mjs.map +1 -1
- package/dist/kernel.manifest.json +4 -4
- package/dist/kernel.node.js +172 -106
- package/dist/kernel.worker.js +173 -107
- package/dist/node.mjs +5 -2
- package/dist/node.mjs.map +1 -1
- package/package.json +5 -5
package/dist/kernel.worker.js
CHANGED
|
@@ -98,8 +98,8 @@ var __chunks = (base, ids, nodes, entry) => {
|
|
|
98
98
|
__chunkSeen ||= {};
|
|
99
99
|
__preload(ids[entry], 1);
|
|
100
100
|
};
|
|
101
|
-
__chunks(import.meta.url,["
|
|
102
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
101
|
+
__chunks(import.meta.url,["s5tqy9kw","h69ffzx5","1vpxmqwn","k5etevb7","gsare3mw"],[["./kernel.worker.js",3],["./signer-h69ffzx5.js",3,4],["./browser-1vpxmqwn.js",4],["./worker-k5etevb7.js"],["./worker-gsare3mw.js"]],0);
|
|
102
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/util-D8wUYmm0.mjs
|
|
103
103
|
var NostrError = class extends Error {
|
|
104
104
|
name = "NostrError";
|
|
105
105
|
};
|
|
@@ -168,7 +168,7 @@ function hasLoneSurrogate(value) {
|
|
|
168
168
|
return false;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
171
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/kind-BAnfDHdg.mjs
|
|
172
172
|
var Kind = {
|
|
173
173
|
Metadata: 0,
|
|
174
174
|
TextNote: 1,
|
|
@@ -200,7 +200,7 @@ var Kind = {
|
|
|
200
200
|
StarterPack: 39089
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
203
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/event-B__SmruU.mjs
|
|
204
204
|
function isTag(value) {
|
|
205
205
|
if (!Array.isArray(value) || value.length === 0)
|
|
206
206
|
return false;
|
|
@@ -281,7 +281,7 @@ function getEventHash(event) {
|
|
|
281
281
|
return bytesToHex$1(sha256(utf8Encoder.encode(serialized)));
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
284
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/key-BxwA02Gx.mjs
|
|
285
285
|
var SecretKey = class SecretKey {
|
|
286
286
|
#bytes;
|
|
287
287
|
constructor(bytes) {
|
|
@@ -410,7 +410,7 @@ function signEvent(unsigned, secretKey, auxRand) {
|
|
|
410
410
|
return event;
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
413
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/verifier-iQR5ivRF.mjs
|
|
414
414
|
function createEventVerifier(backend) {
|
|
415
415
|
return (event) => {
|
|
416
416
|
if (isMarkedVerified(event))
|
|
@@ -430,7 +430,7 @@ function createEventVerifier(backend) {
|
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
432
|
var verifyEvent = createEventVerifier(nobleBackend);
|
|
433
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
433
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/error-Cord_cbw.mjs
|
|
434
434
|
var SignerDisposedError = class extends NostrError {
|
|
435
435
|
name = "SignerDisposedError";
|
|
436
436
|
};
|
|
@@ -889,7 +889,7 @@ var cbc = /* @__PURE__ */ wrapCipher({ blockSize: 16, nonceLength: 16 }, functio
|
|
|
889
889
|
};
|
|
890
890
|
});
|
|
891
891
|
|
|
892
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
892
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip04.mjs
|
|
893
893
|
function normalizeSharedSecret(privkey, pubkey, backend) {
|
|
894
894
|
assertHex32(pubkey, "public key");
|
|
895
895
|
const sharedX = backend.ecdhX(privkey, hexToBytes$1(lowerAscii(pubkey)));
|
|
@@ -1563,7 +1563,7 @@ var hkdf = (hash, ikm, salt, info, length) => {
|
|
|
1563
1563
|
return expand(hash, HMAC.digest(), info, length, HMAC);
|
|
1564
1564
|
};
|
|
1565
1565
|
|
|
1566
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
1566
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip44.mjs
|
|
1567
1567
|
var minPlaintextSize = 1;
|
|
1568
1568
|
var maxPlaintextSize = 4294967295;
|
|
1569
1569
|
var extendedPrefixThreshold = 65536;
|
|
@@ -1689,7 +1689,7 @@ function decrypt3(payload, conversationKey, opts) {
|
|
|
1689
1689
|
return unpad(chacha20(chacha_key, chacha_nonce, ciphertext));
|
|
1690
1690
|
}
|
|
1691
1691
|
|
|
1692
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
1692
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip59.mjs
|
|
1693
1693
|
var Nip59Error = class extends NostrError {
|
|
1694
1694
|
name = "Nip59Error";
|
|
1695
1695
|
};
|
|
@@ -1762,7 +1762,7 @@ async function unwrap(crypto2, giftWrap, options) {
|
|
|
1762
1762
|
return rumor;
|
|
1763
1763
|
}
|
|
1764
1764
|
|
|
1765
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
1765
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/signer-Y3gcghwd.mjs
|
|
1766
1766
|
var KeysSigner = class {
|
|
1767
1767
|
#keys;
|
|
1768
1768
|
#convKeys = /* @__PURE__ */ new Map;
|
|
@@ -1849,15 +1849,17 @@ class KernelError extends Error {
|
|
|
1849
1849
|
code;
|
|
1850
1850
|
retryAt;
|
|
1851
1851
|
corrupted;
|
|
1852
|
-
|
|
1852
|
+
detail;
|
|
1853
|
+
constructor(code, message, retryAt, corrupted = false, detail) {
|
|
1853
1854
|
super(message);
|
|
1854
1855
|
this.name = "KernelError";
|
|
1855
1856
|
this.code = code;
|
|
1856
1857
|
this.retryAt = retryAt;
|
|
1857
1858
|
this.corrupted = corrupted;
|
|
1859
|
+
this.detail = detail;
|
|
1858
1860
|
}
|
|
1859
1861
|
}
|
|
1860
|
-
// ../wallet/dist/core-
|
|
1862
|
+
// ../wallet/dist/core-DDfzuSIa.mjs
|
|
1861
1863
|
var ValidationError = class extends Error {
|
|
1862
1864
|
name = "ValidationError";
|
|
1863
1865
|
};
|
|
@@ -2076,7 +2078,7 @@ var walletInfo = obj({
|
|
|
2076
2078
|
createdAt: safeTime
|
|
2077
2079
|
});
|
|
2078
2080
|
var passphraseBytes = bytes(1, 1024);
|
|
2079
|
-
var walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-
|
|
2081
|
+
var walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-invalidated"), literal("no-device-credential"), literal("passkey-not-configured"), literal("passkey-prf-unsupported"), literal("wrong-password"), literal("wrong-passkey"), literal("rate-limited"), literal("invalid-input"), literal("not-found"), literal("already-exists"), literal("conflict"), literal("unsupported"), literal("unavailable"), literal("integrity"), literal("approval-required"), literal("crashed"));
|
|
2080
2082
|
var createdResult = obj({
|
|
2081
2083
|
wallet: walletInfo,
|
|
2082
2084
|
session: sessionId
|
|
@@ -2237,7 +2239,7 @@ var CORE_METHODS = {
|
|
|
2237
2239
|
}
|
|
2238
2240
|
};
|
|
2239
2241
|
|
|
2240
|
-
// ../wallet/dist/protocol-
|
|
2242
|
+
// ../wallet/dist/protocol-C8x0H3Rr.mjs
|
|
2241
2243
|
var MAX_FACTOR_CHARS = 512;
|
|
2242
2244
|
var MAX_STRING_BYTES = 64000;
|
|
2243
2245
|
var MAX_PAYLOAD_CHARS = 1400000;
|
|
@@ -2272,6 +2274,7 @@ var backupInfo = obj({
|
|
|
2272
2274
|
createdAt: safeTime
|
|
2273
2275
|
});
|
|
2274
2276
|
var template = union(literal("evm.bip44"), literal("solana.bip44-change"), union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84")), literal("btc.bip86"));
|
|
2277
|
+
var btcTemplate = union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86"));
|
|
2275
2278
|
var caip2 = str(200, /^[a-z0-9-]{3,64}:[0-9a-zA-Z-]{1,128}$/);
|
|
2276
2279
|
var addressResult = (t) => obj({
|
|
2277
2280
|
template: literal(t),
|
|
@@ -2355,9 +2358,16 @@ var signRequest = union(obj({
|
|
|
2355
2358
|
}), obj({
|
|
2356
2359
|
kind: literal("bitcoin.psbt"),
|
|
2357
2360
|
network: caip2,
|
|
2358
|
-
account:
|
|
2361
|
+
account: obj({
|
|
2362
|
+
kind: literal("hd"),
|
|
2363
|
+
walletId,
|
|
2364
|
+
groupIndex
|
|
2365
|
+
}),
|
|
2359
2366
|
psbt: bytes(1, 131072),
|
|
2360
|
-
sign: arr(
|
|
2367
|
+
sign: arr(obj({
|
|
2368
|
+
index: int(0, 1024),
|
|
2369
|
+
template: btcTemplate
|
|
2370
|
+
}), 1024)
|
|
2361
2371
|
}), obj({
|
|
2362
2372
|
kind: literal("bitcoin.message"),
|
|
2363
2373
|
network: caip2,
|
|
@@ -2999,7 +3009,8 @@ var METHODS = {
|
|
|
2999
3009
|
var lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"), literal("invalidated"));
|
|
3000
3010
|
var errorPayload = obj({
|
|
3001
3011
|
code: walletErrorCode,
|
|
3002
|
-
retryAt: opt(safeTime)
|
|
3012
|
+
retryAt: opt(safeTime),
|
|
3013
|
+
detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/))
|
|
3003
3014
|
});
|
|
3004
3015
|
var kernelEvent = union(obj({
|
|
3005
3016
|
v: literal(2),
|
|
@@ -3014,7 +3025,7 @@ var kernelEvent = union(obj({
|
|
|
3014
3025
|
// ../wallet-kernel/src/platform.ts
|
|
3015
3026
|
function requirePasskey(platform) {
|
|
3016
3027
|
if (platform.passkey === undefined) {
|
|
3017
|
-
throw new KernelError("
|
|
3028
|
+
throw new KernelError("unsupported", "this platform runs passkey ceremonies in the host");
|
|
3018
3029
|
}
|
|
3019
3030
|
return platform.passkey;
|
|
3020
3031
|
}
|
|
@@ -3051,12 +3062,12 @@ function serializeCeremonies(platform) {
|
|
|
3051
3062
|
}
|
|
3052
3063
|
function assertFactorKindAvailable(platform, kind) {
|
|
3053
3064
|
if (platform.keystore !== undefined !== (kind === "hardware")) {
|
|
3054
|
-
throw new KernelError("
|
|
3065
|
+
throw new KernelError("unsupported", "this factor kind is not available here");
|
|
3055
3066
|
}
|
|
3056
3067
|
}
|
|
3057
3068
|
function requireKeystore(platform) {
|
|
3058
3069
|
if (platform.keystore === undefined) {
|
|
3059
|
-
throw new KernelError("
|
|
3070
|
+
throw new KernelError("unsupported", "this platform has no hardware keystore");
|
|
3060
3071
|
}
|
|
3061
3072
|
return platform.keystore;
|
|
3062
3073
|
}
|
|
@@ -4359,7 +4370,7 @@ async function unlock(platform, image, factor, commit) {
|
|
|
4359
4370
|
if (factor.kind === "hardware") {
|
|
4360
4371
|
const stored = image.factors.find((f) => f.kind === "hardware");
|
|
4361
4372
|
if (stored === undefined) {
|
|
4362
|
-
throw new KernelError("
|
|
4373
|
+
throw new KernelError("not-found", "no hardware factor exists");
|
|
4363
4374
|
}
|
|
4364
4375
|
const kek = await kekFor(platform, factor, stored, corePromptFor(platform.keystore, "unlock"));
|
|
4365
4376
|
try {
|
|
@@ -4451,7 +4462,7 @@ async function verifyFactor(platform, image, factor, dek, prompt) {
|
|
|
4451
4462
|
throw new KernelError(candidates.length > 0 ? "wrong-password" : "invalid-input", "password did not verify");
|
|
4452
4463
|
}
|
|
4453
4464
|
if (factor.kind === "hardware") {
|
|
4454
|
-
throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", undefined, true) : new KernelError("
|
|
4465
|
+
throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", undefined, true) : new KernelError("not-found", "no hardware factor exists");
|
|
4455
4466
|
}
|
|
4456
4467
|
throw new KernelError("wrong-passkey", "passkey did not verify");
|
|
4457
4468
|
}
|
|
@@ -7454,7 +7465,7 @@ function walletPrfOf(result) {
|
|
|
7454
7465
|
if (result.first !== undefined) {
|
|
7455
7466
|
wipe(result.first);
|
|
7456
7467
|
}
|
|
7457
|
-
throw new KernelError("
|
|
7468
|
+
throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
|
|
7458
7469
|
}
|
|
7459
7470
|
return { prfWallet: result.first, synced: result.synced };
|
|
7460
7471
|
}
|
|
@@ -7487,7 +7498,7 @@ async function walletCeremony(ctx, params) {
|
|
|
7487
7498
|
}
|
|
7488
7499
|
async function createWithPasskey(ctx, params, requestSession) {
|
|
7489
7500
|
if (ctx.platform.passkey !== undefined !== (params.ceremony === "kernel")) {
|
|
7490
|
-
throw new KernelError("
|
|
7501
|
+
throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
|
|
7491
7502
|
}
|
|
7492
7503
|
const gated = gate(ctx, params.factor, requestSession);
|
|
7493
7504
|
let prf;
|
|
@@ -7671,7 +7682,7 @@ function backupMaterialOf(result) {
|
|
|
7671
7682
|
result.second?.fill(0);
|
|
7672
7683
|
if (!result.userVerified || result.first?.length !== 32) {
|
|
7673
7684
|
result.first?.fill(0);
|
|
7674
|
-
throw new KernelError("
|
|
7685
|
+
throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
|
|
7675
7686
|
}
|
|
7676
7687
|
return { kind: "passkey", credentialId: result.credentialId, prfBackup: result.first };
|
|
7677
7688
|
}
|
|
@@ -7680,7 +7691,7 @@ async function backupMaterial(ctx, factor, allowCredentials) {
|
|
|
7680
7691
|
return factor;
|
|
7681
7692
|
}
|
|
7682
7693
|
if (ctx.platform.passkey !== undefined !== (factor.ceremony === "kernel")) {
|
|
7683
|
-
throw new KernelError("
|
|
7694
|
+
throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
|
|
7684
7695
|
}
|
|
7685
7696
|
if (factor.ceremony === "host") {
|
|
7686
7697
|
return factor;
|
|
@@ -9764,6 +9775,13 @@ var checkDerivations = (tx, coinType) => {
|
|
|
9764
9775
|
};
|
|
9765
9776
|
var DEFAULT_SIGHASH = 0;
|
|
9766
9777
|
var SIGHASH_ALL = 1;
|
|
9778
|
+
var TEMPLATES = /* @__PURE__ */ new Set([
|
|
9779
|
+
"btc.bip44",
|
|
9780
|
+
"btc.bip49",
|
|
9781
|
+
"btc.bip84",
|
|
9782
|
+
"btc.bip86"
|
|
9783
|
+
]);
|
|
9784
|
+
var isSignEntry = (value) => isRecord$1(value) && typeof value["index"] === "number" && Number.isSafeInteger(value["index"]) && value["index"] >= 0 && typeof value["template"] === "string" && TEMPLATES.has(value["template"]);
|
|
9767
9785
|
var isTaprootInput = (input) => input.tapInternalKey !== undefined || getInputType(input).type === "taproot";
|
|
9768
9786
|
var normalizeBitcoinPsbt = (psbt, sign, network) => {
|
|
9769
9787
|
const net = bitcoinNetwork(network);
|
|
@@ -9773,18 +9791,19 @@ var normalizeBitcoinPsbt = (psbt, sign, network) => {
|
|
|
9773
9791
|
} catch {
|
|
9774
9792
|
throw new ChainError("invalid-request", "PSBT failed to decode");
|
|
9775
9793
|
}
|
|
9776
|
-
if (!Array.isArray(sign) || sign.length === 0 || !sign.every(
|
|
9777
|
-
throw new ChainError("invalid-request", "sign must be a non-empty array of
|
|
9778
|
-
const
|
|
9779
|
-
const
|
|
9780
|
-
|
|
9794
|
+
if (!Array.isArray(sign) || sign.length === 0 || !sign.every(isSignEntry))
|
|
9795
|
+
throw new ChainError("invalid-request", "sign must be a non-empty array of {index, template} entries");
|
|
9796
|
+
const sorted = [...sign].sort((a, b) => a.index - b.index);
|
|
9797
|
+
const indices = new Set(sorted.map((s) => s.index));
|
|
9798
|
+
const last = sorted.at(-1)?.index;
|
|
9799
|
+
if (indices.size !== sorted.length || last === undefined || last >= tx.inputsLength)
|
|
9781
9800
|
throw new ChainError("invalid-request", "sign must be unique, ascending, and in range");
|
|
9782
9801
|
checkDerivations(tx, net.coinType);
|
|
9783
|
-
for (const idx of
|
|
9802
|
+
for (const { index: idx, template } of sorted) {
|
|
9784
9803
|
const input = tx.getInput(idx);
|
|
9785
9804
|
if (input.witnessUtxo === undefined && input.nonWitnessUtxo === undefined)
|
|
9786
9805
|
throw new ChainError("invalid-request", `input ${idx} carries neither witnessUtxo nor nonWitnessUtxo`);
|
|
9787
|
-
if (input.
|
|
9806
|
+
if (template === "btc.bip86" ? input.tapBip32Derivation === undefined : input.bip32Derivation === undefined)
|
|
9788
9807
|
throw new ChainError("invalid-request", `input ${idx} is missing a bip32 derivation`);
|
|
9789
9808
|
const { type } = getInputType(input);
|
|
9790
9809
|
if ((type === "legacy" || type === "nonwitness-script") && input.nonWitnessUtxo === undefined)
|
|
@@ -9797,7 +9816,7 @@ var normalizeBitcoinPsbt = (psbt, sign, network) => {
|
|
|
9797
9816
|
}
|
|
9798
9817
|
return {
|
|
9799
9818
|
psbt: tx.toPSBT(0),
|
|
9800
|
-
sign:
|
|
9819
|
+
sign: sorted
|
|
9801
9820
|
};
|
|
9802
9821
|
};
|
|
9803
9822
|
var SATS = "sats";
|
|
@@ -9833,7 +9852,7 @@ var decodeOutput = (script, amount) => {
|
|
|
9833
9852
|
var decodeBitcoinPsbt = (request, ownScripts = /* @__PURE__ */ new Set) => {
|
|
9834
9853
|
const tx = parsePsbt(request.psbt);
|
|
9835
9854
|
const coder = Address(bitcoinNetwork(request.network).params);
|
|
9836
|
-
const signed = new Set(request.sign);
|
|
9855
|
+
const signed = new Set(request.sign.map((s) => s.index));
|
|
9837
9856
|
const outflows = [];
|
|
9838
9857
|
let canFee = true;
|
|
9839
9858
|
let outSum = 0n;
|
|
@@ -9873,7 +9892,7 @@ var decodeBitcoinPsbt = (request, ownScripts = /* @__PURE__ */ new Set) => {
|
|
|
9873
9892
|
}
|
|
9874
9893
|
const external = tx.inputsLength - signed.size > 0;
|
|
9875
9894
|
const undecodable = outflows.some((o) => !o.verified);
|
|
9876
|
-
const listing = request.sign.some((
|
|
9895
|
+
const listing = request.sign.some((s) => tx.getInput(s.index).sighashType === SIGHASH_SINGLE_ANYONECANPAY);
|
|
9877
9896
|
const verifiability = external ? "opaque" : listing || undecodable ? "partial" : "full";
|
|
9878
9897
|
return {
|
|
9879
9898
|
family: "bitcoin",
|
|
@@ -9926,20 +9945,32 @@ var messageTarget = (address, network, format) => {
|
|
|
9926
9945
|
var normalizeBitcoin = (request) => {
|
|
9927
9946
|
if (!isRecord2(request) || typeof request["kind"] !== "string")
|
|
9928
9947
|
throw new ChainError("invalid-request", "request must be an object with a kind");
|
|
9929
|
-
const { network, account } = common(request);
|
|
9930
9948
|
if (request["kind"] === "bitcoin.psbt") {
|
|
9931
|
-
const { psbt } = request;
|
|
9949
|
+
const { network, account, psbt } = request;
|
|
9950
|
+
if (typeof network !== "string")
|
|
9951
|
+
throw new ChainError("invalid-request", "request.network must be a string");
|
|
9952
|
+
bitcoinNetwork(network);
|
|
9953
|
+
if (!isRecord2(account) || account["kind"] !== "hd")
|
|
9954
|
+
throw new ChainError("invalid-request", "request.account must be a wallet group");
|
|
9955
|
+
const { walletId, groupIndex } = account;
|
|
9956
|
+
if (typeof walletId !== "string" || typeof groupIndex !== "number" || !Number.isSafeInteger(groupIndex) || groupIndex < 0)
|
|
9957
|
+
throw new ChainError("invalid-request", "request.account must be a wallet group");
|
|
9932
9958
|
if (!(psbt instanceof Uint8Array))
|
|
9933
9959
|
throw new ChainError("invalid-request", "psbt must be bytes");
|
|
9934
9960
|
const normalized = normalizeBitcoinPsbt(psbt, request["sign"], network);
|
|
9935
9961
|
return {
|
|
9936
9962
|
kind: "bitcoin.psbt",
|
|
9937
9963
|
network,
|
|
9938
|
-
account
|
|
9964
|
+
account: {
|
|
9965
|
+
kind: "hd",
|
|
9966
|
+
walletId,
|
|
9967
|
+
groupIndex
|
|
9968
|
+
},
|
|
9939
9969
|
psbt: normalized.psbt,
|
|
9940
9970
|
sign: normalized.sign
|
|
9941
9971
|
};
|
|
9942
9972
|
}
|
|
9973
|
+
const { network, account } = common(request);
|
|
9943
9974
|
if (request["kind"] === "bitcoin.message") {
|
|
9944
9975
|
const { format } = request;
|
|
9945
9976
|
const target = messageTarget(request["address"], network, format);
|
|
@@ -16759,6 +16790,18 @@ function mapChainError(error) {
|
|
|
16759
16790
|
// ../wallet-kernel/src/modules/chains/bitcoin.ts
|
|
16760
16791
|
var isPath2 = (path) => Array.isArray(path) && path.every((p) => typeof p === "number");
|
|
16761
16792
|
var hex = (bytes) => bytes.reduce((acc, b) => acc + b.toString(16).padStart(2, "0"), "");
|
|
16793
|
+
var PURPOSES = [44, 49, 84, 86];
|
|
16794
|
+
var contextFor = (b, purpose) => {
|
|
16795
|
+
let ctx = b.purposes.get(purpose);
|
|
16796
|
+
if (ctx === undefined) {
|
|
16797
|
+
ctx = {
|
|
16798
|
+
accountNode: b.master.derive(`m/${purpose}'/${b.coinType}'/${b.groupIndex}'`),
|
|
16799
|
+
children: []
|
|
16800
|
+
};
|
|
16801
|
+
b.purposes.set(purpose, ctx);
|
|
16802
|
+
}
|
|
16803
|
+
return ctx;
|
|
16804
|
+
};
|
|
16762
16805
|
var derivationOf = (owner, fingerprint, purpose) => {
|
|
16763
16806
|
if (purpose === 86) {
|
|
16764
16807
|
const claimed = (der) => der.fingerprint === fingerprint && isPath2(der.path);
|
|
@@ -16778,46 +16821,52 @@ var derivationOf = (owner, fingerprint, purpose) => {
|
|
|
16778
16821
|
};
|
|
16779
16822
|
var expectedPub = (purpose, pub) => purpose === 86 ? pub.slice(1) : pub;
|
|
16780
16823
|
var expectedScript = (purpose, pub) => purpose === 86 ? p2tr(pub.slice(1)).script : purpose === 49 ? p2sh(p2wpkh(pub)).script : purpose === 44 ? p2pkh(pub).script : p2wpkh(pub).script;
|
|
16781
|
-
var childAt = (b, path) => {
|
|
16824
|
+
var childAt = (b, purpose, path) => {
|
|
16782
16825
|
const [purposePath, coinPath, groupPath, change, index] = path;
|
|
16783
|
-
if (path.length !== 5 || purposePath !==
|
|
16826
|
+
if (path.length !== 5 || purposePath !== purpose + b.hardened || coinPath !== b.coinType + b.hardened || groupPath !== b.groupIndex + b.hardened || change === undefined || index === undefined || change !== 0 && change !== 1 || index < 0 || index >= b.hardened) {
|
|
16784
16827
|
throw new KernelError("invalid-input", "derivation path is not this account's");
|
|
16785
16828
|
}
|
|
16786
|
-
const
|
|
16787
|
-
|
|
16829
|
+
const ctx = contextFor(b, purpose);
|
|
16830
|
+
const child = ctx.accountNode.deriveChild(change).deriveChild(index);
|
|
16831
|
+
ctx.children.push(child);
|
|
16788
16832
|
return child;
|
|
16789
16833
|
};
|
|
16790
|
-
var bitcoinInput = (b, tx,
|
|
16834
|
+
var bitcoinInput = (b, tx, entry) => {
|
|
16835
|
+
const purpose = BTC_PURPOSE[entry.template];
|
|
16836
|
+
if (purpose === undefined) {
|
|
16837
|
+
throw new KernelError("invalid-input", "sign template is not a bitcoin account template");
|
|
16838
|
+
}
|
|
16839
|
+
const { index: idx } = entry;
|
|
16791
16840
|
const input = tx.getInput(idx);
|
|
16792
|
-
const
|
|
16793
|
-
if (
|
|
16841
|
+
const der = derivationOf(input, b.master.fingerprint, purpose);
|
|
16842
|
+
if (der === undefined) {
|
|
16794
16843
|
throw new KernelError("invalid-input", `input ${idx}: derivation entry is not this account's`);
|
|
16795
16844
|
}
|
|
16796
|
-
const child = childAt(b,
|
|
16845
|
+
const child = childAt(b, purpose, der.path);
|
|
16797
16846
|
const pub = child.publicKey;
|
|
16798
16847
|
const priv = child.privateKey;
|
|
16799
16848
|
if (pub === null || priv === null) {
|
|
16800
16849
|
throw new KernelError("integrity", "no key at derivation path");
|
|
16801
16850
|
}
|
|
16802
|
-
if (!deepEqual(
|
|
16851
|
+
if (!deepEqual(der.pubkey, expectedPub(purpose, pub))) {
|
|
16803
16852
|
throw new KernelError("invalid-input", `input ${idx}: derivation pubkey is not ours`);
|
|
16804
16853
|
}
|
|
16805
|
-
if (
|
|
16854
|
+
if (purpose === 44) {
|
|
16806
16855
|
if (input.nonWitnessUtxo === undefined) {
|
|
16807
16856
|
throw new KernelError("invalid-input", `input ${idx}: P2PKH spend requires nonWitnessUtxo`);
|
|
16808
16857
|
}
|
|
16809
16858
|
const vout = input.index;
|
|
16810
16859
|
const outs = input.nonWitnessUtxo.outputs;
|
|
16811
16860
|
const prevScript = vout === undefined ? undefined : outs[vout]?.script;
|
|
16812
|
-
if (prevScript === undefined || !deepEqual(prevScript, expectedScript(
|
|
16861
|
+
if (prevScript === undefined || !deepEqual(prevScript, expectedScript(purpose, pub))) {
|
|
16813
16862
|
throw new KernelError("invalid-input", `input ${idx}: nonWitnessUtxo prevout is not this key's`);
|
|
16814
16863
|
}
|
|
16815
16864
|
} else {
|
|
16816
16865
|
const prevout = input.witnessUtxo;
|
|
16817
|
-
if (prevout === undefined || !deepEqual(prevout.script, expectedScript(
|
|
16866
|
+
if (prevout === undefined || !deepEqual(prevout.script, expectedScript(purpose, pub))) {
|
|
16818
16867
|
throw new KernelError("invalid-input", `input ${idx}: prevout script is not this key's`);
|
|
16819
16868
|
}
|
|
16820
|
-
if (
|
|
16869
|
+
if (purpose === 49 && (input.redeemScript === undefined || !deepEqual(input.redeemScript, p2wpkh(pub).script))) {
|
|
16821
16870
|
throw new KernelError("invalid-input", `input ${idx}: redeemScript is not this key's`);
|
|
16822
16871
|
}
|
|
16823
16872
|
}
|
|
@@ -16830,25 +16879,27 @@ var bitcoinOwnScripts = (b, tx) => {
|
|
|
16830
16879
|
if (output.script === undefined) {
|
|
16831
16880
|
continue;
|
|
16832
16881
|
}
|
|
16833
|
-
const
|
|
16834
|
-
|
|
16835
|
-
|
|
16836
|
-
|
|
16837
|
-
|
|
16838
|
-
|
|
16839
|
-
|
|
16840
|
-
|
|
16841
|
-
|
|
16882
|
+
for (const purpose of PURPOSES) {
|
|
16883
|
+
const entry = derivationOf(output, b.master.fingerprint, purpose);
|
|
16884
|
+
if (entry === undefined) {
|
|
16885
|
+
continue;
|
|
16886
|
+
}
|
|
16887
|
+
try {
|
|
16888
|
+
const child = childAt(b, purpose, entry.path);
|
|
16889
|
+
const pub = child.publicKey;
|
|
16890
|
+
if (pub !== null && deepEqual(output.script, expectedScript(purpose, pub))) {
|
|
16891
|
+
ownScripts.add(hex(output.script));
|
|
16892
|
+
}
|
|
16893
|
+
} catch {
|
|
16894
|
+
continue;
|
|
16842
16895
|
}
|
|
16843
|
-
} catch {
|
|
16844
|
-
continue;
|
|
16845
16896
|
}
|
|
16846
16897
|
}
|
|
16847
16898
|
return ownScripts;
|
|
16848
16899
|
};
|
|
16849
16900
|
var executeBitcoinPsbt = (b, request, random, intentOnly) => {
|
|
16850
16901
|
const tx = Transaction.fromPSBT(request.psbt);
|
|
16851
|
-
const inputs = request.sign.map((
|
|
16902
|
+
const inputs = request.sign.map((entry) => bitcoinInput(b, tx, entry));
|
|
16852
16903
|
const ownScripts = bitcoinOwnScripts(b, tx);
|
|
16853
16904
|
let normalized;
|
|
16854
16905
|
try {
|
|
@@ -16873,14 +16924,14 @@ var executeBitcoinPsbt = (b, request, random, intentOnly) => {
|
|
|
16873
16924
|
signedPsbt: signBitcoinPsbt(request.psbt, inputs, () => random(32))
|
|
16874
16925
|
};
|
|
16875
16926
|
};
|
|
16876
|
-
var executeBitcoinMessage = (b, request, random, intentOnly) => {
|
|
16877
|
-
if (request.format === "legacy" &&
|
|
16927
|
+
var executeBitcoinMessage = (b, purpose, request, random, intentOnly) => {
|
|
16928
|
+
if (request.format === "legacy" && purpose !== 44) {
|
|
16878
16929
|
throw new KernelError("unsupported", "legacy message format is btc.bip44-only");
|
|
16879
16930
|
}
|
|
16880
|
-
const child = childAt(b, [
|
|
16881
|
-
|
|
16931
|
+
const child = childAt(b, purpose, [
|
|
16932
|
+
purpose + b.hardened,
|
|
16882
16933
|
b.coinType + b.hardened,
|
|
16883
|
-
b.
|
|
16934
|
+
b.groupIndex + b.hardened,
|
|
16884
16935
|
request.change,
|
|
16885
16936
|
request.index
|
|
16886
16937
|
]);
|
|
@@ -16889,7 +16940,7 @@ var executeBitcoinMessage = (b, request, random, intentOnly) => {
|
|
|
16889
16940
|
if (pub === null || priv === null) {
|
|
16890
16941
|
throw new KernelError("integrity", "no key at derivation path");
|
|
16891
16942
|
}
|
|
16892
|
-
const derived =
|
|
16943
|
+
const derived = purpose === 86 ? p2tr(pub.slice(1), undefined, b.net.params).address : purpose === 49 ? p2sh(p2wpkh(pub, b.net.params), b.net.params).address : purpose === 44 ? p2pkh(pub, b.net.params).address : p2wpkh(pub, b.net.params).address;
|
|
16893
16944
|
if (derived !== request.address) {
|
|
16894
16945
|
throw new KernelError("invalid-input", "address is not ours");
|
|
16895
16946
|
}
|
|
@@ -16918,34 +16969,33 @@ var executeBitcoinMessage = (b, request, random, intentOnly) => {
|
|
|
16918
16969
|
var executeBitcoin = (random, request, account, seed, intentOnly) => {
|
|
16919
16970
|
const net = bitcoinNetwork(request.network);
|
|
16920
16971
|
const master = HDKey.fromMasterSeed(seed, net.bip32);
|
|
16972
|
+
const b = {
|
|
16973
|
+
master,
|
|
16974
|
+
purposes: new Map,
|
|
16975
|
+
coinType: net.coinType,
|
|
16976
|
+
hardened: 2147483648,
|
|
16977
|
+
groupIndex: account.groupIndex,
|
|
16978
|
+
net
|
|
16979
|
+
};
|
|
16921
16980
|
try {
|
|
16922
|
-
|
|
16923
|
-
|
|
16924
|
-
|
|
16925
|
-
|
|
16926
|
-
|
|
16927
|
-
|
|
16928
|
-
|
|
16929
|
-
|
|
16930
|
-
|
|
16931
|
-
|
|
16932
|
-
|
|
16933
|
-
|
|
16934
|
-
|
|
16935
|
-
|
|
16936
|
-
};
|
|
16937
|
-
try {
|
|
16938
|
-
if (request.kind === "bitcoin.psbt") {
|
|
16939
|
-
return executeBitcoinPsbt(b, request, random, intentOnly);
|
|
16940
|
-
}
|
|
16941
|
-
return executeBitcoinMessage(b, request, random, intentOnly);
|
|
16942
|
-
} finally {
|
|
16943
|
-
for (const child of children) {
|
|
16981
|
+
if (request.kind === "bitcoin.psbt") {
|
|
16982
|
+
return executeBitcoinPsbt(b, request, random, intentOnly);
|
|
16983
|
+
}
|
|
16984
|
+
if (request.account.kind !== "hd") {
|
|
16985
|
+
throw new KernelError("unsupported", "imported accounts are not yet supported");
|
|
16986
|
+
}
|
|
16987
|
+
const purpose = BTC_PURPOSE[request.account.template];
|
|
16988
|
+
if (purpose === undefined) {
|
|
16989
|
+
throw new KernelError("invalid-input", "account template is not a bitcoin template");
|
|
16990
|
+
}
|
|
16991
|
+
return executeBitcoinMessage(b, purpose, request, random, intentOnly);
|
|
16992
|
+
} finally {
|
|
16993
|
+
for (const ctx of b.purposes.values()) {
|
|
16994
|
+
for (const child of ctx.children) {
|
|
16944
16995
|
child.wipePrivateData();
|
|
16945
16996
|
}
|
|
16946
|
-
accountNode.wipePrivateData();
|
|
16997
|
+
ctx.accountNode.wipePrivateData();
|
|
16947
16998
|
}
|
|
16948
|
-
} finally {
|
|
16949
16999
|
master.wipePrivateData();
|
|
16950
17000
|
}
|
|
16951
17001
|
};
|
|
@@ -17204,23 +17254,35 @@ var chainSign = async (ctx, params, session) => {
|
|
|
17204
17254
|
if (account.kind !== "hd") {
|
|
17205
17255
|
throw new KernelError("unsupported", "imported accounts are not yet supported");
|
|
17206
17256
|
}
|
|
17207
|
-
|
|
17208
|
-
|
|
17209
|
-
|
|
17210
|
-
|
|
17257
|
+
if (request.kind === "bitcoin.psbt") {
|
|
17258
|
+
if (request.sign.some((s) => BTC_PURPOSE[s.template] === undefined)) {
|
|
17259
|
+
throw new KernelError("invalid-input", "sign template is not a bitcoin account template");
|
|
17260
|
+
}
|
|
17261
|
+
} else {
|
|
17262
|
+
const [family] = request.kind.split(".", 1);
|
|
17263
|
+
const expected = family === "evm" ? ["evm.bip44"] : family === "solana" ? ["solana.bip44-change"] : ["btc.bip44", "btc.bip49", "btc.bip84", "btc.bip86"];
|
|
17264
|
+
if (!("template" in account) || !expected.includes(account.template)) {
|
|
17265
|
+
throw new KernelError("invalid-input", "account template does not match the request family");
|
|
17266
|
+
}
|
|
17211
17267
|
}
|
|
17212
17268
|
const record = ctx.image.records.find((entry) => entry.kind === "entropy" && entry.id === account.walletId);
|
|
17213
17269
|
if (record === undefined) {
|
|
17214
17270
|
throw new KernelError("not-found", "no such wallet");
|
|
17215
17271
|
}
|
|
17216
17272
|
const execute = (seed, intentOnly) => {
|
|
17217
|
-
if (request.kind === "
|
|
17218
|
-
return
|
|
17273
|
+
if (request.kind === "bitcoin.psbt") {
|
|
17274
|
+
return executeBitcoin(ctx.platform.random, request, request.account, seed, intentOnly);
|
|
17275
|
+
}
|
|
17276
|
+
if (request.account.kind !== "hd") {
|
|
17277
|
+
throw new KernelError("unsupported", "imported accounts are not yet supported");
|
|
17219
17278
|
}
|
|
17220
|
-
if (request.kind === "bitcoin.
|
|
17221
|
-
return executeBitcoin(ctx.platform.random, request, account, seed, intentOnly);
|
|
17279
|
+
if (request.kind === "bitcoin.message") {
|
|
17280
|
+
return executeBitcoin(ctx.platform.random, request, request.account, seed, intentOnly);
|
|
17281
|
+
}
|
|
17282
|
+
if (request.kind === "evm.transaction" || request.kind === "evm.personal-message" || request.kind === "evm.typed-data") {
|
|
17283
|
+
return executeEvm(request, request.account, seed, intentOnly);
|
|
17222
17284
|
}
|
|
17223
|
-
return executeSolana(request, account, seed, intentOnly);
|
|
17285
|
+
return executeSolana(request, request.account, seed, intentOnly);
|
|
17224
17286
|
};
|
|
17225
17287
|
const withSeed = async (run) => withWalletSeed(ctx.platform.pbkdf2, dek, record, run);
|
|
17226
17288
|
const prepared = await withSeed((seed) => execute(seed, true));
|
|
@@ -17273,7 +17335,7 @@ function nostrKeyAt(master, index) {
|
|
|
17273
17335
|
}
|
|
17274
17336
|
}
|
|
17275
17337
|
|
|
17276
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
17338
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip19.mjs
|
|
17277
17339
|
var Bech32MaxSize2 = 5000;
|
|
17278
17340
|
function encodeBech32(prefix, data) {
|
|
17279
17341
|
const words = bech32.toWords(data);
|
|
@@ -17446,7 +17508,7 @@ async function scryptAsync(password, salt, opts) {
|
|
|
17446
17508
|
return scryptOutput(password, dkLen, B, V, tmp);
|
|
17447
17509
|
}
|
|
17448
17510
|
|
|
17449
|
-
// ../../node_modules/.bun/@qntx+nostr@0.15.
|
|
17511
|
+
// ../../node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip49.mjs
|
|
17450
17512
|
var VERSION2 = 2;
|
|
17451
17513
|
var SALT_LEN = 16;
|
|
17452
17514
|
var NONCE_LEN = 24;
|
|
@@ -18745,7 +18807,11 @@ function startKernel(host, port) {
|
|
|
18745
18807
|
integrityFailure = true;
|
|
18746
18808
|
setHealth("corrupted");
|
|
18747
18809
|
}
|
|
18748
|
-
const err = error instanceof KernelError ?
|
|
18810
|
+
const err = error instanceof KernelError ? {
|
|
18811
|
+
code: error.code,
|
|
18812
|
+
...error.retryAt === undefined ? {} : { retryAt: error.retryAt },
|
|
18813
|
+
...error.detail === undefined ? {} : { detail: error.detail }
|
|
18814
|
+
} : { code: "integrity" };
|
|
18749
18815
|
return { v: PROTOCOL_VERSION, id, err };
|
|
18750
18816
|
}
|
|
18751
18817
|
};
|
package/dist/node.mjs
CHANGED
|
@@ -18,12 +18,15 @@ var KernelError = class extends Error {
|
|
|
18
18
|
* corrupted state on it. Ordinary failures (a wrong factor, a bad param) leave it false.
|
|
19
19
|
*/
|
|
20
20
|
corrupted;
|
|
21
|
-
|
|
21
|
+
/** Platform diagnostic `"<domain>:<code>"` a backend reported; forwarded to the host verbatim. */
|
|
22
|
+
detail;
|
|
23
|
+
constructor(code, message, retryAt, corrupted = false, detail) {
|
|
22
24
|
super(message);
|
|
23
25
|
this.name = "KernelError";
|
|
24
26
|
this.code = code;
|
|
25
27
|
this.retryAt = retryAt;
|
|
26
28
|
this.corrupted = corrupted;
|
|
29
|
+
this.detail = detail;
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
// ../wallet-kernel/src/vault/memory.ts
|
|
@@ -285,7 +288,7 @@ function createSoftwarePasskey(seed, options) {
|
|
|
285
288
|
},
|
|
286
289
|
assert: async ({ credentialIds, salts }) => {
|
|
287
290
|
const credentialId = credentialIds === void 0 ? lastCreated : credentialIds.find((id) => known.has(bytesToHex(id)));
|
|
288
|
-
if (credentialId === void 0) throw new WalletError("
|
|
291
|
+
if (credentialId === void 0) throw new WalletError("passkey-prf-unsupported", credentialIds === void 0 ? "no software credential exists yet" : "unknown software credential");
|
|
289
292
|
const entry = known.get(bytesToHex(credentialId));
|
|
290
293
|
return result(credentialId, salts, entry?.userHandle);
|
|
291
294
|
}
|