@mysten/zksend 0.3.1 → 0.4.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 (44) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/channel/events.d.ts +27 -27
  3. package/dist/cjs/channel/index.d.ts +1 -1
  4. package/dist/cjs/index.d.ts +4 -2
  5. package/dist/cjs/index.js +5 -1
  6. package/dist/cjs/index.js.map +3 -3
  7. package/dist/cjs/links/builder.d.ts +13 -2
  8. package/dist/cjs/links/builder.js +130 -42
  9. package/dist/cjs/links/builder.js.map +2 -2
  10. package/dist/cjs/links/claim.d.ts +10 -47
  11. package/dist/cjs/links/claim.js +157 -126
  12. package/dist/cjs/links/claim.js.map +3 -3
  13. package/dist/cjs/links/list-created-links.d.ts +22 -0
  14. package/dist/cjs/links/list-created-links.js +145 -0
  15. package/dist/cjs/links/list-created-links.js.map +7 -0
  16. package/dist/cjs/links/utils.d.ts +30 -17
  17. package/dist/cjs/links/utils.js +66 -109
  18. package/dist/cjs/links/utils.js.map +3 -3
  19. package/dist/cjs/links/zk-bag.d.ts +1 -0
  20. package/dist/cjs/links/zk-bag.js +6 -0
  21. package/dist/cjs/links/zk-bag.js.map +2 -2
  22. package/dist/esm/channel/events.d.ts +27 -27
  23. package/dist/esm/channel/index.d.ts +1 -1
  24. package/dist/esm/index.d.ts +4 -2
  25. package/dist/esm/index.js +6 -2
  26. package/dist/esm/index.js.map +2 -2
  27. package/dist/esm/links/builder.d.ts +13 -2
  28. package/dist/esm/links/builder.js +131 -43
  29. package/dist/esm/links/builder.js.map +2 -2
  30. package/dist/esm/links/claim.d.ts +10 -47
  31. package/dist/esm/links/claim.js +155 -124
  32. package/dist/esm/links/claim.js.map +2 -2
  33. package/dist/esm/links/list-created-links.d.ts +22 -0
  34. package/dist/esm/links/list-created-links.js +125 -0
  35. package/dist/esm/links/list-created-links.js.map +7 -0
  36. package/dist/esm/links/utils.d.ts +30 -17
  37. package/dist/esm/links/utils.js +67 -110
  38. package/dist/esm/links/utils.js.map +3 -3
  39. package/dist/esm/links/zk-bag.d.ts +1 -0
  40. package/dist/esm/links/zk-bag.js +6 -0
  41. package/dist/esm/links/zk-bag.js.map +2 -2
  42. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @mysten/zksend
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c05a4e8cb7: removed listClaimableAssets, and added new assets and claimed properties to link instances
8
+ - c05a4e8cb7: Use contract by default for new links
9
+ - c05a4e8cb7: Add helper for bulk link creation
10
+ - c05a4e8cb7: Removed options for filtering claims
11
+ - c05a4e8cb7: renamed loadOwnedData to loadAssets
12
+
3
13
  ## 0.3.1
4
14
 
5
15
  ### Patch Changes
@@ -17,8 +17,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
17
17
  address: import("valibot").StringSchema<string>;
18
18
  }, undefined, {
19
19
  address: string;
20
- bytes: string;
21
20
  type: "sign-personal-message";
21
+ bytes: string;
22
22
  }>], {
23
23
  type: "connect";
24
24
  } | {
@@ -27,8 +27,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
27
27
  type: "sign-transaction-block";
28
28
  } | {
29
29
  address: string;
30
- bytes: string;
31
30
  type: "sign-personal-message";
31
+ bytes: string;
32
32
  }>;
33
33
  export type ZkSendRequestData = Output<typeof ZkSendRequestData>;
34
34
  export declare const ZkSendRequest: import("valibot").ObjectSchema<{
@@ -53,8 +53,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
53
53
  address: import("valibot").StringSchema<string>;
54
54
  }, undefined, {
55
55
  address: string;
56
- bytes: string;
57
56
  type: "sign-personal-message";
57
+ bytes: string;
58
58
  }>], {
59
59
  type: "connect";
60
60
  } | {
@@ -63,8 +63,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
63
63
  type: "sign-transaction-block";
64
64
  } | {
65
65
  address: string;
66
- bytes: string;
67
66
  type: "sign-personal-message";
67
+ bytes: string;
68
68
  }>;
