@mysten/zksend 0.3.0 → 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 +16 -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 +6 -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 +13 -47
  11. package/dist/cjs/links/claim.js +176 -150
  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 +32 -15
  17. package/dist/cjs/links/utils.js +86 -100
  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 +7 -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 +13 -47
  31. package/dist/esm/links/claim.js +174 -148
  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 +32 -15
  37. package/dist/esm/links/utils.js +87 -101
  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
@@ -20,7 +20,8 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _client, _address, _keypair, _initiallyOwnedObjects, _ownedObjects, _bagObjects, _gasCoin, _hasSui, _creatorAddress, _contract, _claimApi, _network, _host, _path, _loadBag, loadBag_fn, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn, _fetch, fetch_fn, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn, _loadOwnedObjects, loadOwnedObjects_fn, _loadInitialTransactionData, loadInitialTransactionData_fn;
23
+ var _client, _contract, _claimApi, _network, _host, _path, _gasCoin, _hasSui, _ownedObjects, _loadBag, loadBag_fn, _loadClaimedAssets, loadClaimedAssets_fn, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn, _fetch, fetch_fn, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn, _loadOwnedObjects, loadOwnedObjects_fn;
24
+ import { bcs } from "@mysten/sui.js/bcs";
24
25
  import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client";
25
26
  import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
26
27
  import { TransactionBlock } from "@mysten/sui.js/transactions";
@@ -34,7 +35,8 @@ import {
34
35
  toB64
35
36
  } from "@mysten/sui.js/utils";
36
37
  import { ZkSendLinkBuilder } from "./builder.js";
37
- import { ZkBag } from "./zk-bag.js";
38
+ import { getAssetsFromTxnBlock, isOwner, ownedAfterChange } from "./utils.js";
39
+ import { MAINNET_CONTRACT_IDS, ZkBag } from "./zk-bag.js";
38
40
  const DEFAULT_ZK_SEND_LINK_OPTIONS = {
39
41
  host: "https://zksend.com",
40
42
  path: "/claim",
@@ -49,40 +51,36 @@ const _ZkSendLink = class {
49
51
  claimApi = DEFAULT_ZK_SEND_LINK_OPTIONS.claimApi,
50
52
  client = new SuiClient({ url: getFullnodeUrl(network) }),
51
53
  keypair,
52
- contract,
54
+ contract = network === "mainnet" ? MAINNET_CONTRACT_IDS : null,
53
55
  address,
54
56
  host,
55
57
  path,
56
58
  isContractLink
57
59
  }) {
58
60
  __privateAdd(this, _loadBag);
61
+ __privateAdd(this, _loadClaimedAssets);
59
62
  __privateAdd(this, _createSponsoredTransactionBlock);
60
63
  __privateAdd(this, _executeSponsoredTransactionBlock);
61
64
  __privateAdd(this, _fetch);
62
65
  __privateAdd(this, _listNonContractClaimableAssets);
63
66
  __privateAdd(this, _createNonContractClaimTransaction);
64
67
  __privateAdd(this, _loadOwnedObjects);
65
- __privateAdd(this, _loadInitialTransactionData);
66
68
  __privateAdd(this, _client, void 0);
67
- __privateAdd(this, _address, void 0);
68
- __privateAdd(this, _keypair, void 0);
69
- __privateAdd(this, _initiallyOwnedObjects, /* @__PURE__ */ new Set());
70
- __privateAdd(this, _ownedObjects, []);
71
- __privateAdd(this, _bagObjects, null);
72
- __privateAdd(this, _gasCoin, void 0);
73
- __privateAdd(this, _hasSui, false);
74
- __privateAdd(this, _creatorAddress, void 0);
75
69
  __privateAdd(this, _contract, void 0);
76
70
  __privateAdd(this, _claimApi, void 0);
77
71
  __privateAdd(this, _network, void 0);
78
72
  __privateAdd(this, _host, void 0);
79
73
  __privateAdd(this, _path, void 0);
74
+ // State for non-contract based links
75
+ __privateAdd(this, _gasCoin, void 0);
76
+ __privateAdd(this, _hasSui, false);
77
+ __privateAdd(this, _ownedObjects, []);
80
78
  if (!keypair && !address) {
81
79
  throw new Error("Either keypair or address must be provided");
82
80
  }
83
81
  __privateSet(this, _client, client);
84
- __privateSet(this, _keypair, keypair);
85
- __privateSet(this, _address, address ?? keypair.toSuiAddress());
82
+ this.keypair = keypair;
83
+ this.address = address ?? keypair.toSuiAddress();
86
84
  __privateSet(this, _claimApi, claimApi);
87
85
  __privateSet(this, _network, network);
88
86
  __privateSet(this, _host, host);
@@ -94,25 +92,18 @@ const _ZkSendLink = class {
94
92
  __privateSet(this, _contract, new ZkBag(contract.packageId, contract));
95
93
  }
96
94
  }
