@aastar/sdk 0.21.1 → 0.22.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 (98) hide show
  1. package/dist/UserClient-AJOGJXOC.cjs +15 -0
  2. package/dist/{UserClient-QM2CQVRM.cjs.map → UserClient-AJOGJXOC.cjs.map} +1 -1
  3. package/dist/UserClient-Y65JLJ23.js +6 -0
  4. package/dist/{UserClient-2JL52CNK.js.map → UserClient-Y65JLJ23.js.map} +1 -1
  5. package/dist/account.cjs +7 -7
  6. package/dist/account.js +2 -2
  7. package/dist/admin.cjs +3 -3
  8. package/dist/admin.js +2 -2
  9. package/dist/airaccount.cjs +1 -1
  10. package/dist/airaccount.js +1 -1
  11. package/dist/channel.cjs +6 -6
  12. package/dist/channel.js +2 -2
  13. package/dist/{chunk-M5WFKETT.js → chunk-2TS6T2WY.js} +1512 -66
  14. package/dist/chunk-2TS6T2WY.js.map +1 -0
  15. package/dist/{chunk-WR4OZUXR.cjs → chunk-3OIVYXUG.cjs} +6 -6
  16. package/dist/{chunk-WR4OZUXR.cjs.map → chunk-3OIVYXUG.cjs.map} +1 -1
  17. package/dist/{chunk-HT6LGLDM.cjs → chunk-6ISQM3SF.cjs} +26 -26
  18. package/dist/{chunk-HT6LGLDM.cjs.map → chunk-6ISQM3SF.cjs.map} +1 -1
  19. package/dist/{chunk-IJN776TA.cjs → chunk-7HO4IUHZ.cjs} +32 -32
  20. package/dist/{chunk-IJN776TA.cjs.map → chunk-7HO4IUHZ.cjs.map} +1 -1
  21. package/dist/{chunk-Z4GZ6DQA.cjs → chunk-7RNOKMAJ.cjs} +9 -9
  22. package/dist/{chunk-Z4GZ6DQA.cjs.map → chunk-7RNOKMAJ.cjs.map} +1 -1
  23. package/dist/{chunk-IZN2COBP.cjs → chunk-BBZAD5G2.cjs} +11 -11
  24. package/dist/{chunk-IZN2COBP.cjs.map → chunk-BBZAD5G2.cjs.map} +1 -1
  25. package/dist/{chunk-Y4EJX7UA.cjs → chunk-BLA57KBS.cjs} +12 -12
  26. package/dist/{chunk-Y4EJX7UA.cjs.map → chunk-BLA57KBS.cjs.map} +1 -1
  27. package/dist/{chunk-5JFYTJOE.cjs → chunk-DOVGH7HB.cjs} +4 -4
  28. package/dist/{chunk-5JFYTJOE.cjs.map → chunk-DOVGH7HB.cjs.map} +1 -1
  29. package/dist/{chunk-M7HXR7G5.cjs → chunk-FZLBMUPN.cjs} +5 -5
  30. package/dist/{chunk-M7HXR7G5.cjs.map → chunk-FZLBMUPN.cjs.map} +1 -1
  31. package/dist/{chunk-5NKU5NT5.js → chunk-JCK7VAZF.js} +8 -8
  32. package/dist/{chunk-5NKU5NT5.js.map → chunk-JCK7VAZF.js.map} +1 -1
  33. package/dist/{chunk-EY2AJTGV.js → chunk-LKSQASFZ.js} +3 -3
  34. package/dist/{chunk-EY2AJTGV.js.map → chunk-LKSQASFZ.js.map} +1 -1
  35. package/dist/{chunk-3HZEIFBW.cjs → chunk-MG72SGVS.cjs} +5 -5
  36. package/dist/{chunk-3HZEIFBW.cjs.map → chunk-MG72SGVS.cjs.map} +1 -1
  37. package/dist/{chunk-ENSMYCU6.js → chunk-MQMTICTP.js} +3 -3
  38. package/dist/{chunk-ENSMYCU6.js.map → chunk-MQMTICTP.js.map} +1 -1
  39. package/dist/{chunk-DQBKE4ND.js → chunk-R3N7L7RE.js} +4 -4
  40. package/dist/{chunk-DQBKE4ND.js.map → chunk-R3N7L7RE.js.map} +1 -1
  41. package/dist/{chunk-PED7PJQZ.cjs → chunk-RF3MSLRW.cjs} +16 -16
  42. package/dist/{chunk-PED7PJQZ.cjs.map → chunk-RF3MSLRW.cjs.map} +1 -1
  43. package/dist/{chunk-MKUILC7J.js → chunk-SNVHOCU6.js} +3 -3
  44. package/dist/{chunk-MKUILC7J.js.map → chunk-SNVHOCU6.js.map} +1 -1
  45. package/dist/{chunk-UP2S7C7R.js → chunk-T2GF4S3E.js} +6 -6
  46. package/dist/{chunk-UP2S7C7R.js.map → chunk-T2GF4S3E.js.map} +1 -1
  47. package/dist/{chunk-CIEYY3A6.cjs → chunk-TS5CXRNI.cjs} +1541 -64
  48. package/dist/chunk-TS5CXRNI.cjs.map +1 -0
  49. package/dist/{chunk-57XLR2NT.js → chunk-UUT246S2.js} +3 -3
  50. package/dist/{chunk-57XLR2NT.js.map → chunk-UUT246S2.js.map} +1 -1
  51. package/dist/{chunk-JYHDAOUT.js → chunk-VUNNHEND.js} +9 -9
  52. package/dist/{chunk-JYHDAOUT.js.map → chunk-VUNNHEND.js.map} +1 -1
  53. package/dist/{chunk-KZERVPUR.js → chunk-XTF6MNIK.js} +3 -3
  54. package/dist/{chunk-KZERVPUR.js.map → chunk-XTF6MNIK.js.map} +1 -1
  55. package/dist/{chunk-E4CQFW75.js → chunk-XZDMKHKG.js} +3 -3
  56. package/dist/{chunk-E4CQFW75.js.map → chunk-XZDMKHKG.js.map} +1 -1
  57. package/dist/core.cjs +295 -171
  58. package/dist/core.d.cts +362 -27
  59. package/dist/core.d.ts +362 -27
  60. package/dist/core.js +1 -1
  61. package/dist/dapp.cjs +5 -5
  62. package/dist/dapp.js +2 -2
  63. package/dist/enduser.cjs +6 -6
  64. package/dist/enduser.js +3 -3
  65. package/dist/identity.cjs +5 -5
  66. package/dist/identity.js +2 -2
  67. package/dist/index.cjs +396 -272
  68. package/dist/index.d.cts +1 -1
  69. package/dist/index.d.ts +1 -1
  70. package/dist/index.js +15 -15
  71. package/dist/kms.cjs +1 -1
  72. package/dist/kms.js +1 -1
  73. package/dist/operator.cjs +6 -6
  74. package/dist/operator.js +2 -2
  75. package/dist/paymaster.cjs +15 -15
  76. package/dist/paymaster.js +2 -2
  77. package/dist/{src-CTYY6FNI.js → src-MDGW57S5.js} +4 -4
  78. package/dist/src-MDGW57S5.js.map +1 -0
  79. package/dist/src-SCR3OCME.js +5 -0
  80. package/dist/src-SCR3OCME.js.map +1 -0
  81. package/dist/{src-CUHI6G6W.cjs → src-UQ4RDCJG.cjs} +297 -173
  82. package/dist/src-UQ4RDCJG.cjs.map +1 -0
  83. package/dist/{src-X5IECEPM.cjs → src-WGYHZSLY.cjs} +17 -17
  84. package/dist/src-WGYHZSLY.cjs.map +1 -0
  85. package/dist/tokens.cjs +3 -3
  86. package/dist/tokens.js +2 -2
  87. package/dist/x402.cjs +25 -25
  88. package/dist/x402.js +2 -2
  89. package/package.json +1 -1
  90. package/dist/UserClient-2JL52CNK.js +0 -6
  91. package/dist/UserClient-QM2CQVRM.cjs +0 -15
  92. package/dist/chunk-CIEYY3A6.cjs.map +0 -1
  93. package/dist/chunk-M5WFKETT.js.map +0 -1
  94. package/dist/src-CTYY6FNI.js.map +0 -1
  95. package/dist/src-CUHI6G6W.cjs.map +0 -1
  96. package/dist/src-X5IECEPM.cjs.map +0 -1
  97. package/dist/src-XCV6BTSV.js +0 -5
  98. package/dist/src-XCV6BTSV.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { TEST_TOKEN_ADDRESSES, COMMUNITY_OWNERS, MONITORING_ADDRESSES, CORE_ADDRESSES, TOKEN_ADDRESSES, TEST_COMMUNITIES, OFFICIAL_ADDRESSES, PAYMASTER_ADDRESSES, TEST_ACCOUNT_ADDRESSES } from './chunk-UCLK6LTB.js';
2
- import { keccak256, toHex, parseEther, parseAbi, createPublicClient, http, toBytes, decodeFunctionData, decodeAbiParameters, zeroAddress, erc20Abi, formatEther, encodeAbiParameters, parseAbiParameters, encodePacked, concat, numberToHex, isHex, size, isAddress, custom } from 'viem';
2
+ import { keccak256, toHex, parseEther, parseAbi, createPublicClient, http, toBytes, decodeFunctionData, decodeAbiParameters, zeroAddress, erc20Abi, formatEther, encodeAbiParameters, parseAbiParameters, encodePacked, isHex, size, isAddressEqual, concat, numberToHex, pad, sha256 as sha256$1, isAddress, custom } from 'viem';
3
3
  import { sepolia, mainnet } from 'viem/chains';
4
4
  import * as nc from 'crypto';
5
5
  import { getEnsAddress, normalize, getEnsName } from 'viem/ens';
@@ -36624,6 +36624,12 @@ function abytes(b, ...lengths) {
36624
36624
  if (lengths.length > 0 && !lengths.includes(b.length))
36625
36625
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
36626
36626
  }
36627
+ function ahash(h) {
36628
+ if (typeof h !== "function" || typeof h.create !== "function")
36629
+ throw new Error("Hash should be wrapped by utils.createHasher");
36630
+ anumber(h.outputLen);
36631
+ anumber(h.blockLen);
36632
+ }
36627
36633
  function aexists(instance, checkFinished = true) {
36628
36634
  if (instance.destroyed)
36629
36635
  throw new Error("Hash instance has been destroyed");
@@ -36659,6 +36665,21 @@ function toBytes2(data) {
36659
36665
  abytes(data);
36660
36666
  return data;
36661
36667
  }
36668
+ function concatBytes(...arrays) {
36669
+ let sum = 0;
36670
+ for (let i = 0; i < arrays.length; i++) {
36671
+ const a = arrays[i];
36672
+ abytes(a);
36673
+ sum += a.length;
36674
+ }
36675
+ const res = new Uint8Array(sum);
36676
+ for (let i = 0, pad2 = 0; i < arrays.length; i++) {
36677
+ const a = arrays[i];
36678
+ res.set(a, pad2);
36679
+ pad2 += a.length;
36680
+ }
36681
+ return res;
36682
+ }
36662
36683
  var Hash = class {
36663
36684
  };
36664
36685
  function createHasher(hashCons) {
@@ -36683,9 +36704,9 @@ function randomBytes(bytesLength = 32) {
36683
36704
  function setBigUint64(view, byteOffset, value, isLE) {
36684
36705
  if (typeof view.setBigUint64 === "function")
36685
36706
  return view.setBigUint64(byteOffset, value, isLE);
36686
- const _32n = BigInt(32);
36707
+ const _32n2 = BigInt(32);
36687
36708
  const _u32_max = BigInt(4294967295);
36688
- const wh = Number(value >> _32n & _u32_max);
36709
+ const wh = Number(value >> _32n2 & _u32_max);
36689
36710
  const wl = Number(value & _u32_max);
36690
36711
  const h = isLE ? 4 : 0;
36691
36712
  const l = isLE ? 0 : 4;
@@ -36798,6 +36819,77 @@ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
36798
36819
  528734635,
36799
36820
  1541459225
36800
36821
  ]);
36822
+ var SHA384_IV = /* @__PURE__ */ Uint32Array.from([
36823
+ 3418070365,
36824
+ 3238371032,
36825
+ 1654270250,
36826
+ 914150663,
36827
+ 2438529370,
36828
+ 812702999,
36829
+ 355462360,
36830
+ 4144912697,
36831
+ 1731405415,
36832
+ 4290775857,
36833
+ 2394180231,
36834
+ 1750603025,
36835
+ 3675008525,
36836
+ 1694076839,
36837
+ 1203062813,
36838
+ 3204075428
36839
+ ]);
36840
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
36841
+ 1779033703,
36842
+ 4089235720,
36843
+ 3144134277,
36844
+ 2227873595,
36845
+ 1013904242,
36846
+ 4271175723,
36847
+ 2773480762,
36848
+ 1595750129,
36849
+ 1359893119,
36850
+ 2917565137,
36851
+ 2600822924,
36852
+ 725511199,
36853
+ 528734635,
36854
+ 4215389547,
36855
+ 1541459225,
36856
+ 327033209
36857
+ ]);
36858
+
36859
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
36860
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
36861
+ var _32n = /* @__PURE__ */ BigInt(32);
36862
+ function fromBig(n, le = false) {
36863
+ if (le)
36864
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
36865
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
36866
+ }
36867
+ function split(lst, le = false) {
36868
+ const len = lst.length;
36869
+ let Ah = new Uint32Array(len);
36870
+ let Al = new Uint32Array(len);
36871
+ for (let i = 0; i < len; i++) {
36872
+ const { h, l } = fromBig(lst[i], le);
36873
+ [Ah[i], Al[i]] = [h, l];
36874
+ }
36875
+ return [Ah, Al];
36876
+ }
36877
+ var shrSH = (h, _l, s) => h >>> s;
36878
+ var shrSL = (h, l, s) => h << 32 - s | l >>> s;
36879
+ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
36880
+ var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
36881
+ var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
36882
+ var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
36883
+ function add(Ah, Al, Bh, Bl) {
36884
+ const l = (Al >>> 0) + (Bl >>> 0);
36885
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
36886
+ }
36887
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
36888
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
36889
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
36890
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
36891
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
36892
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
36801
36893
 