69
69
  }, undefined, {
70
70
  id: string;
@@ -77,8 +77,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
77
77
  type: "sign-transaction-block";
78
78
  } | {
79
79
  address: string;
80
- bytes: string;
81
80
  type: "sign-personal-message";
81
+ bytes: string;
82
82
  };
83
83
  name?: string | undefined;
84
84
  }>;
@@ -95,27 +95,27 @@ export declare const ZkSendResponseData: import("valibot").VariantSchema<"type",
95
95
  signature: import("valibot").StringSchema<string>;
96
96
  }, undefined, {
97
97
  signature: string;
98
- bytes: string;
99
98
  type: "sign-transaction-block";
99
+ bytes: string;
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
- bytes: string;
107
106
  type: "sign-personal-message";
107
+ bytes: string;
108
108
  }>], {
109
109
  address: string;
110
110
  type: "connect";
111
111
  } | {
112
112
  signature: string;
113
- bytes: string;
114
113
  type: "sign-transaction-block";
114
+ bytes: string;
115
115
  } | {
116
116
  signature: string;
117
- bytes: string;
118
117
  type: "sign-personal-message";
118
+ bytes: string;
119
119
  }>;
120
120
  export type ZkSendResponseData = Output<typeof ZkSendResponseData>;
121
121
  export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
@@ -136,27 +136,27 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
136
136
  signature: import("valibot").StringSchema<string>;
137
137
  }, undefined, {
138
138
  signature: string;
139
- bytes: string;
140
139
  type: "sign-transaction-block";
140
+ bytes: string;
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
- bytes: string;
148
147
  type: "sign-personal-message";
148
+ bytes: string;
149
149
  }>], {
150
150
  address: string;
151
151
  type: "connect";
152
152
  } | {
153
153
  signature: string;
154
- bytes: string;
155
154
  type: "sign-transaction-block";
155
+ bytes: string;
156
156
  } | {
157
157
  signature: string;
158
- bytes: string;
159
158
  type: "sign-personal-message";
159
+ bytes: string;
160
160
  }>;
161
161
  }, undefined, {
162
162
  data: {
@@ -164,12 +164,12 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
164
164
  type: "connect";
165
165
  } | {
166
166
  signature: string;
167
- bytes: string;
168
167
  type: "sign-transaction-block";
168
+ bytes: string;
169
169
  } | {
170
170
  signature: string;
171
- bytes: string;
172
171
  type: "sign-personal-message";
172
+ bytes: string;
173
173
  };
174
174
  type: "resolve";
175
175
  }>], {
@@ -180,12 +180,12 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
180
180
  type: "connect";
181
181
  } | {
182
182
  signature: string;
183
- bytes: string;
184
183
  type: "sign-transaction-block";
184
+ bytes: string;
185
185
  } | {
186
186
  signature: string;
187
- bytes: string;
188
187
  type: "sign-personal-message";
188
+ bytes: string;
189
189
  };
190
190
  type: "resolve";
191
191
  }>;
@@ -211,27 +211,27 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
211
211
  signature: import("valibot").StringSchema<string>;
212
212
  }, undefined, {
213
213
  signature: string;
214
- bytes: string;
215
214
  type: "sign-transaction-block";
215
+ bytes: string;
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
- bytes: string;
223
222
  type: "sign-personal-message";
223
+ bytes: string;
224
224
  }>], {
225
225
  address: string;
226
226
  type: "connect";
227
227
  } | {
228
228
  signature: string;
229
- bytes: string;
230
229
  type: "sign-transaction-block";
230
+ bytes: string;
231
231
  } | {
232
232
  signature: string;
233
- bytes: string;
234
233
  type: "sign-personal-message";
234
+ bytes: string;
235
235
  }>;
236
236
  }, undefined, {
237
237
  data: {
@@ -239,12 +239,12 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
239
239
  type: "connect";
240
240
  } | {
241
241
  signature: string;
242
- bytes: string;
243
242
  type: "sign-transaction-block";
243
+ bytes: string;
244
244
  } | {
245
245
  signature: string;
246
- bytes: string;
247
246
  type: "sign-personal-message";
247
+ bytes: string;
248
248
  };
249
249
  type: "resolve";
250
250
  }>], {
@@ -255,12 +255,12 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
255
255
  type: "connect";
256
256
  } | {
257
257
  signature: string;
258
- bytes: string;
259
258
  type: "sign-transaction-block";
259
+ bytes: string;
260
260
  } | {
261
261
  signature: string;
262
- bytes: string;
263
262
  type: "sign-personal-message";
263
+ bytes: string;
264
264
  };
