@mysten/zksend 0.1.1 → 0.2.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 (40) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/cjs/channel/events.d.ts +294 -0
  3. package/dist/cjs/channel/events.js +80 -0
  4. package/dist/cjs/channel/events.js.map +7 -0
  5. package/dist/cjs/channel/index.d.ts +38 -0
  6. package/dist/cjs/channel/index.js +172 -0
  7. package/dist/cjs/channel/index.js.map +7 -0
  8. package/dist/cjs/index.d.ts +3 -0
  9. package/dist/cjs/index.js +19 -0
  10. package/dist/cjs/index.js.map +3 -3
  11. package/dist/cjs/links.d.ts +80 -0
  12. package/dist/cjs/links.js +370 -0
  13. package/dist/cjs/links.js.map +7 -0
  14. package/dist/cjs/utils/withResolvers.d.ts +6 -0
  15. package/dist/cjs/utils/withResolvers.js +33 -0
  16. package/dist/cjs/utils/withResolvers.js.map +7 -0
  17. package/dist/cjs/wallet.d.ts +24 -0
  18. package/dist/cjs/wallet.js +227 -0
  19. package/dist/cjs/wallet.js.map +7 -0
  20. package/dist/esm/channel/events.d.ts +294 -0
  21. package/dist/esm/channel/events.js +60 -0
  22. package/dist/esm/channel/events.js.map +7 -0
  23. package/dist/esm/channel/index.d.ts +38 -0
  24. package/dist/esm/channel/index.js +152 -0
  25. package/dist/esm/channel/index.js.map +7 -0
  26. package/dist/esm/index.d.ts +3 -0
  27. package/dist/esm/index.js +3 -9
  28. package/dist/esm/index.js.map +2 -2
  29. package/dist/esm/links.d.ts +80 -0
  30. package/dist/esm/links.js +358 -0
  31. package/dist/esm/links.js.map +7 -0
  32. package/dist/esm/utils/withResolvers.d.ts +6 -0
  33. package/dist/esm/utils/withResolvers.js +13 -0
  34. package/dist/esm/utils/withResolvers.js.map +7 -0
  35. package/dist/esm/wallet.d.ts +24 -0
  36. package/dist/esm/wallet.js +197 -0
  37. package/dist/esm/wallet.js.map +7 -0
  38. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +6 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @mysten/zksend
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e81f49e8dc: Add SDK for creating ZKSend links
8
+
9
+ ### Patch Changes
10
+
11
+ - c07aa19958: Fix coin merging for sending balances
12
+ - 13e922d9b1: Rework timing and window opening logic to try and improve browser compatibility
13
+ - c859f41a1c: Handle base64 with spaces in hash
14
+ - d21c01ed47: Add method for claiming zksend assets from link
15
+ - 2814db6529: Fix required redirect
16
+ - e87d99734a: Add method for sending non-sui balances
17
+ - ba6fccd010: Add support for autoconnection from redirects
18
+ - c6b3066069: Fix cursor when enumerating links owned assets
19
+ - 66fbbc7faa: Detect gasCoin when claiming
20
+ - 7b8d044603: Detect wallet closing
21
+ - c6b3066069: Improve zkSend error messages
22
+ - a2904e0075: Fix for claimable assets not accounting for cases where claimable balance comes from gas coin
23
+ - ea2744b0c3: Add redirect parameter and fix listing assets on links without Sui
24
+ - 44a1f9ea0b: Tweak types of events sent over the bridge
25
+ - 7cc09a7bb4: Handle cases where list of objects to transfer is empty
26
+ - 9a14e61db4: Add gas estimation for creating zksend links
27
+ - f041b10b9f: Allow origin to be set when registering zksend wallet"
28
+ - c1f6cfff47: Fix import paths
29
+ - 7c9a8cc24b: Fix window opening for transactions with unresolved data
30
+ - ae9ae17eea: Fix ownedAfterClaim check
31
+ - Updated dependencies [a34f1cb67d]
32
+ - Updated dependencies [c08e3569ef]
33
+ - Updated dependencies [9a14e61db4]
34
+ - Updated dependencies [13e922d9b1]
35
+ - Updated dependencies [a34f1cb67d]
36
+ - Updated dependencies [220a766d86]
37
+ - @mysten/sui.js@0.50.0
38
+ - @mysten/wallet-standard@0.10.2
39
+
3
40
  ## 0.1.1
