@mysten/enoki 1.3.4 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @mysten/enoki
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7a6b363: - `EnokiClient.prepareSponsoredTransaction({ transaction, network })` sets Enoki's
8
+ sponsor as gas owner with an empty gas payment. It works with a public API key, so a browser can
9
+ prepare a transaction, have the wallet sign it, and send it to your backend.
10
+ `EnokiClient.getSponsorAddress({ network })` returns the cached address. The `enoki()` extension's
11
+ `prepareSponsoredTransaction` and `getSponsorAddress` now use these.
12
+ - `client.enoki.getSponsorSigner()` returns a remote signer for the sponsor SDK's `createSponsor`,
13
+ so a sponsor built with it uses Enoki. Transactions Enoki declines are returned as `Rejected`.
14
+
15
+ ## 1.4.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 83ab0c5: Add Enoki sponsorship in one request:
20
+
21
+ - `enoki()` client extension: `client.enoki.sponsorAndExecuteTransaction({ transaction, signer })`
22
+ builds the transaction with Enoki as gas owner, signs it, and has Enoki sponsor and execute it.
23
+ It also accepts already-built bytes with a `signature`.
24
+ `client.enoki.prepareSponsoredTransaction({ transaction })` sets Enoki as gas owner without
25
+ building, for signing with a wallet or running your own checks first, and
26
+ `client.enoki.getSponsorAddress()` returns the sponsor address.
27
+ - `EnokiClient.sponsorAndExecuteTransaction`, and `sponsorAddresses` on `getApp`'s response.
28
+ - `EnokiClientError#requiresRebuild` and `isStaleTransactionError`, for errors where the
29
+ transaction must be built and signed again before retrying.
30
+
3
31
  ## 1.3.4
4
32
 
5
33
  ## 1.3.3
package/README.md CHANGED
@@ -49,6 +49,57 @@ function LoginButton() {
49
49
  }
