@mysten/enoki 0.2.8 → 0.3.1

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,27 @@
1
1
  # @mysten/enoki
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6fc6235984]
8
+ - @mysten/sui@1.0.1
9
+ - @mysten/zklogin@0.7.1
10
+
11
+ ## 0.3.0
12
+
13
+ ### Minor Changes
14
+
15
+ - a92b03de42: The Typescript SDK has been renamed to `@mysten/sui` and includes many new features and breaking changes.
16
+ See the [full migration guide](https://sdk.mystenlabs.com/typescript/migrations/sui-1.0) for details on how to upgrade.
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [ebdfe7cf21]
21
+ - Updated dependencies [a92b03de42]
22
+ - @mysten/sui@1.0.0
23
+ - @mysten/zklogin@0.7.0
24
+
3
25
  ## 0.2.8
4
26
 
5
27
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { CreateSponsoredTransactionBlockApiInput, CreateSponsoredTransactionBlockApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, ExecuteSponsoredTransactionBlockApiInput, ExecuteSponsoredTransactionBlockApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
1
+ import type { CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, 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;
@@ -23,6 +23,6 @@ export declare class EnokiClient {
23
23
  getZkLogin(input: GetZkLoginApiInput): Promise<GetZkLoginApiResponse>;
24
24
  createZkLoginNonce(input: CreateZkLoginNonceApiInput): Promise<CreateZkLoginNonceApiResponse>;
25
25
  createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
26
- createSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput): Promise<CreateSponsoredTransactionBlockApiResponse>;
27
- executeSponsoredTransactionBlock(input: ExecuteSponsoredTransactionBlockApiInput): Promise<ExecuteSponsoredTransactionBlockApiResponse>;
26
+ createSponsoredTransaction(input: CreateSponsoredTransactionApiInput): Promise<CreateSponsoredTransactionApiResponse>;
27
+ executeSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput): Promise<ExecuteSponsoredTransactionApiResponse>;
28
28
  }
@@ -111,7 +111,7 @@ class EnokiClient {
111
111
  })
112
112
  });
113
113
  }
