@haneullabs/enoki 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +1109 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/EnokiClient/index.d.ts +36 -0
  4. package/dist/cjs/EnokiClient/index.js +196 -0
  5. package/dist/cjs/EnokiClient/index.js.map +7 -0
  6. package/dist/cjs/EnokiClient/type.d.ts +119 -0
  7. package/dist/cjs/EnokiClient/type.js +17 -0
  8. package/dist/cjs/EnokiClient/type.js.map +7 -0
  9. package/dist/cjs/EnokiFlow.d.ts +74 -0
  10. package/dist/cjs/EnokiFlow.js +279 -0
  11. package/dist/cjs/EnokiFlow.js.map +7 -0
  12. package/dist/cjs/EnokiKeypair.d.ts +20 -0
  13. package/dist/cjs/EnokiKeypair.js +87 -0
  14. package/dist/cjs/EnokiKeypair.js.map +7 -0
  15. package/dist/cjs/encryption.d.ts +15 -0
  16. package/dist/cjs/encryption.js +96 -0
  17. package/dist/cjs/encryption.js.map +7 -0
  18. package/dist/cjs/index.d.ts +12 -0
  19. package/dist/cjs/index.js +50 -0
  20. package/dist/cjs/index.js.map +7 -0
  21. package/dist/cjs/package.json +4 -0
  22. package/dist/cjs/react.d.ts +20 -0
  23. package/dist/cjs/react.js +76 -0
  24. package/dist/cjs/react.js.map +7 -0
  25. package/dist/cjs/stores.d.ts +21 -0
  26. package/dist/cjs/stores.js +67 -0
  27. package/dist/cjs/stores.js.map +7 -0
  28. package/dist/cjs/utils.d.ts +2 -0
  29. package/dist/cjs/utils.js +27 -0
  30. package/dist/cjs/utils.js.map +7 -0
  31. package/dist/cjs/wallet/features.d.ts +50 -0
  32. package/dist/cjs/wallet/features.js +27 -0
  33. package/dist/cjs/wallet/features.js.map +7 -0
  34. package/dist/cjs/wallet/initializer.d.ts +11 -0
  35. package/dist/cjs/wallet/initializer.js +41 -0
  36. package/dist/cjs/wallet/initializer.js.map +7 -0
  37. package/dist/cjs/wallet/providers.d.ts +7 -0
  38. package/dist/cjs/wallet/providers.js +51 -0
  39. package/dist/cjs/wallet/providers.js.map +7 -0
  40. package/dist/cjs/wallet/register.d.ts +7 -0
  41. package/dist/cjs/wallet/register.js +68 -0
  42. package/dist/cjs/wallet/register.js.map +7 -0
  43. package/dist/cjs/wallet/state.d.ts +18 -0
  44. package/dist/cjs/wallet/state.js +142 -0
  45. package/dist/cjs/wallet/state.js.map +7 -0
  46. package/dist/cjs/wallet/types.d.ts +82 -0
  47. package/dist/cjs/wallet/types.js +17 -0
  48. package/dist/cjs/wallet/types.js.map +7 -0
  49. package/dist/cjs/wallet/utils.d.ts +11 -0
  50. package/dist/cjs/wallet/utils.js +83 -0
  51. package/dist/cjs/wallet/utils.js.map +7 -0
  52. package/dist/cjs/wallet/wallet.d.ts +16 -0
  53. package/dist/cjs/wallet/wallet.js +466 -0
  54. package/dist/cjs/wallet/wallet.js.map +7 -0
  55. package/dist/esm/EnokiClient/index.d.ts +36 -0
  56. package/dist/esm/EnokiClient/index.js +176 -0
  57. package/dist/esm/EnokiClient/index.js.map +7 -0
  58. package/dist/esm/EnokiClient/type.d.ts +119 -0
  59. package/dist/esm/EnokiClient/type.js +1 -0
  60. package/dist/esm/EnokiClient/type.js.map +7 -0
  61. package/dist/esm/EnokiFlow.d.ts +74 -0
  62. package/dist/esm/EnokiFlow.js +259 -0
  63. package/dist/esm/EnokiFlow.js.map +7 -0
  64. package/dist/esm/EnokiKeypair.d.ts +20 -0
  65. package/dist/esm/EnokiKeypair.js +67 -0
  66. package/dist/esm/EnokiKeypair.js.map +7 -0
  67. package/dist/esm/encryption.d.ts +15 -0
  68. package/dist/esm/encryption.js +76 -0
  69. package/dist/esm/encryption.js.map +7 -0
  70. package/dist/esm/index.d.ts +12 -0
  71. package/dist/esm/index.js +41 -0
  72. package/dist/esm/index.js.map +7 -0
  73. package/dist/esm/package.json +4 -0
  74. package/dist/esm/react.d.ts +20 -0
  75. package/dist/esm/react.js +56 -0
  76. package/dist/esm/react.js.map +7 -0
  77. package/dist/esm/stores.d.ts +21 -0
  78. package/dist/esm/stores.js +47 -0
  79. package/dist/esm/stores.js.map +7 -0
  80. package/dist/esm/utils.d.ts +2 -0
  81. package/dist/esm/utils.js +7 -0
  82. package/dist/esm/utils.js.map +7 -0
  83. package/dist/esm/wallet/features.d.ts +50 -0
  84. package/dist/esm/wallet/features.js +7 -0
  85. package/dist/esm/wallet/features.js.map +7 -0
  86. package/dist/esm/wallet/initializer.d.ts +11 -0
  87. package/dist/esm/wallet/initializer.js +21 -0
  88. package/dist/esm/wallet/initializer.js.map +7 -0
  89. package/dist/esm/wallet/providers.d.ts +7 -0
  90. package/dist/esm/wallet/providers.js +31 -0
  91. package/dist/esm/wallet/providers.js.map +7 -0
  92. package/dist/esm/wallet/register.d.ts +7 -0
  93. package/dist/esm/wallet/register.js +48 -0
  94. package/dist/esm/wallet/register.js.map +7 -0
  95. package/dist/esm/wallet/state.d.ts +18 -0
  96. package/dist/esm/wallet/state.js +122 -0
  97. package/dist/esm/wallet/state.js.map +7 -0
  98. package/dist/esm/wallet/types.d.ts +82 -0
  99. package/dist/esm/wallet/types.js +1 -0
  100. package/dist/esm/wallet/types.js.map +7 -0
  101. package/dist/esm/wallet/utils.d.ts +11 -0
  102. package/dist/esm/wallet/utils.js +63 -0
  103. package/dist/esm/wallet/utils.js.map +7 -0
  104. package/dist/esm/wallet/wallet.d.ts +16 -0
  105. package/dist/esm/wallet/wallet.js +444 -0
  106. package/dist/esm/wallet/wallet.js.map +7 -0
  107. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  108. package/dist/tsconfig.tsbuildinfo +1 -0
  109. package/package.json +80 -0
  110. package/react/package.json +5 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # `@haneullabs/enoki`