50
50
  ```
51
51
 
52
+ ### Sponsor transactions
53
+
54
+ Add the `enoki()` extension to a Sui client on your backend, with a private API key that has
55
+ sponsored transactions enabled. Enoki pays gas from its sponsor's address balance, so the sender
56
+ doesn't need SUI.
57
+
58
+ ```ts
59
+ import { enoki } from '@mysten/enoki';
60
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
61
+
62
+ const client = new SuiGrpcClient({
63
+ network: 'mainnet',
64
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
65
+ }).$extend(enoki({ apiKey: process.env.ENOKI_PRIVATE_KEY! }));
66
+
67
+ // Builds with Enoki as gas owner, signs, and has Enoki sponsor and execute it
68
+ const result = await client.enoki.sponsorAndExecuteTransaction({ transaction, signer });
69
+ ```
70
+
71
+ To sign another way, such as with a wallet, or to check the transaction first, prepare it and send
72
+ the signed bytes:
73
+
74
+ ```ts
75
+ transaction.setSenderIfNotSet(signer.toSuiAddress());
76
+ await client.enoki.prepareSponsoredTransaction({ transaction });
77
+ const bytes = await transaction.build({ client });
78
+ const { signature } = await signer.signTransaction(bytes);
79
+
80
+ await client.enoki.sponsorAndExecuteTransaction({ transaction: bytes, signature });
81
+ ```
82
+
83
+ If `isStaleTransactionError(error)` is true, the sponsor address or reference gas price changed
84
+ since the transaction was built. Create a new `Transaction`, sign it and try again; one that was
85
+ already built keeps its gas owner and gas price.
86
+
87
+ In a browser, prepare the transaction with an `EnokiClient` that uses your public API key, have the
88
+ wallet sign it, and send the bytes and signature to your backend:
89
+
90
+ ```ts
91
+ import { EnokiClient } from '@mysten/enoki';
92
+
93
+ const enoki = new EnokiClient({ apiKey: 'your-public-api-key' });
94
+
95
+ await enoki.prepareSponsoredTransaction({ transaction, network: 'mainnet' });
96
+ const { bytes, signature } = await dAppKit.signTransaction({ transaction });
97
+ // POST { bytes, signature } to your backend, which calls client.enoki.sponsorAndExecuteTransaction
98
+ ```
99
+
100
+ The sponsor address is cached for up to a minute, so after Enoki rotates it a retry may fail until
101
+ the cache refreshes.
102
+
52
103
  ### Low-level client usage
53
104
 
54
105
  Use the client-only entry point to call the Enoki API without loading wallet helpers or local
@@ -1,4 +1,5 @@
1
- import { CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateSubnameApiInput, CreateSubnameApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, DeleteSubnameApiInput, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, GetAppApiInput, GetAppApiResponse, GetSubnamesApiInput, GetSubnamesApiResponse, GetZkLoginAddressesApiInput, GetZkLoginAddressesApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from "./type.mjs";
1
+ import { CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateSubnameApiInput, CreateSubnameApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, DeleteSubnameApiInput, EnokiDomainNetwork, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, GetAppApiInput, GetAppApiResponse, GetSubnamesApiInput, GetSubnamesApiResponse, GetZkLoginAddressesApiInput, GetZkLoginAddressesApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse, SponsorAndExecuteTransactionApiInput, SponsorAndExecuteTransactionApiResponse } from "./type.mjs";
2
+ import { Transaction } from "@mysten/sui/transactions";
2
3
 
3
4
  //#region src/EnokiClient/index.d.ts
4
5
  interface EnokiClientConfig {
@@ -18,7 +19,17 @@ declare class EnokiClientError extends Error {
18
19
  status: number;
19
20
  code: string;
20
21
  constructor(status: number, response: string);
22
+ /**
23
+ * True when the transaction must be built and signed again before retrying, because Enoki's
24
+ * sponsor address or the reference gas price changed since it was built.
25
+ */
26
+ get requiresRebuild(): boolean;
21
27
  }
28
+ /**
29
+ * Whether a sponsorship failed because the transaction was built with a sponsor address or
30
+ * reference gas price that's no longer current. Build it again, have the sender sign it, and retry.
31
+ */
32
+ declare function isStaleTransactionError(error: unknown): error is EnokiClientError;
22
33
  /**
23
34
  * A low-level client for interacting with the Enoki API.
24
35
  */
@@ -32,10 +43,36 @@ declare class EnokiClient {
32
43
  createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
33
44
  createSponsoredTransaction(input: CreateSponsoredTransactionApiInput): Promise<CreateSponsoredTransactionApiResponse>;
34
45
  executeSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput): Promise<ExecuteSponsoredTransactionApiResponse>;
46
+ /**
47
+ * Sponsors and executes a transaction in one request. Build it with the sponsor address from
48
+ * `getApp` as gas owner and an empty gas payment, and have the sender sign it. Requires a private
49
+ * API key.
50
+ *
51
+ * On `invalid_gas_owner` or `invalid_gas_price`, rebuild with the value in the error's `data`,
52
+ * sign again and retry. `already_sponsored` means Enoki has already sponsored this transaction.
53
+ */
54
+ sponsorAndExecuteTransaction(input: SponsorAndExecuteTransactionApiInput): Promise<SponsorAndExecuteTransactionApiResponse>;
55
+ /** Enoki's sponsor address. Works with a public key. Cached for a minute, or until a stale error. */
56
+ getSponsorAddress({
57
+ network
58
+ }: {
59
+ network: EnokiDomainNetwork;
60
+ }): Promise<string>;
61
+ /**
62
+ * Sets Enoki's sponsor as gas owner with an empty gas payment, without building. Works with a
63
+ * public key. Throws if the transaction has a different gas owner or a gas payment.
64
+ */
65
+ prepareSponsoredTransaction({
66
+ transaction,
67
+ network
68
+ }: {
69
+ transaction: Transaction;
70
+ network: EnokiDomainNetwork;
71
+ }): Promise<Transaction>;
35
72
  getSubnames(input: GetSubnamesApiInput): Promise<GetSubnamesApiResponse>;
36
73
  createSubname(input: CreateSubnameApiInput): Promise<CreateSubnameApiResponse>;
37
74
  deleteSubname(input: DeleteSubnameApiInput): void;
38
75
  }
39
76
  //#endregion
40
- export { EnokiClient, EnokiClientConfig, EnokiClientError };
77
+ export { EnokiClient, EnokiClientConfig, EnokiClientError, isStaleTransactionError };
41
78
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/EnokiClient/index.ts"],"mappings":";;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6e4;
3
6
  const ZKLOGIN_HEADER = "zklogin-jwt";
4
7
  var EnokiClientError = class extends Error {
5
8
  constructor(status, response) {
@@ -15,8 +18,22 @@ var EnokiClientError = class extends Error {
15
18
  this.status = status;
16
19
  this.code = errors?.[0]?.code ?? "unknown_error";
17
20
  }
21
+ /**
22
+ * True when the transaction must be built and signed again before retrying, because Enoki's
23
+ * sponsor address or the reference gas price changed since it was built.
24
+ */
25
+ get requiresRebuild() {
26
+ return this.code === "invalid_gas_owner" || this.code === "invalid_gas_price";
27
+ }
18
28
  };
19
29
  /**
30
+ * Whether a sponsorship failed because the transaction was built with a sponsor address or
31
+ * reference gas price that's no longer current. Build it again, have the sender sign it, and retry.
32
+ */
33
+ function isStaleTransactionError(error) {
34
+ return error instanceof EnokiClientError && error.requiresRebuild;
35
+ }
36
+ /**
20
37
  * A low-level client for interacting with the Enoki API.
21
38
  */
22
39
  var EnokiClient = class {
@@ -24,6 +41,7 @@ var EnokiClient = class {
24
41
  #apiUrl;
25
42
  #apiKey;
26
43
  #additionalEpochs;
44
+ #sponsorAddresses = /* @__PURE__ */ new Map();
27
45
  constructor(config) {
28
46
  this.#version = "v1";
29
47
  this.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;
@@ -86,6 +104,63 @@ var EnokiClient = class {
86
104
  body: JSON.stringify({ signature: input.signature })
87
105
  });
88
106
  }
107
+ /**
108
+ * Sponsors and executes a transaction in one request. Build it with the sponsor address from
109
+ * `getApp` as gas owner and an empty gas payment, and have the sender sign it. Requires a private
110
+ * API key.
111
+ *
112
+ * On `invalid_gas_owner` or `invalid_gas_price`, rebuild with the value in the error's `data`,
113
+ * sign again and retry. `already_sponsored` means Enoki has already sponsored this transaction.
114
+ */
115
+ async sponsorAndExecuteTransaction(input) {
116
+ try {
117
+ return await this.#fetch("transaction-blocks/sponsor/execute", {
118
+ method: "POST",
119
+ body: JSON.stringify({
120
+ network: input.network,
121
+ transactionBytes: input.transactionBytes,
122
+ signature: input.signature,
123
+ allowedAddresses: input.allowedAddresses,
124
+ allowedMoveCallTargets: input.allowedMoveCallTargets
125
+ })
126
+ });
127
+ } catch (error) {
128
+ if (isStaleTransactionError(error)) this.#sponsorAddresses.delete(input.network === "testnet" ? "testnet" : "mainnet");
129
+ throw error;
130
+ }
131
+ }
132
+ /** Enoki's sponsor address. Works with a public key. Cached for a minute, or until a stale error. */
133
+ getSponsorAddress({ network }) {
134
+ const cached = this.#sponsorAddresses.get(network);
135
+ if (cached && cached.expiresAt > Date.now()) return cached.address;
136
+ const address = this.getApp().then(({ sponsorAddresses }) => {
137
+ const sponsorAddress = sponsorAddresses?.[network];
138
+ if (!sponsorAddress) throw new Error(`Enoki does not sponsor transactions on ${network}`);
139
+ return normalizeSuiAddress(sponsorAddress);
140
+ });
141
+ const entry = {
142
+ address,
143
+ expiresAt: Date.now() + SPONSOR_ADDRESS_TTL_MS
144
+ };
145
+ address.catch(() => {
146
+ if (this.#sponsorAddresses.get(network) === entry) this.#sponsorAddresses.delete(network);
147
+ });
148
+ this.#sponsorAddresses.set(network, entry);
149
+ return address;
150
+ }
151
+ /**
152
+ * Sets Enoki's sponsor as gas owner with an empty gas payment, without building. Works with a
153
+ * public key. Throws if the transaction has a different gas owner or a gas payment.
154
+ */
155
+ async prepareSponsoredTransaction({ transaction, network }) {
156
+ const sponsorAddress = await this.getSponsorAddress({ network });
157
+ const { gasData } = transaction.getData();
158
+ if (gasData.owner && normalizeSuiAddress(gasData.owner) !== sponsorAddress) throw new Error(`Transaction gas owner is ${gasData.owner}, not Enoki's sponsor ${sponsorAddress}`);
159
+ if (gasData.payment && gasData.payment.length > 0) throw new Error("Sponsored transactions pay gas from the sponsor; remove the gas payment");
160
+ transaction.setGasOwner(sponsorAddress);
161
+ transaction.setGasPayment([]);
162
+ return transaction;
163
+ }
89
164
  getSubnames(input) {
90
165
  const query = new URLSearchParams();
91
166
  if (input.address) query.set("address", input.address);
@@ -132,5 +207,5 @@ var EnokiClient = class {
132
207
  };
133
208
 
134
209
  //#endregion
135
- export { EnokiClient, EnokiClientError };
210
+ export { EnokiClient, EnokiClientError, isStaleTransactionError };
136
211
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#version","#apiUrl","#apiKey","#additionalEpochs","#fetch"],"sources":["../../src/EnokiClient/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n\n\t/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */\n\tadditionalEpochs?: number;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\t#additionalEpochs: number | undefined;\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t\tthis.#additionalEpochs = config.additionalEpochs;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs ?? this.#additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],"mappings":";AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB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,MAAc,MAA+B;EACtE,MAAM,MAAM,MAAM,MAAM,GAAG,MAAKH,OAAQ,GAAG,MAAKD,QAAS,GAAG,QAAQ;GACnE,GAAG;GACH,SAAS;IACR,GAAG,KAAK;IACR,eAAe,UAAU,MAAKE;IAC9B,gBAAgB;IAChB,cAAc,OAAO,YAAY;IACjC;GACD,CAAC;AAEF,MAAI,CAAC,IAAI,GACR,OAAM,IAAI,iBAAiB,IAAI,QAAQ,MAAM,IAAI,MAAM,CAAC;EAGzD,MAAM,EAAE,SAAS,MAAM,IAAI,MAAM;AAEjC,SAAO"}
1
+ {"version":3,"file":"index.mjs","names":["#version","#apiUrl","#apiKey","#additionalEpochs","#fetch","#sponsorAddresses"],"sources":["../../src/EnokiClient/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tEnokiDomainNetwork,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n\tSponsorAndExecuteTransactionApiInput,\n\tSponsorAndExecuteTransactionApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.mystenlabs.com';\nconst SPONSOR_ADDRESS_TTL_MS = 60_000;\nconst ZKLOGIN_HEADER = 'zklogin-jwt';\n\nexport interface EnokiClientConfig {\n\t/** The API key for the Enoki app, available in the Enoki Portal. */\n\tapiKey: string;\n\n\t/** The API URL for Enoki. In most cases, this should not be set. */\n\tapiUrl?: string;\n\n\t/** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */\n\tadditionalEpochs?: number;\n}\n\nexport class EnokiClientError extends Error {\n\terrors: { code: string; message: string; data: unknown }[] = [];\n\tstatus: number;\n\tcode: string;\n\n\tconstructor(status: number, response: string) {\n\t\tlet errors;\n\t\ttry {\n\t\t\tconst parsedResponse = JSON.parse(response) as {\n\t\t\t\terrors: { code: string; message: string; data: unknown }[];\n\t\t\t};\n\t\t\terrors = parsedResponse.errors;\n\t\t} catch {\n\t\t\t// Ignore\n\t\t}\n\t\tconst cause = errors?.[0] ? new Error(errors[0].message) : undefined;\n\t\tsuper(`Request to Enoki API failed (status: ${status})`, {\n\t\t\tcause,\n\t\t});\n\t\tthis.errors = errors ?? [];\n\t\tthis.name = 'EnokiClientError';\n\t\tthis.status = status;\n\t\tthis.code = errors?.[0]?.code ?? 'unknown_error';\n\t}\n\n\t/**\n\t * True when the transaction must be built and signed again before retrying, because Enoki's\n\t * sponsor address or the reference gas price changed since it was built.\n\t */\n\tget requiresRebuild(): boolean {\n\t\treturn this.code === 'invalid_gas_owner' || this.code === 'invalid_gas_price';\n\t}\n}\n\n/**\n * Whether a sponsorship failed because the transaction was built with a sponsor address or\n * reference gas price that's no longer current. Build it again, have the sender sign it, and retry.\n */\nexport function isStaleTransactionError(error: unknown): error is EnokiClientError {\n\treturn error instanceof EnokiClientError && error.requiresRebuild;\n}\n\n/**\n * A low-level client for interacting with the Enoki API.\n */\nexport class EnokiClient {\n\t#version: string;\n\t#apiUrl: string;\n\t#apiKey: string;\n\t#additionalEpochs: number | undefined;\n\t#sponsorAddresses = new Map<\n\t\tEnokiDomainNetwork,\n\t\t{ address: Promise<string>; expiresAt: number }\n\t>();\n\n\tconstructor(config: EnokiClientConfig) {\n\t\tthis.#version = 'v1';\n\t\tthis.#apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n\t\tthis.#apiKey = config.apiKey;\n\t\tthis.#additionalEpochs = config.additionalEpochs;\n\t}\n\n\tgetApp(_input?: GetAppApiInput) {\n\t\treturn this.#fetch<GetAppApiResponse>('app', {\n\t\t\tmethod: 'GET',\n\t\t});\n\t}\n\n\tgetZkLogin(input: GetZkLoginApiInput) {\n\t\treturn this.#fetch<GetZkLoginApiResponse>('zklogin', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tgetZkLoginAddresses(input: GetZkLoginAddressesApiInput) {\n\t\treturn this.#fetch<GetZkLoginAddressesApiResponse>('zklogin/addresses', {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t});\n\t}\n\n\tcreateZkLoginNonce(input: CreateZkLoginNonceApiInput) {\n\t\treturn this.#fetch<CreateZkLoginNonceApiResponse>('zklogin/nonce', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tadditionalEpochs: input.additionalEpochs ?? this.#additionalEpochs,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateZkLoginZkp(input: CreateZkLoginZkpApiInput) {\n\t\treturn this.#fetch<CreateZkLoginZkpApiResponse>('zklogin/zkp', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tephemeralPublicKey: input.ephemeralPublicKey.toSuiPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Sponsors and executes a transaction in one request. Build it with the sponsor address from\n\t * `getApp` as gas owner and an empty gas payment, and have the sender sign it. Requires a private\n\t * API key.\n\t *\n\t * On `invalid_gas_owner` or `invalid_gas_price`, rebuild with the value in the error's `data`,\n\t * sign again and retry. `already_sponsored` means Enoki has already sponsored this transaction.\n\t */\n\tasync sponsorAndExecuteTransaction(input: SponsorAndExecuteTransactionApiInput) {\n\t\ttry {\n\t\t\treturn await this.#fetch<SponsorAndExecuteTransactionApiResponse>(\n\t\t\t\t'transaction-blocks/sponsor/execute',\n\t\t\t\t{\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tnetwork: input.network,\n\t\t\t\t\t\ttransactionBytes: input.transactionBytes,\n\t\t\t\t\t\tsignature: input.signature,\n\t\t\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (isStaleTransactionError(error)) {\n\t\t\t\tthis.#sponsorAddresses.delete(input.network === 'testnet' ? 'testnet' : 'mainnet');\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Enoki's sponsor address. Works with a public key. Cached for a minute, or until a stale error. */\n\tgetSponsorAddress({ network }: { network: EnokiDomainNetwork }): Promise<string> {\n\t\tconst cached = this.#sponsorAddresses.get(network);\n\t\tif (cached && cached.expiresAt > Date.now()) {\n\t\t\treturn cached.address;\n\t\t}\n\n\t\tconst address = this.getApp().then(({ sponsorAddresses }) => {\n\t\t\tconst sponsorAddress = sponsorAddresses?.[network];\n\t\t\tif (!sponsorAddress) {\n\t\t\t\tthrow new Error(`Enoki does not sponsor transactions on ${network}`);\n\t\t\t}\n\t\t\treturn normalizeSuiAddress(sponsorAddress);\n\t\t});\n\t\tconst entry = { address, expiresAt: Date.now() + SPONSOR_ADDRESS_TTL_MS };\n\t\taddress.catch(() => {\n\t\t\tif (this.#sponsorAddresses.get(network) === entry) {\n\t\t\t\tthis.#sponsorAddresses.delete(network);\n\t\t\t}\n\t\t});\n\t\tthis.#sponsorAddresses.set(network, entry);\n\t\treturn address;\n\t}\n\n\t/**\n\t * Sets Enoki's sponsor as gas owner with an empty gas payment, without building. Works with a\n\t * public key. Throws if the transaction has a different gas owner or a gas payment.\n\t */\n\tasync prepareSponsoredTransaction({\n\t\ttransaction,\n\t\tnetwork,\n\t}: {\n\t\ttransaction: Transaction;\n\t\tnetwork: EnokiDomainNetwork;\n\t}): Promise<Transaction> {\n\t\tconst sponsorAddress = await this.getSponsorAddress({ network });\n\t\tconst { gasData } = transaction.getData();\n\n\t\tif (gasData.owner && normalizeSuiAddress(gasData.owner) !== sponsorAddress) {\n\t\t\tthrow new Error(\n\t\t\t\t`Transaction gas owner is ${gasData.owner}, not Enoki's sponsor ${sponsorAddress}`,\n\t\t\t);\n\t\t}\n\t\tif (gasData.payment && gasData.payment.length > 0) {\n\t\t\tthrow new Error('Sponsored transactions pay gas from the sponsor; remove the gas payment');\n\t\t}\n\n\t\ttransaction.setGasOwner(sponsorAddress);\n\t\ttransaction.setGasPayment([]);\n\t\treturn transaction;\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],"mappings":";;;AAgCA,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;AAC/B,MAAM,iBAAiB;AAavB,IAAa,mBAAb,cAAsC,MAAM;CAK3C,YAAY,QAAgB,UAAkB;EAC7C,IAAI;AACJ,MAAI;AAIH,YAHuB,KAAK,MAAM,SAAS,CAGnB;UACjB;EAGR,MAAM,QAAQ,SAAS,KAAK,IAAI,MAAM,OAAO,GAAG,QAAQ,GAAG;AAC3D,QAAM,wCAAwC,OAAO,IAAI,EACxD,OACA,CAAC;gBAjB0D,EAAE;AAkB9D,OAAK,SAAS,UAAU,EAAE;AAC1B,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,OAAO,SAAS,IAAI,QAAQ;;;;;;CAOlC,IAAI,kBAA2B;AAC9B,SAAO,KAAK,SAAS,uBAAuB,KAAK,SAAS;;;;;;;AAQ5D,SAAgB,wBAAwB,OAA2C;AAClF,QAAO,iBAAiB,oBAAoB,MAAM;;;;;AAMnD,IAAa,cAAb,MAAyB;CACxB;CACA;CACA;CACA;CACA,oCAAoB,IAAI,KAGrB;CAEH,YAAY,QAA2B;AACtC,QAAKA,UAAW;AAChB,QAAKC,SAAU,OAAO,UAAU;AAChC,QAAKC,SAAU,OAAO;AACtB,QAAKC,mBAAoB,OAAO;;CAGjC,OAAO,QAAyB;AAC/B,SAAO,MAAKC,MAA0B,OAAO,EAC5C,QAAQ,OACR,CAAC;;CAGH,WAAW,OAA2B;AACrC,S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AAQ;AAEpC,MAAI,MAAM,QACT,OAAM,IAAI,WAAW,MAAM,QAAQ;AAEpC,MAAI,MAAM,OACT,OAAM,IAAI,UAAU,MAAM,OAAO;AAElC,SAAO,MAAKD,MACX,cAAc,MAAM,OAAO,IAAI,IAAI,MAAM,UAAU,KAAK,KACxD,EACC,QAAQ,OACR,CACD;;CAGF,cAAc,OAA8B;AAC3C,SAAO,MAAKA,MAAiC,YAAY;GACxD,QAAQ;GACR,SAAS,MAAM,MACZ,GACC,iBAAiB,MAAM,KACxB,GACA,EAAE;GACL,MAAM,KAAK,UAAU;IACpB,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,SAAS,MAAM;IACf,eAAe,MAAM;IACrB,CAAC;GACF,CAAC;;CAGH,cAAc,OAA8B;AAC3C,QAAKA,MAAiC,YAAY;GACjD,QAAQ;GACR,MAAM,KAAK,UAAU;IACpB,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,SAAS,MAAM;IACf,CAAC;GACF,CAAC;;CAGH,OAAMA,MAAoB,MAAc,MAA+B;EACtE,MAAM,MAAM,MAAM,MAAM,GAAG,MAAKH,OAAQ,GAAG,MAAKD,QAAS,GAAG,QAAQ;GACnE,GAAG;GACH,SAAS;IACR,GAAG,KAAK;IACR,eAAe,UAAU,MAAKE;IAC9B,gBAAgB;IAChB,cAAc,OAAO,YAAY;IACjC;GACD,CAAC;AAEF,MAAI,CAAC,IAAI,GACR,OAAM,IAAI,iBAAiB,IAAI,QAAQ,MAAM,IAAI,MAAM,CAAC;EAGzD,MAAM,EAAE,SAAS,MAAM,IAAI,MAAM;AAEjC,SAAO"}
@@ -18,6 +18,11 @@ interface GetAppApiResponse {
18
18
  name: string;
19
19
  network: EnokiDomainNetwork;
20
20
  }[];
21
+ /**
22
+ * Enoki's sponsor address on each network it sponsors on. Use it as the gas owner for
23
+ * `sponsorAndExecuteTransaction`.
24
+ */
25
+ sponsorAddresses: Partial<Record<EnokiDomainNetwork, string>>;
21
26
  }
22
27
  interface GetZkLoginApiInput {
23
28
  jwt: string;
@@ -84,6 +89,21 @@ interface ExecuteSponsoredTransactionApiInput {
84
89
  interface ExecuteSponsoredTransactionApiResponse {
85
90
  digest: string;
86
91
  }
92
+ interface SponsorAndExecuteTransactionApiInput {
93
+ network?: EnokiNetwork;
94
+ /**
95
+ * Base64 BCS bytes of the built transaction, with the sponsor address from `getApp` as gas owner
96
+ * and an empty gas payment.
97
+ */
98
+ transactionBytes: string;
99
+ /** The sender's signature over `transactionBytes`. */
100
+ signature: string;
101
+ allowedAddresses?: string[];
102
+ allowedMoveCallTargets?: string[];
103
+ }
104
+ interface SponsorAndExecuteTransactionApiResponse {
105
+ digest: string;
106
+ }
87
107
  interface GetSubnamesApiInput {
88
108
  address?: string;
89
109
  network?: EnokiDomainNetwork;
@@ -115,5 +135,5 @@ interface DeleteSubnameApiInput {
115
135
  subname: string;
116
136
  }
117
137
  //#endregion
118
- export { AuthProvider, CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateSubnameApiInput, CreateSubnameApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, DeleteSubnameApiInput, EnokiNetwork, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, GetAppApiInput, GetAppApiResponse, GetSubnamesApiInput, GetSubnamesApiResponse, GetZkLoginAddressesApiInput, GetZkLoginAddressesApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse };
138
+ export { AuthProvider, CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateSubnameApiInput, CreateSubnameApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, DeleteSubnameApiInput, EnokiDomainNetwork, EnokiNetwork, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, GetAppApiInput, GetAppApiResponse, GetSubnamesApiInput, GetSubnamesApiResponse, GetZkLoginAddressesApiInput, GetZkLoginAddressesApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse, SponsorAndExecuteTransactionApiInput, SponsorAndExecuteTransactionApiResponse };
119
139
  //# sourceMappingURL=type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.mts","names":[],"sources":["../../src/EnokiClient/type.ts"],"mappings":";;;;KAMY,YAAA;AAAA,KACA,YAAA;AAAA,KACA,kBAAA;AAAA,KACA,mBAAA;AAAA,UAEK,cAAA;AAAA,UACA,iBAAA;EAChB,cAAA;EACA,uBAAA;IACC,YAAA,EAAc,YAAA;IACd,QAAA;EAAA;EAED,OAAA;IACC,KAAA;IACA,IAAA;IACA,OAAA,EAAS,kBAAA;EAAA;AAAA;AAAA,UAIM,kBAAA;EAChB,GAAA;AAAA;AAAA,UAEgB,qBAAA;EAChB,OAAA;EACA,SAAA;EACA,IAAA;AAAA;AAAA,UAGgB,2BAAA;EAChB,GAAA;AAAA;AAAA,UAEgB,8BAAA;EAChB,SAAA;IACC,QAAA;IACA,IAAA;IACA,OAAA;IACA,SAAA;IACA,MAAA;EAAA;AAAA;AAAA,UAIe,0BAAA;EAChB,OAAA,GAAU,YAAA;EACV,kBAAA,EAAoB,SAAA;EACpB,gBAAA;AAAA;AAAA,UAEgB,6BAAA;EAChB,KAAA;EACA,UAAA;EACA,KAAA;EACA,QAAA;EACA,mBAAA;AAAA;AAAA,UAGgB,wBAAA;EAChB,OAAA,GAAU,YAAA;EACV,GAAA;EACA,kBAAA,EAAoB,SAAA;EACpB,UAAA;EACA,QAAA;AAAA;AAAA,UAEgB,2BAAA,SAAoC,sBAAA;AAAA,KAEzC,kCAAA;EACX,OAAA,GAAU,YAAA;EACV,oBAAA;AAAA;EAGE,GAAA;EACA,MAAA;EACA,gBAAA;EACA,sBAAA;AAAA;EAGA,MAAA;EACA,gBAAA;EACA,sBAAA;EACA,GAAA;AAAA;AAAA,UAIc,qCAAA;EAChB,KAAA;EACA,MAAA;AAAA;AAA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;EACA,mBAAA;AAAA;AAAA,UAGgB,wBAAA;EAChB,OAAA,GAAU,YAAA;EACV,GAAA;EACA,kBAAA,EAAoB,SAAA;EACpB,UAAA;EACA,QAAA;AAAA;AAAA,UAEgB,2BAAA,SAAoC,sBAAA;AAAA,KAEzC,kCAAA;EACX,OAAA,GAAU,YAAA;EACV,oBAAA;AAAA;EAGE,GAAA;EACA,MAAA;EACA,gBAAA;EACA,sBAAA;AAAA;EAGA,MAAA;EACA,gBAAA;EACA,sBAAA;EACA,GAAA;AAAA;AAAA,UAIc,qCAAA;EAChB,KAAA;EACA,MAAA;AAAA;AAAA,UAGgB,mCAAA;EAChB,MAAA;EACA,SAAA;AAAA;AAAA,UAGgB,sCAAA;EAChB,MAAA;AAAA;AAAA,UAGgB,oCAAA;EAChB,OAAA,GAAU,YAAA;EArDU;;;;EA0DpB,gBAAA;EAvD6C;EAyD7C,SAAA;EACA,gBAAA;EACA,sBAAA;AAAA;AAAA,UAGgB,uCAAA;EAChB,MAAA;AAAA;AAAA,UAGgB,mBAAA;EAChB,OAAA;EACA,OAAA,GAAU,kBAAA;EACV,MAAA;AAAA;AAAA,UAEgB,sBAAA;EAChB,QAAA;IACC,IAAA;IACA,MAAA,EAAQ,mBAAA;EAAA;AAAA;AAAA,KAIE,qBAAA;EACX,MAAA;EACA,OAAA,GAAU,kBAAA;EACV,OAAA;AAAA;EAGE,GAAA;EACA,aAAA;AAAA;EAGA,aAAA;EACA,GAAA;AAAA;AAAA,UAGc,wBAAA;EAChB,IAAA;AAAA;AAAA,UAGgB,qBAAA;EAChB,MAAA;EACA,OAAA,GAAU,kBAAA;EACV,OAAA;AAAA"}
@@ -2,10 +2,10 @@ import { EnokiClient } from "./EnokiClient/index.mjs";
2
2
  import { createDefaultEncryption } from "./encryption.mjs";
3
3
  import { EnokiKeypair } from "./EnokiKeypair.mjs";
4
4
  import { createSessionStorage } from "./stores.mjs";
5
+ import { fromBase64, toBase64 } from "@mysten/sui/utils";
5
6
  import { WebCryptoSigner } from "@mysten/webcrypto-signer";
6
7
  import { decodeSuiPrivateKey } from "@mysten/sui/cryptography";
7
8
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
8
- import { fromBase64, toBase64 } from "@mysten/sui/utils";
9
9
  import { decodeJwt } from "@mysten/sui/zklogin";
10
10
  import { clear, createStore, get, set } from "idb-keyval";
11
11
  import { atom, onMount, onSet } from "nanostores";
package/dist/client.d.mts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { AuthProvider, EnokiNetwork } from "./EnokiClient/type.mjs";
2
- import { EnokiClient, EnokiClientConfig, EnokiClientError } from "./EnokiClient/index.mjs";
3
- export { type AuthProvider, EnokiClient, type EnokiClientConfig, EnokiClientError, type EnokiNetwork };
2
+ import { EnokiClient, EnokiClientConfig, EnokiClientError, isStaleTransactionError } from "./EnokiClient/index.mjs";
3
+ import { EnokiClientExtension, EnokiExtensionOptions, EnokiPrepareSponsoredTransactionOptions, EnokiSponsorAndExecuteTransactionOptions, EnokiSponsorSigner, enoki } from "./extension.mjs";
4
+ export { type AuthProvider, EnokiClient, type EnokiClientConfig, EnokiClientError, EnokiClientExtension, type EnokiExtensionOptions, type EnokiNetwork, type EnokiPrepareSponsoredTransactionOptions, type EnokiSponsorAndExecuteTransactionOptions, type EnokiSponsorSigner, enoki, isStaleTransactionError };
package/dist/client.mjs CHANGED
@@ -1,3 +1,4 @@
1
- import { EnokiClient, EnokiClientError } from "./EnokiClient/index.mjs";
1
+ import { EnokiClient, EnokiClientError, isStaleTransactionError } from "./EnokiClient/index.mjs";
2
+ import { EnokiClientExtension, enoki } from "./extension.mjs";
2
3
 
3
- export { EnokiClient, EnokiClientError };
4
+ export { EnokiClient, EnokiClientError, EnokiClientExtension, enoki, isStaleTransactionError };
@@ -0,0 +1,115 @@
1
+ import { EnokiClient, EnokiClientConfig } from "./EnokiClient/index.mjs";
2
+ import { Transaction } from "@mysten/sui/transactions";
3
+ import { Signer } from "@mysten/sui/cryptography";
4
+ import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
5
+
6
+ //#region src/extension.d.ts
7
+ type EnokiExtensionOptions<Name extends string = 'enoki'> = Omit<EnokiClientConfig, 'additionalEpochs'> & {
8
+ name?: Name;
9
+ };
10
+ interface EnokiSponsorAndExecuteBaseOptions<Include extends SuiClientTypes.TransactionInclude> extends SuiClientTypes.CoreClientMethodOptions {
11
+ /** Addresses the transaction may use, in addition to the app's allowlist in the Enoki Portal. */
12
+ allowedAddresses?: string[];
13
+ /** Move call targets the transaction may call, in addition to the app's allowlist in the Enoki Portal. */
14
+ allowedMoveCallTargets?: string[];
15
+ include?: Include & SuiClientTypes.TransactionInclude;
16
+ }
17
+ type EnokiSponsorAndExecuteTransactionOptions<Include extends SuiClientTypes.TransactionInclude = {}> = EnokiSponsorAndExecuteBaseOptions<Include> & ({
18
+ /** The transaction to send. Enoki is set as gas owner, and the sender defaults to `signer`. */transaction: Transaction; /** Signs as the transaction sender. */
19
+ signer: Signer;
20
+ signature?: never;
21
+ } | {
22
+ /**
23
+ * Built transaction bytes (or base64) of a transaction prepared with
24
+ * `prepareSponsoredTransaction`.
25
+ */
26
+ transaction: Uint8Array | string; /** The sender's signature over the bytes. */
27
+ signature: string;
28
+ signer?: never;
29
+ });
30
+ interface EnokiPrepareSponsoredTransactionOptions {
31
+ /** The transaction to prepare. Enoki is set as gas owner, paying from its address balance. */
32
+ transaction: Transaction;
33
+ }
34
+ /** A sponsor SDK `RemoteSigner` backed by Enoki: pass it as `createSponsor`'s `signer`. */
35
+ interface EnokiSponsorSigner {
36
+ toSuiAddress(): string;
37
+ signAndExecuteTransaction(options: {
38
+ transaction: Uint8Array;
39
+ additionalSignatures: string[];
40
+ signal?: AbortSignal;
41
+ }): Promise<{
42
+ $kind: 'Rejected';
43
+ issues: Issue[];
44
+ policyIssues: Issue[];
45
+ analysisIssues: Issue[];
46
+ reason: 'POLICY_REJECTED';
47
+ } | SuiClientTypes.TransactionResult<{
48
+ effects: true;
49
+ }>>;
50
+ }
51
+ type Issue = {
52
+ code?: string;
53
+ message: string;
54
+ };
55
+ /**
56
+ * Adds Enoki sponsorship to a Sui client. Requires a private API key with sponsored transactions
57
+ * enabled.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const client = new SuiGrpcClient({ network: 'mainnet', baseUrl }).$extend(
62
+ * enoki({ apiKey: process.env.ENOKI_PRIVATE_KEY! }),
63
+ * );
64
+ *
65
+ * const result = await client.enoki.sponsorAndExecuteTransaction({ transaction, signer });
66
+ * ```
67
+ */
68
+ declare function enoki<const Name extends string = 'enoki'>({
69
+ name,
70
+ ...config
71
+ }: EnokiExtensionOptions<Name>): {
72
+ name: Name;
73
+ register: (client: ClientWithCoreApi) => EnokiClientExtension;
74
+ };
75
+ declare class EnokiClientExtension {
76
+ #private;
77
+ constructor({
78
+ client,
79
+ enoki
80
+ }: {
81
+ client: ClientWithCoreApi;
82
+ enoki: EnokiClient;
83
+ });
84
+ /** Enoki's sponsor address on the client's network. */
85
+ getSponsorAddress(): Promise<string>;
86
+ /** Sets Enoki as gas owner with an empty gas payment, without building. */
87
+ prepareSponsoredTransaction({
88
+ transaction
89
+ }: EnokiPrepareSponsoredTransactionOptions): Promise<Transaction>;
90
+ /**
91
+ * Has Enoki sponsor and execute a transaction, and waits for it. Returns the same result as
92
+ * `client.core.signAndExecuteTransaction`.
93
+ *
94
+ * With a `signer`, the transaction is prepared with `prepareSponsoredTransaction`, built and
95
+ * signed here. With a `signature`, the bytes are sent as they are.
96
+ *
97
+ * Enoki errors are thrown as `EnokiClientError`. If `isStaleTransactionError(error)`, build a new
98
+ * transaction, sign it and call this again; the sponsor address is fetched again.
99
+ */
100
+ sponsorAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(options: EnokiSponsorAndExecuteTransactionOptions<Include>): Promise<SuiClientTypes.TransactionResult<Include>>;
101
+ /**
102
+ * A signer that makes Enoki the sponsor in the sponsor SDK's `createSponsor`. Create the sponsor
103
+ * per request. Enoki's `invalid_transaction` is returned as `Rejected`.
104
+ */
105
+ getSponsorSigner({
106
+ allowedAddresses,
107
+ allowedMoveCallTargets
108
+ }?: {
109
+ allowedAddresses?: string[];
110
+ allowedMoveCallTargets?: string[];
111
+ }): Promise<EnokiSponsorSigner>;
112
+ }
113
+ //#endregion
114
+ export { EnokiClientExtension, EnokiExtensionOptions, EnokiPrepareSponsoredTransactionOptions, EnokiSponsorAndExecuteTransactionOptions, EnokiSponsorSigner, enoki };
115
+ //# sourceMappingURL=extension.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.mts","names":[],"sources":["../src/extension.ts"],"mappings":";;;;;;KAYY,qBAAA,kCAAuD,IAAA,CAClE,iBAAA;EAGA,IAAA,GAAO,IAAA;AAAA;AAAA,UAGE,iCAAA,iBAAkD,cAAA,CAAe,kBAAA,UAClE,cAAA,CAAe,uBAAA;EAPvB;EASA,gBAAA;EANO;EAQP,sBAAA;EACA,OAAA,GAAU,OAAA,GAAU,cAAA,CAAe,kBAAA;AAAA;AAAA,KAGxB,wCAAA,iBACK,cAAA,CAAe,kBAAA,SAC5B,iCAAA,CAAkC,OAAA;EAjBrC,+FAqBG,WAAA,EAAa,WAAA,EAlBT;EAoBJ,MAAA,EAAQ,MAAA;EACR,SAAA;AAAA;EAlBuC;;;;EAyBvC,WAAA,EAAa,UAAA,WAxBR;EA0BL,SAAA;EACA,MAAA;AAAA;AAAA,UAIa,uCAAA;EAhC0D;EAkC1E,WAAA,EAAa,WAAA;AAAA;;UAIG,kBAAA;EAChB,YAAA;EACA,yBAAA,CAA0B,OAAA;IACzB,WAAA,EAAa,UAAA;IACb,oBAAA;IACA,MAAA,GAAS,WAAA;EAAA,IACN,OAAA;IAED,KAAA;IACA,MAAA,EAAQ,KAAA;IACR,YAAA,EAAc,KAAA;IACd,cAAA,EAAgB,KAAA;IAChB,MAAA;EAAA,IAEA,cAAA,CAAe,iBAAA;IAAoB,OAAA;EAAA;AAAA;AAAA,KAIlC,KAAA;EAAU,IAAA;EAAe,OAAA;AAAA;;;;;;;;;;;;;;iBAed,KAAA,qCAAA,CAAA;EACf,IAAA;EAAA,GACG;AAAA,GACD,qBAAA,CAAsB,IAAA;;qBAGJ,iBAAA,KAAiB,oBAAA;AAAA;AAAA,cAKzB,oBAAA;EAAA;;IAIE,MAAA;IAAQ;EAAA;IAAW,MAAA,EAAQ,iBAAA;IAAmB,KAAA,EAAO,WAAA;EAAA;EA3CzD;EAiDV,iBAAA,CAAA,GAAqB,OAAA;EA5CJ;EAiDjB,2BAAA,CAAA;IACC;EAAA,GACE,uCAAA,GAA0C,OAAA,CAAQ,WAAA;EA/ClD;;;;;;;;;;EA6DG,4BAAA,iBAA6C,cAAA,CAAe,kBAAA,MAAA,CACjE,OAAA,EAAS,wCAAA,CAAyC,OAAA,IAChD,OAAA,CAAQ,cAAA,CAAe,iBAAA,CAAkB,OAAA;EA3ElB;;;;EAsHpB,gBAAA,CAAA;IACL,gBAAA;IACA;EAAA;IAEA,gBAAA;IACA,sBAAA;EAAA,IACQ,OAAA,CAAQ,kBAAA;AAAA"}
@@ -0,0 +1,134 @@
1
+ import { EnokiClient, EnokiClientError } from "./EnokiClient/index.mjs";
2
+ import { fromBase64, toBase64 } from "@mysten/sui/utils";
3
+ import { TransactionDataBuilder } from "@mysten/sui/transactions";
4
+
5
+ //#region src/extension.ts
6
+ /**
7
+ * Adds Enoki sponsorship to a Sui client. Requires a private API key with sponsored transactions
8
+ * enabled.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const client = new SuiGrpcClient({ network: 'mainnet', baseUrl }).$extend(
13
+ * enoki({ apiKey: process.env.ENOKI_PRIVATE_KEY! }),
14
+ * );
15
+ *
16
+ * const result = await client.enoki.sponsorAndExecuteTransaction({ transaction, signer });
17
+ * ```
18
+ */
19
+ function enoki({ name = "enoki", ...config }) {
20
+ return {
21
+ name,
22
+ register: (client) => new EnokiClientExtension({
23
+ client,
24
+ enoki: new EnokiClient(config)
25
+ })
26
+ };
27
+ }
28
+ var EnokiClientExtension = class {
29
+ #client;
30
+ #enoki;
31
+ constructor({ client, enoki: enoki$1 }) {
32
+ this.#client = client;
33
+ this.#enoki = enoki$1;
34
+ }
35
+ /** Enoki's sponsor address on the client's network. */
36
+ getSponsorAddress() {
37
+ return this.#enoki.getSponsorAddress({ network: this.#network() });
38
+ }
39
+ /** Sets Enoki as gas owner with an empty gas payment, without building. */
40
+ prepareSponsoredTransaction({ transaction }) {
41
+ return this.#enoki.prepareSponsoredTransaction({
42
+ transaction,
43
+ network: this.#network()
44
+ });
45
+ }
46
+ /**
47
+ * Has Enoki sponsor and execute a transaction, and waits for it. Returns the same result as
48
+ * `client.core.signAndExecuteTransaction`.
49
+ *
50
+ * With a `signer`, the transaction is prepared with `prepareSponsoredTransaction`, built and
51
+ * signed here. With a `signature`, the bytes are sent as they are.
52
+ *
53
+ * Enoki errors are thrown as `EnokiClientError`. If `isStaleTransactionError(error)`, build a new
54
+ * transaction, sign it and call this again; the sponsor address is fetched again.
55
+ */
56
+ async sponsorAndExecuteTransaction(options) {
57
+ const network = this.#network();
58
+ let bytes;
59
+ let signature;
60
+ if (options.signer) {
61
+ const { transaction, signer } = options;
62
+ transaction.setSenderIfNotSet(signer.toSuiAddress());
63
+ await this.prepareSponsoredTransaction({ transaction });
64
+ bytes = await transaction.build({ client: this.#client });
65
+ ({signature} = await signer.signTransaction(bytes));
66
+ } else {
67
+ bytes = options.transaction;
68
+ signature = options.signature;
69
+ }
70
+ const transactionBytes = typeof bytes === "string" ? fromBase64(bytes) : bytes;
71
+ const digest = TransactionDataBuilder.getDigestFromBytes(transactionBytes);
72
+ options.signal?.throwIfAborted();
73
+ const response = await this.#enoki.sponsorAndExecuteTransaction({
74
+ network,
75
+ transactionBytes: toBase64(transactionBytes),
76
+ signature,
77
+ allowedAddresses: options.allowedAddresses,
78
+ allowedMoveCallTargets: options.allowedMoveCallTargets
79
+ });
80
+ if (response.digest !== digest) throw new Error(`Enoki returned digest ${response.digest}, but the transaction is ${digest}`);
81
+ return this.#client.core.waitForTransaction({
82
+ digest,
83
+ include: options.include,
84
+ signal: options.signal
85
+ });
86
+ }
87
+ /**
88
+ * A signer that makes Enoki the sponsor in the sponsor SDK's `createSponsor`. Create the sponsor
89
+ * per request. Enoki's `invalid_transaction` is returned as `Rejected`.
90
+ */
91
+ async getSponsorSigner({ allowedAddresses, allowedMoveCallTargets } = {}) {
92
+ const address = await this.getSponsorAddress();
93
+ return {
94
+ toSuiAddress: () => address,
95
+ signAndExecuteTransaction: async ({ transaction, additionalSignatures, signal }) => {
96
+ if (additionalSignatures.length !== 1) throw new Error("Enoki sponsorship takes exactly one user signature.");
97
+ try {
98
+ return await this.sponsorAndExecuteTransaction({
99
+ transaction,
100
+ signature: additionalSignatures[0],
101
+ include: { effects: true },
102
+ signal,
103
+ allowedAddresses,
104
+ allowedMoveCallTargets
105
+ });
106
+ } catch (error) {
107
+ if (error instanceof EnokiClientError && error.code === "invalid_transaction") {
108
+ const issues = error.errors.map(({ code, message }) => ({
109
+ code,
110
+ message
111
+ }));
112
+ return {
113
+ $kind: "Rejected",
114
+ issues,
115
+ policyIssues: issues,
116
+ analysisIssues: [],
117
+ reason: "POLICY_REJECTED"
118
+ };
119
+ }
120
+ throw error;
121
+ }
122
+ }
123
+ };
124
+ }
125
+ #network() {
126
+ const network = this.#client.network;
127
+ if (network === "mainnet" || network === "testnet") return network;
128
+ throw new Error(`Enoki sponsorship is not available on ${network}`);
129
+ }
130
+ };
131
+
132
+ //#endregion
133
+ export { EnokiClientExtension, enoki };
134
+ //# sourceMappingURL=extension.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.mjs","names":["#client","#enoki","enoki","#network"],"sources":["../src/extension.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport { TransactionDataBuilder, type Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\n\nimport type { EnokiClientConfig } from './EnokiClient/index.js';\nimport { EnokiClient, EnokiClientError } from './EnokiClient/index.js';\nimport type { EnokiDomainNetwork } from './EnokiClient/type.js';\n\nexport type EnokiExtensionOptions<Name extends string = 'enoki'> = Omit<\n\tEnokiClientConfig,\n\t'additionalEpochs'\n> & {\n\tname?: Name;\n};\n\ninterface EnokiSponsorAndExecuteBaseOptions<Include extends SuiClientTypes.TransactionInclude>\n\textends SuiClientTypes.CoreClientMethodOptions {\n\t/** Addresses the transaction may use, in addition to the app's allowlist in the Enoki Portal. */\n\tallowedAddresses?: string[];\n\t/** Move call targets the transaction may call, in addition to the app's allowlist in the Enoki Portal. */\n\tallowedMoveCallTargets?: string[];\n\tinclude?: Include & SuiClientTypes.TransactionInclude;\n}\n\nexport type EnokiSponsorAndExecuteTransactionOptions<\n\tInclude extends SuiClientTypes.TransactionInclude = {},\n> = EnokiSponsorAndExecuteBaseOptions<Include> &\n\t(\n\t\t| {\n\t\t\t\t/** The transaction to send. Enoki is set as gas owner, and the sender defaults to `signer`. */\n\t\t\t\ttransaction: Transaction;\n\t\t\t\t/** Signs as the transaction sender. */\n\t\t\t\tsigner: Signer;\n\t\t\t\tsignature?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Built transaction bytes (or base64) of a transaction prepared with\n\t\t\t\t * `prepareSponsoredTransaction`.\n\t\t\t\t */\n\t\t\t\ttransaction: Uint8Array | string;\n\t\t\t\t/** The sender's signature over the bytes. */\n\t\t\t\tsignature: string;\n\t\t\t\tsigner?: never;\n\t\t }\n\t);\n\nexport interface EnokiPrepareSponsoredTransactionOptions {\n\t/** The transaction to prepare. Enoki is set as gas owner, paying from its address balance. */\n\ttransaction: Transaction;\n}\n\n/** A sponsor SDK `RemoteSigner` backed by Enoki: pass it as `createSponsor`'s `signer`. */\nexport interface EnokiSponsorSigner {\n\ttoSuiAddress(): string;\n\tsignAndExecuteTransaction(options: {\n\t\ttransaction: Uint8Array;\n\t\tadditionalSignatures: string[];\n\t\tsignal?: AbortSignal;\n\t}): Promise<\n\t\t| {\n\t\t\t\t$kind: 'Rejected';\n\t\t\t\tissues: Issue[];\n\t\t\t\tpolicyIssues: Issue[];\n\t\t\t\tanalysisIssues: Issue[];\n\t\t\t\treason: 'POLICY_REJECTED';\n\t\t }\n\t\t| SuiClientTypes.TransactionResult<{ effects: true }>\n\t>;\n}\n\ntype Issue = { code?: string; message: string };\n\n/**\n * Adds Enoki sponsorship to a Sui client. Requires a private API key with sponsored transactions\n * enabled.\n *\n * @example\n * ```ts\n * const client = new SuiGrpcClient({ network: 'mainnet', baseUrl }).$extend(\n * enoki({ apiKey: process.env.ENOKI_PRIVATE_KEY! }),\n * );\n *\n * const result = await client.enoki.sponsorAndExecuteTransaction({ transaction, signer });\n * ```\n */\nexport function enoki<const Name extends string = 'enoki'>({\n\tname = 'enoki' as Name,\n\t...config\n}: EnokiExtensionOptions<Name>) {\n\treturn {\n\t\tname,\n\t\tregister: (client: ClientWithCoreApi) =>\n\t\t\tnew EnokiClientExtension({ client, enoki: new EnokiClient(config) }),\n\t};\n}\n\nexport class EnokiClientExtension {\n\t#client: ClientWithCoreApi;\n\t#enoki: EnokiClient;\n\n\tconstructor({ client, enoki }: { client: ClientWithCoreApi; enoki: EnokiClient }) {\n\t\tthis.#client = client;\n\t\tthis.#enoki = enoki;\n\t}\n\n\t/** Enoki's sponsor address on the client's network. */\n\tgetSponsorAddress(): Promise<string> {\n\t\treturn this.#enoki.getSponsorAddress({ network: this.#network() });\n\t}\n\n\t/** Sets Enoki as gas owner with an empty gas payment, without building. */\n\tprepareSponsoredTransaction({\n\t\ttransaction,\n\t}: EnokiPrepareSponsoredTransactionOptions): Promise<Transaction> {\n\t\treturn this.#enoki.prepareSponsoredTransaction({ transaction, network: this.#network() });\n\t}\n\n\t/**\n\t * Has Enoki sponsor and execute a transaction, and waits for it. Returns the same result as\n\t * `client.core.signAndExecuteTransaction`.\n\t *\n\t * With a `signer`, the transaction is prepared with `prepareSponsoredTransaction`, built and\n\t * signed here. With a `signature`, the bytes are sent as they are.\n\t *\n\t * Enoki errors are thrown as `EnokiClientError`. If `isStaleTransactionError(error)`, build a new\n\t * transaction, sign it and call this again; the sponsor address is fetched again.\n\t */\n\tasync sponsorAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: EnokiSponsorAndExecuteTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>> {\n\t\tconst network = this.#network();\n\n\t\tlet bytes: Uint8Array | string;\n\t\tlet signature: string;\n\t\tif (options.signer) {\n\t\t\tconst { transaction, signer } = options;\n\t\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\t\tawait this.prepareSponsoredTransaction({ transaction });\n\t\t\tbytes = await transaction.build({ client: this.#client });\n\t\t\t({ signature } = await signer.signTransaction(bytes));\n\t\t} else {\n\t\t\tbytes = options.transaction;\n\t\t\tsignature = options.signature;\n\t\t}\n\n\t\tconst transactionBytes = typeof bytes === 'string' ? fromBase64(bytes) : bytes;\n\t\t// Wait on the digest of the bytes that were signed, not one reported by the server.\n\t\tconst digest = TransactionDataBuilder.getDigestFromBytes(transactionBytes);\n\n\t\toptions.signal?.throwIfAborted();\n\t\tconst response = await this.#enoki.sponsorAndExecuteTransaction({\n\t\t\tnetwork,\n\t\t\ttransactionBytes: toBase64(transactionBytes),\n\t\t\tsignature,\n\t\t\tallowedAddresses: options.allowedAddresses,\n\t\t\tallowedMoveCallTargets: options.allowedMoveCallTargets,\n\t\t});\n\t\tif (response.digest !== digest) {\n\t\t\tthrow new Error(`Enoki returned digest ${response.digest}, but the transaction is ${digest}`);\n\t\t}\n\n\t\treturn this.#client.core.waitForTransaction({\n\t\t\tdigest,\n\t\t\tinclude: options.include,\n\t\t\tsignal: options.signal,\n\t\t});\n\t}\n\n\t/**\n\t * A signer that makes Enoki the sponsor in the sponsor SDK's `createSponsor`. Create the sponsor\n\t * per request. Enoki's `invalid_transaction` is returned as `Rejected`.\n\t */\n\tasync getSponsorSigner({\n\t\tallowedAddresses,\n\t\tallowedMoveCallTargets,\n\t}: {\n\t\tallowedAddresses?: string[];\n\t\tallowedMoveCallTargets?: string[];\n\t} = {}): Promise<EnokiSponsorSigner> {\n\t\tconst address = await this.getSponsorAddress();\n\t\treturn {\n\t\t\ttoSuiAddress: () => address,\n\t\t\tsignAndExecuteTransaction: async ({ transaction, additionalSignatures, signal }) => {\n\t\t\t\tif (additionalSignatures.length !== 1) {\n\t\t\t\t\tthrow new Error('Enoki sponsorship takes exactly one user signature.');\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn await this.sponsorAndExecuteTransaction({\n\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\tsignature: additionalSignatures[0],\n\t\t\t\t\t\tinclude: { effects: true },\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tallowedAddresses,\n\t\t\t\t\t\tallowedMoveCallTargets,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof EnokiClientError && error.code === 'invalid_transaction') {\n\t\t\t\t\t\tconst issues = error.errors.map(({ code, message }) => ({ code, message }));\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t$kind: 'Rejected',\n\t\t\t\t\t\t\tissues,\n\t\t\t\t\t\t\tpolicyIssues: issues,\n\t\t\t\t\t\t\tanalysisIssues: [],\n\t\t\t\t\t\t\treason: 'POLICY_REJECTED',\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t#network(): EnokiDomainNetwork {\n\t\tconst network: string = this.#client.network;\n\t\tif (network === 'mainnet' || network === 'testnet') {\n\t\t\treturn network;\n\t\t}\n\t\tthrow new Error(`Enoki sponsorship is not available on ${network}`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0FA,SAAgB,MA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BAAmB;GAC3C;GACA,SAAS,QAAQ;GACjB,QAAQ,QAAQ;GAChB,CAAC;;;;;;CAOH,MAAM,iBAAiB,EACtB,kBACA,2BAIG,EAAE,EAA+B;EACpC,MAAM,UAAU,MAAM,KAAK,mBAAmB;AAC9C,SAAO;GACN,oBAAoB;GACpB,2BAA2B,OAAO,EAAE,aAAa,sBAAsB,aAAa;AACnF,QAAI,qBAAqB,WAAW,EACnC,OAAM,IAAI,MAAM,sDAAsD;AAEvE,QAAI;AACH,YAAO,MAAM,KAAK,6BAA6B;MAC9C;MACA,WAAW,qBAAqB;MAChC,SAAS,EAAE,SAAS,MAAM;MAC1B;MACA;MACA;MACA,CAAC;aACM,OAAO;AACf,SAAI,iBAAiB,oBAAoB,MAAM,SAAS,uBAAuB;MAC9E,MAAM,SAAS,MAAM,OAAO,KAAK,EAAE,MAAM,eAAe;OAAE;OAAM;OAAS,EAAE;AAC3E,aAAO;OACN,OAAO;OACP;OACA,cAAc;OACd,gBAAgB,EAAE;OAClB,QAAQ;OACR;;AAEF,WAAM;;;GAGR;;CAGF,WAA+B;EAC9B,MAAM,UAAkB,MAAKA,OAAQ;AACrC,MAAI,YAAY,aAAa,YAAY,UACxC,QAAO;AAER,QAAM,IAAI,MAAM,yCAAyC,UAAU"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AuthProvider, EnokiNetwork } from "./EnokiClient/type.mjs";
2
- import { EnokiClient, EnokiClientConfig, EnokiClientError } from "./EnokiClient/index.mjs";
2
+ import { EnokiClient, EnokiClientConfig, EnokiClientError, isStaleTransactionError } from "./EnokiClient/index.mjs";
3
+ import { EnokiClientExtension, EnokiExtensionOptions, EnokiPrepareSponsoredTransactionOptions, EnokiSponsorAndExecuteTransactionOptions, EnokiSponsorSigner, enoki } from "./extension.mjs";
3
4
  import "./client.mjs";
