@coinbase/cdp-core 0.0.32 → 0.0.33

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 (274) hide show
  1. package/dist/esm/index.native.js +40 -38
  2. package/dist/esm/index.native10.js +115 -21
  3. package/dist/esm/index.native100.js +6 -9
  4. package/dist/esm/index.native101.js +11 -13
  5. package/dist/esm/index.native102.js +11 -8
  6. package/dist/esm/index.native103.js +7 -14
  7. package/dist/esm/index.native104.js +16 -80
  8. package/dist/esm/index.native105.js +79 -11
  9. package/dist/esm/index.native106.js +12 -35
  10. package/dist/esm/index.native107.js +35 -41
  11. package/dist/esm/index.native108.js +38 -75
  12. package/dist/esm/index.native109.js +81 -0
  13. package/dist/esm/index.native11.js +20 -30
  14. package/dist/esm/index.native12.js +30 -7
  15. package/dist/esm/index.native13.js +9 -15
  16. package/dist/esm/index.native14.js +14 -15
  17. package/dist/esm/index.native15.js +13 -116
  18. package/dist/esm/index.native16.js +116 -11
  19. package/dist/esm/index.native17.js +14 -42
  20. package/dist/esm/index.native18.js +42 -20
  21. package/dist/esm/index.native19.js +20 -172
  22. package/dist/esm/index.native2.js +3 -3
  23. package/dist/esm/index.native20.js +170 -39
  24. package/dist/esm/index.native21.js +41 -49
  25. package/dist/esm/index.native22.js +47 -70
  26. package/dist/esm/index.native23.js +69 -23
  27. package/dist/esm/index.native24.js +22 -156
  28. package/dist/esm/index.native25.js +157 -45
  29. package/dist/esm/index.native26.js +43 -245
  30. package/dist/esm/index.native27.js +247 -53
  31. package/dist/esm/index.native28.js +56 -17
  32. package/dist/esm/index.native29.js +15 -21
  33. package/dist/esm/index.native3.js +40 -30
  34. package/dist/esm/index.native30.js +21 -49
  35. package/dist/esm/index.native31.js +50 -8
  36. package/dist/esm/index.native32.js +8 -17
  37. package/dist/esm/index.native33.js +16 -44
  38. package/dist/esm/index.native34.js +45 -13
  39. package/dist/esm/index.native35.js +13 -55
  40. package/dist/esm/index.native36.js +55 -6
  41. package/dist/esm/index.native37.js +6 -21
  42. package/dist/esm/index.native38.js +21 -11
  43. package/dist/esm/index.native39.js +11 -3
  44. package/dist/esm/index.native4.js +67 -21
  45. package/dist/esm/index.native40.js +3 -3
  46. package/dist/esm/index.native41.js +3 -34
  47. package/dist/esm/index.native42.js +32 -10
  48. package/dist/esm/index.native43.js +12 -4
  49. package/dist/esm/index.native44.js +4 -28
  50. package/dist/esm/index.native45.js +28 -6
  51. package/dist/esm/index.native46.js +6 -24
  52. package/dist/esm/index.native47.js +24 -16
  53. package/dist/esm/index.native48.js +16 -54
  54. package/dist/esm/index.native49.js +53 -22
  55. package/dist/esm/index.native5.js +21 -254
  56. package/dist/esm/index.native50.js +23 -11
  57. package/dist/esm/index.native51.js +10 -26
  58. package/dist/esm/index.native52.js +26 -41
  59. package/dist/esm/index.native53.js +41 -54
  60. package/dist/esm/index.native54.js +54 -126
  61. package/dist/esm/index.native55.js +126 -11
  62. package/dist/esm/index.native56.js +9 -101
  63. package/dist/esm/index.native57.js +104 -6
  64. package/dist/esm/index.native58.js +7 -3
  65. package/dist/esm/index.native59.js +3 -15
  66. package/dist/esm/index.native6.js +262 -176
  67. package/dist/esm/index.native60.js +14 -42
  68. package/dist/esm/index.native61.js +38 -74
  69. package/dist/esm/index.native62.js +79 -2
  70. package/dist/esm/index.native63.js +2 -2
  71. package/dist/esm/index.native64.js +2 -13
  72. package/dist/esm/index.native65.js +8 -33
  73. package/dist/esm/index.native66.js +36 -5
  74. package/dist/esm/index.native67.js +5 -33
  75. package/dist/esm/index.native68.js +34 -8
  76. package/dist/esm/index.native69.js +8 -10
  77. package/dist/esm/index.native7.js +213 -115
  78. package/dist/esm/index.native70.js +10 -11
  79. package/dist/esm/index.native71.js +11 -13
  80. package/dist/esm/index.native72.js +13 -18
  81. package/dist/esm/index.native73.js +18 -5
  82. package/dist/esm/index.native74.js +6 -5
  83. package/dist/esm/index.native75.js +5 -11
  84. package/dist/esm/index.native76.js +10 -54
  85. package/dist/esm/index.native77.js +54 -10
  86. package/dist/esm/index.native78.js +11 -2
  87. package/dist/esm/index.native79.js +2 -45
  88. package/dist/esm/index.native8.js +115 -137
  89. package/dist/esm/index.native80.js +44 -13
  90. package/dist/esm/index.native81.js +14 -2
  91. package/dist/esm/index.native82.js +1 -1
  92. package/dist/esm/index.native83.js +2 -20
  93. package/dist/esm/index.native84.js +103 -79
  94. package/dist/esm/index.native85.js +18 -102
  95. package/dist/esm/index.native86.js +79 -32
  96. package/dist/esm/index.native87.js +32 -6
  97. package/dist/esm/index.native88.js +6 -78
  98. package/dist/esm/index.native89.js +2 -2
  99. package/dist/esm/index.native9.js +138 -113
  100. package/dist/esm/index.native90.js +3 -3
  101. package/dist/esm/index.native92.js +3 -3
  102. package/dist/esm/index.native93.js +1 -1
  103. package/dist/esm/index.native94.js +3 -3
  104. package/dist/esm/index.native95.js +79 -10
  105. package/dist/esm/index.native96.js +10 -5
  106. package/dist/esm/index.native97.js +5 -18
  107. package/dist/esm/index.native98.js +18 -28
  108. package/dist/esm/index.native99.js +26 -6
  109. package/dist/esm/index.web100.js +13 -28
  110. package/dist/esm/index.web101.js +10 -8
  111. package/dist/esm/index.web102.js +17 -11
  112. package/dist/esm/index.web103.js +80 -12
  113. package/dist/esm/index.web104.js +13 -10
  114. package/dist/esm/index.web105.js +36 -17
  115. package/dist/esm/index.web106.js +40 -79
  116. package/dist/esm/index.web26.js +1 -1
  117. package/dist/esm/index.web5.js +131 -109
  118. package/dist/esm/index.web6.js +65 -38
  119. package/dist/esm/index.web75.js +6 -6
  120. package/dist/esm/index.web84.js +1 -1
  121. package/dist/esm/index.web87.js +21 -10
  122. package/dist/esm/index.web88.js +10 -79
  123. package/dist/esm/index.web89.js +19 -20
  124. package/dist/esm/index.web90.js +93 -9
  125. package/dist/esm/index.web91.js +19 -18
  126. package/dist/esm/index.web92.js +105 -81
  127. package/dist/esm/index.web93.js +78 -20
  128. package/dist/esm/index.web94.js +9 -117
  129. package/dist/esm/index.web96.js +18 -13
  130. package/dist/esm/index.web97.js +27 -35
  131. package/dist/esm/index.web98.js +7 -41
  132. package/dist/esm/index.web99.js +11 -18
  133. package/dist/native/index.native.js +40 -38
  134. package/dist/native/index.native10.js +115 -21
  135. package/dist/native/index.native100.js +6 -9
  136. package/dist/native/index.native101.js +11 -13
  137. package/dist/native/index.native102.js +11 -8
  138. package/dist/native/index.native103.js +7 -14
  139. package/dist/native/index.native104.js +16 -80
  140. package/dist/native/index.native105.js +79 -11
  141. package/dist/native/index.native106.js +12 -35
  142. package/dist/native/index.native107.js +35 -41
  143. package/dist/native/index.native108.js +38 -75
  144. package/dist/native/index.native109.js +81 -0
  145. package/dist/native/index.native11.js +20 -30
  146. package/dist/native/index.native12.js +30 -7
  147. package/dist/native/index.native13.js +9 -15
  148. package/dist/native/index.native14.js +14 -15
  149. package/dist/native/index.native15.js +13 -116
  150. package/dist/native/index.native16.js +116 -11
  151. package/dist/native/index.native17.js +14 -42
  152. package/dist/native/index.native18.js +42 -20
  153. package/dist/native/index.native19.js +20 -172
  154. package/dist/native/index.native2.js +3 -3
  155. package/dist/native/index.native20.js +170 -39
  156. package/dist/native/index.native21.js +41 -49
  157. package/dist/native/index.native22.js +47 -70
  158. package/dist/native/index.native23.js +69 -23
  159. package/dist/native/index.native24.js +22 -156
  160. package/dist/native/index.native25.js +157 -45
  161. package/dist/native/index.native26.js +43 -245
  162. package/dist/native/index.native27.js +247 -53
  163. package/dist/native/index.native28.js +56 -17
  164. package/dist/native/index.native29.js +15 -21
  165. package/dist/native/index.native3.js +40 -30
  166. package/dist/native/index.native30.js +21 -49
  167. package/dist/native/index.native31.js +50 -8
  168. package/dist/native/index.native32.js +8 -17
  169. package/dist/native/index.native33.js +16 -44
  170. package/dist/native/index.native34.js +45 -13
  171. package/dist/native/index.native35.js +13 -55
  172. package/dist/native/index.native36.js +55 -6
  173. package/dist/native/index.native37.js +6 -21
  174. package/dist/native/index.native38.js +21 -11
  175. package/dist/native/index.native39.js +11 -3
  176. package/dist/native/index.native4.js +67 -21
  177. package/dist/native/index.native40.js +3 -3
  178. package/dist/native/index.native41.js +3 -34
  179. package/dist/native/index.native42.js +32 -10
  180. package/dist/native/index.native43.js +12 -4
  181. package/dist/native/index.native44.js +4 -28
  182. package/dist/native/index.native45.js +28 -6
  183. package/dist/native/index.native46.js +6 -24
  184. package/dist/native/index.native47.js +24 -16
  185. package/dist/native/index.native48.js +16 -54
  186. package/dist/native/index.native49.js +53 -22
  187. package/dist/native/index.native5.js +21 -254
  188. package/dist/native/index.native50.js +23 -11
  189. package/dist/native/index.native51.js +10 -26
  190. package/dist/native/index.native52.js +26 -41
  191. package/dist/native/index.native53.js +41 -54
  192. package/dist/native/index.native54.js +54 -126
  193. package/dist/native/index.native55.js +126 -11
  194. package/dist/native/index.native56.js +9 -101
  195. package/dist/native/index.native57.js +104 -6
  196. package/dist/native/index.native58.js +7 -3
  197. package/dist/native/index.native59.js +3 -15
  198. package/dist/native/index.native6.js +262 -176
  199. package/dist/native/index.native60.js +14 -42
  200. package/dist/native/index.native61.js +38 -74
  201. package/dist/native/index.native62.js +79 -2
  202. package/dist/native/index.native63.js +2 -2
  203. package/dist/native/index.native64.js +2 -13
  204. package/dist/native/index.native65.js +8 -33
  205. package/dist/native/index.native66.js +36 -5
  206. package/dist/native/index.native67.js +5 -33
  207. package/dist/native/index.native68.js +34 -8
  208. package/dist/native/index.native69.js +8 -10
  209. package/dist/native/index.native7.js +213 -115
  210. package/dist/native/index.native70.js +10 -11
  211. package/dist/native/index.native71.js +11 -13
  212. package/dist/native/index.native72.js +13 -18
  213. package/dist/native/index.native73.js +18 -5
  214. package/dist/native/index.native74.js +6 -5
  215. package/dist/native/index.native75.js +5 -11
  216. package/dist/native/index.native76.js +10 -54
  217. package/dist/native/index.native77.js +54 -10
  218. package/dist/native/index.native78.js +11 -2
  219. package/dist/native/index.native79.js +2 -45
  220. package/dist/native/index.native8.js +115 -137
  221. package/dist/native/index.native80.js +44 -13
  222. package/dist/native/index.native81.js +14 -2
  223. package/dist/native/index.native82.js +1 -1
  224. package/dist/native/index.native83.js +2 -20
  225. package/dist/native/index.native84.js +103 -79
  226. package/dist/native/index.native85.js +18 -102
  227. package/dist/native/index.native86.js +79 -32
  228. package/dist/native/index.native87.js +32 -6
  229. package/dist/native/index.native88.js +6 -78
  230. package/dist/native/index.native89.js +2 -2
  231. package/dist/native/index.native9.js +138 -113
  232. package/dist/native/index.native90.js +3 -3
  233. package/dist/native/index.native92.js +3 -3
  234. package/dist/native/index.native93.js +1 -1
  235. package/dist/native/index.native94.js +3 -3
  236. package/dist/native/index.native95.js +79 -10
  237. package/dist/native/index.native96.js +10 -5
  238. package/dist/native/index.native97.js +5 -18
  239. package/dist/native/index.native98.js +18 -28
  240. package/dist/native/index.native99.js +26 -6
  241. package/dist/native-types/auth/authManager.d.ts +3 -0
  242. package/dist/native-types/platform/native/secureStorage.d.ts +2 -0
  243. package/dist/native-types/platform/types.d.ts +7 -0
  244. package/dist/types/auth/authManager.d.ts +3 -0
  245. package/dist/types/platform/native/secureStorage.d.ts +2 -0
  246. package/dist/types/platform/types.d.ts +7 -0
  247. package/dist/web/index.web100.js +13 -28
  248. package/dist/web/index.web101.js +10 -8
  249. package/dist/web/index.web102.js +17 -11
  250. package/dist/web/index.web103.js +80 -12
  251. package/dist/web/index.web104.js +13 -10
  252. package/dist/web/index.web105.js +36 -17
  253. package/dist/web/index.web106.js +40 -79
  254. package/dist/web/index.web26.js +1 -1
  255. package/dist/web/index.web5.js +131 -109
  256. package/dist/web/index.web6.js +65 -38
  257. package/dist/web/index.web75.js +6 -6
  258. package/dist/web/index.web84.js +1 -1
  259. package/dist/web/index.web87.js +21 -10
  260. package/dist/web/index.web88.js +10 -79
  261. package/dist/web/index.web89.js +19 -20
  262. package/dist/web/index.web90.js +93 -9
  263. package/dist/web/index.web91.js +19 -18
  264. package/dist/web/index.web92.js +105 -81
  265. package/dist/web/index.web93.js +78 -20
  266. package/dist/web/index.web94.js +9 -117
  267. package/dist/web/index.web96.js +18 -13
  268. package/dist/web/index.web97.js +27 -35
  269. package/dist/web/index.web98.js +7 -41
  270. package/dist/web/index.web99.js +11 -18
  271. package/dist/web-types/auth/authManager.d.ts +3 -0
  272. package/dist/web-types/platform/native/secureStorage.d.ts +2 -0
  273. package/dist/web-types/platform/types.d.ts +7 -0
  274. package/package.json +8 -4
