@mysten/zksend 0.9.10 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +40 -6
  2. package/dist/cjs/links/builder.js +43 -57
  3. package/dist/cjs/links/builder.js.map +2 -2
  4. package/dist/cjs/links/claim.js +39 -68
  5. package/dist/cjs/links/claim.js.map +2 -2
  6. package/dist/cjs/links/get-sent-transactions.js.map +2 -2
  7. package/dist/cjs/links/list-created-links.js.map +1 -1
  8. package/dist/cjs/links/zk-bag.d.ts +14 -14
  9. package/dist/cjs/links/zk-bag.js +59 -62
  10. package/dist/cjs/links/zk-bag.js.map +2 -2
  11. package/dist/cjs/wallet/channel/events.d.ts +78 -283
  12. package/dist/cjs/wallet/channel/events.js +3 -3
  13. package/dist/cjs/wallet/channel/events.js.map +2 -2
  14. package/dist/cjs/wallet/channel/index.d.ts +3 -3
  15. package/dist/cjs/wallet/channel/index.js +25 -40
  16. package/dist/cjs/wallet/channel/index.js.map +2 -2
  17. package/dist/cjs/wallet/index.js +19 -33
  18. package/dist/cjs/wallet/index.js.map +1 -1
  19. package/dist/esm/links/builder.js +42 -56
  20. package/dist/esm/links/builder.js.map +2 -2
  21. package/dist/esm/links/claim.js +38 -67
  22. package/dist/esm/links/claim.js.map +2 -2
  23. package/dist/esm/links/get-sent-transactions.js.map +2 -2
  24. package/dist/esm/links/list-created-links.js.map +1 -1
  25. package/dist/esm/links/zk-bag.d.ts +14 -14
  26. package/dist/esm/links/zk-bag.js +58 -61
  27. package/dist/esm/links/zk-bag.js.map +2 -2
  28. package/dist/esm/wallet/channel/events.d.ts +78 -283
  29. package/dist/esm/wallet/channel/events.js +4 -4
  30. package/dist/esm/wallet/channel/events.js.map +2 -2
  31. package/dist/esm/wallet/channel/index.d.ts +3 -3
  32. package/dist/esm/wallet/channel/index.js +24 -39
  33. package/dist/esm/wallet/channel/index.js.map +2 -2
  34. package/dist/esm/wallet/index.js +18 -32
  35. package/dist/esm/wallet/index.js.map +1 -1
  36. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +8 -8
@@ -1,291 +1,86 @@
1
- import type { Output } from 'valibot';
1
+ import type { InferOutput } from 'valibot';
2
2
  export declare const StashedRequestData: 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
- address: string;
13
- data: 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
- bytes: string;
21
- address: string;
22
- }>], {
23
- type: "connect";
24
- } | {
25
- type: "sign-transaction-block";
26
- address: string;
27
- data: string;
28
- } | {
29
- type: "sign-personal-message";
30
- bytes: string;
31
- address: string;
32
- }>;
33
- export type StashedRequestData = Output<typeof StashedRequestData>;
3
+ readonly type: import("valibot").LiteralSchema<"connect", undefined>;
4
+ }, undefined>, import("valibot").ObjectSchema<{
5
+ readonly type: import("valibot").LiteralSchema<"sign-transaction-block", undefined>;
6
+ readonly data: import("valibot").StringSchema<"`data` is required">;
7
+ readonly address: import("valibot").StringSchema<"`address` is required">;
8
+ }, undefined>, import("valibot").ObjectSchema<{
9
+ readonly type: import("valibot").LiteralSchema<"sign-personal-message", undefined>;
10
+ readonly bytes: import("valibot").StringSchema<"`bytes` is required">;
11
+ readonly address: import("valibot").StringSchema<"`address` is required">;
12
+ }, undefined>], undefined>;
13
+ export type StashedRequestData = InferOutput<typeof StashedRequestData>;
34
14
  export declare const StashedRequest: 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
