@mysten/zksend 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/channel/events.d.ts +54 -54
- package/dist/cjs/channel/index.d.ts +4 -4
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.test.d.ts +9 -1
- package/dist/cjs/links/builder.d.ts +41 -0
- package/dist/cjs/links/builder.js +264 -0
- package/dist/cjs/links/builder.js.map +7 -0
- package/dist/cjs/links/claim.d.ts +77 -0
- package/dist/cjs/links/claim.js +520 -0
- package/dist/cjs/links/claim.js.map +7 -0
- package/dist/cjs/links/utils.d.ts +17 -0
- package/dist/cjs/links/utils.js +133 -0
- package/dist/cjs/links/utils.js.map +7 -0
- package/dist/cjs/links/zk-bag.d.ts +79 -0
- package/dist/cjs/links/zk-bag.js +129 -0
- package/dist/cjs/links/zk-bag.js.map +7 -0
- package/dist/esm/channel/events.d.ts +54 -54
- package/dist/esm/channel/index.d.ts +4 -4
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +11 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.test.d.ts +9 -1
- package/dist/esm/links/builder.d.ts +41 -0
- package/dist/esm/links/builder.js +244 -0
- package/dist/esm/links/builder.js.map +7 -0
- package/dist/esm/links/claim.d.ts +77 -0
- package/dist/esm/links/claim.js +508 -0
- package/dist/esm/links/claim.js.map +7 -0
- package/dist/esm/links/utils.d.ts +17 -0
- package/dist/esm/links/utils.js +113 -0
- package/dist/esm/links/utils.js.map +7 -0
- package/dist/esm/links/zk-bag.d.ts +79 -0
- package/dist/esm/links/zk-bag.js +109 -0
- package/dist/esm/links/zk-bag.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/dist/cjs/links.d.ts +0 -80
- package/dist/cjs/links.js +0 -374
- package/dist/cjs/links.js.map +0 -7
- package/dist/esm/links.d.ts +0 -80
- package/dist/esm/links.js +0 -362
- package/dist/esm/links.js.map +0 -7
|
@@ -8,27 +8,27 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
|
|
|
8
8
|
data: import("valibot").StringSchema<string>;
|
|
9
9
|
address: import("valibot").StringSchema<string>;
|
|
10
10
|
}, undefined, {
|
|
11
|
-
type: "sign-transaction-block";
|
|
12
|
-
data: string;
|
|
13
11
|
address: string;
|
|
12
|
+
data: string;
|
|
13
|
+
type: "sign-transaction-block";
|
|
14
14
|
}>, import("valibot").ObjectSchema<{
|
|
15
15
|
type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
|
|
16
16
|
bytes: import("valibot").StringSchema<string>;
|
|
17
17
|
address: import("valibot").StringSchema<string>;
|
|
18
18
|
}, undefined, {
|
|
19
|
-
type: "sign-personal-message";
|
|
20
19
|
address: string;
|
|
21
20
|
bytes: string;
|
|
21
|
+
type: "sign-personal-message";
|
|
22
22
|
}>], {
|
|
23
23
|
type: "connect";
|
|
24
24
|
} | {
|
|
25
|
-
type: "sign-transaction-block";
|
|
26
|
-
data: string;
|
|
27
25
|
address: string;
|
|
26
|
+
data: string;
|
|
27
|
+
type: "sign-transaction-block";
|
|
28
28
|
} | {
|
|
29
|
-
type: "sign-personal-message";
|
|
30
29
|
address: string;
|
|
31
30
|
bytes: string;
|
|
31
|
+
type: "sign-personal-message";
|
|
32
32
|
}>;
|
|
33
33
|
export type ZkSendRequestData = Output<typeof ZkSendRequestData>;
|
|
34
34
|
export declare const ZkSendRequest: import("valibot").ObjectSchema<{
|
|
@@ -44,41 +44,41 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
|
|
|
44
44
|
data: import("valibot").StringSchema<string>;
|
|
45
45
|
address: import("valibot").StringSchema<string>;
|
|
46
46
|
}, undefined, {
|
|
47
|
-
type: "sign-transaction-block";
|
|
48
|
-
data: string;
|
|
49
47
|
address: string;
|
|
48
|
+
data: string;
|
|
49
|
+
type: "sign-transaction-block";
|
|
50
50
|
}>, import("valibot").ObjectSchema<{
|
|
51
51
|
type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
|
|
52
52
|
bytes: import("valibot").StringSchema<string>;
|
|
53
53
|
address: import("valibot").StringSchema<string>;
|
|
54
54
|
}, undefined, {
|
|
55
|
-
type: "sign-personal-message";
|
|
56
55
|
address: string;
|
|
57
56
|
bytes: string;
|
|
57
|
+
type: "sign-personal-message";
|
|
58
58
|
}>], {
|
|
59
59
|
type: "connect";
|
|
60
60
|
} | {
|
|
61
|
-
type: "sign-transaction-block";
|
|
62
|
-
data: string;
|
|
63
61
|
address: string;
|
|
62
|
+
data: string;
|
|
63
|
+
type: "sign-transaction-block";
|
|
64
64
|
} | {
|
|
65
|
-
type: "sign-personal-message";
|
|
66
65
|
address: string;
|
|
67
66
|
bytes: string;
|
|
67
|
+
type: "sign-personal-message";
|
|
68
68
|
}>;
|
|
69
69
|
}, undefined, {
|
|
70
|
-
origin: string;
|
|
71
70
|
id: string;
|
|
71
|
+
origin: string;
|
|
72
72
|
payload: {
|
|
73
73
|
type: "connect";
|
|
74
74
|
} | {
|
|
75
|
-
type: "sign-transaction-block";
|
|
76
|
-
data: string;
|
|
77
75
|
address: string;
|
|
76
|
+
data: string;
|
|
77
|
+
type: "sign-transaction-block";
|
|
78
78
|
} | {
|
|
79
|
-
type: "sign-personal-message";
|
|
80
79
|
address: string;
|
|
81
80
|
bytes: string;
|
|
81
|
+
type: "sign-personal-message";
|
|
82
82
|
};
|
|
83
83
|
name?: string | undefined;
|
|
84
84
|
}>;
|
|
@@ -87,35 +87,35 @@ export declare const ZkSendResponseData: import("valibot").VariantSchema<"type",
|
|
|
87
87
|
type: import("valibot").LiteralSchema<"connect", "connect">;
|
|
88
88
|
address: import("valibot").StringSchema<string>;
|
|
89
89
|
}, undefined, {
|
|
90
|
-
type: "connect";
|
|
91
90
|
address: string;
|
|
91
|
+
type: "connect";
|
|
92
92
|
}>, import("valibot").ObjectSchema<{
|
|
93
93
|
type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
|
|
94
94
|
bytes: import("valibot").StringSchema<string>;
|
|
95
95
|
signature: import("valibot").StringSchema<string>;
|
|
96
96
|
}, undefined, {
|
|
97
97
|
signature: string;
|
|
98
|
-
type: "sign-transaction-block";
|
|
99
98
|
bytes: string;
|
|
99
|
+
type: "sign-transaction-block";
|
|
100
100
|
}>, import("valibot").ObjectSchema<{
|
|
101
101
|
type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
|
|
102
102
|
bytes: import("valibot").StringSchema<string>;
|
|
103
103
|
signature: import("valibot").StringSchema<string>;
|
|
104
104
|
}, undefined, {
|
|
105
105
|
signature: string;
|
|
106
|
-
type: "sign-personal-message";
|
|
107
106
|
bytes: string;
|
|
107
|
+
type: "sign-personal-message";
|
|
108
108
|
}>], {
|
|
109
|
-
type: "connect";
|
|
110
109
|
address: string;
|
|
110
|
+
type: "connect";
|
|
111
111
|
} | {
|
|
112
112
|
signature: string;
|
|
113
|
-
type: "sign-transaction-block";
|
|
114
113
|
bytes: string;
|
|
114
|
+
type: "sign-transaction-block";
|
|
115
115
|
} | {
|
|
116
116
|
signature: string;
|
|
117
|
-
type: "sign-personal-message";
|
|
118
117
|
bytes: string;
|
|
118
|
+
type: "sign-personal-message";
|
|
119
119
|
}>;
|
|
120
120
|
export type ZkSendResponseData = Output<typeof ZkSendResponseData>;
|
|
121
121
|
export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
|
|
@@ -128,66 +128,66 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
|
|
|
128
128
|
type: import("valibot").LiteralSchema<"connect", "connect">;
|
|
129
129
|
address: import("valibot").StringSchema<string>;
|
|
130
130
|
}, undefined, {
|
|
131
|
-
type: "connect";
|
|
132
131
|
address: string;
|
|
132
|
+
type: "connect";
|
|
133
133
|
}>, import("valibot").ObjectSchema<{
|
|
134
134
|
type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
|
|
135
135
|
bytes: import("valibot").StringSchema<string>;
|
|
136
136
|
signature: import("valibot").StringSchema<string>;
|
|
137
137
|
}, undefined, {
|
|
138
138
|
signature: string;
|
|
139
|
-
type: "sign-transaction-block";
|
|
140
139
|
bytes: string;
|
|
140
|
+
type: "sign-transaction-block";
|
|
141
141
|
}>, import("valibot").ObjectSchema<{
|
|
142
142
|
type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
|
|
143
143
|
bytes: import("valibot").StringSchema<string>;
|
|
144
144
|
signature: import("valibot").StringSchema<string>;
|
|
145
145
|
}, undefined, {
|
|
146
146
|
signature: string;
|
|
147
|
-
type: "sign-personal-message";
|
|
148
147
|
bytes: string;
|
|
148
|
+
type: "sign-personal-message";
|
|
149
149
|
}>], {
|
|
150
|
-
type: "connect";
|
|
151
150
|
address: string;
|
|
151
|
+
type: "connect";
|
|
152
152
|
} | {
|
|
153
153
|
signature: string;
|
|
154
|
-
type: "sign-transaction-block";
|
|
155
154
|
bytes: string;
|
|
155
|
+
type: "sign-transaction-block";
|
|
156
156
|
} | {
|
|
157
157
|
signature: string;
|
|
158
|
-
type: "sign-personal-message";
|
|
159
158
|
bytes: string;
|
|
159
|
+
type: "sign-personal-message";
|
|
160
160
|
}>;
|
|
161
161
|
}, undefined, {
|
|
162
|
-
type: "resolve";
|
|
163
162
|
data: {
|
|
164
|
-
type: "connect";
|
|
165
163
|
address: string;
|
|
164
|
+
type: "connect";
|
|
166
165
|
} | {
|
|
167
166
|
signature: string;
|
|
168
|
-
type: "sign-transaction-block";
|
|
169
167
|
bytes: string;
|
|
168
|
+
type: "sign-transaction-block";
|
|
170
169
|
} | {
|
|
171
170
|
signature: string;
|
|
172
|
-
type: "sign-personal-message";
|
|
173
171
|
bytes: string;
|
|
172
|
+
type: "sign-personal-message";
|
|
174
173
|
};
|
|
174
|
+
type: "resolve";
|
|
175
175
|
}>], {
|
|
176
176
|
type: "reject";
|
|
177
177
|
} | {
|
|
178
|
-
type: "resolve";
|
|
179
178
|
data: {
|
|
180
|
-
type: "connect";
|
|
181
179
|
address: string;
|
|
180
|
+
type: "connect";
|
|
182
181
|
} | {
|
|
183
182
|
signature: string;
|
|
184
|
-
type: "sign-transaction-block";
|
|
185
183
|
bytes: string;
|
|
184
|
+
type: "sign-transaction-block";
|
|
186
185
|
} | {
|
|
187
186
|
signature: string;
|
|
188
|
-
type: "sign-personal-message";
|
|
189
187
|
bytes: string;
|
|
188
|
+
type: "sign-personal-message";
|
|
190
189
|
};
|
|
190
|
+
type: "resolve";
|
|
191
191
|
}>;
|
|
192
192
|
export type ZkSendResponsePayload = Output<typeof ZkSendResponsePayload>;
|
|
193
193
|
export declare const ZkSendResponse: import("valibot").ObjectSchema<{
|
|
@@ -203,85 +203,85 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
|
|
|
203
203
|
type: import("valibot").LiteralSchema<"connect", "connect">;
|
|
204
204
|
address: import("valibot").StringSchema<string>;
|
|
205
205
|
}, undefined, {
|
|
206
|
-
type: "connect";
|
|
207
206
|
address: string;
|
|
207
|
+
type: "connect";
|
|
208
208
|
}>, import("valibot").ObjectSchema<{
|
|
209
209
|
type: import("valibot").LiteralSchema<"sign-transaction-block", "sign-transaction-block">;
|
|
210
210
|
bytes: import("valibot").StringSchema<string>;
|
|
211
211
|
signature: import("valibot").StringSchema<string>;
|
|
212
212
|
}, undefined, {
|
|
213
213
|
signature: string;
|
|
214
|
-
type: "sign-transaction-block";
|
|
215
214
|
bytes: string;
|
|
215
|
+
type: "sign-transaction-block";
|
|
216
216
|
}>, import("valibot").ObjectSchema<{
|
|
217
217
|
type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
|
|
218
218
|
bytes: import("valibot").StringSchema<string>;
|
|
219
219
|
signature: import("valibot").StringSchema<string>;
|
|
220
220
|
}, undefined, {
|
|
221
221
|
signature: string;
|
|
222
|
-
type: "sign-personal-message";
|
|
223
222
|
bytes: string;
|
|
223
|
+
type: "sign-personal-message";
|
|
224
224
|
}>], {
|
|
225
|
-
type: "connect";
|
|
226
225
|
address: string;
|
|
226
|
+
type: "connect";
|
|
227
227
|
} | {
|
|
228
228
|
signature: string;
|
|
229
|
-
type: "sign-transaction-block";
|
|
230
229
|
bytes: string;
|
|
230
|
+
type: "sign-transaction-block";
|
|
231
231
|
} | {
|
|
232
232
|
signature: string;
|
|
233
|
-
type: "sign-personal-message";
|
|
234
233
|
bytes: string;
|
|
234
|
+
type: "sign-personal-message";
|
|
235
235
|
}>;
|
|
236
236
|
}, undefined, {
|
|
237
|
-
type: "resolve";
|
|
238
237
|
data: {
|
|
239
|
-
type: "connect";
|
|
240
238
|
address: string;
|
|
239
|
+
type: "connect";
|
|
241
240
|
} | {
|
|
242
241
|
signature: string;
|
|
243
|
-
type: "sign-transaction-block";
|
|
244
242
|
bytes: string;
|
|
243
|
+
type: "sign-transaction-block";
|
|
245
244
|
} | {
|
|
246
245
|
signature: string;
|
|
247
|
-
type: "sign-personal-message";
|
|
248
246
|
bytes: string;
|
|
247
|
+
type: "sign-personal-message";
|
|
249
248
|
};
|
|
249
|
+
type: "resolve";
|
|
250
250
|
}>], {
|
|
251
251
|
type: "reject";
|
|
252
252
|
} | {
|
|
253
|
-
type: "resolve";
|
|
254
253
|
data: {
|
|
255
|
-
type: "connect";
|
|
256
254
|
address: string;
|
|
255
|
+
type: "connect";
|
|
257
256
|
} | {
|
|
258
257
|
signature: string;
|
|
259
|
-
type: "sign-transaction-block";
|
|
260
258
|
bytes: string;
|
|
259
|
+
type: "sign-transaction-block";
|
|
261
260
|
} | {
|
|
262
261
|
signature: string;
|
|
263
|
-
type: "sign-personal-message";
|
|
264
262
|
bytes: string;
|
|
263
|
+
type: "sign-personal-message";
|
|
265
264
|
};
|
|
265
|
+
type: "resolve";
|
|
266
266
|
}>;
|
|
267
267
|
}, undefined, {
|
|
268
268
|
id: string;
|
|
269
269
|
payload: {
|
|
270
270
|
type: "reject";
|
|
271
271
|
} | {
|
|
272
|
-
type: "resolve";
|
|
273
272
|
data: {
|
|
274
|
-
type: "connect";
|
|
275
273
|
address: string;
|
|
274
|
+
type: "connect";
|
|
276
275
|
} | {
|
|
277
276
|
signature: string;
|
|
278
|
-
type: "sign-transaction-block";
|
|
279
277
|
bytes: string;
|
|
278
|
+
type: "sign-transaction-block";
|
|
280
279
|
} | {
|
|
281
280
|
signature: string;
|
|
282
|
-
type: "sign-personal-message";
|
|
283
281
|
bytes: string;
|
|
282
|
+
type: "sign-personal-message";
|
|
284
283
|
};
|
|
284
|
+
type: "resolve";
|
|
285
285
|
};
|
|
286
286
|
source: "zksend-channel";
|
|
287
287
|
}>;
|
|
@@ -18,18 +18,18 @@ export declare class ZkSendHost {
|
|
|
18
18
|
constructor(request: Output<typeof ZkSendRequest>);
|
|
19
19
|
static fromUrl(url?: string): ZkSendHost;
|
|
20
20
|
getRequestData(): {
|
|
21
|
-
origin: string;
|
|
22
21
|
id: string;
|
|
22
|
+
origin: string;
|
|
23
23
|
payload: {
|
|
24
24
|
type: "connect";
|
|
25
25
|
} | {
|
|
26
|
-
type: "sign-transaction-block";
|
|
27
|
-
data: string;
|
|
28
26
|
address: string;
|
|
27
|
+
data: string;
|
|
28
|
+
type: "sign-transaction-block";
|
|
29
29
|
} | {
|
|
30
|
-
type: "sign-personal-message";
|
|
31
30
|
address: string;
|
|
32
31
|
bytes: string;
|
|
32
|
+
type: "sign-personal-message";
|
|
33
33
|
};
|
|
34
34
|
name?: string | undefined;
|
|
35
35
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { ZkSendLinkBuilder, type ZkSendLinkBuilderOptions, type CreateZkSendLinkOptions, } from './links/builder.js';
|
|
2
|
+
export { ZkSendLink, type ZkSendLinkOptions } from './links/claim.js';
|
|
3
|
+
export { type ZkBagContractOptions } from './links/zk-bag.js';
|
|
4
|
+
export { listCreatedLinks } from './links/utils.js';
|
|
2
5
|
export * from './wallet.js';
|
|
3
6
|
export * from './channel/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
ZkSendLinkBuilder
|
|
3
|
+
} from "./links/builder.js";
|
|
4
|
+
import { ZkSendLink } from "./links/claim.js";
|
|
5
|
+
import {} from "./links/zk-bag.js";
|
|
6
|
+
import { listCreatedLinks } from "./links/utils.js";
|
|
2
7
|
export * from "./wallet.js";
|
|
3
8
|
export * from "./channel/index.js";
|
|
9
|
+
export {
|
|
10
|
+
ZkSendLink,
|
|
11
|
+
ZkSendLinkBuilder,
|
|
12
|
+
listCreatedLinks
|
|
13
|
+
};
|
|
4
14
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport
|
|
5
|
-
"mappings": "AAGA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport {\n\tZkSendLinkBuilder,\n\ttype ZkSendLinkBuilderOptions,\n\ttype CreateZkSendLinkOptions,\n} from './links/builder.js';\nexport { ZkSendLink, type ZkSendLinkOptions } from './links/claim.js';\nexport { type ZkBagContractOptions } from './links/zk-bag.js';\nexport { listCreatedLinks } from './links/utils.js';\nexport * from './wallet.js';\nexport * from './channel/index.js';\n"],
|
|
5
|
+
"mappings": "AAGA;AAAA,EACC;AAAA,OAGM;AACP,SAAS,kBAA0C;AACnD,eAA0C;AAC1C,SAAS,wBAAwB;AACjC,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.test.d.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui.js/client';
|
|
2
|
+
import type { Keypair, Signer } from '@mysten/sui.js/cryptography';
|
|
3
|
+
import type { TransactionObjectInput } from '@mysten/sui.js/transactions';
|
|
4
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
5
|
+
import type { ZkBagContractOptions } from './zk-bag.js';
|
|
6
|
+
interface ZkSendLinkRedirect {
|
|
7
|
+
url: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ZkSendLinkBuilderOptions {
|
|
11
|
+
host?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
keypair?: Keypair;
|
|
14
|
+
network?: 'mainnet' | 'testnet';
|
|
15
|
+
client?: SuiClient;
|
|
16
|
+
sender: string;
|
|
17
|
+
redirect?: ZkSendLinkRedirect;
|
|
18
|
+
contract?: ZkBagContractOptions;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateZkSendLinkOptions {
|
|
21
|
+
transactionBlock?: TransactionBlock;
|
|
22
|
+
calculateGas?: (options: {
|
|
23
|
+
balances: Map<string, bigint>;
|
|
24
|
+
objects: TransactionObjectInput[];
|
|
25
|
+
gasEstimateFromDryRun: bigint;
|
|
26
|
+
}) => Promise<bigint> | bigint;
|
|
27
|
+
}
|
|
28
|
+
export declare class ZkSendLinkBuilder {
|
|
29
|
+
#private;
|
|
30
|
+
constructor({ host, path, keypair, network, client, sender, redirect, contract, }: ZkSendLinkBuilderOptions);
|
|
31
|
+
addClaimableMist(amount: bigint): void;
|
|
32
|
+
addClaimableBalance(coinType: string, amount: bigint): void;
|
|
33
|
+
addClaimableObject(id: string): void;
|
|
34
|
+
getLink(): string;
|
|
35
|
+
create({ signer, ...options }: CreateZkSendLinkOptions & {
|
|
36
|
+
signer: Signer;
|
|
37
|
+
waitForTransactionBlock?: boolean;
|
|
38
|
+
}): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
|
|
39
|
+
createSendTransaction({ transactionBlock: txb, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
|
+
if (!member.has(obj))
|
|
3
|
+
throw TypeError("Cannot " + msg);
|
|
4
|
+
};
|
|
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 _host, _path, _keypair, _client, _redirect, _objects, _balances, _sender, _coinsByType, _contract, _objectsToTransfer, objectsToTransfer_fn, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn, _estimateClaimGasFee, estimateClaimGasFee_fn, _getCoinsByType, getCoinsByType_fn;
|
|
24
|
+
import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client";
|
|
25
|
+
import { decodeSuiPrivateKey } from "@mysten/sui.js/cryptography";
|
|
26
|
+
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
|
|
27
|
+
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
28
|
+
import { normalizeStructTag, normalizeSuiAddress, SUI_TYPE_ARG, toB64 } from "@mysten/sui.js/utils";
|
|
29
|
+
import { ZkBag } from "./zk-bag.js";
|
|
30
|
+
const DEFAULT_ZK_SEND_LINK_OPTIONS = {
|
|
31
|
+
host: "https://zksend.com",
|
|
32
|
+
path: "/claim",
|
|
33
|
+
network: "mainnet"
|
|
34
|
+
};
|
|
35
|
+
const SUI_COIN_TYPE = normalizeStructTag(SUI_TYPE_ARG);
|
|
36
|
+
class ZkSendLinkBuilder {
|
|
37
|
+
constructor({
|
|
38
|
+
host = DEFAULT_ZK_SEND_LINK_OPTIONS.host,
|
|
39
|
+
path = DEFAULT_ZK_SEND_LINK_OPTIONS.path,
|
|
40
|
+
keypair = new Ed25519Keypair(),
|
|
41
|
+
network = DEFAULT_ZK_SEND_LINK_OPTIONS.network,
|
|
42
|
+
client = new SuiClient({ url: getFullnodeUrl(network) }),
|
|
43
|
+
sender,
|
|
44
|
+
redirect,
|
|
45
|
+
contract
|
|
46
|
+
}) {
|
|
47
|
+
__privateAdd(this, _objectsToTransfer);
|
|
48
|
+
__privateAdd(this, _createSendTransactionWithoutContract);
|
|
49
|
+
__privateAdd(this, _estimateClaimGasFee);
|
|
50
|
+
__privateAdd(this, _getCoinsByType);
|
|
51
|
+
__privateAdd(this, _host, void 0);
|
|
52
|
+
__privateAdd(this, _path, void 0);
|
|
53
|
+
__privateAdd(this, _keypair, void 0);
|
|
54
|
+
__privateAdd(this, _client, void 0);
|
|
55
|
+
__privateAdd(this, _redirect, void 0);
|
|
56
|
+
__privateAdd(this, _objects, /* @__PURE__ */ new Set());
|
|
57
|
+
__privateAdd(this, _balances, /* @__PURE__ */ new Map());
|
|
58
|
+
__privateAdd(this, _sender, void 0);
|
|
59
|
+
__privateAdd(this, _coinsByType, /* @__PURE__ */ new Map());
|
|
60
|
+
__privateAdd(this, _contract, void 0);
|
|
61
|
+
__privateSet(this, _host, host);
|
|
62
|
+
__privateSet(this, _path, path);
|
|
63
|
+
__privateSet(this, _redirect, redirect);
|
|
64
|
+
__privateSet(this, _keypair, keypair);
|
|
65
|
+
__privateSet(this, _client, client);
|
|
66
|
+
__privateSet(this, _sender, normalizeSuiAddress(sender));
|
|
67
|
+
if (contract) {
|
|
68
|
+
__privateSet(this, _contract, new ZkBag(contract.packageId, contract));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
addClaimableMist(amount) {
|
|
72
|
+
this.addClaimableBalance(SUI_COIN_TYPE, amount);
|
|
73
|
+
}
|
|
74
|
+
addClaimableBalance(coinType, amount) {
|
|
75
|
+
const normalizedType = normalizeStructTag(coinType);
|
|
76
|
+
__privateGet(this, _balances).set(normalizedType, (__privateGet(this, _balances).get(normalizedType) ?? 0n) + amount);
|
|
77
|
+
}
|
|
78
|
+
addClaimableObject(id) {
|
|
79
|
+
__privateGet(this, _objects).add(id);
|
|
80
|
+
}
|
|
81
|
+
getLink() {
|
|
82
|
+
const link = new URL(__privateGet(this, _host));
|
|
83
|
+
link.pathname = __privateGet(this, _path);
|
|
84
|
+
link.hash = `${__privateGet(this, _contract) ? "$" : ""}${toB64(
|
|
85
|
+
decodeSuiPrivateKey(__privateGet(this, _keypair).getSecretKey()).secretKey
|
|
86
|
+
)}`;
|
|
87
|
+
if (__privateGet(this, _redirect)) {
|
|
88
|
+
link.searchParams.set("redirect_url", __privateGet(this, _redirect).url);
|
|
89
|
+
if (__privateGet(this, _redirect).name) {
|
|
90
|
+
link.searchParams.set("name", __privateGet(this, _redirect).name);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return link.toString();
|
|
94
|
+
}
|
|
95
|
+
async create({
|
|
96
|
+
signer,
|
|
97
|
+
...options
|
|
98
|
+
}) {
|
|
99
|
+
const txb = await this.createSendTransaction(options);
|
|
100
|
+
const result = await __privateGet(this, _client).signAndExecuteTransactionBlock({
|
|
101
|
+
transactionBlock: await txb.build({ client: __privateGet(this, _client) }),
|
|
102
|
+
signer
|
|
103
|
+
});
|
|
104
|
+
if (options.waitForTransactionBlock) {
|
|
105
|
+
await __privateGet(this, _client).waitForTransactionBlock({ digest: result.digest });
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
async createSendTransaction({
|
|
110
|
+
transactionBlock: txb = new TransactionBlock(),
|
|
111
|
+
calculateGas
|
|
112
|
+
} = {}) {
|
|
113
|
+
if (!__privateGet(this, _contract)) {
|
|
114
|
+
return __privateMethod(this, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn).call(this, { transactionBlock: txb, calculateGas });
|
|
115
|
+
}
|
|
116
|
+
const receiver = txb.pure.address(__privateGet(this, _keypair).toSuiAddress());
|
|
117
|
+
const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
|
|
118
|
+
__privateGet(this, _contract).new(txb, { arguments: [store, receiver] });
|
|
119
|
+
txb.setSenderIfNotSet(__privateGet(this, _sender));
|
|
120
|
+
const objectsToTransfer = await __privateMethod(this, _objectsToTransfer, objectsToTransfer_fn).call(this, txb);
|
|
121
|
+
for (const object of objectsToTransfer) {
|
|
122
|
+
__privateGet(this, _contract).add(txb, {
|
|
123
|
+
arguments: [store, receiver, object.ref],
|
|
124
|
+
typeArguments: [object.type]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return txb;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_host = new WeakMap();
|
|
131
|
+
_path = new WeakMap();
|
|
132
|
+
_keypair = new WeakMap();
|
|
133
|
+
_client = new WeakMap();
|
|
134
|
+
_redirect = new WeakMap();
|
|
135
|
+
_objects = new WeakMap();
|
|
136
|
+
_balances = new WeakMap();
|
|
137
|
+
_sender = new WeakMap();
|
|
138
|
+
_coinsByType = new WeakMap();
|
|
139
|
+
_contract = new WeakMap();
|
|
140
|
+
_objectsToTransfer = new WeakSet();
|
|
141
|
+
objectsToTransfer_fn = async function(txb) {
|
|
142
|
+
const objectIDs = [...__privateGet(this, _objects)];
|
|
143
|
+
const refsWithType = (await __privateGet(this, _client).multiGetObjects({
|
|
144
|
+
ids: objectIDs,
|
|
145
|
+
options: {
|
|
146
|
+
showType: true
|
|
147
|
+
}
|
|
148
|
+
})).map((res, i) => {
|
|
149
|
+
if (!res.data || res.error) {
|
|
150
|
+
throw new Error(`Failed to load object ${objectIDs[i]} (${res.error?.code})`);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
ref: txb.objectRef({
|
|
154
|
+
version: res.data.version,
|
|
155
|
+
digest: res.data.digest,
|
|
156
|
+
objectId: res.data.objectId
|
|
157
|
+
}),
|
|
158
|
+
type: res.data.type
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
txb.setSenderIfNotSet(__privateGet(this, _sender));
|
|
162
|
+
for (const [coinType, amount] of __privateGet(this, _balances)) {
|
|
163
|
+
if (coinType === SUI_COIN_TYPE) {
|
|
164
|
+
const [sui] = txb.splitCoins(txb.gas, [amount]);
|
|
165
|
+
refsWithType.push({
|
|
166
|
+
ref: sui,
|
|
167
|
+
type: `0x2::coin::Coin<${coinType}>`
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
const coins = (await __privateMethod(this, _getCoinsByType, getCoinsByType_fn).call(this, coinType)).map((coin) => coin.coinObjectId);
|
|
171
|
+
if (coins.length > 1) {
|
|
172
|
+
txb.mergeCoins(coins[0], coins.slice(1));
|
|
173
|
+
}
|
|
174
|
+
const [split] = txb.splitCoins(coins[0], [amount]);
|
|
175
|
+
refsWithType.push({
|
|
176
|
+
ref: split,
|
|
177
|
+
type: `0x2::coin:Coin<${coinType}>`
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return refsWithType;
|
|
182
|
+
};
|
|
183
|
+
_createSendTransactionWithoutContract = new WeakSet();
|
|
184
|
+
createSendTransactionWithoutContract_fn = async function({
|
|
185
|
+
transactionBlock: txb = new TransactionBlock(),
|
|
186
|
+
calculateGas
|
|
187
|
+
} = {}) {
|
|
188
|
+
const gasEstimateFromDryRun = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this);
|
|
189
|
+
const baseGasAmount = calculateGas ? await calculateGas({
|
|
190
|
+
balances: __privateGet(this, _balances),
|
|
191
|
+
objects: [...__privateGet(this, _objects)],
|
|
192
|
+
gasEstimateFromDryRun
|
|
193
|
+
}) : gasEstimateFromDryRun * 2n;
|
|
194
|
+
const gasWithBuffer = baseGasAmount + 1013n;
|
|
195
|
+
const roundedGasAmount = gasWithBuffer - gasWithBuffer % 1000n - 13n;
|
|
196
|
+
const address = __privateGet(this, _keypair).toSuiAddress();
|
|
197
|
+
const objectsToTransfer = (await __privateMethod(this, _objectsToTransfer, objectsToTransfer_fn).call(this, txb)).map((obj) => obj.ref);
|
|
198
|
+
const [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]);
|
|
199
|
+
objectsToTransfer.push(gas);
|
|
200
|
+
txb.setSenderIfNotSet(__privateGet(this, _sender));
|
|
201
|
+
txb.transferObjects(objectsToTransfer, address);
|
|
202
|
+
return txb;
|
|
203
|
+
};
|
|
204
|
+
_estimateClaimGasFee = new WeakSet();
|
|
205
|
+
estimateClaimGasFee_fn = async function() {
|
|
206
|
+
const txb = new TransactionBlock();
|
|
207
|
+
txb.setSender(__privateGet(this, _sender));
|
|
208
|
+
txb.setGasPayment([]);
|
|
209
|
+
txb.transferObjects([txb.gas], __privateGet(this, _keypair).toSuiAddress());
|
|
210
|
+
const idsToTransfer = [...__privateGet(this, _objects)];
|
|
211
|
+
for (const [coinType] of __privateGet(this, _balances)) {
|
|
212
|
+
const coins = await __privateMethod(this, _getCoinsByType, getCoinsByType_fn).call(this, coinType);
|
|
213
|
+
if (!coins.length) {
|
|
214
|
+
throw new Error(`Sending account does not contain any coins of type ${coinType}`);
|
|
215
|
+
}
|
|
216
|
+
idsToTransfer.push(coins[0].coinObjectId);
|
|
217
|
+
}
|
|
218
|
+
if (idsToTransfer.length > 0) {
|
|
219
|
+
txb.transferObjects(
|
|
220
|
+
idsToTransfer.map((id) => txb.object(id)),
|
|
221
|
+
__privateGet(this, _keypair).toSuiAddress()
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
const result = await __privateGet(this, _client).dryRunTransactionBlock({
|
|
225
|
+
transactionBlock: await txb.build({ client: __privateGet(this, _client) })
|
|
226
|
+
});
|
|
227
|
+
return BigInt(result.effects.gasUsed.computationCost) + BigInt(result.effects.gasUsed.storageCost) - BigInt(result.effects.gasUsed.storageRebate);
|
|
228
|
+
};
|
|
229
|
+
_getCoinsByType = new WeakSet();
|
|
230
|
+
getCoinsByType_fn = async function(coinType) {
|
|
231
|
+
if (__privateGet(this, _coinsByType).has(coinType)) {
|
|
232
|
+
return __privateGet(this, _coinsByType).get(coinType);
|
|
233
|
+
}
|
|
234
|
+
const coins = await __privateGet(this, _client).getCoins({
|
|
235
|
+
coinType,
|
|
236
|
+
owner: __privateGet(this, _sender)
|
|
237
|
+
});
|
|
238
|
+
__privateGet(this, _coinsByType).set(coinType, coins.data);
|
|
239
|
+
return coins.data;
|
|
240
|
+
};
|
|
241
|
+
export {
|
|
242
|
+
ZkSendLinkBuilder
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=builder.js.map
|