97
- static async fromUrl(url, {
98
- contract,
99
- ...options
100
- } = {}) {
95
+ static async fromUrl(url, options = {}) {
101
96
  const parsed = new URL(url);
102
97
  const isContractLink = parsed.hash.startsWith("#$");
103
98
  let link;
104
99
  if (isContractLink) {
105
- if (!contract) {
106
- throw new Error("Contract options are required for contract based links");
107
- }
108
100
  const keypair = Ed25519Keypair.fromSecretKey(fromB64(parsed.hash.slice(2)));
109
101
  link = new _ZkSendLink({
110
102
  ...options,
111
103
  keypair,
112
104
  host: `${parsed.protocol}//${parsed.host}`,
113
105
  path: parsed.pathname,
114
- isContractLink: true,
115
- contract
106
+ isContractLink: true
116
107
  });
117
108
  } else {
118
109
  const keypair = Ed25519Keypair.fromSecretKey(
@@ -126,7 +117,7 @@ const _ZkSendLink = class {
126
117
  isContractLink: false
127
118
  });
128
119
  }
129
- await link.loadOwnedData();
120
+ await link.loadAssets();
130
121
  return link;
131
122
  }
132
123
  static async fromAddress(address, options) {
@@ -135,83 +126,53 @@ const _ZkSendLink = class {
135
126
  address,
136
127
  isContractLink: true
137
128
  });
138
- await link.loadOwnedData();
129
+ await link.loadAssets();
139
130
  return link;
140
131
  }
141
- async loadOwnedData() {
132
+ async loadAssets() {
142
133
  if (__privateGet(this, _contract)) {
143
134
  await __privateMethod(this, _loadBag, loadBag_fn).call(this);
144
135
  } else {
145
- await Promise.all([__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this)]);
136
+ await __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this);
146
137
  }
147
138
  }
