@aastar/sdk 0.24.2 → 0.26.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.
Files changed (126) hide show
  1. package/dist/UserClient-5PQP6APK.js +6 -0
  2. package/dist/{UserClient-DPJ6E2XL.js.map → UserClient-5PQP6APK.js.map} +1 -1
  3. package/dist/UserClient-CD7R3335.cjs +15 -0
  4. package/dist/{UserClient-4MRK2D7W.cjs.map → UserClient-CD7R3335.cjs.map} +1 -1
  5. package/dist/account.cjs +8 -8
  6. package/dist/account.js +3 -3
  7. package/dist/addresses-D12T3kLs.d.cts +210 -0
  8. package/dist/addresses-D12T3kLs.d.ts +210 -0
  9. package/dist/admin.cjs +4 -4
  10. package/dist/admin.js +3 -3
  11. package/dist/airaccount.cjs +135 -103
  12. package/dist/airaccount.d.cts +1 -1
  13. package/dist/airaccount.d.ts +1 -1
  14. package/dist/airaccount.js +3 -3
  15. package/dist/channel.cjs +7 -7
  16. package/dist/channel.js +3 -3
  17. package/dist/{chunk-S7IUUQ5E.cjs → chunk-2RHBOBL7.cjs} +6 -6
  18. package/dist/{chunk-S7IUUQ5E.cjs.map → chunk-2RHBOBL7.cjs.map} +1 -1
  19. package/dist/{chunk-BPAAWQQA.js → chunk-4GJSK7E6.js} +557 -115
  20. package/dist/chunk-4GJSK7E6.js.map +1 -0
  21. package/dist/{chunk-EEWLL7GE.js → chunk-6DZCDV4Q.js} +2137 -13
  22. package/dist/chunk-6DZCDV4Q.js.map +1 -0
  23. package/dist/{chunk-MCDFQ5JH.cjs → chunk-7HTUDNH3.cjs} +11 -11
  24. package/dist/{chunk-MCDFQ5JH.cjs.map → chunk-7HTUDNH3.cjs.map} +1 -1
  25. package/dist/{chunk-UJPW54CK.js → chunk-7JVL5CU3.js} +3 -3
  26. package/dist/{chunk-UJPW54CK.js.map → chunk-7JVL5CU3.js.map} +1 -1
  27. package/dist/{chunk-7FLPD3V4.js → chunk-A4FO6FKN.js} +3 -3
  28. package/dist/{chunk-7FLPD3V4.js.map → chunk-A4FO6FKN.js.map} +1 -1
  29. package/dist/{chunk-MANVOQY7.cjs → chunk-CI4UJW5Y.cjs} +5 -5
  30. package/dist/{chunk-MANVOQY7.cjs.map → chunk-CI4UJW5Y.cjs.map} +1 -1
  31. package/dist/{chunk-PUE5GEKK.js → chunk-COTHBCR2.js} +3 -3
  32. package/dist/{chunk-PUE5GEKK.js.map → chunk-COTHBCR2.js.map} +1 -1
  33. package/dist/{chunk-TQIRRSGL.cjs → chunk-FIMXPANS.cjs} +4 -4
  34. package/dist/{chunk-TQIRRSGL.cjs.map → chunk-FIMXPANS.cjs.map} +1 -1
  35. package/dist/{chunk-MXJEULSE.cjs → chunk-G33MXEHU.cjs} +29 -2
  36. package/dist/chunk-G33MXEHU.cjs.map +1 -0
  37. package/dist/{chunk-FUY4MHPM.cjs → chunk-GASCTLKR.cjs} +9 -9
  38. package/dist/{chunk-FUY4MHPM.cjs.map → chunk-GASCTLKR.cjs.map} +1 -1
  39. package/dist/{chunk-W73Y6JWZ.js → chunk-IG4BG25C.js} +6 -6
  40. package/dist/{chunk-W73Y6JWZ.js.map → chunk-IG4BG25C.js.map} +1 -1
  41. package/dist/{chunk-TGEVD7OR.cjs → chunk-J3UAXGNP.cjs} +16 -16
  42. package/dist/{chunk-TGEVD7OR.cjs.map → chunk-J3UAXGNP.cjs.map} +1 -1
  43. package/dist/{chunk-Y5QM4LI4.js → chunk-JCEUTCFZ.js} +4 -4
  44. package/dist/{chunk-Y5QM4LI4.js.map → chunk-JCEUTCFZ.js.map} +1 -1
  45. package/dist/{chunk-IB3KOSHW.cjs → chunk-KOWTQJIX.cjs} +2177 -49
  46. package/dist/chunk-KOWTQJIX.cjs.map +1 -0
  47. package/dist/chunk-L6D2AGTF.js +500 -0
  48. package/dist/chunk-L6D2AGTF.js.map +1 -0
  49. package/dist/{chunk-KYXXIKEI.cjs → chunk-LRPAX5AG.cjs} +32 -32
  50. package/dist/{chunk-KYXXIKEI.cjs.map → chunk-LRPAX5AG.cjs.map} +1 -1
  51. package/dist/{chunk-UCLK6LTB.js → chunk-MBWBHKUE.js} +28 -3
  52. package/dist/chunk-MBWBHKUE.js.map +1 -0
  53. package/dist/{chunk-3FRNYRWI.cjs → chunk-NHDZQPDE.cjs} +26 -26
  54. package/dist/{chunk-3FRNYRWI.cjs.map → chunk-NHDZQPDE.cjs.map} +1 -1
  55. package/dist/{chunk-HP44S5U5.cjs → chunk-OBPTMV5W.cjs} +5 -5
  56. package/dist/{chunk-HP44S5U5.cjs.map → chunk-OBPTMV5W.cjs.map} +1 -1
  57. package/dist/{chunk-SX5GUCTF.js → chunk-QTXPAGNX.js} +9 -9
  58. package/dist/{chunk-SX5GUCTF.js.map → chunk-QTXPAGNX.js.map} +1 -1
  59. package/dist/{chunk-PTVXBXZX.js → chunk-UANSP3OK.js} +3 -3
  60. package/dist/{chunk-PTVXBXZX.js.map → chunk-UANSP3OK.js.map} +1 -1
  61. package/dist/{chunk-P3B6UTED.js → chunk-UTSFTWFC.js} +3 -3
  62. package/dist/{chunk-P3B6UTED.js.map → chunk-UTSFTWFC.js.map} +1 -1
  63. package/dist/{chunk-4Q6FADF6.cjs → chunk-UZE7IPOK.cjs} +571 -121
  64. package/dist/chunk-UZE7IPOK.cjs.map +1 -0
  65. package/dist/chunk-WTURYJEA.cjs +504 -0
  66. package/dist/chunk-WTURYJEA.cjs.map +1 -0
  67. package/dist/{chunk-XBZGVJ5K.js → chunk-YR7CTWY6.js} +3 -3
  68. package/dist/{chunk-XBZGVJ5K.js.map → chunk-YR7CTWY6.js.map} +1 -1
  69. package/dist/{contract-addresses-RABD77VP.cjs → contract-addresses-6K6IB5OB.cjs} +13 -13
  70. package/dist/{contract-addresses-RABD77VP.cjs.map → contract-addresses-6K6IB5OB.cjs.map} +1 -1
  71. package/dist/{contract-addresses-TVXSRQ7I.js → contract-addresses-CHZ7PK5H.js} +3 -3
  72. package/dist/{contract-addresses-TVXSRQ7I.js.map → contract-addresses-CHZ7PK5H.js.map} +1 -1
  73. package/dist/core.cjs +285 -261
  74. package/dist/core.d.cts +6 -175
  75. package/dist/core.d.ts +6 -175
  76. package/dist/core.js +2 -2
  77. package/dist/dapp.cjs +6 -6
  78. package/dist/dapp.js +3 -3
  79. package/dist/enduser.cjs +7 -7
  80. package/dist/enduser.js +4 -4
  81. package/dist/identity.cjs +6 -6
  82. package/dist/identity.js +3 -3
  83. package/dist/index.cjs +406 -374
  84. package/dist/index.d.cts +3 -2
  85. package/dist/index.d.ts +3 -2
  86. package/dist/index.js +17 -17
  87. package/dist/kms.cjs +135 -103
  88. package/dist/kms.d.cts +330 -26
  89. package/dist/kms.d.ts +330 -26
  90. package/dist/kms.js +3 -3
  91. package/dist/operator.cjs +7 -7
  92. package/dist/operator.js +3 -3
  93. package/dist/paymaster.cjs +16 -16
  94. package/dist/paymaster.js +3 -3
  95. package/dist/{src-VO7TXJPG.cjs → src-DNURNUIA.cjs} +287 -263
  96. package/dist/src-DNURNUIA.cjs.map +1 -0
  97. package/dist/{src-RM6DDR7K.cjs → src-DZDH3BSU.cjs} +18 -18
  98. package/dist/src-DZDH3BSU.cjs.map +1 -0
  99. package/dist/{src-HKOFZ4V3.js → src-EVM7OESP.js} +5 -5
  100. package/dist/src-EVM7OESP.js.map +1 -0
  101. package/dist/src-FY3KAPPC.js +5 -0
  102. package/dist/src-FY3KAPPC.js.map +1 -0
  103. package/dist/tokens.cjs +12 -4
  104. package/dist/tokens.d.cts +133 -1
  105. package/dist/tokens.d.ts +133 -1
  106. package/dist/tokens.js +3 -3
  107. package/dist/x402.cjs +26 -26
  108. package/dist/x402.js +3 -3
  109. package/package.json +1 -1
  110. package/dist/UserClient-4MRK2D7W.cjs +0 -15
  111. package/dist/UserClient-DPJ6E2XL.js +0 -6
  112. package/dist/chunk-4Q6FADF6.cjs.map +0 -1
  113. package/dist/chunk-BPAAWQQA.js.map +0 -1
  114. package/dist/chunk-EEWLL7GE.js.map +0 -1
  115. package/dist/chunk-IB3KOSHW.cjs.map +0 -1
  116. package/dist/chunk-MXJEULSE.cjs.map +0 -1
  117. package/dist/chunk-O2CN77MV.js +0 -226
  118. package/dist/chunk-O2CN77MV.js.map +0 -1
  119. package/dist/chunk-UCLK6LTB.js.map +0 -1
  120. package/dist/chunk-V23XPVHO.cjs +0 -228
  121. package/dist/chunk-V23XPVHO.cjs.map +0 -1
  122. package/dist/src-HKOFZ4V3.js.map +0 -1
  123. package/dist/src-L2BLX34S.js +0 -5
  124. package/dist/src-L2BLX34S.js.map +0 -1
  125. package/dist/src-RM6DDR7K.cjs.map +0 -1
  126. package/dist/src-VO7TXJPG.cjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { selectorFromId, keccak256, solidityPacked, ERC4337Utils, BLSManager, resolveTier, algIdForTier, encodeAbiParams, ecdsa, ALG_CUMULATIVE_T3, ALG_CUMULATIVE_T2, ALG_P256, ALG_ECDSA, ALG_BLS, weierstrass, sha256 } from './chunk-X3AMH53O.js';