36802
36894
  // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
36803
36895
  var SHA256_K = /* @__PURE__ */ Uint32Array.from([
@@ -36937,7 +37029,227 @@ var SHA256 = class extends HashMD {
36937
37029
  clean(this.buffer);
36938
37030
  }
36939
37031
  };
37032
+ var K512 = /* @__PURE__ */ (() => split([
37033
+ "0x428a2f98d728ae22",
37034
+ "0x7137449123ef65cd",
37035
+ "0xb5c0fbcfec4d3b2f",
37036
+ "0xe9b5dba58189dbbc",
37037
+ "0x3956c25bf348b538",
37038
+ "0x59f111f1b605d019",
37039
+ "0x923f82a4af194f9b",
37040
+ "0xab1c5ed5da6d8118",
37041
+ "0xd807aa98a3030242",
37042
+ "0x12835b0145706fbe",
37043
+ "0x243185be4ee4b28c",
37044
+ "0x550c7dc3d5ffb4e2",
37045
+ "0x72be5d74f27b896f",
37046
+ "0x80deb1fe3b1696b1",
37047
+ "0x9bdc06a725c71235",
37048
+ "0xc19bf174cf692694",
37049
+ "0xe49b69c19ef14ad2",
37050
+ "0xefbe4786384f25e3",
37051
+ "0x0fc19dc68b8cd5b5",
37052
+ "0x240ca1cc77ac9c65",
37053
+ "0x2de92c6f592b0275",
37054
+ "0x4a7484aa6ea6e483",
37055
+ "0x5cb0a9dcbd41fbd4",
37056
+ "0x76f988da831153b5",
37057
+ "0x983e5152ee66dfab",
37058
+ "0xa831c66d2db43210",
37059
+ "0xb00327c898fb213f",
37060
+ "0xbf597fc7beef0ee4",
37061
+ "0xc6e00bf33da88fc2",
37062
+ "0xd5a79147930aa725",
37063
+ "0x06ca6351e003826f",
37064
+ "0x142929670a0e6e70",
37065
+ "0x27b70a8546d22ffc",
37066
+ "0x2e1b21385c26c926",
37067
+ "0x4d2c6dfc5ac42aed",
37068
+ "0x53380d139d95b3df",
37069
+ "0x650a73548baf63de",
37070
+ "0x766a0abb3c77b2a8",
37071
+ "0x81c2c92e47edaee6",
37072
+ "0x92722c851482353b",
37073
+ "0xa2bfe8a14cf10364",
37074
+ "0xa81a664bbc423001",
37075
+ "0xc24b8b70d0f89791",
37076
+ "0xc76c51a30654be30",
37077
+ "0xd192e819d6ef5218",
37078
+ "0xd69906245565a910",
37079
+ "0xf40e35855771202a",
37080
+ "0x106aa07032bbd1b8",
37081
+ "0x19a4c116b8d2d0c8",
37082
+ "0x1e376c085141ab53",
37083
+ "0x2748774cdf8eeb99",
37084
+ "0x34b0bcb5e19b48a8",
37085
+ "0x391c0cb3c5c95a63",
37086
+ "0x4ed8aa4ae3418acb",
37087
+ "0x5b9cca4f7763e373",
37088
+ "0x682e6ff3d6b2b8a3",
37089
+ "0x748f82ee5defb2fc",
37090
+ "0x78a5636f43172f60",
37091
+ "0x84c87814a1f0ab72",
37092
+ "0x8cc702081a6439ec",
37093
+ "0x90befffa23631e28",
37094
+ "0xa4506cebde82bde9",
37095
+ "0xbef9a3f7b2c67915",
37096
+ "0xc67178f2e372532b",
37097
+ "0xca273eceea26619c",
37098
+ "0xd186b8c721c0c207",
37099
+ "0xeada7dd6cde0eb1e",
37100
+ "0xf57d4f7fee6ed178",
37101
+ "0x06f067aa72176fba",
37102
+ "0x0a637dc5a2c898a6",
37103
+ "0x113f9804bef90dae",
37104
+ "0x1b710b35131c471b",
37105
+ "0x28db77f523047d84",
37106
+ "0x32caab7b40c72493",
37107
+ "0x3c9ebe0a15c9bebc",
37108
+ "0x431d67c49c100d4c",
37109
+ "0x4cc5d4becb3e42b6",
37110
+ "0x597f299cfc657e2a",
37111
+ "0x5fcb6fab3ad6faec",
37112
+ "0x6c44198c4a475817"
37113
+ ].map((n) => BigInt(n))))();
37114
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
37115
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
37116
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
37117
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
37118
+ var SHA512 = class extends HashMD {
37119
+ constructor(outputLen = 64) {
37120
+ super(128, outputLen, 16, false);
37121
+ this.Ah = SHA512_IV[0] | 0;
37122
+ this.Al = SHA512_IV[1] | 0;
37123
+ this.Bh = SHA512_IV[2] | 0;
37124
+ this.Bl = SHA512_IV[3] | 0;
37125
+ this.Ch = SHA512_IV[4] | 0;
37126
+ this.Cl = SHA512_IV[5] | 0;
37127
+ this.Dh = SHA512_IV[6] | 0;
37128
+ this.Dl = SHA512_IV[7] | 0;
37129
+ this.Eh = SHA512_IV[8] | 0;
37130
+ this.El = SHA512_IV[9] | 0;
37131
+ this.Fh = SHA512_IV[10] | 0;
37132
+ this.Fl = SHA512_IV[11] | 0;
37133
+ this.Gh = SHA512_IV[12] | 0;
37134
+ this.Gl = SHA512_IV[13] | 0;
37135
+ this.Hh = SHA512_IV[14] | 0;
37136
+ this.Hl = SHA512_IV[15] | 0;
37137
+ }
37138
+ // prettier-ignore
37139
+ get() {
37140
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
37141
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
37142
+ }
37143
+ // prettier-ignore
37144
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
37145
+ this.Ah = Ah | 0;
37146
+ this.Al = Al | 0;
37147
+ this.Bh = Bh | 0;
37148
+ this.Bl = Bl | 0;
37149
+ this.Ch = Ch | 0;
37150
+ this.Cl = Cl | 0;
37151
+ this.Dh = Dh | 0;
37152
+ this.Dl = Dl | 0;
37153
+ this.Eh = Eh | 0;
37154
+ this.El = El | 0;
37155
+ this.Fh = Fh | 0;
37156
+ this.Fl = Fl | 0;
37157
+ this.Gh = Gh | 0;
37158
+ this.Gl = Gl | 0;
37159
+ this.Hh = Hh | 0;
37160
+ this.Hl = Hl | 0;
37161
+ }
37162
+ process(view, offset) {
37163
+ for (let i = 0; i < 16; i++, offset += 4) {
37164
+ SHA512_W_H[i] = view.getUint32(offset);
37165
+ SHA512_W_L[i] = view.getUint32(offset += 4);
37166
+ }
37167
+ for (let i = 16; i < 80; i++) {
37168
+ const W15h = SHA512_W_H[i - 15] | 0;
37169
+ const W15l = SHA512_W_L[i - 15] | 0;
37170
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
37171
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
37172
+ const W2h = SHA512_W_H[i - 2] | 0;
37173
+ const W2l = SHA512_W_L[i - 2] | 0;
37174
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
37175
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
37176
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
37177
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
37178
+ SHA512_W_H[i] = SUMh | 0;
37179
+ SHA512_W_L[i] = SUMl | 0;
37180
+ }
37181
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
37182
+ for (let i = 0; i < 80; i++) {
37183
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
37184
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
37185
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
37186
+ const CHIl = El & Fl ^ ~El & Gl;
37187
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
37188
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
37189
+ const T1l = T1ll | 0;
37190
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
37191
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
37192
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
37193
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
37194
+ Hh = Gh | 0;
37195
+ Hl = Gl | 0;
37196
+ Gh = Fh | 0;
37197
+ Gl = Fl | 0;
37198
+ Fh = Eh | 0;
37199
+ Fl = El | 0;
37200
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
37201
+ Dh = Ch | 0;
37202
+ Dl = Cl | 0;
37203
+ Ch = Bh | 0;
37204
+ Cl = Bl | 0;
37205
+ Bh = Ah | 0;
37206
+ Bl = Al | 0;
37207
+ const All = add3L(T1l, sigma0l, MAJl);
37208
+ Ah = add3H(All, T1h, sigma0h, MAJh);
37209
+ Al = All | 0;
37210
+ }
37211
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
37212
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
37213
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
37214
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
37215
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
37216
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
37217
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
37218
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
37219
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
37220
+ }
37221
+ roundClean() {
37222
+ clean(SHA512_W_H, SHA512_W_L);
37223
+ }
37224
+ destroy() {
37225
+ clean(this.buffer);
37226
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
37227
+ }
37228
+ };
37229
+ var SHA384 = class extends SHA512 {
37230
+ constructor() {
37231
+ super(48);
37232
+ this.Ah = SHA384_IV[0] | 0;
37233
+ this.Al = SHA384_IV[1] | 0;
37234
+ this.Bh = SHA384_IV[2] | 0;
37235
+ this.Bl = SHA384_IV[3] | 0;
37236
+ this.Ch = SHA384_IV[4] | 0;
37237
+ this.Cl = SHA384_IV[5] | 0;
37238
+ this.Dh = SHA384_IV[6] | 0;
37239
+ this.Dl = SHA384_IV[7] | 0;
37240
+ this.Eh = SHA384_IV[8] | 0;
37241
+ this.El = SHA384_IV[9] | 0;
37242
+ this.Fh = SHA384_IV[10] | 0;
37243
+ this.Fl = SHA384_IV[11] | 0;
37244
+ this.Gh = SHA384_IV[12] | 0;
37245
+ this.Gl = SHA384_IV[13] | 0;
37246
+ this.Hh = SHA384_IV[14] | 0;
37247
+ this.Hl = SHA384_IV[15] | 0;
37248
+ }
37249
+ };
36940
37250
  var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
37251
+ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
37252
+ var sha384 = /* @__PURE__ */ createHasher(() => new SHA384());
36941
37253
 
36942
37254
  // ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/utils.js
36943
37255
  var _0n = /* @__PURE__ */ BigInt(0);
@@ -36953,6 +37265,10 @@ function abool(title, value) {
36953
37265
  if (typeof value !== "boolean")
36954
37266
  throw new Error(title + " boolean expected, got " + value);
36955
37267
  }