- address: string;
49
- data: 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
- bytes: string;
57
- address: string;
58
- }>], {
59
- type: "connect";
60
- } | {
61
- type: "sign-transaction-block";
62
- address: string;
63
- data: string;
64
- } | {
65
- type: "sign-personal-message";
66
- bytes: string;
67
- address: string;
68
- }>;
69
- }, undefined, {
70
- origin: string;
71
- id: string;
72
- payload: {
73
- type: "connect";
74
- } | {
75
- type: "sign-transaction-block";
76
- address: string;
77
- data: string;
78
- } | {
79
- type: "sign-personal-message";
80
- bytes: string;
81
- address: string;
82
- };
83
- name?: string | undefined;
84
- }>;
85
- export type StashedRequest = Output<typeof StashedRequest>;
15
+ readonly id: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"`id` is required">, import("valibot").UuidAction<string, undefined>]>;
16
+ readonly origin: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UrlAction<string, "`origin` must be a valid URL">]>;
17
+ readonly name: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, never>;
18
+ readonly payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
19
+ readonly type: import("valibot").LiteralSchema<"connect", undefined>;
20
+ }, undefined>, import("valibot").ObjectSchema<{
21
+ readonly type: import("valibot").LiteralSchema<"sign-transaction-block", undefined>;
22
+ readonly data: import("valibot").StringSchema<"`data` is required">;
23
+ readonly address: import("valibot").StringSchema<"`address` is required">;
24
+ }, undefined>, import("valibot").ObjectSchema<{
25
+ readonly type: import("valibot").LiteralSchema<"sign-personal-message", undefined>;
26
+ readonly bytes: import("valibot").StringSchema<"`bytes` is required">;
27
+ readonly address: import("valibot").StringSchema<"`address` is required">;
28
+ }, undefined>], undefined>;
29
+ }, undefined>;
30
+ export type StashedRequest = InferOutput<typeof StashedRequest>;
86
31
  export declare const StashedResponseData: 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
- type: "sign-transaction-block";
98
- bytes: string;
99
- signature: 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
- type: "sign-personal-message";
106
- bytes: string;
107
- signature: string;
108
- }>], {
109
- type: "connect";
110
- address: string;
111
- } | {
112
- type: "sign-transaction-block";
113
- bytes: string;
114
- signature: string;
115
- } | {
116
- type: "sign-personal-message";
117
- bytes: string;
118
- signature: string;
119
- }>;
120
- export type StashedResponseData = Output<typeof StashedResponseData>;
32
+ readonly type: import("valibot").LiteralSchema<"connect", undefined>;
33
+ readonly address: import("valibot").StringSchema<undefined>;
34
+ }, undefined>, import("valibot").ObjectSchema<{
35
+ readonly type: import("valibot").LiteralSchema<"sign-transaction-block", undefined>;
36
+ readonly bytes: import("valibot").StringSchema<undefined>;
37
+ readonly signature: import("valibot").StringSchema<undefined>;
38
+ }, undefined>, import("valibot").ObjectSchema<{
39
+ readonly type: import("valibot").LiteralSchema<"sign-personal-message", undefined>;
40
+ readonly bytes: import("valibot").StringSchema<undefined>;
41
+ readonly signature: import("valibot").StringSchema<undefined>;
42
+ }, undefined>], undefined>;
43
+ export type StashedResponseData = InferOutput<typeof StashedResponseData>;
121
44
  export declare const StashedResponsePayload: 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