4
5
  import { Encryption, createDefaultEncryption } from "./encryption.mjs";
5
6
  import { EnokiKeypair, EnokiPublicKey } from "./EnokiKeypair.mjs";
@@ -11,4 +12,4 @@ import { registerEnokiWallets } from "./wallet/register.mjs";
11
12
  import { enokiWalletsInitializer } from "./wallet/initializer.mjs";
12
13
  import { getSession, getWalletMetadata, isEnokiWallet, isFacebookWallet, isGoogleWallet, isTwitchWallet } from "./wallet/utils.mjs";
13
14
  import { isEnokiNetwork } from "./utils.mjs";
14
- export { AuthProvider, type Encryption, EnokiClient, EnokiClientConfig, EnokiClientError, EnokiFlow, type EnokiFlowConfig, EnokiKeypair, EnokiNetwork, EnokiPublicKey, type EnokiWallet, type RegisterEnokiWalletsOptions, type SyncStore, createDefaultEncryption, createInMemoryStorage, createLocalStorage, createSessionStorage, enokiWalletsInitializer, getSession, getWalletMetadata, isEnokiNetwork, isEnokiWallet, isFacebookWallet, isGoogleWallet, isTwitchWallet, registerEnokiWallets };
15
+ export { AuthProvider, type Encryption, EnokiClient, EnokiClientConfig, EnokiClientError, EnokiClientExtension, EnokiExtensionOptions, EnokiFlow, type EnokiFlowConfig, EnokiKeypair, EnokiNetwork, EnokiPrepareSponsoredTransactionOptions, EnokiPublicKey, EnokiSponsorAndExecuteTransactionOptions, EnokiSponsorSigner, type EnokiWallet, type RegisterEnokiWalletsOptions, type SyncStore, createDefaultEncryption, createInMemoryStorage, createLocalStorage, createSessionStorage, enoki, enokiWalletsInitializer, getSession, getWalletMetadata, isEnokiNetwork, isEnokiWallet, isFacebookWallet, isGoogleWallet, isStaleTransactionError, isTwitchWallet, registerEnokiWallets };
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { EnokiClient, EnokiClientError } from "./EnokiClient/index.mjs";
1
+ import { EnokiClient, EnokiClientError, isStaleTransactionError } from "./EnokiClient/index.mjs";
2
+ import { EnokiClientExtension, enoki } from "./extension.mjs";
3
+ import "./client.mjs";
2
4
  import { createDefaultEncryption } from "./encryption.mjs";
