@mysten/zksend 0.5.0 → 0.7.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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mysten/zksend
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 879421a5ac: Add support for creating links from objects created in the same transaction block
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [774bfb41a8]
12
+ - @mysten/sui.js@0.53.0
13
+ - @mysten/wallet-standard@0.11.4
14
+
15
+ ## 0.6.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 905bc99e88: Add `createSendToAddressTransaction` method
20
+
21
+ ### Patch Changes
22
+
23
+ - 9a9ff3cde1: Fix assets extracted from transactionBlocks using type instead of objectType from object changes"
24
+
3
25
  ## 0.5.0
4
26
 
5
27
  ### Minor Changes
@@ -9,8 +9,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
9
9
  address: import("valibot").StringSchema<string>;
10
10
  }, undefined, {
11
11
  address: string;
12
- data: string;
13
12
  type: "sign-transaction-block";
13
+ data: string;
14
14
  }>, import("valibot").ObjectSchema<{
15
15
  type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
16
16
  bytes: import("valibot").StringSchema<string>;
@@ -23,8 +23,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
23
23
  type: "connect";
24
24
  } | {
25
25
  address: string;
26
- data: string;
27
26
  type: "sign-transaction-block";
27
+ data: string;
28
28
  } | {
29
29
  address: string;
30
30
  type: "sign-personal-message";
@@ -45,8 +45,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
45
45
  address: import("valibot").StringSchema<string>;
46
46
  }, undefined, {
47
47
  address: string;
48
- data: string;
49
48
  type: "sign-transaction-block";
49
+ data: string;
50
50
  }>, import("valibot").ObjectSchema<{
51
51
  type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
52
52
  bytes: import("valibot").StringSchema<string>;
@@ -59,8 +59,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
59
59
  type: "connect";
60
60
  } | {
61
61
  address: string;
62
- data: string;
63
62
  type: "sign-transaction-block";
63
+ data: string;
64
64
  } | {
65
65
  address: string;
66
66
  type: "sign-personal-message";
@@ -73,8 +73,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
73
73
  type: "connect";
74
74
  } | {
75
75
  address: string;
76
- data: string;
77
76
  type: "sign-transaction-block";
77
+ data: string;
78
78
  } | {
79
79
  address: string;
80
80
  type: "sign-personal-message";
@@ -159,6 +159,7 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
159
159
  bytes: string;
160
160
  }>;
161
161
  }, undefined, {
162
+ type: "resolve";
162
163
  data: {
163
164
  address: string;
164
165
  type: "connect";
@@ -171,10 +172,10 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
171
172
  type: "sign-personal-message";
172
173
  bytes: string;
173
174
  };
174
- type: "resolve";
175
175
  }>], {
176
176
  type: "reject";
177
177
  } | {
178
+ type: "resolve";
178
179
  data: {
179
180
  address: string;
180
181
  type: "connect";
@@ -187,7 +188,6 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
187
188
  type: "sign-personal-message";
188
189
  bytes: string;
189
190
  };
190
- type: "resolve";
191
191
  }>;
192
192
  export type ZkSendResponsePayload = Output<typeof ZkSendResponsePayload>;
193
193
  export declare const ZkSendResponse: import("valibot").ObjectSchema<{
@@ -234,6 +234,7 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
234
234
  bytes: string;
235
235
  }>;
236
236
  }, undefined, {
237
+ type: "resolve";
237
238
  data: {
238
239
  address: string;
239
240
  type: "connect";
@@ -246,10 +247,10 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
246
247
  type: "sign-personal-message";
247
248
  bytes: string;
248
249
  };
249
- type: "resolve";
250
250
  }>], {
251
251
  type: "reject";
252
252
  } | {
253
+ type: "resolve";
253
254
  data: {
254
255
  address: string;
255
256
  type: "connect";
@@ -262,13 +263,13 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
262
263
  type: "sign-personal-message";
263
264
  bytes: string;
264
265
  };
265
- type: "resolve";
266
266
  }>;
267
267
  }, undefined, {
268
268
  id: string;
269
269
  payload: {
270
270
  type: "reject";
271
271
  } | {
272
+ type: "resolve";
272
273
  data: {
273
274
  address: string;
274
275
  type: "connect";
@@ -281,7 +282,6 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
281
282
  type: "sign-personal-message";
282
283
  bytes: string;
283
284
  };
284
- type: "resolve";
285
285
  };
286
286
  source: "zksend-channel";
287
287
  }>;