265
265
  type: "resolve";
266
266
  }>;
@@ -274,12 +274,12 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
274
274
  type: "connect";
275
275
  } | {
276
276
  signature: string;
277
- bytes: string;
278
277
  type: "sign-transaction-block";
278
+ bytes: string;
279
279
  } | {
280
280
  signature: string;
281
- bytes: string;
282
281
  type: "sign-personal-message";
282
+ bytes: string;
283
283
  };
284
284
  type: "resolve";
285
285
  };
@@ -28,8 +28,8 @@ export declare class ZkSendHost {
28
28
  type: "sign-transaction-block";
29
29
  } | {
30
30
  address: string;
31
- bytes: string;
32
31
  type: "sign-personal-message";
32
+ bytes: string;
33
33
  };
34
34
  name?: string | undefined;
35
35
  };
@@ -1,6 +1,8 @@
1
1
  export { ZkSendLinkBuilder, type ZkSendLinkBuilderOptions, type CreateZkSendLinkOptions, } from './links/builder.js';
2
2
  export { ZkSendLink, type ZkSendLinkOptions } from './links/claim.js';
3
- export { type ZkBagContractOptions } from './links/zk-bag.js';
4
- export { listCreatedLinks, isClaimTransaction } from './links/utils.js';
3
+ export { type ZkBagContractOptions, ZkBag } from './links/zk-bag.js';
4
+ export { isClaimTransaction } from './links/utils.js';
5
+ export { listCreatedLinks } from './links/list-created-links.js';
6
+ export { MAINNET_CONTRACT_IDS } from './links/zk-bag.js';
5
7
  export * from './wallet.js';
6
8
  export * from './channel/index.js';
package/dist/cjs/index.js CHANGED
@@ -19,16 +19,20 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
+ MAINNET_CONTRACT_IDS: () => import_zk_bag2.MAINNET_CONTRACT_IDS,
23
+ ZkBag: () => import_zk_bag.ZkBag,
22
24
  ZkSendLink: () => import_claim.ZkSendLink,
23
25
  ZkSendLinkBuilder: () => import_builder.ZkSendLinkBuilder,
24
26
  isClaimTransaction: () => import_utils.isClaimTransaction,
25
- listCreatedLinks: () => import_utils.listCreatedLinks
27
+ listCreatedLinks: () => import_list_created_links.listCreatedLinks
26
28
  });
27
29
  module.exports = __toCommonJS(src_exports);
28
30
  var import_builder = require("./links/builder.js");
29
31
  var import_claim = require("./links/claim.js");
30
32
  var import_zk_bag = require("./links/zk-bag.js");
31
33
  var import_utils = require("./links/utils.js");
34
+ var import_list_created_links = require("./links/list-created-links.js");
35
+ var import_zk_bag2 = require("./links/zk-bag.js");
32
36
  __reExport(src_exports, require("./wallet.js"), module.exports);
33
37
  __reExport(src_exports, require("./channel/index.js"), module.exports);
34
38
  //# sourceMappingURL=index.js.map
@@ -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 {\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, isClaimTransaction } from './links/utils.js';\nexport * from './wallet.js';\nexport * from './channel/index.js';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAIO;AACP,mBAAmD;AACnD,oBAA0C;AAC1C,mBAAqD;AACrD,wBAAc,wBAXd;AAYA,wBAAc,+BAZd;",
6
- "names": []
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, ZkBag } from './links/zk-bag.js';\nexport { isClaimTransaction } from './links/utils.js';\nexport { listCreatedLinks } from './links/list-created-links.js';\n\nexport { MAINNET_CONTRACT_IDS } from './links/zk-bag.js';\nexport * from './wallet.js';\nexport * from './channel/index.js';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAIO;AACP,mBAAmD;AACnD,oBAAiD;AACjD,mBAAmC;AACnC,gCAAiC;AAEjC,IAAAA,iBAAqC;AACrC,wBAAc,wBAdd;AAeA,wBAAc,+BAfd;",
6
+ "names": ["import_zk_bag"]
7
7
  }