4
41
 
5
42
  ### Patch Changes
@@ -0,0 +1,294 @@
1
+ import type { Output } from 'valibot';
2
+ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
3
+ type: import("valibot").LiteralSchema<"connect", "connect">;
4
+ }, undefined, {
5
+ type: "connect";
6
+ }>, import("valibot").ObjectSchema<{
7
+ type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
8
+ data: import("valibot").StringSchema<string>;
9
+ address: import("valibot").StringSchema<string>;
10
+ }, undefined, {
11
+ type: "sign-transaction-block";
12
+ data: string;
13
+ address: string;
14
+ }>, import("valibot").ObjectSchema<{
15
+ type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
16
+ bytes: import("valibot").StringSchema<string>;
17
+ address: import("valibot").StringSchema<string>;
18
+ }, undefined, {
19
+ type: "sign-personal-message";
20
+ address: string;
21
+ bytes: string;
22
+ }>], {
23
+ type: "connect";
24
+ } | {
25
+ type: "sign-transaction-block";
26
+ data: string;
27
+ address: string;
28
+ } | {
29
+ type: "sign-personal-message";
30
+ address: string;
31
+ bytes: string;
32
+ }>;
33
+ export type ZkSendRequestData = Output<typeof ZkSendRequestData>;
34
+ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
35
+ id: import("valibot").StringSchema<string>;
36
+ origin: import("valibot").StringSchema<string>;
37
+ name: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
38
+ payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
39
+ type: import("valibot").LiteralSchema<"connect", "connect">;
40
+ }, undefined, {
41
+ type: "connect";
42
+ }>, import("valibot").ObjectSchema<{
43
+ type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
44
+ data: import("valibot").StringSchema<string>;
45
+ address: import("valibot").StringSchema<string>;
46
+ }, undefined, {
47
+ type: "sign-transaction-block";
48
+ data: string;
49
+ address: string;
50
+ }>, import("valibot").ObjectSchema<{
51
+ type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
52
+ bytes: import("valibot").StringSchema<string>;
53
+ address: import("valibot").StringSchema<string>;
54
+ }, undefined, {
55
+ type: "sign-personal-message";
56
+ address: string;
57
+ bytes: string;
58
+ }>], {
59
+ type: "connect";
60
+ } | {
61
+ type: "sign-transaction-block";
62
+ data: string;
63
+ address: string;
64
+ } | {
65
+ type: "sign-personal-message";
66
+ address: string;
67
+ bytes: string;
68
+ }>;
69
+ }, undefined, {
70
+ origin: string;
71
+ id: string;
72
+ payload: {
73
+ type: "connect";
74
+ } | {
75
+ type: "sign-transaction-block";
76
+ data: string;
77
+ address: string;
78
+ } | {
79
+ type: "sign-personal-message";
80
+ address: string;
81
+ bytes: string;
82
+ };
83
+ name?: string | undefined;
84
+ }>;
85
+ export type ZkSendRequest = Output<typeof ZkSendRequest>;
86
+ export declare const ZkSendResponseData: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
87
+ type: import("valibot").LiteralSchema<"connect", "connect">;
88
+ address: import("valibot").StringSchema<string>;
89
+ }, undefined, {
90
+ type: "connect";
91
+ address: string;
92
+ }>, import("valibot").ObjectSchema<{
93
+ type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
94
+ bytes: import("valibot").StringSchema<string>;
95
+ signature: import("valibot").StringSchema<string>;
96
+ }, undefined, {
97
+ signature: string;
98
+ type: "sign-transaction-block";
99
+ bytes: string;
100
+ }>, import("valibot").ObjectSchema<{
101
+ type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
102
+ bytes: import("valibot").StringSchema<string>;
103
+ signature: import("valibot").StringSchema<string>;
104
+ }, undefined, {
105
+ signature: string;
106
+ type: "sign-personal-message";
107
+ bytes: string;
108
+ }>], {
109
+ type: "connect";
110
+ address: string;
111
+ } | {
112
+ signature: string;
113
+ type: "sign-transaction-block";
114
+ bytes: string;
115
+ } | {
116
+ signature: string;
117
+ type: "sign-personal-message";
118
+ bytes: string;
119
+ }>;
120
+ export type ZkSendResponseData = Output<typeof ZkSendResponseData>;
121
+ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
122
+ type: import("valibot").LiteralSchema<"reject", "reject">;
123
+ }, undefined, {
124
+ type: "reject";
125
+ }>, import("valibot").ObjectSchema<{
126
+ type: import("valibot").LiteralSchema<"resolve", "resolve">;
127
+ data: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
128
+ type: import("valibot").LiteralSchema<"connect", "connect">;
129
+ address: import("valibot").StringSchema<string>;
130
+ }, undefined, {
131
+ type: "connect";
132
+ address: string;
133
+ }>, import("valibot").ObjectSchema<{
134
+ type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
135
+ bytes: import("valibot").StringSchema<string>;
136
+ signature: import("valibot").StringSchema<string>;
137
+ }, undefined, {
138
+ signature: string;
139
+ type: "sign-transaction-block";
140
+ bytes: string;
141
+ }>, import("valibot").ObjectSchema<{
142
+ type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
143
+ bytes: import("valibot").StringSchema<string>;
144
+ signature: import("valibot").StringSchema<string>;
145
+ }, undefined, {
146
+ signature: string;
147
+ type: "sign-personal-message";
148
+ bytes: string;
149
+ }>], {
150
+ type: "connect";
151
+ address: string;
152
+ } | {
153
+ signature: string;
154
+ type: "sign-transaction-block";
155
+ bytes: string;
156
+ } | {
157
+ signature: string;
158
+ type: "sign-personal-message";
159
+ bytes: string;
160
+ }>;
161
+ }, undefined, {
162
+ type: "resolve";
163
+ data: {
164
+ type: "connect";
165
+ address: string;
166
+ } | {
167
+ signature: string;
168
+ type: "sign-transaction-block";
169
+ bytes: string;
170
+ } | {
171
+ signature: string;
172
+ type: "sign-personal-message";
173
+ bytes: string;
174
+ };
175
+ }>], {
176
+ type: "reject";
177
+ } | {
178
+ type: "resolve";
179
+ data: {
180
+ type: "connect";
181
+ address: string;
182
+ } | {
183
+ signature: string;
184
+ type: "sign-transaction-block";
185
+ bytes: string;
186
+ } | {
187
+ signature: string;
188
+ type: "sign-personal-message";
189
+ bytes: string;
190
+ };
191
+ }>;
192
+ export type ZkSendResponsePayload = Output<typeof ZkSendResponsePayload>;
193
+ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
194
+ id: import("valibot").StringSchema<string>;
195
+ source: import("valibot").LiteralSchema<"zksend-channel", "zksend-channel">;
196
+ payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
197
+ type: import("valibot").LiteralSchema<"reject", "reject">;
198
+ }, undefined, {
199
+ type: "reject";
200
+ }>, import("valibot").ObjectSchema<{
201
+ type: import("valibot").LiteralSchema<"resolve", "resolve">;
202
+ data: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
203
+ type: import("valibot").LiteralSchema<"connect", "connect">;
204
+ address: import("valibot").StringSchema<string>;
205
+ }, undefined, {
206
+ type: "connect";
207
+ address: string;
208
+ }>, import("valibot").ObjectSchema<{
209
+ type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
210
+ bytes: import("valibot").StringSchema<string>;
211
+ signature: import("valibot").StringSchema<string>;
212
+ }, undefined, {
213
+ signature: string;
214
+ type: "sign-transaction-block";
215
+ bytes: string;
216
+ }>, import("valibot").ObjectSchema<{
217
+ type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
218
+ bytes: import("valibot").StringSchema<string>;
219
+ signature: import("valibot").StringSchema<string>;
220
+ }, undefined, {
221
+ signature: string;
222
+ type: "sign-personal-message";
223
+ bytes: string;
224
+ }>], {
225
+ type: "connect";
226
+ address: string;
227
+ } | {
228
+ signature: string;
229
+ type: "sign-transaction-block";
230
+ bytes: string;
231
+ } | {
232
+ signature: string;
233
+ type: "sign-personal-message";
234
+ bytes: string;
235
+ }>;
236
+ }, undefined, {
237
+ type: "resolve";
238
+ data: {
239
+ type: "connect";
240
+ address: string;
241
+ } | {
242
+ signature: string;
243
+ type: "sign-transaction-block";
244
+ bytes: string;
245
+ } | {
246
+ signature: string;
247
+ type: "sign-personal-message";
248
+ bytes: string;
249
+ };
250
+ }>], {
251
+ type: "reject";
252
+ } | {
253
+ type: "resolve";
254
+ data: {
255
+ type: "connect";
256
+ address: string;
257
+ } | {
258
+ signature: string;
259
+ type: "sign-transaction-block";
260
+ bytes: string;
261
+ } | {
262
+ signature: string;
263
+ type: "sign-personal-message";
264
+ bytes: string;
265
+ };
266
+ }>;
267
+ }, undefined, {
268
+ id: string;
269
+ payload: {
270
+ type: "reject";
271
+ } | {
272
+ type: "resolve";
273
+ data: {
274
+ type: "connect";
275
+ address: string;
276
+ } | {
277
+ signature: string;
278
+ type: "sign-transaction-block";
279
+ bytes: string;
280
+ } | {
281
+ signature: string;
282
+ type: "sign-personal-message";
283
+ bytes: string;
284
+ };
285
+ };
286
+ source: "zksend-channel";
287
+ }>;
288
+ export type ZkSendResponse = Output<typeof ZkSendResponse>;
289
+ export type ZkSendRequestTypes = Record<string, any> & {
290
+ [P in ZkSendRequestData as P['type']]: P;
291
+ };
292
+ export type ZkSendResponseTypes = {
293
+ [P in ZkSendResponseData as P['type']]: P;
294
+ };
@@ -0,0 +1,80 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var events_exports = {};
20
+ __export(events_exports, {
21
+ ZkSendRequest: () => ZkSendRequest,
22
+ ZkSendRequestData: () => ZkSendRequestData,
23
+ ZkSendResponse: () => ZkSendResponse,
24
+ ZkSendResponseData: () => ZkSendResponseData,
25
+ ZkSendResponsePayload: () => ZkSendResponsePayload
26
+ });
27
+ module.exports = __toCommonJS(events_exports);
28
+ var import_valibot = require("valibot");
29
+ const ZkSendRequestData = (0, import_valibot.variant)("type", [
30
+ (0, import_valibot.object)({
31
+ type: (0, import_valibot.literal)("connect")
32
+ }),
33
+ (0, import_valibot.object)({
34
+ type: (0, import_valibot.literal)("sign-transaction-block"),
35
+ data: (0, import_valibot.string)("`data` is required"),
36
+ address: (0, import_valibot.string)("`address` is required")
37
+ }),
38
+ (0, import_valibot.object)({
39
+ type: (0, import_valibot.literal)("sign-personal-message"),
40
+ bytes: (0, import_valibot.string)("`bytes` is required"),
41
+ address: (0, import_valibot.string)("`address` is required")
42
+ })
43
+ ]);
44
+ const ZkSendRequest = (0, import_valibot.object)({
45
+ id: (0, import_valibot.string)("`id` is required", [(0, import_valibot.uuid)()]),
46
+ origin: (0, import_valibot.string)([(0, import_valibot.url)("`origin` must be a valid URL")]),
47
+ name: (0, import_valibot.optional)((0, import_valibot.string)()),
48
+ payload: ZkSendRequestData
49
+ });
50
+ const ZkSendResponseData = (0, import_valibot.variant)("type", [
51
+ (0, import_valibot.object)({
52
+ type: (0, import_valibot.literal)("connect"),
53
+ address: (0, import_valibot.string)()
54
+ }),
55
+ (0, import_valibot.object)({
56
+ type: (0, import_valibot.literal)("sign-transaction-block"),
57
+ bytes: (0, import_valibot.string)(),
58
+ signature: (0, import_valibot.string)()
59
+ }),
60
+ (0, import_valibot.object)({
61
+ type: (0, import_valibot.literal)("sign-personal-message"),
62
+ bytes: (0, import_valibot.string)(),
63
+ signature: (0, import_valibot.string)()
64
+ })
65
+ ]);
66
+ const ZkSendResponsePayload = (0, import_valibot.variant)("type", [
67
+ (0, import_valibot.object)({
68
+ type: (0, import_valibot.literal)("reject")
69
+ }),
70
+ (0, import_valibot.object)({
71
+ type: (0, import_valibot.literal)("resolve"),
72
+ data: ZkSendResponseData
73
+ })
74
+ ]);
75
+ const ZkSendResponse = (0, import_valibot.object)({
76
+ id: (0, import_valibot.string)([(0, import_valibot.uuid)()]),
77
+ source: (0, import_valibot.literal)("zksend-channel"),
78
+ payload: ZkSendResponsePayload
79
+ });
80
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/channel/events.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Output } from 'valibot';\nimport { literal, object, optional, string, url, uuid, variant } from 'valibot';\n\nexport const ZkSendRequestData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tdata: string('`data` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string('`bytes` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n]);\nexport type ZkSendRequestData = Output<typeof ZkSendRequestData>;\n\nexport const ZkSendRequest = object({\n\tid: string('`id` is required', [uuid()]),\n\torigin: string([url('`origin` must be a valid URL')]),\n\tname: optional(string()),\n\tpayload: ZkSendRequestData,\n});\n\nexport type ZkSendRequest = Output<typeof ZkSendRequest>;\n\nexport const ZkSendResponseData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t\taddress: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n]);\nexport type ZkSendResponseData = Output<typeof ZkSendResponseData>;\n\nexport const ZkSendResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: ZkSendResponseData,\n\t}),\n]);\nexport type ZkSendResponsePayload = Output<typeof ZkSendResponsePayload>;\n\nexport const ZkSendResponse = object({\n\tid: string([uuid()]),\n\tsource: literal('zksend-channel'),\n\tpayload: ZkSendResponsePayload,\n});\nexport type ZkSendResponse = Output<typeof ZkSendResponse>;\n\nexport type ZkSendRequestTypes = Record<string, any> & {\n\t[P in ZkSendRequestData as P['type']]: P;\n};\n\nexport type ZkSendResponseTypes = {\n\t[P in ZkSendResponseData as P['type']]: P;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAsE;AAE/D,MAAM,wBAAoB,wBAAQ,QAAQ;AAAA,MAChD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,EACxB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,wBAAwB;AAAA,IACtC,UAAM,uBAAO,oBAAoB;AAAA,IACjC,aAAS,uBAAO,uBAAuB;AAAA,EACxC,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,uBAAuB;AAAA,IACrC,WAAO,uBAAO,qBAAqB;AAAA,IACnC,aAAS,uBAAO,uBAAuB;AAAA,EACxC,CAAC;AACF,CAAC;AAGM,MAAM,oBAAgB,uBAAO;AAAA,EACnC,QAAI,uBAAO,oBAAoB,KAAC,qBAAK,CAAC,CAAC;AAAA,EACvC,YAAQ,uBAAO,KAAC,oBAAI,8BAA8B,CAAC,CAAC;AAAA,EACpD,UAAM,6BAAS,uBAAO,CAAC;AAAA,EACvB,SAAS;AACV,CAAC;AAIM,MAAM,yBAAqB,wBAAQ,QAAQ;AAAA,MACjD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,IACvB,aAAS,uBAAO;AAAA,EACjB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,wBAAwB;AAAA,IACtC,WAAO,uBAAO;AAAA,IACd,eAAW,uBAAO;AAAA,EACnB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,uBAAuB;AAAA,IACrC,WAAO,uBAAO;AAAA,IACd,eAAW,uBAAO;AAAA,EACnB,CAAC;AACF,CAAC;AAGM,MAAM,4BAAwB,wBAAQ,QAAQ;AAAA,MACpD,uBAAO;AAAA,IACN,UAAM,wBAAQ,QAAQ;AAAA,EACvB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,qBAAiB,uBAAO;AAAA,EACpC,QAAI,uBAAO,KAAC,qBAAK,CAAC,CAAC;AAAA,EACnB,YAAQ,wBAAQ,gBAAgB;AAAA,EAChC,SAAS;AACV,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ import type { Output } from 'valibot';
2
+ import type { ZkSendRequestData, ZkSendResponsePayload, ZkSendResponseTypes } from './events.js';
3
+ import { ZkSendRequest, ZkSendResponse } from './events.js';
4
+ export declare const DEFAULT_ZKSEND_ORIGIN = "https://zksend.com";
5
+ export { ZkSendRequest, ZkSendResponse };
6
+ interface ZkSendPopupOptions {
7
+ origin?: string;
8
+ name: string;
9
+ }
10
+ export declare class ZkSendPopup {
11
+ #private;
12
+ constructor({ origin, name }: ZkSendPopupOptions);
13
+ createRequest<T extends ZkSendRequestData>(request: T): Promise<ZkSendResponseTypes[T['type']]>;
14
+ close(): void;
15
+ }
16
+ export declare class ZkSendHost {
17
+ #private;
18
+ constructor(request: Output<typeof ZkSendRequest>);
19
+ static fromUrl(url?: string): ZkSendHost;
20
+ getRequestData(): {
21
+ origin: string;
22
+ id: string;
23
+ payload: {
24
+ type: "connect";
25
+ } | {
26
+ type: "sign-transaction-block";
27
+ data: string;
28
+ address: string;
29
+ } | {
30
+ type: "sign-personal-message";
31
+ address: string;
32
+ bytes: string;
33
+ };
34
+ name?: string | undefined;
35
+ };
36
+ sendMessage(payload: ZkSendResponsePayload): void;
37
+ close(payload?: ZkSendResponsePayload): void;
38
+ }
@@ -0,0 +1,172 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __accessCheck = (obj, member, msg) => {
20
+ if (!member.has(obj))
21
+ throw TypeError("Cannot " + msg);
22
+ };
23
+ var __privateGet = (obj, member, getter) => {
24
+ __accessCheck(obj, member, "read from private field");
25
+ return getter ? getter.call(obj) : member.get(obj);
26
+ };
27
+ var __privateAdd = (obj, member, value) => {
28
+ if (member.has(obj))
29
+ throw TypeError("Cannot add the same private member more than once");
30
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31
+ };
32
+ var __privateSet = (obj, member, value, setter) => {
33
+ __accessCheck(obj, member, "write to private field");
34
+ setter ? setter.call(obj, value) : member.set(obj, value);
35
+ return value;
36
+ };
37
+ var channel_exports = {};
38
+ __export(channel_exports, {
39
+ DEFAULT_ZKSEND_ORIGIN: () => DEFAULT_ZKSEND_ORIGIN,
40
+ ZkSendHost: () => ZkSendHost,
41
+ ZkSendPopup: () => ZkSendPopup,
42
+ ZkSendRequest: () => import_events.ZkSendRequest,
43
+ ZkSendResponse: () => import_events.ZkSendResponse
44
+ });
45
+ module.exports = __toCommonJS(channel_exports);
46
+ var import_valibot = require("valibot");
47
+ var import_withResolvers = require("../utils/withResolvers.js");
48
+ var import_events = require("./events.js");
49
+ var _id, _origin, _name, _close, _request;
50
+ const DEFAULT_ZKSEND_ORIGIN = "https://zksend.com";
51
+ class ZkSendPopup {
52
+ constructor({ origin = DEFAULT_ZKSEND_ORIGIN, name }) {
53
+ __privateAdd(this, _id, void 0);
54
+ __privateAdd(this, _origin, void 0);
55
+ __privateAdd(this, _name, void 0);
56
+ __privateAdd(this, _close, void 0);
57
+ __privateSet(this, _id, crypto.randomUUID());
58
+ __privateSet(this, _origin, origin);
59
+ __privateSet(this, _name, name);
60
+ }
61
+ async createRequest(request) {
62
+ const popup = window.open("about:blank", "_blank");
63
+ if (!popup) {
64
+ throw new Error("Failed to open new window");
65
+ }
66
+ const { promise, resolve, reject } = (0, import_withResolvers.withResolvers)();
67
+ let interval = null;
68
+ function cleanup() {
69
+ if (interval) {
70
+ clearInterval(interval);
71
+ }
72
+ window.removeEventListener("message", listener);
73
+ }
74
+ const listener = (event) => {
75
+ if (event.origin !== __privateGet(this, _origin)) {
76
+ return;
77
+ }
78
+ const { success, output } = (0, import_valibot.safeParse)(import_events.ZkSendResponse, event.data);
79
+ if (!success || output.id !== __privateGet(this, _id))
80
+ return;
81
+ cleanup();
82
+ if (output.payload.type === "reject") {
83
+ reject(new Error("User rejected the request"));
84
+ } else if (output.payload.type === "resolve") {
85
+ resolve(output.payload.data);
86
+ }
87
+ };
88
+ __privateSet(this, _close, () => {
89
+ cleanup();
90
+ popup?.close();
91
+ });
92
+ window.addEventListener("message", listener);
93
+ const { type, ...data } = request;
94
+ popup?.location.assign(
95
+ `${__privateGet(this, _origin)}/dapp/${type}?${new URLSearchParams({
96
+ id: __privateGet(this, _id),
97
+ origin: window.origin,
98
+ name: __privateGet(this, _name)
99
+ })}${data ? `#${new URLSearchParams(data)}` : ""}`
100
+ );
101
+ interval = setInterval(() => {
102
+ try {
103
+ if (popup?.closed) {
104
+ cleanup();
105
+ reject(new Error("User closed the zkSend window"));
106
+ }
107
+ } catch {
108
+ }
109
+ }, 1e3);
110
+ return promise;
111
+ }
112
+ close() {
113
+ var _a;
114
+ (_a = __privateGet(this, _close)) == null ? void 0 : _a.call(this);
115
+ }
116
+ }
117
+ _id = new WeakMap();
118
+ _origin = new WeakMap();
119
+ _name = new WeakMap();
120
+ _close = new WeakMap();
121
+ const _ZkSendHost = class {
122
+ constructor(request) {
123
+ __privateAdd(this, _request, void 0);
124
+ if (typeof window === "undefined" || !window.opener) {
125
+ throw new Error(
126
+ "ZkSendHost can only be used in a window opened through `window.open`. `window.opener` is not available."
127
+ );
128
+ }
129
+ __privateSet(this, _request, request);
130
+ }
131
+ static fromUrl(url = window.location.href) {
132
+ const parsed = new URL(url);
133
+ const urlHashData = parsed.hash ? Object.fromEntries(
134
+ [...new URLSearchParams(parsed.hash.slice(1))].map(([key, value]) => [
135
+ key,
136
+ value.replace(/ /g, "+")
137
+ ])
138
+ ) : {};
139
+ const request = (0, import_valibot.parse)(import_events.ZkSendRequest, {
140
+ id: parsed.searchParams.get("id"),
141
+ origin: parsed.searchParams.get("origin"),
142
+ name: parsed.searchParams.get("name"),
143
+ payload: {
144
+ type: parsed.pathname.split("/").pop(),
145
+ ...urlHashData
146
+ }
147
+ });
148
+ return new _ZkSendHost(request);
149
+ }
150
+ getRequestData() {
151
+ return __privateGet(this, _request);
152
+ }
153
+ sendMessage(payload) {
154
+ window.opener.postMessage(
155
+ {
156
+ id: __privateGet(this, _request).id,
157
+ source: "zksend-channel",
158
+ payload
159
+ },
160
+ __privateGet(this, _request).origin
161
+ );
162
+ }
163
+ close(payload) {
164
+ if (payload) {
165
+ this.sendMessage(payload);
166
+ }
167
+ window.close();
168
+ }
169
+ };
170
+ let ZkSendHost = _ZkSendHost;
171
+ _request = new WeakMap();
172
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/channel/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Output } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../utils/withResolvers.js';\nimport type { ZkSendRequestData, ZkSendResponsePayload, ZkSendResponseTypes } from './events.js';\nimport { ZkSendRequest, ZkSendResponse } from './events.js';\n\nexport const DEFAULT_ZKSEND_ORIGIN = 'https://zksend.com';\n\nexport { ZkSendRequest, ZkSendResponse };\n\ninterface ZkSendPopupOptions {\n\torigin?: string;\n\tname: string;\n}\n\nexport class ZkSendPopup {\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\n\t#close?: () => void;\n\n\tconstructor({ origin = DEFAULT_ZKSEND_ORIGIN, name }: ZkSendPopupOptions) {\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\t}\n\n\tasync createRequest<T extends ZkSendRequestData>(\n\t\trequest: T,\n\t): Promise<ZkSendResponseTypes[T['type']]> {\n\t\tconst popup = window.open('about:blank', '_blank');\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open new window');\n\t\t}\n\n\t\tconst { promise, resolve, reject } = withResolvers<ZkSendResponseTypes[T['type']]>();\n\n\t\tlet interval: NodeJS.Timer | null = null;\n\n\t\tfunction cleanup() {\n\t\t\tif (interval) {\n\t\t\t\tclearInterval(interval);\n\t\t\t}\n\t\t\twindow.removeEventListener('message', listener);\n\t\t}\n\n\t\tconst listener = (event: MessageEvent) => {\n\t\t\tif (event.origin !== this.#origin) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { success, output } = safeParse(ZkSendResponse, event.data);\n\t\t\tif (!success || output.id !== this.#id) return;\n\n\t\t\tcleanup();\n\n\t\t\tif (output.payload.type === 'reject') {\n\t\t\t\treject(new Error('User rejected the request'));\n\t\t\t} else if (output.payload.type === 'resolve') {\n\t\t\t\tresolve(output.payload.data as ZkSendResponseTypes[T['type']]);\n\t\t\t}\n\t\t};\n\n\t\tthis.#close = () => {\n\t\t\tcleanup();\n\t\t\tpopup?.close();\n\t\t};\n\n\t\twindow.addEventListener('message', listener);\n\n\t\tconst { type, ...data } = request;\n\n\t\tpopup?.location.assign(\n\t\t\t`${this.#origin}/dapp/${type}?${new URLSearchParams({\n\t\t\t\tid: this.#id,\n\t\t\t\torigin: window.origin,\n\t\t\t\tname: this.#name,\n\t\t\t})}${data ? `#${new URLSearchParams(data as Record<string, string>)}` : ''}`,\n\t\t);\n\n\t\tinterval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (popup?.closed) {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treject(new Error('User closed the zkSend window'));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// This can error during the login flow, but that's fine.\n\t\t\t}\n\t\t}, 1000);\n\n\t\treturn promise;\n\t}\n\n\tclose() {\n\t\tthis.#close?.();\n\t}\n}\n\nexport class ZkSendHost {\n\t#request: Output<typeof ZkSendRequest>;\n\n\tconstructor(request: Output<typeof ZkSendRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'ZkSendHost can only be used in a window opened through `window.open`. `window.opener` is not available.',\n\t\t\t);\n\t\t}\n\n\t\tthis.#request = request;\n\t}\n\n\tstatic fromUrl(url: string = window.location.href) {\n\t\tconst parsed = new URL(url);\n\n\t\tconst urlHashData = parsed.hash\n\t\t\t? Object.fromEntries(\n\t\t\t\t\t[...new URLSearchParams(parsed.hash.slice(1))].map(([key, value]) => [\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tvalue.replace(/ /g, '+'),\n\t\t\t\t\t]),\n\t\t\t )\n\t\t\t: {};\n\n\t\tconst request = parse(ZkSendRequest, {\n\t\t\tid: parsed.searchParams.get('id'),\n\t\t\torigin: parsed.searchParams.get('origin'),\n\t\t\tname: parsed.searchParams.get('name'),\n\t\t\tpayload: {\n\t\t\t\ttype: parsed.pathname.split('/').pop(),\n\t\t\t\t...urlHashData,\n\t\t\t},\n\t\t});\n\n\t\treturn new ZkSendHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: ZkSendResponsePayload) {\n\t\twindow.opener.postMessage(\n\t\t\t{\n\t\t\t\tid: this.#request.id,\n\t\t\t\tsource: 'zksend-channel',\n\t\t\t\tpayload,\n\t\t\t} satisfies ZkSendResponse,\n\t\t\tthis.#request.origin,\n\t\t);\n\t}\n\n\tclose(payload?: ZkSendResponsePayload) {\n\t\tif (payload) {\n\t\t\tthis.sendMessage(payload);\n\t\t}\n\t\twindow.close();\n\t}\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from './links.js';
2
+ export * from './wallet.js';
3
+ export * from './channel/index.js';