@@ -0,0 +1,36 @@
1
+ import type { CreateSponsoredTransactionApiInput, CreateSponsoredTransactionApiResponse, CreateSubnameApiInput, CreateSubnameApiResponse, CreateZkLoginNonceApiInput, CreateZkLoginNonceApiResponse, CreateZkLoginZkpApiInput, CreateZkLoginZkpApiResponse, DeleteSubnameApiInput, ExecuteSponsoredTransactionApiInput, ExecuteSponsoredTransactionApiResponse, GetAppApiInput, GetAppApiResponse, GetSubnamesApiInput, GetSubnamesApiResponse, GetZkLoginAddressesApiInput, GetZkLoginAddressesApiResponse, GetZkLoginApiInput, GetZkLoginApiResponse } from './type.js';
2
+ export interface EnokiClientConfig {
3
+ /** The API key for the Enoki app, available in the Enoki Portal. */
4
+ apiKey: string;
5
+ /** The API URL for Enoki. In most cases, this should not be set. */
6
+ apiUrl?: string;
7
+ /** The amount of epochs that you would like to have the nonce be valid for. Range: `0 <= value <= 30` */
8
+ additionalEpochs?: number;
9
+ }
10
+ export declare class EnokiClientError extends Error {
11
+ errors: {
12
+ code: string;
13
+ message: string;
14
+ data: unknown;
15
+ }[];
16
+ status: number;
17
+ code: string;
18
+ constructor(status: number, response: string);
19
+ }
20
+ /**
21
+ * A low-level client for interacting with the Enoki API.
22
+ */
23
+ export declare class EnokiClient {
24
+ #private;
25
+ constructor(config: EnokiClientConfig);
26
+ getApp(_input?: GetAppApiInput): Promise<GetAppApiResponse>;
27
+ getZkLogin(input: GetZkLoginApiInput): Promise<GetZkLoginApiResponse>;
28
+ getZkLoginAddresses(input: GetZkLoginAddressesApiInput): Promise<GetZkLoginAddressesApiResponse>;
29
+ createZkLoginNonce(input: CreateZkLoginNonceApiInput): Promise<CreateZkLoginNonceApiResponse>;
30
+ createZkLoginZkp(input: CreateZkLoginZkpApiInput): Promise<CreateZkLoginZkpApiResponse>;
31
+ createSponsoredTransaction(input: CreateSponsoredTransactionApiInput): Promise<CreateSponsoredTransactionApiResponse>;
32
+ executeSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput): Promise<ExecuteSponsoredTransactionApiResponse>;
33
+ getSubnames(input: GetSubnamesApiInput): Promise<GetSubnamesApiResponse>;
34
+ createSubname(input: CreateSubnameApiInput): Promise<CreateSubnameApiResponse>;
35
+ deleteSubname(input: DeleteSubnameApiInput): void;
36
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+ var EnokiClient_exports = {};
28
+ __export(EnokiClient_exports, {
29
+ EnokiClient: () => EnokiClient,
30
+ EnokiClientError: () => EnokiClientError
31
+ });
32
+ module.exports = __toCommonJS(EnokiClient_exports);
33
+ var _version, _apiUrl, _apiKey, _additionalEpochs, _EnokiClient_instances, fetch_fn;
34
+ const DEFAULT_API_URL = "https://api.enoki.haneullabs.com";
35
+ const ZKLOGIN_HEADER = "zklogin-jwt";
36
+ class EnokiClientError extends Error {
37
+ constructor(status, response) {
38
+ let errors;
39
+ try {
40
+ const parsedResponse = JSON.parse(response);
41
+ errors = parsedResponse.errors;
42
+ } catch {
43
+ }
44
+ const cause = errors?.[0] ? new Error(errors[0].message) : void 0;
45
+ super(`Request to Enoki API failed (status: ${status})`, {
46
+ cause
47
+ });
48
+ this.errors = [];
49
+ this.errors = errors ?? [];
50
+ this.name = "EnokiClientError";
51
+ this.status = status;
52
+ this.code = errors?.[0]?.code ?? "unknown_error";
53
+ }
54
+ }
55
+ class EnokiClient {
56
+ constructor(config) {
57
+ __privateAdd(this, _EnokiClient_instances);
58
+ __privateAdd(this, _version);
59
+ __privateAdd(this, _apiUrl);
60
+ __privateAdd(this, _apiKey);
61
+ __privateAdd(this, _additionalEpochs);
62
+ __privateSet(this, _version, "v1");
63
+ __privateSet(this, _apiUrl, config.apiUrl ?? DEFAULT_API_URL);
64
+ __privateSet(this, _apiKey, config.apiKey);
65
+ __privateSet(this, _additionalEpochs, config.additionalEpochs);
66
+ }
67
+ getApp(_input) {
68
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "app", {
69
+ method: "GET"
70
+ });
71
+ }
72
+ getZkLogin(input) {
73
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin", {
74
+ method: "GET",
75
+ headers: {
76
+ [ZKLOGIN_HEADER]: input.jwt
77
+ }
78
+ });
79
+ }
80
+ getZkLoginAddresses(input) {
81
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/addresses", {
82
+ method: "GET",
83
+ headers: {
84
+ [ZKLOGIN_HEADER]: input.jwt
85
+ }
86
+ });
87
+ }
88
+ createZkLoginNonce(input) {
89
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/nonce", {
90
+ method: "POST",
91
+ body: JSON.stringify({
92
+ network: input.network,
93
+ ephemeralPublicKey: input.ephemeralPublicKey.toHaneulPublicKey(),
94
+ additionalEpochs: input.additionalEpochs ?? __privateGet(this, _additionalEpochs)
95
+ })
96
+ });
97
+ }
98
+ createZkLoginZkp(input) {
99
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/zkp", {
100
+ method: "POST",
101
+ headers: {
102
+ [ZKLOGIN_HEADER]: input.jwt
103
+ },
104
+ body: JSON.stringify({
105
+ network: input.network,
106
+ ephemeralPublicKey: input.ephemeralPublicKey.toHaneulPublicKey(),
107
+ maxEpoch: input.maxEpoch,
108
+ randomness: input.randomness
109
+ })
110
+ });
111
+ }
112
+ createSponsoredTransaction(input) {
113
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "transaction-blocks/sponsor", {
114
+ method: "POST",
115
+ headers: input.jwt ? {
116
+ [ZKLOGIN_HEADER]: input.jwt
117
+ } : {},
118
+ body: JSON.stringify({
119
+ sender: input.sender,
120
+ network: input.network,
121
+ transactionBlockKindBytes: input.transactionKindBytes,
122
+ allowedAddresses: input.allowedAddresses,
123
+ allowedMoveCallTargets: input.allowedMoveCallTargets
124
+ })
125
+ });
126
+ }
127
+ executeSponsoredTransaction(input) {
128
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, `transaction-blocks/sponsor/${input.digest}`, {
129
+ method: "POST",
130
+ body: JSON.stringify({
131
+ signature: input.signature
132
+ })
133
+ });
134
+ }
135
+ getSubnames(input) {
136
+ const query = new URLSearchParams();
137
+ if (input.address) {
138
+ query.set("address", input.address);
139
+ }
140
+ if (input.network) {
141
+ query.set("network", input.network);
142
+ }
143
+ if (input.domain) {
144
+ query.set("domain", input.domain);
145
+ }
146
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames" + (query.size > 0 ? `?${query.toString()}` : ""), {
147
+ method: "GET"
148
+ });
149
+ }
150
+ createSubname(input) {
151
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames", {
152
+ method: "POST",
153
+ headers: input.jwt ? {
154
+ [ZKLOGIN_HEADER]: input.jwt
155
+ } : {},
156
+ body: JSON.stringify({
157
+ network: input.network,
158
+ domain: input.domain,
159
+ subname: input.subname,
160
+ targetAddress: input.targetAddress
161
+ })
162
+ });
163
+ }
164
+ deleteSubname(input) {
165
+ __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames", {
166
+ method: "DELETE",
167
+ body: JSON.stringify({
168
+ network: input.network,
169
+ domain: input.domain,
170
+ subname: input.subname
171
+ })
172
+ });
173
+ }
174
+ }
175
+ _version = new WeakMap();
176
+ _apiUrl = new WeakMap();
177
+ _apiKey = new WeakMap();
178
+ _additionalEpochs = new WeakMap();
179
+ _EnokiClient_instances = new WeakSet();
180
+ fetch_fn = async function(path, init) {
181
+ const res = await fetch(`${__privateGet(this, _apiUrl)}/${__privateGet(this, _version)}/${path}`, {
182
+ ...init,
183
+ headers: {
184
+ ...init.headers,
185
+ Authorization: `Bearer ${__privateGet(this, _apiKey)}`,
186
+ "Content-Type": "application/json",
187
+ "Request-Id": crypto.randomUUID()
188
+ }
189
+ });
190
+ if (!res.ok) {
191
+ throw new EnokiClientError(res.status, await res.text());
192
+ }
193
+ const { data } = await res.json();
194
+ return data;
195
+ };
196
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/EnokiClient/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tCreateSponsoredTransactionApiInput,\n\tCreateSponsoredTransactionApiResponse,\n\tCreateSubnameApiInput,\n\tCreateSubnameApiResponse,\n\tCreateZkLoginNonceApiInput,\n\tCreateZkLoginNonceApiResponse,\n\tCreateZkLoginZkpApiInput,\n\tCreateZkLoginZkpApiResponse,\n\tDeleteSubnameApiInput,\n\tDeleteSubnameApiResponse,\n\tExecuteSponsoredTransactionApiInput,\n\tExecuteSponsoredTransactionApiResponse,\n\tGetAppApiInput,\n\tGetAppApiResponse,\n\tGetSubnamesApiInput,\n\tGetSubnamesApiResponse,\n\tGetZkLoginAddressesApiInput,\n\tGetZkLoginAddressesApiResponse,\n\tGetZkLoginApiInput,\n\tGetZkLoginApiResponse,\n} from './type.js';\n\nconst DEFAULT_API_URL = 'https://api.enoki.haneullabs.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.toHaneulPublicKey(),\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.toHaneulPublicKey(),\n\t\t\t\tmaxEpoch: input.maxEpoch,\n\t\t\t\trandomness: input.randomness,\n\t\t\t}),\n\t\t});\n\t}\n\n\tcreateSponsoredTransaction(input: CreateSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<CreateSponsoredTransactionApiResponse>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsender: input.sender,\n\t\t\t\tnetwork: input.network,\n\t\t\t\ttransactionBlockKindBytes: input.transactionKindBytes,\n\t\t\t\tallowedAddresses: input.allowedAddresses,\n\t\t\t\tallowedMoveCallTargets: input.allowedMoveCallTargets,\n\t\t\t}),\n\t\t});\n\t}\n\n\texecuteSponsoredTransaction(input: ExecuteSponsoredTransactionApiInput) {\n\t\treturn this.#fetch<ExecuteSponsoredTransactionApiResponse>(\n\t\t\t`transaction-blocks/sponsor/${input.digest}`,\n\t\t\t{\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tsignature: input.signature,\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t}\n\n\tgetSubnames(input: GetSubnamesApiInput) {\n\t\tconst query = new URLSearchParams();\n\t\tif (input.address) {\n\t\t\tquery.set('address', input.address);\n\t\t}\n\t\tif (input.network) {\n\t\t\tquery.set('network', input.network);\n\t\t}\n\t\tif (input.domain) {\n\t\t\tquery.set('domain', input.domain);\n\t\t}\n\t\treturn this.#fetch<GetSubnamesApiResponse>(\n\t\t\t'subnames' + (query.size > 0 ? `?${query.toString()}` : ''),\n\t\t\t{\n\t\t\t\tmethod: 'GET',\n\t\t\t},\n\t\t);\n\t}\n\n\tcreateSubname(input: CreateSubnameApiInput) {\n\t\treturn this.#fetch<CreateSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: input.jwt\n\t\t\t\t? {\n\t\t\t\t\t\t[ZKLOGIN_HEADER]: input.jwt,\n\t\t\t\t\t}\n\t\t\t\t: {},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t\ttargetAddress: input.targetAddress,\n\t\t\t}),\n\t\t});\n\t}\n\n\tdeleteSubname(input: DeleteSubnameApiInput) {\n\t\tthis.#fetch<DeleteSubnameApiResponse>('subnames', {\n\t\t\tmethod: 'DELETE',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: input.network,\n\t\t\t\tdomain: input.domain,\n\t\t\t\tsubname: input.subname,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#apiUrl}/${this.#version}/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\tAuthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Request-Id': crypto.randomUUID(),\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new EnokiClientError(res.status, await res.text());\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAahB,MAAM,yBAAyB,MAAM;AAAA,EAK3C,YAAY,QAAgB,UAAkB;AAC7C,QAAI;AACJ,QAAI;AACH,YAAM,iBAAiB,KAAK,MAAM,QAAQ;AAG1C,eAAS,eAAe;AAAA,IACzB,QAAQ;AAAA,IAER;AACA,UAAM,QAAQ,SAAS,CAAC,IAAI,IAAI,MAAM,OAAO,CAAC,EAAE,OAAO,IAAI;AAC3D,UAAM,wCAAwC,MAAM,KAAK;AAAA,MACxD;AAAA,IACD,CAAC;AAjBF,kBAA6D,CAAC;AAkB7D,SAAK,SAAS,UAAU,CAAC;AACzB,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,SAAS,CAAC,GAAG,QAAQ;AAAA,EAClC;AACD;AAKO,MAAM,YAAY;AAAA,EAMxB,YAAY,QAA2B;AANjC;AAC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A,MACtB,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EAEA,cAAc,OAA8B;AAC3C,0BAAK,kCAAL,WAAsC,YAAY;AAAA,MACjD,QAAQ;AAAA,MACR,MAAM,KAAK,UAAU;AAAA,QACpB,SAAS,MAAM;AAAA,QACf,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM;AAAA,MAChB,CAAC;AAAA,IACF;AAAA,EACD;AAqBD;AA9JC;AACA;AACA;AACA;AAJM;AA4IA,WAAmB,eAAC,MAAc,MAA+B;AACtE,QAAM,MAAM,MAAM,MAAM,GAAG,mBAAK,QAAO,IAAI,mBAAK,SAAQ,IAAI,IAAI,IAAI;AAAA,IACnE,GAAG;AAAA,IACH,SAAS;AAAA,MACR,GAAG,KAAK;AAAA,MACR,eAAe,UAAU,mBAAK,QAAO;AAAA,MACrC,gBAAgB;AAAA,MAChB,cAAc,OAAO,WAAW;AAAA,IACjC;AAAA,EACD,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACZ,UAAM,IAAI,iBAAiB,IAAI,QAAQ,MAAM,IAAI,KAAK,CAAC;AAAA,EACxD;AAEA,QAAM,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK;AAEhC,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,119 @@
1
+ import type { PublicKey } from '@haneullabs/haneul/cryptography';
2
+ import type { ZkLoginSignatureInputs } from '@haneullabs/haneul/zklogin';
3
+ export type AuthProvider = 'google' | 'facebook' | 'twitch' | 'onefc' | 'playtron';
4
+ export type EnokiNetwork = 'mainnet' | 'testnet' | 'devnet';
5
+ export type EnokiDomainNetwork = 'mainnet' | 'testnet';
6
+ export type EnokiSubanameStatus = 'PENDING' | 'ACTIVE';
7
+ export interface GetAppApiInput {
8
+ }
9
+ export interface GetAppApiResponse {
10
+ allowedOrigins: string[];
11
+ authenticationProviders: {
12
+ providerType: AuthProvider;
13
+ clientId: string;
14
+ }[];
15
+ domains: {
16
+ nftId: string;
17
+ name: string;
18
+ network: EnokiDomainNetwork;
19
+ }[];
20
+ }
21
+ export interface GetZkLoginApiInput {
22
+ jwt: string;
23
+ }
24
+ export interface GetZkLoginApiResponse {
25
+ address: string;
26
+ publicKey: string;
27
+ salt: string;
28
+ }
29
+ export interface GetZkLoginAddressesApiInput {
30
+ jwt: string;
31
+ }
32
+ export interface GetZkLoginAddressesApiResponse {
33
+ addresses: {
34
+ clientId: string;
35
+ salt: string;
36
+ address: string;
37
+ publicKey: string;
38
+ legacy?: boolean;
39
+ }[];
40
+ }
41
+ export interface CreateZkLoginNonceApiInput {
42
+ network?: EnokiNetwork;
43
+ ephemeralPublicKey: PublicKey;
44
+ additionalEpochs?: number;
45
+ }
46
+ export interface CreateZkLoginNonceApiResponse {
47
+ nonce: string;
48
+ randomness: string;
49
+ epoch: number;
50
+ maxEpoch: number;
51
+ estimatedExpiration: number;
52
+ }
53
+ export interface CreateZkLoginZkpApiInput {
54
+ network?: EnokiNetwork;
55
+ jwt: string;
56
+ ephemeralPublicKey: PublicKey;
57
+ randomness: string;
58
+ maxEpoch: number;
59
+ }
60
+ export interface CreateZkLoginZkpApiResponse extends ZkLoginSignatureInputs {
61
+ }
62
+ export type CreateSponsoredTransactionApiInput = {
63
+ network?: EnokiNetwork;
64
+ transactionKindBytes: string;
65
+ } & ({
66
+ jwt: string;
67
+ sender?: never;
68
+ allowedAddresses?: never;
69
+ allowedMoveCallTargets?: never;
70
+ } | {
71
+ sender: string;
72
+ allowedAddresses?: string[];
73
+ allowedMoveCallTargets?: string[];
74
+ jwt?: never;
75
+ });
76
+ export interface CreateSponsoredTransactionApiResponse {
77
+ bytes: string;
78
+ digest: string;
79
+ }
80
+ export interface ExecuteSponsoredTransactionApiInput {
81
+ digest: string;
82
+ signature: string;
83
+ }
84
+ export interface ExecuteSponsoredTransactionApiResponse {
85
+ digest: string;
86
+ }
87
+ export interface GetSubnamesApiInput {
88
+ address?: string;
89
+ network?: EnokiDomainNetwork;
90
+ domain?: string;
91
+ }
92
+ export interface GetSubnamesApiResponse {
93
+ subnames: {
94
+ name: string;
95
+ status: EnokiSubanameStatus;
96
+ }[];
97
+ }
98
+ export type CreateSubnameApiInput = {
99
+ domain: string;
100
+ network?: EnokiDomainNetwork;
101
+ subname: string;
102
+ } & ({
103
+ jwt: string;
104
+ targetAddress?: never;
105
+ } | {
106
+ targetAddress: string;
107
+ jwt?: never;
108
+ });
109
+ export interface CreateSubnameApiResponse {
110
+ name: string;
111
+ }
112
+ export interface DeleteSubnameApiInput {
113
+ domain: string;
114
+ network?: EnokiDomainNetwork;
115
+ subname: string;
116
+ }
117
+ export interface DeleteSubnameApiResponse {
118
+ name: string;
119
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var type_exports = {};
16
+ module.exports = __toCommonJS(type_exports);
17
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 '@haneullabs/haneul/cryptography';\nimport type { ZkLoginSignatureInputs } from '@haneullabs/haneul/zklogin';\n\nexport type AuthProvider = 'google' | 'facebook' | 'twitch' | 'onefc' | 'playtron';\nexport type EnokiNetwork = 'mainnet' | 'testnet' | 'devnet';\nexport type EnokiDomainNetwork = 'mainnet' | 'testnet';\nexport type EnokiSubanameStatus = 'PENDING' | 'ACTIVE';\n\nexport interface GetAppApiInput {}\nexport interface GetAppApiResponse {\n\tallowedOrigins: string[];\n\tauthenticationProviders: {\n\t\tproviderType: AuthProvider;\n\t\tclientId: string;\n\t}[];\n\tdomains: {\n\t\tnftId: string;\n\t\tname: string;\n\t\tnetwork: EnokiDomainNetwork;\n\t}[];\n}\n\nexport interface GetZkLoginApiInput {\n\tjwt: string;\n}\nexport interface GetZkLoginApiResponse {\n\taddress: string;\n\tpublicKey: string;\n\tsalt: string;\n}\n\nexport interface GetZkLoginAddressesApiInput {\n\tjwt: string;\n}\nexport interface GetZkLoginAddressesApiResponse {\n\taddresses: {\n\t\tclientId: string;\n\t\tsalt: string;\n\t\taddress: string;\n\t\tpublicKey: string;\n\t\tlegacy?: boolean;\n\t}[];\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\nexport interface GetSubnamesApiInput {\n\taddress?: string;\n\tnetwork?: EnokiDomainNetwork;\n\tdomain?: string;\n}\nexport interface GetSubnamesApiResponse {\n\tsubnames: {\n\t\tname: string;\n\t\tstatus: EnokiSubanameStatus;\n\t}[];\n}\n\nexport type CreateSubnameApiInput = {\n\tdomain: string;\n\tnetwork?: EnokiDomainNetwork;\n\tsubname: string;\n} & (\n\t| {\n\t\t\tjwt: string;\n\t\t\ttargetAddress?: never;\n\t }\n\t| {\n\t\t\ttargetAddress: string;\n\t\t\tjwt?: never;\n\t }\n);\nexport interface CreateSubnameApiResponse {\n\tname: string;\n}\n\nexport interface DeleteSubnameApiInput {\n\tdomain: string;\n\tnetwork?: EnokiDomainNetwork;\n\tsubname: string;\n}\nexport interface DeleteSubnameApiResponse {\n\tname: string;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,74 @@
1
+ import type { ZkLoginSignatureInputs } from '@haneullabs/haneul/zklogin';
2
+ import type { WritableAtom } from 'nanostores';
3
+ import type { Encryption } from './encryption.js';
4
+ import type { EnokiClientConfig } from './EnokiClient/index.js';
5
+ import { EnokiClient } from './EnokiClient/index.js';
6
+ import type { AuthProvider, EnokiNetwork } from './EnokiClient/type.js';
7
+ import { EnokiKeypair } from './EnokiKeypair.js';
8
+ import type { SyncStore } from './stores.js';
9
+ /**
10
+ * @deprecated Use `RegisterEnokiWalletsOptions` instead
11
+ */
12
+ export type EnokiFlowConfig = EnokiClientConfig & ({
13
+ experimental_nativeCryptoSigner?: unknown;
14
+ /**
15
+ * The storage interface to persist Enoki data locally.
16
+ * If not provided, it will use a sessionStorage-backed store.
17
+ */
18
+ store?: SyncStore;
19
+ /**
20
+ * The encryption interface that will be used to encrypt data before storing it locally.
21
+ * If not provided, it will use a default encryption interface.
22
+ */
23
+ encryption?: Encryption;
24
+ } | {
25
+ store?: never;
26
+ encryption?: never;
27
+ /**
28
+ * Enables the new native crypto signer for the EnokiFlow, which is more secure.
29
+ */
30
+ experimental_nativeCryptoSigner: true;
31
+ });
32
+ export interface ZkLoginState {
33
+ provider?: AuthProvider;
34
+ address?: string;
35
+ salt?: string;
36
+ publicKey?: string;
37
+ }
38
+ export interface ZkLoginSession {
39
+ ephemeralKeyPair: string;
40
+ maxEpoch: number;
41
+ randomness: string;
42
+ expiresAt: number;
43
+ jwt?: string;
44
+ proof?: ZkLoginSignatureInputs;
45
+ }
46
+ /**
47
+ * @deprecated Use `registerEnokiWallets` instead
48
+ */
49
+ export declare class EnokiFlow {
50
+ #private;
51
+ $zkLoginSession: WritableAtom<{
52
+ initialized: boolean;
53
+ value: ZkLoginSession | null;
54
+ }>;
55
+ $zkLoginState: WritableAtom<ZkLoginState>;
56
+ constructor(config: EnokiFlowConfig);
57
+ get enokiClient(): EnokiClient;
58
+ createAuthorizationURL(input: {
59
+ provider: AuthProvider;
60
+ clientId: string;
61
+ redirectUrl: string;
62
+ network?: 'mainnet' | 'testnet' | 'devnet';
63
+ extraParams?: Record<string, unknown>;
64
+ }): Promise<string>;
65
+ handleAuthCallback(hash?: string): Promise<string | null>;
66
+ getSession(): Promise<ZkLoginSession | null>;
67
+ logout(): Promise<void>;
68
+ getProof({ network }?: {
69
+ network?: EnokiNetwork;
70
+ }): Promise<import("./EnokiClient/type.js").CreateZkLoginZkpApiResponse>;
71
+ getKeypair({ network }?: {
72
+ network?: EnokiNetwork;
73
+ }): Promise<EnokiKeypair>;
74
+ }