@qntx/wallet-native 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.
@@ -497,7 +497,7 @@
497
497
  var init_defineProperty = __esmMin((() => {
498
498
  init_toPropertyKey();
499
499
  }));
500
- // packages/wallet/dist/core-D-NCx1CQ.mjs
500
+ // packages/wallet/dist/core-DDfzuSIa.mjs
501
501
  init_defineProperty();
502
502
  /**
503
503
  * Strict validator combinators for the secret-area protocol. Both sides share them: the kernel
@@ -716,7 +716,7 @@
716
716
  });
717
717
  /** A BIP-39 passphrase on the wire: raw UTF-8 bytes, never empty (the host omits "none"). */
718
718
  var passphraseBytes = bytes(1, 1024);
719
- var walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-unavailable"), literal("factor-invalidated"), 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"));
719
+ 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"));
720
720
  var createdResult = obj({
721
721
  wallet: walletInfo$1,
722
722
  session: sessionId
@@ -901,7 +901,7 @@
901
901
  var init_objectSpread2 = __esmMin((() => {
902
902
  init_defineProperty();
903
903
  }));
904
- // packages/wallet/dist/protocol-DDz4nlYK.mjs
904
+ // packages/wallet/dist/protocol-C8x0H3Rr.mjs
905
905
  init_objectSpread2();
906
906
  /**
907
907
  * Backup-envelope wire validators (design/backup.mdx): the strict structural shape the kernel and
@@ -942,6 +942,7 @@
942
942
  createdAt: safeTime
943
943
  });
944
944
  var template = union(literal("evm.bip44"), literal("solana.bip44-change"), union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84")), literal("btc.bip86"));
945
+ var btcTemplate = union(literal("btc.bip44"), literal("btc.bip49"), literal("btc.bip84"), literal("btc.bip86"));
945
946
  var caip2 = str(200, /^[a-z0-9-]{3,64}:[0-9a-zA-Z-]{1,128}$/);
946
947
  var addressResult = (t) => obj({
947
948
  template: literal(t),
@@ -1022,9 +1023,16 @@
1022
1023
  }), obj({
1023
1024
  kind: literal("bitcoin.psbt"),
1024
1025
  network: caip2,
1025
- account: accountRef,
1026
+ account: obj({
1027
+ kind: literal("hd"),
1028
+ walletId,
1029
+ groupIndex
1030
+ }),
1026
1031
  psbt: bytes(1, 131072),
1027
- sign: arr(int(0, 1024), 1024)
1032
+ sign: arr(obj({
1033
+ index: int(0, 1024),
1034
+ template: btcTemplate
1035
+ }), 1024)
1028
1036
  }), obj({
1029
1037
  kind: literal("bitcoin.message"),
1030
1038
  network: caip2,
@@ -1661,7 +1669,8 @@
1661
1669
  var lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"), literal("invalidated"));
1662
1670
  obj({
1663
1671
  code: walletErrorCode,
1664
- retryAt: opt(safeTime)
1672
+ retryAt: opt(safeTime),
1673
+ detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/))
1665
1674
  });
1666
1675
  obj({
1667
1676
  v: literal(2),
@@ -3615,7 +3624,7 @@
3615
3624
  * input or secret contents.
3616
3625
  */
3617
3626
  var KernelError = class extends Error {
3618
- constructor(code, message, retryAt, corrupted = false) {
3627
+ constructor(code, message, retryAt, corrupted = false, detail) {
3619
3628
  super(message);
3620
3629
  _defineProperty(this, "code", void 0);
3621
3630
  _defineProperty(this, "retryAt", void 0);
@@ -3628,17 +3637,24 @@
3628
3637
  "corrupted",
3629
3638
  void 0
3630
3639
  );
3640
+ _defineProperty(
3641
+ this,
3642
+ /** Platform diagnostic `"<domain>:<code>"` a backend reported; forwarded to the host verbatim. */
3643
+ "detail",
3644
+ void 0
3645
+ );
3631
3646
  this.name = "KernelError";
3632
3647
  this.code = code;
3633
3648
  this.retryAt = retryAt;
3634
3649
  this.corrupted = corrupted;
3650
+ this.detail = detail;
3635
3651
  }
3636
3652
  };
3637
3653
  // packages/wallet-kernel/src/platform.ts
3638
3654
  init_objectSpread2();
3639
- /** The platform authenticator, or `factor-unavailable` where the host runs ceremonies. */
3655
+ /** The platform authenticator, or `unsupported` where the host runs ceremonies. */
3640
3656
  function requirePasskey(platform) {
3641
- if (platform.passkey === void 0) throw new KernelError("factor-unavailable", "this platform runs passkey ceremonies in the host");
3657
+ if (platform.passkey === void 0) throw new KernelError("unsupported", "this platform runs passkey ceremonies in the host");
3642
3658
  return platform.passkey;
3643
3659
  }
3644
3660
  /**
@@ -3683,11 +3699,11 @@
3683
3699
  * factors are exempt.
3684
3700
  */
3685
3701
  function assertFactorKindAvailable(platform, kind) {
3686
- if (platform.keystore !== void 0 !== (kind === "hardware")) throw new KernelError("factor-unavailable", "this factor kind is not available here");
3702
+ if (platform.keystore !== void 0 !== (kind === "hardware")) throw new KernelError("unsupported", "this factor kind is not available here");
3687
3703
  }
3688
- /** The platform keystore, or `factor-unavailable` on hosts without secure hardware. */
3704
+ /** The platform keystore, or `unsupported` on hosts without secure hardware. */
3689
3705
  function requireKeystore(platform) {
3690
- if (platform.keystore === void 0) throw new KernelError("factor-unavailable", "this platform has no hardware keystore");
3706
+ if (platform.keystore === void 0) throw new KernelError("unsupported", "this platform has no hardware keystore");
3691
3707
  return platform.keystore;
3692
3708
  }
3693
3709
  // packages/wallet-kernel/src/prompts.ts
@@ -7969,7 +7985,7 @@
7969
7985
  let dek;
7970
7986
  if (factor.kind === "hardware") {
7971
7987
  const stored = image.factors.find((f) => f.kind === "hardware");
7972
- if (stored === void 0) throw new KernelError("factor-unavailable", "no hardware factor exists");
7988
+ if (stored === void 0) throw new KernelError("not-found", "no hardware factor exists");
7973
7989
  const kek = await kekFor(platform, factor, stored, corePromptFor(platform.keystore, "unlock"));
7974
7990
  try {
7975
7991
  dek = unwrapDek(kek, stored);
@@ -8031,9 +8047,9 @@
8031
8047
  * compare. A public-key miss — `wrong-password`/`wrong-passkey` — tries the next candidate; every
8032
8048
  * other failure (including corruption-marked integrity) propagates immediately. When no candidate
8033
8049
  * matched, the miss is reported by factor kind: `wrong-password` (or `invalid-input` when no
8034
- * password factor exists), `wrong-passkey`, or for hardware `factor-unavailable` (no hardware
8035
- * factor) / `integrity` (the keystore opened a KEK for another DEK). `prompt` renders the system
8036
- * verification text and runs only for hardware. The verify path never touches the rate limiter.
8050
+ * password factor exists), `wrong-passkey`, or for hardware `not-found` (no hardware factor) /
8051
+ * `integrity` (the keystore opened a KEK for another DEK). `prompt` renders the system verification
8052
+ * text and runs only for hardware. The verify path never touches the rate limiter.
8037
8053
  */
8038
8054
  async function verifyFactor(platform, image, factor, dek, prompt) {
8039
8055
  assertFactorKindAvailable(platform, factor.kind);
@@ -8057,7 +8073,7 @@
8057
8073
  }
8058
8074
  }
8059
8075
  if (factor.kind === "password") throw new KernelError(candidates.length > 0 ? "wrong-password" : "invalid-input", "password did not verify");
8060
- if (factor.kind === "hardware") throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", void 0, true) : new KernelError("factor-unavailable", "no hardware factor exists");
8076
+ if (factor.kind === "hardware") throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", void 0, true) : new KernelError("not-found", "no hardware factor exists");
8061
8077
  throw new KernelError("wrong-passkey", "passkey did not verify");
8062
8078
  }
8063
8079
  /**
@@ -12903,15 +12919,15 @@ zoo`.split("\n"));
12903
12919
  var PURPOSE_WALLET = 1;
12904
12920
  /**
12905
12921
  * One platform ceremony's wallet PRF: the result must be user-verified and carry a 32-byte `first`
12906
- * output; anything else is an authenticator without usable PRF support (`factor-unavailable`). The
12907
- * unused `second` output is wiped.
12922
+ * output; anything else is an authenticator without usable PRF support (`passkey-prf-unsupported`).
12923
+ * The unused `second` output is wiped.
12908
12924
  */
12909
12925
  function walletPrfOf(result) {
12910
12926
  var _result$first;
12911
12927
  if (result.second !== void 0) wipe(result.second);
12912
12928
  if (!result.userVerified || ((_result$first = result.first) === null || _result$first === void 0 ? void 0 : _result$first.length) !== 32) {
12913
12929
  if (result.first !== void 0) wipe(result.first);
12914
- throw new KernelError("factor-unavailable", "the passkey returned no verified PRF output");
12930
+ throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
12915
12931
  }
12916
12932
  return {
12917
12933
  prfWallet: result.first,
@@ -12958,10 +12974,10 @@ zoo`.split("\n"));
12958
12974
  /**
12959
12975
  * Creates or restores a passkey wallet. The ceremony runs where the platform puts it: in the kernel
12960
12976
  * when a platform authenticator exists, in the host (evidence on the wire) otherwise — the other
12961
- * shape is `factor-unavailable`.
12977
+ * shape is `unsupported`.
12962
12978
  */
12963
12979
  async function createWithPasskey(ctx, params, requestSession) {
12964
- if (ctx.platform.passkey !== void 0 !== (params.ceremony === "kernel")) throw new KernelError("factor-unavailable", "this platform runs passkey ceremonies elsewhere");
12980
+ if (ctx.platform.passkey !== void 0 !== (params.ceremony === "kernel")) throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
12965
12981
  const gated = gate(ctx, params.factor, requestSession);
12966
12982
  let prf;
12967
12983
  try {
@@ -13127,7 +13143,7 @@ zoo`.split("\n"));
13127
13143
  var PURPOSE_PROTECTION = 2;
13128
13144
  /**
13129
13145
  * The backup PRF from one platform ceremony: user-verified with a 32-byte `first` output, else
13130
- * `factor-unavailable`. The unused `second` output is wiped.
13146
+ * `passkey-prf-unsupported`. The unused `second` output is wiped.
13131
13147
  */
13132
13148
  function backupMaterialOf(result) {
13133
13149
  var _result$second, _result$first;
@@ -13135,7 +13151,7 @@ zoo`.split("\n"));
13135
13151
  if (!result.userVerified || ((_result$first = result.first) === null || _result$first === void 0 ? void 0 : _result$first.length) !== 32) {
13136
13152
  var _result$first2;
13137
13153
  (_result$first2 = result.first) === null || _result$first2 === void 0 || _result$first2.fill(0);
13138
- throw new KernelError("factor-unavailable", "the passkey returned no verified PRF output");
13154
+ throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
13139
13155
  }
13140
13156
  return {
13141
13157
  kind: "passkey",
@@ -13151,7 +13167,7 @@ zoo`.split("\n"));
13151
13167
  */
13152
13168
  async function backupMaterial(ctx, factor, allowCredentials) {
13153
13169
  if (factor.kind === "password") return factor;
13154
- if (ctx.platform.passkey !== void 0 !== (factor.ceremony === "kernel")) throw new KernelError("factor-unavailable", "this platform runs passkey ceremonies elsewhere");
13170
+ if (ctx.platform.passkey !== void 0 !== (factor.ceremony === "kernel")) throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
13155
13171
  if (factor.ceremony === "host") return factor;
13156
13172
  const passkey = requirePasskey(ctx.platform);
13157
13173
  const salts = { first: utf8ToBytes$1(factor.backupSalt) };
@@ -19750,13 +19766,21 @@ zoo`.split("\n"));
19750
19766
  };
19751
19767
  var DEFAULT_SIGHASH = 0;
19752
19768
  var SIGHASH_ALL = 1;
19769
+ var TEMPLATES = /* @__PURE__ */ new Set([
19770
+ "btc.bip44",
19771
+ "btc.bip49",
19772
+ "btc.bip84",
19773
+ "btc.bip86"
19774
+ ]);
19775
+ var isSignEntry = (value) => isRecord$1$1(value) && typeof value["index"] === "number" && Number.isSafeInteger(value["index"]) && value["index"] >= 0 && typeof value["template"] === "string" && TEMPLATES.has(value["template"]);
19753
19776
  var isTaprootInput = (input) => input.tapInternalKey !== void 0 || getInputType(input).type === "taproot";
19754
19777
  /**
19755
19778
  * Validates and canonicalizes a bitcoin.psbt request (network already checked by the caller).
19756
19779
  * `strictPrevoutValidation` makes btc-signer verify every `nonWitnessUtxo`'s txid against its
19757
- * outpoint.
19780
+ * outpoint. The returned `sign` is sorted ascending by index — a normalized request is canonical.
19758
19781
  */
19759
19782
  var normalizeBitcoinPsbt = (psbt, sign, network) => {
19783
+ var _sorted$at;
19760
19784
  const net = bitcoinNetwork(network);
19761
19785
  let tx;
19762
19786
  try {
@@ -19764,15 +19788,16 @@ zoo`.split("\n"));
19764
19788
  } catch (_unused) {
19765
19789
  throw new ChainError("invalid-request", "PSBT failed to decode");
19766
19790
  }
19767
- if (!Array.isArray(sign) || sign.length === 0 || !sign.every((i) => Number.isSafeInteger(i) && i >= 0)) throw new ChainError("invalid-request", "sign must be a non-empty array of input indices");
19768
- const unique = [...new Set(sign.map(Number))].sort((a, b) => a - b);
19769
- const last = unique.at(-1);
19770
- if (unique.length !== sign.length || last === void 0 || last >= tx.inputsLength) throw new ChainError("invalid-request", "sign must be unique, ascending, and in range");
19791
+ if (!Array.isArray(sign) || sign.length === 0 || !sign.every(isSignEntry)) throw new ChainError("invalid-request", "sign must be a non-empty array of {index, template} entries");
19792
+ const sorted = [...sign].sort((a, b) => a.index - b.index);
19793
+ const indices = new Set(sorted.map((s) => s.index));
19794
+ const last = (_sorted$at = sorted.at(-1)) === null || _sorted$at === void 0 ? void 0 : _sorted$at.index;
19795
+ if (indices.size !== sorted.length || last === void 0 || last >= tx.inputsLength) throw new ChainError("invalid-request", "sign must be unique, ascending, and in range");
19771
19796
  checkDerivations(tx, net.coinType);
19772
- for (const idx of unique) {
19797
+ for (const { index: idx, template } of sorted) {
19773
19798
  const input = tx.getInput(idx);
19774
19799
  if (input.witnessUtxo === void 0 && input.nonWitnessUtxo === void 0) throw new ChainError("invalid-request", `input ${idx} carries neither witnessUtxo nor nonWitnessUtxo`);
19775
- if (input.bip32Derivation === void 0 && input.tapBip32Derivation === void 0) throw new ChainError("invalid-request", `input ${idx} is missing a bip32 derivation`);
19800
+ if (template === "btc.bip86" ? input.tapBip32Derivation === void 0 : input.bip32Derivation === void 0) throw new ChainError("invalid-request", `input ${idx} is missing a bip32 derivation`);
19776
19801
  const { type } = getInputType(input);
19777
19802
  if ((type === "legacy" || type === "nonwitness-script") && input.nonWitnessUtxo === void 0) throw new ChainError("invalid-request", `input ${idx} is missing nonWitnessUtxo`);
19778
19803
  const sighash = input.sighashType;
@@ -19781,7 +19806,7 @@ zoo`.split("\n"));
19781
19806
  }
19782
19807
  return {
19783
19808
  psbt: tx.toPSBT(0),
19784
- sign: unique
19809
+ sign: sorted
19785
19810
  };
19786
19811
  };
19787
19812
  var SATS = "sats";
@@ -19822,7 +19847,7 @@ zoo`.split("\n"));
19822
19847
  var decodeBitcoinPsbt = (request, ownScripts = /* @__PURE__ */ new Set()) => {
19823
19848
  const tx = parsePsbt(request.psbt);
19824
19849
  const coder = Address(bitcoinNetwork(request.network).params);
19825
- const signed = new Set(request.sign);
19850
+ const signed = new Set(request.sign.map((s) => s.index));
19826
19851
  const outflows = [];
19827
19852
  let canFee = true;
19828
19853
  let outSum = 0n;
@@ -19859,7 +19884,7 @@ zoo`.split("\n"));
19859
19884
  }
19860
19885
  const external = tx.inputsLength - signed.size > 0;
19861
19886
  const undecodable = outflows.some((o) => !o.verified);
19862
- const listing = request.sign.some((i) => tx.getInput(i).sighashType === SIGHASH_SINGLE_ANYONECANPAY);
19887
+ const listing = request.sign.some((s) => tx.getInput(s.index).sighashType === SIGHASH_SINGLE_ANYONECANPAY);
19863
19888
  const verifiability = external ? "opaque" : listing || undecodable ? "partial" : "full";
19864
19889
  return {
19865
19890
  family: "bitcoin",
@@ -19911,19 +19936,28 @@ zoo`.split("\n"));
19911
19936
  */
19912
19937
  var normalizeBitcoin = (request) => {
19913
19938
  if (!isRecord$3(request) || typeof request["kind"] !== "string") throw new ChainError("invalid-request", "request must be an object with a kind");
19914
- const { network, account } = common(request);
19915
19939
  if (request["kind"] === "bitcoin.psbt") {
19916
- const { psbt } = request;
19940
+ const { network, account, psbt } = request;
19941
+ if (typeof network !== "string") throw new ChainError("invalid-request", "request.network must be a string");
19942
+ bitcoinNetwork(network);
19943
+ if (!isRecord$3(account) || account["kind"] !== "hd") throw new ChainError("invalid-request", "request.account must be a wallet group");
19944
+ const { walletId, groupIndex } = account;
19945
+ if (typeof walletId !== "string" || typeof groupIndex !== "number" || !Number.isSafeInteger(groupIndex) || groupIndex < 0) throw new ChainError("invalid-request", "request.account must be a wallet group");
19917
19946
  if (!(psbt instanceof Uint8Array)) throw new ChainError("invalid-request", "psbt must be bytes");
19918
19947
  const normalized = normalizeBitcoinPsbt(psbt, request["sign"], network);
19919
19948
  return {
19920
19949
  kind: "bitcoin.psbt",
19921
19950
  network,
19922
- account,
19951
+ account: {
19952
+ kind: "hd",
19953
+ walletId,
19954
+ groupIndex
19955
+ },
19923
19956
  psbt: normalized.psbt,
19924
19957
  sign: normalized.sign
19925
19958
  };
19926
19959
  }
19960
+ const { network, account } = common(request);
19927
19961
  if (request["kind"] === "bitcoin.message") {
19928
19962
  const { format } = request;
19929
19963
  const target = messageTarget(request["address"], network, format);
@@ -29002,6 +29036,23 @@ zoo`.split("\n"));
29002
29036
  init_transaction();
29003
29037
  var isPath = (path) => Array.isArray(path) && path.every((p) => typeof p === "number");
29004
29038
  var hex$1 = (bytes) => bytes.reduce((acc, b) => acc + b.toString(16).padStart(2, "0"), "");
29039
+ var PURPOSES = [
29040
+ 44,
29041
+ 49,
29042
+ 84,
29043
+ 86
29044
+ ];
29045
+ var contextFor = (b, purpose) => {
29046
+ let ctx = b.purposes.get(purpose);
29047
+ if (ctx === void 0) {
29048
+ ctx = {
29049
+ accountNode: b.master.derive(`m/${purpose}'/${b.coinType}'/${b.groupIndex}'`),
29050
+ children: []
29051
+ };
29052
+ b.purposes.set(purpose, ctx);
29053
+ }
29054
+ return ctx;
29055
+ };
29005
29056
  /** The PSBT derivation entry that claims this account's fingerprint and path, if any. */
29006
29057
  var derivationOf = (owner, fingerprint, purpose) => {
29007
29058
  var _owner$bip32Derivatio;
@@ -29023,58 +29074,70 @@ zoo`.split("\n"));
29023
29074
  };
29024
29075
  var expectedPub = (purpose, pub) => purpose === 86 ? pub.slice(1) : pub;
29025
29076
  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;
29026
- /** Derives `m/purpose'/coin'/group'/change/index` — the only path shape this account may sign. */
29027
- var childAt = (b, path) => {
29077
+ /** Derives `m/purpose'/coin'/group'/change/index` — the only path shape this group may sign. */
29078
+ var childAt = (b, purpose, path) => {
29028
29079
  const [purposePath, coinPath, groupPath, change, index] = path;
29029
- if (path.length !== 5 || purposePath !== b.purpose + b.hardened || coinPath !== b.coinType + b.hardened || groupPath !== b.account.groupIndex + b.hardened || change === void 0 || index === void 0 || change !== 0 && change !== 1 || index < 0 || index >= b.hardened) throw new KernelError("invalid-input", "derivation path is not this account's");
29030
- const child = b.accountNode.deriveChild(change).deriveChild(index);
29031
- b.children.push(child);
29080
+ if (path.length !== 5 || purposePath !== purpose + b.hardened || coinPath !== b.coinType + b.hardened || groupPath !== b.groupIndex + b.hardened || change === void 0 || index === void 0 || change !== 0 && change !== 1 || index < 0 || index >= b.hardened) throw new KernelError("invalid-input", "derivation path is not this account's");
29081
+ const ctx = contextFor(b, purpose);
29082
+ const child = ctx.accountNode.deriveChild(change).deriveChild(index);
29083
+ ctx.children.push(child);
29032
29084
  return child;
29033
29085
  };
29034
29086
  /**
29035
- * Ownership check for one `request.sign` input: the derivation entry must be this account's, the
29036
- * claimed pubkey the derived child's, and the prevout script (witnessUtxo, or nonWitnessUtxo for
29037
- * P2PKH, plus redeemScript for P2SH-P2WPKH) the script of that key.
29087
+ * Ownership check for one `request.sign` entry: under the entry's own template, the derivation
29088
+ * entry must be this account's, the claimed pubkey the derived child's, and the prevout script
29089
+ * (witnessUtxo, or nonWitnessUtxo for P2PKH, plus redeemScript for P2SH-P2WPKH) the script of that
29090
+ * key. A template that disagrees with the input's script type fails the path or script check.
29038
29091
  */
29039
- var bitcoinInput = (b, tx, idx) => {
29092
+ var bitcoinInput = (b, tx, entry) => {
29093
+ const purpose = BTC_PURPOSE[entry.template];
29094
+ if (purpose === void 0) throw new KernelError("invalid-input", "sign template is not a bitcoin account template");
29095
+ const { index: idx } = entry;
29040
29096
  const input = tx.getInput(idx);
29041
- const entry = derivationOf(input, b.master.fingerprint, b.purpose);
29042
- if (entry === void 0) throw new KernelError("invalid-input", `input ${idx}: derivation entry is not this account's`);
29043
- const child = childAt(b, entry.path);
29097
+ const der = derivationOf(input, b.master.fingerprint, purpose);
29098
+ if (der === void 0) throw new KernelError("invalid-input", `input ${idx}: derivation entry is not this account's`);
29099
+ const child = childAt(b, purpose, der.path);
29044
29100
  const pub = child.publicKey;
29045
29101
  const priv = child.privateKey;
29046
29102
  if (pub === null || priv === null) throw new KernelError("integrity", "no key at derivation path");
29047
- if (!deepEqual(entry.pubkey, expectedPub(b.purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: derivation pubkey is not ours`);
29048
- if (b.purpose === 44) {
29103
+ if (!deepEqual(der.pubkey, expectedPub(purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: derivation pubkey is not ours`);
29104
+ if (purpose === 44) {
29049
29105
  var _outs$vout;
29050
29106
  if (input.nonWitnessUtxo === void 0) throw new KernelError("invalid-input", `input ${idx}: P2PKH spend requires nonWitnessUtxo`);
29051
29107
  const vout = input.index;
29052
29108
  const outs = input.nonWitnessUtxo.outputs;
29053
29109
  const prevScript = vout === void 0 ? void 0 : (_outs$vout = outs[vout]) === null || _outs$vout === void 0 ? void 0 : _outs$vout.script;
29054
- if (prevScript === void 0 || !deepEqual(prevScript, expectedScript(b.purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: nonWitnessUtxo prevout is not this key's`);
29110
+ if (prevScript === void 0 || !deepEqual(prevScript, expectedScript(purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: nonWitnessUtxo prevout is not this key's`);
29055
29111
  } else {
29056
29112
  const prevout = input.witnessUtxo;
29057
- if (prevout === void 0 || !deepEqual(prevout.script, expectedScript(b.purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: prevout script is not this key's`);
29058
- if (b.purpose === 49 && (input.redeemScript === void 0 || !deepEqual(input.redeemScript, p2wpkh(pub).script))) throw new KernelError("invalid-input", `input ${idx}: redeemScript is not this key's`);
29113
+ if (prevout === void 0 || !deepEqual(prevout.script, expectedScript(purpose, pub))) throw new KernelError("invalid-input", `input ${idx}: prevout script is not this key's`);
29114
+ if (purpose === 49 && (input.redeemScript === void 0 || !deepEqual(input.redeemScript, p2wpkh(pub).script))) throw new KernelError("invalid-input", `input ${idx}: redeemScript is not this key's`);
29059
29115
  }
29060
29116
  return {
29061
29117
  index: idx,
29062
29118
  privateKey: priv
29063
29119
  };
29064
29120
  };
29065
- /** Output binding: the scripts of outputs that look like this account's (its change addresses). */
29121
+ /**
29122
+ * Output binding, independent of which templates sign inputs: an output is this group's own when it
29123
+ * carries a derivation entry with our fingerprint — tap entries only for bip86, bip32 entries for
29124
+ * 44/49/84 — whose path is a valid `m/purpose'/coin'/group'/{0,1}/i` of this group and whose script
29125
+ * equals that key's script for the purpose. Failures just mean "not own".
29126
+ */
29066
29127
  var bitcoinOwnScripts = (b, tx) => {
29067
29128
  const ownScripts = /* @__PURE__ */ new Set();
29068
29129
  for (let i = 0; i < tx.outputsLength; i++) {
29069
29130
  const output = tx.getOutput(i);
29070
29131
  if (output.script === void 0) continue;
29071
- const entry = derivationOf(output, b.master.fingerprint, b.purpose);
29072
- if (entry === void 0) continue;
29073
- try {
29074
- const pub = childAt(b, entry.path).publicKey;
29075
- if (pub !== null && deepEqual(output.script, expectedScript(b.purpose, pub))) ownScripts.add(hex$1(output.script));
29076
- } catch (_unused) {
29077
- continue;
29132
+ for (const purpose of PURPOSES) {
29133
+ const entry = derivationOf(output, b.master.fingerprint, purpose);
29134
+ if (entry === void 0) continue;
29135
+ try {
29136
+ const pub = childAt(b, purpose, entry.path).publicKey;
29137
+ if (pub !== null && deepEqual(output.script, expectedScript(purpose, pub))) ownScripts.add(hex$1(output.script));
29138
+ } catch (_unused) {
29139
+ continue;
29140
+ }
29078
29141
  }
29079
29142
  }
29080
29143
  return ownScripts;
@@ -29082,7 +29145,7 @@ zoo`.split("\n"));
29082
29145
  /** The PSBT path: input ownership, output binding, normalize, decode intent or sign. */
29083
29146
  var executeBitcoinPsbt = (b, request, random, intentOnly) => {
29084
29147
  const tx = Transaction.fromPSBT(request.psbt);
29085
- const inputs = request.sign.map((idx) => bitcoinInput(b, tx, idx));
29148
+ const inputs = request.sign.map((entry) => bitcoinInput(b, tx, entry));
29086
29149
  const ownScripts = bitcoinOwnScripts(b, tx);
29087
29150
  let normalized;
29088
29151
  try {
@@ -29104,19 +29167,19 @@ zoo`.split("\n"));
29104
29167
  };
29105
29168
  };
29106
29169
  /** The message path: the declared change/index must derive this address, then normalize/sign. */
29107
- var executeBitcoinMessage = (b, request, random, intentOnly) => {
29108
- if (request.format === "legacy" && b.account.template !== "btc.bip44") throw new KernelError("unsupported", "legacy message format is btc.bip44-only");
29109
- const child = childAt(b, [
29110
- b.purpose + b.hardened,
29170
+ var executeBitcoinMessage = (b, purpose, request, random, intentOnly) => {
29171
+ if (request.format === "legacy" && purpose !== 44) throw new KernelError("unsupported", "legacy message format is btc.bip44-only");
29172
+ const child = childAt(b, purpose, [
29173
+ purpose + b.hardened,
29111
29174
  b.coinType + b.hardened,
29112
- b.account.groupIndex + b.hardened,
29175
+ b.groupIndex + b.hardened,
29113
29176
  request.change,
29114
29177
  request.index
29115
29178
  ]);
29116
29179
  const pub = child.publicKey;
29117
29180
  const priv = child.privateKey;
29118
29181
  if (pub === null || priv === null) throw new KernelError("integrity", "no key at derivation path");
29119
- if ((b.purpose === 86 ? p2tr(pub.slice(1), void 0, b.net.params).address : b.purpose === 49 ? p2sh(p2wpkh(pub, b.net.params), b.net.params).address : b.purpose === 44 ? p2pkh(pub, b.net.params).address : p2wpkh(pub, b.net.params).address) !== request.address) throw new KernelError("invalid-input", "address is not ours");
29182
+ if ((purpose === 86 ? p2tr(pub.slice(1), void 0, 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) !== request.address) throw new KernelError("invalid-input", "address is not ours");
29120
29183
  let normalized;
29121
29184
  try {
29122
29185
  normalized = normalizeBitcoin(request);
@@ -29138,31 +29201,25 @@ zoo`.split("\n"));
29138
29201
  var executeBitcoin = (random, request, account, seed, intentOnly) => {
29139
29202
  const net = bitcoinNetwork(request.network);
29140
29203
  const master = HDKey$1.fromMasterSeed(seed, net.bip32);
29204
+ const b = {
29205
+ master,
29206
+ purposes: /* @__PURE__ */ new Map(),
29207
+ coinType: net.coinType,
29208
+ hardened: 2147483648,
29209
+ groupIndex: account.groupIndex,
29210
+ net
29211
+ };
29141
29212
  try {
29142
- var _BTC_PURPOSE$account$;
29143
- const purpose = (_BTC_PURPOSE$account$ = BTC_PURPOSE[account.template]) !== null && _BTC_PURPOSE$account$ !== void 0 ? _BTC_PURPOSE$account$ : 84;
29144
- const { coinType } = net;
29145
- const hardened = 2147483648;
29146
- const accountNode = master.derive(`m/${purpose}'/${coinType}'/${account.groupIndex}'`);
29147
- const children = [];
29148
- const b = {
29149
- master,
29150
- accountNode,
29151
- children,
29152
- purpose,
29153
- coinType,
29154
- hardened,
29155
- account,
29156
- net
29157
- };
29158
- try {
29159
- if (request.kind === "bitcoin.psbt") return executeBitcoinPsbt(b, request, random, intentOnly);
29160
- return executeBitcoinMessage(b, request, random, intentOnly);
29161
- } finally {
29162
- for (const child of children) child.wipePrivateData();
29163
- accountNode.wipePrivateData();
29164
- }
29213
+ if (request.kind === "bitcoin.psbt") return executeBitcoinPsbt(b, request, random, intentOnly);
29214
+ if (request.account.kind !== "hd") throw new KernelError("unsupported", "imported accounts are not yet supported");
29215
+ const purpose = BTC_PURPOSE[request.account.template];
29216
+ if (purpose === void 0) throw new KernelError("invalid-input", "account template is not a bitcoin template");
29217
+ return executeBitcoinMessage(b, purpose, request, random, intentOnly);
29165
29218
  } finally {
29219
+ for (const ctx of b.purposes.values()) {
29220
+ for (const child of ctx.children) child.wipePrivateData();
29221
+ ctx.accountNode.wipePrivateData();
29222
+ }
29166
29223
  master.wipePrivateData();
29167
29224
  }
29168
29225
  };
@@ -29403,19 +29460,26 @@ zoo`.split("\n"));
29403
29460
  const { request, verify } = params;
29404
29461
  const { account } = request;
29405
29462
  if (account.kind !== "hd") throw new KernelError("unsupported", "imported accounts are not yet supported");
29406
- const [family] = request.kind.split(".", 1);
29407
- if (!(family === "evm" ? ["evm.bip44"] : family === "solana" ? ["solana.bip44-change"] : [
29408
- "btc.bip44",
29409
- "btc.bip49",
29410
- "btc.bip84",
29411
- "btc.bip86"
29412
- ]).includes(account.template)) throw new KernelError("invalid-input", "account template does not match the request family");
29463
+ if (request.kind === "bitcoin.psbt") {
29464
+ if (request.sign.some((s) => BTC_PURPOSE[s.template] === void 0)) throw new KernelError("invalid-input", "sign template is not a bitcoin account template");
29465
+ } else {
29466
+ const [family] = request.kind.split(".", 1);
29467
+ const expected = family === "evm" ? ["evm.bip44"] : family === "solana" ? ["solana.bip44-change"] : [
29468
+ "btc.bip44",
29469
+ "btc.bip49",
29470
+ "btc.bip84",
29471
+ "btc.bip86"
29472
+ ];
29473
+ if (!("template" in account) || !expected.includes(account.template)) throw new KernelError("invalid-input", "account template does not match the request family");
29474
+ }
29413
29475
  const record = ctx.image.records.find((entry) => entry.kind === "entropy" && entry.id === account.walletId);
29414
29476
  if (record === void 0) throw new KernelError("not-found", "no such wallet");
29415
29477
  const execute = (seed, intentOnly) => {
29416
- if (request.kind === "evm.transaction" || request.kind === "evm.personal-message" || request.kind === "evm.typed-data") return executeEvm(request, account, seed, intentOnly);
29417
- if (request.kind === "bitcoin.psbt" || request.kind === "bitcoin.message") return executeBitcoin(ctx.platform.random, request, account, seed, intentOnly);
29418
- return executeSolana(request, account, seed, intentOnly);
29478
+ if (request.kind === "bitcoin.psbt") return executeBitcoin(ctx.platform.random, request, request.account, seed, intentOnly);
29479
+ if (request.account.kind !== "hd") throw new KernelError("unsupported", "imported accounts are not yet supported");
29480
+ if (request.kind === "bitcoin.message") return executeBitcoin(ctx.platform.random, request, request.account, seed, intentOnly);
29481
+ if (request.kind === "evm.transaction" || request.kind === "evm.personal-message" || request.kind === "evm.typed-data") return executeEvm(request, request.account, seed, intentOnly);
29482
+ return executeSolana(request, request.account, seed, intentOnly);
29419
29483
  };
29420
29484
  const withSeed = async (run) => withWalletSeed(ctx.platform.pbkdf2, dek, record, run);
29421
29485
  const prepared = await withSeed((seed) => execute(seed, true));
@@ -29444,7 +29508,7 @@ zoo`.split("\n"));
29444
29508
  }
29445
29509
  };
29446
29510
  }
29447
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/util-BcRBO6o-.mjs
29511
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/util-D8wUYmm0.mjs
29448
29512
  init_utils$2();
29449
29513
  init_defineProperty();
29450
29514
  /** Base error for all @qntx/nostr failures. */
@@ -29542,7 +29606,7 @@ zoo`.split("\n"));
29542
29606
  }
29543
29607
  return false;
29544
29608
  }
29545
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/kind-I2Tvbe82.mjs
29609
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/kind-BAnfDHdg.mjs
29546
29610
  /** Kind numbers used by this package. */
29547
29611
  var Kind = {
29548
29612
  Metadata: 0,
@@ -29574,7 +29638,7 @@ zoo`.split("\n"));
29574
29638
  EmojiSet: 30030,
29575
29639
  StarterPack: 39089
29576
29640
  };
29577
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/event-DHtcm0jM.mjs
29641
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/event-B__SmruU.mjs
29578
29642
  init_sha2();
29579
29643
  /** Type guard: a non-empty array of strings. */
29580
29644
  function isTag(value) {
@@ -29654,7 +29718,7 @@ zoo`.split("\n"));
29654
29718
  const serialized = serializeEvent(event);
29655
29719
  return bytesToHex$1(sha256$1(utf8Encoder.encode(serialized)));
29656
29720
  }
29657
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/key-Bt0ow7mI.mjs
29721
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/key-BxwA02Gx.mjs
29658
29722
  init_utils$2();
29659
29723
  init_sha2();
29660
29724
  init_secp256k1();
@@ -29801,7 +29865,7 @@ zoo`.split("\n"));
29801
29865
  markVerified(event);
29802
29866
  return event;
29803
29867
  }
29804
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/verifier-DBSPHzGg.mjs
29868
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/verifier-iQR5ivRF.mjs
29805
29869
  /**
29806
29870
  * Build an event verifier with exactly the semantics of {@link verifyEvent}, delegating the hash and
29807
29871
  * signature check to `backend`. Verified/failed results share `verifyEvent`'s WeakSet caches, so
@@ -29823,7 +29887,7 @@ zoo`.split("\n"));
29823
29887
  }
29824
29888
  /** Verify event id and BIP-340 signature. Uses WeakSet cache (does not mutate the event). */
29825
29889
  var verifyEvent = createEventVerifier(nobleBackend);
29826
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/error-CoP2myne.mjs
29890
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/error-Cord_cbw.mjs
29827
29891
  init_defineProperty();
29828
29892
  /** Thrown when a method is called on a signer after {@link NostrSigner dispose}. */
29829
29893
  var SignerDisposedError = class extends NostrError {
@@ -30125,7 +30189,7 @@ zoo`.split("\n"));
30125
30189
  }
30126
30190
  };
30127
30191
  });
30128
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip04.mjs
30192
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip04.mjs
30129
30193
  init_utils$2();
30130
30194
  init_base();
30131
30195
  /** NIP-04 legacy encrypted direct messages. Prefer NIP-44 for new applications. */
@@ -30186,7 +30250,7 @@ zoo`.split("\n"));
30186
30250
  if (parts.length !== 2 || ciphertext === void 0 || ciphertext === "" || iv === void 0 || iv === "") throw new CryptoError("invalid NIP-04 payload: missing iv");
30187
30251
  return [ciphertext, iv];
30188
30252
  }
30189
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip44.mjs
30253
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip44.mjs
30190
30254
  init_utils$2();
30191
30255
  init_sha2();
30192
30256
  init_base();
@@ -30308,7 +30372,7 @@ zoo`.split("\n"));
30308
30372
  if (!equalBytes$3(hmacAad(hmac_key, ciphertext, nonce), mac)) throw new CryptoError("invalid MAC");
30309
30373
  return unpad(chacha20(chacha_key, chacha_nonce, ciphertext));
30310
30374
  }
30311
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip59.mjs
30375
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip59.mjs
30312
30376
  init_defineProperty();
30313
30377
  init_objectSpread2();
30314
30378
  /**
@@ -30376,13 +30440,13 @@ zoo`.split("\n"));
30376
30440
  if (sealRaw.pubkey !== rumor.pubkey) throw new Nip59Error("seal pubkey does not match rumor pubkey");
30377
30441
  return rumor;
30378
30442
  }
30379
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip46.mjs
30443
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip46.mjs
30380
30444
  init_defineProperty();
30381
30445
  // \0@oxc-project+runtime@0.155.0/helpers/esm/classPrivateMethodInitSpec.js
30382
30446
  function _classPrivateMethodInitSpec(e, a) {
30383
30447
  _checkPrivateRedeclaration(e, a), a.add(e);
30384
30448
  }
30385
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/signer-DQzjm3pt.mjs
30449
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/signer-Y3gcghwd.mjs
30386
30450
  init_utils$2();
30387
30451
  init_objectSpread2();
30388
30452
  var _keys;
@@ -30479,7 +30543,7 @@ zoo`.split("\n"));
30479
30543
  }
30480
30544
  return key;
30481
30545
  }
30482
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip19.mjs
30546
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip19.mjs
30483
30547
  init_base();
30484
30548
  /** Maximum bech32 string length accepted by {@link decode} (NIP-19). */
30485
30549
  var Bech32MaxSize = 5e3;
@@ -30715,7 +30779,7 @@ zoo`.split("\n"));
30715
30779
  swap32IfBE(B32);
30716
30780
  return scryptOutput(password, dkLen, B, V, tmp);
30717
30781
  }
30718
- // node_modules/.bun/@qntx+nostr@0.15.3+ea9f70ecde856c26/node_modules/@qntx/nostr/dist/nips/nip49.mjs
30782
+ // node_modules/.bun/@qntx+nostr@0.15.4+cb72dcd9952e90a1/node_modules/@qntx/nostr/dist/nips/nip49.mjs
30719
30783
  init_utils$2();
30720
30784
  init_defineProperty();
30721
30785
  init_objectSpread2();
@@ -41309,10 +41373,7 @@ zoo`.split("\n"));
41309
41373
  integrityFailure = true;
41310
41374
  setHealth("corrupted");
41311
41375
  }
41312
- const err = error instanceof KernelError ? error.retryAt === void 0 ? { code: error.code } : {
41313
- code: error.code,
41314
- retryAt: error.retryAt
41315
- } : { code: "integrity" };
41376
+ const err = error instanceof KernelError ? _objectSpread2(_objectSpread2({ code: error.code }, error.retryAt === void 0 ? {} : { retryAt: error.retryAt }), error.detail === void 0 ? {} : { detail: error.detail }) : { code: "integrity" };
41316
41377
  return {
41317
41378
  v: 2,
41318
41379
  id,
@@ -41338,21 +41399,32 @@ zoo`.split("\n"));
41338
41399
  });
41339
41400
  enqueue(reloadAndPost);
41340
41401
  }
41402
+ // packages/wallet-native/kernel/detail.ts
41403
+ /**
41404
+ * A `"<domain>:<code>"` diagnostic a platform reports alongside a failure code (e.g.
41405
+ * `"LAErrorDomain:-5"`, `"android:KeyPermanentlyInvalidatedException"`): kept only when it is a
41406
+ * short token string — anything else (oversize, free text) is dropped at this producer boundary,
41407
+ * never rejected. Never carries userInfo, localized text or input.
41408
+ */
41409
+ function detailOf(detail) {
41410
+ return detail !== void 0 && detail.length <= 80 && /^[A-Za-z0-9_.:-]+$/.test(detail) ? detail : void 0;
41411
+ }
41341
41412
  // packages/wallet-native/kernel/keystore.ts
41342
41413
  /**
41343
41414
  * Binds the native `__qntx.keystore` object to the kernel's `Keystore` contract. The C++ side
41344
- * completes each call with `(bytes, code)`; a failure code is already the kernel error code
41345
- * (`cancelled`, `factor-invalidated`, `factor-unavailable`, `unavailable`) and becomes a
41415
+ * completes each call with `(bytes, code, detail)`; a failure code is already the kernel error code
41416
+ * (`cancelled`, `factor-invalidated`, `no-device-credential`, `unavailable`) and becomes a
41346
41417
  * `KernelError` so the vault reports it verbatim instead of as an integrity failure.
41347
41418
  */
41348
- function failure$1(code) {
41349
- return code === "cancelled" || code === "factor-invalidated" || code === "factor-unavailable" || code === "unavailable" ? new KernelError(code, "the platform keystore did not complete") : new KernelError("unavailable", "the platform keystore reported no outcome");
41419
+ function failure$1(code, detail) {
41420
+ const diagnostic = detailOf(detail);
41421
+ return code === "cancelled" || code === "factor-invalidated" || code === "no-device-credential" || code === "unavailable" ? new KernelError(code, "the platform keystore did not complete", void 0, false, diagnostic) : new KernelError("unavailable", "the platform keystore reported no outcome", void 0, false, diagnostic);
41350
41422
  }
41351
41423
  async function bytesOf$1(start) {
41352
41424
  return new Promise((resolve, reject) => {
41353
- start((result, code) => {
41425
+ start((result, code, detail) => {
41354
41426
  if (result === void 0) {
41355
- reject(failure$1(code));
41427
+ reject(failure$1(code, detail));
41356
41428
  return;
41357
41429
  }
41358
41430
  resolve(result);
@@ -41361,9 +41433,9 @@ zoo`.split("\n"));
41361
41433
  }
41362
41434
  async function outcomeOf(start) {
41363
41435
  return new Promise((resolve, reject) => {
41364
- start((_result, code) => {
41436
+ start((_result, code, detail) => {
41365
41437
  if (code !== void 0) {
41366
- reject(failure$1(code));
41438
+ reject(failure$1(code, detail));
41367
41439
  return;
41368
41440
  }
41369
41441
  resolve();
@@ -43756,8 +43828,9 @@ zoo`.split("\n"));
43756
43828
  };
43757
43829
  /** Whether bit `flag` (a power of two) is set in the authenticator-data flags byte. */
43758
43830
  var hasFlag = (flags, flag) => Math.floor(flags / flag) % 2 === 1;
43759
- function failure(code) {
43760
- return code === "cancelled" || code === "factor-unavailable" || code === "unavailable" ? new KernelError(code, "the platform passkey ceremony did not complete") : new KernelError("unavailable", "the platform passkey ceremony reported no outcome");
43831
+ function failure(code, detail) {
43832
+ const diagnostic = detailOf(detail);
43833
+ return code === "cancelled" || code === "passkey-not-configured" || code === "unsupported" || code === "unavailable" ? new KernelError(code, "the platform passkey ceremony did not complete", void 0, false, diagnostic) : new KernelError("unavailable", "the platform passkey ceremony reported no outcome", void 0, false, diagnostic);
43761
43834
  }
43762
43835
  var malformed = () => new KernelError("unavailable", "the platform returned a malformed passkey response");
43763
43836
  var b64 = (bytes) => base64urlnopad.encode(bytes);
@@ -43829,7 +43902,7 @@ zoo`.split("\n"));
43829
43902
  if (!assertion && enabled === false) {
43830
43903
  first === null || first === void 0 || first.fill(0);
43831
43904
  second === null || second === void 0 || second.fill(0);
43832
- throw new KernelError("factor-unavailable", "the passkey does not support the PRF extension");
43905
+ throw new KernelError("passkey-prf-unsupported", "the passkey does not support the PRF extension");
43833
43906
  }
43834
43907
  const rawAuthData = response["authenticatorData"];
43835
43908
  let authData;
@@ -43862,9 +43935,9 @@ zoo`.split("\n"));
43862
43935
  }
43863
43936
  async function run(start, request, assertion) {
43864
43937
  return parseResponse(await new Promise((resolve, reject) => {
43865
- start(JSON.stringify(request), (responseJson, code) => {
43938
+ start(JSON.stringify(request), (responseJson, code, detail) => {
43866
43939
  if (responseJson === void 0) {
43867
- reject(failure(code));
43940
+ reject(failure(code, detail));
43868
43941
  return;
43869
43942
  }
43870
43943
  resolve(responseJson);