37268
+ function numberToHexUnpadded(num) {
37269
+ const hex = num.toString(16);
37270
+ return hex.length & 1 ? "0" + hex : hex;
37271
+ }
36956
37272
  function hexToNumber(hex) {
36957
37273
  if (typeof hex !== "string")
36958
37274
  throw new Error("hex string expected, got " + typeof hex);
@@ -37035,7 +37351,7 @@ function ensureBytes(title, hex, expectedLength) {
37035
37351
  throw new Error(title + " of length " + expectedLength + " expected, got " + len);
37036
37352
  return res;
37037
37353
  }
37038
- function concatBytes(...arrays) {
37354
+ function concatBytes2(...arrays) {
37039
37355
  let sum = 0;
37040
37356
  for (let i = 0; i < arrays.length; i++) {
37041
37357
  const a = arrays[i];
@@ -37043,10 +37359,10 @@ function concatBytes(...arrays) {
37043
37359
  sum += a.length;
37044
37360
  }
37045
37361
  const res = new Uint8Array(sum);
37046
- for (let i = 0, pad = 0; i < arrays.length; i++) {
37362
+ for (let i = 0, pad2 = 0; i < arrays.length; i++) {
37047
37363
  const a = arrays[i];
37048
- res.set(a, pad);
37049
- pad += a.length;
37364
+ res.set(a, pad2);
37365
+ pad2 += a.length;
37050
37366
  }
37051
37367
  return res;
37052
37368
  }
@@ -37073,6 +37389,56 @@ function bitGet(n, pos) {
37073
37389
  return n >> BigInt(pos) & _1n;
37074
37390
  }
37075
37391
  var bitMask = (n) => (_1n << BigInt(n)) - _1n;
37392
+ var u8n = (len) => new Uint8Array(len);
37393
+ var u8fr = (arr) => Uint8Array.from(arr);
37394
+ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
37395
+ if (typeof hashLen !== "number" || hashLen < 2)
37396
+ throw new Error("hashLen must be a number");
37397
+ if (typeof qByteLen !== "number" || qByteLen < 2)
37398
+ throw new Error("qByteLen must be a number");
37399
+ if (typeof hmacFn !== "function")
37400
+ throw new Error("hmacFn must be a function");
37401
+ let v = u8n(hashLen);
37402
+ let k = u8n(hashLen);
37403
+ let i = 0;
37404
+ const reset = () => {
37405
+ v.fill(1);
37406
+ k.fill(0);
37407
+ i = 0;
37408
+ };
37409
+ const h = (...b) => hmacFn(k, v, ...b);
37410
+ const reseed = (seed = u8n(0)) => {
37411
+ k = h(u8fr([0]), seed);
37412
+ v = h();
37413
+ if (seed.length === 0)
37414
+ return;
37415
+ k = h(u8fr([1]), seed);
37416
+ v = h();
37417
+ };
37418
+ const gen = () => {
37419
+ if (i++ >= 1e3)
37420
+ throw new Error("drbg: tried 1000 values");
37421
+ let len = 0;
37422
+ const out = [];
37423
+ while (len < qByteLen) {
37424
+ v = h();
37425
+ const sl = v.slice();
37426
+ out.push(sl);
37427
+ len += v.length;
37428
+ }
37429
+ return concatBytes2(...out);
37430
+ };
37431
+ const genUntil = (seed, pred) => {
37432
+ reset();
37433
+ reseed(seed);
37434
+ let res = void 0;
37435
+ while (!(res = pred(gen())))
37436
+ reseed();
37437
+ reset();
37438
+ return res;
37439
+ };
37440
+ return genUntil;
37441
+ }
37076
37442
  var validatorFns = {
37077
37443
  bigint: (val) => typeof val === "bigint",
37078
37444
  function: (val) => typeof val === "function",
@@ -37412,22 +37778,22 @@ function expand_message_xmd(msg, DST, lenInBytes, H) {
37412
37778
  abytes2(DST);
37413
37779
  anum(lenInBytes);
37414
37780
  if (DST.length > 255)
37415
- DST = H(concatBytes(utf8ToBytes2("H2C-OVERSIZE-DST-"), DST));
37781
+ DST = H(concatBytes2(utf8ToBytes2("H2C-OVERSIZE-DST-"), DST));
37416
37782
  const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
37417
37783
  const ell = Math.ceil(lenInBytes / b_in_bytes);
37418
37784
  if (lenInBytes > 65535 || ell > 255)
37419
37785
  throw new Error("expand_message_xmd: invalid lenInBytes");
37420
- const DST_prime = concatBytes(DST, i2osp(DST.length, 1));
37786
+ const DST_prime = concatBytes2(DST, i2osp(DST.length, 1));
37421
37787
  const Z_pad = i2osp(0, r_in_bytes);
37422
37788
  const l_i_b_str = i2osp(lenInBytes, 2);
37423
37789
  const b = new Array(ell);
37424
- const b_0 = H(concatBytes(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
37425
- b[0] = H(concatBytes(b_0, i2osp(1, 1), DST_prime));
37790
+ const b_0 = H(concatBytes2(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
37791
+ b[0] = H(concatBytes2(b_0, i2osp(1, 1), DST_prime));
37426
37792
  for (let i = 1; i <= ell; i++) {
37427
37793
  const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
37428
- b[i] = H(concatBytes(...args));
37794
+ b[i] = H(concatBytes2(...args));
37429
37795
  }
37430
- const pseudo_random_bytes = concatBytes(...b);
37796
+ const pseudo_random_bytes = concatBytes2(...b);
37431
37797
  return pseudo_random_bytes.slice(0, lenInBytes);
37432
37798
  }
37433
37799
  function expand_message_xof(msg, DST, lenInBytes, k, H) {
@@ -37765,6 +38131,12 @@ function validateBasic(curve) {
37765
38131
  }
37766
38132
 
37767
38133
  // ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/weierstrass.js
38134
+ function validateSigVerOpts(opts) {
38135
+ if (opts.lowS !== void 0)
38136
+ abool("lowS", opts.lowS);
38137
+ if (opts.prehash !== void 0)
38138
+ abool("prehash", opts.prehash);
38139
+ }
37768
38140
  function validatePointOpts(curve) {
37769
38141
  const opts = validateBasic(curve);
37770
38142
  validateObject(opts, {
@@ -37790,6 +38162,114 @@ function validatePointOpts(curve) {
37790
38162
  }
37791
38163
  return Object.freeze({ ...opts });
37792
38164
  }
38165
+ var DERErr = class extends Error {
38166
+ constructor(m = "") {
38167
+ super(m);
38168
+ }
38169
+ };
38170
+ var DER = {
38171
+ // asn.1 DER encoding utils
38172
+ Err: DERErr,
38173
+ // Basic building block is TLV (Tag-Length-Value)
38174
+ _tlv: {
38175
+ encode: (tag, data) => {
38176
+ const { Err: E } = DER;
38177
+ if (tag < 0 || tag > 256)
38178
+ throw new E("tlv.encode: wrong tag");
38179
+ if (data.length & 1)
38180
+ throw new E("tlv.encode: unpadded data");
38181
+ const dataLen = data.length / 2;
38182
+ const len = numberToHexUnpadded(dataLen);
38183
+ if (len.length / 2 & 128)
38184
+ throw new E("tlv.encode: long form length too big");
38185
+ const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
38186
+ const t = numberToHexUnpadded(tag);
38187
+ return t + lenLen + len + data;
38188
+ },
38189
+ // v - value, l - left bytes (unparsed)
38190
+ decode(tag, data) {
38191
+ const { Err: E } = DER;
38192
+ let pos = 0;
38193
+ if (tag < 0 || tag > 256)
38194
+ throw new E("tlv.encode: wrong tag");
38195
+ if (data.length < 2 || data[pos++] !== tag)
38196
+ throw new E("tlv.decode: wrong tlv");
38197
+ const first = data[pos++];
38198
+ const isLong = !!(first & 128);
38199
+ let length = 0;
38200
+ if (!isLong)
38201
+ length = first;
38202
+ else {
38203
+ const lenLen = first & 127;
38204
+ if (!lenLen)
38205
+ throw new E("tlv.decode(long): indefinite length not supported");
38206
+ if (lenLen > 4)
38207
+ throw new E("tlv.decode(long): byte length is too big");
38208
+ const lengthBytes = data.subarray(pos, pos + lenLen);
38209
+ if (lengthBytes.length !== lenLen)
38210
+ throw new E("tlv.decode: length bytes not complete");
38211
+ if (lengthBytes[0] === 0)
38212
+ throw new E("tlv.decode(long): zero leftmost byte");
38213
+ for (const b of lengthBytes)
38214
+ length = length << 8 | b;
38215
+ pos += lenLen;
38216
+ if (length < 128)
38217
+ throw new E("tlv.decode(long): not minimal encoding");
38218
+ }
38219
+ const v = data.subarray(pos, pos + length);
38220
+ if (v.length !== length)
38221
+ throw new E("tlv.decode: wrong value length");
38222
+ return { v, l: data.subarray(pos + length) };
38223
+ }
38224
+ },
38225
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
38226
+ // since we always use positive integers here. It must always be empty:
38227
+ // - add zero byte if exists
38228
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
38229
+ _int: {
38230
+ encode(num) {
38231
+ const { Err: E } = DER;
38232
+ if (num < _0n4)
38233
+ throw new E("integer: negative integers are not allowed");
38234
+ let hex = numberToHexUnpadded(num);
38235
+ if (Number.parseInt(hex[0], 16) & 8)
38236
+ hex = "00" + hex;
38237
+ if (hex.length & 1)
38238
+ throw new E("unexpected DER parsing assertion: unpadded hex");
38239
+ return hex;
38240
+ },
38241
+ decode(data) {
38242
+ const { Err: E } = DER;
38243
+ if (data[0] & 128)
38244
+ throw new E("invalid signature integer: negative");
38245
+ if (data[0] === 0 && !(data[1] & 128))
38246
+ throw new E("invalid signature integer: unnecessary leading zero");
38247
+ return bytesToNumberBE(data);
38248
+ }
38249
+ },
38250
+ toSig(hex) {
38251
+ const { Err: E, _int: int, _tlv: tlv } = DER;
38252
+ const data = ensureBytes("signature", hex);
38253
+ const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
38254
+ if (seqLeftBytes.length)
38255
+ throw new E("invalid signature: left bytes after parsing");
38256
+ const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
38257
+ const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
38258
+ if (sLeftBytes.length)
38259
+ throw new E("invalid signature: left bytes after parsing");
38260
+ return { r: int.decode(rBytes), s: int.decode(sBytes) };
38261
+ },
38262
+ hexFromSig(sig) {
38263
+ const { _tlv: tlv, _int: int } = DER;
38264
+ const rs = tlv.encode(2, int.encode(sig.r));
38265
+ const ss = tlv.encode(2, int.encode(sig.s));
38266
+ const seq = rs + ss;
38267
+ return tlv.encode(48, seq);
38268
+ }
38269
+ };
38270
+ function numToSizedHex(num, size4) {
38271
+ return bytesToHex(numberToBytesBE(num, size4));
38272
+ }
37793
38273
  var _0n4 = BigInt(0);
37794
38274
  var _1n4 = BigInt(1);
37795
38275
  var _2n2 = BigInt(2);
@@ -37799,9 +38279,9 @@ function weierstrassPoints(opts) {
37799
38279
  const CURVE = validatePointOpts(opts);
37800
38280
  const { Fp: Fp3 } = CURVE;
37801
38281
  const Fn = Field(CURVE.n, CURVE.nBitLength);
37802
- const toBytes6 = CURVE.toBytes || ((_c, point, _isCompressed) => {
38282
+ const toBytes7 = CURVE.toBytes || ((_c, point, _isCompressed) => {
37803
38283
  const a = point.toAffine();
37804
- return concatBytes(Uint8Array.from([4]), Fp3.toBytes(a.x), Fp3.toBytes(a.y));
38284
+ return concatBytes2(Uint8Array.from([4]), Fp3.toBytes(a.x), Fp3.toBytes(a.y));
37805
38285
  });
37806
38286
  const fromBytes = CURVE.fromBytes || ((bytes) => {
37807
38287
  const tail = bytes.subarray(1);
@@ -38179,7 +38659,7 @@ function weierstrassPoints(opts) {
38179
38659
  toRawBytes(isCompressed = true) {
38180
38660
  abool("isCompressed", isCompressed);
38181
38661
  this.assertValidity();
38182
- return toBytes6(Point, this, isCompressed);
38662
+ return toBytes7(Point, this, isCompressed);
38183
38663
  }
38184
38664
  toHex(isCompressed = true) {
38185
38665
  abool("isCompressed", isCompressed);
@@ -38198,6 +38678,343 @@ function weierstrassPoints(opts) {
38198
38678
  isWithinCurveOrder
38199
38679
  };
38200
38680
  }
38681
+ function validateOpts(curve) {
38682
+ const opts = validateBasic(curve);
38683
+ validateObject(opts, {
38684
+ hash: "hash",
38685
+ hmac: "function",
38686
+ randomBytes: "function"
38687
+ }, {
38688
+ bits2int: "function",
38689
+ bits2int_modN: "function",
38690
+ lowS: "boolean"
38691
+ });
38692
+ return Object.freeze({ lowS: true, ...opts });
38693
+ }
38694
+ function weierstrass(curveDef) {
38695
+ const CURVE = validateOpts(curveDef);
38696
+ const { Fp: Fp3, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
38697
+ const compressedLen = Fp3.BYTES + 1;
38698
+ const uncompressedLen = 2 * Fp3.BYTES + 1;
38699
+ function modN(a) {
38700
+ return mod(a, CURVE_ORDER);
38701
+ }
38702
+ function invN(a) {
38703
+ return invert(a, CURVE_ORDER);
38704
+ }
38705
+ const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
38706
+ ...CURVE,
38707
+ toBytes(_c, point, isCompressed) {
38708
+ const a = point.toAffine();
38709
+ const x = Fp3.toBytes(a.x);
38710
+ const cat = concatBytes2;
38711
+ abool("isCompressed", isCompressed);
38712
+ if (isCompressed) {
38713
+ return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
38714
+ } else {
38715
+ return cat(Uint8Array.from([4]), x, Fp3.toBytes(a.y));
38716
+ }
38717
+ },
38718
+ fromBytes(bytes) {
38719
+ const len = bytes.length;
38720
+ const head = bytes[0];
38721
+ const tail = bytes.subarray(1);
38722
+ if (len === compressedLen && (head === 2 || head === 3)) {
38723
+ const x = bytesToNumberBE(tail);
38724
+ if (!inRange(x, _1n4, Fp3.ORDER))
38725
+ throw new Error("Point is not on curve");
38726
+ const y2 = weierstrassEquation(x);
38727
+ let y;
38728
+ try {
38729
+ y = Fp3.sqrt(y2);
38730
+ } catch (sqrtError) {
38731
+ const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
38732
+ throw new Error("Point is not on curve" + suffix);
38733
+ }
38734
+ const isYOdd = (y & _1n4) === _1n4;
38735
+ const isHeadOdd = (head & 1) === 1;
38736
+ if (isHeadOdd !== isYOdd)
38737
+ y = Fp3.neg(y);
38738
+ return { x, y };
38739
+ } else if (len === uncompressedLen && head === 4) {
38740
+ const x = Fp3.fromBytes(tail.subarray(0, Fp3.BYTES));
38741
+ const y = Fp3.fromBytes(tail.subarray(Fp3.BYTES, 2 * Fp3.BYTES));
38742
+ return { x, y };
38743
+ } else {
38744
+ const cl = compressedLen;
38745
+ const ul = uncompressedLen;
38746
+ throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
38747
+ }
38748
+ }
38749
+ });
38750
+ function isBiggerThanHalfOrder(number) {
38751
+ const HALF = CURVE_ORDER >> _1n4;
38752
+ return number > HALF;
38753
+ }
38754
+ function normalizeS(s) {
38755
+ return isBiggerThanHalfOrder(s) ? modN(-s) : s;
38756
+ }
38757
+ const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
38758
+ class Signature {
38759
+ constructor(r, s, recovery) {
38760
+ aInRange("r", r, _1n4, CURVE_ORDER);
38761
+ aInRange("s", s, _1n4, CURVE_ORDER);
38762
+ this.r = r;
38763
+ this.s = s;
38764
+ if (recovery != null)
38765
+ this.recovery = recovery;
38766
+ Object.freeze(this);
38767
+ }
38768
+ // pair (bytes of r, bytes of s)
38769
+ static fromCompact(hex) {
38770
+ const l = nByteLength;
38771
+ hex = ensureBytes("compactSignature", hex, l * 2);
38772
+ return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
38773
+ }
38774
+ // DER encoded ECDSA signature
38775
+ // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
38776
+ static fromDER(hex) {
38777
+ const { r, s } = DER.toSig(ensureBytes("DER", hex));
38778
+ return new Signature(r, s);
38779
+ }
38780
+ /**
38781
+ * @todo remove
38782
+ * @deprecated
38783
+ */
38784
+ assertValidity() {
38785
+ }
38786
+ addRecoveryBit(recovery) {
38787
+ return new Signature(this.r, this.s, recovery);
38788
+ }
38789
+ recoverPublicKey(msgHash) {
38790
+ const { r, s, recovery: rec } = this;
38791
+ const h = bits2int_modN(ensureBytes("msgHash", msgHash));
38792
+ if (rec == null || ![0, 1, 2, 3].includes(rec))
38793
+ throw new Error("recovery id invalid");
38794
+ const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
38795
+ if (radj >= Fp3.ORDER)
38796
+ throw new Error("recovery id 2 or 3 invalid");
38797
+ const prefix = (rec & 1) === 0 ? "02" : "03";
38798
+ const R = Point.fromHex(prefix + numToSizedHex(radj, Fp3.BYTES));
38799
+ const ir = invN(radj);
38800
+ const u1 = modN(-h * ir);
38801
+ const u2 = modN(s * ir);
38802
+ const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2);
38803
+ if (!Q)
38804
+ throw new Error("point at infinify");
38805
+ Q.assertValidity();
38806
+ return Q;
38807
+ }
38808
+ // Signatures should be low-s, to prevent malleability.
38809
+ hasHighS() {
38810
+ return isBiggerThanHalfOrder(this.s);
38811
+ }
38812
+ normalizeS() {
38813
+ return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
38814
+ }
38815
+ // DER-encoded
38816
+ toDERRawBytes() {
38817
+ return hexToBytes(this.toDERHex());
38818
+ }
38819
+ toDERHex() {
38820
+ return DER.hexFromSig(this);
38821
+ }
38822
+ // padded bytes of r, then padded bytes of s
38823
+ toCompactRawBytes() {
38824
+ return hexToBytes(this.toCompactHex());
38825
+ }
38826
+ toCompactHex() {
38827
+ const l = nByteLength;
38828
+ return numToSizedHex(this.r, l) + numToSizedHex(this.s, l);
38829
+ }
38830
+ }
38831
+ const utils = {
38832
+ isValidPrivateKey(privateKey) {
38833
+ try {
38834
+ normPrivateKeyToScalar(privateKey);
38835
+ return true;
38836
+ } catch (error) {
38837
+ return false;
38838
+ }
38839
+ },
38840
+ normPrivateKeyToScalar,
38841
+ /**
38842
+ * Produces cryptographically secure private key from random of size
38843
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
38844
+ */
38845
+ randomPrivateKey: () => {
38846
+ const length = getMinHashLength(CURVE.n);
38847
+ return mapHashToField(CURVE.randomBytes(length), CURVE.n);
38848
+ },
38849
+ /**
38850
+ * Creates precompute table for an arbitrary EC point. Makes point "cached".
38851
+ * Allows to massively speed-up `point.multiply(scalar)`.
38852
+ * @returns cached point
38853
+ * @example
38854
+ * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
38855
+ * fast.multiply(privKey); // much faster ECDH now
38856
+ */
38857
+ precompute(windowSize = 8, point = Point.BASE) {
38858
+ point._setWindowSize(windowSize);
38859
+ point.multiply(BigInt(3));
38860
+ return point;
38861
+ }
38862
+ };
38863
+ function getPublicKey(privateKey, isCompressed = true) {
38864
+ return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
38865
+ }
38866
+ function isProbPub(item) {
38867
+ if (typeof item === "bigint")
38868
+ return false;
38869
+ if (item instanceof Point)
38870
+ return true;
38871
+ const arr = ensureBytes("key", item);
38872
+ const len = arr.length;
38873
+ const fpl = Fp3.BYTES;
38874
+ const compLen = fpl + 1;
38875
+ const uncompLen = 2 * fpl + 1;
38876
+ if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
38877
+ return void 0;
38878
+ } else {
38879
+ return len === compLen || len === uncompLen;
38880
+ }
38881
+ }
38882
+ function getSharedSecret(privateA, publicB, isCompressed = true) {
38883
+ if (isProbPub(privateA) === true)
38884
+ throw new Error("first arg must be private key");
38885
+ if (isProbPub(publicB) === false)
38886
+ throw new Error("second arg must be public key");
38887
+ const b = Point.fromHex(publicB);
38888
+ return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
38889
+ }
38890
+ const bits2int = CURVE.bits2int || function(bytes) {
38891
+ if (bytes.length > 8192)
38892
+ throw new Error("input is too large");
38893
+ const num = bytesToNumberBE(bytes);
38894
+ const delta = bytes.length * 8 - nBitLength;
38895
+ return delta > 0 ? num >> BigInt(delta) : num;
38896
+ };
38897
+ const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
38898
+ return modN(bits2int(bytes));
38899
+ };
38900
+ const ORDER_MASK = bitMask(nBitLength);
38901
+ function int2octets(num) {
38902
+ aInRange("num < 2^" + nBitLength, num, _0n4, ORDER_MASK);
38903
+ return numberToBytesBE(num, nByteLength);
38904
+ }
38905
+ function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
38906
+ if (["recovered", "canonical"].some((k) => k in opts))
38907
+ throw new Error("sign() legacy options not supported");
38908
+ const { hash, randomBytes: randomBytes2 } = CURVE;
38909
+ let { lowS, prehash, extraEntropy: ent } = opts;
38910
+ if (lowS == null)
38911
+ lowS = true;
38912
+ msgHash = ensureBytes("msgHash", msgHash);
38913
+ validateSigVerOpts(opts);
38914
+ if (prehash)
38915
+ msgHash = ensureBytes("prehashed msgHash", hash(msgHash));
38916
+ const h1int = bits2int_modN(msgHash);
38917
+ const d = normPrivateKeyToScalar(privateKey);
38918
+ const seedArgs = [int2octets(d), int2octets(h1int)];
38919
+ if (ent != null && ent !== false) {
38920
+ const e = ent === true ? randomBytes2(Fp3.BYTES) : ent;
38921
+ seedArgs.push(ensureBytes("extraEntropy", e));
38922
+ }
38923
+ const seed = concatBytes2(...seedArgs);
38924
+ const m = h1int;
38925
+ function k2sig(kBytes) {
38926
+ const k = bits2int(kBytes);
38927
+ if (!isWithinCurveOrder(k))
38928
+ return;
38929
+ const ik = invN(k);
38930
+ const q = Point.BASE.multiply(k).toAffine();
38931
+ const r = modN(q.x);
38932
+ if (r === _0n4)
38933
+ return;
38934
+ const s = modN(ik * modN(m + r * d));
38935
+ if (s === _0n4)
38936
+ return;
38937
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n4);
38938
+ let normS = s;
38939
+ if (lowS && isBiggerThanHalfOrder(s)) {
38940
+ normS = normalizeS(s);
38941
+ recovery ^= 1;
38942
+ }
38943
+ return new Signature(r, normS, recovery);
38944
+ }
38945
+ return { seed, k2sig };
38946
+ }
38947
+ const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
38948
+ const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
38949
+ function sign(msgHash, privKey, opts = defaultSigOpts) {
38950
+ const { seed, k2sig } = prepSig(msgHash, privKey, opts);
38951
+ const C = CURVE;
38952
+ const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
38953
+ return drbg(seed, k2sig);
38954
+ }
38955
+ Point.BASE._setWindowSize(8);
38956
+ function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
38957
+ const sg = signature;
38958
+ msgHash = ensureBytes("msgHash", msgHash);
38959
+ publicKey = ensureBytes("publicKey", publicKey);
38960
+ const { lowS, prehash, format } = opts;
38961
+ validateSigVerOpts(opts);
38962
+ if ("strict" in opts)
38963
+ throw new Error("options.strict was renamed to lowS");
38964
+ if (format !== void 0 && format !== "compact" && format !== "der")
38965
+ throw new Error("format must be compact or der");
38966
+ const isHex4 = typeof sg === "string" || isBytes2(sg);
38967
+ const isObj = !isHex4 && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
38968
+ if (!isHex4 && !isObj)
38969
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
38970
+ let _sig = void 0;
38971
+ let P;
38972
+ try {
38973
+ if (isObj)
38974
+ _sig = new Signature(sg.r, sg.s);
38975
+ if (isHex4) {
38976
+ try {
38977
+ if (format !== "compact")
38978
+ _sig = Signature.fromDER(sg);
38979
+ } catch (derError) {
38980
+ if (!(derError instanceof DER.Err))
38981
+ throw derError;
38982
+ }
38983
+ if (!_sig && format !== "der")
38984
+ _sig = Signature.fromCompact(sg);
38985
+ }
38986
+ P = Point.fromHex(publicKey);
38987
+ } catch (error) {
38988
+ return false;
38989
+ }
38990
+ if (!_sig)
38991
+ return false;
38992
+ if (lowS && _sig.hasHighS())
38993
+ return false;
38994
+ if (prehash)
38995
+ msgHash = CURVE.hash(msgHash);
38996
+ const { r, s } = _sig;
38997
+ const h = bits2int_modN(msgHash);
38998
+ const is = invN(s);
38999
+ const u1 = modN(h * is);
39000
+ const u2 = modN(r * is);
39001
+ const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
39002
+ if (!R)
39003
+ return false;
39004
+ const v = modN(R.x);
39005
+ return v === r;
39006
+ }
39007
+ return {
39008
+ CURVE,
39009
+ getPublicKey,
39010
+ getSharedSecret,
39011
+ sign,
39012
+ verify,
39013
+ ProjectivePoint: Point,
39014
+ Signature,
39015
+ utils
39016
+ };
39017
+ }
38201
39018
  function SWUFpSqrtRatio(Fp3, Z) {
38202
39019
  const q = Fp3.ORDER;
38203
39020
  let l = _0n4;
@@ -38748,7 +39565,7 @@ function tower12(opts) {
38748
39565
  throw new Error("fromBytes invalid length=" + b.length);
38749
39566
  return { c0: Fp3.fromBytes(b.subarray(0, Fp3.BYTES)), c1: Fp3.fromBytes(b.subarray(Fp3.BYTES)) };
38750
39567
  },
38751
- toBytes: ({ c0, c1 }) => concatBytes(Fp3.toBytes(c0), Fp3.toBytes(c1)),
39568
+ toBytes: ({ c0, c1 }) => concatBytes2(Fp3.toBytes(c0), Fp3.toBytes(c1)),
38752
39569
  cmov: ({ c0, c1 }, { c0: r0, c1: r1 }, c) => ({
38753
39570
  c0: Fp3.cmov(c0, r0, c),
38754
39571
  c1: Fp3.cmov(c1, r1, c)
@@ -38855,7 +39672,7 @@ function tower12(opts) {
38855
39672
  c2: Fp22.fromBytes(b.subarray(2 * Fp22.BYTES))
38856
39673
  };
38857
39674
  },
38858
- toBytes: ({ c0, c1, c2 }) => concatBytes(Fp22.toBytes(c0), Fp22.toBytes(c1), Fp22.toBytes(c2)),
39675
+ toBytes: ({ c0, c1, c2 }) => concatBytes2(Fp22.toBytes(c0), Fp22.toBytes(c1), Fp22.toBytes(c2)),
38859
39676
  cmov: ({ c0, c1, c2 }, { c0: r0, c1: r1, c2: r2 }, c) => ({
38860
39677
  c0: Fp22.cmov(c0, r0, c),
38861
39678
  c1: Fp22.cmov(c1, r1, c),
@@ -38982,7 +39799,7 @@ function tower12(opts) {
38982
39799
  c1: Fp62.fromBytes(b.subarray(Fp62.BYTES))
38983
39800
  };
38984
39801
  },
38985
- toBytes: ({ c0, c1 }) => concatBytes(Fp62.toBytes(c0), Fp62.toBytes(c1)),
39802
+ toBytes: ({ c0, c1 }) => concatBytes2(Fp62.toBytes(c0), Fp62.toBytes(c1)),
38986
39803
  cmov: ({ c0, c1 }, { c0: r0, c1: r1 }, c) => ({
38987
39804
  c0: Fp62.cmov(c0, r0, c),
38988
39805
  c1: Fp62.cmov(c1, r1, c)
@@ -39344,14 +40161,14 @@ function signatureG2ToRawBytes(point) {
39344
40161
  point.assertValidity();
39345
40162
  const len = Fp.BYTES;
39346
40163
  if (point.equals(bls12_381.G2.ProjectivePoint.ZERO))
39347
- return concatBytes(COMPRESSED_ZERO, numberToBytesBE(_0n7, len));
40164
+ return concatBytes2(COMPRESSED_ZERO, numberToBytesBE(_0n7, len));
39348
40165
  const { x, y } = point.toAffine();
39349
40166
  const { re: x0, im: x1 } = Fp2.reim(x);
39350
40167
  const { re: y0, im: y1 } = Fp2.reim(y);
39351
40168
  const tmp = y1 > _0n7 ? y1 * _2n5 : y0 * _2n5;
39352
40169
  const sort = Boolean(tmp / Fp.ORDER & _1n7);
39353
40170
  const z2 = x0;
39354
- return concatBytes(setMask(numberToBytesBE(x1, len), { sort, compressed: true }), numberToBytesBE(z2, len));
40171
+ return concatBytes2(setMask(numberToBytesBE(x1, len), { sort, compressed: true }), numberToBytesBE(z2, len));
39355
40172
  }
39356
40173
  var bls12_381 = bls({
39357
40174
  // Fields
@@ -39440,10 +40257,10 @@ var bls12_381 = bls({
39440
40257
  return setMask(numberToBytesBE(x, Fp.BYTES), { compressed: true, sort });
39441
40258
  } else {
39442
40259
  if (isZero) {
39443
- const x2 = concatBytes(new Uint8Array([64]), new Uint8Array(2 * Fp.BYTES - 1));
40260
+ const x2 = concatBytes2(new Uint8Array([64]), new Uint8Array(2 * Fp.BYTES - 1));
39444
40261
  return x2;
39445
40262
  } else {
39446
- return concatBytes(numberToBytesBE(x, Fp.BYTES), numberToBytesBE(y, Fp.BYTES));
40263
+ return concatBytes2(numberToBytesBE(x, Fp.BYTES), numberToBytesBE(y, Fp.BYTES));
39447
40264
  }
39448
40265
  }
39449
40266
  },
@@ -39577,15 +40394,15 @@ var bls12_381 = bls({
39577
40394
  const { x, y } = point.toAffine();
39578
40395
  if (isCompressed) {
39579
40396
  if (isZero)
39580
- return concatBytes(COMPRESSED_ZERO, numberToBytesBE(_0n7, len));
40397
+ return concatBytes2(COMPRESSED_ZERO, numberToBytesBE(_0n7, len));
39581
40398
  const flag = Boolean(y.c1 === _0n7 ? y.c0 * _2n5 / P : y.c1 * _2n5 / P);
39582
- return concatBytes(setMask(numberToBytesBE(x.c1, len), { compressed: true, sort: flag }), numberToBytesBE(x.c0, len));
40399
+ return concatBytes2(setMask(numberToBytesBE(x.c1, len), { compressed: true, sort: flag }), numberToBytesBE(x.c0, len));
39583
40400
  } else {
39584
40401
  if (isZero)
39585
- return concatBytes(new Uint8Array([64]), new Uint8Array(4 * len - 1));
40402
+ return concatBytes2(new Uint8Array([64]), new Uint8Array(4 * len - 1));
39586
40403
  const { re: x0, im: x1 } = Fp2.reim(x);
39587
40404
  const { re: y0, im: y1 } = Fp2.reim(y);
39588
- return concatBytes(numberToBytesBE(x1, len), numberToBytesBE(x0, len), numberToBytesBE(y1, len), numberToBytesBE(y0, len));
40405
+ return concatBytes2(numberToBytesBE(x1, len), numberToBytesBE(x0, len), numberToBytesBE(y1, len), numberToBytesBE(y0, len));
39589
40406
  }
39590
40407
  },
39591
40408
  Signature: {
@@ -42061,16 +42878,59 @@ var airAccountFactoryActions = (address) => (client) => ({
42061
42878
  }
42062
42879
  }
42063
42880
  });
42064
-
42065
- // ../core/src/actions/airAccountExtension.ts
42881
+ var GUARDIAN_REMOVAL_NONCE_SLOT = 15n;
42882
+ var TIER_LIMIT_NONCE_SLOT = 16n;
42883
+ var RECOVERY_NONCE_SLOT = 38n;
42884
+ var GUARDIAN_ADDITION_NONCE_SLOT = 39n;
42885
+ var MAX_GUARDIAN_SLOT = 2;
42066
42886
  var V7_ABI = AAStarAirAccountV7ABI;
42067
42887
  var EXT_ABI = AirAccountExtensionABI;
42068
- var BATCH2 = (fn) => {
42069
- throw new AAStarError(
42070
- "E4001" /* NOT_IMPLEMENTED */,
42071
- `${fn} is part of the Batch 2 / P-256 (WebAuthn) guardian feature and is not yet wired into the SDK. The v0.20.0 contract supports it (AirAccountExtension, via the account fallback), but the SDK assertion/payload encoders land in Batch 2.`
42072
- );
42073
- };
42888
+ function feeOverrides(maxFeePerGas, maxPriorityFeePerGas) {
42889
+ return {
42890
+ ...maxFeePerGas !== void 0 ? { maxFeePerGas } : {},
42891
+ ...maxPriorityFeePerGas !== void 0 ? { maxPriorityFeePerGas } : {}
42892
+ };
42893
+ }
42894
+ function validateMixedSigs(signerIdxs, sigs) {
42895
+ validateRequired(signerIdxs, "signerIdxs");
42896
+ validateRequired(sigs, "sigs");
42897
+ if (signerIdxs.length !== sigs.length) {
42898
+ throw new AAStarError(
42899
+ "E1003" /* INVALID_PARAMETER */,
42900
+ `signerIdxs (${signerIdxs.length}) and sigs (${sigs.length}) must have equal length`
42901
+ );
42902
+ }
42903
+ if (signerIdxs.length < 2) {
42904
+ throw new AAStarError(
42905
+ "E1003" /* INVALID_PARAMETER */,
42906
+ `mixed-sig guardian operations require at least RECOVERY_THRESHOLD (2) signatures, got ${signerIdxs.length}`
42907
+ );
42908
+ }
42909
+ const seen = /* @__PURE__ */ new Set();
42910
+ for (const idx of signerIdxs) {
42911
+ if (!Number.isInteger(idx) || idx < 0 || idx > MAX_GUARDIAN_SLOT) {
42912
+ throw new AAStarError(
42913
+ "E1003" /* INVALID_PARAMETER */,
42914
+ `signerIdxs must be integers in 0..${MAX_GUARDIAN_SLOT} (max ${MAX_GUARDIAN_SLOT + 1} guardian slots), got ${idx}`
42915
+ );
42916
+ }
42917
+ if (seen.has(idx)) {
42918
+ throw new AAStarError(
42919
+ "E1003" /* INVALID_PARAMETER */,
42920
+ `signerIdxs must be unique (the contract rejects a duplicate guardian slot via DuplicateGuardianSig), got repeated ${idx}`
42921
+ );
42922
+ }
42923
+ seen.add(idx);
42924
+ }
42925
+ }
42926
+ async function readNonceSlot(client, address, slot, fn) {
42927
+ try {
42928
+ const raw = await client.getStorageAt({ address, slot: numberToHex(slot, { size: 32 }) });
42929
+ return raw && raw !== "0x" ? BigInt(raw) : 0n;
42930
+ } catch (error) {
42931
+ throw AAStarError.fromViemError(error, fn);
42932
+ }
42933
+ }
42074
42934
  var airAccountExtensionActions = (address) => (client) => ({
42075
42935
  // ── Views ─────────────────────────────────────────────────────────────────
42076
42936
  async getRecoveryNonce() {
@@ -42099,34 +42959,222 @@ var airAccountExtensionActions = (address) => (client) => ({
42099
42959
  throw AAStarError.fromViemError(error, "getGuardianP256Key");
42100
42960
  }
42101
42961
  },
42102
- // ── Batch 2 stubs ──────────────────────────────────────────────────────────
42103
- // Each references its ABI functionName so the doc-coverage gate counts the
42104
- // wrapper while the real encoder is deferred to Batch 2.
42105
- async addP256Guardian() {
42106
- return BATCH2("addP256Guardian");
42962
+ // Internal-slot nonce reads (no public getter on-chain). Cross-validated on-chain against
42963
+ // `getRecoveryNonce()` (slot 38) in tests/regression/onchain-evidence/p256-guardian-e2e.ts.
42964
+ getGuardianAdditionNonce() {
42965
+ return readNonceSlot(client, address, GUARDIAN_ADDITION_NONCE_SLOT, "getGuardianAdditionNonce");
42107
42966
  },
42108
- async addP256GuardianWithMixedSigs() {
42109
- return BATCH2("addP256GuardianWithMixedSigs");
42967
+ getGuardianRemovalNonce() {
42968
+ return readNonceSlot(client, address, GUARDIAN_REMOVAL_NONCE_SLOT, "getGuardianRemovalNonce");
42110
42969
  },
42111
- async addGuardianWithMixedSigs() {
42112
- return BATCH2("addGuardianWithMixedSigs");
42970
+ getTierLimitNonce() {
42971
+ return readNonceSlot(client, address, TIER_LIMIT_NONCE_SLOT, "getTierLimitNonce");
42113
42972
  },
42114
- async proposeRecoveryWithSig() {
42115
- return BATCH2("proposeRecoveryWithSig");
42973
+ // ── P-256 / WebAuthn guardian writes ───────────────────────────────────────
42974
+ // Each routes to AirAccountExtension via the account's fallback → delegatecall,
42975
+ // so `address` (the account) is the write target and `functionName` is the EXT fn.
42976
+ async addP256Guardian({ x, y, account, maxFeePerGas, maxPriorityFeePerGas }) {
42977
+ try {
42978
+ validateRequired(x, "x");
42979
+ validateRequired(y, "y");
42980
+ return await client.writeContract({
42981
+ address,
42982
+ abi: EXT_ABI,
42983
+ functionName: "addP256Guardian",
42984
+ args: [x, y],
42985
+ account,
42986
+ chain: client.chain,
42987
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
42988
+ });
42989
+ } catch (error) {
42990
+ throw AAStarError.fromViemError(error, "addP256Guardian");
42991
+ }
42116
42992
  },
42117
- async approveRecoveryWithSig() {
42118
- return BATCH2("approveRecoveryWithSig");
42993
+ async addP256GuardianWithMixedSigs({ x, y, signerIdxs, sigs, account, maxFeePerGas, maxPriorityFeePerGas }) {
42994
+ try {
42995
+ validateRequired(x, "x");
42996
+ validateRequired(y, "y");
42997
+ validateMixedSigs(signerIdxs, sigs);
42998
+ return await client.writeContract({
42999
+ address,
43000
+ abi: EXT_ABI,
43001
+ functionName: "addP256GuardianWithMixedSigs",
43002
+ args: [x, y, signerIdxs, sigs],
43003
+ account,
43004
+ chain: client.chain,
43005
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43006
+ });
43007
+ } catch (error) {
43008
+ throw AAStarError.fromViemError(error, "addP256GuardianWithMixedSigs");
43009
+ }
42119
43010
  },
42120
- async cancelRecoveryWithSig() {
42121
- return BATCH2("cancelRecoveryWithSig");
43011
+ async addGuardianWithMixedSigs({ guardian, signerIdxs, sigs, account, maxFeePerGas, maxPriorityFeePerGas }) {
43012
+ try {
43013
+ validateRequired(guardian, "guardian");
43014
+ validateMixedSigs(signerIdxs, sigs);
43015
+ return await client.writeContract({
43016
+ address,
43017
+ abi: EXT_ABI,
43018
+ functionName: "addGuardianWithMixedSigs",
43019
+ args: [guardian, signerIdxs, sigs],
43020
+ account,
43021
+ chain: client.chain,
43022
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43023
+ });
43024
+ } catch (error) {
43025
+ throw AAStarError.fromViemError(error, "addGuardianWithMixedSigs");
43026
+ }
42122
43027
  },
42123
- async removeGuardianWithMixedSigs() {
42124
- return BATCH2("removeGuardianWithMixedSigs");
43028
+ async proposeRecoveryWithSig({ newOwner, gIdx, sig, account, maxFeePerGas, maxPriorityFeePerGas }) {
43029
+ try {
43030
+ validateRequired(newOwner, "newOwner");
43031
+ validateRequired(gIdx, "gIdx");
43032
+ validateRequired(sig, "sig");
43033
+ return await client.writeContract({
43034
+ address,
43035
+ abi: EXT_ABI,
43036
+ functionName: "proposeRecoveryWithSig",
43037
+ args: [newOwner, gIdx, sig],
43038
+ account,
43039
+ chain: client.chain,
43040
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43041
+ });
43042
+ } catch (error) {
43043
+ throw AAStarError.fromViemError(error, "proposeRecoveryWithSig");
43044
+ }
42125
43045
  },
42126
- async modifyTierLimitsWithMixedGuardians() {
42127
- return BATCH2("modifyTierLimitsWithMixedGuardians");
43046
+ async approveRecoveryWithSig({ gIdx, sig, account, maxFeePerGas, maxPriorityFeePerGas }) {
43047
+ try {
43048
+ validateRequired(gIdx, "gIdx");
43049
+ validateRequired(sig, "sig");
43050
+ return await client.writeContract({
43051
+ address,
43052
+ abi: EXT_ABI,
43053
+ functionName: "approveRecoveryWithSig",
43054
+ args: [gIdx, sig],
43055
+ account,
43056
+ chain: client.chain,
43057
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43058
+ });
43059
+ } catch (error) {
43060
+ throw AAStarError.fromViemError(error, "approveRecoveryWithSig");
43061
+ }
43062
+ },
43063
+ async cancelRecoveryWithSig({ gIdx, sig, account, maxFeePerGas, maxPriorityFeePerGas }) {
43064
+ try {
43065
+ validateRequired(gIdx, "gIdx");
43066
+ validateRequired(sig, "sig");
43067
+ return await client.writeContract({
43068
+ address,
43069
+ abi: EXT_ABI,
43070
+ functionName: "cancelRecoveryWithSig",
43071
+ args: [gIdx, sig],
43072
+ account,
43073
+ chain: client.chain,
43074
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43075
+ });
43076
+ } catch (error) {
43077
+ throw AAStarError.fromViemError(error, "cancelRecoveryWithSig");
43078
+ }
43079
+ },
43080
+ async removeGuardianWithMixedSigs({ index, signerIdxs, sigs, account, maxFeePerGas, maxPriorityFeePerGas }) {
43081
+ try {
43082
+ validateRequired(index, "index");
43083
+ validateMixedSigs(signerIdxs, sigs);
43084
+ return await client.writeContract({
43085
+ address,
43086
+ abi: EXT_ABI,
43087
+ functionName: "removeGuardianWithMixedSigs",
43088
+ args: [index, signerIdxs, sigs],
43089
+ account,
43090
+ chain: client.chain,
43091
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43092
+ });
43093
+ } catch (error) {
43094
+ throw AAStarError.fromViemError(error, "removeGuardianWithMixedSigs");
43095
+ }
43096
+ },
43097
+ async modifyTierLimitsWithMixedGuardians({ tier1, tier2, deadline, signerIdxs, sigs, account, maxFeePerGas, maxPriorityFeePerGas }) {
43098
+ try {
43099
+ validateRequired(tier1, "tier1");
43100
+ validateRequired(tier2, "tier2");
43101
+ validateRequired(deadline, "deadline");
43102
+ validateMixedSigs(signerIdxs, sigs);
43103
+ return await client.writeContract({
43104
+ address,
43105
+ abi: EXT_ABI,
43106
+ functionName: "modifyTierLimitsWithMixedGuardians",
43107
+ args: [tier1, tier2, deadline, signerIdxs, sigs],
43108
+ account,
43109
+ chain: client.chain,
43110
+ ...feeOverrides(maxFeePerGas, maxPriorityFeePerGas)
43111
+ });
43112
+ } catch (error) {
43113
+ throw AAStarError.fromViemError(error, "modifyTierLimitsWithMixedGuardians");
43114
+ }
42128
43115
  }
42129
43116
  });
43117
+ var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
43118
+ var ZERO32 = `0x${"00".repeat(32)}`;
43119
+ var P256_GUARDIAN_SENTINEL = "0x0000000000000000000000000000000000007026";
43120
+ var ALG_ECDSA = 2;
43121
+ var ALG_PASSKEY_P256 = 1;
43122
+ function isZero32(v) {
43123
+ return /^0x0*$/.test(v);
43124
+ }
43125
+ function buildInitConfig(params) {
43126
+ const specs = params.guardians ?? [];
43127
+ if (specs.length > 3) {
43128
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `at most 3 guardians are supported, got ${specs.length}`);
43129
+ }
43130
+ if (params.dailyLimit <= 0n) {
43131
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, "dailyLimit must be > 0 to enable the on-chain GUARD");
43132
+ }
43133
+ const guardians = [ZERO_ADDRESS2, ZERO_ADDRESS2, ZERO_ADDRESS2];
43134
+ const guardianP256X = [ZERO32, ZERO32, ZERO32];
43135
+ const guardianP256Y = [ZERO32, ZERO32, ZERO32];
43136
+ let hasP256 = false;
43137
+ specs.forEach((spec, i) => {
43138
+ const hasEcdsa = spec.ecdsa !== void 0 && spec.ecdsa !== ZERO_ADDRESS2;
43139
+ const hasP256Key = spec.p256 !== void 0;
43140
+ if (hasEcdsa && hasP256Key) {
43141
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `guardian[${i}]: supply exactly one of { ecdsa, p256 }, not both`);
43142
+ }
43143
+ if (!hasEcdsa && !hasP256Key) {
43144
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `guardian[${i}]: supply one of { ecdsa, p256 }`);
43145
+ }
43146
+ if (hasP256Key) {
43147
+ const { x, y } = spec.p256;
43148
+ if (!isHex(x) || size(x) !== 32 || !isHex(y) || size(y) !== 32) {
43149
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `guardian[${i}].p256: x and y must each be 32-byte hex values`);
43150
+ }
43151
+ if (isZero32(x) || isZero32(y)) {
43152
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `guardian[${i}].p256: x and y must be non-zero (all-or-nothing per the contract)`);
43153
+ }
43154
+ guardians[i] = ZERO_ADDRESS2;
43155
+ guardianP256X[i] = x;
43156
+ guardianP256Y[i] = y;
43157
+ hasP256 = true;
43158
+ } else {
43159
+ const ecdsa = spec.ecdsa;
43160
+ if (isAddressEqual(ecdsa, P256_GUARDIAN_SENTINEL)) {
43161
+ throw new AAStarError("E1003" /* INVALID_PARAMETER */, `guardian[${i}].ecdsa: the P-256 sentinel ${P256_GUARDIAN_SENTINEL} is not a valid ECDSA guardian`);
43162
+ }
43163
+ guardians[i] = ecdsa;
43164
+ }
43165
+ });
43166
+ const approvedAlgIds = params.approvedAlgIds ?? (hasP256 ? [ALG_ECDSA, ALG_PASSKEY_P256] : [ALG_ECDSA]);
43167
+ return {
43168
+ guardians,
43169
+ guardianP256X,
43170
+ guardianP256Y,
43171
+ dailyLimit: params.dailyLimit,
43172
+ approvedAlgIds,
43173
+ minDailyLimit: params.minDailyLimit ?? 0n,
43174
+ initialTokens: params.initialTokens ?? [],
43175
+ initialTokenConfigs: params.initialTokenConfigs ?? []
43176
+ };
43177
+ }
42130
43178
 
42131
43179
  // ../core/src/actions/agentRegistry.ts
42132
43180
  var ABI4 = AgentRegistryABI;
@@ -42561,28 +43609,28 @@ function encodeDVTVerifierProof(nodeIds, blsSig) {
42561
43609
  const sig = encodeG2Point(blsSig);
42562
43610
  return concat([...ids, sig]);
42563
43611
  }
42564
- function normalizeP256(p256) {
42565
- if (typeof p256 === "string") {
42566
- if (!isHex(p256) || size(p256) !== 64) {
43612
+ function normalizeP256(p2562) {
43613
+ if (typeof p2562 === "string") {
43614
+ if (!isHex(p2562) || size(p2562) !== 64) {
42567
43615
  throw new Error("encodeDVTAccountSignature: p256 bytes form must be a 64-byte (r\u2016s) hex value");
42568
43616
  }
42569
- return p256;
43617
+ return p2562;
42570
43618
  }
42571
- if (!isHex(p256.r) || size(p256.r) !== 32) {
43619
+ if (!isHex(p2562.r) || size(p2562.r) !== 32) {
42572
43620
  throw new Error("encodeDVTAccountSignature: p256.r must be a 32-byte hex value");
42573
43621
  }
42574
- if (!isHex(p256.s) || size(p256.s) !== 32) {
43622
+ if (!isHex(p2562.s) || size(p2562.s) !== 32) {
42575
43623
  throw new Error("encodeDVTAccountSignature: p256.s must be a 32-byte hex value");
42576
43624
  }
42577
- return concat([p256.r, p256.s]);
43625
+ return concat([p2562.r, p2562.s]);
42578
43626
  }
42579
43627
  function encodeDVTAccountSignature(params) {
42580
- const { tier, p256, nodeIds, blsSig, guardianSig } = params;
43628
+ const { tier, p256: p2562, nodeIds, blsSig, guardianSig } = params;
42581
43629
  if (tier !== DVT_TIER_T2 && tier !== DVT_TIER_T3) {
42582
43630
  throw new Error(`encodeDVTAccountSignature: tier must be 0x04 (T2) or 0x05 (T3), got ${tier}`);
42583
43631
  }
42584
43632
  const tierByte = numberToHex(tier, { size: 1 });
42585
- const p256Bytes = normalizeP256(p256);
43633
+ const p256Bytes = normalizeP256(p2562);
42586
43634
  const ids = validateNodeIds(nodeIds, "encodeDVTAccountSignature");
42587
43635
  const nodeIdsLength = numberToHex(ids.length, { size: 32 });
42588
43636
  const sig = encodeG2Point(blsSig);
@@ -42627,6 +43675,402 @@ function hashToFieldU0U1(message) {
42627
43675
  u1c1b: u1c1.b
42628
43676
  };
42629
43677
  }
43678
+
43679
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
43680
+ var HMAC = class extends Hash {
43681
+ constructor(hash, _key) {
43682
+ super();
43683
+ this.finished = false;
43684
+ this.destroyed = false;
43685
+ ahash(hash);
43686
+ const key = toBytes2(_key);
43687
+ this.iHash = hash.create();
43688
+ if (typeof this.iHash.update !== "function")
43689
+ throw new Error("Expected instance of class which extends utils.Hash");
43690
+ this.blockLen = this.iHash.blockLen;
43691
+ this.outputLen = this.iHash.outputLen;
43692
+ const blockLen = this.blockLen;
43693
+ const pad2 = new Uint8Array(blockLen);
43694
+ pad2.set(key.length > blockLen ? hash.create().update(key).digest() : key);
43695
+ for (let i = 0; i < pad2.length; i++)
43696
+ pad2[i] ^= 54;
43697
+ this.iHash.update(pad2);
43698
+ this.oHash = hash.create();
43699
+ for (let i = 0; i < pad2.length; i++)
43700
+ pad2[i] ^= 54 ^ 92;
43701
+ this.oHash.update(pad2);
43702
+ clean(pad2);
43703
+ }
43704
+ update(buf) {
43705
+ aexists(this);
43706
+ this.iHash.update(buf);
43707
+ return this;
43708
+ }
43709
+ digestInto(out) {
43710
+ aexists(this);
43711
+ abytes(out, this.outputLen);
43712
+ this.finished = true;
43713
+ this.iHash.digestInto(out);
43714
+ this.oHash.update(out);
43715
+ this.oHash.digestInto(out);
43716
+ this.destroy();
43717
+ }
43718
+ digest() {
43719
+ const out = new Uint8Array(this.oHash.outputLen);
43720
+ this.digestInto(out);
43721
+ return out;
43722
+ }
43723
+ _cloneInto(to) {
43724
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
43725
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
43726
+ to = to;
43727
+ to.finished = finished;
43728
+ to.destroyed = destroyed;
43729
+ to.blockLen = blockLen;
43730
+ to.outputLen = outputLen;
43731
+ to.oHash = oHash._cloneInto(to.oHash);
43732
+ to.iHash = iHash._cloneInto(to.iHash);
43733
+ return to;
43734
+ }
43735
+ clone() {
43736
+ return this._cloneInto();
43737
+ }
43738
+ destroy() {
43739
+ this.destroyed = true;
43740
+ this.oHash.destroy();
43741
+ this.iHash.destroy();
43742
+ }
43743
+ };
43744
+ var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
43745
+ hmac.create = (hash, key) => new HMAC(hash, key);
43746
+
43747
+ // ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/_shortw_utils.js
43748
+ function getHash(hash) {
43749
+ return {
43750
+ hash,
43751
+ hmac: (key, ...msgs) => hmac(hash, key, concatBytes(...msgs)),
43752
+ randomBytes
43753
+ };
43754
+ }
43755
+ function createCurve(curveDef, defHash) {
43756
+ const create = (hash) => weierstrass({ ...curveDef, ...getHash(hash) });
43757
+ return { ...create(defHash), create };
43758
+ }
43759
+
43760
+ // ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/nist.js
43761
+ var Fp256 = Field(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"));
43762
+ var p256_a = Fp256.create(BigInt("-3"));
43763
+ var p256_b = BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
43764
+ var p256 = createCurve({
43765
+ a: p256_a,
43766
+ b: p256_b,
43767
+ Fp: Fp256,
43768
+ n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
43769
+ Gx: BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),
43770
+ Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
43771
+ h: BigInt(1),
43772
+ lowS: false
43773
+ }, sha256);
43774
+ var Fp384 = Field(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"));
43775
+ var p384_a = Fp384.create(BigInt("-3"));
43776
+ var p384_b = BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");
43777
+ createCurve({
43778
+ a: p384_a,
43779
+ b: p384_b,
43780
+ Fp: Fp384,
43781
+ n: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),
43782
+ Gx: BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),
43783
+ Gy: BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),
43784
+ h: BigInt(1),
43785
+ lowS: false
43786
+ }, sha384);
43787
+ var Fp521 = Field(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
43788
+ var p521_a = Fp521.create(BigInt("-3"));
43789
+ var p521_b = BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");
43790
+ createCurve({
43791
+ a: p521_a,
43792
+ b: p521_b,
43793
+ Fp: Fp521,
43794
+ n: BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),
43795
+ Gx: BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),
43796
+ Gy: BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),
43797
+ h: BigInt(1),
43798
+ lowS: false,
43799
+ allowedPrivateKeyLengths: [130, 131, 132]
43800
+ // P521 keys are variable-length. Normalize to 132b
43801
+ }, sha512);
43802
+
43803
+ // ../core/src/crypto/p256Guardian.ts
43804
+ var GUARDIAN_SIG_VERSION = 4;
43805
+ var P256_GUARDIAN_DOMAIN = "P256_GUARDIAN";
43806
+ var WEBAUTHN_GET_CHALLENGE_PREFIX = '{"type":"webauthn.get","challenge":"';
43807
+ var PREFIX_LEN = 36;
43808
+ var CHALLENGE_B64_LEN = 43;
43809
+ var P256_GUARDIAN_SENTINEL2 = "0x0000000000000000000000000000000000007026";
43810
+ var SECP256R1_N = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n;
43811
+ var SECP256R1_N_OVER_2 = SECP256R1_N >> 1n;
43812
+ var B64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
43813
+ function base64UrlEncode(bytes) {
43814
+ let out = "";
43815
+ let i = 0;
43816
+ for (; i + 3 <= bytes.length; i += 3) {
43817
+ const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
43818
+ out += B64URL_ALPHABET[n >> 18 & 63] + B64URL_ALPHABET[n >> 12 & 63] + B64URL_ALPHABET[n >> 6 & 63] + B64URL_ALPHABET[n & 63];
43819
+ }
43820
+ const rem = bytes.length - i;
43821
+ if (rem === 1) {
43822
+ const n = bytes[i] << 16;
43823
+ out += B64URL_ALPHABET[n >> 18 & 63] + B64URL_ALPHABET[n >> 12 & 63];
43824
+ } else if (rem === 2) {
43825
+ const n = bytes[i] << 16 | bytes[i + 1] << 8;
43826
+ out += B64URL_ALPHABET[n >> 18 & 63] + B64URL_ALPHABET[n >> 12 & 63] + B64URL_ALPHABET[n >> 6 & 63];
43827
+ }
43828
+ return out;
43829
+ }
43830
+ function buildP256GuardianChallenge(params) {
43831
+ const version = params.version ?? GUARDIAN_SIG_VERSION;
43832
+ return keccak256(
43833
+ encodeAbiParameters(
43834
+ [
43835
+ { type: "uint8" },
43836
+ { type: "uint256" },
43837
+ { type: "address" },
43838
+ { type: "string" },
43839
+ { type: "string" },
43840
+ { type: "bytes" }
43841
+ ],
43842
+ [version, BigInt(params.chainId), params.account, P256_GUARDIAN_DOMAIN, params.opLabel, params.opData]
43843
+ )
43844
+ );
43845
+ }
43846
+ function opDataRecovery(nonce, newOwner) {
43847
+ return encodeAbiParameters([{ type: "uint256" }, { type: "address" }], [nonce, newOwner]);
43848
+ }
43849
+ function opDataAddP256Guardian(nonce, x, y) {
43850
+ return encodeAbiParameters(
43851
+ [{ type: "uint256" }, { type: "bytes32" }, { type: "bytes32" }],
43852
+ [nonce, toBytes32(x, "x"), toBytes32(y, "y")]
43853
+ );
43854
+ }
43855
+ function opDataAddGuardian(nonce, guardian) {
43856
+ return encodeAbiParameters([{ type: "uint256" }, { type: "address" }], [nonce, guardian]);
43857
+ }
43858
+ function opDataRemoveGuardian(nonce, index, guardianToRemove, p256X, p256Y) {
43859
+ return encodeAbiParameters(
43860
+ [{ type: "uint256" }, { type: "uint8" }, { type: "address" }, { type: "bytes32" }, { type: "bytes32" }],
43861
+ [nonce, index, guardianToRemove, toBytes32(p256X, "p256X"), toBytes32(p256Y, "p256Y")]
43862
+ );
43863
+ }
43864
+ function opDataModifyTierLimits(nonce, tier1, tier2, deadline) {
43865
+ return encodeAbiParameters(
43866
+ [{ type: "uint256" }, { type: "uint256" }, { type: "uint256" }, { type: "uint256" }],
43867
+ [nonce, tier1, tier2, deadline]
43868
+ );
43869
+ }
43870
+ function buildProposeRecoveryChallenge(p) {
43871
+ return buildP256GuardianChallenge({ ...p, opLabel: "PROPOSE_RECOVERY", opData: opDataRecovery(p.nonce, p.newOwner) });
43872
+ }
43873
+ function buildApproveRecoveryChallenge(p) {
43874
+ return buildP256GuardianChallenge({ ...p, opLabel: "APPROVE_RECOVERY", opData: opDataRecovery(p.nonce, p.newOwner) });
43875
+ }
43876
+ function buildCancelRecoveryChallenge(p) {
43877
+ return buildP256GuardianChallenge({ ...p, opLabel: "CANCEL_RECOVERY", opData: opDataRecovery(p.nonce, p.newOwner) });
43878
+ }
43879
+ function buildAddP256GuardianChallenge(p) {
43880
+ return buildP256GuardianChallenge({ ...p, opLabel: "ADD_P256_GUARDIAN", opData: opDataAddP256Guardian(p.nonce, p.x, p.y) });
43881
+ }
43882
+ function buildAddGuardianChallenge(p) {
43883
+ return buildP256GuardianChallenge({ ...p, opLabel: "ADD_GUARDIAN", opData: opDataAddGuardian(p.nonce, p.guardian) });
43884
+ }
43885
+ function buildRemoveGuardianChallenge(p) {
43886
+ return buildP256GuardianChallenge({
43887
+ ...p,
43888
+ opLabel: "REMOVE_GUARDIAN",
43889
+ opData: opDataRemoveGuardian(p.nonce, p.index, p.guardianToRemove, p.p256X, p.p256Y)
43890
+ });
43891
+ }
43892
+ function buildModifyTierLimitsChallenge(p) {
43893
+ return buildP256GuardianChallenge({
43894
+ ...p,
43895
+ opLabel: "MODIFY_TIER_LIMITS",
43896
+ opData: opDataModifyTierLimits(p.nonce, p.tier1, p.tier2, p.deadline)
43897
+ });
43898
+ }
43899
+ function scalarToBigInt(v, name) {
43900
+ if (typeof v === "bigint") return v;
43901
+ if (v instanceof Uint8Array) return BigInt(toHex(v));
43902
+ if (isHex(v)) return BigInt(v);
43903
+ throw new Error(`encodeWebAuthnAssertion: ${name} must be a hex string, Uint8Array, or bigint`);
43904
+ }
43905
+ function toBytes32(v, name) {
43906
+ if (!isHex(v)) throw new Error(`${name} must be a 0x-hex value`);
43907
+ if (size(v) > 32) throw new Error(`${name} must be at most 32 bytes`);
43908
+ return pad(v, { size: 32 });
43909
+ }
43910
+ function asBytes(v, name) {
43911
+ if (v instanceof Uint8Array) return v;
43912
+ if (typeof v === "string" && isHex(v)) return toBytes(v);
43913
+ if (typeof v === "string") return new TextEncoder().encode(v);
43914
+ throw new Error(`${name} must be hex, bytes, or a string`);
43915
+ }
43916
+ function encodeWebAuthnAssertion(params) {
43917
+ const authData = asBytes(params.authenticatorData, "authenticatorData");
43918
+ if (authData.length < 37) {
43919
+ throw new Error(`encodeWebAuthnAssertion: authenticatorData must be >= 37 bytes, got ${authData.length}`);
43920
+ }
43921
+ if ((authData[32] & 1) === 0) {
43922
+ throw new Error("encodeWebAuthnAssertion: authenticatorData UP (User Present) flag (byte 32, bit 0) must be set");
43923
+ }
43924
+ const cdj = asBytes(params.clientDataJSON, "clientDataJSON");
43925
+ const prefixBytes = new TextEncoder().encode(WEBAUTHN_GET_CHALLENGE_PREFIX);
43926
+ if (cdj.length < PREFIX_LEN + CHALLENGE_B64_LEN + 1) {
43927
+ throw new Error(
43928
+ `encodeWebAuthnAssertion: clientDataJSON too short (${cdj.length} bytes) \u2014 expected at least prefix(${PREFIX_LEN}) + base64url(challenge)(${CHALLENGE_B64_LEN}) + closing quote`
43929
+ );
43930
+ }
43931
+ for (let i = 0; i < PREFIX_LEN; i++) {
43932
+ if (cdj[i] !== prefixBytes[i]) {
43933
+ throw new Error(
43934
+ `encodeWebAuthnAssertion: clientDataJSON must start with the exact prefix ${JSON.stringify(WEBAUTHN_GET_CHALLENGE_PREFIX)} (the contract rejects any other prefix)`
43935
+ );
43936
+ }
43937
+ }
43938
+ if (cdj[PREFIX_LEN + CHALLENGE_B64_LEN] !== 34) {
43939
+ throw new Error(
43940
+ "encodeWebAuthnAssertion: the base64url(challenge) slot is not exactly 43 chars (no closing quote at the expected position) \u2014 clientDataJSON is malformed for the contract"
43941
+ );
43942
+ }
43943
+ const prefix = cdj.slice(0, PREFIX_LEN);
43944
+ const suffix = cdj.slice(PREFIX_LEN + CHALLENGE_B64_LEN);
43945
+ const r = scalarToBigInt(params.r, "r");
43946
+ let s = scalarToBigInt(params.s, "s");
43947
+ if (s > SECP256R1_N_OVER_2) s = SECP256R1_N - s;
43948
+ return encodeAbiParameters(
43949
+ [{ type: "bytes" }, { type: "bytes" }, { type: "bytes" }, { type: "bytes32" }, { type: "bytes32" }],
43950
+ [toHex(authData), toHex(prefix), toHex(suffix), numberToHex(r, { size: 32 }), numberToHex(s, { size: 32 })]
43951
+ );
43952
+ }
43953
+ function decodeWebAuthnAssertion(sig) {
43954
+ const [authenticatorData, clientDataJSONPrefix, clientDataJSONSuffix, r, s] = decodeAbiParameters(
43955
+ [{ type: "bytes" }, { type: "bytes" }, { type: "bytes" }, { type: "bytes32" }, { type: "bytes32" }],
43956
+ sig
43957
+ );
43958
+ return { authenticatorData, clientDataJSONPrefix, clientDataJSONSuffix, r, s };
43959
+ }
43960
+ function decompressP256Point(compressed) {
43961
+ const lib = p256;
43962
+ const Point = lib.Point ?? lib.ProjectivePoint;
43963
+ if (!Point) throw new Error("coseToP256XY: @noble/curves p256 point class unavailable for decompression");
43964
+ const pt = Point.fromHex(compressed);
43965
+ const uncompressed = pt.toBytes ? pt.toBytes(false) : pt.toRawBytes(false);
43966
+ return uncompressed;
43967
+ }
43968
+ function coseToP256XY(cosePublicKey) {
43969
+ const bytes = cosePublicKey instanceof Uint8Array ? cosePublicKey : toBytes(cosePublicKey);
43970
+ if (bytes.length === 65 && bytes[0] === 4) {
43971
+ return { x: toHex(bytes.slice(1, 33)), y: toHex(bytes.slice(33, 65)) };
43972
+ }
43973
+ if (bytes.length === 33 && (bytes[0] === 2 || bytes[0] === 3)) {
43974
+ const uncompressed = decompressP256Point(bytes);
43975
+ return { x: toHex(uncompressed.slice(1, 33)), y: toHex(uncompressed.slice(33, 65)) };
43976
+ }
43977
+ const map = decodeCoseMap(bytes);
43978
+ const kty = map.get(1);
43979
+ const crv = map.get(-1);
43980
+ if (kty !== 2n) {
43981
+ throw new Error(`coseToP256XY: COSE key type (label 1) must be present and 2 (EC2), got ${String(kty)}`);
43982
+ }
43983
+ if (crv !== 1n) {
43984
+ throw new Error(`coseToP256XY: COSE curve (label -1) must be present and 1 (P-256), got ${String(crv)}`);
43985
+ }
43986
+ const x = map.get(-2);
43987
+ const y = map.get(-3);
43988
+ if (!(x instanceof Uint8Array) || !(y instanceof Uint8Array)) {
43989
+ throw new Error("coseToP256XY: COSE key missing the -2 (x) / -3 (y) coordinate byte strings");
43990
+ }
43991
+ if (x.length !== 32 || y.length !== 32) {
43992
+ throw new Error(`coseToP256XY: P-256 coordinates must be 32 bytes (got x=${x.length}, y=${y.length})`);
43993
+ }
43994
+ return { x: toHex(x), y: toHex(y) };
43995
+ }
43996
+ function decodeCoseMap(buf) {
43997
+ let pos = 0;
43998
+ function readArgument(ai) {
43999
+ if (ai < 24) return ai;
44000
+ if (ai === 24) return buf[pos++];
44001
+ if (ai === 25) {
44002
+ const v = buf[pos] << 8 | buf[pos + 1];
44003
+ pos += 2;
44004
+ return v;
44005
+ }
44006
+ if (ai === 26) {
44007
+ const v = buf[pos] * 16777216 + (buf[pos + 1] << 16) + (buf[pos + 2] << 8) + buf[pos + 3];
44008
+ pos += 4;
44009
+ return v;
44010
+ }
44011
+ throw new Error("decodeCoseMap: unsupported CBOR argument size (64-bit values not supported for COSE keys)");
44012
+ }
44013
+ function readItem() {
44014
+ const ib2 = buf[pos++];
44015
+ const major = ib2 >> 5;
44016
+ const ai = ib2 & 31;
44017
+ switch (major) {
44018
+ case 0:
44019
+ return BigInt(readArgument(ai));
44020
+ case 1:
44021
+ return BigInt(-1 - readArgument(ai));
44022
+ case 2: {
44023
+ const len = readArgument(ai);
44024
+ const out = buf.slice(pos, pos + len);
44025
+ pos += len;
44026
+ return out;
44027
+ }
44028
+ default:
44029
+ throw new Error(`decodeCoseMap: unsupported CBOR major type ${major} in COSE key`);
44030
+ }
44031
+ }
44032
+ const ib = buf[pos++];
44033
+ if (ib >> 5 !== 5) throw new Error("coseToP256XY: input is not a CBOR map (COSE_Key)");
44034
+ const n = readArgument(ib & 31);
44035
+ const map = /* @__PURE__ */ new Map();
44036
+ for (let i = 0; i < n; i++) {
44037
+ const key = readItem();
44038
+ const val = readItem();
44039
+ if (typeof key === "bigint") map.set(Number(key), val);
44040
+ }
44041
+ return map;
44042
+ }
44043
+ function signP256GuardianAssertion(params) {
44044
+ const priv = params.privateKey instanceof Uint8Array ? params.privateKey : toBytes(params.privateKey);
44045
+ const rpId = params.rpId ?? "airaccount.example";
44046
+ const origin = params.origin ?? "https://airaccount.example";
44047
+ const flags = params.flags ?? 5;
44048
+ const signCount = params.signCount ?? 0;
44049
+ const challengeBytes = toBytes(params.challenge);
44050
+ if (challengeBytes.length !== 32) throw new Error("signP256GuardianAssertion: challenge must be 32 bytes");
44051
+ const challengeB64 = base64UrlEncode(challengeBytes);
44052
+ const clientDataJSONStr = `${WEBAUTHN_GET_CHALLENGE_PREFIX}${challengeB64}","origin":"${origin}","crossOrigin":false}`;
44053
+ const clientDataJSON = new TextEncoder().encode(clientDataJSONStr);
44054
+ const rpIdHash = toBytes(sha256$1(new TextEncoder().encode(rpId)));
44055
+ const authData = new Uint8Array(37);
44056
+ authData.set(rpIdHash, 0);
44057
+ authData[32] = flags & 255;
44058
+ new DataView(authData.buffer).setUint32(33, signCount >>> 0, false);
44059
+ const clientDataHash = toBytes(sha256$1(clientDataJSON));
44060
+ const message = new Uint8Array(authData.length + clientDataHash.length);
44061
+ message.set(authData, 0);
44062
+ message.set(clientDataHash, authData.length);
44063
+ const signature = p256.sign(message, priv, { prehash: true, lowS: true });
44064
+ const r = numberToHex(signature.r, { size: 32 });
44065
+ const s = numberToHex(signature.s, { size: 32 });
44066
+ const sig = encodeWebAuthnAssertion({ authenticatorData: authData, clientDataJSON, r, s });
44067
+ return { sig, authenticatorData: toHex(authData), clientDataJSON: toHex(clientDataJSON), r, s };
44068
+ }
44069
+ function p256GuardianPublicKey(privateKey) {
44070
+ const priv = privateKey instanceof Uint8Array ? privateKey : toBytes(privateKey);
44071
+ const pub = p256.getPublicKey(priv, false);
44072
+ return coseToP256XY(pub);
44073
+ }
42630
44074
  var DEFAULT_ADMIN_ROLE = "0x0000000000000000000000000000000000000000000000000000000000000000";
42631
44075
  var ROLE_COMMUNITY = keccak256(toHex("COMMUNITY"));
42632
44076
  var ROLE_ENDUSER = keccak256(toHex("ENDUSER"));
@@ -43060,9 +44504,11 @@ function makeMainnetClient(rpcUrl) {
43060
44504
  @noble/curves/esm/abstract/bls.js:
43061
44505
  @noble/curves/esm/abstract/tower.js:
43062
44506
  @noble/curves/esm/bls12-381.js:
44507
+ @noble/curves/esm/_shortw_utils.js:
44508
+ @noble/curves/esm/nist.js:
43063
44509
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
43064
44510
  */
43065
44511
 
43066
- export { AASTAR_COMMUNITY, AAStarAirAccountFactoryV7ABI, AAStarAirAccountFactoryV7Artifact, AAStarAirAccountV7ABI, AAStarAirAccountV7Artifact, AAStarBLSAggregatorABI, AAStarBLSAggregatorArtifact, AAStarBLSAlgorithmABI, AAStarBLSAlgorithmArtifact, AAStarValidatorABI, AAStarValidatorArtifact, ALL_ROLES, AgentRegistryABI, AgentRegistryArtifact, AirAccountDelegateABI, AirAccountDelegateArtifact, AirAccountExtensionABI, AirAccountExtensionArtifact, AuthorizationState, BLSAggregatorABI, BLSAggregatorArtifact, BLSHelpers, BLSSigner, BLSValidatorABI, BLSValidatorArtifact, BLS_POP_DST, BRANDING, BREAD_COMMUNITY, BaseClient, BundlerClient, COMMUNITIES, CONTRACTS, CONTRACT_METADATA, CalldataParserRegistryABI, CalldataParserRegistryArtifact, ContractConfigManager, DEFAULT_ADMIN_ROLE, DVTValidatorABI, DVTValidatorArtifact, DVT_TIER_T2, DVT_TIER_T3, EntryPointABI, EntryPointArtifact, EntryPointVersion, ForceExitModuleABI, ForceExitModuleArtifact, GTokenABI, GTokenArtifact, GTokenAuthorizationABI, GTokenAuthorizationArtifact, GTokenStakingABI, GTokenStakingArtifact, INITIAL_ROLE_STAKES, LINKS, MicroPaymentChannelABI, MicroPaymentChannelArtifact, MySBTABI, MySBTArtifact, NETWORKS, NodeType, PaymasterABI, PaymasterArtifact, PaymasterFactoryABI, PaymasterFactoryArtifact, PolicyDecision, PolicyRegistryABI, PolicyRegistryArtifact, ROLE_ANODE, ROLE_COMMUNITY, ROLE_DVT, ROLE_ENDUSER, ROLE_KMS, ROLE_NAMES, ROLE_PAYMASTER_AOA, ROLE_PAYMASTER_SUPER, ROLE_PERMISSION_LEVELS, RegistryABI, RegistryArtifact, ReputationSystemABI, ReputationSystemArtifact, RequirementChecker, RolePermissionLevel, SEPOLIA_CONTRACTS, SEPOLIA_V2_VERSIONS, SepoliaFaucetAPI, SessionKeyValidatorABI, SessionKeyValidatorArtifact, SimpleAccountABI, SimpleAccountArtifact, SimpleAccountFactoryABI, SimpleAccountFactoryArtifact, StateValidator, SuperPaymasterABI, SuperPaymasterArtifact, V2_SUMMARY, X402FacilitatorABI, X402FacilitatorArtifact, accountActions, accountFactoryActions, agentActions, agentRegistryActions, aggregatorActions, airAccountActions, airAccountExtensionActions, airAccountFactoryActions, blsAlgorithmActions, channelActions, createAAStarPublicClient, createHeliosTransport, dvtActions, encodeDVTAccountSignature, encodeDVTVerifierProof, encodeG2Point, entryPointActions, forceExitActions, gTokenActions, gTokenAuthorizationActions, getAddressUrl, getAllCommunityConfigs, getAllV2Contracts, getBlockExplorer, getChainId, getCommunities, getCommunity, getCommunityConfig, getContract, getContractNetworks, getContracts, getCoreContracts, getDeploymentDate, getEntryPoint, getNetwork, getPaymasterV4_1, getRoleName, getRpcUrl, getSimpleAccountFactory, getSuperPaymasterV2, getTestAccounts, getTestTokenContracts, getTokenContracts, getTxUrl, getV2ContractByAddress, getV2ContractByName, getV2ContractsByDate, hashToFieldU0U1, isContractNetworkSupported, isRegisteredCommunity, isV2Contract, lookupAddress, paymasterActions, paymasterFactoryActions, policyRegistryActions, registryActions, reputationActions, resolveEns, resolveEnsVerified, sbtActions, sessionKeyValidatorActions, stakingActions, superPaymasterActions, tokenActions, x402Actions, x402IsNonceUsed, x402NonceKey, xPNTsFactoryABI, xPNTsFactoryActions, xPNTsFactoryArtifact, xPNTsTokenABI, xPNTsTokenActions, xPNTsTokenArtifact };
43067
- //# sourceMappingURL=chunk-M5WFKETT.js.map
43068
- //# sourceMappingURL=chunk-M5WFKETT.js.map
44512
+ export { AASTAR_COMMUNITY, AAStarAirAccountFactoryV7ABI, AAStarAirAccountFactoryV7Artifact, AAStarAirAccountV7ABI, AAStarAirAccountV7Artifact, AAStarBLSAggregatorABI, AAStarBLSAggregatorArtifact, AAStarBLSAlgorithmABI, AAStarBLSAlgorithmArtifact, AAStarValidatorABI, AAStarValidatorArtifact, ALL_ROLES, AgentRegistryABI, AgentRegistryArtifact, AirAccountDelegateABI, AirAccountDelegateArtifact, AirAccountExtensionABI, AirAccountExtensionArtifact, AuthorizationState, BLSAggregatorABI, BLSAggregatorArtifact, BLSHelpers, BLSSigner, BLSValidatorABI, BLSValidatorArtifact, BLS_POP_DST, BRANDING, BREAD_COMMUNITY, BaseClient, BundlerClient, COMMUNITIES, CONTRACTS, CONTRACT_METADATA, CalldataParserRegistryABI, CalldataParserRegistryArtifact, ContractConfigManager, DEFAULT_ADMIN_ROLE, DVTValidatorABI, DVTValidatorArtifact, DVT_TIER_T2, DVT_TIER_T3, EntryPointABI, EntryPointArtifact, EntryPointVersion, ForceExitModuleABI, ForceExitModuleArtifact, GTokenABI, GTokenArtifact, GTokenAuthorizationABI, GTokenAuthorizationArtifact, GTokenStakingABI, GTokenStakingArtifact, GUARDIAN_ADDITION_NONCE_SLOT, GUARDIAN_REMOVAL_NONCE_SLOT, GUARDIAN_SIG_VERSION, INITIAL_ROLE_STAKES, LINKS, MAX_GUARDIAN_SLOT, MicroPaymentChannelABI, MicroPaymentChannelArtifact, MySBTABI, MySBTArtifact, NETWORKS, NodeType, P256_GUARDIAN_DOMAIN, P256_GUARDIAN_SENTINEL2 as P256_GUARDIAN_SENTINEL, PaymasterABI, PaymasterArtifact, PaymasterFactoryABI, PaymasterFactoryArtifact, PolicyDecision, PolicyRegistryABI, PolicyRegistryArtifact, RECOVERY_NONCE_SLOT, ROLE_ANODE, ROLE_COMMUNITY, ROLE_DVT, ROLE_ENDUSER, ROLE_KMS, ROLE_NAMES, ROLE_PAYMASTER_AOA, ROLE_PAYMASTER_SUPER, ROLE_PERMISSION_LEVELS, RegistryABI, RegistryArtifact, ReputationSystemABI, ReputationSystemArtifact, RequirementChecker, RolePermissionLevel, SECP256R1_N, SECP256R1_N_OVER_2, SEPOLIA_CONTRACTS, SEPOLIA_V2_VERSIONS, SepoliaFaucetAPI, SessionKeyValidatorABI, SessionKeyValidatorArtifact, SimpleAccountABI, SimpleAccountArtifact, SimpleAccountFactoryABI, SimpleAccountFactoryArtifact, StateValidator, SuperPaymasterABI, SuperPaymasterArtifact, TIER_LIMIT_NONCE_SLOT, V2_SUMMARY, WEBAUTHN_GET_CHALLENGE_PREFIX, X402FacilitatorABI, X402FacilitatorArtifact, accountActions, accountFactoryActions, agentActions, agentRegistryActions, aggregatorActions, airAccountActions, airAccountExtensionActions, airAccountFactoryActions, base64UrlEncode, blsAlgorithmActions, buildAddGuardianChallenge, buildAddP256GuardianChallenge, buildApproveRecoveryChallenge, buildCancelRecoveryChallenge, buildInitConfig, buildModifyTierLimitsChallenge, buildP256GuardianChallenge, buildProposeRecoveryChallenge, buildRemoveGuardianChallenge, channelActions, coseToP256XY, createAAStarPublicClient, createHeliosTransport, decodeWebAuthnAssertion, dvtActions, encodeDVTAccountSignature, encodeDVTVerifierProof, encodeG2Point, encodeWebAuthnAssertion, entryPointActions, forceExitActions, gTokenActions, gTokenAuthorizationActions, getAddressUrl, getAllCommunityConfigs, getAllV2Contracts, getBlockExplorer, getChainId, getCommunities, getCommunity, getCommunityConfig, getContract, getContractNetworks, getContracts, getCoreContracts, getDeploymentDate, getEntryPoint, getNetwork, getPaymasterV4_1, getRoleName, getRpcUrl, getSimpleAccountFactory, getSuperPaymasterV2, getTestAccounts, getTestTokenContracts, getTokenContracts, getTxUrl, getV2ContractByAddress, getV2ContractByName, getV2ContractsByDate, hashToFieldU0U1, isContractNetworkSupported, isRegisteredCommunity, isV2Contract, lookupAddress, opDataAddGuardian, opDataAddP256Guardian, opDataModifyTierLimits, opDataRecovery, opDataRemoveGuardian, p256GuardianPublicKey, paymasterActions, paymasterFactoryActions, policyRegistryActions, registryActions, reputationActions, resolveEns, resolveEnsVerified, sbtActions, sessionKeyValidatorActions, signP256GuardianAssertion, stakingActions, superPaymasterActions, tokenActions, x402Actions, x402IsNonceUsed, x402NonceKey, xPNTsFactoryABI, xPNTsFactoryActions, xPNTsFactoryArtifact, xPNTsTokenABI, xPNTsTokenActions, xPNTsTokenArtifact };
44513
+ //# sourceMappingURL=chunk-2TS6T2WY.js.map
44514
+ //# sourceMappingURL=chunk-2TS6T2WY.js.map