@mysten/enoki 0.0.2 → 0.0.4

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mysten/enoki
2
2
 
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 732fdbb5b: Make enoki flow session observable. Expose state parameter on useAuthCallback.
8
+
9
+ ## 0.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - dfa523c77: Key storage off of the API key, and add APIs for transaction block sponsorship
14
+
3
15
  ## 0.0.2
4
16
 
5
17
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
1
+ import type { CreateSponsoredTransactionBlockApiInput, CreateSponsoredTransactionBlockApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
2
2
  export interface EnokiClientConfig {
3
3
  /** The API key for the Enoki app, available in the Enoki Portal. */
4
4
  apiKey: string;
@@ -15,4 +15,5 @@ export declare class EnokiClient {
15
15
  getZkLogin(input: GetZkLoginApiInput): Promise<GetZkLoginApiResponse>;
16
16
  createZkLoginNonce(input: CreateZkLoginNonceApiInput): Promise<CreateZkLoginNonceApiResponse>;
17
17
  createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
18
+ createSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput): Promise<CreateSponsoredTransactionBlockApiResponse>;
18
19
  }
@@ -78,7 +78,7 @@ class EnokiClient {
78
78
  });
79
79
  }
80
80
  createZkLoginZkp(input) {
81
- return __privateMethod(this, _fetch, fetch_fn).call(this, "zklogin/kzp", {
81
+ return __privateMethod(this, _fetch, fetch_fn).call(this, "zklogin/zkp", {
82
82
  method: "POST",
83
83
  headers: {
84
84
  [ZKLOGIN_HEADER]: input.jwt
@@ -90,6 +90,18 @@ class EnokiClient {
90
90
  })
91
91
  });
92
92
  }
93
+ createSponsoredTransactionBlock(input) {
94
+ return __privateMethod(this, _fetch, fetch_fn).call(this, "transaction-blocks/sponsor", {
95
+ method: "POST",
96
+ headers: {
97
+ [ZKLOGIN_HEADER]: input.jwt
98
+ },
99
+ body: JSON.stringify({
100
+ network: input.network,
101
+ transactionBlockKindBytes: input.transactionBlockKindBytes
102
+ })
103
+ });
104
+ }
93
105
  }
94
106
  _version = new WeakMap();
95
107
  _apiUrl = new WeakMap();
@@ -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\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\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\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\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\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/kzp', {\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\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\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 Error('Failed to fetch');\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
5
-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AAG;AAAA,IACH,SAAS;AAAA,MACR,GAAG,KAAK;AAAA,MACR,eAAe,UAAU,mBAAK;AAAA,MAC9B,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,MAAM,iBAAiB;AAAA,EAClC;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionBlockApiInput,\n\tCreateSponsoredTransactionBlockApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\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\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\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\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\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\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\tcreateSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionBlockApiResponse>('transaction-blocks/sponsor', {\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\ttransactionBlockKindBytes: input.transactionBlockKindBytes,\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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AAK,kBAAL,WAAwD,8BAA8B;AAAA,MAC5F,QAAQ;AAAA,MACR,SAAS;AAAA,QACR,CAAC,cAAc,GAAG,MAAM;AAAA,MACzB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACpB,SAAS,MAAM;AAAA,QACf,2BAA2B,MAAM;AAAA,MAClC,CAAC;AAAA,IACF;AAAA,EACD;AAqBD;AAhFC;AACA;AACA;AA2DM;AAAA,WAAmB,eAAC,MAAc,MAA+B;AACtE,QAAM,MAAM,MAAM,MAAM,GAAG,mBAAK,YAAW,mBAAK,aAAY,QAAQ;AAAA,IACnE,GAAG;AAAA,IACH,SAAS;AAAA,MACR,GAAG,KAAK;AAAA,MACR,eAAe,UAAU,mBAAK;AAAA,MAC9B,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,MAAM,iBAAiB;AAAA,EAClC;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -34,3 +34,15 @@ export interface CreateZkLoginZkpApiInput {
34
34
  }
35
35
  export interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {
36
36
  }
37
+ export interface CreateSponsoredTransactionBlockApiInput {
38
+ network?: 'mainnet' | 'testnet';
39
+ jwt: string;
40
+ transactionBlockKindBytes: string;
41
+ }
42
+ export interface CreateSponsoredTransactionBlockApiResponse {
43
+ bytes: string;
44
+ signature: string;
45
+ digest: string;
46
+ expireAtTime: number;
47
+ expireAfterEpoch: number;
48
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/EnokiClient/type.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PublicKey } from '@mysten/sui.js/cryptography';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';\n\nimport type { AuthProvider } from '../EnokiFlow.js';\n\nexport interface GetAppApiInput {}\nexport interface GetAppApiResponse {\n\tauthenticationProviders: {\n\t\tproviderType: AuthProvider;\n\t\tclientId: string;\n\t}[];\n}\n\nexport interface GetZkLoginApiInput {\n\tjwt: string;\n}\nexport interface GetZkLoginApiResponse {\n\taddress: string;\n\tsalt: string;\n}\n\nexport interface CreateZkLoginNonceApiInput {\n\tephemeralPublicKey: PublicKey;\n}\nexport interface CreateZkLoginNonceApiResponse {\n\tnonce: string;\n\trandomness: string;\n\tepoch: number;\n\tmaxEpoch: number;\n\testimatedExpiration: number;\n}\n\nexport interface CreateZkLoginZkpApiInput {\n\tjwt: string;\n\tephemeralPublicKey: PublicKey;\n\trandomness: string;\n\tmaxEpoch: number;\n}\nexport interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {}\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PublicKey } from '@mysten/sui.js/cryptography';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';\n\nimport type { AuthProvider } from '../EnokiFlow.js';\n\nexport interface GetAppApiInput {}\nexport interface GetAppApiResponse {\n\tauthenticationProviders: {\n\t\tproviderType: AuthProvider;\n\t\tclientId: string;\n\t}[];\n}\n\nexport interface GetZkLoginApiInput {\n\tjwt: string;\n}\nexport interface GetZkLoginApiResponse {\n\taddress: string;\n\tsalt: string;\n}\n\nexport interface CreateZkLoginNonceApiInput {\n\tephemeralPublicKey: PublicKey;\n}\nexport interface CreateZkLoginNonceApiResponse {\n\tnonce: string;\n\trandomness: string;\n\tepoch: number;\n\tmaxEpoch: number;\n\testimatedExpiration: number;\n}\n\nexport interface CreateZkLoginZkpApiInput {\n\tjwt: string;\n\tephemeralPublicKey: PublicKey;\n\trandomness: string;\n\tmaxEpoch: number;\n}\nexport interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {}\n\nexport interface CreateSponsoredTransactionBlockApiInput {\n\tnetwork?: 'mainnet' | 'testnet';\n\tjwt: string;\n\ttransactionBlockKindBytes: string;\n}\n\nexport interface CreateSponsoredTransactionBlockApiResponse {\n\tbytes: string;\n\tsignature: string;\n\tdigest: string;\n\texpireAtTime: number;\n\texpireAfterEpoch: number;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,5 @@
1
+ import type { ExecuteTransactionBlockParams, SuiClient } from '@mysten/sui.js/client';
2
+ import type { TransactionBlock } from '@mysten/sui.js/transactions';
1
3
  import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';
2
4
  import type { WritableAtom } from 'nanostores';
3
5
  import type { Encryption } from './encryption.js';
@@ -33,6 +35,10 @@ export interface ZkLoginSession {
33
35
  export type AuthProvider = 'google' | 'facebook' | 'twitch';
34
36
  export declare class EnokiFlow {
35
37
  #private;
38
+ $zkLoginSession: WritableAtom<{
39
+ initialized: boolean;
40
+ value: ZkLoginSession | null;
41
+ }>;
36
42
  $zkLoginState: WritableAtom<ZkLoginState>;
37
43
  constructor(config: EnokiFlowConfig);
38
44
  get enokiClient(): EnokiClient;
@@ -47,4 +53,9 @@ export declare class EnokiFlow {
47
53
  logout(): Promise<void>;
48
54
  getProof(): Promise<import("./EnokiClient/type.js").CreateZkLoginZkpApiResponse>;
49
55
  getKeypair(): Promise<EnokiKeypair>;
56
+ sponsorAndExecuteTransactionBlock({ network, transactionBlock, client, ...options }: {
57
+ network?: 'mainnet' | 'testnet';
58
+ transactionBlock: TransactionBlock;
59
+ client: SuiClient;
60
+ } & Omit<ExecuteTransactionBlockParams, 'signature' | 'transactionBlock'>): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
50
61
  }
@@ -51,20 +51,19 @@ var import_encryption = require("./encryption.js");
51
51
  var import_EnokiClient = require("./EnokiClient/index.js");
52
52
  var import_EnokiKeypair = require("./EnokiKeypair.js");
53
53
  var import_stores = require("./stores.js");
54
- var _enokiClient, _encryption, _encryptionKey, _store, _zkLoginSessionInitialized, _zkLoginSession, _setSession, setSession_fn;
55
- const STORAGE_KEYS = {
56
- STATE: "@enoki/flow/state",
57
- SESSION: "@enoki/flow/session"
58
- };
54
+ var _storageKeys, _enokiClient, _encryption, _encryptionKey, _store, _setSession, setSession_fn;
55
+ const createStorageKeys = (apiKey) => ({
56
+ STATE: `@enoki/flow/state/${apiKey}`,
57
+ SESSION: `@enoki/flow/session/${apiKey}`
58
+ });
59
59
  class EnokiFlow {
60
60
  constructor(config) {
61
61
  __privateAdd(this, _setSession);
62
+ __privateAdd(this, _storageKeys, void 0);
62
63
  __privateAdd(this, _enokiClient, void 0);
63
64
  __privateAdd(this, _encryption, void 0);
64
65
  __privateAdd(this, _encryptionKey, void 0);
65
66
  __privateAdd(this, _store, void 0);
66
- __privateAdd(this, _zkLoginSessionInitialized, void 0);
67
- __privateAdd(this, _zkLoginSession, void 0);
68
67
  __privateSet(this, _enokiClient, new import_EnokiClient.EnokiClient({
69
68
  apiKey: config.apiKey,
70
69
  apiUrl: config.apiUrl
@@ -72,19 +71,19 @@ class EnokiFlow {
72
71
  __privateSet(this, _encryptionKey, config.apiKey);
73
72
  __privateSet(this, _encryption, config.encryption ?? (0, import_encryption.createDefaultEncryption)());
74
73
  __privateSet(this, _store, config.store ?? (0, import_stores.createSessionStorage)());
74
+ __privateSet(this, _storageKeys, createStorageKeys(config.apiKey));
75
75
  let storedState = null;
76
76
  try {
77
- const rawStoredValue = __privateGet(this, _store).get(STORAGE_KEYS.STATE);
77
+ const rawStoredValue = __privateGet(this, _store).get(__privateGet(this, _storageKeys).STATE);
78
78
  if (rawStoredValue) {
79
79
  storedState = JSON.parse(rawStoredValue);
80
80
  }
81
81
  } catch {
82
82
  }
83
83
  this.$zkLoginState = (0, import_nanostores.atom)(storedState || {});
84
- __privateSet(this, _zkLoginSessionInitialized, false);
85
- __privateSet(this, _zkLoginSession, null);
84
+ this.$zkLoginSession = (0, import_nanostores.atom)({ initialized: false, value: null });
86
85
  (0, import_nanostores.onSet)(this.$zkLoginState, ({ newValue }) => {
87
- __privateGet(this, _store).set(STORAGE_KEYS.STATE, JSON.stringify(newValue));
86
+ __privateGet(this, _store).set(__privateGet(this, _storageKeys).STATE, JSON.stringify(newValue));
88
87
  });
89
88
  }
90
89
  get enokiClient() {
@@ -165,11 +164,11 @@ class EnokiFlow {
165
164
  return params.get("state");
166
165
  }
167
166
  async getSession() {
168
- if (__privateGet(this, _zkLoginSessionInitialized)) {
169
- return __privateGet(this, _zkLoginSession);
167
+ if (this.$zkLoginSession.get().initialized) {
168
+ return this.$zkLoginSession.get().value;
170
169
  }
171
170
  try {
172
- const storedValue = __privateGet(this, _store).get(STORAGE_KEYS.SESSION);
171
+ const storedValue = __privateGet(this, _store).get(__privateGet(this, _storageKeys).SESSION);
173
172
  if (!storedValue)
174
173
  return null;
175
174
  const state = JSON.parse(
@@ -178,16 +177,16 @@ class EnokiFlow {
178
177
  if (state?.expiresAt && Date.now() > state.expiresAt) {
179
178
  await this.logout();
180
179
  } else {
181
- __privateSet(this, _zkLoginSession, state);
180
+ this.$zkLoginSession.set({ initialized: true, value: state });
182
181
  }
183
- return __privateGet(this, _zkLoginSession);
184
- } finally {
185
- __privateSet(this, _zkLoginSessionInitialized, true);
182
+ } catch {
183
+ this.$zkLoginSession.set({ initialized: true, value: null });
186
184
  }
185
+ return this.$zkLoginSession.get().value;
187
186
  }
188
187
  async logout() {
189
188
  this.$zkLoginState.set({});
190
- __privateGet(this, _store).delete(STORAGE_KEYS.STATE);
189
+ __privateGet(this, _store).delete(__privateGet(this, _storageKeys).STATE);
191
190
  await __privateMethod(this, _setSession, setSession_fn).call(this, null);
192
191
  }
193
192
  // TODO: Should this return the proof if it already exists?
@@ -217,8 +216,8 @@ class EnokiFlow {
217
216
  return proof;
218
217
  }
219
218
  async getKeypair() {
220
- const zkp = await this.getSession();
221
219
  await this.getProof();
220
+ const zkp = await this.getSession();
222
221
  const { address } = this.$zkLoginState.get();
223
222
  if (!address || !zkp || !zkp.proof) {
224
223
  throw new Error("Missing required data for keypair generation.");
@@ -233,13 +232,43 @@ class EnokiFlow {
233
232
  ephemeralKeypair: import_ed25519.Ed25519Keypair.fromSecretKey((0, import_utils.fromB64)(zkp.ephemeralKeyPair))
234
233
  });
235
234
  }
235
+ async sponsorAndExecuteTransactionBlock({
236
+ network,
237
+ transactionBlock,
238
+ client,
239
+ ...options
240
+ }) {
241
+ const session = await this.getSession();
242
+ const keypair = await this.getKeypair();
243
+ const transactionBlockKindBytes = await transactionBlock.build({
244
+ onlyTransactionKind: true,
245
+ client,
246
+ // Theses limits will get verified during the final transaction construction, so we can safely ignore them here:
247
+ limits: {
248
+ maxGasObjects: Infinity,
249
+ maxPureArgumentSize: Infinity,
250
+ maxTxGas: Infinity,
251
+ maxTxSizeBytes: Infinity
252
+ }
253
+ });
254
+ const { bytes, signature: sponsorSignature } = await __privateGet(this, _enokiClient).createSponsoredTransactionBlock({
255
+ jwt: session.jwt,
256
+ network,
257
+ transactionBlockKindBytes: (0, import_utils.toB64)(transactionBlockKindBytes)
258
+ });
259
+ const userSignature = await keypair.signTransactionBlock((0, import_utils.fromB64)(bytes));
260
+ return client.executeTransactionBlock({
261
+ transactionBlock: bytes,
262
+ signature: [userSignature.signature, sponsorSignature],
263
+ ...options
264
+ });
265
+ }
236
266
  }
267
+ _storageKeys = new WeakMap();
237
268
  _enokiClient = new WeakMap();
238
269
  _encryption = new WeakMap();
239
270
  _encryptionKey = new WeakMap();
240
271
  _store = new WeakMap();
241
- _zkLoginSessionInitialized = new WeakMap();
242
- _zkLoginSession = new WeakMap();
243
272
  _setSession = new WeakSet();
244
273
  setSession_fn = async function(newValue) {
245
274
  if (newValue) {
@@ -247,10 +276,10 @@ setSession_fn = async function(newValue) {
247
276
  __privateGet(this, _encryptionKey),
248
277
  JSON.stringify(newValue)
249
278
  );
250
- __privateGet(this, _store).set(STORAGE_KEYS.SESSION, storedValue);
279
+ __privateGet(this, _store).set(__privateGet(this, _storageKeys).SESSION, storedValue);
251
280
  } else {
252
- __privateGet(this, _store).delete(STORAGE_KEYS.SESSION);
281
+ __privateGet(this, _store).delete(__privateGet(this, _storageKeys).SESSION);
253
282
  }
254
- __privateSet(this, _zkLoginSession, newValue);
283
+ this.$zkLoginSession.set({ initialized: true, value: newValue });
255
284
  };
256
285
  //# sourceMappingURL=EnokiFlow.js.map
@@ -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 { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';\nimport { fromB64 } from '@mysten/sui.js/utils';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';\nimport { decodeJwt } from 'jose';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, 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 { EnokiKeypair } from './EnokiKeypair.js';\nimport type { SyncStore } from './stores.js';\nimport { createSessionStorage } from './stores.js';\n\nexport interface EnokiFlowConfig extends EnokiClientConfig {\n\t/**\n\t * The storage interface to persist Enoki data locally.\n\t * If not provided, it will use a sessionStorage-backed store.\n\t */\n\tstore?: SyncStore;\n\t/**\n\t * The encryption interface that will be used to encrypt data before storing it locally.\n\t * If not provided, it will use a default encryption interface.\n\t */\n\tencryption?: Encryption;\n}\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}\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\nexport type AuthProvider = 'google' | 'facebook' | 'twitch';\n\nconst STORAGE_KEYS = {\n\tSTATE: '@enoki/flow/state',\n\tSESSION: '@enoki/flow/session',\n};\n\nexport class EnokiFlow {\n\t#enokiClient: EnokiClient;\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\t#store: SyncStore;\n\n\t#zkLoginSessionInitialized: boolean;\n\t#zkLoginSession: ZkLoginSession | null;\n\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\t\tthis.#encryption = config.encryption ?? createDefaultEncryption();\n\t\tthis.#store = config.store ?? createSessionStorage();\n\n\t\tlet storedState = null;\n\t\ttry {\n\t\t\tconst rawStoredValue = this.#store.get(STORAGE_KEYS.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\n\t\tthis.#zkLoginSessionInitialized = false;\n\t\tthis.#zkLoginSession = null;\n\n\t\tonSet(this.$zkLoginState, ({ newValue }) => {\n\t\t\tthis.#store.set(STORAGE_KEYS.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\textraParams?: Record<string, unknown>;\n\t}) {\n\t\tconst ephemeralKeyPair = new Ed25519Keypair();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\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\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: ephemeralKeyPair.export().privateKey,\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\tconst decodedJwt = decodeJwt(jwt);\n\t\tif (!decodedJwt.sub || !decodedJwt.aud || typeof decodedJwt.aud !== 'string') {\n\t\t\tthrow new Error('Missing JWT data');\n\t\t}\n\n\t\tconst { address, salt } = 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});\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(STORAGE_KEYS.SESSION, storedValue);\n\t\t} else {\n\t\t\tthis.#store.delete(STORAGE_KEYS.SESSION);\n\t\t}\n\n\t\tthis.#zkLoginSession = newValue;\n\t}\n\n\tasync getSession() {\n\t\tif (this.#zkLoginSessionInitialized) {\n\t\t\treturn this.#zkLoginSession;\n\t\t}\n\n\t\ttry {\n\t\t\tconst storedValue = this.#store.get(STORAGE_KEYS.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 = state;\n\t\t\t}\n\n\t\t\treturn this.#zkLoginSession;\n\t\t} finally {\n\t\t\tthis.#zkLoginSessionInitialized = true;\n\t\t}\n\t}\n\n\tasync logout() {\n\t\tthis.$zkLoginState.set({});\n\t\tthis.#store.delete(STORAGE_KEYS.STATE);\n\n\t\tawait this.#setSession(null);\n\t}\n\n\t// TODO: Should this return the proof if it already exists?\n\tasync getProof() {\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\tconst ephemeralKeyPair = Ed25519Keypair.fromSecretKey(fromB64(zkp.ephemeralKeyPair));\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\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() {\n\t\tconst zkp = await this.getSession();\n\n\t\t// Get the proof, so that we ensure it exists in state:\n\t\tawait this.getProof();\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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CAAC;AAAA,EACF;AACD;AA1PC;AACA;AACA;AACA;AAEA;AACA;AA0IM;AAAA,gBAAW,eAAC,UAAiC;AAClD,MAAI,UAAU;AACb,UAAM,cAAc,MAAM,mBAAK,aAAY;AAAA,MAC1C,mBAAK;AAAA,MACL,KAAK,UAAU,QAAQ;AAAA,IACxB;AAEA,uBAAK,QAAO,IAAI,aAAa,SAAS,WAAW;AAAA,EAClD,OAAO;AACN,uBAAK,QAAO,OAAO,aAAa,OAAO;AAAA,EACxC;AAEA,qBAAK,iBAAkB;AACxB;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ExecuteTransactionBlockParams, SuiClient } from '@mysten/sui.js/client';\nimport { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';\nimport type { TransactionBlock } from '@mysten/sui.js/transactions';\nimport { fromB64, toB64 } from '@mysten/sui.js/utils';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';\nimport { decodeJwt } from 'jose';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, 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 { EnokiKeypair } from './EnokiKeypair.js';\nimport type { SyncStore } from './stores.js';\nimport { createSessionStorage } from './stores.js';\n\nexport interface EnokiFlowConfig extends EnokiClientConfig {\n\t/**\n\t * The storage interface to persist Enoki data locally.\n\t * If not provided, it will use a sessionStorage-backed store.\n\t */\n\tstore?: SyncStore;\n\t/**\n\t * The encryption interface that will be used to encrypt data before storing it locally.\n\t * If not provided, it will use a default encryption interface.\n\t */\n\tencryption?: Encryption;\n}\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}\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\nexport type AuthProvider = 'google' | 'facebook' | 'twitch';\n\nconst createStorageKeys = (apiKey: string) => ({\n\tSTATE: `@enoki/flow/state/${apiKey}`,\n\tSESSION: `@enoki/flow/session/${apiKey}`,\n});\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\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\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\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\textraParams?: Record<string, unknown>;\n\t}) {\n\t\tconst ephemeralKeyPair = new Ed25519Keypair();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\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\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: ephemeralKeyPair.export().privateKey,\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\tconst decodedJwt = decodeJwt(jwt);\n\t\tif (!decodedJwt.sub || !decodedJwt.aud || typeof decodedJwt.aud !== 'string') {\n\t\t\tthrow new Error('Missing JWT data');\n\t\t}\n\n\t\tconst { address, salt } = 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});\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\tawait this.#setSession(null);\n\t}\n\n\t// TODO: Should this return the proof if it already exists?\n\tasync getProof() {\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\tconst ephemeralKeyPair = Ed25519Keypair.fromSecretKey(fromB64(zkp.ephemeralKeyPair));\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\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() {\n\t\t// Get the proof, so that we ensure it exists in state:\n\t\tawait this.getProof();\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\treturn new EnokiKeypair({\n\t\t\taddress,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\tproof: zkp.proof,\n\t\t\tephemeralKeypair: Ed25519Keypair.fromSecretKey(fromB64(zkp.ephemeralKeyPair)),\n\t\t});\n\t}\n\n\tasync sponsorAndExecuteTransactionBlock({\n\t\tnetwork,\n\t\ttransactionBlock,\n\t\tclient,\n\t\t...options\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\ttransactionBlock: TransactionBlock;\n\t\tclient: SuiClient;\n\t} & Omit<ExecuteTransactionBlockParams, 'signature' | 'transactionBlock'>) {\n\t\tconst session = await this.getSession();\n\t\tconst keypair = await this.getKeypair();\n\n\t\tconst transactionBlockKindBytes = await transactionBlock.build({\n\t\t\tonlyTransactionKind: true,\n\t\t\tclient,\n\t\t\t// Theses limits will get verified during the final transaction construction, so we can safely ignore them here:\n\t\t\tlimits: {\n\t\t\t\tmaxGasObjects: Infinity,\n\t\t\t\tmaxPureArgumentSize: Infinity,\n\t\t\t\tmaxTxGas: Infinity,\n\t\t\t\tmaxTxSizeBytes: Infinity,\n\t\t\t},\n\t\t});\n\n\t\tconst { bytes, signature: sponsorSignature } =\n\t\t\tawait this.#enokiClient.createSponsoredTransactionBlock({\n\t\t\t\tjwt: session!.jwt!,\n\t\t\t\tnetwork,\n\t\t\t\ttransactionBlockKindBytes: toB64(transactionBlockKindBytes),\n\t\t\t});\n\n\t\tconst userSignature = await keypair.signTransactionBlock(fromB64(bytes));\n\n\t\treturn client.executeTransactionBlock({\n\t\t\ttransactionBlock: bytes,\n\t\t\tsignature: [userSignature.signature, sponsorSignature],\n\t\t\t...options,\n\t\t});\n\t}\n}\n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
7
  }
@@ -7,3 +7,8 @@ export interface EnokiFlowProviderProps extends EnokiFlowConfig {
7
7
  export declare function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps): import("react/jsx-runtime.js").JSX.Element;
8
8
  export declare function useEnokiFlow(): EnokiFlow;
9
9
  export declare function useZkLogin(): import("./EnokiFlow.js").ZkLoginState;
10
+ export declare function useZkLoginSession(): import("./EnokiFlow.js").ZkLoginSession | null;
11
+ export declare function useAuthCallback(): {
12
+ handled: boolean;
13
+ state: string | null;
14
+ };
package/dist/cjs/react.js CHANGED
@@ -19,8 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var react_exports = {};
20
20
  __export(react_exports, {
21
21
  EnokiFlowProvider: () => EnokiFlowProvider,
22
+ useAuthCallback: () => useAuthCallback,
22
23
  useEnokiFlow: () => useEnokiFlow,
23
- useZkLogin: () => useZkLogin
24
+ useZkLogin: () => useZkLogin,
25
+ useZkLoginSession: () => useZkLoginSession
24
26
  });
25
27
  module.exports = __toCommonJS(react_exports);
26
28
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -43,4 +45,33 @@ function useZkLogin() {
43
45
  const flow = useEnokiFlow();
44
46
  return (0, import_react.useStore)(flow.$zkLoginState);
45
47
  }
48
+ function useZkLoginSession() {
49
+ const flow = useEnokiFlow();
50
+ return (0, import_react.useStore)(flow.$zkLoginSession).value;
51
+ }
52
+ function useAuthCallback() {
53
+ const flow = useEnokiFlow();
54
+ const [state, setState] = (0, import_react2.useState)(null);
55
+ const [handled, setHandled] = (0, import_react2.useState)(false);
56
+ const [hash, setHash] = (0, import_react2.useState)(null);
57
+ (0, import_react2.useEffect)(() => {
58
+ const listener = () => setHash(window.location.hash.slice(1).trim());
59
+ listener();
60
+ window.addEventListener("hashchange", listener);
61
+ return () => window.removeEventListener("hashchange", listener);
62
+ }, []);
63
+ (0, import_react2.useEffect)(() => {
64
+ if (!hash)
65
+ return;
66
+ (async () => {
67
+ try {
68
+ setState(await flow.handleAuthCallback(hash));
69
+ window.location.hash = "";
70
+ } finally {
71
+ setHandled(true);
72
+ }
73
+ })();
74
+ }, [hash, flow]);
75
+ return { handled, state };
76
+ }
46
77
  //# sourceMappingURL=react.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react.tsx"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useStore } from '@nanostores/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useState } from 'react';\n\nimport type { EnokiFlowConfig } from './EnokiFlow.js';\nimport { EnokiFlow } from './EnokiFlow.js';\n\nconst EnokiFlowContext = createContext<EnokiFlow | null>(null);\n\nexport interface EnokiFlowProviderProps extends EnokiFlowConfig {\n\tchildren: ReactNode;\n}\n\nexport function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps) {\n\tconst [enokiFlow] = useState(() => new EnokiFlow(config));\n\treturn <EnokiFlowContext.Provider value={enokiFlow}>{children}</EnokiFlowContext.Provider>;\n}\n\nexport function useEnokiFlow() {\n\tconst context = useContext(EnokiFlowContext);\n\tif (!context) {\n\t\tthrow new Error('Missing `EnokiFlowContext` provider');\n\t}\n\treturn context;\n}\n\nexport function useZkLogin() {\n\tconst flow = useEnokiFlow();\n\treturn useStore(flow.$zkLoginState);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBQ;AAfR,mBAAyB;AAEzB,IAAAA,gBAAoD;AAGpD,uBAA0B;AAE1B,MAAM,uBAAmB,6BAAgC,IAAI;AAMtD,SAAS,kBAAkB,EAAE,UAAU,GAAG,OAAO,GAA2B;AAClF,QAAM,CAAC,SAAS,QAAI,wBAAS,MAAM,IAAI,2BAAU,MAAM,CAAC;AACxD,SAAO,4CAAC,iBAAiB,UAAjB,EAA0B,OAAO,WAAY,UAAS;AAC/D;AAEO,SAAS,eAAe;AAC9B,QAAM,cAAU,0BAAW,gBAAgB;AAC3C,MAAI,CAAC,SAAS;AACb,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACtD;AACA,SAAO;AACR;AAEO,SAAS,aAAa;AAC5B,QAAM,OAAO,aAAa;AAC1B,aAAO,uBAAS,KAAK,aAAa;AACnC;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useStore } from '@nanostores/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useEffect, useState } from 'react';\n\nimport type { EnokiFlowConfig } from './EnokiFlow.js';\nimport { EnokiFlow } from './EnokiFlow.js';\n\nconst EnokiFlowContext = createContext<EnokiFlow | null>(null);\n\nexport interface EnokiFlowProviderProps extends EnokiFlowConfig {\n\tchildren: ReactNode;\n}\n\nexport function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps) {\n\tconst [enokiFlow] = useState(() => new EnokiFlow(config));\n\treturn <EnokiFlowContext.Provider value={enokiFlow}>{children}</EnokiFlowContext.Provider>;\n}\n\nexport function useEnokiFlow() {\n\tconst context = useContext(EnokiFlowContext);\n\tif (!context) {\n\t\tthrow new Error('Missing `EnokiFlowContext` provider');\n\t}\n\treturn context;\n}\n\nexport function useZkLogin() {\n\tconst flow = useEnokiFlow();\n\treturn useStore(flow.$zkLoginState);\n}\n\nexport function useZkLoginSession() {\n\tconst flow = useEnokiFlow();\n\treturn useStore(flow.$zkLoginSession).value;\n}\n\nexport function useAuthCallback() {\n\tconst flow = useEnokiFlow();\n\tconst [state, setState] = useState<string | null>(null);\n\tconst [handled, setHandled] = useState(false);\n\tconst [hash, setHash] = useState<string | null>(null);\n\n\tuseEffect(() => {\n\t\tconst listener = () => setHash(window.location.hash.slice(1).trim());\n\t\tlistener();\n\n\t\twindow.addEventListener('hashchange', listener);\n\t\treturn () => window.removeEventListener('hashchange', listener);\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (!hash) return;\n\n\t\t(async () => {\n\t\t\ttry {\n\t\t\t\tsetState(await flow.handleAuthCallback(hash));\n\n\t\t\t\twindow.location.hash = '';\n\t\t\t} finally {\n\t\t\t\tsetHandled(true);\n\t\t\t}\n\t\t})();\n\t}, [hash, flow]);\n\n\treturn { handled, state };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBQ;AAfR,mBAAyB;AAEzB,IAAAA,gBAA+D;AAG/D,uBAA0B;AAE1B,MAAM,uBAAmB,6BAAgC,IAAI;AAMtD,SAAS,kBAAkB,EAAE,UAAU,GAAG,OAAO,GAA2B;AAClF,QAAM,CAAC,SAAS,QAAI,wBAAS,MAAM,IAAI,2BAAU,MAAM,CAAC;AACxD,SAAO,4CAAC,iBAAiB,UAAjB,EAA0B,OAAO,WAAY,UAAS;AAC/D;AAEO,SAAS,eAAe;AAC9B,QAAM,cAAU,0BAAW,gBAAgB;AAC3C,MAAI,CAAC,SAAS;AACb,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACtD;AACA,SAAO;AACR;AAEO,SAAS,aAAa;AAC5B,QAAM,OAAO,aAAa;AAC1B,aAAO,uBAAS,KAAK,aAAa;AACnC;AAEO,SAAS,oBAAoB;AACnC,QAAM,OAAO,aAAa;AAC1B,aAAO,uBAAS,KAAK,eAAe,EAAE;AACvC;AAEO,SAAS,kBAAkB;AACjC,QAAM,OAAO,aAAa;AAC1B,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAwB,IAAI;AACtD,QAAM,CAAC,SAAS,UAAU,QAAI,wBAAS,KAAK;AAC5C,QAAM,CAAC,MAAM,OAAO,QAAI,wBAAwB,IAAI;AAEpD,+BAAU,MAAM;AACf,UAAM,WAAW,MAAM,QAAQ,OAAO,SAAS,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC;AACnE,aAAS;AAET,WAAO,iBAAiB,cAAc,QAAQ;AAC9C,WAAO,MAAM,OAAO,oBAAoB,cAAc,QAAQ;AAAA,EAC/D,GAAG,CAAC,CAAC;AAEL,+BAAU,MAAM;AACf,QAAI,CAAC;AAAM;AAEX,KAAC,YAAY;AACZ,UAAI;AACH,iBAAS,MAAM,KAAK,mBAAmB,IAAI,CAAC;AAE5C,eAAO,SAAS,OAAO;AAAA,MACxB,UAAE;AACD,mBAAW,IAAI;AAAA,MAChB;AAAA,IACD,GAAG;AAAA,EACJ,GAAG,CAAC,MAAM,IAAI,CAAC;AAEf,SAAO,EAAE,SAAS,MAAM;AACzB;",
6
6
  "names": ["import_react"]
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
1
+ import type { CreateSponsoredTransactionBlockApiInput, CreateSponsoredTransactionBlockApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
2
2
  export interface EnokiClientConfig {
3
3
  /** The API key for the Enoki app, available in the Enoki Portal. */
4
4
  apiKey: string;
@@ -15,4 +15,5 @@ export declare class EnokiClient {
15
15
  getZkLogin(input: GetZkLoginApiInput): Promise<GetZkLoginApiResponse>;
16
16
  createZkLoginNonce(input: CreateZkLoginNonceApiInput): Promise<CreateZkLoginNonceApiResponse>;
17
17
  createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
18
+ createSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput): Promise<CreateSponsoredTransactionBlockApiResponse>;
18
19
  }
@@ -55,7 +55,7 @@ class EnokiClient {
55
55
  });
56
56
  }
57
57
  createZkLoginZkp(input) {
58
- return __privateMethod(this, _fetch, fetch_fn).call(this, "zklogin/kzp", {
58
+ return __privateMethod(this, _fetch, fetch_fn).call(this, "zklogin/zkp", {
59
59
  method: "POST",
60
60
  headers: {
61
61
  [ZKLOGIN_HEADER]: input.jwt
@@ -67,6 +67,18 @@ class EnokiClient {
67
67
  })
68
68
  });
69
69
  }
70
+ createSponsoredTransactionBlock(input) {
71
+ return __privateMethod(this, _fetch, fetch_fn).call(this, "transaction-blocks/sponsor", {
72
+ method: "POST",
73
+ headers: {
74
+ [ZKLOGIN_HEADER]: input.jwt
75
+ },
76
+ body: JSON.stringify({
77
+ network: input.network,
78
+ transactionBlockKindBytes: input.transactionBlockKindBytes
79
+ })
80
+ });
81
+ }
70
82
  }
71
83
  _version = new WeakMap();
72
84
  _apiUrl = new WeakMap();
@@ -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\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\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\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\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\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/kzp', {\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\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\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 Error('Failed to fetch');\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;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C9B,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,MAAM,iBAAiB;AAAA,EAClC;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionBlockApiInput,\n\tCreateSponsoredTransactionBlockApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\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\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\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\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\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\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\tcreateSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionBlockApiResponse>('transaction-blocks/sponsor', {\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\ttransactionBlockKindBytes: input.transactionBlockKindBytes,\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 Error('Failed to fetch');\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\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UAAU;AAAA,QACpB,SAAS,MAAM;AAAA,QACf,2BAA2B,MAAM;AAAA,MAClC,CAAC;AAAA,IACF;AAAA,EACD;AAqBD;AAhFC;AACA;AACA;AA2DM;AAAA,WAAmB,eAAC,MAAc,MAA+B;AACtE,QAAM,MAAM,MAAM,MAAM,GAAG,mBAAK,YAAW,mBAAK,aAAY,QAAQ;AAAA,IACnE,GAAG;AAAA,IACH,SAAS;AAAA,MACR,GAAG,KAAK;AAAA,MACR,eAAe,UAAU,mBAAK;AAAA,MAC9B,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,MAAM,iBAAiB;AAAA,EAClC;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -34,3 +34,15 @@ export interface CreateZkLoginZkpApiInput {
34
34
  }
35
35
  export interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {
36
36
  }
37
+ export interface CreateSponsoredTransactionBlockApiInput {
38
+ network?: 'mainnet' | 'testnet';
39
+ jwt: string;
40
+ transactionBlockKindBytes: string;
41
+ }
42
+ export interface CreateSponsoredTransactionBlockApiResponse {
43
+ bytes: string;
44
+ signature: string;
45
+ digest: string;
46
+ expireAtTime: number;
47
+ expireAfterEpoch: number;
48
+ }
@@ -1,3 +1,5 @@
1
+ import type { ExecuteTransactionBlockParams, SuiClient } from '@mysten/sui.js/client';
2
+ import type { TransactionBlock } from '@mysten/sui.js/transactions';
1
3
  import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';
2
4
  import type { WritableAtom } from 'nanostores';
3
5
  import type { Encryption } from './encryption.js';
@@ -33,6 +35,10 @@ export interface ZkLoginSession {
33
35
  export type AuthProvider = 'google' | 'facebook' | 'twitch';
34
36
  export declare class EnokiFlow {
35
37
  #private;
38
+ $zkLoginSession: WritableAtom<{
39
+ initialized: boolean;
40
+ value: ZkLoginSession | null;
41
+ }>;
36
42
  $zkLoginState: WritableAtom<ZkLoginState>;
37
43
  constructor(config: EnokiFlowConfig);
38
44
  get enokiClient(): EnokiClient;
@@ -47,4 +53,9 @@ export declare class EnokiFlow {
47
53
  logout(): Promise<void>;
48
54
  getProof(): Promise<import("./EnokiClient/type.js").CreateZkLoginZkpApiResponse>;
49
55
  getKeypair(): Promise<EnokiKeypair>;
56
+ sponsorAndExecuteTransactionBlock({ network, transactionBlock, client, ...options }: {
57
+ network?: 'mainnet' | 'testnet';
58
+ transactionBlock: TransactionBlock;
59
+ client: SuiClient;
60
+ } & Omit<ExecuteTransactionBlockParams, 'signature' | 'transactionBlock'>): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
50
61
  }