@mysten/enoki 0.12.15 → 0.13.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/EnokiClient/index.d.ts +2 -0
- package/dist/cjs/EnokiClient/index.js +5 -2
- package/dist/cjs/EnokiClient/index.js.map +2 -2
- package/dist/cjs/EnokiFlow.js +2 -1
- package/dist/cjs/EnokiFlow.js.map +2 -2
- package/dist/cjs/wallet/register.js +1 -0
- package/dist/cjs/wallet/register.js.map +2 -2
- package/dist/cjs/wallet/types.d.ts +1 -1
- package/dist/cjs/wallet/types.js.map +1 -1
- package/dist/cjs/wallet/wallet.d.ts +1 -1
- package/dist/cjs/wallet/wallet.js +2 -1
- package/dist/cjs/wallet/wallet.js.map +2 -2
- package/dist/esm/EnokiClient/index.d.ts +2 -0
- package/dist/esm/EnokiClient/index.js +5 -2
- package/dist/esm/EnokiClient/index.js.map +2 -2
- package/dist/esm/EnokiFlow.js +2 -1
- package/dist/esm/EnokiFlow.js.map +2 -2
- package/dist/esm/wallet/register.js +1 -0
- package/dist/esm/wallet/register.js.map +2 -2
- package/dist/esm/wallet/types.d.ts +1 -1
- package/dist/esm/wallet/wallet.d.ts +1 -1
- package/dist/esm/wallet/wallet.js +2 -1
- package/dist/esm/wallet/wallet.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,8 @@ export interface EnokiClientConfig {
|
|
|
4
4
|
apiKey: string;
|
|
5
5
|
/** The API URL for Enoki. In most cases, this should not be set. */
|
|
6
6
|
apiUrl?: string;
|
|
7
|
+
/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */
|
|
8
|
+
additionalEpochs?: number;
|
|
7
9
|
}
|
|
8
10
|
export declare class EnokiClientError extends Error {
|
|
9
11
|
errors: {
|
|
@@ -30,7 +30,7 @@ __export(EnokiClient_exports, {
|
|
|
30
30
|
EnokiClientError: () => EnokiClientError
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(EnokiClient_exports);
|
|
33
|
-
var _version, _apiUrl, _apiKey, _EnokiClient_instances, fetch_fn;
|
|
33
|
+
var _version, _apiUrl, _apiKey, _additionalEpochs, _EnokiClient_instances, fetch_fn;
|
|
34
34
|
const DEFAULT_API_URL = "https://api.enoki.mystenlabs.com";
|
|
35
35
|
const ZKLOGIN_HEADER = "zklogin-jwt";
|
|
36
36
|
class EnokiClientError extends Error {
|
|
@@ -58,9 +58,11 @@ class EnokiClient {
|
|
|
58
58
|
__privateAdd(this, _version);
|
|
59
59
|
__privateAdd(this, _apiUrl);
|
|
60
60
|
__privateAdd(this, _apiKey);
|
|
61
|
+
__privateAdd(this, _additionalEpochs);
|
|
61
62
|
__privateSet(this, _version, "v1");
|
|
62
63
|
__privateSet(this, _apiUrl, config.apiUrl ?? DEFAULT_API_URL);
|
|
63
64
|
__privateSet(this, _apiKey, config.apiKey);
|
|
65
|
+
__privateSet(this, _additionalEpochs, config.additionalEpochs);
|
|
64
66
|
}
|
|
65
67
|
getApp(_input) {
|
|
66
68
|
return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "app", {
|
|
@@ -89,7 +91,7 @@ class EnokiClient {
|
|
|
89
91
|
body: JSON.stringify({
|
|
90
92
|
network: input.network,
|
|
91
93
|
ephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),
|
|
92
|
-
additionalEpochs: input.additionalEpochs
|
|
94
|
+
additionalEpochs: input.additionalEpochs ?? __privateGet(this, _additionalEpochs)
|
|
93
95
|
})
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -173,6 +175,7 @@ class EnokiClient {
|
|
|
173
175
|
_version = new WeakMap();
|
|
174
176
|
_apiUrl = new WeakMap();
|
|
175
177
|
_apiKey = new WeakMap();
|
|
178
|
+
_additionalEpochs = new WeakMap();
|
|
176
179
|
_EnokiClient_instances = new WeakSet();
|
|
177
180
|
fetch_fn = async function(path, init) {
|
|
178
181
|
const res = await fetch(`${__privateGet(this, _apiUrl)}/${__privateGet(this, _version)}/${path}`, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/EnokiClient/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n\n\t/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */\n\tadditionalEpochs?: number;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\t#additionalEpochs: number | undefined;\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t\tthis.#additionalEpochs = config.additionalEpochs;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs ?? this.#additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAahB,MAAM,yBAAyB,MAAM;AAAA,EAK3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,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,7 +57,8 @@ class EnokiFlow {
|
|
|
57
57
|
__privateAdd(this, _idbStore);
|
|
58
58
|
__privateSet(this, _enokiClient, new import_EnokiClient.EnokiClient({
|
|
59
59
|
apiKey: config.apiKey,
|
|
60
|
-
apiUrl: config.apiUrl
|
|
60
|
+
apiUrl: config.apiUrl,
|
|
61
|
+
additionalEpochs: config.additionalEpochs
|
|
61
62
|
}));
|
|
62
63
|
__privateSet(this, _encryptionKey, config.apiKey);
|
|
63
64
|
if (config.experimental_nativeCryptoSigner) {
|
|
@@ -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(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,
|
|
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\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\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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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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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;",
|
|
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\tadditionalEpochs: config.additionalEpochs,\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,kBAAkB,OAAO;AAAA,QACzB,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -68,7 +68,7 @@ export type RegisterEnokiWalletsOptions = {
|
|
|
68
68
|
* Configuration for each OAuth provider.
|
|
69
69
|
*/
|
|
70
70
|
providers: Partial<Record<AuthProvider, AuthProviderOptions>>;
|
|
71
|
-
} & Pick<EnokiWalletOptions, 'apiKey' | 'apiUrl' | 'windowFeatures'> & (ClientConfig | {
|
|
71
|
+
} & Pick<EnokiWalletOptions, 'apiKey' | 'apiUrl' | 'additionalEpochs' | 'windowFeatures'> & (ClientConfig | {
|
|
72
72
|
/**
|
|
73
73
|
* The SuiClient instance to use when building and executing transactions.
|
|
74
74
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/types.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { StandardEventsListeners, Wallet } from '@mysten/wallet-standard';\n\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\n\nexport type WalletEventsMap = {\n\t[E in keyof StandardEventsListeners]: Parameters<StandardEventsListeners[E]>[0];\n};\n\nexport type ZkLoginState = {\n\taddress: string;\n\tpublicKey: string;\n};\n\nexport type ZkLoginSession = {\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n};\n\nexport type EnokiSessionContext = {\n\tidbStore: UseStore;\n\tclient: ClientWithCoreApi;\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n};\n\ntype ClientConfig = {\n\t/**\n\t * A list of client instances to use when building and executing transactions.\n\t */\n\tclients: ClientWithCoreApi[];\n\n\t/**\n\t * A function that returns the current network that the application is acting on.\n\t */\n\tgetCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n};\n\nexport type EnokiWalletOptions = {\n\t/**\n\t * The window features to use when opening the authorization popup.\n\t * https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures\n\t */\n\twindowFeatures?: string | (() => string);\n\n\t/**\n\t * The authentication provider to register the wallet for.\n\t */\n\tprovider: AuthProvider;\n} & AuthProviderOptions &\n\tEnokiClientConfig &\n\tClientConfig &\n\tPick<Wallet, 'name' | 'icon'>;\n\nexport type AuthProviderOptions = {\n\t/**\n\t * The OAuth client ID.\n\t */\n\tclientId: string;\n\n\t/**\n\t * The URL to redirect to after authorization.\n\t */\n\tredirectUrl?: string;\n\n\t/**\n\t * Extra parameters to include in the authorization URL.\n\t */\n\textraParams?: Record<string, string> | (() => Record<string, string>);\n};\n\nexport type RegisterEnokiWalletsOptions = {\n\t/**\n\t * Configuration for each OAuth provider.\n\t */\n\tproviders: Partial<Record<AuthProvider, AuthProviderOptions>>;\n} & Pick<EnokiWalletOptions, 'apiKey' | 'apiUrl' | 'windowFeatures'> &\n\t(\n\t\t| ClientConfig\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * The SuiClient instance to use when building and executing transactions.\n\t\t\t\t */\n\t\t\t\tclient: SuiClient;\n\n\t\t\t\t/**\n\t\t\t\t * The network to use when building and executing transactions.\n\t\t\t\t * @default 'mainnet'\n\t\t\t\t */\n\t\t\t\tnetwork?: EnokiNetwork;\n\t\t }\n\t);\n"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { StandardEventsListeners, Wallet } from '@mysten/wallet-standard';\n\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\n\nexport type WalletEventsMap = {\n\t[E in keyof StandardEventsListeners]: Parameters<StandardEventsListeners[E]>[0];\n};\n\nexport type ZkLoginState = {\n\taddress: string;\n\tpublicKey: string;\n};\n\nexport type ZkLoginSession = {\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n};\n\nexport type EnokiSessionContext = {\n\tidbStore: UseStore;\n\tclient: ClientWithCoreApi;\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n};\n\ntype ClientConfig = {\n\t/**\n\t * A list of client instances to use when building and executing transactions.\n\t */\n\tclients: ClientWithCoreApi[];\n\n\t/**\n\t * A function that returns the current network that the application is acting on.\n\t */\n\tgetCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n};\n\nexport type EnokiWalletOptions = {\n\t/**\n\t * The window features to use when opening the authorization popup.\n\t * https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures\n\t */\n\twindowFeatures?: string | (() => string);\n\n\t/**\n\t * The authentication provider to register the wallet for.\n\t */\n\tprovider: AuthProvider;\n} & AuthProviderOptions &\n\tEnokiClientConfig &\n\tClientConfig &\n\tPick<Wallet, 'name' | 'icon'>;\n\nexport type AuthProviderOptions = {\n\t/**\n\t * The OAuth client ID.\n\t */\n\tclientId: string;\n\n\t/**\n\t * The URL to redirect to after authorization.\n\t */\n\tredirectUrl?: string;\n\n\t/**\n\t * Extra parameters to include in the authorization URL.\n\t */\n\textraParams?: Record<string, string> | (() => Record<string, string>);\n};\n\nexport type RegisterEnokiWalletsOptions = {\n\t/**\n\t * Configuration for each OAuth provider.\n\t */\n\tproviders: Partial<Record<AuthProvider, AuthProviderOptions>>;\n} & Pick<EnokiWalletOptions, 'apiKey' | 'apiUrl' | 'additionalEpochs' | 'windowFeatures'> &\n\t(\n\t\t| ClientConfig\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * The SuiClient instance to use when building and executing transactions.\n\t\t\t\t */\n\t\t\t\tclient: SuiClient;\n\n\t\t\t\t/**\n\t\t\t\t * The network to use when building and executing transactions.\n\t\t\t\t * @default 'mainnet'\n\t\t\t\t */\n\t\t\t\tnetwork?: EnokiNetwork;\n\t\t }\n\t);\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,5 +12,5 @@ export declare class EnokiWallet implements Wallet {
|
|
|
12
12
|
get chains(): `sui:${string & {}}`[];
|
|
13
13
|
get accounts(): ReadonlyWalletAccount[];
|
|
14
14
|
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature & EnokiGetSessionFeature;
|
|
15
|
-
constructor({ name, icon, provider, clientId, redirectUrl, extraParams, windowFeatures, getCurrentNetwork, apiKey, apiUrl, clients, }: EnokiWalletOptions);
|
|
15
|
+
constructor({ name, icon, provider, clientId, redirectUrl, extraParams, windowFeatures, getCurrentNetwork, apiKey, apiUrl, additionalEpochs, clients, }: EnokiWalletOptions);
|
|
16
16
|
}
|
|
@@ -69,6 +69,7 @@ class EnokiWallet {
|
|
|
69
69
|
getCurrentNetwork,
|
|
70
70
|
apiKey,
|
|
71
71
|
apiUrl,
|
|
72
|
+
additionalEpochs,
|
|
72
73
|
clients
|
|
73
74
|
}) {
|
|
74
75
|
__privateAdd(this, _EnokiWallet_instances);
|
|
@@ -167,7 +168,7 @@ class EnokiWallet {
|
|
|
167
168
|
__privateSet(this, _events, (0, import_mitt.default)());
|
|
168
169
|
__privateSet(this, _name, name);
|
|
169
170
|
__privateSet(this, _icon, icon);
|
|
170
|
-
__privateSet(this, _enokiClient, new import_EnokiClient.EnokiClient({ apiKey, apiUrl }));
|
|
171
|
+
__privateSet(this, _enokiClient, new import_EnokiClient.EnokiClient({ apiKey, apiUrl, additionalEpochs }));
|
|
171
172
|
__privateSet(this, _state, new import_state.EnokiWalletState({ apiKey, clientId, clients }));
|
|
172
173
|
__privateSet(this, _provider, provider);
|
|
173
174
|
__privateSet(this, _clientId, clientId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/wallet.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport type {\n\tIdentifierString,\n\tStandardConnectFeature,\n\tStandardConnectMethod,\n\tStandardDisconnectFeature,\n\tStandardDisconnectMethod,\n\tStandardEventsFeature,\n\tStandardEventsOnMethod,\n\tSuiSignAndExecuteTransactionFeature,\n\tSuiSignAndExecuteTransactionMethod,\n\tSuiSignPersonalMessageFeature,\n\tSuiSignPersonalMessageMethod,\n\tSuiSignTransactionFeature,\n\tSuiSignTransactionMethod,\n\tWallet,\n} from '@mysten/wallet-standard';\nimport {\n\tReadonlyWalletAccount,\n\tStandardConnect,\n\tStandardDisconnect,\n\tStandardEvents,\n\tSuiSignAndExecuteTransaction,\n\tSuiSignPersonalMessage,\n\tSuiSignTransaction,\n} from '@mysten/wallet-standard';\nimport type { Emitter } from 'mitt';\nimport mitt from 'mitt';\n\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport type { EnokiWalletOptions, WalletEventsMap, EnokiSessionContext } from './types.js';\nimport type {\n\tEnokiGetMetadataFeature,\n\tEnokiGetMetadataMethod,\n\tEnokiGetSessionFeature,\n\tEnokiGetSessionMethod,\n} from './features.js';\nimport { EnokiGetMetadata, EnokiGetSession } from './features.js';\nimport type { Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { get, set } from 'idb-keyval';\n\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\n\nimport { EnokiWalletState } from './state.js';\nimport { allTasks } from 'nanostores';\n\nconst pkceFlowProviders: Partial<Record<AuthProvider, { tokenEndpoint: string }>> = {\n\tplaytron: {\n\t\ttokenEndpoint: 'https://oauth2.playtron.one/oauth2/token',\n\t},\n};\n\ntype PKCEContext = { codeChallenge: string; codeVerifier: string };\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#icon: Wallet['icon'];\n\t#enokiClient: EnokiClient;\n\t#state: EnokiWalletState;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string;\n\t#extraParams: Record<string, string> | (() => Record<string, string>) | undefined;\n\t#getCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n\t#windowFeatures?: string | (() => string);\n\n\tget name() {\n\t\treturn this.#name;\n\t}\n\n\tget provider() {\n\t\treturn this.#provider;\n\t}\n\n\tget icon() {\n\t\treturn this.#icon;\n\t}\n\n\tget version() {\n\t\treturn '1.0.0' as const;\n\t}\n\n\tget chains() {\n\t\treturn [...this.#state.sessionContextByNetwork.keys()].map(\n\t\t\t(network) => `sui:${network}` as const,\n\t\t);\n\t}\n\n\tget accounts() {\n\t\treturn this.#accounts;\n\t}\n\n\tget features(): StandardConnectFeature &\n\t\tStandardDisconnectFeature &\n\t\tStandardEventsFeature &\n\t\tSuiSignTransactionFeature &\n\t\tSuiSignAndExecuteTransactionFeature &\n\t\tSuiSignPersonalMessageFeature &\n\t\tEnokiGetMetadataFeature &\n\t\tEnokiGetSessionFeature {\n\t\treturn {\n\t\t\t[StandardConnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tconnect: this.#connect,\n\t\t\t},\n\t\t\t[StandardDisconnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdisconnect: this.#disconnect,\n\t\t\t},\n\t\t\t[StandardEvents]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\ton: this.#on,\n\t\t\t},\n\t\t\t[SuiSignTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignTransaction: this.#signTransaction,\n\t\t\t},\n\t\t\t[SuiSignAndExecuteTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignAndExecuteTransaction: this.#signAndExecuteTransaction,\n\t\t\t},\n\t\t\t[SuiSignPersonalMessage]: {\n\t\t\t\tversion: '1.1.0',\n\t\t\t\tsignPersonalMessage: this.#signPersonalMessage,\n\t\t\t},\n\t\t\t[EnokiGetMetadata]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetMetadata: this.#getMetadata,\n\t\t\t},\n\t\t\t[EnokiGetSession]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetSession: this.#getSession,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\twindowFeatures,\n\t\tgetCurrentNetwork,\n\t\tapiKey,\n\t\tapiUrl,\n\t\tclients,\n\t}: EnokiWalletOptions) {\n\t\tthis.#events = mitt();\n\t\tthis.#name = name;\n\t\tthis.#icon = icon;\n\t\tthis.#enokiClient = new EnokiClient({ apiKey, apiUrl });\n\t\tthis.#state = new EnokiWalletState({ apiKey, clientId, clients });\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl || window.location.href.split('#')[0];\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\t\tthis.#getCurrentNetwork = getCurrentNetwork;\n\t\tthis.#accounts = [];\n\n\t\tthis.#state.zkLoginState.subscribe(() => {\n\t\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t\t});\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account, signal }) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\t\treturn keypair.signTransaction(await parsedTransaction.build({ client }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t\tsignal,\n\t}) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst bytes = await parsedTransaction.build({ client });\n\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\n\t\tconst result = await keypair.signAndExecuteTransaction({\n\t\t\ttransaction: parsedTransaction,\n\t\t\tclient,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: result.signatures[0],\n\t\t\tdigest: result.digest,\n\t\t\teffects: toBase64(result.effects.bcs!),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tconst { keypair } = await this.#getSignerContext(chain);\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn keypair.signPersonalMessage(message);\n\t};\n\n\t#getMetadata: EnokiGetMetadataMethod = () => {\n\t\treturn {\n\t\t\tprovider: this.#provider,\n\t\t};\n\t};\n\n\t#getSession: EnokiGetSessionMethod = async (input) => {\n\t\tconst sessionContext = this.#state.getSessionContext(\n\t\t\tinput?.network ?? this.#getCurrentNetwork(),\n\t\t);\n\t\treturn await this.#state.getSession(sessionContext);\n\t};\n\n\t#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\t// NOTE: This is a hackfix for the old version of dApp Kit where auto-connection logic\n\t\t// only fires on initial mount of the WalletProvider component. Since hydrating the\n\t\t// zkLogin state from IndexedDB is an asynchronous process, we need to make sure it\n\t\t// is populated before the connect logic runs.\n\t\tawait allTasks();\n\n\t\tif (input?.silent || this.#accounts.length > 0) {\n\t\t\treturn { accounts: this.#accounts };\n\t\t}\n\n\t\tconst currentNetwork = this.#getCurrentNetwork();\n\t\tawait this.#createSession({ network: currentNetwork });\n\n\t\treturn { accounts: this.#accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#state.logout();\n\t\tthis.#accounts = [];\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t};\n\n\t#getAuthorizedAccounts() {\n\t\tconst zkLoginState = this.#state.zkLoginState.get();\n\t\tif (zkLoginState) {\n\t\t\treturn [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: zkLoginState.address,\n\t\t\t\t\tchains: this.chains,\n\t\t\t\t\ticon: this.icon,\n\t\t\t\t\tfeatures: [SuiSignPersonalMessage, SuiSignTransaction, SuiSignAndExecuteTransaction],\n\t\t\t\t\tpublicKey: fromBase64(zkLoginState.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t}\n\n\tasync #getKeypair(sessionContext: EnokiSessionContext) {\n\t\tconst session = await this.#state.getSession(sessionContext);\n\t\tif (!session?.jwt || Date.now() > session.expiresAt) {\n\t\t\tawait this.#createSession({ network: sessionContext.client.network });\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.idbStore,\n\t\t);\n\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst updatedSession = await this.#state.getSession(sessionContext);\n\t\tif (!updatedSession?.jwt) {\n\t\t\tthrow new Error('Failed to retrieve an active session.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\t\tconst proof =\n\t\t\tupdatedSession.proof ??\n\t\t\t(await this.#enokiClient.createZkLoginZkp({\n\t\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tjwt: updatedSession.jwt,\n\t\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\t\trandomness: updatedSession.randomness,\n\t\t\t\tephemeralPublicKey: ephemeralKeypair.getPublicKey(),\n\t\t\t}));\n\n\t\tawait this.#state.setSession(sessionContext, { ...updatedSession, proof });\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress: this.accounts[0].address,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\tephemeralKeypair,\n\t\t\tproof,\n\t\t});\n\t}\n\n\tasync #getSignerContext(chain?: IdentifierString) {\n\t\tconst sessionContext = chain ? this.#state.getSessionContext(chain.split(':')[1]) : null;\n\t\tif (!sessionContext) {\n\t\t\tthrow new Error(\n\t\t\t\t`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`,\n\t\t\t);\n\t\t}\n\n\t\tconst keypair = await this.#getKeypair(sessionContext);\n\t\treturn { client: sessionContext.client, keypair };\n\t}\n\n\tasync #createSession({ network }: { network: Experimental_SuiClientTypes.Network }) {\n\t\tconst popup = window.open(\n\t\t\t'about:blank',\n\t\t\t'_blank',\n\t\t\ttypeof this.#windowFeatures === 'function' ? this.#windowFeatures() : this.#windowFeatures,\n\t\t);\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst sessionContext = this.#state.getSessionContext(network);\n\t\tconst pkceContext = await this.#getPKCEFlowContext();\n\n\t\tpopup.location = await this.#createAuthorizationURL(sessionContext, pkceContext);\n\n\t\treturn await new Promise<void>((resolve, reject) => {\n\t\t\tconst interval = setInterval(() => {\n\t\t\t\ttry {\n\t\t\t\t\tif (popup.closed) {\n\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\treject(new Error('Popup closed'));\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((!pkceContext && !popup.location.hash) || (pkceContext && !popup.location.search)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearInterval(interval);\n\n\t\t\t\tthis.#handleAuthCallback({\n\t\t\t\t\thash: popup.location.hash,\n\t\t\t\t\tsessionContext,\n\t\t\t\t\tsearch: popup.location.search,\n\t\t\t\t\tpkceContext,\n\t\t\t\t}).then(() => resolve(), reject);\n\n\t\t\t\ttry {\n\t\t\t\t\tpopup.close();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}, 16);\n\t\t});\n\t}\n\n\tasync #getPKCEFlowContext(): Promise<PKCEContext | undefined> {\n\t\tif (!pkceFlowProviders[this.#provider]) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst array = new Uint8Array(64);\n\t\tcrypto.getRandomValues(array);\n\t\tconst codeVerifier = toBase64(array).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n\t\tconst codeChallenge = toBase64(\n\t\t\tnew Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier))),\n\t\t)\n\t\t\t.replace(/=/g, '')\n\t\t\t.replace(/\\+/g, '-')\n\t\t\t.replace(/\\//g, '_');\n\n\t\treturn { codeVerifier, codeChallenge };\n\t}\n\n\tasync #createAuthorizationURL(sessionContext: EnokiSessionContext, pkceContext?: PKCEContext) {\n\t\tconst ephemeralKeyPair = await WebCryptoSigner.generate();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst extraParams =\n\t\t\ttypeof this.#extraParams === 'function' ? this.#extraParams() : this.#extraParams;\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: this.#clientId,\n\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\tscope: ['openid', ...(extraParams?.scope ? extraParams.scope.split(' ') : [])]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t\t...(pkceContext\n\t\t\t\t? {\n\t\t\t\t\t\tresponse_type: 'code',\n\t\t\t\t\t\tcode_challenge_method: 'S256',\n\t\t\t\t\t\tcode_challenge: pkceContext.codeChallenge,\n\t\t\t\t\t}\n\t\t\t\t: undefined),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (this.#provider) {\n\t\t\tcase 'google':\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'facebook':\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'twitch':\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'onefc':\n\t\t\t\toauthUrl = `https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'playtron':\n\t\t\t\toauthUrl = `https://oauth2.playtron.one/oauth2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${this.#provider}`);\n\t\t}\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), sessionContext.idbStore);\n\t\tawait this.#state.setSession(sessionContext, {\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\tasync #handleAuthCallback({\n\t\thash,\n\t\tsessionContext,\n\t\tpkceContext,\n\t\tsearch,\n\t}: {\n\t\thash: string;\n\t\tsessionContext: EnokiSessionContext;\n\t\tpkceContext?: PKCEContext;\n\t\tsearch: string;\n\t}) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (!zkp?.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = pkceContext\n\t\t\t? await this.#pkceTokenExchange(search, pkceContext)\n\t\t\t: params.get('id_token');\n\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.#state.zkLoginState.set({ address, publicKey });\n\t\tawait this.#state.setSession(sessionContext, { ...zkp, jwt });\n\n\t\treturn params.get('state');\n\t}\n\n\tasync #pkceTokenExchange(search: string, pkceContext: PKCEContext) {\n\t\tconst params = new URLSearchParams(search);\n\t\tconst code = params.get('code');\n\n\t\tif (!code) {\n\t\t\tthrow new Error('Missing code');\n\t\t}\n\n\t\tconst tokenEndpoint = pkceFlowProviders[this.#provider]?.tokenEndpoint;\n\n\t\tif (!tokenEndpoint) {\n\t\t\tthrow new Error(`PKCE flow not supported for provider: ${this.#provider}`);\n\t\t}\n\n\t\tconst response = await fetch(tokenEndpoint, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: new URLSearchParams({\n\t\t\t\tgrant_type: 'authorization_code',\n\t\t\t\tclient_id: this.#clientId,\n\t\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\t\tcode,\n\t\t\t\tcode_verifier: pkceContext.codeVerifier,\n\t\t\t}),\n\t\t});\n\n\t\treturn (await response.json()).id_token;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA4B;AAC5B,mBAAqC;AAiBrC,6BAQO;AAEP,kBAAiB;AAUjB,sBAAkD;AAElD,qBAA0B;AAE1B,uBAAgC;AAChC,wBAAyB;AAEzB,yBAA4B;AAE5B,0BAA6B;AAE7B,mBAAiC;AACjC,wBAAyB;AArDzB;AAuDA,MAAM,oBAA8E;AAAA,EACnF,UAAU;AAAA,IACT,eAAe;AAAA,EAChB;AACD;AAIO,MAAM,YAA8B;AAAA,EAoF1C,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAuB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport type {\n\tIdentifierString,\n\tStandardConnectFeature,\n\tStandardConnectMethod,\n\tStandardDisconnectFeature,\n\tStandardDisconnectMethod,\n\tStandardEventsFeature,\n\tStandardEventsOnMethod,\n\tSuiSignAndExecuteTransactionFeature,\n\tSuiSignAndExecuteTransactionMethod,\n\tSuiSignPersonalMessageFeature,\n\tSuiSignPersonalMessageMethod,\n\tSuiSignTransactionFeature,\n\tSuiSignTransactionMethod,\n\tWallet,\n} from '@mysten/wallet-standard';\nimport {\n\tReadonlyWalletAccount,\n\tStandardConnect,\n\tStandardDisconnect,\n\tStandardEvents,\n\tSuiSignAndExecuteTransaction,\n\tSuiSignPersonalMessage,\n\tSuiSignTransaction,\n} from '@mysten/wallet-standard';\nimport type { Emitter } from 'mitt';\nimport mitt from 'mitt';\n\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport type { EnokiWalletOptions, WalletEventsMap, EnokiSessionContext } from './types.js';\nimport type {\n\tEnokiGetMetadataFeature,\n\tEnokiGetMetadataMethod,\n\tEnokiGetSessionFeature,\n\tEnokiGetSessionMethod,\n} from './features.js';\nimport { EnokiGetMetadata, EnokiGetSession } from './features.js';\nimport type { Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { get, set } from 'idb-keyval';\n\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\n\nimport { EnokiWalletState } from './state.js';\nimport { allTasks } from 'nanostores';\n\nconst pkceFlowProviders: Partial<Record<AuthProvider, { tokenEndpoint: string }>> = {\n\tplaytron: {\n\t\ttokenEndpoint: 'https://oauth2.playtron.one/oauth2/token',\n\t},\n};\n\ntype PKCEContext = { codeChallenge: string; codeVerifier: string };\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#icon: Wallet['icon'];\n\t#enokiClient: EnokiClient;\n\t#state: EnokiWalletState;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string;\n\t#extraParams: Record<string, string> | (() => Record<string, string>) | undefined;\n\t#getCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n\t#windowFeatures?: string | (() => string);\n\n\tget name() {\n\t\treturn this.#name;\n\t}\n\n\tget provider() {\n\t\treturn this.#provider;\n\t}\n\n\tget icon() {\n\t\treturn this.#icon;\n\t}\n\n\tget version() {\n\t\treturn '1.0.0' as const;\n\t}\n\n\tget chains() {\n\t\treturn [...this.#state.sessionContextByNetwork.keys()].map(\n\t\t\t(network) => `sui:${network}` as const,\n\t\t);\n\t}\n\n\tget accounts() {\n\t\treturn this.#accounts;\n\t}\n\n\tget features(): StandardConnectFeature &\n\t\tStandardDisconnectFeature &\n\t\tStandardEventsFeature &\n\t\tSuiSignTransactionFeature &\n\t\tSuiSignAndExecuteTransactionFeature &\n\t\tSuiSignPersonalMessageFeature &\n\t\tEnokiGetMetadataFeature &\n\t\tEnokiGetSessionFeature {\n\t\treturn {\n\t\t\t[StandardConnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tconnect: this.#connect,\n\t\t\t},\n\t\t\t[StandardDisconnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdisconnect: this.#disconnect,\n\t\t\t},\n\t\t\t[StandardEvents]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\ton: this.#on,\n\t\t\t},\n\t\t\t[SuiSignTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignTransaction: this.#signTransaction,\n\t\t\t},\n\t\t\t[SuiSignAndExecuteTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignAndExecuteTransaction: this.#signAndExecuteTransaction,\n\t\t\t},\n\t\t\t[SuiSignPersonalMessage]: {\n\t\t\t\tversion: '1.1.0',\n\t\t\t\tsignPersonalMessage: this.#signPersonalMessage,\n\t\t\t},\n\t\t\t[EnokiGetMetadata]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetMetadata: this.#getMetadata,\n\t\t\t},\n\t\t\t[EnokiGetSession]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetSession: this.#getSession,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\twindowFeatures,\n\t\tgetCurrentNetwork,\n\t\tapiKey,\n\t\tapiUrl,\n\t\tadditionalEpochs,\n\t\tclients,\n\t}: EnokiWalletOptions) {\n\t\tthis.#events = mitt();\n\t\tthis.#name = name;\n\t\tthis.#icon = icon;\n\t\tthis.#enokiClient = new EnokiClient({ apiKey, apiUrl, additionalEpochs });\n\t\tthis.#state = new EnokiWalletState({ apiKey, clientId, clients });\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl || window.location.href.split('#')[0];\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\t\tthis.#getCurrentNetwork = getCurrentNetwork;\n\t\tthis.#accounts = [];\n\n\t\tthis.#state.zkLoginState.subscribe(() => {\n\t\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t\t});\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account, signal }) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\t\treturn keypair.signTransaction(await parsedTransaction.build({ client }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t\tsignal,\n\t}) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst bytes = await parsedTransaction.build({ client });\n\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\n\t\tconst result = await keypair.signAndExecuteTransaction({\n\t\t\ttransaction: parsedTransaction,\n\t\t\tclient,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: result.signatures[0],\n\t\t\tdigest: result.digest,\n\t\t\teffects: toBase64(result.effects.bcs!),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tconst { keypair } = await this.#getSignerContext(chain);\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn keypair.signPersonalMessage(message);\n\t};\n\n\t#getMetadata: EnokiGetMetadataMethod = () => {\n\t\treturn {\n\t\t\tprovider: this.#provider,\n\t\t};\n\t};\n\n\t#getSession: EnokiGetSessionMethod = async (input) => {\n\t\tconst sessionContext = this.#state.getSessionContext(\n\t\t\tinput?.network ?? this.#getCurrentNetwork(),\n\t\t);\n\t\treturn await this.#state.getSession(sessionContext);\n\t};\n\n\t#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\t// NOTE: This is a hackfix for the old version of dApp Kit where auto-connection logic\n\t\t// only fires on initial mount of the WalletProvider component. Since hydrating the\n\t\t// zkLogin state from IndexedDB is an asynchronous process, we need to make sure it\n\t\t// is populated before the connect logic runs.\n\t\tawait allTasks();\n\n\t\tif (input?.silent || this.#accounts.length > 0) {\n\t\t\treturn { accounts: this.#accounts };\n\t\t}\n\n\t\tconst currentNetwork = this.#getCurrentNetwork();\n\t\tawait this.#createSession({ network: currentNetwork });\n\n\t\treturn { accounts: this.#accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#state.logout();\n\t\tthis.#accounts = [];\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t};\n\n\t#getAuthorizedAccounts() {\n\t\tconst zkLoginState = this.#state.zkLoginState.get();\n\t\tif (zkLoginState) {\n\t\t\treturn [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: zkLoginState.address,\n\t\t\t\t\tchains: this.chains,\n\t\t\t\t\ticon: this.icon,\n\t\t\t\t\tfeatures: [SuiSignPersonalMessage, SuiSignTransaction, SuiSignAndExecuteTransaction],\n\t\t\t\t\tpublicKey: fromBase64(zkLoginState.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t}\n\n\tasync #getKeypair(sessionContext: EnokiSessionContext) {\n\t\tconst session = await this.#state.getSession(sessionContext);\n\t\tif (!session?.jwt || Date.now() > session.expiresAt) {\n\t\t\tawait this.#createSession({ network: sessionContext.client.network });\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.idbStore,\n\t\t);\n\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst updatedSession = await this.#state.getSession(sessionContext);\n\t\tif (!updatedSession?.jwt) {\n\t\t\tthrow new Error('Failed to retrieve an active session.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\t\tconst proof =\n\t\t\tupdatedSession.proof ??\n\t\t\t(await this.#enokiClient.createZkLoginZkp({\n\t\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tjwt: updatedSession.jwt,\n\t\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\t\trandomness: updatedSession.randomness,\n\t\t\t\tephemeralPublicKey: ephemeralKeypair.getPublicKey(),\n\t\t\t}));\n\n\t\tawait this.#state.setSession(sessionContext, { ...updatedSession, proof });\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress: this.accounts[0].address,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\tephemeralKeypair,\n\t\t\tproof,\n\t\t});\n\t}\n\n\tasync #getSignerContext(chain?: IdentifierString) {\n\t\tconst sessionContext = chain ? this.#state.getSessionContext(chain.split(':')[1]) : null;\n\t\tif (!sessionContext) {\n\t\t\tthrow new Error(\n\t\t\t\t`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`,\n\t\t\t);\n\t\t}\n\n\t\tconst keypair = await this.#getKeypair(sessionContext);\n\t\treturn { client: sessionContext.client, keypair };\n\t}\n\n\tasync #createSession({ network }: { network: Experimental_SuiClientTypes.Network }) {\n\t\tconst popup = window.open(\n\t\t\t'about:blank',\n\t\t\t'_blank',\n\t\t\ttypeof this.#windowFeatures === 'function' ? this.#windowFeatures() : this.#windowFeatures,\n\t\t);\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst sessionContext = this.#state.getSessionContext(network);\n\t\tconst pkceContext = await this.#getPKCEFlowContext();\n\n\t\tpopup.location = await this.#createAuthorizationURL(sessionContext, pkceContext);\n\n\t\treturn await new Promise<void>((resolve, reject) => {\n\t\t\tconst interval = setInterval(() => {\n\t\t\t\ttry {\n\t\t\t\t\tif (popup.closed) {\n\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\treject(new Error('Popup closed'));\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((!pkceContext && !popup.location.hash) || (pkceContext && !popup.location.search)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearInterval(interval);\n\n\t\t\t\tthis.#handleAuthCallback({\n\t\t\t\t\thash: popup.location.hash,\n\t\t\t\t\tsessionContext,\n\t\t\t\t\tsearch: popup.location.search,\n\t\t\t\t\tpkceContext,\n\t\t\t\t}).then(() => resolve(), reject);\n\n\t\t\t\ttry {\n\t\t\t\t\tpopup.close();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}, 16);\n\t\t});\n\t}\n\n\tasync #getPKCEFlowContext(): Promise<PKCEContext | undefined> {\n\t\tif (!pkceFlowProviders[this.#provider]) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst array = new Uint8Array(64);\n\t\tcrypto.getRandomValues(array);\n\t\tconst codeVerifier = toBase64(array).replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n\t\tconst codeChallenge = toBase64(\n\t\t\tnew Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier))),\n\t\t)\n\t\t\t.replace(/=/g, '')\n\t\t\t.replace(/\\+/g, '-')\n\t\t\t.replace(/\\//g, '_');\n\n\t\treturn { codeVerifier, codeChallenge };\n\t}\n\n\tasync #createAuthorizationURL(sessionContext: EnokiSessionContext, pkceContext?: PKCEContext) {\n\t\tconst ephemeralKeyPair = await WebCryptoSigner.generate();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst extraParams =\n\t\t\ttypeof this.#extraParams === 'function' ? this.#extraParams() : this.#extraParams;\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: this.#clientId,\n\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\tscope: ['openid', ...(extraParams?.scope ? extraParams.scope.split(' ') : [])]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t\t...(pkceContext\n\t\t\t\t? {\n\t\t\t\t\t\tresponse_type: 'code',\n\t\t\t\t\t\tcode_challenge_method: 'S256',\n\t\t\t\t\t\tcode_challenge: pkceContext.codeChallenge,\n\t\t\t\t\t}\n\t\t\t\t: undefined),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (this.#provider) {\n\t\t\tcase 'google':\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'facebook':\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'twitch':\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'onefc':\n\t\t\t\toauthUrl = `https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tcase 'playtron':\n\t\t\t\toauthUrl = `https://oauth2.playtron.one/oauth2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${this.#provider}`);\n\t\t}\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), sessionContext.idbStore);\n\t\tawait this.#state.setSession(sessionContext, {\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\tasync #handleAuthCallback({\n\t\thash,\n\t\tsessionContext,\n\t\tpkceContext,\n\t\tsearch,\n\t}: {\n\t\thash: string;\n\t\tsessionContext: EnokiSessionContext;\n\t\tpkceContext?: PKCEContext;\n\t\tsearch: string;\n\t}) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (!zkp?.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = pkceContext\n\t\t\t? await this.#pkceTokenExchange(search, pkceContext)\n\t\t\t: params.get('id_token');\n\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.#state.zkLoginState.set({ address, publicKey });\n\t\tawait this.#state.setSession(sessionContext, { ...zkp, jwt });\n\n\t\treturn params.get('state');\n\t}\n\n\tasync #pkceTokenExchange(search: string, pkceContext: PKCEContext) {\n\t\tconst params = new URLSearchParams(search);\n\t\tconst code = params.get('code');\n\n\t\tif (!code) {\n\t\t\tthrow new Error('Missing code');\n\t\t}\n\n\t\tconst tokenEndpoint = pkceFlowProviders[this.#provider]?.tokenEndpoint;\n\n\t\tif (!tokenEndpoint) {\n\t\t\tthrow new Error(`PKCE flow not supported for provider: ${this.#provider}`);\n\t\t}\n\n\t\tconst response = await fetch(tokenEndpoint, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: new URLSearchParams({\n\t\t\t\tgrant_type: 'authorization_code',\n\t\t\t\tclient_id: this.#clientId,\n\t\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\t\tcode,\n\t\t\t\tcode_verifier: pkceContext.codeVerifier,\n\t\t\t}),\n\t\t});\n\n\t\treturn (await response.json()).id_token;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA4B;AAC5B,mBAAqC;AAiBrC,6BAQO;AAEP,kBAAiB;AAUjB,sBAAkD;AAElD,qBAA0B;AAE1B,uBAAgC;AAChC,wBAAyB;AAEzB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S,GAAG;AAEzD,MAAI,CAAC,eAAe;AACnB,UAAM,IAAI,MAAM,yCAAyC,mBAAK,UAAS,EAAE;AAAA,EAC1E;AAEA,QAAM,WAAW,MAAM,MAAM,eAAe;AAAA,IAC3C,QAAQ;AAAA,IACR,MAAM,IAAI,gBAAgB;AAAA,MACzB,YAAY;AAAA,MACZ,WAAW,mBAAK;AAAA,MAChB,cAAc,mBAAK;AAAA,MACnB;AAAA,MACA,eAAe,YAAY;AAAA,IAC5B,CAAC;AAAA,EACF,CAAC;AAED,UAAQ,MAAM,SAAS,KAAK,GAAG;AAChC;",
|
|
6
6
|
"names": ["mitt"]
|
|
7
7
|
}
|
|
@@ -4,6 +4,8 @@ export interface EnokiClientConfig {
|
|
|
4
4
|
apiKey: string;
|
|
5
5
|
/** The API URL for Enoki. In most cases, this should not be set. */
|
|
6
6
|
apiUrl?: string;
|
|
7
|
+
/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */
|
|
8
|
+
additionalEpochs?: number;
|
|
7
9
|
}
|
|
8
10
|
export declare class EnokiClientError extends Error {
|
|
9
11
|
errors: {
|
|
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
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
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
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
-
var _version, _apiUrl, _apiKey, _EnokiClient_instances, fetch_fn;
|
|
9
|
+
var _version, _apiUrl, _apiKey, _additionalEpochs, _EnokiClient_instances, fetch_fn;
|
|
10
10
|
const DEFAULT_API_URL = "https://api.enoki.mystenlabs.com";
|
|
11
11
|
const ZKLOGIN_HEADER = "zklogin-jwt";
|
|
12
12
|
class EnokiClientError extends Error {
|
|
@@ -34,9 +34,11 @@ class EnokiClient {
|
|
|
34
34
|
__privateAdd(this, _version);
|
|
35
35
|
__privateAdd(this, _apiUrl);
|
|
36
36
|
__privateAdd(this, _apiKey);
|
|
37
|
+
__privateAdd(this, _additionalEpochs);
|
|
37
38
|
__privateSet(this, _version, "v1");
|
|
38
39
|
__privateSet(this, _apiUrl, config.apiUrl ?? DEFAULT_API_URL);
|
|
39
40
|
__privateSet(this, _apiKey, config.apiKey);
|
|
41
|
+
__privateSet(this, _additionalEpochs, config.additionalEpochs);
|
|
40
42
|
}
|
|
41
43
|
getApp(_input) {
|
|
42
44
|
return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "app", {
|
|
@@ -65,7 +67,7 @@ class EnokiClient {
|
|
|
65
67
|
body: JSON.stringify({
|
|
66
68
|
network: input.network,
|
|
67
69
|
ephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),
|
|
68
|
-
additionalEpochs: input.additionalEpochs
|
|
70
|
+
additionalEpochs: input.additionalEpochs ?? __privateGet(this, _additionalEpochs)
|
|
69
71
|
})
|
|
70
72
|
});
|
|
71
73
|
}
|
|
@@ -149,6 +151,7 @@ class EnokiClient {
|
|
|
149
151
|
_version = new WeakMap();
|
|
150
152
|
_apiUrl = new WeakMap();
|
|
151
153
|
_apiKey = new WeakMap();
|
|
154
|
+
_additionalEpochs = new WeakMap();
|
|
152
155
|
_EnokiClient_instances = new WeakSet();
|
|
153
156
|
fetch_fn = async function(path, init) {
|
|
154
157
|
const res = await fetch(`${__privateGet(this, _apiUrl)}/${__privateGet(this, _version)}/${path}`, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/EnokiClient/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAAA;AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n\n\t/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */\n\tadditionalEpochs?: number;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\t#additionalEpochs: number | undefined;\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t\tthis.#additionalEpochs = config.additionalEpochs;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs ?? this.#additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAahB,MAAM,yBAAyB,MAAM;AAAA,EAK3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,QAAQ;AAAA,IAER;AACA,UAAM,QAAQ,SAAS,CAAC,IAAI,IAAI,MAAM,OAAO,CAAC,EAAE,OAAO,IAAI;AAC3D,UAAM,wCAAwC,MAAM,KAAK;AAAA,MACxD;AAAA,IACD,CAAC;AAjBF,kBAA6D,CAAC;AAkB7D,SAAK,SAAS,UAAU,CAAC;AACzB,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,SAAS,CAAC,GAAG,QAAQ;AAAA,EAClC;AACD;AAKO,MAAM,YAAY;AAAA,EAMxB,YAAY,QAA2B;AANjC;AACN;AACA;AACA;AACA;AAGC,uBAAK,UAAW;AAChB,uBAAK,SAAU,O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AAC3C,0BAAK,kCAAL,WAAsC,YAAY;AAAA,MACjD,QAAQ;AAAA,MACR,MAAM,KAAK,UAAU;AAAA,QACpB,SAAS,MAAM;AAAA,QACf,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM;AAAA,MAChB,CAAC;AAAA,IACF;AAAA,EACD;AAqBD;AA9JC;AACA;AACA;AACA;AAJM;AA4IA,WAAmB,eAAC,MAAc,MAA+B;AACtE,QAAM,MAAM,MAAM,MAAM,GAAG,mBAAK,QAAO,IAAI,mBAAK,SAAQ,IAAI,IAAI,IAAI;AAAA,IACnE,GAAG;AAAA,IACH,SAAS;AAAA,MACR,GAAG,KAAK;AAAA,MACR,eAAe,UAAU,mBAAK,QAAO;AAAA,MACrC,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,iBAAiB,IAAI,QAAQ,MAAM,IAAI,KAAK,CAAC;AAAA,EACxD;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/EnokiFlow.js
CHANGED
|
@@ -34,7 +34,8 @@ class EnokiFlow {
|
|
|
34
34
|
__privateAdd(this, _idbStore);
|
|
35
35
|
__privateSet(this, _enokiClient, new EnokiClient({
|
|
36
36
|
apiKey: config.apiKey,
|
|
37
|
-
apiUrl: config.apiUrl
|
|
37
|
+
apiUrl: config.apiUrl,
|
|
38
|
+
additionalEpochs: config.additionalEpochs
|
|
38
39
|
}));
|
|
39
40
|
__privateSet(this, _encryptionKey, config.apiKey);
|
|
40
41
|
if (config.experimental_nativeCryptoSigner) {
|