@mysten/zksend 1.1.1 → 1.2.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,29 @@
1
1
  # @mysten/zksend
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bbf63cb: Updated dependencies
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [bbf63cb]
12
+ - @mysten/utils@0.4.0
13
+ - @mysten/wallet-standard@0.21.0
14
+ - @mysten/window-wallet-core@0.2.0
15
+
16
+ ## 1.1.2
17
+
18
+ ### Patch Changes
19
+
20
+ - f7de3e5: Restore docs in published tarballs.
21
+ - Updated dependencies [f7de3e5]
22
+ - @mysten/sui@2.16.2
23
+ - @mysten/utils@0.3.3
24
+ - @mysten/wallet-standard@0.20.3
25
+ - @mysten/window-wallet-core@0.1.6
26
+
3
27
  ## 1.1.1
4
28
 
5
29
  ### Patch Changes
@@ -0,0 +1,70 @@
1
+ # Composable Claims
2
+
3
+ > Claim a zkSend link and use the assets in the same transaction
4
+
5
+ By default, `link.claimAssets(address)` builds a claim transaction that transfers every asset to the
6
+ recipient and submits it via a Mysten-hosted sponsor. If you want to _use_ a claimed object in the
7
+ same transaction — for example, inserting a claimed NFT into another on-chain object, staking a
8
+ claimed coin, or depositing into a vault — use `link.claimFlow()` to compose the claim into your own
9
+ transaction.
10
+
11
+ ## How it works
12
+
13
+ `link.claimFlow()` returns three transaction thunks:
14
+
15
+ - **`init`** — adds the `init_claim` (or `reclaim`) move call that creates the claim proof.
16
+ - **`assets`** — an array of claimable assets. Each `asset.argument` is a lazy
17
+ `TransactionObjectArgument` that emits the backing `claim<T>` move call the first time it's used.
18
+ - **`finalize`** — consumes the claim proof. Must be added after every asset is claimed.
19
+
20
+ ```ts
21
+
22
+ const tx = new Transaction();
23
+ tx.setSender(claimLink.keypair!.toSuiAddress());
24
+
25
+ const { init, assets, finalize } = claimLink.claimFlow();
26
+
27
+ tx.add(init);
28
+
29
+ for (const asset of assets) {
30
+ if (asset.type === `${PACKAGE_ID}::record::Record`) {
31
+ // Insert the claimed record directly into the recipient's player object
32
+ tx.moveCall({
33
+ target: `${PACKAGE_ID}::player::add_record`,
34
+ arguments: [tx.object(playerId), asset.argument],
35
+ });
36
+ } else {
37
+ tx.transferObjects([asset.argument], recipient);
38
+ }
39
+ }
40
+
41
+ tx.add(finalize);
42
+ ```
43
+
44
+ Every asset in the returned list must be claimed somewhere in the transaction — assets that are
45
+ never used won't create a `claim<T>` command and the transaction will fail. If you only want the
46
+ default claim-and-transfer behavior, use `link.createClaimTransaction(address)` instead.
47
+
48
+ ## Sponsorship
49
+
50
+ `link.claimAssets(address)` uses a sponsorship flow so the claimer does not need gas to claim the
51
+ assets, but it only accepts the standard `init_claim` → `claim<T>` → transfer → `finalize` shape.
52
+ Transactions built with `claimFlow()` may include extra move calls, so the default sponsor may
53
+ reject them.
54
+
55
+ Apps using `claimFlow()` are responsible for their own gas and sponsorship. The ephemeral link
56
+ keypair is still the transaction sender (it authorizes the claim), so the typical pattern is dual
57
+ signing: the link keypair signs as sender and your app's sponsor signs for gas.
58
+
59
+ ```ts
60
+ tx.setGasOwner(sponsorAddress);
61
+ const txBytes = await tx.build({ client });
62
+
63
+ const linkSig = await claimLink.keypair!.signTransaction(txBytes);
64
+ const sponsorSig = await sponsor.signTransaction(txBytes);
65
+
66
+ const result = await client.core.executeTransaction({
67
+ transaction: txBytes,
68
+ signatures: [linkSig.signature, sponsorSig.signature],
69
+ });
70
+ ```
package/docs/index.md ADDED
@@ -0,0 +1,27 @@
1
+ # zkSend SDK
2
+
3
+ > Send Sui assets through shareable claim links using the zkSend SDK.
4
+
5
+ The zkSend SDK provides tools for interacting with the zkSend primitive. It provides functionality
6
+ to create your own zkSend Claim Links, with support for any publicly transferrable asset.
7
+
8
+ ## Installation
9
+
10
+ ```npm
11
+ npm i @mysten/zksend @mysten/sui
12
+ ```
13
+
14
+ ## Setup
15
+
16
+ To use the zkSend SDK, create a Sui client and extend it with the zkSend extension:
17
+
18
+ ```ts
19
+
20
+ const client = new SuiGrpcClient({
21
+ network: 'mainnet',
22
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
23
+ }).$extend(zksend());
24
+ ```
25
+
26
+ The zkSend SDK supports Mainnet and Testnet networks. The extension automatically configures the
27
+ correct contract IDs based on the client's network.
@@ -0,0 +1,193 @@
1
+ # Creating zkSend Links
2
+
3
+ > Create and customize zkSend claim links for sending Sui assets.
4
+
5
+ > **Warning:** Products and services that incorporate zkSend links might be subject to financial regulations,
6
+ > including obtaining money transmitter licenses in jurisdictions where you provide your services.
7
+ > It is the developer's responsibility to ensure compliance with all relevant laws and obtain any
8
+ > necessary licenses. The information provided by Mysten Labs is not legal advice, and developers
9
+ > should consult with a qualified legal professional to address their specific circumstances.
10
+
11
+ ## Limitations
12
+
13
+ - zkSend only supports Mainnet and Testnet at this time.
14
+ - Objects within links must be publicly transferrable.
15
+
16
+ ## Create a link
17
+
18
+ You can start creating your own zkSend link using the `linkBuilder` method on the zkSend client
19
+ extension:
20
+
21
+ ```ts
22
+
23
+ const client = new SuiGrpcClient({
24
+ network: 'mainnet',
25
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
26
+ }).$extend(zksend());
27
+
28
+ const link = client.zksend.linkBuilder({
29
+ sender: '0x...',
30
+ });
31
+ ```
32
+
33
+ #### Adding SUI to the link
34
+
35
+ You can add SUI to the link by calling `link.addClaimableMist()`. This method takes the following
36
+ params:
37
+
38
+ - **`amount`** (required) - The amount of MIST (the base unit of SUI) to add to the link.
39
+
40
+ #### Adding non-SUI coins to the link
41
+
42
+ You can add non-SUI coins to the link by calling `link.addClaimableBalance()`. This method takes the
43
+ following params:
44
+
45
+ - **`coinType`** (required) - The coin type of the coin to add to the link (for example,
46
+ `0x2::sui::SUI`).
47
+ - **`amount`** (required) - The amount of the coin to add to the link. Represented in the base unit
48
+ of the coin.
49
+
50
+ The SDK will automatically perform the necessary coin management logic to transfer the defined
51
+ amount, such as merging and splitting coin objects.
52
+
53
+ #### Adding objects to the link
54
+
55
+ You can add a publicly-transferrable object to the link by calling `link.addClaimableObject()`. This
56
+ method takes the following params:
57
+
58
+ - **`id`** (required) - The ID of the object. This must be owned by the `sender` you configured when
59
+ creating the link.
60
+
61
+ #### Adding objects created in the same transaction
62
+
63
+ You can create objects to add to links in the same transaction the link is created in by using
64
+ `link.addClaimableObjectRef()`
65
+
66
+ - **`ref`** (required) - The reference to the object you want to add to the link.
67
+ - **`type`** (required) - The move type of the object you are adding
68
+
69
+ ```ts
70
+
71
+ const tx = new Transaction();
72
+
73
+ const link = client.zksend.linkBuilder({
74
+ sender: '0x...',
75
+ });
76
+
77
+ const newObject = tx.moveCall({
78
+ target: `${PACKAGE_ID}::your_module::mint`,
79
+ });
80
+
81
+ link.addClaimableObjectRef({
82
+ ref: newObject,
83
+ type: `${PACKAGE_ID}::your_module::YourType`,
84
+ });
85
+
86
+ // Adds the link creation transactions to the transaction
87
+ link.createSendTransaction({
88
+ transaction: tx,
89
+ });
90
+ ```
91
+
92
+ #### Getting the link URL
93
+
94
+ At any time, you can get the URL for the link by calling `link.getLink()`.
95
+
96
+ ## Submitting the link transaction
97
+
98
+ Once you have built your zkSend link, you need to execute a transaction to transfer assets and make
99
+ the link claimable.
100
+
101
+ You can call the `link.createSendTransaction()` method, which returns a `Transaction` object that
102
+ you can sign and submit to the blockchain.
103
+
104
+ ```ts
105
+ const tx = await link.createSendTransaction();
106
+
107
+ const { bytes, signature } = tx.sign({ client, signer: keypair });
108
+
109
+ const result = await client.executeTransactionBlock({
110
+ transactionBlock: bytes,
111
+ signature,
112
+ });
113
+ ```
114
+
115
+ If you have a keypair you would like to send the transaction with, you can use the `create` method
116
+ as shorthand for creating the send transaction, signing it, and submitting it to the blockchain.
117
+
118
+ ```ts
119
+ await link.create({
120
+ signer: yourKeypair,
121
+ // Wait until the new link is ready to be indexed so it is claimable
122
+ waitForTransaction: true,
123
+ });
124
+ ```
125
+
126
+ ## Claiming a link
127
+
128
+ To claim a link through the SDK you can use the `loadLinkFromUrl` method:
129
+
130
+ ```ts
131
+ // Load a link instance from a URL
132
+ const link = await client.zksend.loadLinkFromUrl('https://zksend.com/claim#$abc...');
133
+
134
+ // list what claimable assets the link has
135
+ const { nfts, balances } = link.assets;
136
+
137
+ // claim all the assets from the link
138
+ await link.claimAssets(addressOfClaimer);
139
+ ```
140
+
141
+ ## Regenerating links
142
+
143
+ If you lose a link you've created, you can re-generate the link (this can only done from the address
144
+ that originally created the link):
145
+
146
+ ```ts
147
+ // url will be the new link url
148
+ const { url, transaction } = await link.createRegenerateTransaction(addressOfLinkCreator);
149
+
150
+ // Execute the transaction to regenerate the link
151
+ const result = await client.signAndExecuteTransaction({
152
+ transaction,
153
+ signer: keypair,
154
+ });
155
+
156
+ // Check transaction status
157
+ if (result.$kind === 'FailedTransaction') {
158
+ throw new Error(`Link regeneration failed: ${result.FailedTransaction.status.error?.message}`);
159
+ }
160
+ ```
161
+
162
+ ## Bulk link creation
163
+
164
+ To create multiple links in a single transaction, you can use `client.zksend.createLinks`:
165
+
166
+ ```ts
167
+ const links = [];
168
+
169
+ for (let i = 0; i < 10; i++) {
170
+ const link = client.zksend.linkBuilder({
171
+ sender: keypair.toSuiAddress(),
172
+ });
173
+
174
+ link.addClaimableMist(100n);
175
+ links.push(link);
176
+ }
177
+
178
+ const urls = links.map((link) => link.getLink());
179
+
180
+ const tx = await client.zksend.createLinks({
181
+ links,
182
+ });
183
+
184
+ const result = await client.signAndExecuteTransaction({
185
+ transaction: tx,
186
+ signer: keypair,
187
+ });
188
+
189
+ // Check transaction status
190
+ if (result.$kind === 'FailedTransaction') {
191
+ throw new Error(`Link creation failed: ${result.FailedTransaction.status.error?.message}`);
192
+ }
193
+ ```
@@ -0,0 +1,6 @@
1
+ # ZkSend
2
+ > Send Sui with a link
3
+
4
+ - [zkSend SDK](..md): Send Sui assets through shareable claim links using the zkSend SDK.
5
+ - [Creating zkSend Links](./link-builder.md): Create and customize zkSend claim links for sending Sui assets.
6
+ - [Composable Claims](./composable-claim.md): Claim a zkSend link and use the assets in the same transaction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten/zksend",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Create claimable links for transferring coins and NFTs",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mysten Labs <build@mystenlabs.com>",
@@ -29,20 +29,20 @@
29
29
  },
30
30
  "homepage": "https://sdk.mystenlabs.com/zksend",
31
31
  "devDependencies": {
32
- "@types/node": "^25.0.8",
33
- "typescript": "^5.9.3",
34
- "vitest": "^4.0.17"
32
+ "@types/node": "^25.9.3",
33
+ "typescript": "^6.0.3",
34
+ "vitest": "^4.1.8"
35
35
  },
36
36
  "dependencies": {
37
37
  "mitt": "^3.0.1",
38
- "nanostores": "^1.1.0",
39
- "valibot": "^1.2.0",
40
- "@mysten/wallet-standard": "^0.20.2",
41
- "@mysten/window-wallet-core": "^0.1.5",
42
- "@mysten/utils": "^0.3.2"
38
+ "nanostores": "^1.3.0",
39
+ "valibot": "^1.4.1",
40
+ "@mysten/utils": "^0.4.0",
41
+ "@mysten/window-wallet-core": "^0.2.0",
42
+ "@mysten/wallet-standard": "^0.21.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@mysten/sui": "^2.16.1"
45
+ "@mysten/sui": "^2.18.0"
46
46
  },
47
47
  "scripts": {
48
48
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",