148
- async listClaimableAssets(address, options) {
149
- if (!__privateGet(this, _contract)) {
150
- return __privateMethod(this, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn).call(this, address, options);
151
- }
152
- const coins = [];
153
- const nfts = [];
154
- for (const object of __privateGet(this, _bagObjects) ?? []) {
155
- const type = parseStructTag(object.type);
156
- if (type.address === normalizeSuiAddress("0x2") && type.module === "coin" && type.name === "Coin") {
157
- coins.push(object);
158
- } else {
159
- nfts.push(object);
160
- }
161
- }
162
- const balances = /* @__PURE__ */ new Map();
163
- coins.forEach((coin) => {
164
- if (coin.content?.dataType !== "moveObject") {
165
- return;
166
- }
167
- const amount = BigInt(coin.content.fields.balance);
168
- const coinType = normalizeStructTag(parseStructTag(coin.content.type).typeParams[0]);
169
- if (!balances.has(coinType)) {
170
- balances.set(coinType, { coinType, amount });
171
- } else {
172
- balances.get(coinType).amount += amount;
173
- }
174
- });
175
- return {
176
- balances: [...balances.values()],
177
- nfts,
178
- coins
179
- };
180
- }
181
- async claimAssets(address, options) {
182
- if (!__privateGet(this, _keypair)) {
139
+ async claimAssets(address) {
140
+ if (!this.keypair) {
183
141
  throw new Error("Cannot claim assets without links keypair");
184
142
  }
185
- const txb = this.createClaimTransaction(address, options);
186
- if (!__privateGet(this, _contract) || !__privateGet(this, _bagObjects)) {
143
+ if (this.claimed) {
144
+ throw new Error("Assets have already been claimed");
145
+ }
146
+ if (!__privateGet(this, _contract)) {
187
147
  return __privateGet(this, _client).signAndExecuteTransactionBlock({
188
- transactionBlock: txb,
189
- signer: __privateGet(this, _keypair)
148
+ transactionBlock: this.createClaimTransaction(address),
149
+ signer: this.keypair
190
150
  });
191
151
  }
192
- const { digest } = await __privateMethod(this, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn).call(this, await __privateMethod(this, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn).call(this, txb, address, __privateGet(this, _keypair).toSuiAddress()), __privateGet(this, _keypair));
152
+ if (!this.assets) {
153
+ await __privateMethod(this, _loadBag, loadBag_fn).call(this);
154
+ }
155
+ const txb = this.createClaimTransaction(address);
156
+ const { digest } = await __privateMethod(this, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn).call(this, await __privateMethod(this, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn).call(this, txb, address, this.keypair.toSuiAddress()), this.keypair);
193
157
  return __privateGet(this, _client).waitForTransactionBlock({ digest });
194
158
  }
195
159
  createClaimTransaction(address, {
196
- reclaim,
197
- ...options
160
+ reclaim
198
161
  } = {}) {
199
162
  if (!__privateGet(this, _contract)) {
200
- return __privateMethod(this, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn).call(this, address, options);
163
+ return __privateMethod(this, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn).call(this, address);
201
164
  }
202
- if (Object.keys(options).length > 0) {
203
- throw new Error("Filtering claims is not supported for contract based links");
204
- }
205
- if (!__privateGet(this, _keypair) && !reclaim) {
165
+ if (!this.keypair && !reclaim) {
206
166
  throw new Error("Cannot claim assets without the links keypair");
207
167
  }
208
168
  const txb = new TransactionBlock();
209
- const sender = reclaim ? address : __privateGet(this, _keypair).toSuiAddress();
169
+ const sender = reclaim ? address : this.keypair.toSuiAddress();
210
170
  txb.setSender(sender);
211
171
  const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
212
- const [bag, proof] = reclaim ? __privateGet(this, _contract).reclaim(txb, { arguments: [store, __privateGet(this, _address)] }) : __privateGet(this, _contract).init_claim(txb, { arguments: [store] });
172
+ const [bag, proof] = reclaim ? __privateGet(this, _contract).reclaim(txb, { arguments: [store, this.address] }) : __privateGet(this, _contract).init_claim(txb, { arguments: [store] });
213
173
  const objectsToTransfer = [];
214
- for (const object of __privateGet(this, _bagObjects) ?? []) {
174
+ const objects = [...this.assets?.coins ?? [], ...this.assets?.nfts ?? []];
175
+ for (const object of objects) {
215
176
  objectsToTransfer.push(
216
177
  __privateGet(this, _contract).claim(txb, {
217
178
  arguments: [
@@ -234,7 +195,13 @@ const _ZkSendLink = class {
234
195
  return txb;
235
196
  }
236
197
  async createRegenerateTransaction(sender, options = {}) {
237
- if (!__privateGet(this, _contract) || !__privateGet(this, _bagObjects)) {
198
+ if (!this.assets) {
199
+ await __privateMethod(this, _loadBag, loadBag_fn).call(this);
200
+ }
201
+ if (this.claimed) {
202
+ throw new Error("Assets have already been claimed");
203
+ }
204
+ if (!__privateGet(this, _contract)) {
238
205
  throw new Error("Regenerating non-contract based links is not supported");
239
206
  }
240
207
  const txb = new TransactionBlock();
@@ -251,7 +218,7 @@ const _ZkSendLink = class {
251
218
  keypair: newLinkKp
252
219
  });
253
220
  const to = txb.pure.address(newLinkKp.toSuiAddress());
254
- __privateGet(this, _contract).update_receiver(txb, { arguments: [store, __privateGet(this, _address), to] });
221
+ __privateGet(this, _contract).update_receiver(txb, { arguments: [store, this.address, to] });
255
222
  return {
256
223
  url: newLink.getLink(),
257
224
  transactionBlock: txb
@@ -260,35 +227,40 @@ const _ZkSendLink = class {
260
227
  };
261
228
  let ZkSendLink = _ZkSendLink;
262
229
  _client = new WeakMap();
263
- _address = new WeakMap();
264
- _keypair = new WeakMap();
265
- _initiallyOwnedObjects = new WeakMap();
266
- _ownedObjects = new WeakMap();
267
- _bagObjects = new WeakMap();
268
- _gasCoin = new WeakMap();
269
- _hasSui = new WeakMap();
270
- _creatorAddress = new WeakMap();
271
230
  _contract = new WeakMap();
272
231
  _claimApi = new WeakMap();
273
232
  _network = new WeakMap();
274
233
  _host = new WeakMap();
275
234
  _path = new WeakMap();
235
+ _gasCoin = new WeakMap();
236
+ _hasSui = new WeakMap();
237
+ _ownedObjects = new WeakMap();
276
238
  _loadBag = new WeakSet();
277
239
  loadBag_fn = async function() {
278
240
  if (!__privateGet(this, _contract)) {
279
241
  return;
280
242
  }
243
+ this.assets = {
244
+ balances: [],
245
+ nfts: [],
246
+ coins: []
247
+ };
281
248
  const bagField = await __privateGet(this, _client).getDynamicFieldObject({
282
249
  parentId: __privateGet(this, _contract).ids.bagStoreTableId,
283
250
  name: {
284
251
  type: "address",
285
- value: __privateGet(this, _address)
252
+ value: this.address
286
253
  }
287
254
  });
288
255
  if (!bagField.data) {
256
+ this.claimed = true;
257
+ await __privateMethod(this, _loadClaimedAssets, loadClaimedAssets_fn).call(this);
289
258
  return;
259
+ } else {
260
+ this.claimed = false;
290
261
  }
291
262
  const itemIds = bagField.data?.content?.fields?.value?.fields?.item_ids.fields.contents;
263
+ this.creatorAddress = bagField.data?.content?.fields?.value?.fields?.owner;
292
264
  if (!itemIds) {
293
265
  throw new Error("Invalid bag field");
294
266
  }
@@ -299,18 +271,81 @@ loadBag_fn = async function() {
299
271
  showContent: true
300
272
  }
301
273
  });
302
- __privateSet(this, _bagObjects, objectsResponse.map((object, i) => {
303
- if (!object.data) {
274
+ const balances = /* @__PURE__ */ new Map();
275
+ objectsResponse.forEach((object, i) => {
276
+ if (!object.data || !object.data.type) {
304
277
  throw new Error(`Failed to load claimable object ${itemIds[i]}`);
305
278
  }
306
- return {
307
- objectId: object.data.objectId,
308
- type: normalizeStructTag(object.data.type),
309
- version: object.data.version,
310
- digest: object.data.digest,
311
- content: object.data.content
312
- };
313
- }));
279
+ const type = parseStructTag(normalizeStructTag(object.data.type));
280
+ if (type.address === normalizeSuiAddress("0x2") && type.module === "coin" && type.name === "Coin") {
281
+ this.assets.coins.push({
282
+ objectId: object.data.objectId,
283
+ type: object.data.type,
284
+ version: object.data.version,
285
+ digest: object.data.digest
286
+ });
287
+ if (object.data.content?.dataType === "moveObject") {
288
+ const amount = BigInt(object.data.content.fields.balance);
289
+ const coinType = normalizeStructTag(
290
+ parseStructTag(object.data.content.type).typeParams[0]
291
+ );
292
+ if (!balances.has(coinType)) {
293
+ balances.set(coinType, { coinType, amount });
294
+ } else {
295
+ balances.get(coinType).amount += amount;
296
+ }
297
+ }
298
+ } else {
299
+ this.assets.nfts.push({
300
+ objectId: object.data.objectId,
301
+ type: object.data.type,
302
+ version: object.data.version,
303
+ digest: object.data.digest
304
+ });
305
+ }
306
+ });
307
+ this.assets.balances = [...balances.values()];
308
+ };
309
+ _loadClaimedAssets = new WeakSet();
310
+ loadClaimedAssets_fn = async function() {
311
+ const result = await __privateGet(this, _client).queryTransactionBlocks({
312
+ limit: 1,
313
+ filter: {
314
+ FromAddress: this.address
315
+ },
316
+ options: {
317
+ showObjectChanges: true,
318
+ showBalanceChanges: true,
319
+ showInput: true
320
+ }
321
+ });
322
+ if (!result?.data[0]) {
323
+ return;
324
+ }
325
+ const [txb] = result.data;
326
+ if (txb.transaction?.data.transaction.kind !== "ProgrammableTransaction") {
327
+ return;
328
+ }
329
+ const transfer = txb.transaction.data.transaction.transactions.findLast(
330
+ (tx) => "TransferObjects" in tx
331
+ );
332
+ if (!transfer) {
333
+ return;
334
+ }
335
+ const receiverArg = transfer.TransferObjects[1];
336
+ if (!(typeof receiverArg === "object" && "Input" in receiverArg)) {
337
+ return;
338
+ }
339
+ const input = txb.transaction.data.transaction.inputs[receiverArg.Input];
340
+ if (input.type !== "pure") {
341
+ return;
342
+ }
343
+ const receiver = typeof input.value === "string" ? input.value : bcs.Address.parse(new Uint8Array(input.value.Pure));
344
+ this.assets = getAssetsFromTxnBlock({
345
+ transactionBlock: txb,
346
+ address: receiver,
347
+ isSent: false
348
+ });
314
349
  };
315
350
  _createSponsoredTransactionBlock = new WeakSet();
316
351
  createSponsoredTransactionBlock_fn = async function(txb, claimer, sender) {
@@ -362,18 +397,26 @@ fetch_fn = async function(path, init) {
362
397
  return data;
363
398
  };
364
399
  _listNonContractClaimableAssets = new WeakSet();
365
- listNonContractClaimableAssets_fn = async function(address, options) {
400
+ listNonContractClaimableAssets_fn = async function() {
401
+ const balances = [];
402
+ const nfts = [];
403
+ const coins = [];
404
+ if (__privateGet(this, _ownedObjects).length === 0 && !__privateGet(this, _hasSui)) {
405
+ return {
406
+ balances,
407
+ nfts,
408
+ coins
409
+ };
410
+ }
411
+ const address = new Ed25519Keypair().toSuiAddress();
366
412
  const normalizedAddress = normalizeSuiAddress(address);
367
- const txb = this.createClaimTransaction(normalizedAddress, options);
413
+ const txb = this.createClaimTransaction(normalizedAddress);
368
414
  if (__privateGet(this, _gasCoin) || !__privateGet(this, _hasSui)) {
369
415
  txb.setGasPayment([]);
370
416
  }
371
417
  const dryRun = await __privateGet(this, _client).dryRunTransactionBlock({
372
418
  transactionBlock: await txb.build({ client: __privateGet(this, _client) })
373
419
  });
374
- const balances = [];
375
- const nfts = [];
376
- const coins = [];
377
420
  dryRun.balanceChanges.forEach((balanceChange) => {
378
421
  if (BigInt(balanceChange.amount) > 0n && isOwner(balanceChange.owner, normalizedAddress)) {
379
422
  balances.push({
@@ -403,16 +446,12 @@ listNonContractClaimableAssets_fn = async function(address, options) {
403
446
  };
404
447
  };
405
448
  _createNonContractClaimTransaction = new WeakSet();
406
- createNonContractClaimTransaction_fn = function(address, options) {
407
- if (!__privateGet(this, _keypair)) {
449
+ createNonContractClaimTransaction_fn = function(address) {
450
+ if (!this.keypair) {
408
451
  throw new Error("Cannot claim assets without the links keypair");
409
452
  }
410
- const claimAll = !options?.coinTypes && !options?.objects;
411
453
  const txb = new TransactionBlock();
412
- txb.setSender(__privateGet(this, _keypair).toSuiAddress());
413
- const coinTypes = new Set(
414
- options?.coinTypes?.map((type) => normalizeStructTag(`0x2::coin::Coin<${type}>`)) ?? []
415
- );
454
+ txb.setSender(this.keypair.toSuiAddress());
416
455
  const objectsToTransfer = __privateGet(this, _ownedObjects).filter((object) => {
417
456
  if (__privateGet(this, _gasCoin)) {
418
457
  if (object.objectId === __privateGet(this, _gasCoin).coinObjectId) {
@@ -421,17 +460,11 @@ createNonContractClaimTransaction_fn = function(address, options) {
421
460
  } else if (object.type === SUI_COIN_OBJECT_TYPE) {
422
461
  return false;
423
462
  }
424
- if (coinTypes?.has(object.type) || options?.objects?.includes(object.objectId)) {
425
- return true;
426
- }
427
- if (!options?.claimObjectsAddedAfterCreation && !__privateGet(this, _initiallyOwnedObjects).has(object.objectId)) {
428
- return false;
429
- }
430
- return claimAll;
463
+ return true;
431
464
  }).map((object) => txb.object(object.objectId));
432
- if (__privateGet(this, _gasCoin) && __privateGet(this, _creatorAddress)) {
433
- txb.transferObjects([txb.gas], __privateGet(this, _creatorAddress));
434
- } else if (claimAll || coinTypes?.has(SUI_COIN_TYPE)) {
465
+ if (__privateGet(this, _gasCoin) && this.creatorAddress) {
466
+ txb.transferObjects([txb.gas], this.creatorAddress);
467
+ } else {
435
468
  objectsToTransfer.push(txb.gas);
436
469
  }
437
470
  if (objectsToTransfer.length > 0) {
@@ -441,14 +474,19 @@ createNonContractClaimTransaction_fn = function(address, options) {
441
474
  };
442
475
  _loadOwnedObjects = new WeakSet();
443
476
  loadOwnedObjects_fn = async function() {
444
- __privateSet(this, _ownedObjects, []);
477
+ this.assets = {
478
+ nfts: [],
479
+ balances: [],
480
+ coins: []
481
+ };
445
482
  let nextCursor;
446
483
  do {
447
484
  const ownedObjects = await __privateGet(this, _client).getOwnedObjects({
448
485
  cursor: nextCursor,
449
- owner: __privateGet(this, _address),
486
+ owner: this.address,
450
487
  options: {
451
- showType: true
488
+ showType: true,
489
+ showContent: true
452
490
  }
453
491
  });
454
492
  nextCursor = ownedObjects.hasNextPage ? ownedObjects.nextCursor : null;
@@ -465,43 +503,31 @@ loadOwnedObjects_fn = async function() {
465
503
  } while (nextCursor);
466
504
  const coins = await __privateGet(this, _client).getCoins({
467
505
  coinType: SUI_COIN_TYPE,
468
- owner: __privateGet(this, _address)
506
+ owner: this.address
469
507
  });
470
508
  __privateSet(this, _hasSui, coins.data.length > 0);
471
509
  __privateSet(this, _gasCoin, coins.data.find((coin) => BigInt(coin.balance) % 1000n === 987n));
472
- };
473
- _loadInitialTransactionData = new WeakSet();
474
- loadInitialTransactionData_fn = async function() {
475
510
  const result = await __privateGet(this, _client).queryTransactionBlocks({
476
511
  limit: 1,
477
512
  order: "ascending",
478
513
  filter: {
479
- ToAddress: __privateGet(this, _address)
514
+ ToAddress: this.address
480
515
  },
481
516
  options: {
482
- showObjectChanges: true,
483
- showInput: true
484
- }
485
- });
486
- result.data[0]?.objectChanges?.forEach((objectChange) => {
487
- if (ownedAfterChange(objectChange, __privateGet(this, _address))) {
488
- __privateGet(this, _initiallyOwnedObjects).add(normalizeSuiObjectId(objectChange.objectId));
517
+ showInput: true,
518
+ showBalanceChanges: true,
519
+ showObjectChanges: true
489
520
  }
490
521
  });
491
- __privateSet(this, _creatorAddress, result.data[0]?.transaction?.data.sender);
492
- };
493
- function ownedAfterChange(objectChange, address) {
494
- if (objectChange.type === "transferred" && isOwner(objectChange.recipient, address)) {
495
- return true;
522
+ this.creatorAddress = result.data[0]?.transaction?.data.sender;
523
+ if (__privateGet(this, _hasSui) || __privateGet(this, _ownedObjects).length > 0) {
524
+ this.claimed = false;
525
+ this.assets = await __privateMethod(this, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn).call(this);
526
+ } else if (result.data[0]) {
527
+ this.claimed = true;
528
+ await __privateMethod(this, _loadClaimedAssets, loadClaimedAssets_fn).call(this);
496
529
  }
497
- if ((objectChange.type === "created" || objectChange.type === "mutated") && isOwner(objectChange.owner, address)) {
498
- return true;
499
- }
500
- return false;
501
- }
502
- function isOwner(owner, address) {
503
- return owner && typeof owner === "object" && "AddressOwner" in owner && normalizeSuiAddress(owner.AddressOwner) === address;
504
- }
530
+ };
505
531
  export {
506
532
  ZkSendLink
507
533
  };