@@ -1,121 +1,219 @@
1
- import { Provider as h } from "ox";
2
- import { http as m } from "viem";
3
- import { create as p } from "zustand";
4
- import { subscribeWithSelector as g, persist as f } from "./index.native24.js";
5
- import { validateRequest as I, EIP1193ProviderError as S, STANDARD_ERROR_CODES as w } from "./index.native8.js";
6
- import { EventEmitter as C } from "./index.native25.js";
7
- import { getPlatformStorage as b } from "./index.native4.js";
8
- import "@coinbase/cdp-api-client";
9
- import { handleGetCapabilities as _, handleGetCallsStatus as A, handleSendCalls as v, handleChainId as D, handleSignTypedData as P, handleEthSign as E, handleSwitchEthereumChain as R, handleDisconnect as y, handleSendTransaction as T, handlePersonalSign as q, handleRequestAccounts as G, handleAccounts as L } from "./index.native26.js";
10
- import { onAuthStateChange as M } from "./index.native5.js";
11
- import { baseSepolia as l } from "./index.native27.js";
12
- function N(r, n, s) {
13
- n.subscribe(
14
- (e) => e.chainId,
15
- (e, t) => {
16
- e !== t && r.emit("chainChanged", e);
1
+ import { logOutEndUser as l, refreshAccessToken as c, registerTemporaryWalletSecret as o } from "@coinbase/cdp-api-client";
2
+ import { SignJWT as u } from "./index.native21.js";
3
+ import "viem";
4
+ import { toAuthState as f } from "./index.native14.js";
5
+ import { getPlatformCrypto as n } from "./index.native5.js";
6
+ import { sortKeys as S } from "./index.native18.js";
7
+ const i = 60 * 1e3;
8
+ class p {
9
+ projectId;
10
+ authState = null;
11
+ walletSecret = null;
12
+ authStateChangeCallbacks = [];
13
+ initPromise = null;
14
+ refreshTimeout = null;
15
+ /**
16
+ * Initializes the token manager.
17
+ *
18
+ * @param projectId - The project ID.
19
+ */
20
+ constructor(e) {
21
+ this.projectId = e, this.initPromise = this._doInitialize();
22
+ }
23
+ /**
24
+ * Gets the current user, or null if there is no user signed in.
25
+ *
26
+ * @returns The current user.
27
+ */
28
+ async getUser() {
29
+ return this.authState?.user ?? null;
30
+ }
31
+ /**
32
+ * Returns whether the user is signed in - i.e., whether there is an unexpired
33
+ * access token and user. Attempts to refresh the token if it's expired.
34
+ *
35
+ * @returns True if the user is signed in, false otherwise.
36
+ */
37
+ async isSignedIn() {
38
+ if (!this.authState)
39
+ return !1;
40
+ if (this.authState.expiresAt > Date.now() + i)
41
+ return !0;
42
+ try {
43
+ return await this.getToken() !== null;
44
+ } catch {
45
+ return !1;
17
46
  }
18
- ), n.subscribe(
19
- (e) => e.user,
20
- (e, t) => {
21
- if (!(e?.userId === t?.userId && e?.evmAccounts?.length === t?.evmAccounts?.length)) {
22
- if (!e && t) {
23
- r.emit("disconnect", new h.DisconnectedError());
24
- return;
25
- }
26
- if (e && e.evmAccounts?.length && (!t || t.evmAccounts?.length === 0)) {
27
- const a = n.getState().chainId;
28
- r.emit("connect", { chainId: a });
29
- return;
30
- }
31
- }
47
+ }
48
+ /**
49
+ * Signs out the user, clearing all authentication state.
50
+ */
51
+ async signOut() {
52
+ try {
53
+ await l(this.projectId);
54
+ } catch {
55
+ } finally {
56
+ await this.clearAuthState();
32
57
  }
33
- );
34
- const { chainId: i, setChainId: o } = n.getState(), d = i || s.chains[0].id;
35
- return i || o(d), h.from({
36
- request: async (e) => {
37
- I(e, s);
38
- const t = e;
39
- switch (t.method) {
40
- case "eth_accounts":
41
- return L();
42
- case "eth_requestAccounts":
43
- return G(r, n);
44
- case "personal_sign":
45
- return q(t.params);
46
- case "eth_sendTransaction":
47
- return T(t.params, n, s.transports);
48
- case "wallet_disconnect":
49
- return y();
50
- case "wallet_switchEthereumChain":
51
- return R(t.params, n);
52
- case "eth_sign":
53
- return E(t.params);
54
- case "eth_signTypedData_v4":
55
- return P(t.params);
56
- case "eth_chainId":
57
- return D(n);
58
- case "wallet_sendCalls":
59
- return v(t.params, n);
60
- case "wallet_getCallsStatus":
61
- return A(t.params, n);
62
- case "wallet_getCapabilities":
63
- return _();
64
- // Catch-all for any unknown method
65
- default:
66
- throw new S(
67
- w.provider.unsupportedMethod,
68
- `Method ${t.method} not supported`
69
- );
70
- }
71
- },
72
- // Event emitter methods - only the ones required by the interface
73
- on: r.on.bind(r),
74
- removeListener: r.removeListener.bind(r)
75
- });
76
- }
77
- const u = {
78
- chains: [l],
79
- transports: {
80
- [l.id]: m()
81
58
  }
82
- };
83
- function K(r) {
84
- if (r?.chains.length === 0)
85
- throw new Error("At least one chain must be configured");
86
- const n = r?.chains ?? u.chains, s = r?.transports ?? u.transports;
87
- if (n.length === 0)
88
- throw new Error("No chains found in configuration");
89
- const i = new C(), o = b(), d = {
90
- getItem: (t) => o.getItem(t),
91
- setItem: (t, a) => o.setItem(t, a),
92
- removeItem: (t) => o.removeItem(t)
93
- }, c = p()(
94
- g(
95
- f(
96
- (t) => ({
97
- chainId: n[0].id,
98
- setChainId: (a) => t({ chainId: a }),
99
- chains: n,
100
- user: null,
101
- setUser: (a) => t({ user: a })
102
- }),
103
- {
104
- name: "cdp-provider-store",
105
- storage: d
106
- }
107
- )
108
- )
109
- );
110
- return c.persist.rehydrate(), M((t) => {
111
- c.getState().setUser(t);
112
- }), {
113
- provider: N(i, c, {
114
- chains: n,
115
- transports: s
116
- })
117
- };
59
+ /**
60
+ * Adds a callback to be called when the auth state changes.
61
+ *
62
+ * @param callback - The function to call when the auth state changes.
63
+ */
64
+ addAuthStateChangeCallback(e) {
65
+ this.authStateChangeCallbacks.push(e), e(this.authState?.user ?? null);
66
+ }
67
+ /**
68
+ * Gets the access token, refreshing it if it is expired. Returns null if the user is not
69
+ * signed in.
70
+ *
71
+ * @returns The access token.
72
+ */
73
+ async getToken() {
74
+ return this.shouldRefreshToken() && await this.refreshAccessToken(), this.authState?.accessToken ?? null;
75
+ }
76
+ /**
77
+ * Gets the currently registered wallet secret ID. Rejects if the user is not signed in.
78
+ *
79
+ * @returns The wallet secret ID.
80
+ */
81
+ async getWalletSecretId() {
82
+ if (!await this.isSignedIn())
83
+ throw new Error("Cannot get wallet secret ID if the user is not signed in");
84
+ return this.shouldRefreshWalletSecret() && await this.refreshWalletSecret(), this.walletSecret.walletSecretId;
85
+ }
86
+ /**
87
+ * Gets the X-Wallet-Auth header. Rejects if the user is not signed in.
88
+ *
89
+ * @param options - The options for the request.
90
+ * @param options.requestMethod - The HTTP method of the request.
91
+ * @param options.requestHost - The host of the request.
92
+ * @param options.requestPath - The path of the request.
93
+ * @param options.requestData - The data of the request.
94
+ * @returns The X-Wallet-Auth header.
95
+ */
96
+ async getXWalletAuth(e) {
97
+ if (!await this.isSignedIn())
98
+ throw new Error("Cannot get X-Wallet-Auth header if the user is not signed in");
99
+ this.shouldRefreshWalletSecret() && await this.refreshWalletSecret();
100
+ const t = `${e.requestMethod} ${e.requestHost}${e.requestPath}`, r = Math.floor(Date.now() / 1e3), s = n(), a = {
101
+ uris: [t]
102
+ };
103
+ if (e.requestData && Object.keys(e.requestData).length > 0) {
104
+ const h = S(e.requestData);
105
+ a.reqHash = await s.hash(new TextEncoder().encode(JSON.stringify(h)));
106
+ }
107
+ return await new u(a).setProtectedHeader({ alg: "ES256", typ: "JWT" }).setIssuedAt(r).setNotBefore(r).setJti(s.generateRandomId()).sign(this.walletSecret.keyPair.privateKey);
108
+ }
109
+ /**
110
+ * Sets the authentication state.
111
+ *
112
+ * @param authState - The authentication state.
113
+ */
114
+ async setAuthState(e) {
115
+ this.authState = e, this.authStateChangeCallbacks.forEach((t) => t(this.authState?.user ?? null)), this.scheduleTokenRefresh();
116
+ }
117
+ /**
118
+ * Clears the authentication state.
119
+ */
120
+ async clearAuthState() {
121
+ this.authState = null, this.walletSecret = null, this.cancelTokenRefresh(), this.authStateChangeCallbacks.forEach((e) => e(null));
122
+ }
123
+ /**
124
+ * Ensures the AuthManager is initialized before proceeding.
125
+ * If initialization is already in progress, waits for it to complete.
126
+ */
127
+ async ensureInitialized() {
128
+ if (this.initPromise) {
129
+ await this.initPromise;
130
+ return;
131
+ }
132
+ throw new Error("AuthManager not initialized");
133
+ }
134
+ /**
135
+ * Internal async initialization logic.
136
+ */
137
+ async _doInitialize() {
138
+ try {
139
+ await this.refreshAccessToken();
140
+ } catch (e) {
141
+ console.warn("Failed to refresh access token during initialization:", e);
142
+ }
143
+ }
144
+ /**
145
+ * Returns whether the token should be refreshed.
146
+ *
147
+ * @returns True if the token should be refreshed, false otherwise.
148
+ */
149
+ shouldRefreshToken() {
150
+ return !(this.authState && this.authState.expiresAt > Date.now() + i);
151
+ }
152
+ /**
153
+ * Refreshes the access token and transitions the auth state accordingly.
154
+ * If a refresh is already in progress, it will wait for that refresh to complete.
155
+ *
156
+ * @returns The new access token.
157
+ */
158
+ async refreshAccessToken() {
159
+ try {
160
+ const e = await c(this.projectId, {
161
+ grantType: "refresh_token"
162
+ }), t = f(
163
+ e.accessToken,
164
+ e.validUntil,
165
+ e.endUser
166
+ );
167
+ await this.setAuthState(t);
168
+ } catch {
169
+ await this.signOut();
170
+ }
171
+ }
172
+ /**
173
+ * Returns whether the wallet secret should be refreshed.
174
+ *
175
+ * @returns True if the wallet secret should be refreshed, false otherwise.
176
+ */
177
+ shouldRefreshWalletSecret() {
178
+ return !(this.walletSecret && this.walletSecret.expiresAt > Date.now() + i);
179
+ }
180
+ /**
181
+ * Refreshes the wallet secret. Assumes the user is signed in.
182
+ *
183
+ * @returns The wallet secret.
184
+ */
185
+ async refreshWalletSecret() {
186
+ const e = n(), t = this.walletSecret?.walletSecretId ?? e.generateRandomId(), r = this.walletSecret?.keyPair ?? await e.createKeyPair(), s = this.authState.expiresAt, a = new Date(s).toISOString();
187
+ this.walletSecret = { walletSecretId: t, keyPair: r, expiresAt: s };
188
+ try {
189
+ await o(this.projectId, this.authState.user.userId, {
190
+ walletSecretId: t,
191
+ publicKey: r.publicKeyBase64,
192
+ validUntil: a
193
+ });
194
+ } catch (h) {
195
+ throw this.walletSecret = null, h;
196
+ }
197
+ }
198
+ /**
199
+ * Schedules a token refresh to occur exactly when shouldRefreshToken() would return true.
200
+ * Uses the same REFRESH_CREDENTIALS_BUFFER_MS timing as the rest of the auth system.
201
+ */
202
+ scheduleTokenRefresh() {
203
+ if (this.cancelTokenRefresh(), !this.authState)
204
+ return;
205
+ const t = this.authState.expiresAt - i - Date.now();
206
+ t <= 0 || (this.refreshTimeout = setTimeout(async () => {
207
+ await this.refreshAccessToken(), this.scheduleTokenRefresh();
208
+ }, t));
209
+ }
210
+ /**
211
+ * Cancels any scheduled token refresh.
212
+ */
213
+ cancelTokenRefresh() {
214
+ this.refreshTimeout && (clearTimeout(this.refreshTimeout), this.refreshTimeout = null);
215
+ }
118
216
  }
119
217
  export {
120
- K as createCDPEmbeddedWallet
218
+ p as AuthManager
121
219
  };
@@ -1,14 +1,13 @@
1
- import { commitmentToVersionedHash as i } from "./index.native87.js";
2
- function r(o) {
3
- const { commitments: t, version: n } = o, e = o.to ?? (typeof t[0] == "string" ? "hex" : "bytes"), s = [];
4
- for (const m of t)
5
- s.push(i({
6
- commitment: m,
7
- to: e,
8
- version: n
9
- }));
10
- return s;
1
+ import { hexToBytes as b } from "./index.native36.js";
2
+ import { bytesToHex as y } from "./index.native34.js";
3
+ function h(t) {
4
+ const { kzg: m } = t, c = t.to ?? (typeof t.blobs[0] == "string" ? "hex" : "bytes"), s = typeof t.blobs[0] == "string" ? t.blobs.map((o) => b(o)) : t.blobs, i = typeof t.commitments[0] == "string" ? t.commitments.map((o) => b(o)) : t.commitments, n = [];
5
+ for (let o = 0; o < s.length; o++) {
6
+ const f = s[o], l = i[o];
7
+ n.push(Uint8Array.from(m.computeBlobKzgProof(f, l)));
8
+ }
9
+ return c === "bytes" ? n : n.map((o) => y(o));
11
10
  }
12
11
  export {
13
- r as commitmentsToVersionedHashes
12
+ h as blobsToProofs
14
13
  };
@@ -1,16 +1,14 @@
1
- import { blobsToCommitments as f } from "./index.native68.js";
2
- import { blobsToProofs as l } from "./index.native69.js";
3
- import { toBlobs as p } from "./index.native86.js";
4
- function k(t) {
5
- const { data: i, kzg: n, to: m } = t, s = t.blobs ?? p({ data: i, to: m }), b = t.commitments ?? f({ blobs: s, kzg: n, to: m }), r = t.proofs ?? l({ blobs: s, commitments: b, kzg: n, to: m }), c = [];
6
- for (let o = 0; o < s.length; o++)
7
- c.push({
8
- blob: s[o],
9
- commitment: b[o],
10
- proof: r[o]
11
- });
12
- return c;
1
+ import { commitmentToVersionedHash as i } from "./index.native88.js";
2
+ function r(o) {
3
+ const { commitments: t, version: n } = o, e = o.to ?? (typeof t[0] == "string" ? "hex" : "bytes"), s = [];
4
+ for (const m of t)
5
+ s.push(i({
6
+ commitment: m,
7
+ to: e,
8
+ version: n
9
+ }));
10
+ return s;
13
11
  }
14
12
  export {
15
- k as toBlobSidecars
13
+ r as commitmentsToVersionedHashes
16
14
  };
@@ -1,21 +1,16 @@
1
- import { InvalidAddressError as s } from "./index.native64.js";
2
- import { InvalidStorageKeySizeError as l } from "./index.native60.js";
3
- import { isAddress as f } from "./index.native38.js";
4
- function a(r) {
5
- if (!r || r.length === 0)
6
- return [];
7
- const n = [];
8
- for (let o = 0; o < r.length; o++) {
9
- const { address: i, storageKeys: e } = r[o];
10
- for (let t = 0; t < e.length; t++)
11
- if (e[t].length - 2 !== 64)
12
- throw new l({ storageKey: e[t] });
13
- if (!f(i, { strict: !1 }))
14
- throw new s({ address: i });
15
- n.push([i, e]);
16
- }
17
- return n;
1
+ import { blobsToCommitments as f } from "./index.native69.js";
2
+ import { blobsToProofs as l } from "./index.native70.js";
3
+ import { toBlobs as p } from "./index.native87.js";
4
+ function k(t) {
5
+ const { data: i, kzg: n, to: m } = t, s = t.blobs ?? p({ data: i, to: m }), b = t.commitments ?? f({ blobs: s, kzg: n, to: m }), r = t.proofs ?? l({ blobs: s, commitments: b, kzg: n, to: m }), c = [];
6
+ for (let o = 0; o < s.length; o++)
7
+ c.push({
8
+ blob: s[o],
9
+ commitment: b[o],
10
+ proof: r[o]
11
+ });
12
+ return c;
18
13
  }
19
14
  export {
20
- a as serializeAccessList
15
+ k as toBlobSidecars
21
16
  };
@@ -1,8 +1,21 @@
1
- import { gweiUnits as i } from "./index.native74.js";
2
- import { formatUnits as o } from "./index.native75.js";
3
- function f(r, t = "wei") {
4
- return o(r, i[t]);
1
+ import { InvalidAddressError as s } from "./index.native65.js";
2
+ import { InvalidStorageKeySizeError as l } from "./index.native61.js";
3
+ import { isAddress as f } from "./index.native39.js";
4
+ function a(r) {
5
+ if (!r || r.length === 0)
6
+ return [];
7
+ const n = [];
8
+ for (let o = 0; o < r.length; o++) {
9
+ const { address: i, storageKeys: e } = r[o];
10
+ for (let t = 0; t < e.length; t++)
11
+ if (e[t].length - 2 !== 64)
12
+ throw new l({ storageKey: e[t] });
13
+ if (!f(i, { strict: !1 }))
14
+ throw new s({ address: i });
15
+ n.push([i, e]);
16
+ }
17
+ return n;
5
18
  }
6
19
  export {
7
- f as formatGwei
20
+ a as serializeAccessList
8
21
  };
@@ -1,7 +1,8 @@
1
- const e = {
2
- ether: -9,
3
- wei: 9
4
- };
1
+ import { gweiUnits as i } from "./index.native75.js";
2
+ import { formatUnits as o } from "./index.native76.js";
3
+ function f(r, t = "wei") {
4
+ return o(r, i[t]);
5
+ }
5
6
  export {
6
- e as gweiUnits
7
+ f as formatGwei
7
8
  };
@@ -1,13 +1,7 @@
1
- function a(r, n) {
2
- let t = r.toString();
3
- const i = t.startsWith("-");
4
- i && (t = t.slice(1)), t = t.padStart(n, "0");
5
- let [l, e] = [
6
- t.slice(0, t.length - n),
7
- t.slice(t.length - n)
8
- ];
9
- return e = e.replace(/(0+)$/, ""), `${i ? "-" : ""}${l || "0"}${e ? `.${e}` : ""}`;
10
- }
1
+ const e = {
2
+ ether: -9,
3
+ wei: 9
4
+ };
11
5
  export {
12
- a as formatUnits
6
+ e as gweiUnits
13
7
  };
@@ -1,57 +1,13 @@
1
- import { encode as d } from "./index.native89.js";
2
- import y from "./index.native90.js";
3
- import b from "./index.native91.js";
4
- import { JWSInvalid as r } from "./index.native29.js";
5
- import { encoder as s, concat as u, decoder as h } from "./index.native77.js";
6
- import g from "./index.native92.js";
7
- import H from "./index.native93.js";
8
- import P from "./index.native94.js";
9
- class x {
10
- #r;
11
- #e;
12
- #t;
13
- constructor(e) {
14
- if (!(e instanceof Uint8Array))
15
- throw new TypeError("payload must be an instance of Uint8Array");
16
- this.#r = e;
17
- }
18
- setProtectedHeader(e) {
19
- if (this.#e)
20
- throw new TypeError("setProtectedHeader can only be called once");
21
- return this.#e = e, this;
22
- }
23
- setUnprotectedHeader(e) {
24
- if (this.#t)
25
- throw new TypeError("setUnprotectedHeader can only be called once");
26
- return this.#t = e, this;
27
- }
28
- async sign(e, l) {
29
- if (!this.#e && !this.#t)
30
- throw new r("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
31
- if (!b(this.#e, this.#t))
32
- throw new r("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
33
- const c = {
34
- ...this.#e,
35
- ...this.#t
36
- }, p = H(r, /* @__PURE__ */ new Map([["b64", !0]]), l?.crit, this.#e, c);
37
- let o = !0;
38
- if (p.has("b64") && (o = this.#e.b64, typeof o != "boolean"))
39
- throw new r('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
40
- const { alg: t } = c;
41
- if (typeof t != "string" || !t)
42
- throw new r('JWS "alg" (Algorithm) Header Parameter missing or invalid');
43
- g(t, e, "sign");
44
- let i = this.#r;
45
- o && (i = s.encode(d(i)));
46
- let n;
47
- this.#e ? n = s.encode(d(JSON.stringify(this.#e))) : n = s.encode("");
48
- const f = u(n, s.encode("."), i), m = await P(e, t), w = await y(t, m, f), a = {
49
- signature: d(w),
50
- payload: ""
51
- };
52
- return o && (a.payload = h.decode(i)), this.#t && (a.header = this.#t), this.#e && (a.protected = h.decode(n)), a;
53
- }
1
+ function a(r, n) {
2
+ let t = r.toString();
3
+ const i = t.startsWith("-");
4
+ i && (t = t.slice(1)), t = t.padStart(n, "0");
5
+ let [l, e] = [
6
+ t.slice(0, t.length - n),
7
+ t.slice(t.length - n)
8
+ ];
9
+ return e = e.replace(/(0+)$/, ""), `${i ? "-" : ""}${l || "0"}${e ? `.${e}` : ""}`;
54
10
  }
55
11
  export {
56
- x as FlattenedSign
12
+ a as formatUnits
57
13
  };
@@ -1,13 +1,57 @@
1
- const d = new TextEncoder(), s = new TextDecoder();
2
- function f(...n) {
3
- const c = n.reduce((e, { length: r }) => e + r, 0), t = new Uint8Array(c);
4
- let o = 0;
5
- for (const e of n)
6
- t.set(e, o), o += e.length;
7
- return t;
1
+ import { encode as d } from "./index.native89.js";
2
+ import y from "./index.native90.js";
3
+ import b from "./index.native91.js";
4
+ import { JWSInvalid as r } from "./index.native30.js";
5
+ import { encoder as s, concat as u, decoder as h } from "./index.native78.js";
6
+ import g from "./index.native92.js";
7
+ import H from "./index.native93.js";
8
+ import P from "./index.native94.js";
9
+ class x {
10
+ #r;
11
+ #e;
12
+ #t;
13
+ constructor(e) {
14
+ if (!(e instanceof Uint8Array))
15
+ throw new TypeError("payload must be an instance of Uint8Array");
16
+ this.#r = e;
17
+ }
18
+ setProtectedHeader(e) {
19
+ if (this.#e)
20
+ throw new TypeError("setProtectedHeader can only be called once");
21
+ return this.#e = e, this;
22
+ }
23
+ setUnprotectedHeader(e) {
24
+ if (this.#t)
25
+ throw new TypeError("setUnprotectedHeader can only be called once");
26
+ return this.#t = e, this;
27
+ }
28
+ async sign(e, l) {
29
+ if (!this.#e && !this.#t)
30
+ throw new r("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
31
+ if (!b(this.#e, this.#t))
32
+ throw new r("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
33
+ const c = {
34
+ ...this.#e,
35
+ ...this.#t
36
+ }, p = H(r, /* @__PURE__ */ new Map([["b64", !0]]), l?.crit, this.#e, c);
37
+ let o = !0;
38
+ if (p.has("b64") && (o = this.#e.b64, typeof o != "boolean"))
39
+ throw new r('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
40
+ const { alg: t } = c;
41
+ if (typeof t != "string" || !t)
42
+ throw new r('JWS "alg" (Algorithm) Header Parameter missing or invalid');
43
+ g(t, e, "sign");
44
+ let i = this.#r;
45
+ o && (i = s.encode(d(i)));
46
+ let n;
47
+ this.#e ? n = s.encode(d(JSON.stringify(this.#e))) : n = s.encode("");
48
+ const f = u(n, s.encode("."), i), m = await P(e, t), w = await y(t, m, f), a = {
49
+ signature: d(w),
50
+ payload: ""
51
+ };
52
+ return o && (a.payload = h.decode(i)), this.#t && (a.header = this.#t), this.#e && (a.protected = h.decode(n)), a;
53
+ }
8
54
  }
9
55
  export {
10
- f as concat,
11
- s as decoder,
12
- d as encoder
56
+ x as FlattenedSign
13
57
  };
@@ -1,4 +1,13 @@
1
- const o = (e) => Math.floor(e.getTime() / 1e3);
1
+ const d = new TextEncoder(), s = new TextDecoder();
2
+ function f(...n) {
3
+ const c = n.reduce((e, { length: r }) => e + r, 0), t = new Uint8Array(c);
4
+ let o = 0;
5
+ for (const e of n)
6
+ t.set(e, o), o += e.length;
7
+ return t;
8
+ }
2
9
  export {
3
- o as default
10
+ f as concat,
11
+ s as decoder,
12
+ d as encoder
4
13
  };