2
- import { buildInitConfig, needsValidatorRouter, airAccountActions, airAccountFactoryActions } from './chunk-EEWLL7GE.js';
3
- import { CANONICAL_ADDRESSES, getCanonicalAddresses } from './chunk-UCLK6LTB.js';
4
- import { parseAbi, createPublicClient, http, getContract, formatEther, parseUnits, parseEther, encodeFunctionData, zeroAddress, concat, numberToHex, hexToBytes, formatUnits, encodeAbiParameters, keccak256 as keccak256$1, hashMessage as hashMessage$1, toRlp, concatHex, recoverAddress as recoverAddress$1 } from 'viem';
2
+ import { buildInitConfig, needsValidatorRouter, airAccountActions, airAccountFactoryActions } from './chunk-6DZCDV4Q.js';
3
+ import { CANONICAL_ADDRESSES, getCanonicalAddresses } from './chunk-MBWBHKUE.js';
4
+ import { parseAbi, createPublicClient, http, getContract, formatEther, parseUnits, parseEther, encodeFunctionData, zeroAddress, concat, numberToHex, hexToBytes, formatUnits, encodeAbiParameters, keccak256 as keccak256$1, hashTypedData, encodePacked, hashMessage as hashMessage$1, toRlp, concatHex, recoverAddress as recoverAddress$1 } from 'viem';
5
5
  import axios from 'axios';
6
6
  import { createHash } from 'crypto';
7
7
  import { privateKeyToAccount } from 'viem/accounts';
@@ -1610,7 +1610,12 @@ var TransferManager = class {
1610
1610
  );
1611
1611
  const userOpHash = await this.ethereum.getUserOpHash(userOp, version);
1612
1612
  await this.signer.ensureSigner(userId);
1613
- const assertionCtx = params.passkeyAssertion ? { assertion: params.passkeyAssertion } : void 0;
1613
+ if (params.webAuthnAssertion && params.passkeyAssertion) {
1614
+ throw new Error(
1615
+ "Provide either webAuthnAssertion (preferred) or passkeyAssertion, not both."
1616
+ );
1617
+ }
1618
+ const assertionCtx = params.webAuthnAssertion ? { webAuthnAssertion: params.webAuthnAssertion } : params.passkeyAssertion ? { assertion: params.passkeyAssertion } : void 0;
1614
1619
  let useECDSA = false;
1615
1620
  let isCompositeValidator = false;
1616
1621
  if (version === "0.7" /* V0_7 */ || version === "0.8" /* V0_8 */) {
@@ -1620,6 +1625,11 @@ var TransferManager = class {
1620
1625
  account.address
1621
1626
  ));
1622
1627
  }
