@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @mysten/enoki
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4990b4b: Add multi-network support and an initializer plugin for the Enoki wallet standard
8
+ implementation
9
+
10
+ ## 0.7.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 7a91b1e: fix error creating idb for multiple networks
15
+ - Updated dependencies [3fb7a83]
16
+ - @mysten/sui@1.34.0
17
+ - @mysten/signers@0.2.18
18
+ - @mysten/wallet-standard@0.16.3
19
+
3
20
  ## 0.7.0
4
21
 
5
22
  ### Minor Changes
@@ -62,7 +62,7 @@ class EnokiFlow {
62
62
  __privateSet(this, _encryptionKey, config.apiKey);
63
63
  if (config.experimental_nativeCryptoSigner) {
64
64
  __privateSet(this, _useNativeCryptoSigner, true);
65
- __privateSet(this, _idbStore, (0, import_idb_keyval.createStore)("enoki", config.apiKey));
65
+ __privateSet(this, _idbStore, (0, import_idb_keyval.createStore)(config.apiKey, "enoki"));
66
66
  } else {
67
67
  __privateSet(this, _useNativeCryptoSigner, false);
68
68
  }
@@ -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;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAgC;AAChC,0BAAoC;AACpC,qBAA+B;AAC/B,mBAAqC;AACrC,qBAA0B;AAG1B,wBAA6C;AAE7C,wBAAqC;AAGrC,wBAAwC;AAExC,yBAA4B;AAE5B,0BAA6B;AAE7B,oBAAqC;AAtBrC;AAuEA,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,+BAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAE7B,QAAI,OAAO,iCAAiC;AAC3C,yBAAK,wBAAyB;AAC9B,yBA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+C;AAAA,IAChE;AAEA,QAAI,KAAK,IAAI,IAAI,IAAI,WAAW;AAC/B,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC3C;AAEA,QAAI,qBAA2D;AAC/D,QAAI,mBAAK,2BAA0B,IAAI,qBAAqB,YAAY;AACvE,2BAAqB,UAAM,uBAAI,oBAAoB,mBAAK,UAAS;AACjE,UAAI,CAAC,oBAAoB;AACxB,cAAM,IAAI,MAAM,mCAAmC;AAAA,MACpD;AAAA,IACD;AAEA,UAAM,mBACL,IAAI,qBAAqB,aACtB,iCAAgB,OAAO,kBAAmB,IAC1C,8BAAe,kBAAc,yBAAW,IAAI,gBAAgB,CAAC;AAEjE,WAAO,IAAI,iCAAa;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;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAgC;AAChC,0BAAoC;AACpC,qBAA+B;AAC/B,mBAAqC;AACrC,qBAA0B;AAG1B,wBAA6C;AAE7C,wBAAqC;AAGrC,wBAAwC;AAExC,yBAA4B;AAE5B,0BAA6B;AAE7B,oBAAqC;AAtBrC;AAuEA,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,+BAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAE7B,QAAI,OAAO,iCAAiC;AAC3C,yBAAK,wBAAyB;AAC9B,yBAAK,eAAY,+BAAY,OAAO,QAAQ,OAAO;AAAA,IACpD,OAAO;AACN,yBAAK,wBAAyB;AAAA,IAC/B;AAEA,uBAAK,aAAc,OAAO,kBAAc,2CAAwB;AAChE,uBAAK,QAAS,OAAO,aAAS,oCAAqB;AACnD,uBAAK,cAAe,kBAAkB,OAAO,MAAM;AAEnD,QAAI,cAAc;AAClB,QAAI;AACH,YAAM,iBAAiB,mBAAK,QAAO,IAAI,mBAAK,cA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A,MACpD;AAAA,IACD;AAEA,UAAM,mBACL,IAAI,qBAAqB,aACtB,iCAAgB,OAAO,kBAAmB,IAC1C,8BAAe,kBAAc,yBAAW,IAAI,gBAAgB,CAAC;AAEjE,WAAO,IAAI,iCAAa;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/cjs/index.js CHANGED
@@ -27,13 +27,14 @@ __export(index_exports, {
27
27
  createInMemoryStorage: () => import_stores.createInMemoryStorage,
28
28
  createLocalStorage: () => import_stores.createLocalStorage,
29
29
  createSessionStorage: () => import_stores.createSessionStorage,
30
+ enokiWalletsInitializer: () => import_initializer.enokiWalletsInitializer,
30
31
  getWalletMetadata: () => import_utils.getWalletMetadata,
31
32
  isEnokiNetwork: () => import_utils2.isEnokiNetwork,
32
33
  isEnokiWallet: () => import_utils.isEnokiWallet,
33
34
  isFacebookWallet: () => import_utils.isFacebookWallet,
34
35
  isGoogleWallet: () => import_utils.isGoogleWallet,
35
36
  isTwitchWallet: () => import_utils.isTwitchWallet,
36
- registerEnokiWallets: () => import_wallet.registerEnokiWallets
37
+ registerEnokiWallets: () => import_register.registerEnokiWallets
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
39
40
  var import_EnokiClient = require("./EnokiClient/index.js");
@@ -41,7 +42,8 @@ var import_EnokiFlow = require("./EnokiFlow.js");
41
42
  var import_stores = require("./stores.js");
42
43
  var import_encryption = require("./encryption.js");
43
44
  var import_EnokiKeypair = require("./EnokiKeypair.js");
44
- var import_wallet = require("./wallet/index.js");
45
+ var import_register = require("./wallet/register.js");
46
+ var import_initializer = require("./wallet/initializer.js");
45
47
  var import_utils = require("./wallet/utils.js");
46
48
  var import_utils2 = require("./utils.js");
47
49
  //# sourceMappingURL=index.js.map
@@ -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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAE7C,oBAAuD;AACvD,mBAMO;AAGP,IAAAA,gBAA+B;",
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAG7C,sBAAqC;AACrC,yBAAwC;AAExC,mBAMO;AAGP,IAAAA,gBAA+B;",
6
6
  "names": ["import_utils"]
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
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var initializer_exports = {};
20
+ __export(initializer_exports, {
21
+ enokiWalletsInitializer: () => enokiWalletsInitializer
22
+ });
23
+ module.exports = __toCommonJS(initializer_exports);
24
+ var import_register = require("./register.js");
25
+ function enokiWalletsInitializer(options) {
26
+ return {
27
+ id: "enoki-wallets-initializer",
28
+ async initialize({
29
+ networks,
30
+ getClient
31
+ }) {
32
+ const { unregister } = (0, import_register.registerEnokiWallets)({
33
+ ...options,
34
+ getCurrentNetwork: () => getClient().network,
35
+ clients: networks.map(getClient)
36
+ });
37
+ return { unregister };
38
+ }
39
+ };
40
+ }
41
+ //# sourceMappingURL=initializer.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/initializer.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { registerEnokiWallets } from './register.js';\nimport type { RegisterEnokiWalletsOptions } from './types.js';\n\nexport function enokiWalletsInitializer(\n\toptions: Omit<RegisterEnokiWalletsOptions, 'clients' | 'getCurrentNetwork'>,\n) {\n\treturn {\n\t\tid: 'enoki-wallets-initializer',\n\t\tasync initialize({\n\t\t\tnetworks,\n\t\t\tgetClient,\n\t\t}: {\n\t\t\tnetworks: readonly Experimental_SuiClientTypes.Network[];\n\t\t\tgetClient: (network?: Experimental_SuiClientTypes.Network) => ClientWithCoreApi;\n\t\t}) {\n\t\t\tconst { unregister } = registerEnokiWallets({\n\t\t\t\t...options,\n\t\t\t\tgetCurrentNetwork: () => getClient().network,\n\t\t\t\tclients: networks.map(getClient),\n\t\t\t});\n\n\t\t\treturn { unregister };\n\t\t},\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAqC;AAG9B,SAAS,wBACf,SACC;AACD,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,MAAM,WAAW;AAAA,MAChB;AAAA,MACA;AAAA,IACD,GAGG;AACF,YAAM,EAAE,WAAW,QAAI,sCAAqB;AAAA,QAC3C,GAAG;AAAA,QACH,mBAAmB,MAAM,UAAU,EAAE;AAAA,QACrC,SAAS,SAAS,IAAI,SAAS;AAAA,MAChC,CAAC;AAED,aAAO,EAAE,WAAW;AAAA,IACrB;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import { EnokiWallet } from './wallet.js';
2
+ import type { RegisterEnokiWalletsOptions } from './types.js';
3
+ import type { AuthProvider } from '../EnokiClient/type.js';
4
+ export declare function registerEnokiWallets({ providers, windowFeatures, ...config }: RegisterEnokiWalletsOptions): {
5
+ wallets: Partial<Record<AuthProvider, EnokiWallet>>;
6
+ unregister: () => void;
7
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var register_exports = {};
20
+ __export(register_exports, {
21
+ registerEnokiWallets: () => registerEnokiWallets
22
+ });
23
+ module.exports = __toCommonJS(register_exports);
24
+ var import_wallet = require("./wallet.js");
25
+ var import_wallet_standard = require("@mysten/wallet-standard");
26
+ var import_utils = require("../utils.js");
27
+ var import_providers = require("./providers.js");
28
+ function registerEnokiWallets({
29
+ providers,
30
+ windowFeatures = defaultWindowFeatures,
31
+ ...config
32
+ }) {
33
+ const clients = "clients" in config ? config.clients : [Object.assign(config.client, { network: config.network ?? "mainnet" })];
34
+ const enokiCompatibleClients = clients.filter(({ network }) => (0, import_utils.isEnokiNetwork)(network));
35
+ if (enokiCompatibleClients.length === 0) {
36
+ throw new Error("None of the specified clients are compatible with Enoki.");
37
+ }
38
+ const getCurrentNetwork = "clients" in config ? config.getCurrentNetwork : () => clients[0].network;
39
+ const walletsApi = (0, import_wallet_standard.getWallets)();
40
+ const wallets = {};
41
+ for (const { name, icon, provider } of import_providers.ENOKI_PROVIDER_WALLETS_INFO) {
42
+ const providerOptions = providers[provider];
43
+ if (providerOptions) {
44
+ wallets[provider] = new import_wallet.EnokiWallet({
45
+ ...providerOptions,
46
+ name,
47
+ icon,
48
+ provider,
49
+ windowFeatures,
50
+ getCurrentNetwork,
51
+ apiKey: config.apiKey,
52
+ apiUrl: config.apiUrl,
53
+ clients: enokiCompatibleClients
54
+ });
55
+ }
56
+ }
57
+ const unregister = walletsApi.register(...Object.values(wallets));
58
+ return { wallets, unregister };
59
+ }
60
+ function defaultWindowFeatures() {
61
+ const width = 500;
62
+ const height = 800;
63
+ const left = (screen.width - width) / 2;
64
+ const top = (screen.height - height) / 4;
65
+ return `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;
66
+ }
67
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/register.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { EnokiWallet } from './wallet.js';\nimport type { RegisterEnokiWalletsOptions } from './types.js';\nimport { getWallets } from '@mysten/wallet-standard';\nimport type { ClientWithCoreApi } from '@mysten/sui/experimental';\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport { isEnokiNetwork } from '../utils.js';\nimport { ENOKI_PROVIDER_WALLETS_INFO } from './providers.js';\n\nexport function registerEnokiWallets({\n\tproviders,\n\twindowFeatures = defaultWindowFeatures,\n\t...config\n}: RegisterEnokiWalletsOptions) {\n\tconst clients: ClientWithCoreApi[] =\n\t\t'clients' in config\n\t\t\t? config.clients\n\t\t\t: [Object.assign(config.client, { network: config.network ?? 'mainnet' })];\n\n\tconst enokiCompatibleClients = clients.filter(({ network }) => isEnokiNetwork(network));\n\tif (enokiCompatibleClients.length === 0) {\n\t\tthrow new Error('None of the specified clients are compatible with Enoki.');\n\t}\n\n\tconst getCurrentNetwork =\n\t\t'clients' in config ? config.getCurrentNetwork : () => clients[0].network;\n\n\tconst walletsApi = getWallets();\n\tconst wallets: Partial<Record<AuthProvider, EnokiWallet>> = {};\n\n\tfor (const { name, icon, provider } of ENOKI_PROVIDER_WALLETS_INFO) {\n\t\tconst providerOptions = providers[provider];\n\t\tif (providerOptions) {\n\t\t\twallets[provider] = new EnokiWallet({\n\t\t\t\t...providerOptions,\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t\tprovider,\n\t\t\t\twindowFeatures,\n\t\t\t\tgetCurrentNetwork,\n\t\t\t\tapiKey: config.apiKey,\n\t\t\t\tapiUrl: config.apiUrl,\n\t\t\t\tclients: enokiCompatibleClients,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst unregister = walletsApi.register(...Object.values(wallets));\n\treturn { wallets, unregister };\n}\n\nfunction defaultWindowFeatures() {\n\tconst width = 500;\n\tconst height = 800;\n\tconst left = (screen.width - width) / 2;\n\tconst top = (screen.height - height) / 4;\n\n\treturn `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAE5B,6BAA2B;AAG3B,mBAA+B;AAC/B,uBAA4C;AAErC,SAAS,qBAAqB;AAAA,EACpC;AAAA,EACA,iBAAiB;AAAA,EACjB,GAAG;AACJ,GAAgC;AAC/B,QAAM,UACL,aAAa,SACV,OAAO,UACP,CAAC,OAAO,OAAO,OAAO,QAAQ,EAAE,SAAS,OAAO,WAAW,UAAU,CAAC,CAAC;AAE3E,QAAM,yBAAyB,QAAQ,OAAO,CAAC,EAAE,QAAQ,UAAM,6BAAe,OAAO,CAAC;AACtF,MAAI,uBAAuB,WAAW,GAAG;AACxC,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC3E;AAEA,QAAM,oBACL,aAAa,SAAS,OAAO,oBAAoB,MAAM,QAAQ,CAAC,EAAE;AAEnE,QAAM,iBAAa,mCAAW;AAC9B,QAAM,UAAsD,CAAC;AAE7D,aAAW,EAAE,MAAM,MAAM,SAAS,KAAK,8CAA6B;AACnE,UAAM,kBAAkB,UAAU,QAAQ;AAC1C,QAAI,iBAAiB;AACpB,cAAQ,QAAQ,IAAI,IAAI,0BAAY;AAAA,QACnC,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,SAAS;AAAA,MACV,CAAC;AAAA,IACF;AAAA,EACD;AAEA,QAAM,aAAa,WAAW,SAAS,GAAG,OAAO,OAAO,OAAO,CAAC;AAChE,SAAO,EAAE,SAAS,WAAW;AAC9B;AAEA,SAAS,wBAAwB;AAChC,QAAM,QAAQ;AACd,QAAM,SAAS;AACf,QAAM,QAAQ,OAAO,QAAQ,SAAS;AACtC,QAAM,OAAO,OAAO,SAAS,UAAU;AAEvC,SAAO,gDAAgD,KAAK,WAAW,MAAM,QAAQ,GAAG,SAAS,IAAI;AACtG;",
6
+ "names": []
7
+ }
@@ -1,43 +1,18 @@
1
- import type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';
2
1
  import type { WritableAtom } from 'nanostores';
3
2
  import type { EnokiClientConfig } from '../EnokiClient/index.js';
4
- import type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';
5
- import { EnokiKeypair } from '../EnokiKeypair.js';
6
- type EnokiFlowConfig = EnokiClientConfig & {
7
- network: EnokiNetwork;
3
+ import type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';
4
+ import type { EnokiSessionContext, ZkLoginSession, ZkLoginState } from './types.js';
5
+ export type EnokiWalletStateConfig = EnokiClientConfig & {
6
+ clients: ClientWithCoreApi[];
7
+ clientId: string;
8
8
  };
9
- interface ZkLoginState {
10
- provider?: AuthProvider;
11
- address?: string;
12
- salt?: string;
13
- publicKey?: string;
14
- }
15
- interface ZkLoginSession {
16
- maxEpoch: number;
17
- randomness: string;
18
- expiresAt: number;
19
- jwt?: string;
20
- proof?: ZkLoginSignatureInputs;
21
- }
22
- export declare class INTERNAL_ONLY_EnokiFlow {
9
+ export declare class EnokiWalletState {
23
10
  #private;
24
- $zkLoginSession: WritableAtom<{
25
- initialized: boolean;
26
- value: ZkLoginSession | null;
27
- }>;
28
- $zkLoginState: WritableAtom<ZkLoginState>;
29
- constructor(config: EnokiFlowConfig);
30
- get network(): EnokiNetwork;
31
- createAuthorizationURL(input: {
32
- provider: AuthProvider;
33
- clientId: string;
34
- redirectUrl: string;
35
- extraParams?: Record<string, string>;
36
- }): Promise<string>;
37
- handleAuthCallback(hash?: string): Promise<string | null>;
38
- getSession(): Promise<ZkLoginSession | null>;
11
+ constructor(config: EnokiWalletStateConfig);
12
+ get zkLoginState(): WritableAtom<ZkLoginState>;
13
+ get sessionContextByNetwork(): Map<Experimental_SuiClientTypes.Network, EnokiSessionContext>;
14
+ getSessionContext(network: Experimental_SuiClientTypes.Network): EnokiSessionContext;
39
15
  logout(): Promise<void>;
40
- getProof(): Promise<import("../EnokiClient/type.js").CreateZkLoginZkpApiResponse>;
41
- getKeypair(): Promise<EnokiKeypair>;
16
+ setSession(state: EnokiSessionContext, newValue: ZkLoginSession | null): Promise<void>;
17
+ getSession({ $zkLoginSession, storageKey }: EnokiSessionContext): Promise<ZkLoginSession | null>;
42
18
  }
43
- export {};