- type: "sign-transaction-block";
139
- bytes: string;
140
- signature: 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
- type: "sign-personal-message";
147
- bytes: string;
148
- signature: string;
149
- }>], {
150
- type: "connect";
151
- address: string;
152
- } | {
153
- type: "sign-transaction-block";
154
- bytes: string;
155
- signature: string;
156
- } | {
157
- type: "sign-personal-message";
158
- bytes: string;
159
- signature: string;
160
- }>;
161
- }, undefined, {
162
- type: "resolve";
163
- data: {
164
- type: "connect";
165
- address: string;
166
- } | {
167
- type: "sign-transaction-block";
168
- bytes: string;
169
- signature: string;
170
- } | {
171
- type: "sign-personal-message";
172
- bytes: string;
173
- signature: string;
174
- };
175
- }>], {
176
- type: "reject";
177
- } | {
178
- type: "resolve";
179
- data: {
180
- type: "connect";
181
- address: string;
182
- } | {
183
- type: "sign-transaction-block";
184
- bytes: string;
185
- signature: string;
186
- } | {
187
- type: "sign-personal-message";
188
- bytes: string;
189
- signature: string;
190
- };
191
- }>;
192
- export type StashedResponsePayload = Output<typeof StashedResponsePayload>;
45
+ readonly type: import("valibot").LiteralSchema<"reject", undefined>;
46
+ }, undefined>, import("valibot").ObjectSchema<{
47
+ readonly type: import("valibot").LiteralSchema<"resolve", undefined>;
48
+ readonly data: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
49
+ readonly type: import("valibot").LiteralSchema<"connect", undefined>;
50
+ readonly address: import("valibot").StringSchema<undefined>;
51
+ }, undefined>, import("valibot").ObjectSchema<{
52
+ readonly type: import("valibot").LiteralSchema<"sign-transaction-block", undefined>;
53
+ readonly bytes: import("valibot").StringSchema<undefined>;
54
+ readonly signature: import("valibot").StringSchema<undefined>;
55
+ }, undefined>, import("valibot").ObjectSchema<{
56
+ readonly type: import("valibot").LiteralSchema<"sign-personal-message", undefined>;
57
+ readonly bytes: import("valibot").StringSchema<undefined>;
58
+ readonly signature: import("valibot").StringSchema<undefined>;
59
+ }, undefined>], undefined>;
60
+ }, undefined>], undefined>;
61
+ export type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;
193
62
  export declare const StashedResponse: 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
- type: "sign-transaction-block";
214
- bytes: string;
215
- signature: 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
- type: "sign-personal-message";
222
- bytes: string;
223
- signature: string;
224
- }>], {
225
- type: "connect";
226
- address: string;
227
- } | {
228
- type: "sign-transaction-block";
229
- bytes: string;
230
- signature: string;
231
- } | {
232
- type: "sign-personal-message";
233
- bytes: string;
234
- signature: string;
235
- }>;
236
- }, undefined, {
237
- type: "resolve";
238
- data: {
239
- type: "connect";
240
- address: string;
241
- } | {
242
- type: "sign-transaction-block";
243
- bytes: string;
244
- signature: string;
245
- } | {
246
- type: "sign-personal-message";
247
- bytes: string;
248
- signature: string;
249
- };
250
- }>], {
251
- type: "reject";
252
- } | {
253
- type: "resolve";
254
- data: {
255
- type: "connect";
256
- address: string;
257
- } | {
258
- type: "sign-transaction-block";
259
- bytes: string;
260
- signature: string;
261
- } | {
262
- type: "sign-personal-message";
263
- bytes: string;
264
- signature: 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
- type: "sign-transaction-block";
278
- bytes: string;
279
- signature: string;
280
- } | {
281
- type: "sign-personal-message";
282
- bytes: string;
283
- signature: string;
284
- };
285
- };
286
- source: "zksend-channel";
287
- }>;
288
- export type StashedResponse = Output<typeof StashedResponse>;
63
+ readonly id: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UuidAction<string, undefined>]>;
64
+ readonly source: import("valibot").LiteralSchema<"zksend-channel", undefined>;
65
+ readonly payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
66
+ readonly type: import("valibot").LiteralSchema<"reject", undefined>;
67
+ }, undefined>, import("valibot").ObjectSchema<{
68
+ readonly type: import("valibot").LiteralSchema<"resolve", undefined>;
69
+ readonly data: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
70
+ readonly type: import("valibot").LiteralSchema<"connect", undefined>;
71
+ readonly address: import("valibot").StringSchema<undefined>;
72
+ }, undefined>, import("valibot").ObjectSchema<{
73
+ readonly type: import("valibot").LiteralSchema<"sign-transaction-block", undefined>;
74
+ readonly bytes: import("valibot").StringSchema<undefined>;
75
+ readonly signature: import("valibot").StringSchema<undefined>;
76
+ }, undefined>, import("valibot").ObjectSchema<{
77
+ readonly type: import("valibot").LiteralSchema<"sign-personal-message", undefined>;
78
+ readonly bytes: import("valibot").StringSchema<undefined>;
79
+ readonly signature: import("valibot").StringSchema<undefined>;
80
+ }, undefined>], undefined>;
81
+ }, undefined>], undefined>;
82
+ }, undefined>;
83
+ export type StashedResponse = InferOutput<typeof StashedResponse>;
289
84
  export type StashedRequestTypes = Record<string, any> & {
290
85
  [P in StashedRequestData as P['type']]: P;
291
86
  };
