@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
@@ -0,0 +1,176 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+ var _version, _apiUrl, _apiKey, _additionalEpochs, _EnokiClient_instances, fetch_fn;
10
+ const DEFAULT_API_URL = "https://api.enoki.haneullabs.com";
11
+ const ZKLOGIN_HEADER = "zklogin-jwt";
12
+ class EnokiClientError extends Error {
13
+ constructor(status, response) {
14
+ let errors;
15
+ try {
16
+ const parsedResponse = JSON.parse(response);
17
+ errors = parsedResponse.errors;
18
+ } catch {
19
+ }
20
+ const cause = errors?.[0] ? new Error(errors[0].message) : void 0;
21
+ super(`Request to Enoki API failed (status: ${status})`, {
22
+ cause
23
+ });
24
+ this.errors = [];
25
+ this.errors = errors ?? [];
26
+ this.name = "EnokiClientError";
27
+ this.status = status;
28
+ this.code = errors?.[0]?.code ?? "unknown_error";
29
+ }
30
+ }
31
+ class EnokiClient {
32
+ constructor(config) {
33
+ __privateAdd(this, _EnokiClient_instances);
34
+ __privateAdd(this, _version);
35
+ __privateAdd(this, _apiUrl);
36
+ __privateAdd(this, _apiKey);
37
+ __privateAdd(this, _additionalEpochs);
38
+ __privateSet(this, _version, "v1");
39
+ __privateSet(this, _apiUrl, config.apiUrl ?? DEFAULT_API_URL);
40
+ __privateSet(this, _apiKey, config.apiKey);
41
+ __privateSet(this, _additionalEpochs, config.additionalEpochs);
42
+ }
43
+ getApp(_input) {
44
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "app", {
45
+ method: "GET"
46
+ });
47
+ }
48
+ getZkLogin(input) {
49
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin", {
50
+ method: "GET",
51
+ headers: {
52
+ [ZKLOGIN_HEADER]: input.jwt
53
+ }
54
+ });
55
+ }
56
+ getZkLoginAddresses(input) {
57
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/addresses", {
58
+ method: "GET",
59
+ headers: {
60
+ [ZKLOGIN_HEADER]: input.jwt
61
+ }
62
+ });
63
+ }
64
+ createZkLoginNonce(input) {
65
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/nonce", {
66
+ method: "POST",
67
+ body: JSON.stringify({
68
+ network: input.network,
69
+ ephemeralPublicKey: input.ephemeralPublicKey.toHaneulPublicKey(),
70
+ additionalEpochs: input.additionalEpochs ?? __privateGet(this, _additionalEpochs)
71
+ })
72
+ });
73
+ }
74
+ createZkLoginZkp(input) {
75
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "zklogin/zkp", {
76
+ method: "POST",
77
+ headers: {
78
+ [ZKLOGIN_HEADER]: input.jwt
79
+ },
80
+ body: JSON.stringify({
81
+ network: input.network,
82
+ ephemeralPublicKey: input.ephemeralPublicKey.toHaneulPublicKey(),
83
+ maxEpoch: input.maxEpoch,
84
+ randomness: input.randomness
85
+ })
86
+ });
87
+ }
88
+ createSponsoredTransaction(input) {
89
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "transaction-blocks/sponsor", {
90
+ method: "POST",
91
+ headers: input.jwt ? {
92
+ [ZKLOGIN_HEADER]: input.jwt
93
+ } : {},
94
+ body: JSON.stringify({
95
+ sender: input.sender,
96
+ network: input.network,
97
+ transactionBlockKindBytes: input.transactionKindBytes,
98
+ allowedAddresses: input.allowedAddresses,
99
+ allowedMoveCallTargets: input.allowedMoveCallTargets
100
+ })
101
+ });
102
+ }
103
+ executeSponsoredTransaction(input) {
104
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, `transaction-blocks/sponsor/${input.digest}`, {
105
+ method: "POST",
106
+ body: JSON.stringify({
107
+ signature: input.signature
108
+ })
109
+ });
110
+ }
111
+ getSubnames(input) {
112
+ const query = new URLSearchParams();
113
+ if (input.address) {
114
+ query.set("address", input.address);
115
+ }
116
+ if (input.network) {
117
+ query.set("network", input.network);
118
+ }
119
+ if (input.domain) {
120
+ query.set("domain", input.domain);
121
+ }
122
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames" + (query.size > 0 ? `?${query.toString()}` : ""), {
123
+ method: "GET"
124
+ });
125
+ }
126
+ createSubname(input) {
127
+ return __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames", {
128
+ method: "POST",
129
+ headers: input.jwt ? {
130
+ [ZKLOGIN_HEADER]: input.jwt
131
+ } : {},
132
+ body: JSON.stringify({
133
+ network: input.network,
134
+ domain: input.domain,
135
+ subname: input.subname,
136
+ targetAddress: input.targetAddress
137
+ })
138
+ });
139
+ }
140
+ deleteSubname(input) {
141
+ __privateMethod(this, _EnokiClient_instances, fetch_fn).call(this, "subnames", {
142
+ method: "DELETE",
143
+ body: JSON.stringify({
144
+ network: input.network,
145
+ domain: input.domain,
146
+ subname: input.subname
147
+ })
148
+ });
149
+ }
150
+ }
151
+ _version = new WeakMap();
152
+ _apiUrl = new WeakMap();
153
+ _apiKey = new WeakMap();
154
+ _additionalEpochs = new WeakMap();
155
+ _EnokiClient_instances = new WeakSet();
156
+ fetch_fn = async function(path, init) {
157
+ const res = await fetch(`${__privateGet(this, _apiUrl)}/${__privateGet(this, _version)}/${path}`, {
158
+ ...init,
159
+ headers: {
160
+ ...init.headers,
161
+ Authorization: `Bearer ${__privateGet(this, _apiKey)}`,
162
+ "Content-Type": "application/json",
163
+ "Request-Id": crypto.randomUUID()
164
+ }
165
+ });
166
+ if (!res.ok) {
167
+ throw new EnokiClientError(res.status, await res.text());
168
+ }
169
+ const { data } = await res.json();
170
+ return data;
171
+ };
172
+ export {
173
+ EnokiClient,
174
+ EnokiClientError
175
+ };
176
+ //# 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;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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} 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 @@
1
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
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
+ }
@@ -0,0 +1,259 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+ var _storageKeys, _enokiClient, _encryption, _encryptionKey, _store, _useNativeCryptoSigner, _idbStore, _EnokiFlow_instances, setSession_fn;
10
+ import { WebCryptoSigner } from "@haneullabs/signers/webcrypto";
11
+ import { decodeHaneulPrivateKey } from "@haneullabs/haneul/cryptography";
12
+ import { Ed25519Keypair } from "@haneullabs/haneul/keypairs/ed25519";
13
+ import { fromBase64, toBase64 } from "@haneullabs/haneul/utils";
14
+ import { decodeJwt } from "@haneullabs/haneul/zklogin";
15
+ import { clear, createStore, get, set } from "idb-keyval";
16
+ import { atom, onMount, onSet } from "nanostores";
17
+ import { createDefaultEncryption } from "./encryption.js";
18
+ import { EnokiClient } from "./EnokiClient/index.js";
19
+ import { EnokiKeypair } from "./EnokiKeypair.js";
20
+ import { createSessionStorage } from "./stores.js";
21
+ const createStorageKeys = (apiKey) => ({
22
+ STATE: `@enoki/flow/state/${apiKey}`,
23
+ SESSION: `@enoki/flow/session/${apiKey}`
24
+ });
25
+ class EnokiFlow {
26
+ constructor(config) {
27
+ __privateAdd(this, _EnokiFlow_instances);
28
+ __privateAdd(this, _storageKeys);
29
+ __privateAdd(this, _enokiClient);
30
+ __privateAdd(this, _encryption);
31
+ __privateAdd(this, _encryptionKey);
32
+ __privateAdd(this, _store);
33
+ __privateAdd(this, _useNativeCryptoSigner);
34
+ __privateAdd(this, _idbStore);
35
+ __privateSet(this, _enokiClient, new EnokiClient({
36
+ apiKey: config.apiKey,
37
+ apiUrl: config.apiUrl,
38
+ additionalEpochs: config.additionalEpochs
39
+ }));
40
+ __privateSet(this, _encryptionKey, config.apiKey);
41
+ if (config.experimental_nativeCryptoSigner) {
42
+ __privateSet(this, _useNativeCryptoSigner, true);
43
+ __privateSet(this, _idbStore, createStore(config.apiKey, "enoki"));
44
+ } else {
45
+ __privateSet(this, _useNativeCryptoSigner, false);
46
+ }
47
+ __privateSet(this, _encryption, config.encryption ?? createDefaultEncryption());
48
+ __privateSet(this, _store, config.store ?? createSessionStorage());
49
+ __privateSet(this, _storageKeys, createStorageKeys(config.apiKey));
50
+ let storedState = null;
51
+ try {
52
+ const rawStoredValue = __privateGet(this, _store).get(__privateGet(this, _storageKeys).STATE);
53
+ if (rawStoredValue) {
54
+ storedState = JSON.parse(rawStoredValue);
55
+ }
56
+ } catch {
57
+ }
58
+ this.$zkLoginState = atom(storedState || {});
59
+ this.$zkLoginSession = atom({ initialized: false, value: null });
60
+ onMount(this.$zkLoginSession, () => {
61
+ this.getSession();
62
+ });
63
+ onSet(this.$zkLoginState, ({ newValue }) => {
64
+ __privateGet(this, _store).set(__privateGet(this, _storageKeys).STATE, JSON.stringify(newValue));
65
+ });
66
+ }
67
+ get enokiClient() {
68
+ return __privateGet(this, _enokiClient);
69
+ }
70
+ async createAuthorizationURL(input) {
71
+ const ephemeralKeyPair = __privateGet(this, _useNativeCryptoSigner) ? await WebCryptoSigner.generate() : new Ed25519Keypair();
72
+ const { nonce, randomness, maxEpoch, estimatedExpiration } = await __privateGet(this, _enokiClient).createZkLoginNonce({
73
+ network: input.network,
74
+ ephemeralPublicKey: ephemeralKeyPair.getPublicKey()
75
+ });
76
+ const params = new URLSearchParams({
77
+ ...input.extraParams,
78
+ nonce,
79
+ client_id: input.clientId,
80
+ redirect_uri: input.redirectUrl,
81
+ response_type: "id_token",
82
+ // TODO: Eventually fetch the scopes for this client ID from the Enoki service:
83
+ scope: [
84
+ "openid",
85
+ // Merge the requested scopes in with the required openid scopes:
86
+ ...input.extraParams && "scope" in input.extraParams ? input.extraParams.scope : []
87
+ ].filter(Boolean).join(" ")
88
+ });
89
+ let oauthUrl;
90
+ switch (input.provider) {
91
+ case "google": {
92
+ oauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
93
+ break;
94
+ }
95
+ case "facebook": {
96
+ oauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;
97
+ break;
98
+ }
99
+ case "twitch": {
100
+ params.set("force_verify", "true");
101
+ oauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;
102
+ break;
103
+ }
104
+ default:
105
+ throw new Error(`Invalid provider: ${input.provider}`);
106
+ }
107
+ this.$zkLoginState.set({ provider: input.provider });
108
+ if (__privateGet(this, _useNativeCryptoSigner)) {
109
+ await set("ephemeralKeyPair", ephemeralKeyPair.export(), __privateGet(this, _idbStore));
110
+ }
111
+ await __privateMethod(this, _EnokiFlow_instances, setSession_fn).call(this, {
112
+ expiresAt: estimatedExpiration,
113
+ maxEpoch,
114
+ randomness,
115
+ ephemeralKeyPair: __privateGet(this, _useNativeCryptoSigner) ? "@@native" : toBase64(
116
+ decodeHaneulPrivateKey(ephemeralKeyPair.getSecretKey()).secretKey
117
+ )
118
+ });
119
+ return oauthUrl;
120
+ }
121
+ // TODO: Should our SDK manage this automatically in addition to exposing a method?
122
+ async handleAuthCallback(hash = window.location.hash) {
123
+ const params = new URLSearchParams(hash.startsWith("#") ? hash.slice(1) : hash);
124
+ const zkp = await this.getSession();
125
+ if (!zkp || !zkp.ephemeralKeyPair || !zkp.maxEpoch || !zkp.randomness) {
126
+ throw new Error(
127
+ "Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this."
128
+ );
129
+ }
130
+ const jwt = params.get("id_token");
131
+ if (!jwt) {
132
+ throw new Error("Missing ID Token");
133
+ }
134
+ decodeJwt(jwt);
135
+ const { address, salt, publicKey } = await __privateGet(this, _enokiClient).getZkLogin({ jwt });
136
+ this.$zkLoginState.set({
137
+ ...this.$zkLoginState.get(),
138
+ salt,
139
+ address,
140
+ publicKey
141
+ });
142
+ await __privateMethod(this, _EnokiFlow_instances, setSession_fn).call(this, {
143
+ ...zkp,
144
+ jwt
145
+ });
146
+ return params.get("state");
147
+ }
148
+ async getSession() {
149
+ if (this.$zkLoginSession.get().initialized) {
150
+ return this.$zkLoginSession.get().value;
151
+ }
152
+ try {
153
+ const storedValue = __privateGet(this, _store).get(__privateGet(this, _storageKeys).SESSION);
154
+ if (!storedValue) return null;
155
+ const state = JSON.parse(
156
+ await __privateGet(this, _encryption).decrypt(__privateGet(this, _encryptionKey), storedValue)
157
+ );
158
+ if (state?.expiresAt && Date.now() > state.expiresAt) {
159
+ await this.logout();
160
+ } else {
161
+ this.$zkLoginSession.set({ initialized: true, value: state });
162
+ }
163
+ } catch {
164
+ this.$zkLoginSession.set({ initialized: true, value: null });
165
+ }
166
+ return this.$zkLoginSession.get().value;
167
+ }
168
+ async logout() {
169
+ this.$zkLoginState.set({});
170
+ __privateGet(this, _store).delete(__privateGet(this, _storageKeys).STATE);
171
+ if (__privateGet(this, _useNativeCryptoSigner)) {
172
+ await clear(__privateGet(this, _idbStore));
173
+ }
174
+ await __privateMethod(this, _EnokiFlow_instances, setSession_fn).call(this, null);
175
+ }
176
+ // TODO: Should this return the proof if it already exists?
177
+ async getProof({ network } = {}) {
178
+ const zkp = await this.getSession();
179
+ const { salt } = this.$zkLoginState.get();
180
+ if (zkp?.proof) {
181
+ if (zkp.expiresAt && Date.now() > zkp.expiresAt) {
182
+ throw new Error("Stored proof is expired.");
183
+ }
184
+ return zkp.proof;
185
+ }
186
+ if (!salt || !zkp || !zkp.jwt) {
187
+ throw new Error("Missing required parameters for proof generation");
188
+ }
189
+ let storedNativeSigner = void 0;
190
+ if (__privateGet(this, _useNativeCryptoSigner) && zkp.ephemeralKeyPair === "@@native") {
191
+ storedNativeSigner = await get("ephemeralKeyPair", __privateGet(this, _idbStore));
192
+ if (!storedNativeSigner) {
193
+ throw new Error("Native signer not found in store.");
194
+ }
195
+ }
196
+ const ephemeralKeyPair = zkp.ephemeralKeyPair === "@@native" ? WebCryptoSigner.import(storedNativeSigner) : Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));
197
+ const proof = await __privateGet(this, _enokiClient).createZkLoginZkp({
198
+ network,
199
+ jwt: zkp.jwt,
200
+ maxEpoch: zkp.maxEpoch,
201
+ randomness: zkp.randomness,
202
+ ephemeralPublicKey: ephemeralKeyPair.getPublicKey()
203
+ });
204
+ await __privateMethod(this, _EnokiFlow_instances, setSession_fn).call(this, {
205
+ ...zkp,
206
+ proof
207
+ });
208
+ return proof;
209
+ }
210
+ async getKeypair({ network } = {}) {
211
+ await this.getProof({ network });
212
+ const zkp = await this.getSession();
213
+ const { address } = this.$zkLoginState.get();
214
+ if (!address || !zkp || !zkp.proof) {
215
+ throw new Error("Missing required data for keypair generation.");
216
+ }
217
+ if (Date.now() > zkp.expiresAt) {
218
+ throw new Error("Stored proof is expired.");
219
+ }
220
+ let storedNativeSigner = void 0;
221
+ if (__privateGet(this, _useNativeCryptoSigner) && zkp.ephemeralKeyPair === "@@native") {
222
+ storedNativeSigner = await get("ephemeralKeyPair", __privateGet(this, _idbStore));
223
+ if (!storedNativeSigner) {
224
+ throw new Error("Native signer not found in store.");
225
+ }
226
+ }
227
+ const ephemeralKeypair = zkp.ephemeralKeyPair === "@@native" ? WebCryptoSigner.import(storedNativeSigner) : Ed25519Keypair.fromSecretKey(fromBase64(zkp.ephemeralKeyPair));
228
+ return new EnokiKeypair({
229
+ address,
230
+ ephemeralKeypair,
231
+ maxEpoch: zkp.maxEpoch,
232
+ proof: zkp.proof
233
+ });
234
+ }
235
+ }
236
+ _storageKeys = new WeakMap();
237
+ _enokiClient = new WeakMap();
238
+ _encryption = new WeakMap();
239
+ _encryptionKey = new WeakMap();
240
+ _store = new WeakMap();
241
+ _useNativeCryptoSigner = new WeakMap();
242
+ _idbStore = new WeakMap();
243
+ _EnokiFlow_instances = new WeakSet();
244
+ setSession_fn = async function(newValue) {
245
+ if (newValue) {
246
+ const storedValue = await __privateGet(this, _encryption).encrypt(
247
+ __privateGet(this, _encryptionKey),
248
+ JSON.stringify(newValue)
249
+ );
250
+ __privateGet(this, _store).set(__privateGet(this, _storageKeys).SESSION, storedValue);
251
+ } else {
252
+ __privateGet(this, _store).delete(__privateGet(this, _storageKeys).SESSION);
253
+ }
254
+ this.$zkLoginSession.set({ initialized: true, value: newValue });
255
+ };
256
+ export {
257
+ EnokiFlow
258
+ };
259
+ //# sourceMappingURL=EnokiFlow.js.map