@haneullabs/enoki 0.1.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 (110) hide show
  1. package/CHANGELOG.md +1109 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/EnokiClient/index.d.ts +36 -0
  4. package/dist/cjs/EnokiClient/index.js +196 -0
  5. package/dist/cjs/EnokiClient/index.js.map +7 -0
  6. package/dist/cjs/EnokiClient/type.d.ts +119 -0
  7. package/dist/cjs/EnokiClient/type.js +17 -0
  8. package/dist/cjs/EnokiClient/type.js.map +7 -0
  9. package/dist/cjs/EnokiFlow.d.ts +74 -0
  10. package/dist/cjs/EnokiFlow.js +279 -0
  11. package/dist/cjs/EnokiFlow.js.map +7 -0
  12. package/dist/cjs/EnokiKeypair.d.ts +20 -0
  13. package/dist/cjs/EnokiKeypair.js +87 -0
  14. package/dist/cjs/EnokiKeypair.js.map +7 -0
  15. package/dist/cjs/encryption.d.ts +15 -0
  16. package/dist/cjs/encryption.js +96 -0
  17. package/dist/cjs/encryption.js.map +7 -0
  18. package/dist/cjs/index.d.ts +12 -0
  19. package/dist/cjs/index.js +50 -0
  20. package/dist/cjs/index.js.map +7 -0
  21. package/dist/cjs/package.json +4 -0
  22. package/dist/cjs/react.d.ts +20 -0
  23. package/dist/cjs/react.js +76 -0
  24. package/dist/cjs/react.js.map +7 -0
  25. package/dist/cjs/stores.d.ts +21 -0
  26. package/dist/cjs/stores.js +67 -0
  27. package/dist/cjs/stores.js.map +7 -0
  28. package/dist/cjs/utils.d.ts +2 -0
  29. package/dist/cjs/utils.js +27 -0
  30. package/dist/cjs/utils.js.map +7 -0
  31. package/dist/cjs/wallet/features.d.ts +50 -0
  32. package/dist/cjs/wallet/features.js +27 -0
  33. package/dist/cjs/wallet/features.js.map +7 -0
  34. package/dist/cjs/wallet/initializer.d.ts +11 -0
  35. package/dist/cjs/wallet/initializer.js +41 -0
  36. package/dist/cjs/wallet/initializer.js.map +7 -0
  37. package/dist/cjs/wallet/providers.d.ts +7 -0
  38. package/dist/cjs/wallet/providers.js +51 -0
  39. package/dist/cjs/wallet/providers.js.map +7 -0
  40. package/dist/cjs/wallet/register.d.ts +7 -0
  41. package/dist/cjs/wallet/register.js +68 -0
  42. package/dist/cjs/wallet/register.js.map +7 -0
  43. package/dist/cjs/wallet/state.d.ts +18 -0
  44. package/dist/cjs/wallet/state.js +142 -0
  45. package/dist/cjs/wallet/state.js.map +7 -0
  46. package/dist/cjs/wallet/types.d.ts +82 -0
  47. package/dist/cjs/wallet/types.js +17 -0
  48. package/dist/cjs/wallet/types.js.map +7 -0
  49. package/dist/cjs/wallet/utils.d.ts +11 -0
  50. package/dist/cjs/wallet/utils.js +83 -0
  51. package/dist/cjs/wallet/utils.js.map +7 -0
  52. package/dist/cjs/wallet/wallet.d.ts +16 -0
  53. package/dist/cjs/wallet/wallet.js +466 -0
  54. package/dist/cjs/wallet/wallet.js.map +7 -0
  55. package/dist/esm/EnokiClient/index.d.ts +36 -0
  56. package/dist/esm/EnokiClient/index.js +176 -0
  57. package/dist/esm/EnokiClient/index.js.map +7 -0
  58. package/dist/esm/EnokiClient/type.d.ts +119 -0
  59. package/dist/esm/EnokiClient/type.js +1 -0
  60. package/dist/esm/EnokiClient/type.js.map +7 -0
  61. package/dist/esm/EnokiFlow.d.ts +74 -0
  62. package/dist/esm/EnokiFlow.js +259 -0
  63. package/dist/esm/EnokiFlow.js.map +7 -0
  64. package/dist/esm/EnokiKeypair.d.ts +20 -0
  65. package/dist/esm/EnokiKeypair.js +67 -0
  66. package/dist/esm/EnokiKeypair.js.map +7 -0
  67. package/dist/esm/encryption.d.ts +15 -0
  68. package/dist/esm/encryption.js +76 -0
  69. package/dist/esm/encryption.js.map +7 -0
  70. package/dist/esm/index.d.ts +12 -0
  71. package/dist/esm/index.js +41 -0
  72. package/dist/esm/index.js.map +7 -0
  73. package/dist/esm/package.json +4 -0
  74. package/dist/esm/react.d.ts +20 -0
  75. package/dist/esm/react.js +56 -0
  76. package/dist/esm/react.js.map +7 -0
  77. package/dist/esm/stores.d.ts +21 -0
  78. package/dist/esm/stores.js +47 -0
  79. package/dist/esm/stores.js.map +7 -0
  80. package/dist/esm/utils.d.ts +2 -0
  81. package/dist/esm/utils.js +7 -0
  82. package/dist/esm/utils.js.map +7 -0
  83. package/dist/esm/wallet/features.d.ts +50 -0
  84. package/dist/esm/wallet/features.js +7 -0
  85. package/dist/esm/wallet/features.js.map +7 -0
  86. package/dist/esm/wallet/initializer.d.ts +11 -0
  87. package/dist/esm/wallet/initializer.js +21 -0
  88. package/dist/esm/wallet/initializer.js.map +7 -0
  89. package/dist/esm/wallet/providers.d.ts +7 -0
  90. package/dist/esm/wallet/providers.js +31 -0
  91. package/dist/esm/wallet/providers.js.map +7 -0
  92. package/dist/esm/wallet/register.d.ts +7 -0
  93. package/dist/esm/wallet/register.js +48 -0
  94. package/dist/esm/wallet/register.js.map +7 -0
  95. package/dist/esm/wallet/state.d.ts +18 -0
  96. package/dist/esm/wallet/state.js +122 -0
  97. package/dist/esm/wallet/state.js.map +7 -0
  98. package/dist/esm/wallet/types.d.ts +82 -0
  99. package/dist/esm/wallet/types.js +1 -0
  100. package/dist/esm/wallet/types.js.map +7 -0
  101. package/dist/esm/wallet/utils.d.ts +11 -0
  102. package/dist/esm/wallet/utils.js +63 -0
  103. package/dist/esm/wallet/utils.js.map +7 -0
  104. package/dist/esm/wallet/wallet.d.ts +16 -0
  105. package/dist/esm/wallet/wallet.js +444 -0
  106. package/dist/esm/wallet/wallet.js.map +7 -0
  107. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  108. package/dist/tsconfig.tsbuildinfo +1 -0
  109. package/package.json +80 -0
  110. package/react/package.json +5 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 '@haneullabs/signers/webcrypto';\nimport { WebCryptoSigner } from '@haneullabs/signers/webcrypto';\nimport { decodeHaneulPrivateKey } from '@haneullabs/haneul/cryptography';\nimport { Ed25519Keypair } from '@haneullabs/haneul/keypairs/ed25519';\nimport { fromBase64, toBase64 } from '@haneullabs/haneul/utils';\nimport { decodeJwt } from '@haneullabs/haneul/zklogin';\nimport type { ZkLoginSignatureInputs } from '@haneullabs/haneul/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\tadditionalEpochs: config.additionalEpochs,\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\tdecodeHaneulPrivateKey((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,8BAA8B;AACvC,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,MACf,kBAAkB,OAAO;AAAA,IAC1B,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAE7B,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OAAO;AACnC,YAAM,IAAI,MAAM,+CAA+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,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;AA/SC;AACA;AACA;AACA;AACA;AACA;AACA;AAPM;AA0KA,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
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ import type { SignatureWithBytes } from '@haneullabs/haneul/cryptography';
2
+ import { Signer } from '@haneullabs/haneul/cryptography';
3
+ import type { ZkLoginSignatureInputs } from '@haneullabs/haneul/zklogin';
4
+ import { ZkLoginPublicIdentifier } from '@haneullabs/haneul/zklogin';
5
+ export declare class EnokiPublicKey extends ZkLoginPublicIdentifier {
6
+ }
7
+ export declare class EnokiKeypair extends Signer {
8
+ #private;
9
+ constructor(input: {
10
+ address: string;
11
+ maxEpoch: number;
12
+ proof: ZkLoginSignatureInputs;
13
+ ephemeralKeypair: Signer;
14
+ });
15
+ sign(data: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
16
+ signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>;
17
+ signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>;
18
+ getKeyScheme(): import("@haneullabs/haneul/cryptography").SignatureScheme;
19
+ getPublicKey(): EnokiPublicKey;
20
+ }
@@ -0,0 +1,67 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ 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);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var _proof, _maxEpoch, _ephemeralKeypair, _publicKey;
9
+ import { Signer } from "@haneullabs/haneul/cryptography";
10
+ import { getZkLoginSignature, ZkLoginPublicIdentifier } from "@haneullabs/haneul/zklogin";
11
+ class EnokiPublicKey extends ZkLoginPublicIdentifier {
12
+ }
13
+ class EnokiKeypair extends Signer {
14
+ constructor(input) {
15
+ super();
16
+ __privateAdd(this, _proof);
17
+ __privateAdd(this, _maxEpoch);
18
+ __privateAdd(this, _ephemeralKeypair);
19
+ __privateAdd(this, _publicKey);
20
+ __privateSet(this, _proof, input.proof);
21
+ __privateSet(this, _maxEpoch, input.maxEpoch);
22
+ __privateSet(this, _ephemeralKeypair, input.ephemeralKeypair);
23
+ __privateSet(this, _publicKey, EnokiPublicKey.fromProof(input.address, input.proof));
24
+ }
25
+ async sign(data) {
26
+ return __privateGet(this, _ephemeralKeypair).sign(data);
27
+ }
28
+ async signPersonalMessage(bytes) {
29
+ const { bytes: signedBytes, signature: userSignature } = await __privateGet(this, _ephemeralKeypair).signPersonalMessage(bytes);
30
+ const zkSignature = getZkLoginSignature({
31
+ inputs: __privateGet(this, _proof),
32
+ maxEpoch: __privateGet(this, _maxEpoch),
33
+ userSignature
34
+ });
35
+ return {
36
+ bytes: signedBytes,
37
+ signature: zkSignature
38
+ };
39
+ }
40
+ async signTransaction(bytes) {
41
+ const { bytes: signedBytes, signature: userSignature } = await __privateGet(this, _ephemeralKeypair).signTransaction(bytes);
42
+ const zkSignature = getZkLoginSignature({
43
+ inputs: __privateGet(this, _proof),
44
+ maxEpoch: __privateGet(this, _maxEpoch),
45
+ userSignature
46
+ });
47
+ return {
48
+ bytes: signedBytes,
49
+ signature: zkSignature
50
+ };
51
+ }
52
+ getKeyScheme() {
53
+ return __privateGet(this, _ephemeralKeypair).getKeyScheme();
54
+ }
55
+ getPublicKey() {
56
+ return __privateGet(this, _publicKey);
57
+ }
58
+ }
59
+ _proof = new WeakMap();
60
+ _maxEpoch = new WeakMap();
61
+ _ephemeralKeypair = new WeakMap();
62
+ _publicKey = new WeakMap();
63
+ export {
64
+ EnokiKeypair,
65
+ EnokiPublicKey
66
+ };
67
+ //# sourceMappingURL=EnokiKeypair.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/EnokiKeypair.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureWithBytes } from '@haneullabs/haneul/cryptography';\nimport { Signer } from '@haneullabs/haneul/cryptography';\nimport type { ZkLoginSignatureInputs } from '@haneullabs/haneul/zklogin';\nimport { getZkLoginSignature, ZkLoginPublicIdentifier } from '@haneullabs/haneul/zklogin';\n\nexport class EnokiPublicKey extends ZkLoginPublicIdentifier {}\n\nexport class EnokiKeypair extends Signer {\n\t#proof: ZkLoginSignatureInputs;\n\t#maxEpoch: number;\n\t#ephemeralKeypair: Signer;\n\t#publicKey: EnokiPublicKey;\n\n\tconstructor(input: {\n\t\taddress: string;\n\t\tmaxEpoch: number;\n\t\tproof: ZkLoginSignatureInputs;\n\t\tephemeralKeypair: Signer;\n\t}) {\n\t\tsuper();\n\t\tthis.#proof = input.proof;\n\t\tthis.#maxEpoch = input.maxEpoch;\n\t\tthis.#ephemeralKeypair = input.ephemeralKeypair;\n\t\tthis.#publicKey = EnokiPublicKey.fromProof(input.address, input.proof);\n\t}\n\n\tasync sign(data: Uint8Array) {\n\t\treturn this.#ephemeralKeypair.sign(data);\n\t}\n\n\tasync signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signPersonalMessage(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tasync signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signTransaction(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tgetKeyScheme() {\n\t\treturn this.#ephemeralKeypair.getKeyScheme();\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;AAAA;AAIA,SAAS,cAAc;AAEvB,SAAS,qBAAqB,+BAA+B;AAEtD,MAAM,uBAAuB,wBAAwB;AAAC;AAEtD,MAAM,qBAAqB,OAAO;AAAA,EAMxC,YAAY,OAKT;AACF,UAAM;AAXP;AACA;AACA;AACA;AASC,uBAAK,QAAS,MAAM;AACpB,uBAAK,WAAY,MAAM;AACvB,uBAAK,mBAAoB,MAAM;AAC/B,uBAAK,YAAa,eAAe,UAAU,MAAM,SAAS,MAAM,KAAK;AAAA,EACtE;AAAA,EAEA,MAAM,KAAK,MAAkB;AAC5B,WAAO,mBAAK,mBAAkB,KAAK,IAAI;AAAA,EACxC;AAAA,EAEA,MAAM,oBAAoB,OAAgD;AACzE,UAAM,EAAE,OAAO,aAAa,WAAW,cAAc,IACpD,MAAM,mBAAK,mBAAkB,oBAAoB,KAAK;AAEvD,UAAM,cAAc,oBAAoB;AAAA,MACvC,QAAQ,mBAAK;AAAA,MACb,UAAU,mBAAK;AAAA,MACf;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,OAAO;AAAA,MACP,WAAW;AAAA,IACZ;AAAA,EACD;AAAA,EAEA,MAAM,gBAAgB,OAAgD;AACrE,UAAM,EAAE,OAAO,aAAa,WAAW,cAAc,IACpD,MAAM,mBAAK,mBAAkB,gBAAgB,KAAK;AAEnD,UAAM,cAAc,oBAAoB;AAAA,MACvC,QAAQ,mBAAK;AAAA,MACb,UAAU,mBAAK;AAAA,MACf;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,OAAO;AAAA,MACP,WAAW;AAAA,IACZ;AAAA,EACD;AAAA,EAEA,eAAe;AACd,WAAO,mBAAK,mBAAkB,aAAa;AAAA,EAC5C;AAAA,EAEA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AACD;AA7DC;AACA;AACA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A general interface for specifying how data should be encrypted and decrypted.
3
+ */
4
+ export interface Encryption {
5
+ encrypt(password: string, data: string): Promise<string>;
6
+ decrypt(password: string, data: string): Promise<string>;
7
+ }
8
+ /**
9
+ * Create the default encryption interface, which uses the browsers built-in crypto primitives.
10
+ */
11
+ export declare function createDefaultEncryption(): Encryption;
12
+ /**
13
+ * Create a passthrough encryption interface, which does not encrypt or decrypt data.
14
+ */
15
+ export declare function createPassthroughEncryption(): Encryption;
@@ -0,0 +1,76 @@
1
+ import { fromBase64, toBase64 } from "@haneullabs/haneul/utils";
2
+ function createDefaultEncryption() {
3
+ async function keyFromPassword(password, salt) {
4
+ const key = await crypto.subtle.importKey(
5
+ "raw",
6
+ new TextEncoder().encode(password),
7
+ { name: "PBKDF2" },
8
+ false,
9
+ ["deriveBits", "deriveKey"]
10
+ );
11
+ const derivedKey = await crypto.subtle.deriveKey(
12
+ {
13
+ name: "PBKDF2",
14
+ salt,
15
+ iterations: 9e5,
16
+ hash: "SHA-256"
17
+ },
18
+ key,
19
+ { name: "AES-GCM", length: 256 },
20
+ false,
21
+ ["encrypt", "decrypt"]
22
+ );
23
+ return { key, derivedKey };
24
+ }
25
+ return {
26
+ async encrypt(password, data) {
27
+ const salt = crypto.getRandomValues(new Uint8Array(16));
28
+ const iv = crypto.getRandomValues(new Uint8Array(12));
29
+ const { derivedKey } = await keyFromPassword(password, salt);
30
+ const payload = await crypto.subtle.encrypt(
31
+ {
32
+ name: "AES-GCM",
33
+ iv
34
+ },
35
+ derivedKey,
36
+ new TextEncoder().encode(data)
37
+ );
38
+ return JSON.stringify({
39
+ payload: toBase64(new Uint8Array(payload)),
40
+ iv: toBase64(iv),
41
+ salt: toBase64(salt)
42
+ });
43
+ },
44
+ async decrypt(password, data) {
45
+ const parsed = JSON.parse(data);
46
+ if (!parsed.payload || !parsed.iv || !parsed.salt) {
47
+ throw new Error("Invalid encrypted data");
48
+ }
49
+ const { derivedKey } = await keyFromPassword(password, fromBase64(parsed.salt));
50
+ const decryptedContent = await crypto.subtle.decrypt(
51
+ {
52
+ name: "AES-GCM",
53
+ iv: fromBase64(parsed.iv)
54
+ },
55
+ derivedKey,
56
+ fromBase64(parsed.payload)
57
+ );
58
+ return new TextDecoder().decode(decryptedContent);
59
+ }
60
+ };
61
+ }
62
+ function createPassthroughEncryption() {
63
+ return {
64
+ async encrypt(_password, data) {
65
+ return data;
66
+ },
67
+ async decrypt(_password, data) {
68
+ return data;
69
+ }
70
+ };
71
+ }
72
+ export {
73
+ createDefaultEncryption,
74
+ createPassthroughEncryption
75
+ };
76
+ //# sourceMappingURL=encryption.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/encryption.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64 } from '@haneullabs/haneul/utils';\n\n/**\n * A general interface for specifying how data should be encrypted and decrypted.\n */\nexport interface Encryption {\n\tencrypt(password: string, data: string): Promise<string>;\n\tdecrypt(password: string, data: string): Promise<string>;\n}\n\n/**\n * Create the default encryption interface, which uses the browsers built-in crypto primitives.\n */\nexport function createDefaultEncryption(): Encryption {\n\ttype EncryptedJSON = {\n\t\tpayload: string;\n\t\tiv: string;\n\t\tsalt: string;\n\t};\n\n\tasync function keyFromPassword(password: string, salt: Uint8Array) {\n\t\tconst key = await crypto.subtle.importKey(\n\t\t\t'raw',\n\t\t\tnew TextEncoder().encode(password),\n\t\t\t{ name: 'PBKDF2' },\n\t\t\tfalse,\n\t\t\t['deriveBits', 'deriveKey'],\n\t\t);\n\n\t\tconst derivedKey = await crypto.subtle.deriveKey(\n\t\t\t{\n\t\t\t\tname: 'PBKDF2',\n\t\t\t\tsalt: salt as BufferSource,\n\t\t\t\titerations: 900_000,\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tkey,\n\t\t\t{ name: 'AES-GCM', length: 256 },\n\t\t\tfalse,\n\t\t\t['encrypt', 'decrypt'],\n\t\t);\n\n\t\treturn { key, derivedKey };\n\t}\n\n\treturn {\n\t\tasync encrypt(password, data) {\n\t\t\tconst salt = crypto.getRandomValues(new Uint8Array(16));\n\t\t\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, salt);\n\n\t\t\tconst payload = await crypto.subtle.encrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv,\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tnew TextEncoder().encode(data),\n\t\t\t);\n\n\t\t\treturn JSON.stringify({\n\t\t\t\tpayload: toBase64(new Uint8Array(payload)),\n\t\t\t\tiv: toBase64(iv),\n\t\t\t\tsalt: toBase64(salt),\n\t\t\t} satisfies EncryptedJSON);\n\t\t},\n\t\tasync decrypt(password, data) {\n\t\t\tconst parsed = JSON.parse(data) as EncryptedJSON;\n\t\t\tif (!parsed.payload || !parsed.iv || !parsed.salt) {\n\t\t\t\tthrow new Error('Invalid encrypted data');\n\t\t\t}\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, fromBase64(parsed.salt));\n\n\t\t\tconst decryptedContent = await crypto.subtle.decrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv: fromBase64(parsed.iv),\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tfromBase64(parsed.payload),\n\t\t\t);\n\n\t\t\treturn new TextDecoder().decode(decryptedContent);\n\t\t},\n\t};\n}\n\n/**\n * Create a passthrough encryption interface, which does not encrypt or decrypt data.\n */\nexport function createPassthroughEncryption(): Encryption {\n\treturn {\n\t\tasync encrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t\tasync decrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t};\n}\n"],
5
+ "mappings": "AAGA,SAAS,YAAY,gBAAgB;AAa9B,SAAS,0BAAsC;AAOrD,iBAAe,gBAAgB,UAAkB,MAAkB;AAClE,UAAM,MAAM,MAAM,OAAO,OAAO;AAAA,MAC/B;AAAA,MACA,IAAI,YAAY,EAAE,OAAO,QAAQ;AAAA,MACjC,EAAE,MAAM,SAAS;AAAA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B;AAAA,QACA;AAAA,QACA,WAAW,OAAO,OAAO;AAAA,MAC1B;AAEA,aAAO,IAAI,YAAY,EAAE,OAAO,gBAAgB;AAAA,IACjD;AAAA,EACD;AACD;AAKO,SAAS,8BAA0C;AACzD,SAAO;AAAA,IACN,MAAM,QAAQ,WAAW,MAAM;AAC9B,aAAO;AAAA,IACR;AAAA,IACA,MAAM,QAAQ,WAAW,MAAM;AAC9B,aAAO;AAAA,IACR;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,12 @@
1
+ export { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';
2
+ export type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';
3
+ export { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';
4
+ export { createLocalStorage, createSessionStorage, createInMemoryStorage, type SyncStore, } from './stores.js';
5
+ export { createDefaultEncryption, type Encryption } from './encryption.js';
6
+ export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
7
+ export type { EnokiWallet } from './wallet/wallet.js';
8
+ export { registerEnokiWallets } from './wallet/register.js';
9
+ export { enokiWalletsInitializer } from './wallet/initializer.js';
10
+ export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, getSession, } from './wallet/utils.js';
11
+ export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
12
+ export { isEnokiNetwork } from './utils.js';
@@ -0,0 +1,41 @@
1
+ import { EnokiClient, EnokiClientError } from "./EnokiClient/index.js";
2
+ import { EnokiFlow } from "./EnokiFlow.js";
3
+ import {
4
+ createLocalStorage,
5
+ createSessionStorage,
6
+ createInMemoryStorage
7
+ } from "./stores.js";
8
+ import { createDefaultEncryption } from "./encryption.js";
9
+ import { EnokiKeypair, EnokiPublicKey } from "./EnokiKeypair.js";
10
+ import { registerEnokiWallets } from "./wallet/register.js";
11
+ import { enokiWalletsInitializer } from "./wallet/initializer.js";
12
+ import {
13
+ isEnokiWallet,
14
+ isGoogleWallet,
15
+ isTwitchWallet,
16
+ isFacebookWallet,
17
+ getWalletMetadata,
18
+ getSession
19
+ } from "./wallet/utils.js";
20
+ import { isEnokiNetwork } from "./utils.js";
21
+ export {
22
+ EnokiClient,
23
+ EnokiClientError,
24
+ EnokiFlow,
25
+ EnokiKeypair,
26
+ EnokiPublicKey,
27
+ createDefaultEncryption,
28
+ createInMemoryStorage,
29
+ createLocalStorage,
30
+ createSessionStorage,
31
+ enokiWalletsInitializer,
32
+ getSession,
33
+ getWalletMetadata,
34
+ isEnokiNetwork,
35
+ isEnokiWallet,
36
+ isFacebookWallet,
37
+ isGoogleWallet,
38
+ isTwitchWallet,
39
+ registerEnokiWallets
40
+ };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 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\tgetSession,\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,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "private": true,
3
+ "type": "module"
4
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { EnokiFlowConfig } from './EnokiFlow.js';
3
+ import { EnokiFlow } from './EnokiFlow.js';
4
+ /** @deprecated use `registerEnokiWallets` instead */
5
+ export type EnokiFlowProviderProps = EnokiFlowConfig & {
6
+ children: ReactNode;
7
+ };
8
+ /** @deprecated use `registerEnokiWallets` instead */
9
+ export declare function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps): import("react/jsx-runtime.js").JSX.Element;
10
+ /** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */
11
+ export declare function useEnokiFlow(): EnokiFlow;
12
+ /** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */
13
+ export declare function useZkLogin(): import("./EnokiFlow.js").ZkLoginState;
14
+ /** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */
15
+ export declare function useZkLoginSession(): import("./EnokiFlow.js").ZkLoginSession | null;
16
+ /** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */
17
+ export declare function useAuthCallback(): {
18
+ handled: boolean;
19
+ state: string | null;
20
+ };
@@ -0,0 +1,56 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useStore } from "@nanostores/react";
3
+ import { createContext, useContext, useEffect, useState } from "react";
4
+ import { EnokiFlow } from "./EnokiFlow.js";
5
+ const EnokiFlowContext = createContext(null);
6
+ function EnokiFlowProvider({ children, ...config }) {
7
+ const [enokiFlow] = useState(() => new EnokiFlow(config));
8
+ return /* @__PURE__ */ jsx(EnokiFlowContext.Provider, { value: enokiFlow, children });
9
+ }
10
+ function useEnokiFlow() {
11
+ const context = useContext(EnokiFlowContext);
12
+ if (!context) {
13
+ throw new Error("Missing `EnokiFlowContext` provider");
14
+ }
15
+ return context;
16
+ }
17
+ function useZkLogin() {
18
+ const flow = useEnokiFlow();
19
+ return useStore(flow.$zkLoginState);
20
+ }
21
+ function useZkLoginSession() {
22
+ const flow = useEnokiFlow();
23
+ return useStore(flow.$zkLoginSession).value;
24
+ }
25
+ function useAuthCallback() {
26
+ const flow = useEnokiFlow();
27
+ const [state, setState] = useState(null);
28
+ const [handled, setHandled] = useState(false);
29
+ const [hash, setHash] = useState(null);
30
+ useEffect(() => {
31
+ const listener = () => setHash(window.location.hash.slice(1).trim());
32
+ listener();
33
+ window.addEventListener("hashchange", listener);
34
+ return () => window.removeEventListener("hashchange", listener);
35
+ }, []);
36
+ useEffect(() => {
37
+ if (!hash) return;
38
+ (async () => {
39
+ try {
40
+ setState(await flow.handleAuthCallback(hash));
41
+ window.location.hash = "";
42
+ } finally {
43
+ setHandled(true);
44
+ }
45
+ })();
46
+ }, [hash, flow]);
47
+ return { handled, state };
48
+ }
49
+ export {
50
+ EnokiFlowProvider,
51
+ useAuthCallback,
52
+ useEnokiFlow,
53
+ useZkLogin,
54
+ useZkLoginSession
55
+ };
56
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/react.tsx"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useStore } from '@nanostores/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useEffect, useState } from 'react';\n\nimport type { EnokiFlowConfig } from './EnokiFlow.js';\nimport { EnokiFlow } from './EnokiFlow.js';\n\nconst EnokiFlowContext = createContext<EnokiFlow | null>(null);\n\n/** @deprecated use `registerEnokiWallets` instead */\nexport type EnokiFlowProviderProps = EnokiFlowConfig & {\n\tchildren: ReactNode;\n};\n\n/** @deprecated use `registerEnokiWallets` instead */\nexport function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps) {\n\tconst [enokiFlow] = useState(() => new EnokiFlow(config));\n\treturn <EnokiFlowContext.Provider value={enokiFlow}>{children}</EnokiFlowContext.Provider>;\n}\n\n/** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */\nexport function useEnokiFlow() {\n\tconst context = useContext(EnokiFlowContext);\n\tif (!context) {\n\t\tthrow new Error('Missing `EnokiFlowContext` provider');\n\t}\n\treturn context;\n}\n\n/** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */\nexport function useZkLogin() {\n\tconst flow = useEnokiFlow();\n\treturn useStore(flow.$zkLoginState);\n}\n\n/** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */\nexport function useZkLoginSession() {\n\tconst flow = useEnokiFlow();\n\treturn useStore(flow.$zkLoginSession).value;\n}\n\n/** @deprecated use `registerEnokiWallets` and dapp-kit wallet hooks instead */\nexport function useAuthCallback() {\n\tconst flow = useEnokiFlow();\n\tconst [state, setState] = useState<string | null>(null);\n\tconst [handled, setHandled] = useState(false);\n\tconst [hash, setHash] = useState<string | null>(null);\n\n\tuseEffect(() => {\n\t\tconst listener = () => setHash(window.location.hash.slice(1).trim());\n\t\tlistener();\n\n\t\twindow.addEventListener('hashchange', listener);\n\t\treturn () => window.removeEventListener('hashchange', listener);\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (!hash) return;\n\n\t\t// oxlint-disable @typescript-eslint/no-floating-promises\n\t\t(async () => {\n\t\t\ttry {\n\t\t\t\tsetState(await flow.handleAuthCallback(hash));\n\n\t\t\t\twindow.location.hash = '';\n\t\t\t} finally {\n\t\t\t\tsetHandled(true);\n\t\t\t}\n\t\t})();\n\t}, [hash, flow]);\n\n\treturn { handled, state };\n}\n"],
5
+ "mappings": "AAoBQ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AAA,EACJ,GAAG,CAAC,MAAM,IAAI,CAAC;AAEf,SAAO,EAAE,SAAS,MAAM;AACzB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * An sync key-value store.
3
+ */
4
+ export interface SyncStore {
5
+ get(key: string): string | null;
6
+ set(key: string, value: string): void;
7
+ delete(key: string): void;
8
+ }
9
+ /**
10
+ * Create a storage interface backed by memory.
11
+ * This is generally useful for server-side rendering, and test environments.
12
+ */
13
+ export declare function createInMemoryStorage(): SyncStore;
14
+ /**
15
+ * Create a store backed by `localStorage`.
16
+ */
17
+ export declare function createLocalStorage(): SyncStore;
18
+ /**
19
+ * Create a store backed by `sessionStorage`.
20
+ */
21
+ export declare function createSessionStorage(): SyncStore;
@@ -0,0 +1,47 @@
1
+ function createWebStorage(storage) {
2
+ return {
3
+ get(key) {
4
+ return storage.getItem(key);
5
+ },
6
+ set(key, value) {
7
+ storage.setItem(key, value);
8
+ },
9
+ delete(key) {
10
+ storage.removeItem(key);
11
+ }
12
+ };
13
+ }
14
+ function createInMemoryStorage() {
15
+ const store = /* @__PURE__ */ new Map();
16
+ return {
17
+ get(key) {
18
+ return store.get(key) ?? null;
19
+ },
20
+ set(key, value) {
21
+ store.set(key, value);
22
+ },
23
+ delete(key) {
24
+ store.delete(key);
25
+ }
26
+ };
27
+ }
28
+ function createLocalStorage() {
29
+ if (typeof window === "undefined") {
30
+ console.warn("`window.localStorage` is not available, falling back to in-memory storage");
31
+ return createInMemoryStorage();
32
+ }
33
+ return createWebStorage(window.localStorage);
34
+ }
35
+ function createSessionStorage() {
36
+ if (typeof window === "undefined") {
37
+ console.warn("`window.sessionStorage` is not available, falling back to in-memory storage");
38
+ return createInMemoryStorage();
39
+ }
40
+ return createWebStorage(window.sessionStorage);
41
+ }
42
+ export {
43
+ createInMemoryStorage,
44
+ createLocalStorage,
45
+ createSessionStorage
46
+ };
47
+ //# sourceMappingURL=stores.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/stores.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An sync key-value store.\n */\nexport interface SyncStore {\n\tget(key: string): string | null;\n\tset(key: string, value: string): void;\n\tdelete(key: string): void;\n}\n\nfunction createWebStorage(storage: Storage): SyncStore {\n\treturn {\n\t\tget(key: string) {\n\t\t\treturn storage.getItem(key);\n\t\t},\n\t\tset(key: string, value: string) {\n\t\t\tstorage.setItem(key, value);\n\t\t},\n\t\tdelete(key: string) {\n\t\t\tstorage.removeItem(key);\n\t\t},\n\t};\n}\n\n/**\n * Create a storage interface backed by memory.\n * This is generally useful for server-side rendering, and test environments.\n */\nexport function createInMemoryStorage(): SyncStore {\n\tconst store = new Map<string, string>();\n\treturn {\n\t\tget(key) {\n\t\t\treturn store.get(key) ?? null;\n\t\t},\n\t\tset(key, value) {\n\t\t\tstore.set(key, value);\n\t\t},\n\t\tdelete(key) {\n\t\t\tstore.delete(key);\n\t\t},\n\t};\n}\n\n/**\n * Create a store backed by `localStorage`.\n */\nexport function createLocalStorage(): SyncStore {\n\tif (typeof window === 'undefined') {\n\t\tconsole.warn('`window.localStorage` is not available, falling back to in-memory storage');\n\t\treturn createInMemoryStorage();\n\t}\n\n\treturn createWebStorage(window.localStorage);\n}\n\n/**\n * Create a store backed by `sessionStorage`.\n */\nexport function createSessionStorage(): SyncStore {\n\tif (typeof window === 'undefined') {\n\t\tconsole.warn('`window.sessionStorage` is not available, falling back to in-memory storage');\n\t\treturn createInMemoryStorage();\n\t}\n\n\treturn createWebStorage(window.sessionStorage);\n}\n"],
5
+ "mappings": "AAYA,SAAS,iBAAiB,SAA6B;AACtD,SAAO;AAAA,IACN,IAAI,KAAa;AAChB,aAAO,QAAQ,QAAQ,GAAG;AAAA,IAC3B;AAAA,IACA,IAAI,KAAa,OAAe;AAC/B,cAAQ,QAAQ,KAAK,KAAK;AAAA,IAC3B;AAAA,IACA,OAAO,KAAa;AACnB,cAAQ,WAAW,GAAG;AAAA,IACvB;AAAA,EACD;AACD;AAMO,SAAS,wBAAmC;AAClD,QAAM,QAAQ,oBAAI,IAAoB;AACtC,SAAO;AAAA,IACN,IAAI,KAAK;AACR,aAAO,MAAM,IAAI,GAAG,KAAK;AAAA,IAC1B;AAAA,IACA,IAAI,KAAK,OAAO;AACf,YAAM,IAAI,KAAK,KAAK;AAAA,IACrB;AAAA,IACA,OAAO,KAAK;AACX,YAAM,OAAO,GAAG;AAAA,IACjB;AAAA,EACD;AACD;AAKO,SAAS,qBAAgC;AAC/C,MAAI,OAAO,WAAW,aAAa;AAClC,YAAQ,KAAK,2EAA2E;AACxF,WAAO,sBAAsB;AAAA,EAC9B;AAEA,SAAO,iBAAiB,OAAO,YAAY;AAC5C;AAKO,SAAS,uBAAkC;AACjD,MAAI,OAAO,WAAW,aAAa;AAClC,YAAQ,KAAK,6EAA6E;AAC1F,WAAO,sBAAsB;AAAA,EAC9B;AAEA,SAAO,iBAAiB,OAAO,cAAc;AAC9C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import type { EnokiNetwork } from './EnokiClient/type.js';
2
+ export declare function isEnokiNetwork(network: string): network is EnokiNetwork;
@@ -0,0 +1,7 @@
1
+ function isEnokiNetwork(network) {
2
+ return network === "mainnet" || network === "testnet" || network === "devnet";
3
+ }
4
+ export {
5
+ isEnokiNetwork
6
+ };
7
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { EnokiNetwork } from './EnokiClient/type.js';\n\nexport function isEnokiNetwork(network: string): network is EnokiNetwork {\n\treturn network === 'mainnet' || network === 'testnet' || network === 'devnet';\n}\n"],
5
+ "mappings": "AAKO,SAAS,eAAe,SAA0C;AACxE,SAAO,YAAY,aAAa,YAAY,aAAa,YAAY;AACtE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,50 @@
1
+ import type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';
2
+ import type { ZkLoginSession } from './types.js';
3
+ /** Name of the feature for retrieving basic wallet metadata. */
4
+ export declare const EnokiGetMetadata = "enoki:getMetadata";
5
+ /** The latest API version of the getMetadata API. */
6
+ export type EnokiGetMetadataVersion = '1.0.0';
7
+ /**
8
+ * A Wallet Standard feature for retreiving Enoki-specific metadata about the wallet.
9
+ */
10
+ export type EnokiGetMetadataFeature = {
11
+ /** Namespace for the feature. */
12
+ [EnokiGetMetadata]: {
13
+ /** Version of the feature API. */
14
+ version: EnokiGetMetadataVersion;
15
+ getMetadata: EnokiGetMetadataMethod;
16
+ };
17
+ };
18
+ export type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;
19
+ /** Input for retrieving metadata about the wallet. */
20
+ export type EnokiGetMetadataInput = void;
21
+ /** Output of retrieving metadata about the wallet. */
22
+ export type EnokiGetMetadataOutput = {
23
+ /** The social provider for the wallet. */
24
+ provider: AuthProvider;
25
+ };
26
+ /** Name of the feature for retrieving the Enoki session. */
27
+ export declare const EnokiGetSession = "enoki:getSession";
28
+ /** The latest API version of the getSession API. */
29
+ export type EnokiGetSessionVersion = '1.0.0';
30
+ /**
31
+ * A Wallet Standard feature for retreiving the zkLogin session from the wallet.
32
+ */
33
+ export type EnokiGetSessionFeature = {
34
+ /** Namespace for the feature. */
35
+ [EnokiGetSession]: {
36
+ /** Version of the feature API. */
37
+ version: EnokiGetSessionVersion;
38
+ getSession: EnokiGetSessionMethod;
39
+ };
40
+ };
41
+ export type EnokiGetSessionMethod = (input?: EnokiGetSessionInput) => Promise<EnokiGetSessionOutput>;
42
+ /** Input for retrieving the session from the wallet. */
43
+ export type EnokiGetSessionInput = {
44
+ /**
45
+ * The network to retrieve session data for. Defaults to the active network.
46
+ **/
47
+ network?: EnokiNetwork;
48
+ };
49
+ /** Output of retrieving the Enoki session. */
50
+ export type EnokiGetSessionOutput = ZkLoginSession | null;
@@ -0,0 +1,7 @@
1
+ const EnokiGetMetadata = "enoki:getMetadata";
2
+ const EnokiGetSession = "enoki:getSession";
3
+ export {
4
+ EnokiGetMetadata,
5
+ EnokiGetSession
6
+ };
7
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/features.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport type { ZkLoginSession } from './types.js';\n\n/** Name of the feature for retrieving basic wallet metadata. */\nexport const EnokiGetMetadata = 'enoki:getMetadata';\n\n/** The latest API version of the getMetadata API. */\nexport type EnokiGetMetadataVersion = '1.0.0';\n\n/**\n * A Wallet Standard feature for retreiving Enoki-specific metadata about the wallet.\n */\nexport type EnokiGetMetadataFeature = {\n\t/** Namespace for the feature. */\n\t[EnokiGetMetadata]: {\n\t\t/** Version of the feature API. */\n\t\tversion: EnokiGetMetadataVersion;\n\t\tgetMetadata: EnokiGetMetadataMethod;\n\t};\n};\n\nexport type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;\n\n/** Input for retrieving metadata about the wallet. */\nexport type EnokiGetMetadataInput = void;\n\n/** Output of retrieving metadata about the wallet. */\nexport type EnokiGetMetadataOutput = {\n\t/** The social provider for the wallet. */\n\tprovider: AuthProvider;\n};\n\n/** Name of the feature for retrieving the Enoki session. */\nexport const EnokiGetSession = 'enoki:getSession';\n\n/** The latest API version of the getSession API. */\nexport type EnokiGetSessionVersion = '1.0.0';\n\n/**\n * A Wallet Standard feature for retreiving the zkLogin session from the wallet.\n */\nexport type EnokiGetSessionFeature = {\n\t/** Namespace for the feature. */\n\t[EnokiGetSession]: {\n\t\t/** Version of the feature API. */\n\t\tversion: EnokiGetSessionVersion;\n\t\tgetSession: EnokiGetSessionMethod;\n\t};\n};\n\nexport type EnokiGetSessionMethod = (\n\tinput?: EnokiGetSessionInput,\n) => Promise<EnokiGetSessionOutput>;\n\n/** Input for retrieving the session from the wallet. */\nexport type EnokiGetSessionInput = {\n\t/**\n\t * The network to retrieve session data for. Defaults to the active network.\n\t **/\n\tnetwork?: EnokiNetwork;\n};\n\n/** Output of retrieving the Enoki session. */\nexport type EnokiGetSessionOutput = ZkLoginSession | null;\n"],
5
+ "mappings": "AAOO,MAAM,mBAAmB;AA6BzB,MAAM,kBAAkB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ import type { ClientWithCoreApi, Experimental_HaneulClientTypes } from '@haneullabs/haneul/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_HaneulClientTypes.Network[];
7
+ getClient: (network?: Experimental_HaneulClientTypes.Network) => ClientWithCoreApi;
8
+ }): Promise<{
9
+ unregister: () => void;
10
+ }>;
11
+ };
@@ -0,0 +1,21 @@
1
+ import { registerEnokiWallets } from "./register.js";
2
+ function enokiWalletsInitializer(options) {
3
+ return {
4
+ id: "enoki-wallets-initializer",
5
+ async initialize({
6
+ networks,
7
+ getClient
8
+ }) {
9
+ const { unregister } = registerEnokiWallets({
10
+ ...options,
11
+ getCurrentNetwork: () => getClient().network,
12
+ clients: networks.map(getClient)
13
+ });
14
+ return { unregister };
15
+ }
16
+ };
17
+ }
18
+ export {
19
+ enokiWalletsInitializer
20
+ };
21
+ //# sourceMappingURL=initializer.js.map