1628
+ if (assertionCtx && "webAuthnAssertion" in assertionCtx && !useECDSA && !(params.useAirAccountTiering && this.guardChecker)) {
1629
+ throw new Error(
1630
+ "A one-time webAuthnAssertion cannot authorize the legacy non-tiered BLS dual-sign (two owner signatures, one spent challenge). Use useAirAccountTiering:true (single owner signature), or supply two assertions via the legacy path."
1631
+ );
1632
+ }
1623
1633
  if (useECDSA) {
1624
1634
  const ecdsaSig = await this.signer.signMessage(
1625
1635
  userId,
@@ -2116,7 +2126,7 @@ var BLSSignatureService = class {
2116
2126
  }
2117
2127
  return nodes;
2118
2128
  }
2119
- async generateBLSSignature(userId, userOpHash, ctx) {
2129
+ async generateBLSSignature(userId, userOpHash, ctx, options) {
2120
2130
  const manager = await this.ensureInitialized();
2121
2131
  const activeNodes = await this.getActiveSignerNodes();
2122
2132
  if (activeNodes.length < 1) {
@@ -2175,11 +2185,7 @@ var BLSSignatureService = class {
2175
2185
  `Wallet address mismatch! Wallet: ${walletAddress}, Expected: ${account.signerAddress}`
2176
2186
  );
2177
2187
  }
2178
- const aaSignature = await this.signer.signMessage(
2179
- userId,
2180
- hexToBytes(userOpHash),
2181
- ctx
2182
- );
2188
+ const aaSignature = options?.skipOwnerOpSignature ? "0x" : await this.signer.signMessage(userId, hexToBytes(userOpHash), ctx);
2183
2189
  const messagePointHash = keccak256(messagePoint);
2184
2190
  const messagePointSignature = await this.signer.signMessage(
2185
2191
  userId,
@@ -2196,6 +2202,11 @@ var BLSSignatureService = class {
2196
2202
  };
2197
2203
  }
2198
2204
  async packSignature(blsData) {
2205
+ if (!blsData.aaSignature || blsData.aaSignature === "0x") {
2206
+ throw new Error(
2207
+ "packSignature requires aaSignature; this BLSSignatureData was generated with skipOwnerOpSignature (Tier-2/3 only). Use packCumulativeT2/T3Signature instead."
2208
+ );
2209
+ }
2199
2210
  const manager = await this.ensureInitialized();
2200
2211
  return manager.packSignature(blsData);
2201
2212
  }
@@ -2225,7 +2236,9 @@ var BLSSignatureService = class {
2225
2236
  if (!p256Signature) {
2226
2237
  throw new Error(`P256 signature required for Tier ${tier}`);
2227
2238
  }
2228
- const blsData = await this.generateBLSSignature(userId, userOpHash, ctx);
2239
+ const blsData = await this.generateBLSSignature(userId, userOpHash, ctx, {
2240
+ skipOwnerOpSignature: true
2241
+ });
2229
2242
  if (tier === 2) {
2230
2243
  const t2Data = {
2231
2244
  p256Signature,
@@ -2253,6 +2266,84 @@ var BLSSignatureService = class {
2253
2266
  return manager.packCumulativeT3Signature(t3Data);
2254
2267
  }
2255
2268
  };
2269
+ var ALG_NAMES = {
2270
+ [ALG_BLS]: "BLS (0x01)",
2271
+ [ALG_ECDSA]: "ECDSA (0x02)",
2272
+ [ALG_P256]: "P256 (0x03)",
2273
+ [ALG_CUMULATIVE_T2]: "Cumulative T2 (0x04)",
2274
+ [ALG_CUMULATIVE_T3]: "Cumulative T3 (0x05)"
2275
+ };
2276
+ var GuardChecker = class {
2277
+ constructor(ethereum, logger) {
2278
+ this.ethereum = ethereum;
2279
+ this.logger = logger ?? new ConsoleLogger("[GuardChecker]");
2280
+ }
2281
+ logger;
2282
+ /**
2283
+ * Fetch tier limits from an AirAccount contract.
2284
+ */
2285
+ async fetchTierConfig(accountAddress) {
2286
+ const account = this.ethereum.getAccountContract(accountAddress);
2287
+ return readAccountTierLimits(account);
2288
+ }
2289
+ /**
2290
+ * Fetch guard status from the account's GlobalGuard.
2291
+ */
2292
+ async fetchGuardStatus(accountAddress) {
2293
+ const account = this.ethereum.getAccountContract(accountAddress);
2294
+ const guardAddress = await readAccountGuardAddress(account);
2295
+ if (guardAddress === zeroAddress) {
2296
+ return {
2297
+ hasGuard: false,
2298
+ guardAddress: zeroAddress,
2299
+ dailyLimit: 0n,
2300
+ dailyRemaining: 0n
2301
+ };
2302
+ }
2303
+ const guard = getContract({
2304
+ address: guardAddress,
2305
+ abi: parseAbi(GLOBAL_GUARD_ABI),
2306
+ client: this.ethereum.getProvider()
2307
+ });
2308
+ const { dailyLimit, dailyRemaining } = await readGuardDailyAllowance(guard);
2309
+ return {
2310
+ hasGuard: true,
2311
+ guardAddress,
2312
+ dailyLimit,
2313
+ dailyRemaining
2314
+ };
2315
+ }
2316
+ /**
2317
+ * Pre-check a transaction: determine tier, check guard limits and algorithm approval.
2318
+ * Returns errors array (empty = OK to proceed).
2319
+ */
2320
+ async preCheck(accountAddress, value) {
2321
+ const errors = [];
2322
+ const tierConfig = await this.fetchTierConfig(accountAddress);
2323
+ const tier = resolveTier(value, tierConfig);
2324
+ const algId = algIdForTier(tier);
2325
+ const guard = await this.fetchGuardStatus(accountAddress);
2326
+ if (!guard.hasGuard) {
2327
+ return { ok: true, errors: [], tier, algId };
2328
+ }
2329
+ if (guard.dailyLimit > 0n && value > guard.dailyRemaining) {
2330
+ errors.push(
2331
+ `Daily limit exceeded: requesting ${value} wei but only ${guard.dailyRemaining} remaining (limit: ${guard.dailyLimit})`
2332
+ );
2333
+ }
2334
+ const accountContract = this.ethereum.getAccountContract(accountAddress);
2335
+ const isApproved = await readAlgorithmApproved(accountContract, algId);
2336
+ if (!isApproved) {
2337
+ errors.push(
2338
+ `Algorithm ${ALG_NAMES[algId] ?? `0x${algId.toString(16)}`} is not approved by the account`
2339
+ );
2340
+ }
2341
+ if (errors.length > 0) {
2342
+ this.logger.warn(`Pre-check failed for ${accountAddress}: ${errors.join("; ")}`);
2343
+ }
2344
+ return { ok: errors.length === 0, errors, tier, algId };
2345
+ }
2346
+ };
2256
2347
  var ERC20_ABI_PARSED = parseAbi(ERC20_ABI);
2257
2348
  var TokenService = class {
2258
2349
  constructor(ethereum) {
@@ -2379,7 +2470,8 @@ var AirAccountServerClient = class {
2379
2470
  this.tokens,
2380
2471
  config.storage,
2381
2472
  config.signer,
2382
- logger
2473
+ logger,
2474
+ new GuardChecker(this.ethereum, logger)
2383
2475
  );
2384
2476
  }
2385
2477
  };
@@ -2914,84 +3006,6 @@ async function isOapdDeployed(provider, config) {
2914
3006
  const code = await provider.getCode({ address });
2915
3007
  return code !== void 0 && code !== "0x";
2916
3008
  }
2917
- var ALG_NAMES = {
2918
- [ALG_BLS]: "BLS (0x01)",
2919
- [ALG_ECDSA]: "ECDSA (0x02)",
2920
- [ALG_P256]: "P256 (0x03)",
2921
- [ALG_CUMULATIVE_T2]: "Cumulative T2 (0x04)",
2922
- [ALG_CUMULATIVE_T3]: "Cumulative T3 (0x05)"
2923
- };
2924
- var GuardChecker = class {
2925
- constructor(ethereum, logger) {
2926
- this.ethereum = ethereum;
2927
- this.logger = logger ?? new ConsoleLogger("[GuardChecker]");
2928
- }
2929
- logger;
2930
- /**
2931
- * Fetch tier limits from an AirAccount contract.
2932
- */
2933
- async fetchTierConfig(accountAddress) {
2934
- const account = this.ethereum.getAccountContract(accountAddress);
2935
- return readAccountTierLimits(account);
2936
- }
2937
- /**
2938
- * Fetch guard status from the account's GlobalGuard.
2939
- */
2940
- async fetchGuardStatus(accountAddress) {
2941
- const account = this.ethereum.getAccountContract(accountAddress);
2942
- const guardAddress = await readAccountGuardAddress(account);
2943
- if (guardAddress === zeroAddress) {
2944
- return {
2945
- hasGuard: false,
2946
- guardAddress: zeroAddress,
2947
- dailyLimit: 0n,
2948
- dailyRemaining: 0n
2949
- };
2950
- }
2951
- const guard = getContract({
2952
- address: guardAddress,
2953
- abi: parseAbi(GLOBAL_GUARD_ABI),
2954
- client: this.ethereum.getProvider()
2955
- });
2956
- const { dailyLimit, dailyRemaining } = await readGuardDailyAllowance(guard);
2957
- return {
2958
- hasGuard: true,
2959
- guardAddress,
2960
- dailyLimit,
2961
- dailyRemaining
2962
- };
2963
- }
2964
- /**
2965
- * Pre-check a transaction: determine tier, check guard limits and algorithm approval.
2966
- * Returns errors array (empty = OK to proceed).
2967
- */
2968
- async preCheck(accountAddress, value) {
2969
- const errors = [];
2970
- const tierConfig = await this.fetchTierConfig(accountAddress);
2971
- const tier = resolveTier(value, tierConfig);
2972
- const algId = algIdForTier(tier);
2973
- const guard = await this.fetchGuardStatus(accountAddress);
2974
- if (!guard.hasGuard) {
2975
- return { ok: true, errors: [], tier, algId };
2976
- }
2977
- if (guard.dailyLimit > 0n && value > guard.dailyRemaining) {
2978
- errors.push(
2979
- `Daily limit exceeded: requesting ${value} wei but only ${guard.dailyRemaining} remaining (limit: ${guard.dailyLimit})`
2980
- );
2981
- }
2982
- const accountContract = this.ethereum.getAccountContract(accountAddress);
2983
- const isApproved = await readAlgorithmApproved(accountContract, algId);
2984
- if (!isApproved) {
2985
- errors.push(
2986
- `Algorithm ${ALG_NAMES[algId] ?? `0x${algId.toString(16)}`} is not approved by the account`
2987
- );
2988
- }
2989
- if (errors.length > 0) {
2990
- this.logger.warn(`Pre-check failed for ${accountAddress}: ${errors.join("; ")}`);
2991
- }
2992
- return { ok: errors.length === 0, errors, tier, algId };
2993
- }
2994
- };
2995
3009
  var FORCE_EXIT_ABI = [
2996
3010
  // ERC-7579 module lifecycle
2997
3011
  "function onInstall(bytes calldata data) external",
@@ -4181,6 +4195,9 @@ function hexToBytes4(hex) {
4181
4195
  if (clean.length % 2 !== 0) {
4182
4196
  throw new Error("hexToBytes: odd-length hex string");
4183
4197
  }
4198
+ if (clean.length > 0 && !/^[0-9a-fA-F]+$/.test(clean)) {
4199
+ throw new Error("hexToBytes: non-hex characters in input");
4200
+ }
4184
4201
  const out = new Uint8Array(clean.length / 2);
4185
4202
  for (let i = 0; i < out.length; i++) {
4186
4203
  out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
@@ -4215,11 +4232,14 @@ function buildClientDataJSON(challenge, origin = DEFAULT_ORIGIN) {
4215
4232
  return new TextEncoder().encode(json);
4216
4233
  }
4217
4234
  function buildAuthenticatorData(rpId = DEFAULT_RP_ID, signCount = 1) {
4235
+ if (!Number.isInteger(signCount) || signCount < 0 || signCount > 4294967295) {
4236
+ throw new Error(`buildAuthenticatorData: signCount must be a uint32 (0..2^32-1), got ${signCount}`);
4237
+ }
4218
4238
  const rpIdHash = createHash("sha256").update(rpId).digest();
4219
4239
  const out = new Uint8Array(37);
4220
4240
  out.set(rpIdHash, 0);
4221
4241
  out[32] = 5;
4222
- new DataView(out.buffer).setUint32(33, signCount >>> 0, false);
4242
+ new DataView(out.buffer).setUint32(33, signCount, false);
4223
4243
  return out;
4224
4244
  }
4225
4245
  async function buildAuthenticationCredential(opts) {
@@ -4244,23 +4264,42 @@ async function buildAuthenticationCredential(opts) {
4244
4264
  }
4245
4265
  };
4246
4266
  }
4267
+ function commitChallenge(nonceBase64Url, payload) {
4268
+ const nonce = base64UrlDecode(nonceBase64Url);
4269
+ const payloadBytes = typeof payload === "string" ? hexToBytes4(payload) : payload;
4270
+ if (payloadBytes.length !== 32) {
4271
+ throw new Error(`commitChallenge: payload must be a 32-byte digest, got ${payloadBytes.length} bytes`);
4272
+ }
4273
+ const committed = createHash("sha256").update(nonce).update(payloadBytes).digest();
4274
+ return base64UrlEncode(new Uint8Array(committed));
4275
+ }
4247
4276
  async function runWebAuthnCeremony(begin, options) {
4248
4277
  const begun = await begin();
4249
- const challenge = begun?.Options?.challenge;
4250
- if (!begun?.ChallengeId || !challenge) {
4278
+ const nonce = begun?.Options?.challenge;
4279
+ if (!begun?.ChallengeId || !nonce) {
4251
4280
  throw new Error(
4252
4281
  "WebAuthn ceremony: begin endpoint did not return a ChallengeId + Options.challenge"
4253
4282
  );
4254
4283
  }
4284
+ const challenge = options.payload ? commitChallenge(nonce, options.payload) : nonce;
4255
4285
  const credential = await buildAuthenticationCredential({
4256
4286
  challenge,
4257
4287
  signer: options.signer,
4258
4288
  rpId: options.rpId,
4259
4289
  origin: options.origin,
4260
- signCount: options.signCount
4290
+ // The KMS enforces a strictly-increasing authenticator signCount (anti-clone). A
4291
+ // server-held signer (P256PasskeySigner) has no native counter, so default to a
4292
+ // monotonic value — else a second signature on the same key fails
4293
+ // "signCount not incremented". A real device passkey passes its own counter.
4294
+ signCount: options.signCount ?? nextSignCount()
4261
4295
  });
4262
4296
  return { ChallengeId: begun.ChallengeId, Credential: credential };
4263
4297
  }
4298
+ var _signCountCounter = Math.floor(Date.now() / 1e3);
4299
+ function nextSignCount() {
4300
+ _signCountCounter = _signCountCounter + 1 >>> 0;
4301
+ return _signCountCounter;
4302
+ }
4264
4303
  function beginAuthenticationChallenge(http2, keyId) {
4265
4304
  return http2.post("/BeginAuthentication", { KeyId: keyId });
4266
4305
  }
@@ -4283,6 +4322,133 @@ function runGrantSessionCeremony(http2, keyId, signer, options) {
4283
4322
  }
4284
4323
 
4285
4324
  // ../airaccount/src/server/services/kms-signer.ts
4325
+ function eip712Digest(params) {
4326
+ const types = Object.fromEntries(
4327
+ params.types.filter((t) => t.name !== "EIP712Domain").map((t) => [t.name, t.fields])
4328
+ );
4329
+ const message = Object.fromEntries(params.message.map((f) => [f.name, f.value]));
4330
+ return hashTypedData({
4331
+ domain: params.domain,
4332
+ types,
4333
+ primaryType: params.primaryType,
4334
+ message
4335
+ });
4336
+ }
4337
+ function u256(x) {
4338
+ if (typeof x === "number" && !Number.isSafeInteger(x)) {
4339
+ throw new Error(`u256: number ${x} exceeds safe-integer range \u2014 pass a bigint or string`);
4340
+ }
4341
+ return BigInt(x);
4342
+ }
4343
+ var MINT_TAGS = { agent: "AA-AGENT-MINT-v1", p256: "AA-P256-SESSION-MINT-v1" };
4344
+ function mintDigest(p) {
4345
+ const hex = p.walletId.replace(/-/g, "");
4346
+ if (hex.length !== 32 || !/^[0-9a-fA-F]+$/.test(hex)) {
4347
+ throw new Error("mintDigest: walletId must be a 16-byte UUID");
4348
+ }
4349
+ if (!Number.isInteger(p.index) || p.index < 0 || p.index > 4294967295) {
4350
+ throw new Error(`mintDigest: index must be a uint32, got ${p.index}`);
4351
+ }
4352
+ if (typeof p.ttlSecs === "number" && !Number.isInteger(p.ttlSecs)) {
4353
+ throw new Error(`mintDigest: ttlSecs must be an integer, got ${p.ttlSecs}`);
4354
+ }
4355
+ const ttlBig = BigInt(p.ttlSecs);
4356
+ if (ttlBig < -(1n << 63n) || ttlBig > (1n << 63n) - 1n) {
4357
+ throw new Error(`mintDigest: ttlSecs out of int64 range: ${ttlBig}`);
4358
+ }
4359
+ const sha2562 = (b) => new Uint8Array(createHash("sha256").update(b).digest());
4360
+ const utf8 = (s) => new TextEncoder().encode(s);
4361
+ const walletBytes = new Uint8Array(16);
4362
+ for (let i = 0; i < 16; i++) walletBytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
4363
+ const idx = new Uint8Array(4);
4364
+ new DataView(idx.buffer).setUint32(0, p.index, false);
4365
+ const ttl = new Uint8Array(8);
4366
+ new DataView(ttl.buffer).setBigInt64(0, ttlBig, false);
4367
+ const parts = [utf8(MINT_TAGS[p.kind]), walletBytes, idx, ttl, sha2562(utf8(p.subject))];
4368
+ const total = parts.reduce((n, a) => n + a.length, 0);
4369
+ const buf = new Uint8Array(total);
4370
+ let off = 0;
4371
+ for (const a of parts) {
4372
+ buf.set(a, off);
4373
+ off += a.length;
4374
+ }
4375
+ return "0x" + Buffer.from(sha2562(buf)).toString("hex");
4376
+ }
4377
+ function grantSessionFinalHash(p) {
4378
+ const callTargetsHash = keccak256$1(encodePacked(["address[]"], [p.callTargets]));
4379
+ const selectorsHash = keccak256$1(encodePacked(["bytes4[]"], [p.selectorAllowlist]));
4380
+ const isP256 = "keyX" in p;
4381
+ const inner = isP256 ? keccak256$1(
4382
+ encodeAbiParameters(
4383
+ [
4384
+ { type: "string" },
4385
+ { type: "uint256" },
4386
+ { type: "address" },
4387
+ { type: "address" },
4388
+ { type: "bytes32" },
4389
+ { type: "bytes32" },
4390
+ { type: "uint48" },
4391
+ { type: "address" },
4392
+ { type: "bytes4" },
4393
+ { type: "uint16" },
4394
+ { type: "uint32" },
4395
+ { type: "bytes32" },
4396
+ { type: "bytes32" },
4397
+ { type: "uint256" }
4398
+ ],
4399
+ [
4400
+ "GRANT_P256_SESSION_V2",
4401
+ u256(p.chainId),
4402
+ p.verifyingContract,
4403
+ p.account,
4404
+ p.keyX,
4405
+ p.keyY,
4406
+ p.expiry,
4407
+ p.contractScope,
4408
+ p.selectorScope,
4409
+ p.velocityLimit,
4410
+ p.velocityWindow,
4411
+ callTargetsHash,
4412
+ selectorsHash,
4413
+ u256(p.nonce)
4414
+ ]
4415
+ )
4416
+ ) : keccak256$1(
4417
+ encodeAbiParameters(
4418
+ [
4419
+ { type: "string" },
4420
+ { type: "uint256" },
4421
+ { type: "address" },
4422
+ { type: "address" },
4423
+ { type: "address" },
4424
+ { type: "uint48" },
4425
+ { type: "address" },
4426
+ { type: "bytes4" },
4427
+ { type: "uint16" },
4428
+ { type: "uint32" },
4429
+ { type: "bytes32" },
4430
+ { type: "bytes32" },
4431
+ { type: "uint256" }
4432
+ ],
4433
+ [
4434
+ "GRANT_SESSION_V2",
4435
+ u256(p.chainId),
4436
+ p.verifyingContract,
4437
+ p.account,
4438
+ p.sessionKey,
4439
+ p.expiry,
4440
+ p.contractScope,
4441
+ p.selectorScope,
4442
+ p.velocityLimit,
4443
+ p.velocityWindow,
4444
+ callTargetsHash,
4445
+ selectorsHash,
4446
+ u256(p.nonce)
4447
+ ]
4448
+ )
4449
+ );
4450
+ return hashMessage$1({ raw: inner });
4451
+ }
4286
4452
  var KmsManager = class {
4287
4453
  client;
4288
4454
  logger;
@@ -4372,6 +4538,29 @@ var KmsManager = class {
4372
4538
  this.ensureEnabled();
4373
4539
  return this.amzPost("/ChangePasskey", "TrentService.ChangePasskey", params);
4374
4540
  }
4541
+ // ── Ceremony wrappers for non-signing passkey ops (strict-readiness #135 item 2) ──
4542
+ // These are NON-signing ops, so the challenge is the raw nonce (no payload commitment),
4543
+ // but they MUST go through the ceremony (clientDataJSON present) — strict mode hard-rejects
4544
+ // any assertion without clientDataJSON. Run the ceremony internally so callers never reach
4545
+ // for the deprecated legacy `Passkey` field.
4546
+ /** Schedule key deletion, running the WebAuthn ceremony internally (raw-nonce). */
4547
+ async deleteKeyWithCeremony(params, signer, options) {
4548
+ this.ensureEnabled();
4549
+ const WebAuthn = await this.runAuthenticationCeremony(params.KeyId, signer, options);
4550
+ return this.deleteKey({ ...params, WebAuthn });
4551
+ }
4552
+ /** Unfreeze a dormant key, running the WebAuthn ceremony internally (raw-nonce). */
4553
+ async unfreezeKeyWithCeremony(params, signer, options) {
4554
+ this.ensureEnabled();
4555
+ const WebAuthn = await this.runAuthenticationCeremony(params.KeyId, signer, options);
4556
+ return this.unfreezeKey({ ...params, WebAuthn });
4557
+ }
4558
+ /** Rotate the bound passkey, running the WebAuthn ceremony internally (raw-nonce). */
4559
+ async changePasskeyWithCeremony(params, signer, options) {
4560
+ this.ensureEnabled();
4561
+ const WebAuthn = await this.runAuthenticationCeremony(params.KeyId, signer, options);
4562
+ return this.changePasskey({ ...params, WebAuthn });
4563
+ }
4375
4564
  /**
4376
4565
  * Sign a message or an EIP-155 transaction (WebAuthn-gated).
4377
4566
  * Provide exactly one of `Message` (hex) or `Transaction`. For a raw 32-byte
@@ -4513,24 +4702,50 @@ var KmsManager = class {
4513
4702
  return this.deriveAddress({ ...params, WebAuthn });
4514
4703
  }
4515
4704
  /**
4516
- * Sign a message or EIP-155 transaction, running the challenge-binding ceremony
4517
- * internally. `params.KeyId` is required (it identifies the wallet to challenge).
4705
+ * Sign a message or EIP-155 transaction via `/Sign`, running the ceremony internally.
4706
+ * `params.KeyId` is required.
4707
+ *
4708
+ * ⚠️ STRICT MODE: unlike {@link signHashWithCeremony} / {@link signTypedDataWithCeremony},
4709
+ * this does NOT auto-bind a payload commitment, because the TA derives the signed digest
4710
+ * from `Message` / `Transaction` host-side (EIP-191 / RLP) and the SDK can't reproduce it
4711
+ * byte-exactly for every input. So it sends the RAW nonce by default — which the KMS will
4712
+ * REJECT once strict mode (#63) is on. For strict-safe signing either:
4713
+ * - pass `options.payload` = the exact digest the TA will sign (you computed it), or
4714
+ * - prefer {@link signHashWithCeremony} (commits to a known 32-byte hash).
4518
4715
  */
4519
4716
  async signWithCeremony(params, signer, options) {
4520
4717
  this.ensureEnabled();
4521
4718
  const WebAuthn = await this.runAuthenticationCeremony(params.KeyId, signer, options);
4522
4719
  return this.sign({ ...params, WebAuthn });
4523
4720
  }
4524
- /** Sign a 32-byte digest, running the challenge-binding ceremony internally. */
4721
+ /**
4722
+ * Sign a 32-byte digest, running the challenge-binding ceremony internally.
4723
+ * Binds the challenge to `hash` (WYSIWYS commitment, #68) by default — pass an
4724
+ * explicit `options.payload` only to override.
4725
+ */
4525
4726
  async signHashWithCeremony(hash, target, signer, options) {
4526
4727
  this.ensureEnabled();
4527
- const assertion = await this.runAuthenticationCeremony(target.KeyId, signer, options);
4728
+ const assertion = await this.runAuthenticationCeremony(target.KeyId, signer, {
4729
+ ...options,
4730
+ payload: options?.payload ?? hash
4731
+ });
4528
4732
  return this.signHashWithWebAuthn(hash, assertion.ChallengeId, assertion.Credential, target);
4529
4733
  }
4530
- /** Sign EIP-712 typed data, running the challenge-binding ceremony internally. */
4734
+ /**
4735
+ * Sign EIP-712 typed data, running the challenge-binding ceremony internally.
4736
+ * Auto-binds the WYSIWYS commitment (#68): the ceremony challenge is
4737
+ * `SHA-256(nonce ‖ eip712Digest)`, where `eip712Digest` is the standard EIP-712
4738
+ * digest the KMS hashes host-side — computed here via {@link eip712Digest} so the
4739
+ * user's signature commits to the exact typed-data payload. Pass an explicit
4740
+ * `options.payload` only to override.
4741
+ */
4531
4742
  async signTypedDataWithCeremony(params, signer, options) {
4532
4743
  this.ensureEnabled();
4533
- const webAuthnAssertion = await this.runAuthenticationCeremony(params.keyId, signer, options);
4744
+ const payload = options?.payload ?? eip712Digest(params);
4745
+ const webAuthnAssertion = await this.runAuthenticationCeremony(params.keyId, signer, {
4746
+ ...options,
4747
+ payload
4748
+ });
4534
4749
  return this.signTypedDataWithWebAuthn({ ...params, webAuthnAssertion });
4535
4750
  }
4536
4751
  /**
@@ -4539,7 +4754,10 @@ var KmsManager = class {
4539
4754
  */
4540
4755
  async signGrantSessionWithCeremony(params, signer, options) {
4541
4756
  this.ensureEnabled();
4542
- const webAuthnAssertion = await this.runGrantSessionCeremony(params.keyId, signer, options);
4757
+ const webAuthnAssertion = await this.runGrantSessionCeremony(params.keyId, signer, {
4758
+ ...options,
4759
+ payload: options?.payload ?? grantSessionFinalHash(params)
4760
+ });
4543
4761
  return this.signGrantSession({ ...params, webAuthnAssertion });
4544
4762
  }
4545
4763
  /**
@@ -4548,7 +4766,10 @@ var KmsManager = class {
4548
4766
  */
4549
4767
  async signP256GrantSessionWithCeremony(params, signer, options) {
4550
4768
  this.ensureEnabled();
4551
- const webAuthnAssertion = await this.runGrantSessionCeremony(params.keyId, signer, options);
4769
+ const webAuthnAssertion = await this.runGrantSessionCeremony(params.keyId, signer, {
4770
+ ...options,
4771
+ payload: options?.payload ?? grantSessionFinalHash(params)
4772
+ });
4552
4773
  return this.signP256GrantSession({ ...params, webAuthnAssertion });
4553
4774
  }
4554
4775
  // ── WebAuthn Ceremonies ─────────────────────────────────────────
@@ -4577,27 +4798,100 @@ var KmsManager = class {
4577
4798
  return this.client.post("/BeginAuthentication", { KeyId: keyId });
4578
4799
  }
4579
4800
  // ── Factory ─────────────────────────────────────────────────────
4801
+ /**
4802
+ * Create a KMS signer that authorizes each signature with a LEGACY raw passkey
4803
+ * assertion (reusable, no challenge consumption).
4804
+ *
4805
+ * @deprecated The KMS (v0.20.0+) rejects legacy raw passkey assertions for
4806
+ * signing/mutating operations (`/SignHash` → 400, "no challenge binding —
4807
+ * replayable"), unless `KMS_ALLOW_LEGACY_PASSKEY=1` is set on the KMS (test
4808
+ * only). Prefer {@link createKmsSignerWithCeremony}, which runs a one-time
4809
+ * challenge-bound WebAuthn ceremony per signature.
4810
+ */
4580
4811
  createKmsSigner(keyId, address, assertionProvider) {
4581
4812
  this.ensureEnabled();
4582
- return new KmsSigner(keyId, address, this, assertionProvider);
4813
+ return new KmsSigner(keyId, address, this, { mode: "legacy", assertionProvider });
4814
+ }
4815
+ /**
4816
+ * Create a KMS signer that authorizes each signature with a one-time,
4817
+ * challenge-bound WebAuthn ceremony (production-safe; replay-protected).
4818
+ *
4819
+ * Every `signMessage` call runs a FRESH ceremony (BeginAuthentication →
4820
+ * authenticator assertion → `/SignHash` with the `WebAuthn` field), because the
4821
+ * KMS consumes the challenge atomically (one challenge ⇒ one signature). A
4822
+ * Tier-2/3 BLS transfer that needs N owner signatures therefore triggers N
4823
+ * ceremonies — see {@link BLSSignatureService} (which now skips the unused
4824
+ * userOpHash owner-ECDSA for tiered signatures, so Tier-2 needs only one).
4825
+ *
4826
+ * @param ceremonySigner authenticator that signs the WebAuthn challenge
4827
+ * (a browser passkey on the client, or {@link P256PasskeySigner} server-side).
4828
+ */
4829
+ createKmsSignerWithCeremony(keyId, address, ceremonySigner, ceremonyOptions, commitPayload = true) {
4830
+ this.ensureEnabled();
4831
+ return new KmsSigner(keyId, address, this, {
4832
+ mode: "ceremony",
4833
+ ceremonySigner,
4834
+ ceremonyOptions,
4835
+ commitPayload
4836
+ });
4583
4837
  }
4584
4838
  };
4585
4839
  var KmsSigner = class {
4586
- constructor(keyId, _address, kmsManager, assertionProvider) {
4840
+ constructor(keyId, _address, kmsManager, auth) {
4587
4841
  this.keyId = keyId;
4588
4842
  this._address = _address;
4589
4843
  this.kmsManager = kmsManager;
4590
- this.assertionProvider = assertionProvider;
4844
+ this.auth = auth;
4591
4845
  }
4592
4846
  async getAddress() {
4593
4847
  return this._address;
4594
4848
  }
4595
- async signMessage(message) {
4849
+ /**
4850
+ * EIP-191 personal-sign over a digest. A string is hashed as UTF-8 text, a byte
4851
+ * array as raw bytes — byte-identical to ethers `hashMessage`.
4852
+ *
4853
+ * @param webAuthnAssertion OPTIONAL pre-built, one-time ceremony assertion. Use
4854
+ * this in server flows where the passkey lives on the USER's device: the
4855
+ * frontend runs the BeginAuthentication ceremony and the backend forwards the
4856
+ * resulting `{ ChallengeId, Credential }` here. When supplied it takes
4857
+ * precedence over the signer's baked-in auth mode. Each assertion is one-time
4858
+ * (the KMS consumes the challenge), so a caller that needs N signatures must
4859
+ * supply N distinct assertions.
4860
+ *
4861
+ * WYSIWYS (AirAccount #68): the frontend MUST build the assertion over the
4862
+ * payload-committed challenge `commitChallenge(nonce, hashOf(message))`, not the
4863
+ * raw nonce — otherwise a compromised host could swap the signed payload. The
4864
+ * raw-nonce assertion only works while the KMS runs in transition mode. (The
4865
+ * signer's own ceremony mode does this automatically.)
4866
+ */
4867
+ async signMessage(message, webAuthnAssertion) {
4596
4868
  const messageHash = hashMessage(message);
4597
- const assertion = await this.assertionProvider();
4598
- const signResponse = await this.kmsManager.signHash(messageHash, assertion, {
4599
- Address: this._address
4600
- });
4869
+ const target = { Address: this._address };
4870
+ if (webAuthnAssertion) {
4871
+ const signResponse2 = await this.kmsManager.signHashWithWebAuthn(
4872
+ messageHash,
4873
+ webAuthnAssertion.ChallengeId,
4874
+ webAuthnAssertion.Credential,
4875
+ target
4876
+ );
4877
+ return "0x" + signResponse2.Signature;
4878
+ }
4879
+ if (this.auth.mode === "ceremony") {
4880
+ const assertion2 = await this.kmsManager.runAuthenticationCeremony(
4881
+ this.keyId,
4882
+ this.auth.ceremonySigner,
4883
+ this.auth.commitPayload ? { ...this.auth.ceremonyOptions, payload: messageHash } : this.auth.ceremonyOptions
4884
+ );
4885
+ const signResponse2 = await this.kmsManager.signHashWithWebAuthn(
4886
+ messageHash,
4887
+ assertion2.ChallengeId,
4888
+ assertion2.Credential,
4889
+ target
4890
+ );
4891
+ return "0x" + signResponse2.Signature;
4892
+ }
4893
+ const assertion = await this.auth.assertionProvider();
4894
+ const signResponse = await this.kmsManager.signHash(messageHash, assertion, target);
4601
4895
  return "0x" + signResponse.Signature;
4602
4896
  }
4603
4897
  };
@@ -4660,7 +4954,15 @@ var KmsAgentService = class {
4660
4954
  // challenge bound to the HUMAN key. These helpers run the full ceremony
4661
4955
  // (begin → clientDataJSON → assertion) via the shared
4662
4956
  // {@link runAuthenticationCeremony} helper, then invoke the endpoint.
4663
- /** Mint an agent key, running the challenge-binding ceremony internally. */
4957
+ /**
4958
+ * Mint an agent key, running the challenge-binding ceremony internally.
4959
+ *
4960
+ * STRICT MODE (AirAccount #115): bind the mint params by passing `options.payload =
4961
+ * mintDigest({ kind: "agent", walletId, index, ttlSecs, subject })` — `index` is the
4962
+ * agent_index the KMS will assign (query it first), `subject` the JWT sub (human key id),
4963
+ * `ttlSecs` the JWT lifetime. Without a payload the ceremony sends the raw nonce, which
4964
+ * strict mode rejects.
4965
+ */
4664
4966
  async createAgentKeyWithCeremony(params, signer, options) {
4665
4967
  this.http.ensureEnabled();
4666
4968
  const webAuthnAssertion = await runAuthenticationCeremony(
@@ -4747,7 +5049,15 @@ var KmsSessionService = class {
4747
5049
  // Create + revoke gate on the generic purpose="authentication" challenge bound
4748
5050
  // to the HUMAN key. These helpers run the full ceremony (begin → clientDataJSON
4749
5051
  // → assertion) via the shared {@link runAuthenticationCeremony} helper.
4750
- /** Create a P-256 session key, running the challenge-binding ceremony internally. */
5052
+ /**
5053
+ * Create a P-256 session key, running the challenge-binding ceremony internally.
5054
+ *
5055
+ * STRICT MODE (AirAccount #115): bind the mint params by passing `options.payload =
5056
+ * mintDigest({ kind: "p256", walletId, index, ttlSecs, subject })` — `index` is the
5057
+ * session_index the KMS will assign (query it first), `subject` the JWT sub (human key
5058
+ * id), `ttlSecs` the JWT lifetime. Without a payload the ceremony sends the raw nonce,
5059
+ * which strict mode rejects.
5060
+ */
4751
5061
  async createP256SessionKeyWithCeremony(params, signer, options) {
4752
5062
  this.http.ensureEnabled();
4753
5063
  const webAuthnAssertion = await runAuthenticationCeremony(
@@ -4811,7 +5121,108 @@ var KmsPaymentSigner = class {
4811
5121
  this.http.ensureEnabled();
4812
5122
  return this.signWithAuth("/kms/SignX402Payment", { ...params }, auth);
4813
5123
  }
5124
+ // ── Ceremony-internal variants with WYSIWYS payload commitment (#68 / #135 item 1) ──
5125
+ // Each payment endpoint is a fixed-schema SignTypedData host-side, so the commitment
5126
+ // payload is the EIP-712 digest of that schema. We compute it SDK-side (digest helpers
5127
+ // below, schemas mirrored from kms/host/src/api_server.rs) and bind the ceremony
5128
+ // challenge to it: challenge = SHA-256(nonce ‖ eip712Digest). Live-verified against KMS.
5129
+ /** Sign a MicroPaymentChannel voucher, running the committed ceremony internally. */
5130
+ async signMicropaymentVoucherWithCeremony(params, signer, options) {
5131
+ this.http.ensureEnabled();
5132
+ const webAuthnAssertion = await runAuthenticationCeremony(this.http, params.keyId, signer, {
5133
+ ...options,
5134
+ payload: micropaymentVoucherDigest(params)
5135
+ });
5136
+ return this.signMicropaymentVoucher(params, { webAuthnAssertion });
5137
+ }
5138
+ /** Sign a GToken EIP-3009 authorization, running the committed ceremony internally. */
5139
+ async signGTokenAuthorizationWithCeremony(params, signer, options) {
5140
+ this.http.ensureEnabled();
5141
+ const webAuthnAssertion = await runAuthenticationCeremony(this.http, params.keyId, signer, {
5142
+ ...options,
5143
+ payload: gTokenAuthorizationDigest(params)
5144
+ });
5145
+ return this.signGTokenAuthorization(params, { webAuthnAssertion });
5146
+ }
5147
+ /** Sign an x402 payment, running the committed ceremony internally. */
5148
+ async signX402PaymentWithCeremony(params, signer, options) {
5149
+ this.http.ensureEnabled();
5150
+ const webAuthnAssertion = await runAuthenticationCeremony(this.http, params.keyId, signer, {
5151
+ ...options,
5152
+ payload: x402PaymentDigest(params)
5153
+ });
5154
+ return this.signX402Payment(params, { webAuthnAssertion });
5155
+ }
4814
5156
  };
5157
+ function micropaymentVoucherDigest(p) {
5158
+ return eip712Digest({
5159
+ domain: { name: "MicroPaymentChannel", version: "1.0.0", chainId: p.chainId, verifyingContract: p.verifyingContract },
5160
+ primaryType: "Voucher",
5161
+ types: [
5162
+ {
5163
+ name: "Voucher",
5164
+ fields: [
5165
+ { name: "channelId", type: "bytes32" },
5166
+ { name: "cumulativeAmount", type: "uint256" }
5167
+ ]
5168
+ }
5169
+ ],
5170
+ message: [
5171
+ { name: "channelId", value: p.channelId },
5172
+ { name: "cumulativeAmount", value: p.cumulativeAmount }
5173
+ ]
5174
+ });
5175
+ }
5176
+ function gTokenAuthorizationDigest(p) {
5177
+ return eip712Digest({
5178
+ domain: { name: "GToken", version: "1", chainId: p.chainId, verifyingContract: p.gTokenAddress },
5179
+ primaryType: "TransferWithAuthorization",
5180
+ types: [
5181
+ {
5182
+ name: "TransferWithAuthorization",
5183
+ fields: [
5184
+ { name: "from", type: "address" },
5185
+ { name: "to", type: "address" },
5186
+ { name: "value", type: "uint256" },
5187
+ { name: "validAfter", type: "uint256" },
5188
+ { name: "validBefore", type: "uint256" },
5189
+ { name: "nonce", type: "bytes32" }
5190
+ ]
5191
+ }
5192
+ ],
5193
+ message: [
5194
+ { name: "from", value: p.from },
5195
+ { name: "to", value: p.to },
5196
+ { name: "value", value: p.value },
5197
+ { name: "validAfter", value: p.validAfter },
5198
+ { name: "validBefore", value: p.validBefore },
5199
+ { name: "nonce", value: p.nonce }
5200
+ ]
5201
+ });
5202
+ }
5203
+ function x402PaymentDigest(p) {
5204
+ return eip712Digest({
5205
+ domain: { name: "SuperPaymaster", version: "1", chainId: p.chainId, verifyingContract: p.verifyingContract },
5206
+ primaryType: "PaymentPayload",
5207
+ types: [
5208
+ {
5209
+ name: "PaymentPayload",
5210
+ fields: [
5211
+ { name: "paymentId", type: "bytes32" },
5212
+ { name: "amount", type: "uint256" },
5213
+ { name: "recipient", type: "address" },
5214
+ { name: "deadline", type: "uint256" }
5215
+ ]
5216
+ }
5217
+ ],
5218
+ message: [
5219
+ { name: "paymentId", value: p.paymentId },
5220
+ { name: "amount", value: p.amount },
5221
+ { name: "recipient", value: p.recipient },
5222
+ { name: "deadline", value: p.deadline }
5223
+ ]
5224
+ });
5225
+ }
4815
5226
 
4816
5227
  // ../airaccount/src/server/services/kms-monitor-service.ts
4817
5228
  var KmsMonitorService = class {
@@ -4983,12 +5394,43 @@ var LocalWalletSigner = class {
4983
5394
  return { address: this.account.address };
4984
5395
  }
4985
5396
  };
5397
+
5398
+ // ../airaccount/src/server/adapters/kms-signer-adapter.ts
5399
+ var KmsSignerAdapter = class {
5400
+ constructor(kms, resolveKey) {
5401
+ this.kms = kms;
5402
+ this.resolveKey = resolveKey;
5403
+ }
5404
+ async getAddress(userId) {
5405
+ return (await this.resolveKey(userId)).address;
5406
+ }
5407
+ async ensureSigner(userId) {
5408
+ return { address: (await this.resolveKey(userId)).address };
5409
+ }
5410
+ async signMessage(userId, message, ctx) {
5411
+ const { address } = await this.resolveKey(userId);
5412
+ const hash = hashMessage(message);
5413
+ const target = { Address: address };
5414
+ if (ctx && "webAuthnAssertion" in ctx) {
5415
+ const { ChallengeId, Credential } = ctx.webAuthnAssertion;
5416
+ const res = await this.kms.signHashWithWebAuthn(hash, ChallengeId, Credential, target);
5417
+ return "0x" + res.Signature;
5418
+ }
5419
+ if (ctx && "assertion" in ctx) {
5420
+ const res = await this.kms.signHash(hash, ctx.assertion, target);
5421
+ return "0x" + res.Signature;
5422
+ }
5423
+ throw new Error(
5424
+ "KmsSignerAdapter: KMS signing requires an auth context \u2014 pass a one-time WebAuthnCeremonyContext { webAuthnAssertion } (preferred)."
5425
+ );
5426
+ }
5427
+ };
4986
5428
  /*! Bundled license information:
4987
5429
 
4988
5430
  @noble/curves/nist.js:
4989
5431
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
4990
5432
  */
4991
5433
 
4992
- export { ACCOUNT_ABI, AGENT_SESSION_KEY_VALIDATOR_ABI, AIRACCOUNT_ABI, AIRACCOUNT_ADDRESSES, AIRACCOUNT_FACTORY_ABI, AIR_ACCOUNT_COMPOSITE_VALIDATOR_ABI, AIR_ACCOUNT_DELEGATE_ABI, AIR_ACCOUNT_DELEGATE_ADDRESS, ALG_ID, AccountManager, AgentRegistryService, AirAccountServerClient, BLSSignatureService, CALLDATA_PARSER_REGISTRY_ABI, ConsoleLogger, DEFAULT_CREDENTIAL_ID, DEFAULT_KMS_ENDPOINT, DEFAULT_ORIGIN, DEFAULT_RP_ID, DvtPendingConfirmationError, EIP7702DelegateService, ENTRYPOINT_ABI_V6, ENTRYPOINT_ABI_V7_V8, ENTRYPOINT_ADDRESSES, ERC20_ABI, ERC8004Service, ERC8004_ADDRESSES, EXECUTE_BATCH_SELECTOR, EXECUTE_SELECTOR, EXECUTE_USER_OP_SELECTOR, EntryPointVersion, EthereumProvider, FACTORY_ABI_V6, FACTORY_ABI_V7_V8, FORCE_EXIT_MODULE_ABI, ForceExitService, GLOBAL_GUARD_ABI, GuardChecker, GuardStateReader, KmsAgentService, KmsHttpClient, KmsManager, KmsMonitorService, KmsPaymentSigner, KmsSessionService, KmsSigner, L2_TYPE, LocalWalletSigner, MAX_GUARDIANS, MODULE_TYPE, MemoryStorage, ModuleManager, P256PasskeySigner, PaymasterManager, PaymasterPriceStalenessError, RECOVERY_THRESHOLD, RECOVERY_TIMELOCK_SECONDS, RecoveryService, SESSION_KEY_VALIDATOR_ABI, SessionKeyService, SilentLogger, TIER_GUARD_HOOK_ABI, TokenService, TransferManager, VALIDATOR_ABI, WEIGHT_CHANGE_EXPIRY_SECONDS, WEIGHT_CHANGE_THRESHOLD, WEIGHT_CHANGE_TIMELOCK_SECONDS, WalletManager, WeightedSignatureService, YAAAServerClient, base64UrlDecode, base64UrlEncode, beginAuthenticationChallenge, beginGrantSessionChallenge, buildAuthenticationCredential, buildAuthenticatorData, buildClientDataJSON, buildFullInitConfig, buildInstallModuleHash, buildUninstallModuleHash, computeOapdSalt, erc8004AddressesForChain, getOapdAddress, getOapdAddressWithChainId, initConfigFromRecord, initConfigToTuple, isExecuteUserOpWrapped, isOapdDeployed, isPendingConfirmation, packP256SessionSignature, packSecp256k1SessionSignature, runAuthenticationCeremony, runGrantSessionCeremony, runWebAuthnCeremony, sepoliaV07Config, serializeGuardianSpecs, toGuardianSpecs, validateConfig, wrapExecuteUserOp };
4993
- //# sourceMappingURL=chunk-BPAAWQQA.js.map
4994
- //# sourceMappingURL=chunk-BPAAWQQA.js.map
5434
+ export { ACCOUNT_ABI, AGENT_SESSION_KEY_VALIDATOR_ABI, AIRACCOUNT_ABI, AIRACCOUNT_ADDRESSES, AIRACCOUNT_FACTORY_ABI, AIR_ACCOUNT_COMPOSITE_VALIDATOR_ABI, AIR_ACCOUNT_DELEGATE_ABI, AIR_ACCOUNT_DELEGATE_ADDRESS, ALG_ID, AccountManager, AgentRegistryService, AirAccountServerClient, BLSSignatureService, CALLDATA_PARSER_REGISTRY_ABI, ConsoleLogger, DEFAULT_CREDENTIAL_ID, DEFAULT_KMS_ENDPOINT, DEFAULT_ORIGIN, DEFAULT_RP_ID, DvtPendingConfirmationError, EIP7702DelegateService, ENTRYPOINT_ABI_V6, ENTRYPOINT_ABI_V7_V8, ENTRYPOINT_ADDRESSES, ERC20_ABI, ERC8004Service, ERC8004_ADDRESSES, EXECUTE_BATCH_SELECTOR, EXECUTE_SELECTOR, EXECUTE_USER_OP_SELECTOR, EntryPointVersion, EthereumProvider, FACTORY_ABI_V6, FACTORY_ABI_V7_V8, FORCE_EXIT_MODULE_ABI, ForceExitService, GLOBAL_GUARD_ABI, GuardChecker, GuardStateReader, KmsAgentService, KmsHttpClient, KmsManager, KmsMonitorService, KmsPaymentSigner, KmsSessionService, KmsSigner, KmsSignerAdapter, L2_TYPE, LocalWalletSigner, MAX_GUARDIANS, MODULE_TYPE, MemoryStorage, ModuleManager, P256PasskeySigner, PaymasterManager, PaymasterPriceStalenessError, RECOVERY_THRESHOLD, RECOVERY_TIMELOCK_SECONDS, RecoveryService, SESSION_KEY_VALIDATOR_ABI, SessionKeyService, SilentLogger, TIER_GUARD_HOOK_ABI, TokenService, TransferManager, VALIDATOR_ABI, WEIGHT_CHANGE_EXPIRY_SECONDS, WEIGHT_CHANGE_THRESHOLD, WEIGHT_CHANGE_TIMELOCK_SECONDS, WalletManager, WeightedSignatureService, YAAAServerClient, base64UrlDecode, base64UrlEncode, beginAuthenticationChallenge, beginGrantSessionChallenge, buildAuthenticationCredential, buildAuthenticatorData, buildClientDataJSON, buildFullInitConfig, buildInstallModuleHash, buildUninstallModuleHash, commitChallenge, computeOapdSalt, eip712Digest, erc8004AddressesForChain, gTokenAuthorizationDigest, getOapdAddress, getOapdAddressWithChainId, grantSessionFinalHash, initConfigFromRecord, initConfigToTuple, isExecuteUserOpWrapped, isOapdDeployed, isPendingConfirmation, micropaymentVoucherDigest, mintDigest, packP256SessionSignature, packSecp256k1SessionSignature, runAuthenticationCeremony, runGrantSessionCeremony, runWebAuthnCeremony, sepoliaV07Config, serializeGuardianSpecs, toGuardianSpecs, validateConfig, wrapExecuteUserOp, x402PaymentDigest };
5435
+ //# sourceMappingURL=chunk-4GJSK7E6.js.map
5436
+ //# sourceMappingURL=chunk-4GJSK7E6.js.map