@@ -24,8 +24,8 @@ export declare class ZkSendHost {
24
24
  type: "connect";
25
25
  } | {
26
26
  address: string;
27
- data: string;
28
27
  type: "sign-transaction-block";
28
+ data: string;
29
29
  } | {
30
30
  address: string;
31
31
  type: "sign-personal-message";
@@ -1,6 +1,6 @@
1
1
  import { SuiClient } from '@mysten/sui.js/client';
2
2
  import type { Keypair, Signer } from '@mysten/sui.js/cryptography';
3
- import type { TransactionObjectInput } from '@mysten/sui.js/transactions';
3
+ import type { TransactionObjectArgument, TransactionObjectInput } from '@mysten/sui.js/transactions';
4
4
  import { TransactionBlock } from '@mysten/sui.js/transactions';
5
5
  import type { ZkBagContractOptions } from './zk-bag.js';
6
6
  interface ZkSendLinkRedirect {
@@ -28,6 +28,10 @@ export interface CreateZkSendLinkOptions {
28
28
  export declare class ZkSendLinkBuilder {
29
29
  #private;
30
30
  objectIds: Set<string>;
31
+ objectRefs: {
32
+ ref: TransactionObjectArgument;
33
+ type: string;
34
+ }[];
31
35
  balances: Map<string, bigint>;
32
36
  sender: string;
33
37
  keypair: Keypair;
@@ -35,12 +39,16 @@ export declare class ZkSendLinkBuilder {
35
39
  addClaimableMist(amount: bigint): void;
36
40
  addClaimableBalance(coinType: string, amount: bigint): void;
37
41
  addClaimableObject(id: string): void;
42
+ addClaimableObjectRef(ref: TransactionObjectArgument, type: string): void;
38
43
  getLink(): string;
39
44
  create({ signer, ...options }: CreateZkSendLinkOptions & {
40
45
  signer: Signer;
41
46
  waitForTransactionBlock?: boolean;
42
47
  }): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
43
48
  createSendTransaction({ transactionBlock, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>;
49
+ createSendToAddressTransaction({ transactionBlock, address, }: CreateZkSendLinkOptions & {
50
+ address: string;
51
+ }): Promise<TransactionBlock>;
44
52
  static createLinks({ links, network, client, transactionBlock, contract: contractIds, }: {
45
53
  transactionBlock?: TransactionBlock;
46
54
  client?: SuiClient;
@@ -72,6 +72,7 @@ const _ZkSendLinkBuilder = class {
72
72
  __privateAdd(this, _estimateClaimGasFee);
73
73
  __privateAdd(this, _getCoinsByType);
74
74
  this.objectIds = /* @__PURE__ */ new Set();
75
+ this.objectRefs = [];
75
76
  this.balances = /* @__PURE__ */ new Map();
76
77
  __privateAdd(this, _host, void 0);
77
78
  __privateAdd(this, _path, void 0);
@@ -99,6 +100,9 @@ const _ZkSendLinkBuilder = class {
99
100
  addClaimableObject(id) {
100
101
  this.objectIds.add(id);
101
102
  }
103
+ addClaimableObjectRef(ref, type) {
104
+ this.objectRefs.push({ ref, type });
105
+ }
102
106
  getLink() {
103
107
  const link = new URL(__privateGet(this, _host));
104
108
  link.pathname = __privateGet(this, _path);
@@ -142,6 +146,17 @@ const _ZkSendLinkBuilder = class {
142
146
  links: [this]
143
147
  });
144
148
  }
149
+ async createSendToAddressTransaction({
150
+ transactionBlock = new import_transactions.TransactionBlock(),
151
+ address
152
+ }) {
153
+ const objectsToTransfer = (await __privateMethod(this, _objectsToTransfer, objectsToTransfer_fn).call(this, transactionBlock)).map(
154
+ (obj) => obj.ref
155
+ );
156
+ transactionBlock.setSenderIfNotSet(this.sender);
157
+ transactionBlock.transferObjects(objectsToTransfer, address);
158
+ return transactionBlock;
159
+ }
145
160
  static async createLinks({
146
161
  links,
147
162
  network = "mainnet",
@@ -153,11 +168,13 @@ const _ZkSendLinkBuilder = class {
153
168
  const store = transactionBlock.object(contract.ids.bagStoreId);
154
169
  const coinsByType = /* @__PURE__ */ new Map();
155
170
  const allIds = links.flatMap((link) => [...link.objectIds]);
171
+ const sender = links[0].sender;
172
+ transactionBlock.setSenderIfNotSet(sender);
156
173
  await Promise.all(
157
174
  [...new Set(links.flatMap((link) => [...link.balances.keys()]))].map(async (coinType) => {
158
175
  const coins = await client.getCoins({
159
176
  coinType,
160
- owner: links[0].sender
177
+ owner: sender
161
178
  });
162
179
  coinsByType.set(
163
180
  coinType,
@@ -213,6 +230,12 @@ const _ZkSendLinkBuilder = class {
213
230
  for (const link of links) {
214
231
  const receiver = link.keypair.toSuiAddress();
215
232
  contract.new(transactionBlock, { arguments: [store, receiver] });
233
+ link.objectRefs.forEach(({ ref, type }) => {
234
+ contract.add(transactionBlock, {
235
+ arguments: [store, receiver, ref],
236
+ typeArguments: [type]
237
+ });
238
+ });
216
239
  link.objectIds.forEach((id) => {
217
240
  const object = objectRefs.get(id);
218
241
  if (!object) {
@@ -251,25 +274,26 @@ _contract = new WeakMap();
251
274
  _objectsToTransfer = new WeakSet();
252
275
  objectsToTransfer_fn = async function(txb) {
253
276
  const objectIDs = [...this.objectIds];
254
- const refsWithType = (await __privateGet(this, _client).multiGetObjects({
255
- ids: objectIDs,
256
- options: {
257
- showType: true
258
- }
259
- })).map((res, i) => {
260
- if (!res.data || res.error) {
261
- throw new Error(`Failed to load object ${objectIDs[i]} (${res.error?.code})`);
262
- }
263
- return {
264
- ref: txb.objectRef({
265
- version: res.data.version,
266
- digest: res.data.digest,
267
- objectId: res.data.objectId
268
- }),
269
- type: res.data.type
270
- };
271
- });
272
- txb.setSenderIfNotSet(this.sender);
277
+ const refsWithType = this.objectRefs.concat(
278
+ (objectIDs.length > 0 ? await __privateGet(this, _client).multiGetObjects({
279
+ ids: objectIDs,
280
+ options: {
281
+ showType: true
282
+ }
283
+ }) : []).map((res, i) => {
284
+ if (!res.data || res.error) {
285
+ throw new Error(`Failed to load object ${objectIDs[i]} (${res.error?.code})`);
286
+ }
287
+ return {
288
+ ref: txb.objectRef({
289
+ version: res.data.version,
290
+ digest: res.data.digest,
291
+ objectId: res.data.objectId
292
+ }),
293
+ type: res.data.type
294
+ };
295
+ })
296
+ );
273
297
  for (const [coinType, amount] of this.balances) {
274
298
  if (coinType === SUI_COIN_TYPE) {
275
299
  const [sui] = txb.splitCoins(txb.gas, [amount]);
@@ -285,7 +309,7 @@ objectsToTransfer_fn = async function(txb) {
285
309
  const [split] = txb.splitCoins(coins[0], [amount]);
286
310
  refsWithType.push({
287
311
  ref: split,
288
- type: `0x2::coin:Coin<${coinType}>`
312
+ type: `0x2::coin::Coin<${coinType}>`
289
313
  });
290
314
  }
291
315
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/links/builder.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client';\nimport type { CoinStruct } from '@mysten/sui.js/client';\nimport { decodeSuiPrivateKey } from '@mysten/sui.js/cryptography';\nimport type { Keypair, Signer } from '@mysten/sui.js/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';\nimport type {\n\tTransactionObjectArgument,\n\tTransactionObjectInput,\n} from '@mysten/sui.js/transactions';\nimport { TransactionBlock } from '@mysten/sui.js/transactions';\nimport { normalizeStructTag, normalizeSuiAddress, SUI_TYPE_ARG, toB64 } from '@mysten/sui.js/utils';\n\nimport type { ZkBagContractOptions } from './zk-bag.js';\nimport { MAINNET_CONTRACT_IDS, ZkBag } from './zk-bag.js';\n\ninterface ZkSendLinkRedirect {\n\turl: string;\n\tname?: string;\n}\n\nexport interface ZkSendLinkBuilderOptions {\n\thost?: string;\n\tpath?: string;\n\tkeypair?: Keypair;\n\tnetwork?: 'mainnet' | 'testnet';\n\tclient?: SuiClient;\n\tsender: string;\n\tredirect?: ZkSendLinkRedirect;\n\tcontract?: ZkBagContractOptions | null;\n}\n\nconst DEFAULT_ZK_SEND_LINK_OPTIONS = {\n\thost: 'https://zksend.com',\n\tpath: '/claim',\n\tnetwork: 'mainnet' as const,\n};\n\nconst SUI_COIN_TYPE = normalizeStructTag(SUI_TYPE_ARG);\n\nexport interface CreateZkSendLinkOptions {\n\ttransactionBlock?: TransactionBlock;\n\tcalculateGas?: (options: {\n\t\tbalances: Map<string, bigint>;\n\t\tobjects: TransactionObjectInput[];\n\t\tgasEstimateFromDryRun: bigint;\n\t}) => Promise<bigint> | bigint;\n}\n\nexport class ZkSendLinkBuilder {\n\tobjectIds = new Set<string>();\n\tbalances = new Map<string, bigint>();\n\tsender: string;\n\t#host: string;\n\t#path: string;\n\tkeypair: Keypair;\n\t#client: SuiClient;\n\t#redirect?: ZkSendLinkRedirect;\n\t#coinsByType = new Map<string, CoinStruct[]>();\n\t#contract?: ZkBag<ZkBagContractOptions>;\n\n\tconstructor({\n\t\thost = DEFAULT_ZK_SEND_LINK_OPTIONS.host,\n\t\tpath = DEFAULT_ZK_SEND_LINK_OPTIONS.path,\n\t\tkeypair = new Ed25519Keypair(),\n\t\tnetwork = DEFAULT_ZK_SEND_LINK_OPTIONS.network,\n\t\tclient = new SuiClient({ url: getFullnodeUrl(network) }),\n\t\tsender,\n\t\tredirect,\n\t\tcontract = network === 'mainnet' ? MAINNET_CONTRACT_IDS : undefined,\n\t}: ZkSendLinkBuilderOptions) {\n\t\tthis.#host = host;\n\t\tthis.#path = path;\n\t\tthis.#redirect = redirect;\n\t\tthis.keypair = keypair;\n\t\tthis.#client = client;\n\t\tthis.sender = normalizeSuiAddress(sender);\n\n\t\tif (contract) {\n\t\t\tthis.#contract = new ZkBag(contract.packageId, contract);\n\t\t}\n\t}\n\n\taddClaimableMist(amount: bigint) {\n\t\tthis.addClaimableBalance(SUI_COIN_TYPE, amount);\n\t}\n\n\taddClaimableBalance(coinType: string, amount: bigint) {\n\t\tconst normalizedType = normalizeStructTag(coinType);\n\t\tthis.balances.set(normalizedType, (this.balances.get(normalizedType) ?? 0n) + amount);\n\t}\n\n\taddClaimableObject(id: string) {\n\t\tthis.objectIds.add(id);\n\t}\n\n\tgetLink(): string {\n\t\tconst link = new URL(this.#host);\n\t\tlink.pathname = this.#path;\n\t\tlink.hash = `${this.#contract ? '$' : ''}${toB64(\n\t\t\tdecodeSuiPrivateKey(this.keypair.getSecretKey()).secretKey,\n\t\t)}`;\n\n\t\tif (this.#redirect) {\n\t\t\tlink.searchParams.set('redirect_url', this.#redirect.url);\n\t\t\tif (this.#redirect.name) {\n\t\t\t\tlink.searchParams.set('name', this.#redirect.name);\n\t\t\t}\n\t\t}\n\n\t\treturn link.toString();\n\t}\n\n\tasync create({\n\t\tsigner,\n\t\t...options\n\t}: CreateZkSendLinkOptions & {\n\t\tsigner: Signer;\n\t\twaitForTransactionBlock?: boolean;\n\t}) {\n\t\tconst txb = await this.createSendTransaction(options);\n\n\t\tconst result = await this.#client.signAndExecuteTransactionBlock({\n\t\t\ttransactionBlock: await txb.build({ client: this.#client }),\n\t\t\tsigner,\n\t\t});\n\n\t\tif (options.waitForTransactionBlock) {\n\t\t\tawait this.#client.waitForTransactionBlock({ digest: result.digest });\n\t\t}\n\n\t\treturn result;\n\t}\n\tasync createSendTransaction({\n\t\ttransactionBlock = new TransactionBlock(),\n\t\tcalculateGas,\n\t}: CreateZkSendLinkOptions = {}) {\n\t\tif (!this.#contract) {\n\t\t\treturn this.#createSendTransactionWithoutContract({ transactionBlock, calculateGas });\n\t\t}\n\n\t\ttransactionBlock.setSenderIfNotSet(this.sender);\n\n\t\treturn ZkSendLinkBuilder.createLinks({\n\t\t\ttransactionBlock,\n\t\t\tclient: this.#client,\n\t\t\tcontract: this.#contract.ids,\n\t\t\tlinks: [this],\n\t\t});\n\t}\n\n\tasync #objectsToTransfer(txb: TransactionBlock) {\n\t\tconst objectIDs = [...this.objectIds];\n\t\tconst refsWithType: {\n\t\t\tref: TransactionObjectArgument;\n\t\t\ttype: string;\n\t\t}[] = (\n\t\t\tawait this.#client.multiGetObjects({\n\t\t\t\tids: objectIDs,\n\t\t\t\toptions: {\n\t\t\t\t\tshowType: true,\n\t\t\t\t},\n\t\t\t})\n\t\t).map((res, i) => {\n\t\t\tif (!res.data || res.error) {\n\t\t\t\tthrow new Error(`Failed to load object ${objectIDs[i]} (${res.error?.code})`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tref: txb.objectRef({\n\t\t\t\t\tversion: res.data.version,\n\t\t\t\t\tdigest: res.data.digest,\n\t\t\t\t\tobjectId: res.data.objectId,\n\t\t\t\t}),\n\t\t\t\ttype: res.data.type!,\n\t\t\t};\n\t\t});\n\n\t\ttxb.setSenderIfNotSet(this.sender);\n\n\t\tfor (const [coinType, amount] of this.balances) {\n\t\t\tif (coinType === SUI_COIN_TYPE) {\n\t\t\t\tconst [sui] = txb.splitCoins(txb.gas, [amount]);\n\t\t\t\trefsWithType.push({\n\t\t\t\t\tref: sui,\n\t\t\t\t\ttype: `0x2::coin::Coin<${coinType}>`,\n\t\t\t\t} as never);\n\t\t\t} else {\n\t\t\t\tconst coins = (await this.#getCoinsByType(coinType)).map((coin) => coin.coinObjectId);\n\n\t\t\t\tif (coins.length > 1) {\n\t\t\t\t\ttxb.mergeCoins(coins[0], coins.slice(1));\n\t\t\t\t}\n\t\t\t\tconst [split] = txb.splitCoins(coins[0], [amount]);\n\t\t\t\trefsWithType.push({\n\t\t\t\t\tref: split,\n\t\t\t\t\ttype: `0x2::coin:Coin<${coinType}>`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn refsWithType;\n\t}\n\n\tasync #createSendTransactionWithoutContract({\n\t\ttransactionBlock: txb = new TransactionBlock(),\n\t\tcalculateGas,\n\t}: CreateZkSendLinkOptions = {}) {\n\t\tconst gasEstimateFromDryRun = await this.#estimateClaimGasFee();\n\t\tconst baseGasAmount = calculateGas\n\t\t\t? await calculateGas({\n\t\t\t\t\tbalances: this.balances,\n\t\t\t\t\tobjects: [...this.objectIds],\n\t\t\t\t\tgasEstimateFromDryRun,\n\t\t\t })\n\t\t\t: gasEstimateFromDryRun * 2n;\n\n\t\t// Ensure that rounded gas is not less than the calculated gas\n\t\tconst gasWithBuffer = baseGasAmount + 1013n;\n\t\t// Ensure that gas amount ends in 987\n\t\tconst roundedGasAmount = gasWithBuffer - (gasWithBuffer % 1000n) - 13n;\n\n\t\tconst address = this.keypair.toSuiAddress();\n\t\tconst objectsToTransfer = (await this.#objectsToTransfer(txb)).map((obj) => obj.ref);\n\t\tconst [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]);\n\t\tobjectsToTransfer.push(gas);\n\n\t\ttxb.setSenderIfNotSet(this.sender);\n\t\ttxb.transferObjects(objectsToTransfer, address);\n\n\t\treturn txb;\n\t}\n\n\tasync #estimateClaimGasFee(): Promise<bigint> {\n\t\tconst txb = new TransactionBlock();\n\t\ttxb.setSender(this.sender);\n\t\ttxb.setGasPayment([]);\n\t\ttxb.transferObjects([txb.gas], this.keypair.toSuiAddress());\n\n\t\tconst idsToTransfer = [...this.objectIds];\n\n\t\tfor (const [coinType] of this.balances) {\n\t\t\tconst coins = await this.#getCoinsByType(coinType);\n\n\t\t\tif (!coins.length) {\n\t\t\t\tthrow new Error(`Sending account does not contain any coins of type ${coinType}`);\n\t\t\t}\n\n\t\t\tidsToTransfer.push(coins[0].coinObjectId);\n\t\t}\n\n\t\tif (idsToTransfer.length > 0) {\n\t\t\ttxb.transferObjects(\n\t\t\t\tidsToTransfer.map((id) => txb.object(id)),\n\t\t\t\tthis.keypair.toSuiAddress(),\n\t\t\t);\n\t\t}\n\n\t\tconst result = await this.#client.dryRunTransactionBlock({\n\t\t\ttransactionBlock: await txb.build({ client: this.#client }),\n\t\t});\n\n\t\treturn (\n\t\t\tBigInt(result.effects.gasUsed.computationCost) +\n\t\t\tBigInt(result.effects.gasUsed.storageCost) -\n\t\t\tBigInt(result.effects.gasUsed.storageRebate)\n\t\t);\n\t}\n\n\tasync #getCoinsByType(coinType: string) {\n\t\tif (this.#coinsByType.has(coinType)) {\n\t\t\treturn this.#coinsByType.get(coinType)!;\n\t\t}\n\n\t\tconst coins = await this.#client.getCoins({\n\t\t\tcoinType,\n\t\t\towner: this.sender,\n\t\t});\n\n\t\tthis.#coinsByType.set(coinType, coins.data);\n\n\t\treturn coins.data;\n\t}\n\n\tstatic async createLinks({\n\t\tlinks,\n\t\tnetwork = 'mainnet',\n\t\tclient = new SuiClient({ url: getFullnodeUrl(network) }),\n\t\ttransactionBlock = new TransactionBlock(),\n\t\tcontract: contractIds = MAINNET_CONTRACT_IDS,\n\t}: {\n\t\ttransactionBlock?: TransactionBlock;\n\t\tclient?: SuiClient;\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\tlinks: ZkSendLinkBuilder[];\n\t\tcontract?: ZkBagContractOptions;\n\t}) {\n\t\tconst contract = new ZkBag(contractIds.packageId, contractIds);\n\t\tconst store = transactionBlock.object(contract.ids.bagStoreId);\n\n\t\tconst coinsByType = new Map<string, CoinStruct[]>();\n\t\tconst allIds = links.flatMap((link) => [...link.objectIds]);\n\n\t\tawait Promise.all(\n\t\t\t[...new Set(links.flatMap((link) => [...link.balances.keys()]))].map(async (coinType) => {\n\t\t\t\tconst coins = await client.getCoins({\n\t\t\t\t\tcoinType,\n\t\t\t\t\towner: links[0].sender,\n\t\t\t\t});\n\n\t\t\t\tcoinsByType.set(\n\t\t\t\t\tcoinType,\n\t\t\t\t\tcoins.data.filter((coin) => !allIds.includes(coin.coinObjectId)),\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\n\t\tconst objectRefs = new Map<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tref: TransactionObjectArgument;\n\t\t\t\ttype: string;\n\t\t\t}\n\t\t>();\n\n\t\tconst pageSize = 50;\n\t\tlet offset = 0;\n\t\twhile (offset < allIds.length) {\n\t\t\tlet chunk = allIds.slice(offset, offset + pageSize);\n\t\t\toffset += pageSize;\n\n\t\t\tconst objects = await client.multiGetObjects({\n\t\t\t\tids: chunk,\n\t\t\t\toptions: {\n\t\t\t\t\tshowType: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const [i, res] of objects.entries()) {\n\t\t\t\tif (!res.data || res.error) {\n\t\t\t\t\tthrow new Error(`Failed to load object ${chunk[i]} (${res.error?.code})`);\n\t\t\t\t}\n\t\t\t\tobjectRefs.set(chunk[i], {\n\t\t\t\t\tref: transactionBlock.objectRef({\n\t\t\t\t\t\tversion: res.data.version,\n\t\t\t\t\t\tdigest: res.data.digest,\n\t\t\t\t\t\tobjectId: res.data.objectId,\n\t\t\t\t\t}),\n\t\t\t\t\ttype: res.data.type!,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst mergedCoins = new Map<string, TransactionObjectArgument>([\n\t\t\t[SUI_COIN_TYPE, transactionBlock.gas],\n\t\t]);\n\n\t\tfor (const [coinType, coins] of coinsByType) {\n\t\t\tif (coinType === SUI_COIN_TYPE) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [first, ...rest] = coins.map((coin) =>\n\t\t\t\ttransactionBlock.objectRef({\n\t\t\t\t\tobjectId: coin.coinObjectId,\n\t\t\t\t\tversion: coin.version,\n\t\t\t\t\tdigest: coin.digest,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (rest.length > 0) {\n\t\t\t\ttransactionBlock.mergeCoins(first, rest);\n\t\t\t}\n\t\t\tmergedCoins.set(coinType, transactionBlock.object(first));\n\t\t}\n\n\t\tfor (const link of links) {\n\t\t\tconst receiver = link.keypair.toSuiAddress();\n\t\t\tcontract.new(transactionBlock, { arguments: [store, receiver] });\n\n\t\t\tlink.objectIds.forEach((id) => {\n\t\t\t\tconst object = objectRefs.get(id);\n\t\t\t\tif (!object) {\n\t\t\t\t\tthrow new Error(`Object ${id} not found`);\n\t\t\t\t}\n\t\t\t\tcontract.add(transactionBlock, {\n\t\t\t\t\targuments: [store, receiver, object.ref],\n\t\t\t\t\ttypeArguments: [object.type],\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tfor (const [coinType, merged] of mergedCoins) {\n\t\t\tconst linksWithCoin = links.filter((link) => link.balances.has(coinType));\n\t\t\tif (linksWithCoin.length === 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst balances = linksWithCoin.map((link) => link.balances.get(coinType)!);\n\t\t\tconst splits = transactionBlock.splitCoins(merged, balances);\n\t\t\tfor (const [i, link] of linksWithCoin.entries()) {\n\t\t\t\tcontract.add(transactionBlock, {\n\t\t\t\t\targuments: [store, link.keypair.toSuiAddress(), splits[i]],\n\t\t\t\t\ttypeArguments: [`0x2::coin::Coin<${coinType}>`],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn transactionBlock;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA0C;AAE1C,0BAAoC;AAEpC,qBAA+B;AAK/B,0BAAiC;AACjC,mBAA6E;AAG7E,oBAA4C;AAhB5C;AAkCA,MAAM,+BAA+B;AAAA,EACpC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACV;AAEA,MAAM,oBAAgB,iCAAmB,yBAAY;AAW9C,MAAM,qBAAN,MAAwB;AAAA,EAY9B,YAAY;AAAA,IACX,OAAO,6BAA6B;AAAA,IACpC,OAAO,6BAA6B;AAAA,IACpC,UAAU,IAAI,8BAAe;AAAA,IAC7B,UAAU,6BAA6B;AAAA,IACvC,SAAS,IAAI,wBAAU,EAAE,SAAK,8BAAe,OAAO,EAAE,CAAC;AAAA,IACvD;AAAA,IACA;AAAA,IACA,WAAW,YAAY,YAAY,qCAAuB;AAAA,EAC3D,GAA6B;AAiF7B,uBAAM;AAqDN,uB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I,OAAO,EAAE,CAAC;AAAA,MACxC,KAAK,QAAQ,aAAa;AAAA,IAC3B;AAAA,EACD;AAEA,QAAM,SAAS,MAAM,mBAAK,SAAQ,uBAAuB;AAAA,IACxD,kBAAkB,MAAM,IAAI,MAAM,EAAE,QAAQ,mBAAK,SAAQ,CAAC;AAAA,EAC3D,CAAC;AAED,SACC,OAAO,OAAO,QAAQ,QAAQ,eAAe,IAC7C,OAAO,OAAO,QAAQ,QAAQ,WAAW,IACzC,OAAO,OAAO,QAAQ,QAAQ,aAAa;AAE7C;AAEM;AAAA,oBAAe,eAAC,UAAkB;AACvC,MAAI,mBAAK,cAAa,IAAI,QAAQ,GAAG;AACpC,WAAO,mBAAK,cAAa,IAAI,QAAQ;AAAA,EACtC;AAEA,QAAM,QAAQ,MAAM,mBAAK,SAAQ,SAAS;AAAA,IACzC;AAAA,IACA,OAAO,KAAK;AAAA,EACb,CAAC;AAED,qBAAK,cAAa,IAAI,UAAU,MAAM,IAAI;AAE1C,SAAO,MAAM;AACd;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client';\nimport type { CoinStruct } from '@mysten/sui.js/client';\nimport { decodeSuiPrivateKey } from '@mysten/sui.js/cryptography';\nimport type { Keypair, Signer } from '@mysten/sui.js/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';\nimport type {\n\tTransactionObjectArgument,\n\tTransactionObjectInput,\n} from '@mysten/sui.js/transactions';\nimport { TransactionBlock } from '@mysten/sui.js/transactions';\nimport { normalizeStructTag, normalizeSuiAddress, SUI_TYPE_ARG, toB64 } from '@mysten/sui.js/utils';\n\nimport type { ZkBagContractOptions } from './zk-bag.js';\nimport { MAINNET_CONTRACT_IDS, ZkBag } from './zk-bag.js';\n\ninterface ZkSendLinkRedirect {\n\turl: string;\n\tname?: string;\n}\n\nexport interface ZkSendLinkBuilderOptions {\n\thost?: string;\n\tpath?: string;\n\tkeypair?: Keypair;\n\tnetwork?: 'mainnet' | 'testnet';\n\tclient?: SuiClient;\n\tsender: string;\n\tredirect?: ZkSendLinkRedirect;\n\tcontract?: ZkBagContractOptions | null;\n}\n\nconst DEFAULT_ZK_SEND_LINK_OPTIONS = {\n\thost: 'https://zksend.com',\n\tpath: '/claim',\n\tnetwork: 'mainnet' as const,\n};\n\nconst SUI_COIN_TYPE = normalizeStructTag(SUI_TYPE_ARG);\n\nexport interface CreateZkSendLinkOptions {\n\ttransactionBlock?: TransactionBlock;\n\tcalculateGas?: (options: {\n\t\tbalances: Map<string, bigint>;\n\t\tobjects: TransactionObjectInput[];\n\t\tgasEstimateFromDryRun: bigint;\n\t}) => Promise<bigint> | bigint;\n}\n\nexport class ZkSendLinkBuilder {\n\tobjectIds = new Set<string>();\n\tobjectRefs: {\n\t\tref: TransactionObjectArgument;\n\t\ttype: string;\n\t}[] = [];\n\tbalances = new Map<string, bigint>();\n\tsender: string;\n\t#host: string;\n\t#path: string;\n\tkeypair: Keypair;\n\t#client: SuiClient;\n\t#redirect?: ZkSendLinkRedirect;\n\t#coinsByType = new Map<string, CoinStruct[]>();\n\t#contract?: ZkBag<ZkBagContractOptions>;\n\n\tconstructor({\n\t\thost = DEFAULT_ZK_SEND_LINK_OPTIONS.host,\n\t\tpath = DEFAULT_ZK_SEND_LINK_OPTIONS.path,\n\t\tkeypair = new Ed25519Keypair(),\n\t\tnetwork = DEFAULT_ZK_SEND_LINK_OPTIONS.network,\n\t\tclient = new SuiClient({ url: getFullnodeUrl(network) }),\n\t\tsender,\n\t\tredirect,\n\t\tcontract = network === 'mainnet' ? MAINNET_CONTRACT_IDS : undefined,\n\t}: ZkSendLinkBuilderOptions) {\n\t\tthis.#host = host;\n\t\tthis.#path = path;\n\t\tthis.#redirect = redirect;\n\t\tthis.keypair = keypair;\n\t\tthis.#client = client;\n\t\tthis.sender = normalizeSuiAddress(sender);\n\n\t\tif (contract) {\n\t\t\tthis.#contract = new ZkBag(contract.packageId, contract);\n\t\t}\n\t}\n\n\taddClaimableMist(amount: bigint) {\n\t\tthis.addClaimableBalance(SUI_COIN_TYPE, amount);\n\t}\n\n\taddClaimableBalance(coinType: string, amount: bigint) {\n\t\tconst normalizedType = normalizeStructTag(coinType);\n\t\tthis.balances.set(normalizedType, (this.balances.get(normalizedType) ?? 0n) + amount);\n\t}\n\n\taddClaimableObject(id: string) {\n\t\tthis.objectIds.add(id);\n\t}\n\n\taddClaimableObjectRef(ref: TransactionObjectArgument, type: string) {\n\t\tthis.objectRefs.push({ ref, type });\n\t}\n\n\tgetLink(): string {\n\t\tconst link = new URL(this.#host);\n\t\tlink.pathname = this.#path;\n\t\tlink.hash = `${this.#contract ? '$' : ''}${toB64(\n\t\t\tdecodeSuiPrivateKey(this.keypair.getSecretKey()).secretKey,\n\t\t)}`;\n\n\t\tif (this.#redirect) {\n\t\t\tlink.searchParams.set('redirect_url', this.#redirect.url);\n\t\t\tif (this.#redirect.name) {\n\t\t\t\tlink.searchParams.set('name', this.#redirect.name);\n\t\t\t}\n\t\t}\n\n\t\treturn link.toString();\n\t}\n\n\tasync create({\n\t\tsigner,\n\t\t...options\n\t}: CreateZkSendLinkOptions & {\n\t\tsigner: Signer;\n\t\twaitForTransactionBlock?: boolean;\n\t}) {\n\t\tconst txb = await this.createSendTransaction(options);\n\n\t\tconst result = await this.#client.signAndExecuteTransactionBlock({\n\t\t\ttransactionBlock: await txb.build({ client: this.#client }),\n\t\t\tsigner,\n\t\t});\n\n\t\tif (options.waitForTransactionBlock) {\n\t\t\tawait this.#client.waitForTransactionBlock({ digest: result.digest });\n\t\t}\n\n\t\treturn result;\n\t}\n\tasync createSendTransaction({\n\t\ttransactionBlock = new TransactionBlock(),\n\t\tcalculateGas,\n\t}: CreateZkSendLinkOptions = {}) {\n\t\tif (!this.#contract) {\n\t\t\treturn this.#createSendTransactionWithoutContract({ transactionBlock, calculateGas });\n\t\t}\n\n\t\ttransactionBlock.setSenderIfNotSet(this.sender);\n\n\t\treturn ZkSendLinkBuilder.createLinks({\n\t\t\ttransactionBlock,\n\t\t\tclient: this.#client,\n\t\t\tcontract: this.#contract.ids,\n\t\t\tlinks: [this],\n\t\t});\n\t}\n\n\tasync createSendToAddressTransaction({\n\t\ttransactionBlock = new TransactionBlock(),\n\t\taddress,\n\t}: CreateZkSendLinkOptions & {\n\t\taddress: string;\n\t}) {\n\t\tconst objectsToTransfer = (await this.#objectsToTransfer(transactionBlock)).map(\n\t\t\t(obj) => obj.ref,\n\t\t);\n\n\t\ttransactionBlock.setSenderIfNotSet(this.sender);\n\t\ttransactionBlock.transferObjects(objectsToTransfer, address);\n\n\t\treturn transactionBlock;\n\t}\n\n\tasync #objectsToTransfer(txb: TransactionBlock) {\n\t\tconst objectIDs = [...this.objectIds];\n\t\tconst refsWithType = this.objectRefs.concat(\n\t\t\t(objectIDs.length > 0\n\t\t\t\t? await this.#client.multiGetObjects({\n\t\t\t\t\t\tids: objectIDs,\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tshowType: true,\n\t\t\t\t\t\t},\n\t\t\t\t })\n\t\t\t\t: []\n\t\t\t).map((res, i) => {\n\t\t\t\tif (!res.data || res.error) {\n\t\t\t\t\tthrow new Error(`Failed to load object ${objectIDs[i]} (${res.error?.code})`);\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tref: txb.objectRef({\n\t\t\t\t\t\tversion: res.data.version,\n\t\t\t\t\t\tdigest: res.data.digest,\n\t\t\t\t\t\tobjectId: res.data.objectId,\n\t\t\t\t\t}),\n\t\t\t\t\ttype: res.data.type!,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\tfor (const [coinType, amount] of this.balances) {\n\t\t\tif (coinType === SUI_COIN_TYPE) {\n\t\t\t\tconst [sui] = txb.splitCoins(txb.gas, [amount]);\n\t\t\t\trefsWithType.push({\n\t\t\t\t\tref: sui,\n\t\t\t\t\ttype: `0x2::coin::Coin<${coinType}>`,\n\t\t\t\t} as never);\n\t\t\t} else {\n\t\t\t\tconst coins = (await this.#getCoinsByType(coinType)).map((coin) => coin.coinObjectId);\n\n\t\t\t\tif (coins.length > 1) {\n\t\t\t\t\ttxb.mergeCoins(coins[0], coins.slice(1));\n\t\t\t\t}\n\t\t\t\tconst [split] = txb.splitCoins(coins[0], [amount]);\n\t\t\t\trefsWithType.push({\n\t\t\t\t\tref: split,\n\t\t\t\t\ttype: `0x2::coin::Coin<${coinType}>`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn refsWithType;\n\t}\n\n\tasync #createSendTransactionWithoutContract({\n\t\ttransactionBlock: txb = new TransactionBlock(),\n\t\tcalculateGas,\n\t}: CreateZkSendLinkOptions = {}) {\n\t\tconst gasEstimateFromDryRun = await this.#estimateClaimGasFee();\n\t\tconst baseGasAmount = calculateGas\n\t\t\t? await calculateGas({\n\t\t\t\t\tbalances: this.balances,\n\t\t\t\t\tobjects: [...this.objectIds],\n\t\t\t\t\tgasEstimateFromDryRun,\n\t\t\t })\n\t\t\t: gasEstimateFromDryRun * 2n;\n\n\t\t// Ensure that rounded gas is not less than the calculated gas\n\t\tconst gasWithBuffer = baseGasAmount + 1013n;\n\t\t// Ensure that gas amount ends in 987\n\t\tconst roundedGasAmount = gasWithBuffer - (gasWithBuffer % 1000n) - 13n;\n\n\t\tconst address = this.keypair.toSuiAddress();\n\t\tconst objectsToTransfer = (await this.#objectsToTransfer(txb)).map((obj) => obj.ref);\n\t\tconst [gas] = txb.splitCoins(txb.gas, [roundedGasAmount]);\n\t\tobjectsToTransfer.push(gas);\n\n\t\ttxb.setSenderIfNotSet(this.sender);\n\t\ttxb.transferObjects(objectsToTransfer, address);\n\n\t\treturn txb;\n\t}\n\n\tasync #estimateClaimGasFee(): Promise<bigint> {\n\t\tconst txb = new TransactionBlock();\n\t\ttxb.setSender(this.sender);\n\t\ttxb.setGasPayment([]);\n\t\ttxb.transferObjects([txb.gas], this.keypair.toSuiAddress());\n\n\t\tconst idsToTransfer = [...this.objectIds];\n\n\t\tfor (const [coinType] of this.balances) {\n\t\t\tconst coins = await this.#getCoinsByType(coinType);\n\n\t\t\tif (!coins.length) {\n\t\t\t\tthrow new Error(`Sending account does not contain any coins of type ${coinType}`);\n\t\t\t}\n\n\t\t\tidsToTransfer.push(coins[0].coinObjectId);\n\t\t}\n\n\t\tif (idsToTransfer.length > 0) {\n\t\t\ttxb.transferObjects(\n\t\t\t\tidsToTransfer.map((id) => txb.object(id)),\n\t\t\t\tthis.keypair.toSuiAddress(),\n\t\t\t);\n\t\t}\n\n\t\tconst result = await this.#client.dryRunTransactionBlock({\n\t\t\ttransactionBlock: await txb.build({ client: this.#client }),\n\t\t});\n\n\t\treturn (\n\t\t\tBigInt(result.effects.gasUsed.computationCost) +\n\t\t\tBigInt(result.effects.gasUsed.storageCost) -\n\t\t\tBigInt(result.effects.gasUsed.storageRebate)\n\t\t);\n\t}\n\n\tasync #getCoinsByType(coinType: string) {\n\t\tif (this.#coinsByType.has(coinType)) {\n\t\t\treturn this.#coinsByType.get(coinType)!;\n\t\t}\n\n\t\tconst coins = await this.#client.getCoins({\n\t\t\tcoinType,\n\t\t\towner: this.sender,\n\t\t});\n\n\t\tthis.#coinsByType.set(coinType, coins.data);\n\n\t\treturn coins.data;\n\t}\n\n\tstatic async createLinks({\n\t\tlinks,\n\t\tnetwork = 'mainnet',\n\t\tclient = new SuiClient({ url: getFullnodeUrl(network) }),\n\t\ttransactionBlock = new TransactionBlock(),\n\t\tcontract: contractIds = MAINNET_CONTRACT_IDS,\n\t}: {\n\t\ttransactionBlock?: TransactionBlock;\n\t\tclient?: SuiClient;\n\t\tnetwork?: 'mainnet' | 'testnet';\n\t\tlinks: ZkSendLinkBuilder[];\n\t\tcontract?: ZkBagContractOptions;\n\t}) {\n\t\tconst contract = new ZkBag(contractIds.packageId, contractIds);\n\t\tconst store = transactionBlock.object(contract.ids.bagStoreId);\n\n\t\tconst coinsByType = new Map<string, CoinStruct[]>();\n\t\tconst allIds = links.flatMap((link) => [...link.objectIds]);\n\t\tconst sender = links[0].sender;\n\t\ttransactionBlock.setSenderIfNotSet(sender);\n\n\t\tawait Promise.all(\n\t\t\t[...new Set(links.flatMap((link) => [...link.balances.keys()]))].map(async (coinType) => {\n\t\t\t\tconst coins = await client.getCoins({\n\t\t\t\t\tcoinType,\n\t\t\t\t\towner: sender,\n\t\t\t\t});\n\n\t\t\t\tcoinsByType.set(\n\t\t\t\t\tcoinType,\n\t\t\t\t\tcoins.data.filter((coin) => !allIds.includes(coin.coinObjectId)),\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\n\t\tconst objectRefs = new Map<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tref: TransactionObjectArgument;\n\t\t\t\ttype: string;\n\t\t\t}\n\t\t>();\n\n\t\tconst pageSize = 50;\n\t\tlet offset = 0;\n\t\twhile (offset < allIds.length) {\n\t\t\tlet chunk = allIds.slice(offset, offset + pageSize);\n\t\t\toffset += pageSize;\n\n\t\t\tconst objects = await client.multiGetObjects({\n\t\t\t\tids: chunk,\n\t\t\t\toptions: {\n\t\t\t\t\tshowType: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const [i, res] of objects.entries()) {\n\t\t\t\tif (!res.data || res.error) {\n\t\t\t\t\tthrow new Error(`Failed to load object ${chunk[i]} (${res.error?.code})`);\n\t\t\t\t}\n\t\t\t\tobjectRefs.set(chunk[i], {\n\t\t\t\t\tref: transactionBlock.objectRef({\n\t\t\t\t\t\tversion: res.data.version,\n\t\t\t\t\t\tdigest: res.data.digest,\n\t\t\t\t\t\tobjectId: res.data.objectId,\n\t\t\t\t\t}),\n\t\t\t\t\ttype: res.data.type!,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst mergedCoins = new Map<string, TransactionObjectArgument>([\n\t\t\t[SUI_COIN_TYPE, transactionBlock.gas],\n\t\t]);\n\n\t\tfor (const [coinType, coins] of coinsByType) {\n\t\t\tif (coinType === SUI_COIN_TYPE) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [first, ...rest] = coins.map((coin) =>\n\t\t\t\ttransactionBlock.objectRef({\n\t\t\t\t\tobjectId: coin.coinObjectId,\n\t\t\t\t\tversion: coin.version,\n\t\t\t\t\tdigest: coin.digest,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (rest.length > 0) {\n\t\t\t\ttransactionBlock.mergeCoins(first, rest);\n\t\t\t}\n\t\t\tmergedCoins.set(coinType, transactionBlock.object(first));\n\t\t}\n\n\t\tfor (const link of links) {\n\t\t\tconst receiver = link.keypair.toSuiAddress();\n\t\t\tcontract.new(transactionBlock, { arguments: [store, receiver] });\n\n\t\t\tlink.objectRefs.forEach(({ ref, type }) => {\n\t\t\t\tcontract.add(transactionBlock, {\n\t\t\t\t\targuments: [store, receiver, ref],\n\t\t\t\t\ttypeArguments: [type],\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tlink.objectIds.forEach((id) => {\n\t\t\t\tconst object = objectRefs.get(id);\n\t\t\t\tif (!object) {\n\t\t\t\t\tthrow new Error(`Object ${id} not found`);\n\t\t\t\t}\n\t\t\t\tcontract.add(transactionBlock, {\n\t\t\t\t\targuments: [store, receiver, object.ref],\n\t\t\t\t\ttypeArguments: [object.type],\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tfor (const [coinType, merged] of mergedCoins) {\n\t\t\tconst linksWithCoin = links.filter((link) => link.balances.has(coinType));\n\t\t\tif (linksWithCoin.length === 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst balances = linksWithCoin.map((link) => link.balances.get(coinType)!);\n\t\t\tconst splits = transactionBlock.splitCoins(merged, balances);\n\t\t\tfor (const [i, link] of linksWithCoin.entries()) {\n\t\t\t\tcontract.add(transactionBlock, {\n\t\t\t\t\targuments: [store, link.keypair.toSuiAddress(), splits[i]],\n\t\t\t\t\ttypeArguments: [`0x2::coin::Coin<${coinType}>`],\n\t\t\t\t});\n\t\t\t}\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AAM,CAAC,EAAE,YAAY;AAAA,EACzC;AAEA,MAAI,cAAc,SAAS,GAAG;AAC7B,QAAI;AAAA,MACH,cAAc,IAAI,CAAC,OAAO,IAAI,OAAO,EAAE,CAAC;AAAA,MACxC,KAAK,QAAQ,aAAa;AAAA,IAC3B;AAAA,EACD;AAEA,QAAM,SAAS,MAAM,mBAAK,SAAQ,uBAAuB;AAAA,IACxD,kBAAkB,MAAM,IAAI,MAAM,EAAE,QAAQ,mBAAK,SAAQ,CAAC;AAAA,EAC3D,CAAC;AAED,SACC,OAAO,OAAO,QAAQ,QAAQ,eAAe,IAC7C,OAAO,OAAO,QAAQ,QAAQ,WAAW,IACzC,OAAO,OAAO,QAAQ,QAAQ,aAAa;AAE7C;AAEM;AAAA,oBAAe,eAAC,UAAkB;AACvC,MAAI,mBAAK,cAAa,IAAI,QAAQ,GAAG;AACpC,WAAO,mBAAK,cAAa,IAAI,QAAQ;AAAA,EACtC;AAEA,QAAM,QAAQ,MAAM,mBAAK,SAAQ,SAAS;AAAA,IACzC;AAAA,IACA,OAAO,KAAK;AAAA,EACb,CAAC;AAED,qBAAK,cAAa,IAAI,UAAU,MAAM,IAAI;AAE1C,SAAO,MAAM;AACd;",
6
6
  "names": []
7
7
  }
@@ -72,17 +72,28 @@ function getAssetsFromTxnBlock({
72
72
  }
73
73
  });
74
74
  transactionBlock.objectChanges?.forEach((change) => {
75
+ if (!isObjectOwner(change, normalizedAddress, isSent)) {
76
+ return;
77
+ }
75
78
  if ("objectType" in change) {
76
79
  const type = (0, import_utils.parseStructTag)(change.objectType);
77
80
  if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
78
81
  if (change.type === "created" || change.type === "transferred" || change.type === "mutated") {
79
- coins.push(change);
82
+ coins.push({
83
+ ...change,
84
+ type: change.objectType
85
+ });
80
86
  }
81
87
  return;
82
88
  }
83
89
  }
84
90
  if (isObjectOwner(change, normalizedAddress, isSent) && (change.type === "created" || change.type === "transferred" || change.type === "mutated")) {
85
- nfts.push(change);
91
+ nfts.push({
92
+ objectId: change.objectId,
93
+ type: change.objectType,
94
+ version: change.version,
95
+ digest: change.digest
96
+ });
86
97
  }
87
98
  });
88
99
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/links/utils.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tObjectOwner,\n\tSuiObjectChange,\n\tSuiTransactionBlockResponse,\n} from '@mysten/sui.js/client';\nimport type { TransactionBlock } from '@mysten/sui.js/transactions';\nimport { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui.js/utils';\n\n// eslint-disable-next-line import/no-cycle\n\nexport interface LinkAssets {\n\tbalances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[];\n\n\tnfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n\n\tcoins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n}\n\nexport function isClaimTransaction(\n\ttxb: TransactionBlock,\n\toptions: {\n\t\tpackageId: string;\n\t},\n) {\n\tlet transfers = 0;\n\n\tfor (const tx of txb.blockData.transactions) {\n\t\tswitch (tx.kind) {\n\t\t\tcase 'TransferObjects':\n\t\t\t\t// Ensure that we are only transferring results of a claim\n\t\t\t\tif (!tx.objects.every((o) => o.kind === 'Result' || o.kind === 'NestedResult')) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttransfers++;\n\t\t\t\tbreak;\n\t\t\tcase 'MoveCall':\n\t\t\t\tconst [packageId, module, fn] = tx.target.split('::');\n\n\t\t\t\tif (packageId !== options.packageId) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (module !== 'zk_bag') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (fn !== 'init_claim' && fn !== 'reclaim' && fn !== 'claim' && fn !== 'finalize') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn transfers === 1;\n}\n\nexport function getAssetsFromTxnBlock({\n\ttransactionBlock,\n\taddress,\n\tisSent,\n}: {\n\ttransactionBlock: SuiTransactionBlockResponse;\n\taddress: string;\n\tisSent: boolean;\n}): LinkAssets {\n\tconst normalizedAddress = normalizeSuiAddress(address);\n\tconst balances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[] = [];\n\n\tconst nfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\tconst coins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\ttransactionBlock.balanceChanges?.forEach((change) => {\n\t\tconst validAmountChange = isSent ? BigInt(change.amount) < 0n : BigInt(change.amount) > 0n;\n\t\tif (validAmountChange && isOwner(change.owner, normalizedAddress)) {\n\t\t\tbalances.push({\n\t\t\t\tcoinType: normalizeStructTag(change.coinType),\n\t\t\t\tamount: BigInt(change.amount),\n\t\t\t});\n\t\t}\n\t});\n\n\ttransactionBlock.objectChanges?.forEach((change) => {\n\t\tif ('objectType' in change) {\n\t\t\tconst type = parseStructTag(change.objectType);\n\n\t\t\tif (\n\t\t\t\ttype.address === normalizeSuiAddress('0x2') &&\n\t\t\t\ttype.module === 'coin' &&\n\t\t\t\ttype.name === 'Coin'\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\tchange.type === 'created' ||\n\t\t\t\t\tchange.type === 'transferred' ||\n\t\t\t\t\tchange.type === 'mutated'\n\t\t\t\t) {\n\t\t\t\t\tcoins.push(change);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tisObjectOwner(change, normalizedAddress, isSent) &&\n\t\t\t(change.type === 'created' || change.type === 'transferred' || change.type === 'mutated')\n\t\t) {\n\t\t\tnfts.push(change);\n\t\t}\n\t});\n\n\treturn {\n\t\tbalances,\n\t\tnfts,\n\t\tcoins,\n\t};\n}\n\nfunction getObjectOwnerFromObjectChange(objectChange: SuiObjectChange, isSent: boolean) {\n\tif (isSent) {\n\t\treturn 'owner' in objectChange ? objectChange.owner : null;\n\t}\n\n\treturn 'recipient' in objectChange ? objectChange.recipient : null;\n}\n\nfunction isObjectOwner(objectChange: SuiObjectChange, address: string, isSent: boolean) {\n\tconst owner = getObjectOwnerFromObjectChange(objectChange, isSent);\n\n\tif (isSent) {\n\t\treturn owner && typeof owner === 'object' && 'AddressOwner' in owner;\n\t}\n\n\treturn ownedAfterChange(objectChange, address);\n}\n\nexport function ownedAfterChange(\n\tobjectChange: SuiObjectChange,\n\taddress: string,\n): objectChange is Extract<SuiObjectChange, { type: 'created' | 'transferred' | 'mutated' }> {\n\tif (objectChange.type === 'transferred' && isOwner(objectChange.recipient, address)) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\t(objectChange.type === 'created' || objectChange.type === 'mutated') &&\n\t\tisOwner(objectChange.owner, address)\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nexport function isOwner(owner: ObjectOwner, address: string): owner is { AddressOwner: string } {\n\treturn (\n\t\towner &&\n\t\ttypeof owner === 'object' &&\n\t\t'AddressOwner' in owner &&\n\t\tnormalizeSuiAddress(owner.AddressOwner) === address\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAAwE;AAyBjE,SAAS,mBACf,KACA,SAGC;AACD,MAAI,YAAY;AAEhB,aAAW,MAAM,IAAI,UAAU,cAAc;AAC5C,YAAQ,GAAG,MAAM;AAAA,MAChB,KAAK;AAEJ,YAAI,CAAC,GAAG,QAAQ,MAAM,CAAC,MAAM,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EA,QACC,cAAc,QAAQ,mBAAmB,MAAM,MAC9C,OAAO,SAAS,aAAa,OAAO,SAAS,iBAAiB,OAAO,SAAS,YAC9E;AACD,WAAK,KAAK,MAAM;AAAA,IACjB;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,+BAA+B,cAA+B,QAAiB;AACvF,MAAI,QAAQ;AACX,WAAO,WAAW,eAAe,aAAa,QAAQ;AAAA,EACvD;AAEA,SAAO,eAAe,eAAe,aAAa,YAAY;AAC/D;AAEA,SAAS,cAAc,cAA+B,SAAiB,QAAiB;AACvF,QAAM,QAAQ,+BAA+B,cAAc,MAAM;AAEjE,MAAI,QAAQ;AACX,WAAO,SAAS,OAAO,UAAU,YAAY,kBAAkB;AAAA,EAChE;AAEA,SAAO,iBAAiB,cAAc,OAAO;AAC9C;AAEO,SAAS,iBACf,cACA,SAC4F;AAC5F,MAAI,aAAa,SAAS,iBAAiB,QAAQ,aAAa,WAAW,OAAO,GAAG;AACpF,WAAO;AAAA,EACR;AAEA,OACE,aAAa,SAAS,aAAa,aAAa,SAAS,cAC1D,QAAQ,aAAa,OAAO,OAAO,GAClC;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEO,SAAS,QAAQ,OAAoB,SAAoD;AAC/F,SACC,SACA,OAAO,UAAU,YACjB,kBAAkB,aAClB,kCAAoB,MAAM,YAAY,MAAM;AAE9C;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tObjectOwner,\n\tSuiObjectChange,\n\tSuiTransactionBlockResponse,\n} from '@mysten/sui.js/client';\nimport type { TransactionBlock } from '@mysten/sui.js/transactions';\nimport { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui.js/utils';\n\n// eslint-disable-next-line import/no-cycle\n\nexport interface LinkAssets {\n\tbalances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[];\n\n\tnfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n\n\tcoins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[];\n}\n\nexport function isClaimTransaction(\n\ttxb: TransactionBlock,\n\toptions: {\n\t\tpackageId: string;\n\t},\n) {\n\tlet transfers = 0;\n\n\tfor (const tx of txb.blockData.transactions) {\n\t\tswitch (tx.kind) {\n\t\t\tcase 'TransferObjects':\n\t\t\t\t// Ensure that we are only transferring results of a claim\n\t\t\t\tif (!tx.objects.every((o) => o.kind === 'Result' || o.kind === 'NestedResult')) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttransfers++;\n\t\t\t\tbreak;\n\t\t\tcase 'MoveCall':\n\t\t\t\tconst [packageId, module, fn] = tx.target.split('::');\n\n\t\t\t\tif (packageId !== options.packageId) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (module !== 'zk_bag') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (fn !== 'init_claim' && fn !== 'reclaim' && fn !== 'claim' && fn !== 'finalize') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn transfers === 1;\n}\n\nexport function getAssetsFromTxnBlock({\n\ttransactionBlock,\n\taddress,\n\tisSent,\n}: {\n\ttransactionBlock: SuiTransactionBlockResponse;\n\taddress: string;\n\tisSent: boolean;\n}): LinkAssets {\n\tconst normalizedAddress = normalizeSuiAddress(address);\n\tconst balances: {\n\t\tcoinType: string;\n\t\tamount: bigint;\n\t}[] = [];\n\n\tconst nfts: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\tconst coins: {\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t}[] = [];\n\n\ttransactionBlock.balanceChanges?.forEach((change) => {\n\t\tconst validAmountChange = isSent ? BigInt(change.amount) < 0n : BigInt(change.amount) > 0n;\n\t\tif (validAmountChange && isOwner(change.owner, normalizedAddress)) {\n\t\t\tbalances.push({\n\t\t\t\tcoinType: normalizeStructTag(change.coinType),\n\t\t\t\tamount: BigInt(change.amount),\n\t\t\t});\n\t\t}\n\t});\n\n\ttransactionBlock.objectChanges?.forEach((change) => {\n\t\tif (!isObjectOwner(change, normalizedAddress, isSent)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ('objectType' in change) {\n\t\t\tconst type = parseStructTag(change.objectType);\n\n\t\t\tif (\n\t\t\t\ttype.address === normalizeSuiAddress('0x2') &&\n\t\t\t\ttype.module === 'coin' &&\n\t\t\t\ttype.name === 'Coin'\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\tchange.type === 'created' ||\n\t\t\t\t\tchange.type === 'transferred' ||\n\t\t\t\t\tchange.type === 'mutated'\n\t\t\t\t) {\n\t\t\t\t\tcoins.push({\n\t\t\t\t\t\t...change,\n\t\t\t\t\t\ttype: change.objectType,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tisObjectOwner(change, normalizedAddress, isSent) &&\n\t\t\t(change.type === 'created' || change.type === 'transferred' || change.type === 'mutated')\n\t\t) {\n\t\t\tnfts.push({\n\t\t\t\tobjectId: change.objectId,\n\t\t\t\ttype: change.objectType,\n\t\t\t\tversion: change.version,\n\t\t\t\tdigest: change.digest,\n\t\t\t});\n\t\t}\n\t});\n\n\treturn {\n\t\tbalances,\n\t\tnfts,\n\t\tcoins,\n\t};\n}\n\nfunction getObjectOwnerFromObjectChange(objectChange: SuiObjectChange, isSent: boolean) {\n\tif (isSent) {\n\t\treturn 'owner' in objectChange ? objectChange.owner : null;\n\t}\n\n\treturn 'recipient' in objectChange ? objectChange.recipient : null;\n}\n\nfunction isObjectOwner(objectChange: SuiObjectChange, address: string, isSent: boolean) {\n\tconst owner = getObjectOwnerFromObjectChange(objectChange, isSent);\n\n\tif (isSent) {\n\t\treturn owner && typeof owner === 'object' && 'AddressOwner' in owner;\n\t}\n\n\treturn ownedAfterChange(objectChange, address);\n}\n\nexport function ownedAfterChange(\n\tobjectChange: SuiObjectChange,\n\taddress: string,\n): objectChange is Extract<SuiObjectChange, { type: 'created' | 'transferred' | 'mutated' }> {\n\tif (objectChange.type === 'transferred' && isOwner(objectChange.recipient, address)) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\t(objectChange.type === 'created' || objectChange.type === 'mutated') &&\n\t\tisOwner(objectChange.owner, address)\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nexport function isOwner(owner: ObjectOwner, address: string): owner is { AddressOwner: string } {\n\treturn (\n\t\towner &&\n\t\ttypeof owner === 'object' &&\n\t\t'AddressOwner' in owner &&\n\t\tnormalizeSuiAddress(owner.AddressOwner) === address\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAAwE;AAyBjE,SAAS,mBACf,KACA,SAGC;AACD,MAAI,YAAY;AAEhB,aAAW,MAAM,IAAI,UAAU,cAAc;AAC5C,YAAQ,GAAG,MAAM;AAAA,MAChB,KAAK;AAEJ,YAAI,CAAC,GAAG,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,SAAS,cAAc,GAAG;AAC/E,iBAAO;AAAA,QACR;AACA;AACA;AAAA,MACD,KAAK;AACJ,cAAM,CAAC,WAAWA,SAAQ,EAAE,IAAI,GAAG,OAAO,MAAM,IAAI;AAEpD,YAAI,cAAc,QAAQ,WAAW;AACpC,iBAAO;AAAA,QACR;AAEA,YAAIA,YAAW,UAAU;AACxB,iBAAO;AAAA,QACR;AAEA,YAAI,OAAO,gBAAgB,OAAO,aAAa,OAAO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QAChB,QAAQ,OAAO;AAAA,MAChB,CAAC;AAAA,IACF;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,+BAA+B,cAA+B,QAAiB;AACvF,MAAI,QAAQ;AACX,WAAO,WAAW,eAAe,aAAa,QAAQ;AAAA,EACvD;AAEA,SAAO,eAAe,eAAe,aAAa,YAAY;AAC/D;AAEA,SAAS,cAAc,cAA+B,SAAiB,QAAiB;AACvF,QAAM,QAAQ,+BAA+B,cAAc,MAAM;AAEjE,MAAI,QAAQ;AACX,WAAO,SAAS,OAAO,UAAU,YAAY,kBAAkB;AAAA,EAChE;AAEA,SAAO,iBAAiB,cAAc,OAAO;AAC9C;AAEO,SAAS,iBACf,cACA,SAC4F;AAC5F,MAAI,aAAa,SAAS,iBAAiB,QAAQ,aAAa,WAAW,OAAO,GAAG;AACpF,WAAO;AAAA,EACR;AAEA,OACE,aAAa,SAAS,aAAa,aAAa,SAAS,cAC1D,QAAQ,aAAa,OAAO,OAAO,GAClC;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEO,SAAS,QAAQ,OAAoB,SAAoD;AAC/F,SACC,SACA,OAAO,UAAU,YACjB,kBAAkB,aAClB,kCAAoB,MAAM,YAAY,MAAM;AAE9C;",
6
6
  "names": ["module"]
7
7
  }
@@ -9,8 +9,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
9
9
  address: import("valibot").StringSchema<string>;
10
10
  }, undefined, {
11
11
  address: string;
12
- data: string;
13
12
  type: "sign-transaction-block";
13
+ data: string;
14
14
  }>, import("valibot").ObjectSchema<{
15
15
  type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
16
16
  bytes: import("valibot").StringSchema<string>;
@@ -23,8 +23,8 @@ export declare const ZkSendRequestData: import("valibot").VariantSchema<"type",
23
23
  type: "connect";
24
24
  } | {
25
25
  address: string;
26
- data: string;
27
26
  type: "sign-transaction-block";
27
+ data: string;
28
28
  } | {
29
29
  address: string;
30
30
  type: "sign-personal-message";
@@ -45,8 +45,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
45
45
  address: import("valibot").StringSchema<string>;
46
46
  }, undefined, {
47
47
  address: string;
48
- data: string;
49
48
  type: "sign-transaction-block";
49
+ data: string;
50
50
  }>, import("valibot").ObjectSchema<{
51
51
  type: import("valibot").LiteralSchema<"sign-personal-message", "sign-personal-message">;
52
52
  bytes: import("valibot").StringSchema<string>;
@@ -59,8 +59,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
59
59
  type: "connect";
60
60
  } | {
61
61
  address: string;
62
- data: string;
63
62
  type: "sign-transaction-block";
63
+ data: string;
64
64
  } | {
65
65
  address: string;
66
66
  type: "sign-personal-message";
@@ -73,8 +73,8 @@ export declare const ZkSendRequest: import("valibot").ObjectSchema<{
73
73
  type: "connect";
74
74
  } | {
75
75
  address: string;
76
- data: string;
77
76
  type: "sign-transaction-block";
77
+ data: string;
78
78
  } | {
79
79
  address: string;
80
80
  type: "sign-personal-message";
@@ -159,6 +159,7 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
159
159
  bytes: string;
160
160
  }>;
161
161
  }, undefined, {
162
+ type: "resolve";
162
163
  data: {
163
164
  address: string;
164
165
  type: "connect";
@@ -171,10 +172,10 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
171
172
  type: "sign-personal-message";
172
173
  bytes: string;
173
174
  };
174
- type: "resolve";
175
175
  }>], {
176
176
  type: "reject";
177
177
  } | {
178
+ type: "resolve";
178
179
  data: {
179
180
  address: string;
180
181
  type: "connect";
@@ -187,7 +188,6 @@ export declare const ZkSendResponsePayload: import("valibot").VariantSchema<"typ
187
188
  type: "sign-personal-message";
188
189
  bytes: string;
189
190
  };
190
- type: "resolve";
191
191
  }>;
192
192
  export type ZkSendResponsePayload = Output<typeof ZkSendResponsePayload>;
193
193
  export declare const ZkSendResponse: import("valibot").ObjectSchema<{
@@ -234,6 +234,7 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
234
234
  bytes: string;
235
235
  }>;
236
236
  }, undefined, {
237
+ type: "resolve";
237
238
  data: {
238
239
  address: string;
239
240
  type: "connect";
@@ -246,10 +247,10 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
246
247
  type: "sign-personal-message";
247
248
  bytes: string;
248
249
  };
249
- type: "resolve";
250
250
  }>], {
251
251
  type: "reject";
252
252
  } | {
253
+ type: "resolve";
253
254
  data: {
254
255
  address: string;
255
256
  type: "connect";
@@ -262,13 +263,13 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
262
263
  type: "sign-personal-message";
263
264
  bytes: string;
264
265
  };
265
- type: "resolve";
266
266
  }>;
267
267
  }, undefined, {
268
268
  id: string;
269
269
  payload: {
270
270
  type: "reject";
271
271
  } | {
272
+ type: "resolve";
272
273
  data: {
273
274
  address: string;
274
275
  type: "connect";
@@ -281,7 +282,6 @@ export declare const ZkSendResponse: import("valibot").ObjectSchema<{
281
282
  type: "sign-personal-message";
282
283
  bytes: string;
283
284
  };
284
- type: "resolve";
285
285
  };
286
286
  source: "zksend-channel";
287
287
  }>;
@@ -24,8 +24,8 @@ export declare class ZkSendHost {
24
24
  type: "connect";
25
25
  } | {
26
26
  address: string;
27
- data: string;
28
27
  type: "sign-transaction-block";
28
+ data: string;
29
29
  } | {
30
30
  address: string;
31
31
  type: "sign-personal-message";
@@ -1,6 +1,6 @@
1
1
  import { SuiClient } from '@mysten/sui.js/client';
2
2
  import type { Keypair, Signer } from '@mysten/sui.js/cryptography';
3
- import type { TransactionObjectInput } from '@mysten/sui.js/transactions';
3
+ import type { TransactionObjectArgument, TransactionObjectInput } from '@mysten/sui.js/transactions';
4
4
  import { TransactionBlock } from '@mysten/sui.js/transactions';
5
5
  import type { ZkBagContractOptions } from './zk-bag.js';
6
6
  interface ZkSendLinkRedirect {
@@ -28,6 +28,10 @@ export interface CreateZkSendLinkOptions {
28
28
  export declare class ZkSendLinkBuilder {
29
29
  #private;
30
30
  objectIds: Set<string>;
31
+ objectRefs: {
32
+ ref: TransactionObjectArgument;
33
+ type: string;
34
+ }[];
31
35
  balances: Map<string, bigint>;
32
36
  sender: string;
33
37
  keypair: Keypair;
@@ -35,12 +39,16 @@ export declare class ZkSendLinkBuilder {
35
39
  addClaimableMist(amount: bigint): void;
36
40
  addClaimableBalance(coinType: string, amount: bigint): void;
37
41
  addClaimableObject(id: string): void;
42
+ addClaimableObjectRef(ref: TransactionObjectArgument, type: string): void;
38
43
  getLink(): string;
39
44
  create({ signer, ...options }: CreateZkSendLinkOptions & {
40
45
  signer: Signer;
41
46
  waitForTransactionBlock?: boolean;
42
47
  }): Promise<import("@mysten/sui.js/client").SuiTransactionBlockResponse>;
43
48
  createSendTransaction({ transactionBlock, calculateGas, }?: CreateZkSendLinkOptions): Promise<TransactionBlock>;
49
+ createSendToAddressTransaction({ transactionBlock, address, }: CreateZkSendLinkOptions & {
50
+ address: string;
51
+ }): Promise<TransactionBlock>;
44
52
  static createLinks({ links, network, client, transactionBlock, contract: contractIds, }: {
45
53
  transactionBlock?: TransactionBlock;
46
54
  client?: SuiClient;