3
5
  import { EnokiKeypair, EnokiPublicKey } from "./EnokiKeypair.mjs";
4
6
  import { createInMemoryStorage, createLocalStorage, createSessionStorage } from "./stores.mjs";
@@ -8,4 +10,4 @@ import { registerEnokiWallets } from "./wallet/register.mjs";
8
10
  import { enokiWalletsInitializer } from "./wallet/initializer.mjs";
9
11
  import { getSession, getWalletMetadata, isEnokiWallet, isFacebookWallet, isGoogleWallet, isTwitchWallet } from "./wallet/utils.mjs";
10
12
 
11
- export { EnokiClient, EnokiClientError, EnokiFlow, EnokiKeypair, EnokiPublicKey, createDefaultEncryption, createInMemoryStorage, createLocalStorage, createSessionStorage, enokiWalletsInitializer, getSession, getWalletMetadata, isEnokiNetwork, isEnokiWallet, isFacebookWallet, isGoogleWallet, isTwitchWallet, registerEnokiWallets };
13
+ export { EnokiClient, EnokiClientError, EnokiClientExtension, EnokiFlow, EnokiKeypair, EnokiPublicKey, createDefaultEncryption, createInMemoryStorage, createLocalStorage, createSessionStorage, enoki, enokiWalletsInitializer, getSession, getWalletMetadata, isEnokiNetwork, isEnokiWallet, isFacebookWallet, isGoogleWallet, isStaleTransactionError, isTwitchWallet, registerEnokiWallets };
@@ -2,11 +2,11 @@ import { EnokiClient } from "../EnokiClient/index.mjs";
2
2
  import { EnokiKeypair } from "../EnokiKeypair.mjs";