@@ -15,7 +15,7 @@ export interface ZkSendLinkBuilderOptions {
15
15
  client?: SuiClient;
16
16
  sender: string;
17
17
  redirect?: ZkSendLinkRedirect;
18
- contract?: ZkBagContractOptions;
18
+ contract?: ZkBagContractOptions | null;
19
19
  }
20
20
  export interface CreateZkSendLinkOptions {
21
21
  transactionBlock?: TransactionBlock;
@@ -27,6 +27,10 @@ export interface CreateZkSendLinkOptions {
27
27
  }
28
28
  export declare class ZkSendLinkBuilder {
29
29
  #private;
30
+ objectIds: Set<string>;
31
+ balances: Map<string, bigint>;
32
+ sender: string;
33
+ keypair: Keypair;
30
34
  constructor({ host, path, keypair, network, client, sender, redirect, contract, }: ZkSendLinkBuilderOptions);
31
35
  addClaimableMist(amount: bigint): void;
32
36
  addClaimableBalance(coinType: string, amount: bigint): void;
@@ -36,6 +40,13 @@ export declare class ZkSendLinkBuilder {
36
40
  signer: Signer;
37
41
  waitForTransactionBlock?: boolean;
38
42
  }): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
39
- createSendTransaction({ transactionBlock: txb, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>;
43
+ createSendTransaction({ transactionBlock, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>;
44
+ static createLinks({ links, network, client, transactionBlock, contract: contractIds, }: {
45
+ transactionBlock?: TransactionBlock;
46
+ client?: SuiClient;
47
+ network?: 'mainnet' | 'testnet';
48
+ links: ZkSendLinkBuilder[];
49
+ contract: ZkBagContractOptions;
50
+ }): Promise<TransactionBlock>;
40
51
  }
41
52
  export {};
@@ -49,14 +49,14 @@ var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
49
49
  var import_transactions = require("@mysten/sui.js/transactions");
50
50
  var import_utils = require("@mysten/sui.js/utils");
51
51
  var import_zk_bag = require("./zk-bag.js");
52
- var _host, _path, _keypair, _client, _redirect, _objects, _balances, _sender, _coinsByType, _contract, _objectsToTransfer, objectsToTransfer_fn, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn, _estimateClaimGasFee, estimateClaimGasFee_fn, _getCoinsByType, getCoinsByType_fn;
52
+ var _host, _path, _client, _redirect, _coinsByType, _contract, _objectsToTransfer, objectsToTransfer_fn, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn, _estimateClaimGasFee, estimateClaimGasFee_fn, _getCoinsByType, getCoinsByType_fn;
53
53
  const DEFAULT_ZK_SEND_LINK_OPTIONS = {
54
54
  host: "https://zksend.com",
55
55
  path: "/claim",
56
56
  network: "mainnet"
57
57
  };
58
58
  const SUI_COIN_TYPE = (0, import_utils.normalizeStructTag)(import_utils.SUI_TYPE_ARG);
59
- class ZkSendLinkBuilder {
59
+ const _ZkSendLinkBuilder = class {
60
60
  constructor({
61
61
  host = DEFAULT_ZK_SEND_LINK_OPTIONS.host,
62
62
  path = DEFAULT_ZK_SEND_LINK_OPTIONS.path,
@@ -65,28 +65,26 @@ class ZkSendLinkBuilder {
65
65
  client = new import_client.SuiClient({ url: (0, import_client.getFullnodeUrl)(network) }),
66
66
  sender,
67
67
  redirect,
68
- contract
68
+ contract = network === "mainnet" ? import_zk_bag.MAINNET_CONTRACT_IDS : void 0
69
69
  }) {
70
70
  __privateAdd(this, _objectsToTransfer);
71
71
  __privateAdd(this, _createSendTransactionWithoutContract);
72
72
  __privateAdd(this, _estimateClaimGasFee);
73
73
  __privateAdd(this, _getCoinsByType);
74
+ this.objectIds = /* @__PURE__ */ new Set();
75
+ this.balances = /* @__PURE__ */ new Map();
74
76
  __privateAdd(this, _host, void 0);
75
77
  __privateAdd(this, _path, void 0);
76
- __privateAdd(this, _keypair, void 0);
77
78
  __privateAdd(this, _client, void 0);
78
79
  __privateAdd(this, _redirect, void 0);
79
- __privateAdd(this, _objects, /* @__PURE__ */ new Set());
80
- __privateAdd(this, _balances, /* @__PURE__ */ new Map());
81
- __privateAdd(this, _sender, void 0);
82
80
  __privateAdd(this, _coinsByType, /* @__PURE__ */ new Map());
83
81
  __privateAdd(this, _contract, void 0);
84
82
  __privateSet(this, _host, host);
85
83
  __privateSet(this, _path, path);
86
84
  __privateSet(this, _redirect, redirect);
87
- __privateSet(this, _keypair, keypair);
85
+ this.keypair = keypair;
88
86
  __privateSet(this, _client, client);
89
- __privateSet(this, _sender, (0, import_utils.normalizeSuiAddress)(sender));
87
+ this.sender = (0, import_utils.normalizeSuiAddress)(sender);
90
88
  if (contract) {
91
89
  __privateSet(this, _contract, new import_zk_bag.ZkBag(contract.packageId, contract));
92
90
  }
@@ -96,16 +94,16 @@ class ZkSendLinkBuilder {
96
94
  }
97
95
  addClaimableBalance(coinType, amount) {
98
96
  const normalizedType = (0, import_utils.normalizeStructTag)(coinType);
99
- __privateGet(this, _balances).set(normalizedType, (__privateGet(this, _balances).get(normalizedType) ?? 0n) + amount);
97
+ this.balances.set(normalizedType, (this.balances.get(normalizedType) ?? 0n) + amount);
100
98
  }
101
99
  addClaimableObject(id) {
102
- __privateGet(this, _objects).add(id);
100
+ this.objectIds.add(id);
103
101
  }
104
102
  getLink() {
105
103
  const link = new URL(__privateGet(this, _host));
106
104
  link.pathname = __privateGet(this, _path);
107
105
  link.hash = `${__privateGet(this, _contract) ? "$" : ""}${(0, import_utils.toB64)(
108
- (0, import_cryptography.decodeSuiPrivateKey)(__privateGet(this, _keypair).getSecretKey()).secretKey
106
+ (0, import_cryptography.decodeSuiPrivateKey)(this.keypair.getSecretKey()).secretKey
109
107
  )}`;
110
108
  if (__privateGet(this, _redirect)) {
111
109
  link.searchParams.set("redirect_url", __privateGet(this, _redirect).url);
@@ -130,39 +128,129 @@ class ZkSendLinkBuilder {
130
128
  return result;
131
129
  }
132
130
  async createSendTransaction({
133
- transactionBlock: txb = new import_transactions.TransactionBlock(),
131
+ transactionBlock = new import_transactions.TransactionBlock(),
134
132
  calculateGas
135
133
  } = {}) {
136
134
  if (!__privateGet(this, _contract)) {
137
- return __privateMethod(this, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn).call(this, { transactionBlock: txb, calculateGas });
135
+ return __privateMethod(this, _createSendTransactionWithoutContract, createSendTransactionWithoutContract_fn).call(this, { transactionBlock, calculateGas });
138
136
  }
139
- const receiver = txb.pure.address(__privateGet(this, _keypair).toSuiAddress());
140
- const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
141
- __privateGet(this, _contract).new(txb, { arguments: [store, receiver] });
142
- txb.setSenderIfNotSet(__privateGet(this, _sender));
143
- const objectsToTransfer = await __privateMethod(this, _objectsToTransfer, objectsToTransfer_fn).call(this, txb);
144
- for (const object of objectsToTransfer) {
145
- __privateGet(this, _contract).add(txb, {
146
- arguments: [store, receiver, object.ref],
147
- typeArguments: [object.type]
137
+ transactionBlock.setSenderIfNotSet(this.sender);
138
+ return _ZkSendLinkBuilder.createLinks({
139
+ transactionBlock,
140
+ client: __privateGet(this, _client),
141
+ contract: __privateGet(this, _contract).ids,
142
+ links: [this]
143
+ });
144
+ }
145
+ static async createLinks({
146
+ links,
147
+ network = "mainnet",
148
+ client = new import_client.SuiClient({ url: (0, import_client.getFullnodeUrl)(network) }),
149
+ transactionBlock = new import_transactions.TransactionBlock(),
150
+ contract: contractIds = import_zk_bag.MAINNET_CONTRACT_IDS
151
+ }) {
152
+ const contract = new import_zk_bag.ZkBag(contractIds.packageId, contractIds);
153
+ const store = transactionBlock.object(contract.ids.bagStoreId);
154
+ const coinsByType = /* @__PURE__ */ new Map();
155
+ const allIds = links.flatMap((link) => [...link.objectIds]);
156
+ await Promise.all(
157
+ [...new Set(links.flatMap((link) => [...link.balances.keys()]))].map(async (coinType) => {
158
+ const coins = await client.getCoins({
159
+ coinType,
160
+ owner: links[0].sender
161
+ });
162
+ coinsByType.set(
163
+ coinType,
164
+ coins.data.filter((coin) => !allIds.includes(coin.coinObjectId))
165
+ );
166
+ })
167
+ );
168
+ const objectRefs = /* @__PURE__ */ new Map();
169
+ const pageSize = 50;
170
+ let offset = 0;
171
+ while (offset < allIds.length) {
172
+ let chunk = allIds.slice(offset, offset + pageSize);
173
+ offset += pageSize;
174
+ const objects = await client.multiGetObjects({
175
+ ids: chunk,
176
+ options: {
177
+ showType: true
178
+ }
148
179
  });
180
+ for (const [i, res] of objects.entries()) {
181
+ if (!res.data || res.error) {
182
+ throw new Error(`Failed to load object ${chunk[i]} (${res.error?.code})`);
183
+ }
184
+ objectRefs.set(chunk[i], {
185
+ ref: transactionBlock.objectRef({
186
+ version: res.data.version,
187
+ digest: res.data.digest,
188
+ objectId: res.data.objectId
189
+ }),
190
+ type: res.data.type
191
+ });
192
+ }
149
193
  }
150
- return txb;
194
+ const mergedCoins = /* @__PURE__ */ new Map([
195
+ [SUI_COIN_TYPE, transactionBlock.gas]
196
+ ]);
197
+ for (const [coinType, coins] of coinsByType) {
198
+ if (coinType === SUI_COIN_TYPE) {
199
+ continue;
200
+ }
201
+ const [first, ...rest] = coins.map(
202
+ (coin) => transactionBlock.objectRef({
203
+ objectId: coin.coinObjectId,
204
+ version: coin.version,
205
+ digest: coin.digest
206
+ })
207
+ );
208
+ if (rest.length > 0) {
209
+ transactionBlock.mergeCoins(first, rest);
210
+ }
211
+ mergedCoins.set(coinType, transactionBlock.object(first));
212
+ }
213
+ for (const link of links) {
214
+ const receiver = link.keypair.toSuiAddress();
215
+ contract.new(transactionBlock, { arguments: [store, receiver] });
216
+ link.objectIds.forEach((id) => {
217
+ const object = objectRefs.get(id);
218
+ if (!object) {
219
+ throw new Error(`Object ${id} not found`);
220
+ }
221
+ contract.add(transactionBlock, {
222
+ arguments: [store, receiver, object.ref],
223
+ typeArguments: [object.type]
224
+ });
225
+ });
226
+ }
227
+ for (const [coinType, merged] of mergedCoins) {
228
+ const linksWithCoin = links.filter((link) => link.balances.has(coinType));
229
+ if (linksWithCoin.length === 0) {
230
+ continue;
231
+ }
232
+ const balances = linksWithCoin.map((link) => link.balances.get(coinType));
233
+ const splits = transactionBlock.splitCoins(merged, balances);
234
+ for (const [i, link] of linksWithCoin.entries()) {
235
+ contract.add(transactionBlock, {
236
+ arguments: [store, link.keypair.toSuiAddress(), splits[i]],
237
+ typeArguments: [`0x2::coin::Coin<${coinType}>`]
238
+ });
239
+ }
240
+ }
241
+ return transactionBlock;
151
242
  }
152
- }
243
+ };
244
+ let ZkSendLinkBuilder = _ZkSendLinkBuilder;
153
245
  _host = new WeakMap();
154
246
  _path = new WeakMap();
155
- _keypair = new WeakMap();
156
247
  _client = new WeakMap();
157
248
  _redirect = new WeakMap();
158
- _objects = new WeakMap();
159
- _balances = new WeakMap();
160
- _sender = new WeakMap();
161
249
  _coinsByType = new WeakMap();
162
250
  _contract = new WeakMap();
163
251
  _objectsToTransfer = new WeakSet();
164
252
  objectsToTransfer_fn = async function(txb) {
165
- const objectIDs = [...__privateGet(this, _objects)];
253
+ const objectIDs = [...this.objectIds];
166
254
  const refsWithType = (await __privateGet(this, _client).multiGetObjects({
167
255
  ids: objectIDs,
168
256
  options: {
@@ -181,8 +269,8 @@ objectsToTransfer_fn = async function(txb) {
181
269
  type: res.data.type
182
270
  };
183
271
  });
184
- txb.setSenderIfNotSet(__privateGet(this, _sender));
185
- for (const [coinType, amount] of __privateGet(this, _balances)) {
272
+ txb.setSenderIfNotSet(this.sender);
273
+ for (const [coinType, amount] of this.balances) {
186
274
  if (coinType === SUI_COIN_TYPE) {
187
275
  const [sui] = txb.splitCoins(txb.gas, [amount]);
188
276
  refsWithType.push({
@@ -210,28 +298,28 @@ createSendTransactionWithoutContract_fn = async function({
210
298
  } = {}) {
211
299
  const gasEstimateFromDryRun = await __privateMethod(this, _estimateClaimGasFee, estimateClaimGasFee_fn).call(this);
212
300
  const baseGasAmount = calculateGas ? await calculateGas({
213
- balances: __privateGet(this, _balances),
214
- objects: [...__privateGet(this, _objects)],
301
+ balances: this.balances,
302
+ objects: [...this.objectIds],
215
303
  gasEstimateFromDryRun
216
304
  }) : gasEstimateFromDryRun * 2n;
217
305
  const gasWithBuffer = baseGasAmount + 1013n;
218
306
  const roundedGasAmount = gasWithBuffer - gasWithBuffer % 1000n - 13n;
219
- const address = __privateGet(this, _keypair).toSuiAddress();
307
+ const address = this.keypair.toSuiAddress();
220
308
  const objectsToTransfer = (await __privateMethod(this, _objectsToTransfer, objectsToTransfer_fn).call(this, txb)).map((obj) => obj.ref);
221
309
  const [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]);
222
310
  objectsToTransfer.push(gas);
223
- txb.setSenderIfNotSet(__privateGet(this, _sender));
311
+ txb.setSenderIfNotSet(this.sender);
224
312
  txb.transferObjects(objectsToTransfer, address);
225
313
  return txb;
226
314
  };
227
315
  _estimateClaimGasFee = new WeakSet();
228
316
  estimateClaimGasFee_fn = async function() {
229
317
  const txb = new import_transactions.TransactionBlock();
230
- txb.setSender(__privateGet(this, _sender));
318
+ txb.setSender(this.sender);
231
319
  txb.setGasPayment([]);
232
- txb.transferObjects([txb.gas], __privateGet(this, _keypair).toSuiAddress());
233
- const idsToTransfer = [...__privateGet(this, _objects)];
234
- for (const [coinType] of __privateGet(this, _balances)) {
320
+ txb.transferObjects([txb.gas], this.keypair.toSuiAddress());
321
+ const idsToTransfer = [...this.objectIds];
322
+ for (const [coinType] of this.balances) {
235
323
  const coins = await __privateMethod(this, _getCoinsByType, getCoinsByType_fn).call(this, coinType);
236
324
  if (!coins.length) {
237
325
  throw new Error(`Sending account does not contain any coins of type ${coinType}`);
@@ -241,7 +329,7 @@ estimateClaimGasFee_fn = async function() {
241
329
  if (idsToTransfer.length > 0) {
242
330
  txb.transferObjects(
243
331
  idsToTransfer.map((id) => txb.object(id)),
244
- __privateGet(this, _keypair).toSuiAddress()
332
+ this.keypair.toSuiAddress()
245
333
  );
246
334
  }
247
335
  const result = await __privateGet(this, _client).dryRunTransactionBlock({
@@ -256,7 +344,7 @@ getCoinsByType_fn = async function(coinType) {
256
344
  }
257
345
  const coins = await __privateGet(this, _client).getCoins({
258
346
  coinType,
259
- owner: __privateGet(this, _sender)
347
+ owner: this.sender
260
348
  });
261
349
  __privateGet(this, _coinsByType).set(coinType, coins.data);
262
350
  return coins.data;