114
- createSponsoredTransactionBlock(input) {
114
+ createSponsoredTransaction(input) {
115
115
  return __privateMethod(this, _fetch, fetch_fn).call(this, "transaction-blocks/sponsor", {
116
116
  method: "POST",
117
117
  headers: input.jwt ? {
@@ -120,13 +120,13 @@ class EnokiClient {
120
120
  body: JSON.stringify({
121
121
  sender: input.sender,
122
122
  network: input.network,
123
- transactionBlockKindBytes: input.transactionBlockKindBytes,
123
+ transactionBlockKindBytes: input.transactionKindBytes,
124
124
  allowedAddresses: input.allowedAddresses,
125
125
  allowedMoveCallTargets: input.allowedMoveCallTargets
126
126
  })
127
127
  });
128
128
  }
129
- executeSponsoredTransactionBlock(input) {
129
+ executeSponsoredTransaction(input) {
130
130
  return __privateMethod(this, _fetch, fetch_fn).call(this, `transaction-blocks/sponsor/${input.digest}`, {
131
131
  method: "POST",
132
132
  body: JSON.stringify({
@@ -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\tCreateSponsoredTransactionBlockApiInput,\n\tCreateSponsoredTransactionBlockApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tExecuteSponsoredTransactionBlockApiInput,\n\tExecuteSponsoredTransactionBlockApiResponse,\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\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\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 (e) {\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}\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\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\tcreateSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionBlockApiResponse>('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 }\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.transactionBlockKindBytes,\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\texecuteSponsoredTransactionBlock(input: ExecuteSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionBlockApiResponse>(\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\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;AAkBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAUhB,MAAM,yBAAyB,MAAM;AAAA,EAG3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,SAAS,GAAP;AAAA,IAEF;AACA,UAAM,QAAQ,SAAS,CAAC,IAAI,IAAI,MAAM,OAAO,CAAC,EAAE,OAAO,IAAI;AAC3D,UAAM,wCAAwC,WAAW;AAAA,MACxD;AAAA,IACD,CAAC;AAfF,kBAA6D,CAAC;AAgB7D,SAAK,SAAS,UAAU,CAAC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CAAC;AAAA,MACJ,MAAM,KAAK,UAAU;AAAA,QACpB,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM;AAAA,QACf,2BAA2B,MAAM;AAAA,QACjC,kBAAkB,MAAM;AAAA,QACxB,wBAAwB,MAAM;AAAA,MAC/B,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EAEA,iCAAiC,OAAiD;AACjF,WAAO,sBAAK,kBAAL,WACN,8BAA8B,MAAM,UACpC;AAAA,MACC,QAAQ;AAAA,MACR,MAAM,KAAK,UAAU;AAAA,QACpB,WAAW,MAAM;AAAA,MAClB,CAAC;AAAA,IACF;AAAA,EAEF;AAqBD;AApGC;AACA;AACA;AA+EM;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,iBAAiB,IAAI,QAAQ,MAAM,IAAI,KAAK,CAAC;AAAA,EACxD;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\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\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\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\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 (e) {\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}\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\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 }\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\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;AAkBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAUhB,MAAM,yBAAyB,MAAM;AAAA,EAG3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,SAAS,GAAP;AAAA,IAEF;AACA,UAAM,QAAQ,SAAS,CAAC,IAAI,IAAI,MAAM,OAAO,CAAC,EAAE,OAAO,IAAI;AAC3D,UAAM,wCAAwC,WAAW;AAAA,MACxD;AAAA,IACD,CAAC;AAfF,kBAA6D,CAAC;AAgB7D,SAAK,SAAS,UAAU,CAAC;AACzB,SAAK,OAAO;AAAA,EACb;AACD;AAKO,MAAM,YAAY;AAAA,EAKxB,YAAY,QAA2B;AA6EvC,uBAAM;AAjFN;AACA;AACA;AAGC,uBAAK,UAAW;AAChB,uBAAK,SAAU,OAAO,UAAU;AAChC,uBAAK,SAAU,OAAO;AAAA,EACvB;AAAA,EAEA,OAAO,QAAyB;AAC/B,WAAO,sBAAK,kBAAL,WAA+B,OAAO;AAAA,MAC5C,QAAQ;AAAA,IACT;AAAA,EACD;AAAA,EAEA,WAAW,OAA2B;AACrC,WAAO,sBAAK,kBAAL,W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B,CAAC;AAAA,IACF;AAAA,EAEF;AAqBD;AApGC;AACA;AACA;AA+EM;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,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
  }
@@ -1,5 +1,5 @@
1
- import type { PublicKey } from '@mysten/sui.js/cryptography';
2
- import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';
1
+ import type { PublicKey } from '@mysten/sui/cryptography';
2
+ import type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';
3
3
  import type { AuthProvider } from '../EnokiFlow.js';
4
4
  export type EnokiNetwork = 'mainnet' | 'testnet' | 'devnet';
5
5
  export interface GetAppApiInput {
@@ -38,9 +38,9 @@ export interface CreateZkLoginZkpApiInput {
38
38
  }
39
39
  export interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {
40
40
  }
41
- export type CreateSponsoredTransactionBlockApiInput = {
41
+ export type CreateSponsoredTransactionApiInput = {
42
42
  network?: EnokiNetwork;
43
- transactionBlockKindBytes: string;
43
+ transactionKindBytes: string;
44
44
  } & ({
45
45
  jwt: string;
46
46
  sender?: never;
@@ -52,14 +52,14 @@ export type CreateSponsoredTransactionBlockApiInput = {
52
52
  allowedMoveCallTargets?: string[];
53
53
  jwt?: never;
54
54
  });
55
- export interface CreateSponsoredTransactionBlockApiResponse {
55
+ export interface CreateSponsoredTransactionApiResponse {
56
56
  bytes: string;
57
57
  digest: string;
58
58
  }
59
- export interface ExecuteSponsoredTransactionBlockApiInput {
59
+ export interface ExecuteSponsoredTransactionApiInput {
60
60
  digest: string;
61
61
  signature: string;
62
62
  }
63
- export interface ExecuteSponsoredTransactionBlockApiResponse {
63
+ export interface ExecuteSponsoredTransactionApiResponse {
64
64
  digest: string;
65
65
  }
@@ -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 type EnokiNetwork = 'mainnet' | 'testnet' | 'devnet';\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\tnetwork?: EnokiNetwork;\n\tephemeralPublicKey: PublicKey;\n\tadditionalEpochs?: number;\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\tnetwork?: EnokiNetwork;\n\tjwt: string;\n\tephemeralPublicKey: PublicKey;\n\trandomness: string;\n\tmaxEpoch: number;\n}\nexport interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {}\n\nexport type CreateSponsoredTransactionBlockApiInput = {\n\tnetwork?: EnokiNetwork;\n\ttransactionBlockKindBytes: string;\n} & (\n\t| {\n\t\t\tjwt: string;\n\t\t\tsender?: never;\n\t\t\tallowedAddresses?: never;\n\t\t\tallowedMoveCallTargets?: never;\n\t }\n\t| {\n\t\t\tsender: string;\n\t\t\tallowedAddresses?: string[];\n\t\t\tallowedMoveCallTargets?: string[];\n\t\t\tjwt?: never;\n\t }\n);\n\nexport interface CreateSponsoredTransactionBlockApiResponse {\n\tbytes: string;\n\tdigest: string;\n}\n\nexport interface ExecuteSponsoredTransactionBlockApiInput {\n\tdigest: string;\n\tsignature: string;\n}\n\nexport interface ExecuteSponsoredTransactionBlockApiResponse {\n\tdigest: string;\n}\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { PublicKey } from '@mysten/sui/cryptography';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\n\nimport type { AuthProvider } from '../EnokiFlow.js';\n\nexport type EnokiNetwork = 'mainnet' | 'testnet' | 'devnet';\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\tnetwork?: EnokiNetwork;\n\tephemeralPublicKey: PublicKey;\n\tadditionalEpochs?: number;\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\tnetwork?: EnokiNetwork;\n\tjwt: string;\n\tephemeralPublicKey: PublicKey;\n\trandomness: string;\n\tmaxEpoch: number;\n}\nexport interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {}\n\nexport type CreateSponsoredTransactionApiInput = {\n\tnetwork?: EnokiNetwork;\n\ttransactionKindBytes: string;\n} & (\n\t| {\n\t\t\tjwt: string;\n\t\t\tsender?: never;\n\t\t\tallowedAddresses?: never;\n\t\t\tallowedMoveCallTargets?: never;\n\t }\n\t| {\n\t\t\tsender: string;\n\t\t\tallowedAddresses?: string[];\n\t\t\tallowedMoveCallTargets?: string[];\n\t\t\tjwt?: never;\n\t }\n);\n\nexport interface CreateSponsoredTransactionApiResponse {\n\tbytes: string;\n\tdigest: string;\n}\n\nexport interface ExecuteSponsoredTransactionApiInput {\n\tdigest: string;\n\tsignature: string;\n}\n\nexport interface ExecuteSponsoredTransactionApiResponse {\n\tdigest: string;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
- import type { SuiClient } from '@mysten/sui.js/client';
2
- import type { TransactionBlock } from '@mysten/sui.js/transactions';
3
- import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';
1
+ import type { SuiClient } from '@mysten/sui/client';
2
+ import type { Transaction } from '@mysten/sui/transactions';
3
+ import type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';
4
4
  import type { WritableAtom } from 'nanostores';
5
5
  import type { Encryption } from './encryption.js';
6
6
  import type { EnokiClientConfig } from './EnokiClient/index.js';
@@ -58,12 +58,12 @@ export declare class EnokiFlow {
58
58
  getKeypair({ network }?: {
59
59
  network?: 'mainnet' | 'testnet';
60
60
  }): Promise<EnokiKeypair>;
61
- sponsorTransactionBlock({ network, transactionBlock, client, }: {
61
+ sponsorTransaction({ network, transaction, client, }: {
62
62
  network?: 'mainnet' | 'testnet';
63
- transactionBlock: TransactionBlock;
63
+ transaction: Transaction;
64
64
  client: SuiClient;
65
- }): Promise<import("./EnokiClient/type.js").CreateSponsoredTransactionBlockApiResponse>;
66
- executeTransactionBlock({ network, bytes, digest, client, }: {
65
+ }): Promise<import("./EnokiClient/type.js").CreateSponsoredTransactionApiResponse>;
66
+ executeTransaction({ network, bytes, digest, client, }: {
67
67
  network?: 'mainnet' | 'testnet';
68
68
  bytes: string;
69
69
  digest: string;
@@ -71,9 +71,9 @@ export declare class EnokiFlow {
71
71
  }): Promise<{
72
72
  digest: string;
73
73
  }>;
74
- sponsorAndExecuteTransactionBlock({ network, transactionBlock, client, }: {
74
+ sponsorAndExecuteTransaction({ network, transaction, client, }: {
75
75
  network?: 'mainnet' | 'testnet';
76
- transactionBlock: TransactionBlock;
76
+ transaction: Transaction;
77
77
  client: SuiClient;
78
78
  }): Promise<{
79
79
  digest: string;
@@ -43,9 +43,9 @@ __export(EnokiFlow_exports, {
43
43
  EnokiFlow: () => EnokiFlow
44
44
  });
45
45
  module.exports = __toCommonJS(EnokiFlow_exports);
46
- var import_cryptography = require("@mysten/sui.js/cryptography");
47
- var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
48
- var import_utils = require("@mysten/sui.js/utils");
46
+ var import_cryptography = require("@mysten/sui/cryptography");
47
+ var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
48
+ var import_utils = require("@mysten/sui/utils");
49
49
  var import_jose = require("jose");
50
50
  var import_nanostores = require("nanostores");
51
51
  var import_encryption = require("./encryption.js");
@@ -238,58 +238,51 @@ class EnokiFlow {
238
238
  ephemeralKeypair: import_ed25519.Ed25519Keypair.fromSecretKey((0, import_utils.fromB64)(zkp.ephemeralKeyPair))
239
239
  });
240
240
  }
241
- async sponsorTransactionBlock({
241
+ async sponsorTransaction({
242
242
  network,
243
- transactionBlock,
243
+ transaction,
244
244
  client
245
245
  }) {
246
246
  const session = await this.getSession();
247
247
  if (!session || !session.jwt) {
248
248
  throw new Error("Missing required data for sponsorship.");
249
249
  }
250
- const transactionBlockKindBytes = await transactionBlock.build({
250
+ const transactionKindBytes = await transaction.build({
251
251
  onlyTransactionKind: true,
252
- client,
253
- // Theses limits will get verified during the final transaction construction, so we can safely ignore them here:
254
- limits: {
255
- maxGasObjects: Infinity,
256
- maxPureArgumentSize: Infinity,
257
- maxTxGas: Infinity,
258
- maxTxSizeBytes: Infinity
259
- }
252
+ client
260
253
  });
261
- return await __privateGet(this, _enokiClient).createSponsoredTransactionBlock({
254
+ return await __privateGet(this, _enokiClient).createSponsoredTransaction({
262
255
  jwt: session.jwt,
263
256
  network,
264
- transactionBlockKindBytes: (0, import_utils.toB64)(transactionBlockKindBytes)
257
+ transactionKindBytes: (0, import_utils.toB64)(transactionKindBytes)
265
258
  });
266
259
  }
267
- async executeTransactionBlock({
260
+ async executeTransaction({
268
261
  network,
269
262
  bytes,
270
263
  digest,
271
264
  client
272
265
  }) {
273
266
  const keypair = await this.getKeypair({ network });
274
- const userSignature = await keypair.signTransactionBlock((0, import_utils.fromB64)(bytes));
275
- await __privateGet(this, _enokiClient).executeSponsoredTransactionBlock({
267
+ const userSignature = await keypair.signTransaction((0, import_utils.fromB64)(bytes));
268
+ await __privateGet(this, _enokiClient).executeSponsoredTransaction({
276
269
  digest,
277
270
  signature: userSignature.signature
278
271
  });
279
- await client.waitForTransactionBlock({ digest });
272
+ await client.waitForTransaction({ digest });
280
273
  return { digest };
281
274
  }
282
- async sponsorAndExecuteTransactionBlock({
275
+ async sponsorAndExecuteTransaction({
283
276
  network,
284
- transactionBlock,
277
+ transaction,
285
278
  client
286
279
  }) {
287
- const { bytes, digest } = await this.sponsorTransactionBlock({
280
+ const { bytes, digest } = await this.sponsorTransaction({
288
281
  network,
289
- transactionBlock,
282
+ transaction,
290
283
  client
291
284
  });
292
- return await this.executeTransactionBlock({ network, bytes, digest, client });
285
+ return await this.executeTransaction({ network, bytes, digest, client });
293
286
  }
294
287
  }
295
288
  _storageKeys = new WeakMap();
@@ -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 { SuiClient } from '@mysten/sui.js/client';\nimport { decodeSuiPrivateKey } from '@mysten/sui.js/cryptography';\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, 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 { 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\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 = new Ed25519Keypair();\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\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: toB64(decodeSuiPrivateKey(ephemeralKeyPair.getSecretKey()).secretKey),\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({ network }: { network?: 'mainnet' | 'testnet' } = {}) {\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\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?: 'mainnet' | 'testnet' } = {}) {\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\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 sponsorTransactionBlock({\n\t\tnetwork,\n\t\ttransactionBlock,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\ttransactionBlock: TransactionBlock;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst session = await this.getSession();\n\n\t\tif (!session || !session.jwt) {\n\t\t\tthrow new Error('Missing required data for sponsorship.');\n\t\t}\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\treturn await this.#enokiClient.createSponsoredTransactionBlock({\n\t\t\tjwt: session.jwt,\n\t\t\tnetwork,\n\t\t\ttransactionBlockKindBytes: toB64(transactionBlockKindBytes),\n\t\t});\n\t}\n\n\tasync executeTransactionBlock({\n\t\tnetwork,\n\t\tbytes,\n\t\tdigest,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\tbytes: string;\n\t\tdigest: string;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst keypair = await this.getKeypair({ network });\n\t\tconst userSignature = await keypair.signTransactionBlock(fromB64(bytes));\n\n\t\tawait this.#enokiClient.executeSponsoredTransactionBlock({\n\t\t\tdigest,\n\t\t\tsignature: userSignature.signature,\n\t\t});\n\n\t\t// TODO: Should the parent just do this?\n\t\tawait client.waitForTransactionBlock({ digest });\n\n\t\treturn { digest };\n\t}\n\n\tasync sponsorAndExecuteTransactionBlock({\n\t\tnetwork,\n\t\ttransactionBlock,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\ttransactionBlock: TransactionBlock;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst { bytes, digest } = await this.sponsorTransactionBlock({\n\t\t\tnetwork,\n\t\t\ttransactionBlock,\n\t\t\tclient,\n\t\t});\n\t\treturn await this.executeTransactionBlock({ network, bytes, digest, client });\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAoC;AACpC,qBAA+B;AAE/B,mBAA+B;AAE/B,kBAA0B;AAE1B,wBAAqC;AAGrC,wBAAwC;AAExC,yBAA4B;AAC5B,0BAA6B;AAE7B,oBAAqC;AAnBrC;AAsDA,MAAM,oBAAoB,CAAC,YAAoB;AAAA,EAC9C,OAAO,qBAAqB;AAAA,EAC5B,SAAS,uBAAuB;AACjC;AAEO,MAAM,UAAU;AAAA,EAUtB,YAAY,QAAyB;AA4IrC,uBAAM;AArJN;AACA;AACA;AACA;AACA;AAMC,uBAAK,cAAe,IAAI,+BAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,gBAAiB,OAAO;AAC7B,uBAAK,aAAc,OAAO,kBAAc,2CAAwB;AAChE,uBAAK,QAAS,OAAO,aAAS,oCAAqB;AACnD,uBAAK,cAAe,kBAAkB,OAAO,MAAM;AAEnD,QAAI,cAAc;AAClB,QAAI;AACH,YAAM,iBAAiB,mBAAK,QAAO,IAAI,mBAAK,cAAa,KAAK;AAC9D,UAAI,gBAAgB;AACnB,sBAAc,KAAK,MAAM,cAAc;AAAA,MACxC;AAAA,IACD,QAAE;AAAA,IAEF;AAEA,SAAK,oBAAgB,wBAAK,eAAe,CAAC,CAAC;AAC3C,SAAK,sBAAkB,wBAAK,EAAE,aAAa,OAAO,OAAO,KAAK,CAAC;AAG/D,mCAAQ,KAAK,iBAAiB,MAAM;A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AW,EAAE,QAAQ,CAAC;AACjD,UAAM,gBAAgB,MAAM,QAAQ,yBAAqB,sBAAQ,KAAK,CAAC;AAEvE,UAAM,mBAAK,cAAa,iCAAiC;AAAA,MACxD;AAAA,MACA,WAAW,cAAc;AAAA,IAC1B,CAAC;AAGD,UAAM,OAAO,wBAAwB,EAAE,OAAO,CAAC;AAE/C,WAAO,EAAE,OAAO;AAAA,EACjB;AAAA,EAEA,MAAM,kCAAkC;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAIG;AACF,UAAM,EAAE,OAAO,OAAO,IAAI,MAAM,KAAK,wBAAwB;AAAA,MAC5D;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC;AACD,WAAO,MAAM,KAAK,wBAAwB,EAAE,SAAS,OAAO,QAAQ,OAAO,CAAC;AAAA,EAC7E;AACD;AA5UC;AACA;AACA;AACA;AACA;AAiJM;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,mBAAK,cAAa,SAAS,WAAW;AAAA,EACvD,OAAO;AACN,uBAAK,QAAO,OAAO,mBAAK,cAAa,OAAO;AAAA,EAC7C;AAEA,OAAK,gBAAgB,IAAI,EAAE,aAAa,MAAM,OAAO,SAAS,CAAC;AAChE;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport { decodeSuiPrivateKey } from '@mysten/sui/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { fromB64, toB64 } from '@mysten/sui/utils';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport { decodeJwt } from 'jose';\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 { 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\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 = new Ed25519Keypair();\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\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t\tephemeralKeyPair: toB64(decodeSuiPrivateKey(ephemeralKeyPair.getSecretKey()).secretKey),\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({ network }: { network?: 'mainnet' | 'testnet' } = {}) {\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\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?: 'mainnet' | 'testnet' } = {}) {\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\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 sponsorTransaction({\n\t\tnetwork,\n\t\ttransaction,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\ttransaction: Transaction;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst session = await this.getSession();\n\n\t\tif (!session || !session.jwt) {\n\t\t\tthrow new Error('Missing required data for sponsorship.');\n\t\t}\n\n\t\tconst transactionKindBytes = await transaction.build({\n\t\t\tonlyTransactionKind: true,\n\t\t\tclient,\n\t\t});\n\n\t\treturn await this.#enokiClient.createSponsoredTransaction({\n\t\t\tjwt: session.jwt,\n\t\t\tnetwork,\n\t\t\ttransactionKindBytes: toB64(transactionKindBytes),\n\t\t});\n\t}\n\n\tasync executeTransaction({\n\t\tnetwork,\n\t\tbytes,\n\t\tdigest,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\tbytes: string;\n\t\tdigest: string;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst keypair = await this.getKeypair({ network });\n\t\tconst userSignature = await keypair.signTransaction(fromB64(bytes));\n\n\t\tawait this.#enokiClient.executeSponsoredTransaction({\n\t\t\tdigest,\n\t\t\tsignature: userSignature.signature,\n\t\t});\n\n\t\t// TODO: Should the parent just do this?\n\t\tawait client.waitForTransaction({ digest });\n\n\t\treturn { digest };\n\t}\n\n\tasync sponsorAndExecuteTransaction({\n\t\tnetwork,\n\t\ttransaction,\n\t\tclient,\n\t}: {\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\ttransaction: Transaction;\n\t\tclient: SuiClient;\n\t}) {\n\t\tconst { bytes, digest } = await this.sponsorTransaction({\n\t\t\tnetwork,\n\t\t\ttransaction,\n\t\t\tclient,\n\t\t});\n\t\treturn await this.executeTransaction({ network, bytes, digest, client });\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAoC;AACpC,qBAA+B;AAE/B,mBAA+B;AAE/B,kBAA0B;AAE1B,wBAAqC;AAGrC,wBAAwC;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A;AACA;AACA;AAiJM;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,mBAAK,cAAa,SAAS,WAAW;AAAA,EACvD,OAAO;AACN,uBAAK,QAAO,OAAO,mBAAK,cAAa,OAAO;AAAA,EAC7C;AAEA,OAAK,gBAAgB,IAAI,EAAE,aAAa,MAAM,OAAO,SAAS,CAAC;AAChE;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
- import type { SignatureWithBytes } from '@mysten/sui.js/cryptography';
2
- import { Keypair, PublicKey } from '@mysten/sui.js/cryptography';
3
- import type { Ed25519Keypair, Ed25519PublicKey } from '@mysten/sui.js/keypairs/ed25519';
4
- import type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';
1
+ import type { SignatureWithBytes } from '@mysten/sui/cryptography';
2
+ import { Keypair, PublicKey } from '@mysten/sui/cryptography';
3
+ import type { Ed25519Keypair, Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
4
+ import type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';
5
5
  export declare class EnokiPublicKey extends PublicKey {
6
6
  #private;
7
7
  constructor(input: {
@@ -21,11 +21,10 @@ export declare class EnokiKeypair extends Keypair {
21
21
  proof: ZkLoginSignatureInputs;
22
22
  ephemeralKeypair: Ed25519Keypair;
23
23
  });
24
- signData(data: Uint8Array): Uint8Array;
25
24
  sign(data: Uint8Array): Promise<Uint8Array>;
26
25
  signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>;
27
- signTransactionBlock(bytes: Uint8Array): Promise<SignatureWithBytes>;
28
- getKeyScheme(): import("@mysten/sui.js/cryptography").SignatureScheme;
26
+ signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>;
27
+ getKeyScheme(): import("@mysten/sui/cryptography").SignatureScheme;
29
28
  getPublicKey(): EnokiPublicKey;
30
29
  export(): never;
31
30
  getSecretKey(): never;
@@ -40,7 +40,7 @@ __export(EnokiKeypair_exports, {
40
40
  EnokiPublicKey: () => EnokiPublicKey
41
41
  });
42
42
  module.exports = __toCommonJS(EnokiKeypair_exports);
43
- var import_cryptography = require("@mysten/sui.js/cryptography");
43
+ var import_cryptography = require("@mysten/sui/cryptography");
44
44
  var import_zklogin = require("@mysten/zklogin");
45
45
  var _address, _ephemeralPublicKey, _proof, _maxEpoch, _ephemeralKeypair, _publicKey;
46
46
  class EnokiPublicKey extends import_cryptography.PublicKey {
@@ -81,9 +81,6 @@ class EnokiKeypair extends import_cryptography.Keypair {
81
81
  ephemeralPublicKey: input.ephemeralKeypair.getPublicKey()
82
82
  }));
83
83
  }
84
- signData(data) {
85
- return __privateGet(this, _ephemeralKeypair).signData(data);
86
- }
87
84
  async sign(data) {
88
85
  return __privateGet(this, _ephemeralKeypair).sign(data);
89
86
  }
@@ -99,8 +96,8 @@ class EnokiKeypair extends import_cryptography.Keypair {
99
96
  signature: zkSignature
100
97
  };
101
98
  }
102
- async signTransactionBlock(bytes) {
103
- const { bytes: signedBytes, signature: userSignature } = await __privateGet(this, _ephemeralKeypair).signTransactionBlock(bytes);
99
+ async signTransaction(bytes) {
100
+ const { bytes: signedBytes, signature: userSignature } = await __privateGet(this, _ephemeralKeypair).signTransaction(bytes);
104
101
  const zkSignature = (0, import_zklogin.getZkLoginSignature)({
105
102
  inputs: __privateGet(this, _proof),
106
103
  maxEpoch: __privateGet(this, _maxEpoch),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/EnokiKeypair.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureWithBytes } from '@mysten/sui.js/cryptography';\nimport { Keypair, PublicKey, SIGNATURE_SCHEME_TO_FLAG } from '@mysten/sui.js/cryptography';\nimport type { Ed25519Keypair, Ed25519PublicKey } from '@mysten/sui.js/keypairs/ed25519';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui.js/zklogin';\nimport { getZkLoginSignature } from '@mysten/zklogin';\n\nexport class EnokiPublicKey extends PublicKey {\n\t#address: string;\n\t#ephemeralPublicKey: Ed25519PublicKey;\n\n\tconstructor(input: { address: string; ephemeralPublicKey: Ed25519PublicKey }) {\n\t\tsuper();\n\t\tthis.#address = input.address;\n\t\tthis.#ephemeralPublicKey = input.ephemeralPublicKey;\n\t}\n\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\ttoSuiAddress(): string {\n\t\treturn this.#address;\n\t}\n\n\tverify(): never {\n\t\tthrow new Error('Verification for EnokiPublicKey is not supported');\n\t}\n\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.#ephemeralPublicKey.toRawBytes();\n\t}\n}\n\nexport class EnokiKeypair extends Keypair {\n\t#proof: ZkLoginSignatureInputs;\n\t#maxEpoch: number;\n\t#ephemeralKeypair: Ed25519Keypair;\n\t#publicKey: EnokiPublicKey;\n\n\tconstructor(input: {\n\t\taddress: string;\n\t\tmaxEpoch: number;\n\t\tproof: ZkLoginSignatureInputs;\n\t\tephemeralKeypair: Ed25519Keypair;\n\t}) {\n\t\tsuper();\n\t\tthis.#proof = input.proof;\n\t\tthis.#maxEpoch = input.maxEpoch;\n\t\tthis.#ephemeralKeypair = input.ephemeralKeypair;\n\t\tthis.#publicKey = new EnokiPublicKey({\n\t\t\taddress: input.address,\n\t\t\tephemeralPublicKey: input.ephemeralKeypair.getPublicKey(),\n\t\t});\n\t}\n\n\tsignData(data: Uint8Array) {\n\t\treturn this.#ephemeralKeypair.signData(data);\n\t}\n\n\tasync sign(data: Uint8Array) {\n\t\treturn this.#ephemeralKeypair.sign(data);\n\t}\n\n\tasync signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signPersonalMessage(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tasync signTransactionBlock(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signTransactionBlock(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tgetKeyScheme() {\n\t\treturn this.#ephemeralKeypair.getKeyScheme();\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\texport(): never {\n\t\tthrow new Error('EnokiKeypair does not support exporting');\n\t}\n\n\tgetSecretKey(): never {\n\t\tthrow new Error('EnokiKeypair does not support getting the secret key');\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAA6D;AAG7D,qBAAoC;AAPpC;AASO,MAAM,uBAAuB,8BAAU;AAAA,EAI7C,YAAY,OAAkE;AAC7E,UAAM;AAJP;AACA;AAIC,uBAAK,UAAW,MAAM;AACtB,uBAAK,qBAAsB,MAAM;AAAA,EAClC;AAAA,EAEA,OAAe;AACd,WAAO,6CAAyB,SAAS;AAAA,EAC1C;AAAA,EAEA,eAAuB;AACtB,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,SAAgB;AACf,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACnE;AAAA,EAEA,aAAyB;AACxB,WAAO,mBAAK,q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,yCAAyC;AAAA,EAC1D;AAAA,EAEA,eAAsB;AACrB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACvE;AACD;AA5EC;AACA;AACA;AACA;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureWithBytes } from '@mysten/sui/cryptography';\nimport { Keypair, PublicKey, SIGNATURE_SCHEME_TO_FLAG } from '@mysten/sui/cryptography';\nimport type { Ed25519Keypair, Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport { getZkLoginSignature } from '@mysten/zklogin';\n\nexport class EnokiPublicKey extends PublicKey {\n\t#address: string;\n\t#ephemeralPublicKey: Ed25519PublicKey;\n\n\tconstructor(input: { address: string; ephemeralPublicKey: Ed25519PublicKey }) {\n\t\tsuper();\n\t\tthis.#address = input.address;\n\t\tthis.#ephemeralPublicKey = input.ephemeralPublicKey;\n\t}\n\n\tflag(): number {\n\t\treturn SIGNATURE_SCHEME_TO_FLAG['ZkLogin'];\n\t}\n\n\ttoSuiAddress(): string {\n\t\treturn this.#address;\n\t}\n\n\tverify(): never {\n\t\tthrow new Error('Verification for EnokiPublicKey is not supported');\n\t}\n\n\ttoRawBytes(): Uint8Array {\n\t\treturn this.#ephemeralPublicKey.toRawBytes();\n\t}\n}\n\nexport class EnokiKeypair extends Keypair {\n\t#proof: ZkLoginSignatureInputs;\n\t#maxEpoch: number;\n\t#ephemeralKeypair: Ed25519Keypair;\n\t#publicKey: EnokiPublicKey;\n\n\tconstructor(input: {\n\t\taddress: string;\n\t\tmaxEpoch: number;\n\t\tproof: ZkLoginSignatureInputs;\n\t\tephemeralKeypair: Ed25519Keypair;\n\t}) {\n\t\tsuper();\n\t\tthis.#proof = input.proof;\n\t\tthis.#maxEpoch = input.maxEpoch;\n\t\tthis.#ephemeralKeypair = input.ephemeralKeypair;\n\t\tthis.#publicKey = new EnokiPublicKey({\n\t\t\taddress: input.address,\n\t\t\tephemeralPublicKey: input.ephemeralKeypair.getPublicKey(),\n\t\t});\n\t}\n\n\tasync sign(data: Uint8Array) {\n\t\treturn this.#ephemeralKeypair.sign(data);\n\t}\n\n\tasync signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signPersonalMessage(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tasync signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst { bytes: signedBytes, signature: userSignature } =\n\t\t\tawait this.#ephemeralKeypair.signTransaction(bytes);\n\n\t\tconst zkSignature = getZkLoginSignature({\n\t\t\tinputs: this.#proof,\n\t\t\tmaxEpoch: this.#maxEpoch,\n\t\t\tuserSignature,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: signedBytes,\n\t\t\tsignature: zkSignature,\n\t\t};\n\t}\n\n\tgetKeyScheme() {\n\t\treturn this.#ephemeralKeypair.getKeyScheme();\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\texport(): never {\n\t\tthrow new Error('EnokiKeypair does not support exporting');\n\t}\n\n\tgetSecretKey(): never {\n\t\tthrow new Error('EnokiKeypair does not support getting the secret key');\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAA6D;AAG7D,qBAAoC;AAPpC;AASO,MAAM,uBAAuB,8BAAU;AAAA,EAI7C,YAAY,OAAkE;AAC7E,UAAM;AAJP;AACA;AAIC,uBAAK,UAAW,MAAM;AACtB,uBAAK,qBAAsB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A,EAEA,eAAe;AACd,WAAO,mBAAK,mBAAkB,aAAa;AAAA,EAC5C;AAAA,EAEA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,SAAgB;AACf,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC1D;AAAA,EAEA,eAAsB;AACrB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACvE;AACD;AAxEC;AACA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -22,7 +22,7 @@ __export(encryption_exports, {
22
22
  createPassthroughEncryption: () => createPassthroughEncryption
23
23
  });
24
24
  module.exports = __toCommonJS(encryption_exports);
25
- var import_utils = require("@mysten/sui.js/utils");
25
+ var import_utils = require("@mysten/sui/utils");
26
26
  function createDefaultEncryption() {
27
27
  async function keyFromPassword(password, salt) {
28
28
  const key = await crypto.subtle.importKey(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/encryption.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromB64, toB64 } from '@mysten/sui.js/utils';\n\n/**\n * An interface\n */\nexport interface Encryption {\n\tencrypt(password: string, data: string): Promise<string>;\n\tdecrypt(password: string, data: string): Promise<string>;\n}\n\n/**\n * Create the default encryption interface, which uses the browsers built-in crypto primitives.\n */\nexport function createDefaultEncryption(): Encryption {\n\ttype EncryptedJSON = {\n\t\tpayload: string;\n\t\tiv: string;\n\t\tsalt: string;\n\t};\n\n\tasync function keyFromPassword(password: string, salt: Uint8Array) {\n\t\tconst key = await crypto.subtle.importKey(\n\t\t\t'raw',\n\t\t\tnew TextEncoder().encode(password),\n\t\t\t{ name: 'PBKDF2' },\n\t\t\tfalse,\n\t\t\t['deriveBits', 'deriveKey'],\n\t\t);\n\n\t\tconst derivedKey = await crypto.subtle.deriveKey(\n\t\t\t{\n\t\t\t\tname: 'PBKDF2',\n\t\t\t\tsalt,\n\t\t\t\titerations: 900_000,\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tkey,\n\t\t\t{ name: 'AES-GCM', length: 256 },\n\t\t\tfalse,\n\t\t\t['encrypt', 'decrypt'],\n\t\t);\n\n\t\treturn { key, derivedKey };\n\t}\n\n\treturn {\n\t\tasync encrypt(password, data) {\n\t\t\tconst salt = crypto.getRandomValues(new Uint8Array(16));\n\t\t\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, salt);\n\n\t\t\tconst payload = await crypto.subtle.encrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv,\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tnew TextEncoder().encode(data),\n\t\t\t);\n\n\t\t\treturn JSON.stringify({\n\t\t\t\tpayload: toB64(new Uint8Array(payload)),\n\t\t\t\tiv: toB64(iv),\n\t\t\t\tsalt: toB64(salt),\n\t\t\t} satisfies EncryptedJSON);\n\t\t},\n\t\tasync decrypt(password, data) {\n\t\t\tconst parsed = JSON.parse(data) as EncryptedJSON;\n\t\t\tif (!parsed.payload || !parsed.iv || !parsed.salt) {\n\t\t\t\tthrow new Error('Invalid encrypted data');\n\t\t\t}\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, fromB64(parsed.salt));\n\n\t\t\tconst decryptedContent = await crypto.subtle.decrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv: fromB64(parsed.iv),\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tfromB64(parsed.payload),\n\t\t\t);\n\n\t\t\treturn new TextDecoder().decode(decryptedContent);\n\t\t},\n\t};\n}\n\n/**\n * Create a passthrough encryption interface, which does not encrypt or decrypt data.\n */\nexport function createPassthroughEncryption(): Encryption {\n\treturn {\n\t\tasync encrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t\tasync decrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t};\n}\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromB64, toB64 } from '@mysten/sui/utils';\n\n/**\n * An interface\n */\nexport interface Encryption {\n\tencrypt(password: string, data: string): Promise<string>;\n\tdecrypt(password: string, data: string): Promise<string>;\n}\n\n/**\n * Create the default encryption interface, which uses the browsers built-in crypto primitives.\n */\nexport function createDefaultEncryption(): Encryption {\n\ttype EncryptedJSON = {\n\t\tpayload: string;\n\t\tiv: string;\n\t\tsalt: string;\n\t};\n\n\tasync function keyFromPassword(password: string, salt: Uint8Array) {\n\t\tconst key = await crypto.subtle.importKey(\n\t\t\t'raw',\n\t\t\tnew TextEncoder().encode(password),\n\t\t\t{ name: 'PBKDF2' },\n\t\t\tfalse,\n\t\t\t['deriveBits', 'deriveKey'],\n\t\t);\n\n\t\tconst derivedKey = await crypto.subtle.deriveKey(\n\t\t\t{\n\t\t\t\tname: 'PBKDF2',\n\t\t\t\tsalt,\n\t\t\t\titerations: 900_000,\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tkey,\n\t\t\t{ name: 'AES-GCM', length: 256 },\n\t\t\tfalse,\n\t\t\t['encrypt', 'decrypt'],\n\t\t);\n\n\t\treturn { key, derivedKey };\n\t}\n\n\treturn {\n\t\tasync encrypt(password, data) {\n\t\t\tconst salt = crypto.getRandomValues(new Uint8Array(16));\n\t\t\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, salt);\n\n\t\t\tconst payload = await crypto.subtle.encrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv,\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tnew TextEncoder().encode(data),\n\t\t\t);\n\n\t\t\treturn JSON.stringify({\n\t\t\t\tpayload: toB64(new Uint8Array(payload)),\n\t\t\t\tiv: toB64(iv),\n\t\t\t\tsalt: toB64(salt),\n\t\t\t} satisfies EncryptedJSON);\n\t\t},\n\t\tasync decrypt(password, data) {\n\t\t\tconst parsed = JSON.parse(data) as EncryptedJSON;\n\t\t\tif (!parsed.payload || !parsed.iv || !parsed.salt) {\n\t\t\t\tthrow new Error('Invalid encrypted data');\n\t\t\t}\n\n\t\t\tconst { derivedKey } = await keyFromPassword(password, fromB64(parsed.salt));\n\n\t\t\tconst decryptedContent = await crypto.subtle.decrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv: fromB64(parsed.iv),\n\t\t\t\t},\n\t\t\t\tderivedKey,\n\t\t\t\tfromB64(parsed.payload),\n\t\t\t);\n\n\t\t\treturn new TextDecoder().decode(decryptedContent);\n\t\t},\n\t};\n}\n\n/**\n * Create a passthrough encryption interface, which does not encrypt or decrypt data.\n */\nexport function createPassthroughEncryption(): Encryption {\n\treturn {\n\t\tasync encrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t\tasync decrypt(_password, data) {\n\t\t\treturn data;\n\t\t},\n\t};\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA+B;AAaxB,SAAS,0BAAsC;AAOrD,iBAAe,gBAAgB,UAAkB,MAAkB;AAClE,UAAM,MAAM,MAAM,OAAO,OAAO;AAAA,MAC/B;AAAA,MACA,IAAI,YAAY,EAAE,OAAO,QAAQ;AAAA,MACjC,EAAE,MAAM,SAAS;AAAA,MACjB;AAAA,MACA,CAAC,cAAc,WAAW;AAAA,IAC3B;AAEA,UAAM,aAAa,MAAM,OAAO,OAAO;AAAA,MACtC;AAAA,QACC,MAAM;AAAA,QACN;AAAA,QACA,YAAY;AAAA,QACZ,MAAM;AAAA,MACP;AAAA,MACA;AAAA,MACA,EAAE,MAAM,WAAW,QAAQ,IAAI;AAAA,MAC/B;AAAA,MACA,CAAC,WAAW,SAAS;AAAA,IACtB;AAEA,WAAO,EAA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AA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { CreateSponsoredTransactionBlockApiInput, CreateSponsoredTransactionBlockApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, ExecuteSponsoredTransactionBlockApiInput, ExecuteSponsoredTransactionBlockApiResponse, GetAppApiInput, GetAppApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
1
+ import type { CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, 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;
@@ -23,6 +23,6 @@ export declare class EnokiClient {
23
23
  getZkLogin(input: GetZkLoginApiInput): Promise<GetZkLoginApiResponse>;
24
24
  createZkLoginNonce(input: CreateZkLoginNonceApiInput): Promise<CreateZkLoginNonceApiResponse>;
25
25
  createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
26
- createSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput): Promise<CreateSponsoredTransactionBlockApiResponse>;
27
- executeSponsoredTransactionBlock(input: ExecuteSponsoredTransactionBlockApiInput): Promise<ExecuteSponsoredTransactionBlockApiResponse>;
26
+ createSponsoredTransaction(input: CreateSponsoredTransactionApiInput): Promise<CreateSponsoredTransactionApiResponse>;
27
+ executeSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput): Promise<ExecuteSponsoredTransactionApiResponse>;
28
28
  }
@@ -87,7 +87,7 @@ class EnokiClient {
87
87
  })
88
88
  });
89
89
  }
90
- createSponsoredTransactionBlock(input) {
90
+ createSponsoredTransaction(input) {
91
91
  return __privateMethod(this, _fetch, fetch_fn).call(this, "transaction-blocks/sponsor", {
92
92
  method: "POST",
93
93
  headers: input.jwt ? {
@@ -96,13 +96,13 @@ class EnokiClient {
96
96
  body: JSON.stringify({
97
97
  sender: input.sender,
98
98
  network: input.network,
99
- transactionBlockKindBytes: input.transactionBlockKindBytes,
99
+ transactionBlockKindBytes: input.transactionKindBytes,
100
100
  allowedAddresses: input.allowedAddresses,
101
101
  allowedMoveCallTargets: input.allowedMoveCallTargets
102
102
  })
103
103
  });
104
104
  }
105
- executeSponsoredTransactionBlock(input) {
105
+ executeSponsoredTransaction(input) {
106
106
  return __privateMethod(this, _fetch, fetch_fn).call(this, `transaction-blocks/sponsor/${input.digest}`, {
107
107
  method: "POST",
108
108
  body: JSON.stringify({
@@ -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\tCreateSponsoredTransactionBlockApiInput,\n\tCreateSponsoredTransactionBlockApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tExecuteSponsoredTransactionBlockApiInput,\n\tExecuteSponsoredTransactionBlockApiResponse,\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\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\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 (e) {\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}\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\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\tcreateSponsoredTransactionBlock(input: CreateSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionBlockApiResponse>('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 }\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.transactionBlockKindBytes,\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\texecuteSponsoredTransactionBlock(input: ExecuteSponsoredTransactionBlockApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionBlockApiResponse>(\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\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;AAkBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAUhB,MAAM,yBAAyB,MAAM;AAAA,EAG3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,SAAS,GAAP;AAAA,IAEF;AACA,UAAM,QAAQ,SAAS,CAAC,IAAI,IAAI,MAAM,OAAO,CAAC,EAAE,OAAO,IAAI;AAC3D,UAAM,wCAAwC,WAAW;AAAA,MACxD;AAAA,IACD,CAAC;AAfF,kBAA6D,CAAC;AAgB7D,SAAK,SAAS,UAAU,CAAC;AACzB,SAAK,OAAO;AAAA,EACb;AACD;AAKO,MAAM,YAAY;AAAA,EAKxB,YAAY,QAA2B;AA6EvC,uBAAM;AAjFN;AACA;AACA;AAGC,uBAAK,UAAW;AAChB,uBAAK,SAAU,OAAO,UAAU;AAChC,uBAAK,SAAU,OAAO;AAAA,EACvB;AAAA,EAEA,OAAO,QAAyB;AAC/B,WAAO,sBAAK,kBAAL,WAA+B,OAAO;AAAA,MAC5C,QAAQ;AAAA,IACT;AAAA,EACD;AAAA,EAEA,WAAW,OAA2B;AACrC,WAAO,sBAAK,kBAAL,WAAmC,WAAW;AAAA,MACpD,QAAQ;AAAA,MACR,SAAS;AAAA,QACR,CAAC,cAAc,GAAG,MAAM;AAAA,MACzB;AAAA,IACD;AAAA,EACD;AAAA,EAEA,mBAAmB,OAAmC;AACrD,WAAO,sBAAK,kBAAL,WAA2C,iBAAiB;AAAA,MAClE,QAAQ;AAAA,MACR,MAAM,KAAK,UAAU;AAAA,QACpB,SAAS,MAAM;AAAA,QACf,oBAAoB,MAAM,mBAAmB,e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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;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\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\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\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 (e) {\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}\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\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 }\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\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;AAkBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAUhB,MAAM,yBAAyB,MAAM;AAAA,EAG3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,SAAS,GAAP;AAAA,IAEF;AACA,UAAM,QAAQ,SAAS,CAA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