3
3
  import { EnokiGetMetadata, EnokiGetSession } from "./features.mjs";
4
4
  import { EnokiWalletState } from "./state.mjs";
5
- import { WebCryptoSigner } from "@mysten/webcrypto-signer";
6
5
  import { fromBase64, toBase64 } from "@mysten/sui/utils";
6
+ import { Transaction } from "@mysten/sui/transactions";
7
+ import { WebCryptoSigner } from "@mysten/webcrypto-signer";
7
8
  import { decodeJwt } from "@mysten/sui/zklogin";
8
9
  import { get, set } from "idb-keyval";
9
- import { Transaction } from "@mysten/sui/transactions";
10
10
  import { ReadonlyWalletAccount, StandardConnect, StandardDisconnect, StandardEvents, SuiSignAndExecuteTransaction, SuiSignPersonalMessage, SuiSignTransaction } from "@mysten/wallet-standard";
11
11
  import { mitt } from "@mysten/utils";
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten/enoki",
3
- "version": "1.3.4",
3
+ "version": "1.5.0",
4
4
  "description": "zkLogin authentication and sponsored transactions",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mysten Labs <build@mystenlabs.com>",
@@ -50,8 +50,8 @@
50
50
  "@wallet-standard/ui": "^1.0.3",
51
51
  "idb-keyval": "^6.3.0",
52
52
  "nanostores": "^1.4.2",
53
- "@mysten/utils": "^0.4.2",
54
53
  "@mysten/wallet-standard": "^0.21.38",
54
+ "@mysten/utils": "^0.4.2",
55
55
  "@mysten/webcrypto-signer": "^0.2.38"
56
56
  },
57
57
  "peerDependencies": {