@mysten/enoki 0.7.0 → 0.8.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 (49) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/EnokiFlow.js +1 -1
  3. package/dist/cjs/EnokiFlow.js.map +2 -2
  4. package/dist/cjs/index.d.ts +3 -1
  5. package/dist/cjs/index.js +4 -2
  6. package/dist/cjs/index.js.map +2 -2
  7. package/dist/cjs/wallet/initializer.d.ts +11 -0
  8. package/dist/cjs/wallet/initializer.js +41 -0
  9. package/dist/cjs/wallet/initializer.js.map +7 -0
  10. package/dist/cjs/wallet/register.d.ts +7 -0
  11. package/dist/cjs/wallet/register.js +67 -0
  12. package/dist/cjs/wallet/register.js.map +7 -0
  13. package/dist/cjs/wallet/state.d.ts +12 -37
  14. package/dist/cjs/wallet/state.js +79 -198
  15. package/dist/cjs/wallet/state.js.map +2 -2
  16. package/dist/cjs/wallet/types.d.ts +61 -22
  17. package/dist/cjs/wallet/types.js.map +1 -1
  18. package/dist/cjs/wallet/utils.d.ts +1 -1
  19. package/dist/cjs/wallet/utils.js.map +1 -1
  20. package/dist/cjs/wallet/{index.d.ts → wallet.d.ts} +3 -21
  21. package/dist/cjs/wallet/wallet.js +424 -0
  22. package/dist/cjs/wallet/wallet.js.map +7 -0
  23. package/dist/esm/EnokiFlow.js +1 -1
  24. package/dist/esm/EnokiFlow.js.map +2 -2
  25. package/dist/esm/index.d.ts +3 -1
  26. package/dist/esm/index.js +3 -1
  27. package/dist/esm/index.js.map +2 -2
  28. package/dist/esm/wallet/initializer.d.ts +11 -0
  29. package/dist/esm/wallet/initializer.js +21 -0
  30. package/dist/esm/wallet/initializer.js.map +7 -0
  31. package/dist/esm/wallet/register.d.ts +7 -0
  32. package/dist/esm/wallet/register.js +47 -0
  33. package/dist/esm/wallet/register.js.map +7 -0
  34. package/dist/esm/wallet/state.d.ts +12 -37
  35. package/dist/esm/wallet/state.js +81 -200
  36. package/dist/esm/wallet/state.js.map +2 -2
  37. package/dist/esm/wallet/types.d.ts +61 -22
  38. package/dist/esm/wallet/utils.d.ts +1 -1
  39. package/dist/esm/wallet/utils.js.map +1 -1
  40. package/dist/esm/wallet/{index.d.ts → wallet.d.ts} +3 -21
  41. package/dist/esm/wallet/wallet.js +402 -0
  42. package/dist/esm/wallet/wallet.js.map +7 -0
  43. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +5 -5
  46. package/dist/cjs/wallet/index.js +0 -342
  47. package/dist/cjs/wallet/index.js.map +0 -7
  48. package/dist/esm/wallet/index.js +0 -321
  49. package/dist/esm/wallet/index.js.map +0 -7
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
33
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
34
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
35
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
36
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
37
+ var wallet_exports = {};
38
+ __export(wallet_exports, {
39
+ EnokiWallet: () => EnokiWallet
40
+ });
41
+ module.exports = __toCommonJS(wallet_exports);
42
+ var import_transactions = require("@mysten/sui/transactions");
43
+ var import_utils = require("@mysten/sui/utils");
44
+ var import_wallet_standard = require("@mysten/wallet-standard");
45
+ var import_mitt = __toESM(require("mitt"));
46
+ var import_feature = require("./feature.js");
47
+ var import_zklogin = require("@mysten/sui/zklogin");
48
+ var import_webcrypto = require("@mysten/signers/webcrypto");
49
+ var import_idb_keyval = require("idb-keyval");
50
+ var import_EnokiClient = require("../EnokiClient/index.js");
51
+ var import_EnokiKeypair = require("../EnokiKeypair.js");
52
+ var import_state = require("./state.js");
53
+ var _events, _accounts, _name, _icon, _enokiClient, _state, _provider, _clientId, _redirectUrl, _extraParams, _getCurrentNetwork, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _getMetadata, _on, _connect, _disconnect, _EnokiWallet_instances, getAuthorizedAccounts_fn, getProof_fn, getKeypair_fn, getSignerContext_fn, createSession_fn, createAuthorizationURL_fn, handleAuthCallback_fn;
54
+ class EnokiWallet {
55
+ constructor({
56
+ name,
57
+ icon,
58
+ provider,
59
+ clientId,
60
+ redirectUrl,
61
+ extraParams,
62
+ windowFeatures,
63
+ getCurrentNetwork,
64
+ apiKey,
65
+ apiUrl,
66
+ clients
67
+ }) {
68
+ __privateAdd(this, _EnokiWallet_instances);
69
+ __privateAdd(this, _events);
70
+ __privateAdd(this, _accounts);
71
+ __privateAdd(this, _name);
72
+ __privateAdd(this, _icon);
73
+ __privateAdd(this, _enokiClient);
74
+ __privateAdd(this, _state);
75
+ __privateAdd(this, _provider);
76
+ __privateAdd(this, _clientId);
77
+ __privateAdd(this, _redirectUrl);
78
+ __privateAdd(this, _extraParams);
79
+ __privateAdd(this, _getCurrentNetwork);
80
+ __privateAdd(this, _windowFeatures);
81
+ __privateAdd(this, _signTransaction, async ({ transaction, chain, account, signal }) => {
82
+ signal?.throwIfAborted();
83
+ const { client, keypair } = await __privateMethod(this, _EnokiWallet_instances, getSignerContext_fn).call(this, chain);
84
+ const parsedTransaction = import_transactions.Transaction.from(await transaction.toJSON());
85
+ const suiAddress = keypair.toSuiAddress();
86
+ if (suiAddress !== account.address) {
87
+ throw new Error(
88
+ `The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`
89
+ );
90
+ }
91
+ parsedTransaction.setSenderIfNotSet(suiAddress);
92
+ return keypair.signTransaction(await parsedTransaction.build({ client }));
93
+ });
94
+ __privateAdd(this, _signAndExecuteTransaction, async ({
95
+ transaction,
96
+ chain,
97
+ account,
98
+ signal
99
+ }) => {
100
+ signal?.throwIfAborted();
101
+ const { client, keypair } = await __privateMethod(this, _EnokiWallet_instances, getSignerContext_fn).call(this, chain);
102
+ const parsedTransaction = import_transactions.Transaction.from(await transaction.toJSON());
103
+ const bytes = await parsedTransaction.build({ client });
104
+ const suiAddress = keypair.toSuiAddress();
105
+ if (suiAddress !== account.address) {
106
+ throw new Error(
107
+ `The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`
108
+ );
109
+ }
110
+ parsedTransaction.setSenderIfNotSet(suiAddress);
111
+ const result = await keypair.signAndExecuteTransaction({
112
+ transaction: parsedTransaction,
113
+ client
114
+ });
115
+ return {
116
+ bytes: (0, import_utils.toBase64)(bytes),
117
+ signature: result.signatures[0],
118
+ digest: result.digest,
119
+ effects: (0, import_utils.toBase64)(result.effects.bcs)
120
+ };
121
+ });
122
+ __privateAdd(this, _signPersonalMessage, async ({ message, account, chain }) => {
123
+ const { keypair } = await __privateMethod(this, _EnokiWallet_instances, getSignerContext_fn).call(this, chain);
124
+ const suiAddress = keypair.toSuiAddress();
125
+ if (suiAddress !== account.address) {
126
+ throw new Error(
127
+ `The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`
128
+ );
129
+ }
130
+ return keypair.signPersonalMessage(message);
131
+ });
132
+ __privateAdd(this, _getMetadata, () => {
133
+ const sessionContext = __privateGet(this, _state).getSessionContext(__privateGet(this, _getCurrentNetwork).call(this));
134
+ const session = sessionContext?.$zkLoginSession.get();
135
+ const decodedJwt = session?.value?.jwt ? (0, import_zklogin.decodeJwt)(session.value.jwt) : void 0;
136
+ return {
137
+ provider: __privateGet(this, _provider),
138
+ activeSession: decodedJwt ? { decodedJwt } : void 0
139
+ };
140
+ });
141
+ __privateAdd(this, _on, (event, listener) => {
142
+ __privateGet(this, _events).on(event, listener);
143
+ return () => __privateGet(this, _events).off(event, listener);
144
+ });
145
+ __privateAdd(this, _connect, async (input) => {
146
+ if (input?.silent || __privateGet(this, _accounts).length > 0) {
147
+ return { accounts: __privateGet(this, _accounts) };
148
+ }
149
+ const currentNetwork = __privateGet(this, _getCurrentNetwork).call(this);
150
+ await __privateMethod(this, _EnokiWallet_instances, createSession_fn).call(this, { network: currentNetwork });
151
+ __privateSet(this, _accounts, __privateMethod(this, _EnokiWallet_instances, getAuthorizedAccounts_fn).call(this));
152
+ __privateGet(this, _events).emit("change", { accounts: __privateGet(this, _accounts) });
153
+ return { accounts: __privateGet(this, _accounts) };
154
+ });
155
+ __privateAdd(this, _disconnect, async () => {
156
+ await __privateGet(this, _state).logout();
157
+ __privateSet(this, _accounts, []);
158
+ __privateGet(this, _events).emit("change", { accounts: __privateGet(this, _accounts) });
159
+ });
160
+ __privateSet(this, _events, (0, import_mitt.default)());
161
+ __privateSet(this, _name, name);
162
+ __privateSet(this, _icon, icon);
163
+ __privateSet(this, _enokiClient, new import_EnokiClient.EnokiClient({ apiKey, apiUrl }));
164
+ __privateSet(this, _state, new import_state.EnokiWalletState({ apiKey, clientId, clients }));
165
+ __privateSet(this, _provider, provider);
166
+ __privateSet(this, _clientId, clientId);
167
+ __privateSet(this, _redirectUrl, redirectUrl || window.location.href.split("#")[0]);
168
+ __privateSet(this, _extraParams, extraParams);
169
+ __privateSet(this, _windowFeatures, windowFeatures);
170
+ __privateSet(this, _getCurrentNetwork, getCurrentNetwork);
171
+ __privateSet(this, _accounts, __privateMethod(this, _EnokiWallet_instances, getAuthorizedAccounts_fn).call(this));
172
+ }
173
+ get name() {
174
+ return __privateGet(this, _name);
175
+ }
176
+ get provider() {
177
+ return __privateGet(this, _provider);
178
+ }
179
+ get icon() {
180
+ return __privateGet(this, _icon);
181
+ }
182
+ get version() {
183
+ return "1.0.0";
184
+ }
185
+ get chains() {
186
+ return [...__privateGet(this, _state).sessionContextByNetwork.keys()].map(
187
+ (network) => `sui:${network}`
188
+ );
189
+ }
190
+ get accounts() {
191
+ return __privateGet(this, _accounts);
192
+ }
193
+ get features() {
194
+ return {
195
+ [import_wallet_standard.StandardConnect]: {
196
+ version: "1.0.0",
197
+ connect: __privateGet(this, _connect)
198
+ },
199
+ [import_wallet_standard.StandardDisconnect]: {
200
+ version: "1.0.0",
201
+ disconnect: __privateGet(this, _disconnect)
202
+ },
203
+ [import_wallet_standard.StandardEvents]: {
204
+ version: "1.0.0",
205
+ on: __privateGet(this, _on)
206
+ },
207
+ [import_wallet_standard.SuiSignTransaction]: {
208
+ version: "2.0.0",
209
+ signTransaction: __privateGet(this, _signTransaction)
210
+ },
211
+ [import_wallet_standard.SuiSignAndExecuteTransaction]: {
212
+ version: "2.0.0",
213
+ signAndExecuteTransaction: __privateGet(this, _signAndExecuteTransaction)
214
+ },
215
+ [import_wallet_standard.SuiSignPersonalMessage]: {
216
+ version: "1.1.0",
217
+ signPersonalMessage: __privateGet(this, _signPersonalMessage)
218
+ },
219
+ [import_feature.EnokiGetMetadata]: {
220
+ version: "1.0.0",
221
+ getMetadata: __privateGet(this, _getMetadata)
222
+ }
223
+ };
224
+ }
225
+ }
226
+ _events = new WeakMap();
227
+ _accounts = new WeakMap();
228
+ _name = new WeakMap();
229
+ _icon = new WeakMap();
230
+ _enokiClient = new WeakMap();
231
+ _state = new WeakMap();
232
+ _provider = new WeakMap();
233
+ _clientId = new WeakMap();
234
+ _redirectUrl = new WeakMap();
235
+ _extraParams = new WeakMap();
236
+ _getCurrentNetwork = new WeakMap();
237
+ _windowFeatures = new WeakMap();
238
+ _signTransaction = new WeakMap();
239
+ _signAndExecuteTransaction = new WeakMap();
240
+ _signPersonalMessage = new WeakMap();
241
+ _getMetadata = new WeakMap();
242
+ _on = new WeakMap();
243
+ _connect = new WeakMap();
244
+ _disconnect = new WeakMap();
245
+ _EnokiWallet_instances = new WeakSet();
246
+ getAuthorizedAccounts_fn = function() {
247
+ const { address, publicKey } = __privateGet(this, _state).zkLoginState.get();
248
+ if (address && publicKey) {
249
+ return [
250
+ new import_wallet_standard.ReadonlyWalletAccount({
251
+ address,
252
+ chains: this.chains,
253
+ icon: this.icon,
254
+ features: [import_wallet_standard.SuiSignPersonalMessage, import_wallet_standard.SuiSignTransaction, import_wallet_standard.SuiSignAndExecuteTransaction],
255
+ publicKey: (0, import_utils.fromBase64)(publicKey)
256
+ })
257
+ ];
258
+ }
259
+ return [];
260
+ };
261
+ getProof_fn = async function(sessionContext) {
262
+ const zkp = await __privateGet(this, _state).getSession(sessionContext);
263
+ if (zkp?.proof) {
264
+ if (zkp.expiresAt && Date.now() > zkp.expiresAt) {
265
+ throw new Error("Stored proof is expired.");
266
+ }
267
+ return zkp.proof;
268
+ }
269
+ if (!zkp?.jwt) {
270
+ throw new Error("Missing required parameters for proof generation");
271
+ }
272
+ const storedNativeSigner = await (0, import_idb_keyval.get)(
273
+ "ephemeralKeyPair",
274
+ sessionContext.idbStore
275
+ );
276
+ if (!storedNativeSigner) {
277
+ throw new Error("Native signer not found in store.");
278
+ }
279
+ const ephemeralKeyPair = import_webcrypto.WebCryptoSigner.import(storedNativeSigner);
280
+ const proof = await __privateGet(this, _enokiClient).createZkLoginZkp({
281
+ network: sessionContext.client.network,
282
+ jwt: zkp.jwt,
283
+ maxEpoch: zkp.maxEpoch,
284
+ randomness: zkp.randomness,
285
+ ephemeralPublicKey: ephemeralKeyPair.getPublicKey()
286
+ });
287
+ await __privateGet(this, _state).setSession(sessionContext, { ...zkp, proof });
288
+ return proof;
289
+ };
290
+ getKeypair_fn = async function(sessionContext) {
291
+ await __privateMethod(this, _EnokiWallet_instances, getProof_fn).call(this, sessionContext);
292
+ const zkp = await __privateGet(this, _state).getSession(sessionContext);
293
+ const { address } = __privateGet(this, _state).zkLoginState.get();
294
+ if (!address || !zkp || !zkp.proof) {
295
+ throw new Error("Missing required data for keypair generation.");
296
+ }
297
+ if (Date.now() > zkp.expiresAt) {
298
+ throw new Error("Stored proof is expired.");
299
+ }
300
+ const storedNativeSigner = await (0, import_idb_keyval.get)(
301
+ "ephemeralKeyPair",
302
+ sessionContext.idbStore
303
+ );
304
+ if (!storedNativeSigner) {
305
+ throw new Error("Native signer not found in store.");
306
+ }
307
+ const ephemeralKeypair = import_webcrypto.WebCryptoSigner.import(storedNativeSigner);
308
+ return new import_EnokiKeypair.EnokiKeypair({
309
+ address,
310
+ ephemeralKeypair,
311
+ maxEpoch: zkp.maxEpoch,
312
+ proof: zkp.proof
313
+ });
314
+ };
315
+ getSignerContext_fn = async function(chain) {
316
+ const sessionContext = chain ? __privateGet(this, _state).getSessionContext(chain.split(":")[1]) : null;
317
+ if (!sessionContext) {
318
+ throw new Error(
319
+ `A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`
320
+ );
321
+ }
322
+ const zkLoginSession = await __privateGet(this, _state).getSession(sessionContext);
323
+ if (!zkLoginSession) {
324
+ await __privateMethod(this, _EnokiWallet_instances, createSession_fn).call(this, { network: sessionContext.client.network });
325
+ }
326
+ const keypair = await __privateMethod(this, _EnokiWallet_instances, getKeypair_fn).call(this, sessionContext);
327
+ return { client: sessionContext.client, keypair };
328
+ };
329
+ createSession_fn = async function({ network }) {
330
+ const popup = window.open(
331
+ void 0,
332
+ "_blank",
333
+ typeof __privateGet(this, _windowFeatures) === "function" ? __privateGet(this, _windowFeatures).call(this) : __privateGet(this, _windowFeatures)
334
+ );
335
+ if (!popup) {
336
+ throw new Error("Failed to open popup");
337
+ }
338
+ const sessionContext = __privateGet(this, _state).getSessionContext(network);
339
+ popup.location = await __privateMethod(this, _EnokiWallet_instances, createAuthorizationURL_fn).call(this, sessionContext);
340
+ return await new Promise((resolve, reject) => {
341
+ const interval = setInterval(() => {
342
+ try {
343
+ if (popup.closed) {
344
+ clearInterval(interval);
345
+ reject(new Error("Popup closed"));
346
+ }
347
+ if (!popup.location.hash) {
348
+ return;
349
+ }
350
+ } catch (e) {
351
+ return;
352
+ }
353
+ clearInterval(interval);
354
+ __privateMethod(this, _EnokiWallet_instances, handleAuthCallback_fn).call(this, { hash: popup.location.hash, sessionContext }).then(
355
+ () => resolve(),
356
+ reject
357
+ );
358
+ try {
359
+ popup.close();
360
+ } catch (e) {
361
+ console.error(e);
362
+ }
363
+ }, 16);
364
+ });
365
+ };
366
+ createAuthorizationURL_fn = async function(sessionContext) {
367
+ const ephemeralKeyPair = await import_webcrypto.WebCryptoSigner.generate();
368
+ const { nonce, randomness, maxEpoch, estimatedExpiration } = await __privateGet(this, _enokiClient).createZkLoginNonce({
369
+ network: sessionContext.client.network,
370
+ ephemeralPublicKey: ephemeralKeyPair.getPublicKey()
371
+ });
372
+ const params = new URLSearchParams({
373
+ ...__privateGet(this, _extraParams),
374
+ nonce,
375
+ client_id: __privateGet(this, _clientId),
376
+ redirect_uri: __privateGet(this, _redirectUrl),
377
+ response_type: "id_token",
378
+ scope: ["openid", ...__privateGet(this, _extraParams)?.scope ? __privateGet(this, _extraParams).scope.split(" ") : []].filter(Boolean).join(" ")
379
+ });
380
+ let oauthUrl;
381
+ switch (__privateGet(this, _provider)) {
382
+ case "google":
383
+ oauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
384
+ break;
385
+ case "facebook":
386
+ oauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;
387
+ break;
388
+ case "twitch":
389
+ params.set("force_verify", "true");
390
+ oauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;
391
+ break;
392
+ default:
393
+ throw new Error(`Invalid provider: ${__privateGet(this, _provider)}`);
394
+ }
395
+ await (0, import_idb_keyval.set)("ephemeralKeyPair", ephemeralKeyPair.export(), sessionContext.idbStore);
396
+ await __privateGet(this, _state).setSession(sessionContext, {
397
+ expiresAt: estimatedExpiration,
398
+ maxEpoch,
399
+ randomness
400
+ });
401
+ return oauthUrl;
402
+ };
403
+ handleAuthCallback_fn = async function({
404
+ hash,
405
+ sessionContext
406
+ }) {
407
+ const params = new URLSearchParams(hash.startsWith("#") ? hash.slice(1) : hash);
408
+ const zkp = await __privateGet(this, _state).getSession(sessionContext);
409
+ if (!zkp?.maxEpoch || !zkp.randomness) {
410
+ throw new Error(
411
+ "Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this."
412
+ );
413
+ }
414
+ const jwt = params.get("id_token");
415
+ if (!jwt) {
416
+ throw new Error("Missing ID Token");
417
+ }
418
+ (0, import_zklogin.decodeJwt)(jwt);
419
+ const { address, publicKey } = await __privateGet(this, _enokiClient).getZkLogin({ jwt });
420
+ __privateGet(this, _state).zkLoginState.set({ address, publicKey });
421
+ await __privateGet(this, _state).setSession(sessionContext, { ...zkp, jwt });
422
+ return params.get("state");
423
+ };
424
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/wallet.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport type {\n\tIdentifierString,\n\tStandardConnectFeature,\n\tStandardConnectMethod,\n\tStandardDisconnectFeature,\n\tStandardDisconnectMethod,\n\tStandardEventsFeature,\n\tStandardEventsOnMethod,\n\tSuiSignAndExecuteTransactionFeature,\n\tSuiSignAndExecuteTransactionMethod,\n\tSuiSignPersonalMessageFeature,\n\tSuiSignPersonalMessageMethod,\n\tSuiSignTransactionFeature,\n\tSuiSignTransactionMethod,\n\tWallet,\n} from '@mysten/wallet-standard';\nimport {\n\tReadonlyWalletAccount,\n\tStandardConnect,\n\tStandardDisconnect,\n\tStandardEvents,\n\tSuiSignAndExecuteTransaction,\n\tSuiSignPersonalMessage,\n\tSuiSignTransaction,\n} from '@mysten/wallet-standard';\nimport type { Emitter } from 'mitt';\nimport mitt from 'mitt';\n\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport type { EnokiWalletOptions, WalletEventsMap, EnokiSessionContext } from './types.js';\nimport type { EnokiGetMetadataFeature, EnokiGetMetadataMethod } from './feature.js';\nimport { EnokiGetMetadata } from './feature.js';\nimport type { Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { get, set } from 'idb-keyval';\n\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\n\nimport { EnokiWalletState } from './state.js';\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#icon: Wallet['icon'];\n\t#enokiClient: EnokiClient;\n\t#state: EnokiWalletState;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string;\n\t#extraParams: Record<string, string> | undefined;\n\t#getCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n\t#windowFeatures?: string | (() => string);\n\n\tget name() {\n\t\treturn this.#name;\n\t}\n\n\tget provider() {\n\t\treturn this.#provider;\n\t}\n\n\tget icon() {\n\t\treturn this.#icon;\n\t}\n\n\tget version() {\n\t\treturn '1.0.0' as const;\n\t}\n\n\tget chains() {\n\t\treturn [...this.#state.sessionContextByNetwork.keys()].map(\n\t\t\t(network) => `sui:${network}` as const,\n\t\t);\n\t}\n\n\tget accounts() {\n\t\treturn this.#accounts;\n\t}\n\n\tget features(): StandardConnectFeature &\n\t\tStandardDisconnectFeature &\n\t\tStandardEventsFeature &\n\t\tSuiSignTransactionFeature &\n\t\tSuiSignAndExecuteTransactionFeature &\n\t\tSuiSignPersonalMessageFeature &\n\t\tEnokiGetMetadataFeature {\n\t\treturn {\n\t\t\t[StandardConnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tconnect: this.#connect,\n\t\t\t},\n\t\t\t[StandardDisconnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdisconnect: this.#disconnect,\n\t\t\t},\n\t\t\t[StandardEvents]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\ton: this.#on,\n\t\t\t},\n\t\t\t[SuiSignTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignTransaction: this.#signTransaction,\n\t\t\t},\n\t\t\t[SuiSignAndExecuteTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignAndExecuteTransaction: this.#signAndExecuteTransaction,\n\t\t\t},\n\t\t\t[SuiSignPersonalMessage]: {\n\t\t\t\tversion: '1.1.0',\n\t\t\t\tsignPersonalMessage: this.#signPersonalMessage,\n\t\t\t},\n\t\t\t[EnokiGetMetadata]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetMetadata: this.#getMetadata,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\twindowFeatures,\n\t\tgetCurrentNetwork,\n\t\tapiKey,\n\t\tapiUrl,\n\t\tclients,\n\t}: EnokiWalletOptions) {\n\t\tthis.#events = mitt();\n\t\tthis.#name = name;\n\t\tthis.#icon = icon;\n\t\tthis.#enokiClient = new EnokiClient({ apiKey, apiUrl });\n\t\tthis.#state = new EnokiWalletState({ apiKey, clientId, clients });\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl || window.location.href.split('#')[0];\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\t\tthis.#getCurrentNetwork = getCurrentNetwork;\n\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account, signal }) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\t\treturn keypair.signTransaction(await parsedTransaction.build({ client }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t\tsignal,\n\t}) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst bytes = await parsedTransaction.build({ client });\n\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\n\t\tconst result = await keypair.signAndExecuteTransaction({\n\t\t\ttransaction: parsedTransaction,\n\t\t\tclient,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: result.signatures[0],\n\t\t\tdigest: result.digest,\n\t\t\teffects: toBase64(result.effects.bcs!),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tconst { keypair } = await this.#getSignerContext(chain);\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn keypair.signPersonalMessage(message);\n\t};\n\n\t#getMetadata: EnokiGetMetadataMethod = () => {\n\t\tconst sessionContext = this.#state.getSessionContext(this.#getCurrentNetwork());\n\t\tconst session = sessionContext?.$zkLoginSession.get();\n\t\tconst decodedJwt = session?.value?.jwt ? decodeJwt(session.value.jwt) : undefined;\n\n\t\treturn {\n\t\t\tprovider: this.#provider,\n\t\t\tactiveSession: decodedJwt ? { decodedJwt } : undefined,\n\t\t};\n\t};\n\n\t#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\tif (input?.silent || this.#accounts.length > 0) {\n\t\t\treturn { accounts: this.#accounts };\n\t\t}\n\n\t\tconst currentNetwork = this.#getCurrentNetwork();\n\t\tawait this.#createSession({ network: currentNetwork });\n\n\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\n\t\treturn { accounts: this.#accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#state.logout();\n\n\t\tthis.#accounts = [];\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t};\n\n\t#getAuthorizedAccounts() {\n\t\tconst { address, publicKey } = this.#state.zkLoginState.get();\n\t\tif (address && publicKey) {\n\t\t\treturn [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress,\n\t\t\t\t\tchains: this.chains,\n\t\t\t\t\ticon: this.icon,\n\t\t\t\t\tfeatures: [SuiSignPersonalMessage, SuiSignTransaction, SuiSignAndExecuteTransaction],\n\t\t\t\t\tpublicKey: fromBase64(publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t}\n\n\tasync #getProof(sessionContext: EnokiSessionContext) {\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (zkp?.proof) {\n\t\t\tif (zkp.expiresAt && Date.now() > zkp.expiresAt) {\n\t\t\t\tthrow new Error('Stored proof is expired.');\n\t\t\t}\n\n\t\t\treturn zkp.proof;\n\t\t}\n\n\t\tif (!zkp?.jwt) {\n\t\t\tthrow new Error('Missing required parameters for proof generation');\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.idbStore,\n\t\t);\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst ephemeralKeyPair = WebCryptoSigner.import(storedNativeSigner);\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\tjwt: zkp.jwt,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\trandomness: zkp.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#state.setSession(sessionContext, { ...zkp, proof });\n\t\treturn proof;\n\t}\n\n\tasync #getKeypair(sessionContext: EnokiSessionContext) {\n\t\tawait this.#getProof(sessionContext);\n\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tconst { address } = this.#state.zkLoginState.get();\n\t\tif (!address || !zkp || !zkp.proof) {\n\t\t\tthrow new Error('Missing required data for keypair generation.');\n\t\t}\n\n\t\tif (Date.now() > zkp.expiresAt) {\n\t\t\tthrow new Error('Stored proof is expired.');\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.idbStore,\n\t\t);\n\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress,\n\t\t\tephemeralKeypair,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\tproof: zkp.proof,\n\t\t});\n\t}\n\n\tasync #getSignerContext(chain?: IdentifierString) {\n\t\tconst sessionContext = chain ? this.#state.getSessionContext(chain.split(':')[1]) : null;\n\t\tif (!sessionContext) {\n\t\t\tthrow new Error(\n\t\t\t\t`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`,\n\t\t\t);\n\t\t}\n\n\t\tconst zkLoginSession = await this.#state.getSession(sessionContext);\n\t\tif (!zkLoginSession) {\n\t\t\tawait this.#createSession({ network: sessionContext.client.network });\n\t\t}\n\n\t\tconst keypair = await this.#getKeypair(sessionContext);\n\n\t\treturn { client: sessionContext.client, keypair };\n\t}\n\n\tasync #createSession({ network }: { network: Experimental_SuiClientTypes.Network }) {\n\t\tconst popup = window.open(\n\t\t\tundefined,\n\t\t\t'_blank',\n\t\t\ttypeof this.#windowFeatures === 'function' ? this.#windowFeatures() : this.#windowFeatures,\n\t\t);\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst sessionContext = this.#state.getSessionContext(network);\n\t\tpopup.location = await this.#createAuthorizationURL(sessionContext);\n\n\t\treturn await new Promise<void>((resolve, reject) => {\n\t\t\tconst interval = setInterval(() => {\n\t\t\t\ttry {\n\t\t\t\t\tif (popup.closed) {\n\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\treject(new Error('Popup closed'));\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!popup.location.hash) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearInterval(interval);\n\n\t\t\t\tthis.#handleAuthCallback({ hash: popup.location.hash, sessionContext }).then(\n\t\t\t\t\t() => resolve(),\n\t\t\t\t\treject,\n\t\t\t\t);\n\n\t\t\t\ttry {\n\t\t\t\t\tpopup.close();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}, 16);\n\t\t});\n\t}\n\n\tasync #createAuthorizationURL(sessionContext: EnokiSessionContext) {\n\t\tconst ephemeralKeyPair = await WebCryptoSigner.generate();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...this.#extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: this.#clientId,\n\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\tscope: ['openid', ...(this.#extraParams?.scope ? this.#extraParams.scope.split(' ') : [])]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (this.#provider) {\n\t\t\tcase 'google':\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'facebook':\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'twitch':\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${this.#provider}`);\n\t\t}\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), sessionContext.idbStore);\n\t\tawait this.#state.setSession(sessionContext, {\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\tasync #handleAuthCallback({\n\t\thash,\n\t\tsessionContext,\n\t}: {\n\t\thash: string;\n\t\tsessionContext: EnokiSessionContext;\n\t}) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (!zkp?.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = params.get('id_token');\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.#state.zkLoginState.set({ address, publicKey });\n\t\tawait this.#state.setSession(sessionContext, { ...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AAA,IAC5C,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO;AACR;AAEM,wBAAmB,eAAC;AAAA,EACzB;AAAA,EACA;AACD,GAGG;AACF,QAAM,SAAS,IAAI,gBAAgB,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI;AAC9E,QAAM,MAAM,MAAM,mBAAK,QAAO,WAAW,cAAc;AAEvD,MAAI,CAAC,KAAK,YAAY,CAAC,IAAI,YAAY;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,MAAM,OAAO,IAAI,UAAU;AACjC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACnC;AAEA,gCAAU,GAAG;AAEb,QAAM,EAAE,SAAS,UAAU,IAAI,MAAM,mBAAK,cAAa,WAAW,EAAE,IAAI,CAAC;AAEzE,qBAAK,QAAO,aAAa,IAAI,EAAE,SAAS,UAAU,CAAC;AACnD,QAAM,mBAAK,QAAO,WAAW,gBAAgB,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5D,SAAO,OAAO,IAAI,OAAO;AAC1B;",
6
+ "names": ["mitt"]
7
+ }
@@ -39,7 +39,7 @@ class EnokiFlow {
39
39
  __privateSet(this, _encryptionKey, config.apiKey);
40
40
  if (config.experimental_nativeCryptoSigner) {
41
41
  __privateSet(this, _useNativeCryptoSigner, true);
42
- __privateSet(this, _idbStore, createStore("enoki", config.apiKey));
42
+ __privateSet(this, _idbStore, createStore(config.apiKey, "enoki"));
43
43
  } else {
44
44
  __privateSet(this, _useNativeCryptoSigner, false);
45
45
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/EnokiFlow.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { decodeSuiPrivateKey } from '@mysten/sui/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport { clear, createStore, get, set } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet } from 'nanostores';\n\nimport type { Encryption } from './encryption.js';\nimport { createDefaultEncryption } from './encryption.js';\nimport type { EnokiClientConfig } from './EnokiClient/index.js';\nimport { EnokiClient } from './EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from './EnokiClient/type.js';\nimport { EnokiKeypair } from './EnokiKeypair.js';\nimport type { SyncStore } from './stores.js';\nimport { createSessionStorage } from './stores.js';\n\n/**\n * @deprecated Use `RegisterEnokiWalletsOptions` instead\n */\nexport type EnokiFlowConfig = EnokiClientConfig &\n\t(\n\t\t| {\n\t\t\t\texperimental_nativeCryptoSigner?: unknown;\n\t\t\t\t/**\n\t\t\t\t * The storage interface to persist Enoki data locally.\n\t\t\t\t * If not provided, it will use a sessionStorage-backed store.\n\t\t\t\t */\n\t\t\t\tstore?: SyncStore;\n\t\t\t\t/**\n\t\t\t\t * The encryption interface that will be used to encrypt data before storing it locally.\n\t\t\t\t * If not provided, it will use a default encryption interface.\n\t\t\t\t */\n\t\t\t\tencryption?: Encryption;\n\t\t }\n\t\t| {\n\t\t\t\tstore?: never;\n\t\t\t\tencryption?: never;\n\t\t\t\t/**\n\t\t\t\t * Enables the new native crypto signer for the EnokiFlow, which is more secure.\n\t\t\t\t */\n\t\t\t\texperimental_nativeCryptoSigner: true;\n\t\t }\n\t);\n\n// State that is not bound to a session, and is encrypted.\nexport interface ZkLoginState {\n\tprovider?: AuthProvider;\n\taddress?: string;\n\tsalt?: string;\n\tpublicKey?: string;\n}\n\n// State that session-bound, and is encrypted in storage.\nexport interface ZkLoginSession {\n\tephemeralKeyPair: string;\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n}\n\nconst createStorageKeys = (apiKey: string) => ({\n\tSTATE: `@enoki/flow/state/${apiKey}`,\n\tSESSION: `@enoki/flow/session/${apiKey}`,\n});\n\n/**\n * @deprecated Use `registerEnokiWallets` instead\n */\nexport class EnokiFlow {\n\t#storageKeys: { STATE: string; SESSION: string };\n\t#enokiClient: EnokiClient;\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\t#store: SyncStore;\n\t#useNativeCryptoSigner: boolean;\n\t#idbStore?: UseStore;\n\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n\t$zkLoginState: WritableAtom<ZkLoginState>;\n\n\tconstructor(config: EnokiFlowConfig) {\n\t\tthis.#enokiClient = new EnokiClient({\n\t\t\tapiKey: config.apiKey,\n\t\t\tapiUrl: config.apiUrl,\n\t\t});\n\t\tthis.#encryptionKey = config.apiKey;\n\n\t\tif (config.experimental_nativeCryptoSigner) {\n\t\t\tthis.#useNativeCryptoSigner = true;\n\t\t\tthis.#idbStore = createStore('enoki', config.apiKey);\n\t\t} else {\n\t\t\tthis.#useNativeCryptoSigner = false;\n\t\t}\n\n\t\tthis.#encryption = config.encryption ?? createDefaultEncryption();\n\t\tthis.#store = config.store ?? createSessionStorage();\n\t\tthis.#storageKeys = createStorageKeys(config.apiKey);\n\n\t\tlet storedState = null;\n\t\ttry {\n\t\t\tconst rawStoredValue = this.#store.get(this.#storageKeys.STATE);\n\t\t\tif (rawStoredValue) {\n\t\t\t\tstoredState = JSON.parse(rawStoredValue);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\n\t\tthis.$zkLoginState = atom(storedState || {});\n\t\tthis.$zkLoginSession = atom({ initialized: false, value: null });\n\n\t\t// Hydrate the session on mount:\n\t\tonMount(this.$zkLoginSession, () => {\n\t\t\tthis.getSession();\n\t\t});\n\n\t\tonSet(this.$zkLoginState, ({ newValue }) => {\n\t\t\tthis.#store.set(this.#storageKeys.STATE, JSON.stringify(newValue));\n\t\t});\n\t}\n\n\tget enokiClient() {\n\t\treturn this.#enokiClient;\n\t}\n\n\tasync createAuthorizationURL(input: {\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl: string;\n\t\tnetwork?: 'mainnet' | 'testnet' | 'devnet';\n\t\textraParams?: Record<string, unknown>;\n\t}) {\n\t\tconst ephemeralKeyPair = this.#useNativeCryptoSigner\n\t\t\t? await WebCryptoSigner.generate()\n\t\t\t: new Ed25519Keypair();\n\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...input.extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: input.clientId,\n\t\t\tredirect_uri: input.redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\t// TODO: Eventually fetch the scopes for this client ID from the Enoki service:\n\t\t\tscope: [\n\t\t\t\t'openid',\n\t\t\t\t// Merge the requested scopes in with the required openid scopes:\n\t\t\t\t...(input.extraParams && 'scope' in input.extraParams\n\t\t\t\t\t? (input.extraParams.scope as string[])\n\t\t\t\t\t: []),\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (input.provider) {\n\t\t\tcase 'google': {\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'facebook': {\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'twitch': {\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${input.provider}`);\n\t\t}\n\n\t\tthis.$zkLoginState.set({ provider: input.provider });\n\t\tif (this.#useNativeCryptoSigner) {\n\t\t\tawait set('ephemeralKeyPair', (ephemeralKeyPair as WebCryptoSigner).export(), this.#idbStore);\n\t\t}\n\n\t\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: this.#useNativeCryptoSigner\n\t\t\t\t? '@@native'\n\t\t\t\t: toBase64(\n\t\t\t\t\t\tdecodeSuiPrivateKey((ephemeralKeyPair as Ed25519Keypair).getSecretKey()).secretKey,\n\t\t\t\t\t),\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\t// TODO: Should our SDK manage this automatically in addition to exposing a method?\n\tasync handleAuthCallback(hash: string = window.location.hash) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\n\t\t// Before we handle the auth redirect and get the state, we need to restore it:\n\t\tconst zkp = await this.getSession();\n\n\t\tif (!zkp || !zkp.ephemeralKeyPair || !zkp.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = params.get('id_token');\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, salt, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.$zkLoginState.set({\n\t\t\t...this.$zkLoginState.get(),\n\t\t\tsalt,\n\t\t\taddress,\n\t\t\tpublicKey,\n\t\t});\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tjwt,\n\t\t});\n\n\t\treturn params.get('state');\n\t}\n\n\tasync #setSession(newValue: ZkLoginSession | null) {\n\t\tif (newValue) {\n\t\t\tconst storedValue = await this.#encryption.encrypt(\n\t\t\t\tthis.#encryptionKey,\n\t\t\t\tJSON.stringify(newValue),\n\t\t\t);\n\n\t\t\tthis.#store.set(this.#storageKeys.SESSION, storedValue);\n\t\t} else {\n\t\t\tthis.#store.delete(this.#storageKeys.SESSION);\n\t\t}\n\n\t\tthis.$zkLoginSession.set({ initialized: true, value: newValue });\n\t}\n\n\tasync getSession() {\n\t\tif (this.$zkLoginSession.get().initialized) {\n\t\t\treturn this.$zkLoginSession.get().value;\n\t\t}\n\n\t\ttry {\n\t\t\tconst storedValue = this.#store.get(this.#storageKeys.SESSION);\n\t\t\tif (!storedValue) return null;\n\n\t\t\tconst state: ZkLoginSession = JSON.parse(\n\t\t\t\tawait this.#encryption.decrypt(this.#encryptionKey, storedValue),\n\t\t\t);\n\n\t\t\t// TODO: Rather than having expiration act as a logout, we should keep the state that still is relevant,\n\t\t\t// and just clear out the expired session, but keep the other zkLogin state.\n\t\t\tif (state?.expiresAt && Date.now() > state.expiresAt) {\n\t\t\t\tawait this.logout();\n\t\t\t} else {\n\t\t\t\tthis.$zkLoginSession.set({ initialized: true, value: state });\n\t\t\t}\n\t\t} catch {\n\t\t\tthis.$zkLoginSession.set({ initialized: true, value: null });\n\t\t}\n\n\t\treturn this.$zkLoginSession.get().value;\n\t}\n\n\tasync logout() {\n\t\tthis.$zkLoginState.set({});\n\t\tthis.#store.delete(this.#storageKeys.STATE);\n\n\t\tif (this.#useNativeCryptoSigner) {\n\t\t\tawait clear(this.#idbStore);\n\t\t}\n\t\tawait this.#setSession(null);\n\t}\n\n\t// TODO: Should this return the proof if it already exists?\n\tasync getProof({ network }: { network?: EnokiNetwork } = {}) {\n\t\tconst zkp = await this.getSession();\n\t\tconst { salt } = this.$zkLoginState.get();\n\n\t\tif (zkp?.proof) {\n\t\t\tif (zkp.expiresAt && Date.now() > zkp.expiresAt) {\n\t\t\t\tthrow new Error('Stored proof is expired.');\n\t\t\t}\n\n\t\t\treturn zkp.proof;\n\t\t}\n\n\t\tif (!salt || !zkp || !zkp.jwt) {\n\t\t\tthrow new Error('Missing required parameters for proof generation');\n\t\t}\n\n\t\tlet storedNativeSigner: ExportedWebCryptoKeypair | undefined = undefined;\n\t\tif (this.#useNativeCryptoSigner && zkp.ephemeralKeyPair === '@@native') {\n\t\t\tstoredNativeSigner = await get('ephemeralKeyPair', this.#idbStore);\n\t\t\tif (!storedNativeSigner) {\n\t\t\t\tthrow new Error('Native signer not found in store.');\n\t\t\t}\n\t\t}\n\n\t\tconst ephemeralKeyPair =\n\t\t\tzkp.ephemeralKeyPair === '@@native'\n\t\t\t\t? WebCryptoSigner.import(storedNativeSigner!)\n\t\t\t\t: Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork,\n\t\t\tjwt: zkp.jwt,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\trandomness: zkp.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tproof,\n\t\t});\n\n\t\treturn proof;\n\t}\n\n\tasync getKeypair({ network }: { network?: EnokiNetwork } = {}) {\n\t\t// Get the proof, so that we ensure it exists in state:\n\t\tawait this.getProof({ network });\n\n\t\tconst zkp = await this.getSession();\n\n\t\t// Check to see if we have the essentials for a keypair:\n\t\tconst { address } = this.$zkLoginState.get();\n\t\tif (!address || !zkp || !zkp.proof) {\n\t\t\tthrow new Error('Missing required data for keypair generation.');\n\t\t}\n\n\t\tif (Date.now() > zkp.expiresAt) {\n\t\t\tthrow new Error('Stored proof is expired.');\n\t\t}\n\n\t\tlet storedNativeSigner: ExportedWebCryptoKeypair | undefined = undefined;\n\t\tif (this.#useNativeCryptoSigner && zkp.ephemeralKeyPair === '@@native') {\n\t\t\tstoredNativeSigner = await get('ephemeralKeyPair', this.#idbStore);\n\t\t\tif (!storedNativeSigner) {\n\t\t\t\tthrow new Error('Native signer not found in store.');\n\t\t\t}\n\t\t}\n\n\t\tconst ephemeralKeypair =\n\t\t\tzkp.ephemeralKeyPair === '@@native'\n\t\t\t\t? WebCryptoSigner.import(storedNativeSigner!)\n\t\t\t\t: Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress,\n\t\t\tephemeralKeypair,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\tproof: zkp.proof,\n\t\t});\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;AAAA;AAIA,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,YAAY,gBAAgB;AACrC,SAAS,iBAAiB;AAG1B,SAAS,OAAO,aAAa,KAAK,WAAW;AAE7C,SAAS,MAAM,SAAS,aAAa;AAGrC,SAAS,+BAA+B;AAExC,SAAS,mBAAmB;AAE5B,SAAS,oBAAoB;AAE7B,SAAS,4BAA4B;AAiDrC,MAAM,oBAAoB,CAAC,YAAoB;AAAA,EAC9C,OAAO,qBAAqB,MAAM;AAAA,EAClC,SAAS,uBAAuB,MAAM;AACvC;AAKO,MAAM,UAAU;AAAA,EAYtB,YAAY,QAAyB;AAZ/B;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,uBAAK,cAAe,IAAI,YAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAE7B,QAAI,OAAO,iCAAiC;AAC3C,yBAAK,wBAAyB;AAC9B,yBAAK,WAAY,YAAY,SAAS,OAAO,MAAM;AAAA,IACpD,OAAO;AACN,yBAAK,wBAAyB;AA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A,IAC3C;AAEA,QAAI,qBAA2D;AAC/D,QAAI,mBAAK,2BAA0B,IAAI,qBAAqB,YAAY;AACvE,2BAAqB,MAAM,IAAI,oBAAoB,mBAAK,UAAS;AACjE,UAAI,CAAC,oBAAoB;AACxB,cAAM,IAAI,MAAM,mCAAmC;AAAA,MACpD;AAAA,IACD;AAEA,UAAM,mBACL,IAAI,qBAAqB,aACtB,gBAAgB,OAAO,kBAAmB,IAC1C,eAAe,cAAc,WAAW,IAAI,gBAAgB,CAAC;AAEjE,WAAO,IAAI,aAAa;AAAA,MACvB;AAAA,MACA;AAAA,MACA,UAAU,IAAI;AAAA,MACd,OAAO,IAAI;AAAA,IACZ,CAAC;AAAA,EACF;AACD;AA9SC;AACA;AACA;AACA;AACA;AACA;AACA;AAPM;AAyKA,gBAAW,eAAC,UAAiC;AAClD,MAAI,UAAU;AACb,UAAM,cAAc,MAAM,mBAAK,aAAY;AAAA,MAC1C,mBAAK;AAAA,MACL,KAAK,UAAU,QAAQ;AAAA,IACxB;AAEA,uBAAK,QAAO,IAAI,mBAAK,cAAa,SAAS,WAAW;AAAA,EACvD,OAAO;AACN,uBAAK,QAAO,OAAO,mBAAK,cAAa,OAAO;AAAA,EAC7C;AAEA,OAAK,gBAAgB,IAAI,EAAE,aAAa,MAAM,OAAO,SAAS,CAAC;AAChE;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { decodeSuiPrivateKey } from '@mysten/sui/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport { clear, createStore, get, set } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet } from 'nanostores';\n\nimport type { Encryption } from './encryption.js';\nimport { createDefaultEncryption } from './encryption.js';\nimport type { EnokiClientConfig } from './EnokiClient/index.js';\nimport { EnokiClient } from './EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from './EnokiClient/type.js';\nimport { EnokiKeypair } from './EnokiKeypair.js';\nimport type { SyncStore } from './stores.js';\nimport { createSessionStorage } from './stores.js';\n\n/**\n * @deprecated Use `RegisterEnokiWalletsOptions` instead\n */\nexport type EnokiFlowConfig = EnokiClientConfig &\n\t(\n\t\t| {\n\t\t\t\texperimental_nativeCryptoSigner?: unknown;\n\t\t\t\t/**\n\t\t\t\t * The storage interface to persist Enoki data locally.\n\t\t\t\t * If not provided, it will use a sessionStorage-backed store.\n\t\t\t\t */\n\t\t\t\tstore?: SyncStore;\n\t\t\t\t/**\n\t\t\t\t * The encryption interface that will be used to encrypt data before storing it locally.\n\t\t\t\t * If not provided, it will use a default encryption interface.\n\t\t\t\t */\n\t\t\t\tencryption?: Encryption;\n\t\t }\n\t\t| {\n\t\t\t\tstore?: never;\n\t\t\t\tencryption?: never;\n\t\t\t\t/**\n\t\t\t\t * Enables the new native crypto signer for the EnokiFlow, which is more secure.\n\t\t\t\t */\n\t\t\t\texperimental_nativeCryptoSigner: true;\n\t\t }\n\t);\n\n// State that is not bound to a session, and is encrypted.\nexport interface ZkLoginState {\n\tprovider?: AuthProvider;\n\taddress?: string;\n\tsalt?: string;\n\tpublicKey?: string;\n}\n\n// State that session-bound, and is encrypted in storage.\nexport interface ZkLoginSession {\n\tephemeralKeyPair: string;\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n}\n\nconst createStorageKeys = (apiKey: string) => ({\n\tSTATE: `@enoki/flow/state/${apiKey}`,\n\tSESSION: `@enoki/flow/session/${apiKey}`,\n});\n\n/**\n * @deprecated Use `registerEnokiWallets` instead\n */\nexport class EnokiFlow {\n\t#storageKeys: { STATE: string; SESSION: string };\n\t#enokiClient: EnokiClient;\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\t#store: SyncStore;\n\t#useNativeCryptoSigner: boolean;\n\t#idbStore?: UseStore;\n\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n\t$zkLoginState: WritableAtom<ZkLoginState>;\n\n\tconstructor(config: EnokiFlowConfig) {\n\t\tthis.#enokiClient = new EnokiClient({\n\t\t\tapiKey: config.apiKey,\n\t\t\tapiUrl: config.apiUrl,\n\t\t});\n\t\tthis.#encryptionKey = config.apiKey;\n\n\t\tif (config.experimental_nativeCryptoSigner) {\n\t\t\tthis.#useNativeCryptoSigner = true;\n\t\t\tthis.#idbStore = createStore(config.apiKey, 'enoki');\n\t\t} else {\n\t\t\tthis.#useNativeCryptoSigner = false;\n\t\t}\n\n\t\tthis.#encryption = config.encryption ?? createDefaultEncryption();\n\t\tthis.#store = config.store ?? createSessionStorage();\n\t\tthis.#storageKeys = createStorageKeys(config.apiKey);\n\n\t\tlet storedState = null;\n\t\ttry {\n\t\t\tconst rawStoredValue = this.#store.get(this.#storageKeys.STATE);\n\t\t\tif (rawStoredValue) {\n\t\t\t\tstoredState = JSON.parse(rawStoredValue);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\n\t\tthis.$zkLoginState = atom(storedState || {});\n\t\tthis.$zkLoginSession = atom({ initialized: false, value: null });\n\n\t\t// Hydrate the session on mount:\n\t\tonMount(this.$zkLoginSession, () => {\n\t\t\tthis.getSession();\n\t\t});\n\n\t\tonSet(this.$zkLoginState, ({ newValue }) => {\n\t\t\tthis.#store.set(this.#storageKeys.STATE, JSON.stringify(newValue));\n\t\t});\n\t}\n\n\tget enokiClient() {\n\t\treturn this.#enokiClient;\n\t}\n\n\tasync createAuthorizationURL(input: {\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl: string;\n\t\tnetwork?: 'mainnet' | 'testnet' | 'devnet';\n\t\textraParams?: Record<string, unknown>;\n\t}) {\n\t\tconst ephemeralKeyPair = this.#useNativeCryptoSigner\n\t\t\t? await WebCryptoSigner.generate()\n\t\t\t: new Ed25519Keypair();\n\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...input.extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: input.clientId,\n\t\t\tredirect_uri: input.redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\t// TODO: Eventually fetch the scopes for this client ID from the Enoki service:\n\t\t\tscope: [\n\t\t\t\t'openid',\n\t\t\t\t// Merge the requested scopes in with the required openid scopes:\n\t\t\t\t...(input.extraParams && 'scope' in input.extraParams\n\t\t\t\t\t? (input.extraParams.scope as string[])\n\t\t\t\t\t: []),\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (input.provider) {\n\t\t\tcase 'google': {\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'facebook': {\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'twitch': {\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${input.provider}`);\n\t\t}\n\n\t\tthis.$zkLoginState.set({ provider: input.provider });\n\t\tif (this.#useNativeCryptoSigner) {\n\t\t\tawait set('ephemeralKeyPair', (ephemeralKeyPair as WebCryptoSigner).export(), this.#idbStore);\n\t\t}\n\n\t\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: this.#useNativeCryptoSigner\n\t\t\t\t? '@@native'\n\t\t\t\t: toBase64(\n\t\t\t\t\t\tdecodeSuiPrivateKey((ephemeralKeyPair as Ed25519Keypair).getSecretKey()).secretKey,\n\t\t\t\t\t),\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\t// TODO: Should our SDK manage this automatically in addition to exposing a method?\n\tasync handleAuthCallback(hash: string = window.location.hash) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\n\t\t// Before we handle the auth redirect and get the state, we need to restore it:\n\t\tconst zkp = await this.getSession();\n\n\t\tif (!zkp || !zkp.ephemeralKeyPair || !zkp.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = params.get('id_token');\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, salt, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.$zkLoginState.set({\n\t\t\t...this.$zkLoginState.get(),\n\t\t\tsalt,\n\t\t\taddress,\n\t\t\tpublicKey,\n\t\t});\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tjwt,\n\t\t});\n\n\t\treturn params.get('state');\n\t}\n\n\tasync #setSession(newValue: ZkLoginSession | null) {\n\t\tif (newValue) {\n\t\t\tconst storedValue = await this.#encryption.encrypt(\n\t\t\t\tthis.#encryptionKey,\n\t\t\t\tJSON.stringify(newValue),\n\t\t\t);\n\n\t\t\tthis.#store.set(this.#storageKeys.SESSION, storedValue);\n\t\t} else {\n\t\t\tthis.#store.delete(this.#storageKeys.SESSION);\n\t\t}\n\n\t\tthis.$zkLoginSession.set({ initialized: true, value: newValue });\n\t}\n\n\tasync getSession() {\n\t\tif (this.$zkLoginSession.get().initialized) {\n\t\t\treturn this.$zkLoginSession.get().value;\n\t\t}\n\n\t\ttry {\n\t\t\tconst storedValue = this.#store.get(this.#storageKeys.SESSION);\n\t\t\tif (!storedValue) return null;\n\n\t\t\tconst state: ZkLoginSession = JSON.parse(\n\t\t\t\tawait this.#encryption.decrypt(this.#encryptionKey, storedValue),\n\t\t\t);\n\n\t\t\t// TODO: Rather than having expiration act as a logout, we should keep the state that still is relevant,\n\t\t\t// and just clear out the expired session, but keep the other zkLogin state.\n\t\t\tif (state?.expiresAt && Date.now() > state.expiresAt) {\n\t\t\t\tawait this.logout();\n\t\t\t} else {\n\t\t\t\tthis.$zkLoginSession.set({ initialized: true, value: state });\n\t\t\t}\n\t\t} catch {\n\t\t\tthis.$zkLoginSession.set({ initialized: true, value: null });\n\t\t}\n\n\t\treturn this.$zkLoginSession.get().value;\n\t}\n\n\tasync logout() {\n\t\tthis.$zkLoginState.set({});\n\t\tthis.#store.delete(this.#storageKeys.STATE);\n\n\t\tif (this.#useNativeCryptoSigner) {\n\t\t\tawait clear(this.#idbStore);\n\t\t}\n\t\tawait this.#setSession(null);\n\t}\n\n\t// TODO: Should this return the proof if it already exists?\n\tasync getProof({ network }: { network?: EnokiNetwork } = {}) {\n\t\tconst zkp = await this.getSession();\n\t\tconst { salt } = this.$zkLoginState.get();\n\n\t\tif (zkp?.proof) {\n\t\t\tif (zkp.expiresAt && Date.now() > zkp.expiresAt) {\n\t\t\t\tthrow new Error('Stored proof is expired.');\n\t\t\t}\n\n\t\t\treturn zkp.proof;\n\t\t}\n\n\t\tif (!salt || !zkp || !zkp.jwt) {\n\t\t\tthrow new Error('Missing required parameters for proof generation');\n\t\t}\n\n\t\tlet storedNativeSigner: ExportedWebCryptoKeypair | undefined = undefined;\n\t\tif (this.#useNativeCryptoSigner && zkp.ephemeralKeyPair === '@@native') {\n\t\t\tstoredNativeSigner = await get('ephemeralKeyPair', this.#idbStore);\n\t\t\tif (!storedNativeSigner) {\n\t\t\t\tthrow new Error('Native signer not found in store.');\n\t\t\t}\n\t\t}\n\n\t\tconst ephemeralKeyPair =\n\t\t\tzkp.ephemeralKeyPair === '@@native'\n\t\t\t\t? WebCryptoSigner.import(storedNativeSigner!)\n\t\t\t\t: Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork,\n\t\t\tjwt: zkp.jwt,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\trandomness: zkp.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tproof,\n\t\t});\n\n\t\treturn proof;\n\t}\n\n\tasync getKeypair({ network }: { network?: EnokiNetwork } = {}) {\n\t\t// Get the proof, so that we ensure it exists in state:\n\t\tawait this.getProof({ network });\n\n\t\tconst zkp = await this.getSession();\n\n\t\t// Check to see if we have the essentials for a keypair:\n\t\tconst { address } = this.$zkLoginState.get();\n\t\tif (!address || !zkp || !zkp.proof) {\n\t\t\tthrow new Error('Missing required data for keypair generation.');\n\t\t}\n\n\t\tif (Date.now() > zkp.expiresAt) {\n\t\t\tthrow new Error('Stored proof is expired.');\n\t\t}\n\n\t\tlet storedNativeSigner: ExportedWebCryptoKeypair | undefined = undefined;\n\t\tif (this.#useNativeCryptoSigner && zkp.ephemeralKeyPair === '@@native') {\n\t\t\tstoredNativeSigner = await get('ephemeralKeyPair', this.#idbStore);\n\t\t\tif (!storedNativeSigner) {\n\t\t\t\tthrow new Error('Native signer not found in store.');\n\t\t\t}\n\t\t}\n\n\t\tconst ephemeralKeypair =\n\t\t\tzkp.ephemeralKeyPair === '@@native'\n\t\t\t\t? WebCryptoSigner.import(storedNativeSigner!)\n\t\t\t\t: Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress,\n\t\t\tephemeralKeypair,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\tproof: zkp.proof,\n\t\t});\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;AAAA;AAIA,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,YAAY,gBAAgB;AACrC,SAAS,iBAAiB;AAG1B,SAAS,OAAO,aAAa,KAAK,WAAW;AAE7C,SAAS,MAAM,SAAS,aAAa;AAGrC,SAAS,+BAA+B;AAExC,SAAS,mBAAmB;AAE5B,SAAS,oBAAoB;AAE7B,SAAS,4BAA4B;AAiDrC,MAAM,oBAAoB,CAAC,YAAoB;AAAA,EAC9C,OAAO,qBAAqB,MAAM;AAAA,EAClC,SAAS,uBAAuB,MAAM;AACvC;AAKO,MAAM,UAAU;AAAA,EAYtB,YAAY,QAAyB;AAZ/B;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,uBAAK,cAAe,IAAI,YAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAE7B,QAAI,OAAO,iCAAiC;AAC3C,yBAAK,wBAAyB;AAC9B,yBAAK,WAAY,YAAY,OAAO,QAAQ,OAAO;AAAA,IACpD,OAAO;AACN,yBAAK,wBAAyB;AAAA,IAC/B;AAEA,uBAAK,aAAc,OAAO,cAAc,wBAAwB;AAChE,uBAAK,QAAS,OAAO,SAAS,qBAAqB;AACnD,uBAAK,cAAe,kBAAkB,OAAO,MAAM;AAEnD,QAAI,cAAc;AAClB,QAAI;AACH,YAAM,iBAAiB,mBAAK,QAAO,IAAI,mBAAK,cAAa,KAAK;AAC9D,UAAI,gBAAgB;AACnB,sBAAc,KAAK,MAAM,cAA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,IAC1C,eAAe,cAAc,WAAW,IAAI,gBAAgB,CAAC;AAEjE,WAAO,IAAI,aAAa;AAAA,MACvB;AAAA,MACA;AAAA,MACA,UAAU,IAAI;AAAA,MACd,OAAO,IAAI;AAAA,IACZ,CAAC;AAAA,EACF;AACD;AA9SC;AACA;AACA;AACA;AACA;AACA;AACA;AAPM;AAyKA,gBAAW,eAAC,UAAiC;AAClD,MAAI,UAAU;AACb,UAAM,cAAc,MAAM,mBAAK,aAAY;AAAA,MAC1C,mBAAK;AAAA,MACL,KAAK,UAAU,QAAQ;AAAA,IACxB;AAEA,uBAAK,QAAO,IAAI,mBAAK,cAAa,SAAS,WAAW;AAAA,EACvD,OAAO;AACN,uBAAK,QAAO,OAAO,mBAAK,cAAa,OAAO;AAAA,EAC7C;AAEA,OAAK,gBAAgB,IAAI,EAAE,aAAa,MAAM,OAAO,SAAS,CAAC;AAChE;",
6
6
  "names": []
7
7
  }
@@ -4,7 +4,9 @@ export { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';
4
4
  export { createLocalStorage, createSessionStorage, createInMemoryStorage, type SyncStore, } from './stores.js';
5
5
  export { createDefaultEncryption, type Encryption } from './encryption.js';
6
6
  export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
7
- export { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';
7
+ export type { EnokiWallet } from './wallet/wallet.js';
8
+ export { registerEnokiWallets } from './wallet/register.js';
9
+ export { enokiWalletsInitializer } from './wallet/initializer.js';
8
10
  export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
9
11
  export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
10
12
  export { isEnokiNetwork } from './utils.js';
package/dist/esm/index.js CHANGED
@@ -7,7 +7,8 @@ import {
7
7
  } from "./stores.js";
8
8
  import { createDefaultEncryption } from "./encryption.js";
9
9
  import { EnokiKeypair, EnokiPublicKey } from "./EnokiKeypair.js";
10
- import { registerEnokiWallets } from "./wallet/index.js";
10
+ import { registerEnokiWallets } from "./wallet/register.js";
11
+ import { enokiWalletsInitializer } from "./wallet/initializer.js";
11
12
  import {
12
13
  isEnokiWallet,
13
14
  isGoogleWallet,
@@ -26,6 +27,7 @@ export {
26
27
  createInMemoryStorage,
27
28
  createLocalStorage,
28
29
  createSessionStorage,
30
+ enokiWalletsInitializer,
29
31
  getWalletMetadata,
30
32
  isEnokiNetwork,
31
33
  isEnokiWallet,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n} from './wallet/utils.js';\nexport { type RegisterEnokiWalletsOptions } from './wallet/types.js';\n\nexport { isEnokiNetwork } from './utils.js';\n"],
5
- "mappings": "AAGA,SAAS,aAAqC,wBAAwB;AAEtE,SAAS,iBAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,+BAAgD;AACzD,SAAS,cAAc,sBAAsB;AAE7C,SAAS,4BAA8C;AACvD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n} from './wallet/utils.js';\nexport { type RegisterEnokiWalletsOptions } from './wallet/types.js';\n\nexport { isEnokiNetwork } from './utils.js';\n"],
5
+ "mappings": "AAGA,SAAS,aAAqC,wBAAwB;AAEtE,SAAS,iBAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,+BAAgD;AACzD,SAAS,cAAc,sBAAsB;AAG7C,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAExC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,11 @@
1
+ import type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';
2
+ import type { RegisterEnokiWalletsOptions } from './types.js';
3
+ export declare function enokiWalletsInitializer(options: Omit<RegisterEnokiWalletsOptions, 'clients' | 'getCurrentNetwork'>): {
4
+ id: string;
5
+ initialize({ networks, getClient, }: {
6
+ networks: readonly Experimental_SuiClientTypes.Network[];
7
+ getClient: (network?: Experimental_SuiClientTypes.Network) => ClientWithCoreApi;
8
+ }): Promise<{
9
+ unregister: () => void;
10
+ }>;
11
+ };