@@ -1,4 +1,4 @@
1
- import { literal, object, optional, string, url, uuid, variant } from "valibot";
1
+ import { literal, object, optional, pipe, string, url, uuid, variant } from "valibot";
2
2
  const StashedRequestData = variant("type", [
3
3
  object({
4
4
  type: literal("connect")
@@ -15,8 +15,8 @@ const StashedRequestData = variant("type", [
15
15
  })
16
16
  ]);
17
17
  const StashedRequest = object({
18
- id: string("`id` is required", [uuid()]),
19
- origin: string([url("`origin` must be a valid URL")]),
18
+ id: pipe(string("`id` is required"), uuid()),
19
+ origin: pipe(string(), url("`origin` must be a valid URL")),
20
20
  name: optional(string()),
21
21
  payload: StashedRequestData
22
22
  });
@@ -46,7 +46,7 @@ const StashedResponsePayload = variant("type", [
46
46
  })
47
47
  ]);
48
48
  const StashedResponse = object({
49
- id: string([uuid()]),
49
+ id: pipe(string(), uuid()),
50
50
  source: literal("zksend-channel"),
51
51
  payload: StashedResponsePayload
52
52
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/wallet/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 StashedRequestData = 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 StashedRequestData = Output<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: string('`id` is required', [uuid()]),\n\torigin: string([url('`origin` must be a valid URL')]),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = Output<typeof StashedRequest>;\n\nexport const StashedResponseData = 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 StashedResponseData = Output<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = Output<typeof StashedResponsePayload>;\n\nexport const StashedResponse = object({\n\tid: string([uuid()]),\n\tsource: literal('zksend-channel'),\n\tpayload: StashedResponsePayload,\n});\nexport type StashedResponse = Output<typeof StashedResponse>;\n\nexport type StashedRequestTypes = Record<string, any> & {\n\t[P in StashedRequestData as P['type']]: P;\n};\n\nexport type StashedResponseTypes = {\n\t[P in StashedResponseData as P['type']]: P;\n};\n"],
5
- "mappings": "AAIA,SAAS,SAAS,QAAQ,UAAU,QAAQ,KAAK,MAAM,eAAe;AAE/D,MAAM,qBAAqB,QAAQ,QAAQ;AAAA,EACjD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,EACxB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,MAAM,OAAO,oBAAoB;AAAA,IACjC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO,qBAAqB;AAAA,IACnC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AACF,CAAC;AAGM,MAAM,iBAAiB,OAAO;AAAA,EACpC,IAAI,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAAA,EACvC,QAAQ,OAAO,CAAC,IAAI,8BAA8B,CAAC,CAAC;AAAA,EACpD,MAAM,SAAS,OAAO,CAAC;AAAA,EACvB,SAAS;AACV,CAAC;AAIM,MAAM,sBAAsB,QAAQ,QAAQ;AAAA,EAClD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,SAAS,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AACF,CAAC;AAGM,MAAM,yBAAyB,QAAQ,QAAQ;AAAA,EACrD,OAAO;AAAA,IACN,MAAM,QAAQ,QAAQ;AAAA,EACvB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,kBAAkB,OAAO;AAAA,EACrC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,EACnB,QAAQ,QAAQ,gBAAgB;AAAA,EAChC,SAAS;AACV,CAAC;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { literal, object, optional, pipe, string, url, uuid, variant } from 'valibot';\n\nexport const StashedRequestData = 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 StashedRequestData = InferOutput<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: pipe(string('`id` is required'), uuid()),\n\torigin: pipe(string(), url('`origin` must be a valid URL')),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = InferOutput<typeof StashedRequest>;\n\nexport const StashedResponseData = 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 StashedResponseData = InferOutput<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;\n\nexport const StashedResponse = object({\n\tid: pipe(string(), uuid()),\n\tsource: literal('zksend-channel'),\n\tpayload: StashedResponsePayload,\n});\nexport type StashedResponse = InferOutput<typeof StashedResponse>;\n\nexport type StashedRequestTypes = Record<string, any> & {\n\t[P in StashedRequestData as P['type']]: P;\n};\n\nexport type StashedResponseTypes = {\n\t[P in StashedResponseData as P['type']]: P;\n};\n"],
5
+ "mappings": "AAIA,SAAS,SAAS,QAAQ,UAAU,MAAM,QAAQ,KAAK,MAAM,eAAe;AAErE,MAAM,qBAAqB,QAAQ,QAAQ;AAAA,EACjD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,EACxB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,MAAM,OAAO,oBAAoB;AAAA,IACjC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO,qBAAqB;AAAA,IACnC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AACF,CAAC;AAGM,MAAM,iBAAiB,OAAO;AAAA,EACpC,IAAI,KAAK,OAAO,kBAAkB,GAAG,KAAK,CAAC;AAAA,EAC3C,QAAQ,KAAK,OAAO,GAAG,IAAI,8BAA8B,CAAC;AAAA,EAC1D,MAAM,SAAS,OAAO,CAAC;AAAA,EACvB,SAAS;AACV,CAAC;AAIM,MAAM,sBAAsB,QAAQ,QAAQ;AAAA,EAClD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,SAAS,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AACF,CAAC;AAGM,MAAM,yBAAyB,QAAQ,QAAQ;AAAA,EACrD,OAAO;AAAA,IACN,MAAM,QAAQ,QAAQ;AAAA,EACvB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,kBAAkB,OAAO;AAAA,EACrC,IAAI,KAAK,OAAO,GAAG,KAAK,CAAC;AAAA,EACzB,QAAQ,QAAQ,gBAAgB;AAAA,EAChC,SAAS;AACV,CAAC;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { Output } from 'valibot';
1
+ import type { InferOutput } from 'valibot';
2
2
  import type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';
3
3
  import { StashedRequest, StashedResponse } from './events.js';
4
4
  export declare const DEFAULT_STASHED_ORIGIN = "https://getstashed.com";
@@ -18,11 +18,11 @@ export declare class StashedPopup {
18
18
  }
19
19
  export declare class StashedHost {
20
20
  #private;
21
- constructor(request: Output<typeof StashedRequest>);
21
+ constructor(request: InferOutput<typeof StashedRequest>);
22
22
  static fromUrl(url?: string): StashedHost;
23
23
  getRequestData(): {
24
- origin: string;
25
24
  id: string;
25
+ origin: string;
26
26
  payload: {
27
27
  type: "connect";
28
28
  } | {
@@ -1,49 +1,34 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
4
3
  };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
22
- };
23
- var _popup, _id, _origin, _name, _promise, _resolve, _reject, _interval, _listener, _cleanup, cleanup_fn, _request;
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 _popup, _id, _origin, _name, _promise, _resolve, _reject, _interval, _listener, _StashedPopup_instances, cleanup_fn, _request;
24
10
  import { parse, safeParse } from "valibot";
25
11
  import { withResolvers } from "../../utils/withResolvers.js";
26
12
  import { StashedRequest, StashedResponse } from "./events.js";
27
13
  const DEFAULT_STASHED_ORIGIN = "https://getstashed.com";
28
14
  class StashedPopup {
29
15
  constructor({ name, origin = DEFAULT_STASHED_ORIGIN }) {
30
- __privateAdd(this, _cleanup);
31
- __privateAdd(this, _popup, void 0);
32
- __privateAdd(this, _id, void 0);
33
- __privateAdd(this, _origin, void 0);
34
- __privateAdd(this, _name, void 0);
35
- __privateAdd(this, _promise, void 0);
36
- __privateAdd(this, _resolve, void 0);
37
- __privateAdd(this, _reject, void 0);
16
+ __privateAdd(this, _StashedPopup_instances);
17
+ __privateAdd(this, _popup);
18
+ __privateAdd(this, _id);
19
+ __privateAdd(this, _origin);
20
+ __privateAdd(this, _name);
21
+ __privateAdd(this, _promise);
22
+ __privateAdd(this, _resolve);
23
+ __privateAdd(this, _reject);
38
24
  __privateAdd(this, _interval, null);
39
25
  __privateAdd(this, _listener, (event) => {
40
26
  if (event.origin !== __privateGet(this, _origin)) {
41
27
  return;
42
28
  }
43
29
  const { success, output } = safeParse(StashedResponse, event.data);
44
- if (!success || output.id !== __privateGet(this, _id))
45
- return;
46
- __privateMethod(this, _cleanup, cleanup_fn).call(this);
30
+ if (!success || output.id !== __privateGet(this, _id)) return;
31
+ __privateMethod(this, _StashedPopup_instances, cleanup_fn).call(this);
47
32
  if (output.payload.type === "reject") {
48
33
  __privateGet(this, _reject).call(this, new Error("User rejected the request"));
49
34
  } else if (output.payload.type === "resolve") {
@@ -65,7 +50,7 @@ class StashedPopup {
65
50
  __privateSet(this, _interval, setInterval(() => {
66
51
  try {
67
52
  if (__privateGet(this, _popup).closed) {
68
- __privateMethod(this, _cleanup, cleanup_fn).call(this);
53
+ __privateMethod(this, _StashedPopup_instances, cleanup_fn).call(this);
69
54
  reject(new Error("User closed the Stashed window"));
70
55
  }
71
56
  } catch {
@@ -87,7 +72,7 @@ class StashedPopup {
87
72
  return __privateGet(this, _promise);
88
73
  }
89
74
  close() {
90
- __privateMethod(this, _cleanup, cleanup_fn).call(this);
75
+ __privateMethod(this, _StashedPopup_instances, cleanup_fn).call(this);
91
76
  __privateGet(this, _popup).close();
92
77
  }
93
78
  }
@@ -100,7 +85,7 @@ _resolve = new WeakMap();
100
85
  _reject = new WeakMap();
101
86
  _interval = new WeakMap();
102
87
  _listener = new WeakMap();
103
- _cleanup = new WeakSet();
88
+ _StashedPopup_instances = new WeakSet();
104
89
  cleanup_fn = function() {
105
90
  if (__privateGet(this, _interval)) {
106
91
  clearInterval(__privateGet(this, _interval));
@@ -108,9 +93,9 @@ cleanup_fn = function() {
108
93
  }
109
94
  window.removeEventListener("message", __privateGet(this, _listener));
110
95
  };
111
- const _StashedHost = class {
96
+ const _StashedHost = class _StashedHost {
112
97
  constructor(request) {
113
- __privateAdd(this, _request, void 0);
98
+ __privateAdd(this, _request);
114
99
  if (typeof window === "undefined" || !window.opener) {
115
100
  throw new Error(
116
101
  "StashedHost can only be used in a window opened through `window.open`. `window.opener` is not available."
@@ -157,8 +142,8 @@ const _StashedHost = class {
157
142
  window.close();
158
143
  }
159
144
  };
160
- let StashedHost = _StashedHost;
161
145
  _request = new WeakMap();
146
+ let StashedHost = _StashedHost;
162
147
  export {
163
148
  DEFAULT_STASHED_ORIGIN,
164
149
  StashedHost,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/wallet/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 { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({ name, origin = DEFAULT_STASHED_ORIGIN }: { name: string; origin?: string }) {\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\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed 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\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.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 never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: Output<typeof StashedRequest>;\n\n\tconstructor(request: Output<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost 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(StashedRequest, {\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 StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\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 StashedResponse,\n\t\t\tthis.#request.origin,\n\t\t);\n\t}\n\n\tclose(payload?: StashedResponsePayload) {\n\t\tif (payload) {\n\t\t\tthis.sendMessage(payload);\n\t\t}\n\t\twindow.close();\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAIA,SAAS,OAAO,iBAAiB;AAEjC,SAAS,qBAAqB;AAE9B,SAAS,gBAAgB,uBAAuB;AAEzC,MAAM,yBAAyB;AAI/B,MAAM,aAAa;AAAA,EAazB,YAAY,EAAE,MAAM,SAAS,uBAAuB,GAAsC;AAoE1F;AAhFA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA,kCAAmD;AAsDnD,kCAAY,CAAC,UAAwB;AACpC,UAAI,MAAM,WAAW,mBAAK,UAAS;AAClC;AAAA,MACD;AACA,Y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AAAA,QAClB,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,MACA,mBAAK,UAAS;AAAA,IACf;AAAA,EACD;AAAA,EAEA,MAAM,SAAkC;AACvC,QAAI,SAAS;AACZ,WAAK,YAAY,OAAO;AAAA,IACzB;AACA,WAAO,MAAM;AAAA,EACd;AACD;AA3DO,IAAM,cAAN;AACN;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../../utils/withResolvers.js';\nimport type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({ name, origin = DEFAULT_STASHED_ORIGIN }: { name: string; origin?: string }) {\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\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed 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\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.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 never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: InferOutput<typeof StashedRequest>;\n\n\tconstructor(request: InferOutput<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost 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\t)\n\t\t\t: {};\n\n\t\tconst request = parse(StashedRequest, {\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 StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\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 StashedResponse,\n\t\t\tthis.#request.origin,\n\t\t);\n\t}\n\n\tclose(payload?: StashedResponsePayload) {\n\t\tif (payload) {\n\t\t\tthis.sendMessage(payload);\n\t\t}\n\t\twindow.close();\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;AAAA;AAIA,SAAS,OAAO,iBAAiB;AAEjC,SAAS,qBAAqB;AAE9B,SAAS,gBAAgB,uBAAuB;AAEzC,MAAM,yBAAyB;AAI/B,MAAM,aAAa;AAAA,EAazB,YAAY,EAAE,MAAM,SAAS,uBAAuB,GAAsC;AAbpF;AACN;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA,kCAAmD;AAsDnD,kCAAY,CAAC,UAAwB;AACpC,UAAI,MAAM,WAAW,mBAAK,UAAS;AAClC;AAAA,MACD;AACA,YAAM,EAAE,SAAS,OAAO,IAAI,UAAU,iBAAiB,MAAM,IAAI;AACjE,UAAI,CAAC,WAAW,OAAO,OAAO,mBAAK,KAAK;AAExC,4BAAK,qCAAL;AAEA,UAAI,OAAO,QAAQ,SAAS,UAAU;AACrC,2BAAK,SAAL,WAAa,IAAI,MAAM,2BAA2B;AAAA,MACnD,WA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