@haneullabs/zksend 0.1.0 → 1.0.2
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 +346 -215
- package/README.md +239 -0
- package/dist/client.d.mts +59 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +108 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +7 -0
- package/dist/links/builder.d.mts +83 -0
- package/dist/links/builder.d.mts.map +1 -0
- package/dist/links/builder.mjs +213 -0
- package/dist/links/builder.mjs.map +1 -0
- package/dist/links/claim.d.mts +82 -0
- package/dist/links/claim.d.mts.map +1 -0
- package/dist/links/claim.mjs +235 -0
- package/dist/links/claim.mjs.map +1 -0
- package/dist/links/utils.d.mts +27 -0
- package/dist/links/utils.d.mts.map +1 -0
- package/dist/links/utils.mjs +22 -0
- package/dist/links/utils.mjs.map +1 -0
- package/dist/links/zk-bag.d.mts +79 -0
- package/dist/links/zk-bag.d.mts.map +1 -0
- package/dist/links/zk-bag.mjs +102 -0
- package/dist/links/zk-bag.mjs.map +1 -0
- package/package.json +27 -30
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -38
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/index.test.d.ts +0 -4
- package/dist/cjs/links/builder.d.ts +0 -55
- package/dist/cjs/links/builder.js +0 -361
- package/dist/cjs/links/builder.js.map +0 -7
- package/dist/cjs/links/claim.d.ts +0 -57
- package/dist/cjs/links/claim.js +0 -573
- package/dist/cjs/links/claim.js.map +0 -7
- package/dist/cjs/links/get-sent-transactions.d.ts +0 -25
- package/dist/cjs/links/get-sent-transactions.js +0 -134
- package/dist/cjs/links/get-sent-transactions.js.map +0 -7
- package/dist/cjs/links/list-created-links.d.ts +0 -24
- package/dist/cjs/links/list-created-links.js +0 -124
- package/dist/cjs/links/list-created-links.js.map +0 -7
- package/dist/cjs/links/utils.d.ts +0 -34
- package/dist/cjs/links/utils.js +0 -132
- package/dist/cjs/links/utils.js.map +0 -7
- package/dist/cjs/links/zk-bag.d.ts +0 -72
- package/dist/cjs/links/zk-bag.js +0 -145
- package/dist/cjs/links/zk-bag.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/esm/index.d.ts +0 -7
- package/dist/esm/index.js +0 -20
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/index.test.d.ts +0 -4
- package/dist/esm/links/builder.d.ts +0 -55
- package/dist/esm/links/builder.js +0 -341
- package/dist/esm/links/builder.js.map +0 -7
- package/dist/esm/links/claim.d.ts +0 -57
- package/dist/esm/links/claim.js +0 -561
- package/dist/esm/links/claim.js.map +0 -7
- package/dist/esm/links/get-sent-transactions.d.ts +0 -25
- package/dist/esm/links/get-sent-transactions.js +0 -114
- package/dist/esm/links/get-sent-transactions.js.map +0 -7
- package/dist/esm/links/list-created-links.d.ts +0 -24
- package/dist/esm/links/list-created-links.js +0 -104
- package/dist/esm/links/list-created-links.js.map +0 -7
- package/dist/esm/links/utils.d.ts +0 -34
- package/dist/esm/links/utils.js +0 -112
- package/dist/esm/links/utils.js.map +0 -7
- package/dist/esm/links/zk-bag.d.ts +0 -72
- package/dist/esm/links/zk-bag.js +0 -125
- package/dist/esm/links/zk-bag.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/experimental/unified-adapter/package.json +0 -6
package/README.md
CHANGED
|
@@ -1 +1,240 @@
|
|
|
1
1
|
# `@haneullabs/zksend`
|
|
2
|
+
|
|
3
|
+
Create claimable links for transferring coins and NFTs. Recipients can claim assets via URL without
|
|
4
|
+
needing a wallet set up beforehand.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @haneullabs/zksend
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Limitations
|
|
13
|
+
|
|
14
|
+
- zkSend only supports Mainnet and Testnet at this time.
|
|
15
|
+
- Objects within links must be publicly transferrable.
|
|
16
|
+
|
|
17
|
+
## Create a link
|
|
18
|
+
|
|
19
|
+
You can start creating your own zkSend link using the `ZkSendLinkBuilder` class. This class
|
|
20
|
+
constructor takes an object with the following options:
|
|
21
|
+
|
|
22
|
+
- **`sender`** (required) - The address of the sender / creator of the link.
|
|
23
|
+
- **`client`** (optional) - The `@haneullabs/haneul` client used to fetch data to construct the link. If
|
|
24
|
+
not provided, a default client will be used.
|
|
25
|
+
- **`network`** (optional) - The network that the link will be created for. Defaults to `mainnet`.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { ZkSendLinkBuilder } from '@haneullabs/zksend';
|
|
29
|
+
|
|
30
|
+
const link = new ZkSendLinkBuilder({
|
|
31
|
+
sender: '0x...',
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Adding HANEUL to the link
|
|
36
|
+
|
|
37
|
+
You can add HANEUL to the link by calling `link.addClaimableMist()`. This method takes the following
|
|
38
|
+
params:
|
|
39
|
+
|
|
40
|
+
- **`amount`** (required) - The amount of GEUNHWA (the base unit of HANEUL) to add to the link.
|
|
41
|
+
|
|
42
|
+
### Adding non-HANEUL coins to the link
|
|
43
|
+
|
|
44
|
+
You can add non-HANEUL coins to the link by calling `link.addClaimableBalance()`. This method takes the
|
|
45
|
+
following params:
|
|
46
|
+
|
|
47
|
+
- **`coinType`** (required) - The coin type of the coin to add to the link (e.g. `0x2::haneul::HANEUL`).
|
|
48
|
+
- **`amount`** (required) - The amount of the coin to add to the link. Represented in the base unit
|
|
49
|
+
of the coin.
|
|
50
|
+
|
|
51
|
+
The SDK will automatically perform the necessary coin management logic to transfer the defined
|
|
52
|
+
amount, such as merging and splitting coin objects.
|
|
53
|
+
|
|
54
|
+
### Adding objects to the link
|
|
55
|
+
|
|
56
|
+
You can add a publicly-transferrable object to the link by calling `link.addClaimableObject()`. This
|
|
57
|
+
method takes the following params:
|
|
58
|
+
|
|
59
|
+
- **`id`** (required) - The ID of the object. This must be owned by the `sender` you configured when
|
|
60
|
+
creating the link.
|
|
61
|
+
|
|
62
|
+
### Adding objects created in the same transaction
|
|
63
|
+
|
|
64
|
+
You can create objects to add to links in the same transaction the link is created in by using
|
|
65
|
+
`link.addClaimableObjectRef()`:
|
|
66
|
+
|
|
67
|
+
- **`ref`** (required) - The reference to the object you want to add to the link.
|
|
68
|
+
- **`type`** (required) - The move type of the object you are adding
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const tx = new Transaction();
|
|
72
|
+
|
|
73
|
+
const link = new ZkSendLinkBuilder({
|
|
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.
|
|
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:
|
|
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 via the SDK you can use the `ZkSendLink` class:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { ZkSendLink } from '@haneullabs/zksend';
|
|
132
|
+
|
|
133
|
+
// create a link instance from a URL
|
|
134
|
+
const link = await ZkSendLink.fromUrl('https://zksend.com/claim#$abc...');
|
|
135
|
+
|
|
136
|
+
// list what claimable assets the link has
|
|
137
|
+
const { nfts, balances } = link.assets;
|
|
138
|
+
|
|
139
|
+
// claim all the assets from the link
|
|
140
|
+
await link.claimAssets(addressOfClaimer);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Listing links you have created
|
|
144
|
+
|
|
145
|
+
To list the links created by a specific address, you can use the `listCreatedLinks` function:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { listCreatedLinks } from '@haneullabs/zksend';
|
|
149
|
+
|
|
150
|
+
const { links, hasNextPage, cursor } = await listCreatedLinks({
|
|
151
|
+
address: addressOfCreator,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// get the claimable assets for this link (will be empty if the link has been claimed)
|
|
155
|
+
const { nfts, balances } = await links[0].assets;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Listing transactions and the links they created
|
|
159
|
+
|
|
160
|
+
`getSentTransactionsWithLinks` will return a list of transactions sent by the provided address. Each
|
|
161
|
+
result will include the transaction that was sent, along with an array containing any links that
|
|
162
|
+
were created or regenerated by that transaction.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { getSentTransactionsWithLinks } from '@haneullabs/zksend';
|
|
166
|
+
|
|
167
|
+
const { data, hasNextPage, nextCursor } = await getSentTransactionsWithLinks({
|
|
168
|
+
address: addressOfCreator,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
for (const { transaction, links } of data) {
|
|
172
|
+
// get the claimable assets for this link (will be empty if the link has been claimed)
|
|
173
|
+
const firstLink = links[0];
|
|
174
|
+
|
|
175
|
+
// link is claimed
|
|
176
|
+
firstLink.claimed;
|
|
177
|
+
const { nfts, balances } = firstLink.assets;
|
|
178
|
+
|
|
179
|
+
// claim link
|
|
180
|
+
await firstLink.link.claimAssets(addressOfClaimer);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
By default `getSentTransactionsWithLinks` will not load the assets for claimed links. This can be
|
|
185
|
+
changed by passing `loadClaimedAssets: true` to the function.
|
|
186
|
+
|
|
187
|
+
## Regenerating links
|
|
188
|
+
|
|
189
|
+
If you lose a link you've created, you can re-generate the link (this can only done from the address
|
|
190
|
+
that originally created the link):
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { listCreatedLinks } from '@haneullabs/zksend';
|
|
194
|
+
|
|
195
|
+
const { links, hasNextPage, cursor } = await listCreatedLinks({
|
|
196
|
+
address: addressOfCreator,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// url will be the new link url
|
|
200
|
+
const { url, transaction } = await links[0].link.createRegenerateTransaction(addressOfLinkCreator);
|
|
201
|
+
|
|
202
|
+
// Execute the transaction to regenerate the link
|
|
203
|
+
const result = await client.signAndExecuteTransaction({
|
|
204
|
+
transaction,
|
|
205
|
+
signer: keypair,
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Bulk link creation
|
|
210
|
+
|
|
211
|
+
To create multiple links in a single transaction, you can use `ZkSendLinkBuilder.createLinks`:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
const links = [];
|
|
215
|
+
|
|
216
|
+
for (let i = 0; i < 10; i++) {
|
|
217
|
+
const link = new ZkSendLinkBuilder({
|
|
218
|
+
client,
|
|
219
|
+
sender: keypair.toSuiAddress(),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
link.addClaimableMist(100n);
|
|
223
|
+
links.push(link);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const urls = links.map((link) => link.getLink());
|
|
227
|
+
|
|
228
|
+
const tx = await ZkSendLinkBuilder.createLinks({
|
|
229
|
+
links,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const result = await client.signAndExecuteTransaction({
|
|
233
|
+
transaction: tx,
|
|
234
|
+
signer: keypair,
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Documentation
|
|
239
|
+
|
|
240
|
+
See the [zkSend SDK documentation](https://sdk.haneul-labs.com/zksend) for more details.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ZkBagContractOptions } from "./links/zk-bag.mjs";
|
|
2
|
+
import { ZkSendLinkBuilder } from "./links/builder.mjs";
|
|
3
|
+
import { ZkSendLink } from "./links/claim.mjs";
|
|
4
|
+
import { Transaction } from "@haneullabs/haneul/transactions";
|
|
5
|
+
import { Keypair } from "@haneullabs/haneul/cryptography";
|
|
6
|
+
import { ClientWithCoreApi, HaneulClientRegistration } from "@haneullabs/haneul/client";
|
|
7
|
+
|
|
8
|
+
//#region src/client.d.ts
|
|
9
|
+
type ZkSendCompatibleClient = ClientWithCoreApi;
|
|
10
|
+
interface ZkSendOptions<Name extends string = 'zksend'> {
|
|
11
|
+
name?: Name;
|
|
12
|
+
host?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
claimApi?: string;
|
|
15
|
+
contract?: ZkBagContractOptions;
|
|
16
|
+
}
|
|
17
|
+
interface LinkBuilderOptions {
|
|
18
|
+
sender: string;
|
|
19
|
+
keypair?: Keypair;
|
|
20
|
+
}
|
|
21
|
+
type LoadLinkOptions = {
|
|
22
|
+
address: string;
|
|
23
|
+
keypair?: never;
|
|
24
|
+
} | {
|
|
25
|
+
keypair: Keypair;
|
|
26
|
+
address?: never;
|
|
27
|
+
};
|
|
28
|
+
declare class ZkSendClient {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(client: ZkSendCompatibleClient, options?: Omit<ZkSendOptions, 'name'>);
|
|
31
|
+
linkBuilder(options: LinkBuilderOptions): ZkSendLinkBuilder;
|
|
32
|
+
createLinks(options: {
|
|
33
|
+
links: ZkSendLinkBuilder[];
|
|
34
|
+
transaction?: Transaction;
|
|
35
|
+
}): Promise<Transaction>;
|
|
36
|
+
/**
|
|
37
|
+
* Get a link without loading its assets (synchronous)
|
|
38
|
+
*/
|
|
39
|
+
getLink(options: LoadLinkOptions): ZkSendLink;
|
|
40
|
+
/**
|
|
41
|
+
* Load a link and its assets
|
|
42
|
+
*/
|
|
43
|
+
loadLink(options: LoadLinkOptions): Promise<ZkSendLink>;
|
|
44
|
+
/**
|
|
45
|
+
* Get a link from a URL without loading assets (synchronous)
|
|
46
|
+
*/
|
|
47
|
+
getLinkFromUrl(url: string): ZkSendLink;
|
|
48
|
+
/**
|
|
49
|
+
* Load a link from a URL and its assets
|
|
50
|
+
*/
|
|
51
|
+
loadLinkFromUrl(url: string): Promise<ZkSendLink>;
|
|
52
|
+
}
|
|
53
|
+
declare function zksend<Name extends string = 'zksend'>({
|
|
54
|
+
name,
|
|
55
|
+
...options
|
|
56
|
+
}?: ZkSendOptions<Name>): HaneulClientRegistration<ZkSendCompatibleClient, Name, ZkSendClient>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { LinkBuilderOptions, LoadLinkOptions, ZkSendClient, ZkSendCompatibleClient, ZkSendOptions, zksend };
|
|
59
|
+
//# sourceMappingURL=client.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAcY,sBAAA,GAAyB;UAEpB;EAFL,IAAA,CAAA,EAGJ,IAHI;EAEK,IAAA,CAAA,EAAA,MAAA;EAQA,IAAA,CAAA,EAAA,MAAA;EAKL,QAAA,CAAA,EAAA,MAAA;EAmBC,QAAA,CAAA,EA3BD,oBA2Ba;;AAQkC,UAhC1C,kBAAA,CAgC0C;EAAL,MAAA,EAAA,MAAA;EAShC,OAAA,CAAA,EAvCX,OAuCW;;AAab,KAjDG,eAAA,GAiDH;EACO,OAAA,EAAA,MAAA;EACH,OAAA,CAAA,EAAA,KAAA;CAAR,GAAA;EAaa,OAAA,EA1DN,OA0DM;EAAkB,OAAA,CAAA,EAAA,KAAA;CAeX;AAA0B,cA5DtC,YAAA,CA4DsC;EAAR,CAAA,OAAA;EASb,WAAA,CAAA,MAAA,EA7DT,sBA6DS,EAAA,OAAA,CAAA,EA7DwB,IA6DxB,CA7D6B,aA6D7B,EAAA,MAAA,CAAA;EA8Be,WAAA,CAAA,OAAA,EAlFvB,kBAkFuB,CAAA,EAlFF,iBAkFE;EAAR,WAAA,CAAA,OAAA,EAAA;IAAO,KAAA,EArEnC,iBAqEmC,EAAA;IAO5B,WAAM,CAAA,EA3EN,WA2EM;EACrB,CAAA,CAAA,EA3EI,OA2EJ,CA3EY,WA2EZ,CAAA;EAEgB;;;EAA8D,OAAA,CAAA,OAAA,EAhE7D,eAgE6D,CAAA,EAhE3C,UAgE2C;EAAM;;;oBAjD5D,kBAAkB,QAAQ;;;;+BASrB;;;;gCA8BO,QAAQ;;iBAO7B;;;IAGb,cAAc,QAAa,yBAAyB,wBAAwB,MAAM"}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { getContractIds } from "./links/zk-bag.mjs";
|
|
2
|
+
import { ZkSendLinkBuilder } from "./links/builder.mjs";
|
|
3
|
+
import { ZkSendLink } from "./links/claim.mjs";
|
|
4
|
+
import { Ed25519Keypair } from "@haneullabs/haneul/keypairs/ed25519";
|
|
5
|
+
import { fromBase64 } from "@haneullabs/haneul/utils";
|
|
6
|
+
|
|
7
|
+
//#region src/client.ts
|
|
8
|
+
function getDefaultContractIds(clientNetwork) {
|
|
9
|
+
if (clientNetwork === "mainnet" || clientNetwork === "testnet") return getContractIds(clientNetwork);
|
|
10
|
+
throw new Error(`zkSend only has built-in contract IDs for mainnet and testnet. For network "${clientNetwork}", you must provide a custom contract option.`);
|
|
11
|
+
}
|
|
12
|
+
var ZkSendClient = class {
|
|
13
|
+
#client;
|
|
14
|
+
#network;
|
|
15
|
+
#host;
|
|
16
|
+
#path;
|
|
17
|
+
#claimApi;
|
|
18
|
+
#contract;
|
|
19
|
+
constructor(client, options = {}) {
|
|
20
|
+
this.#client = client;
|
|
21
|
+
this.#network = client.network;
|
|
22
|
+
this.#host = options.host ?? "https://my.slush.app";
|
|
23
|
+
this.#path = options.path ?? "/claim";
|
|
24
|
+
this.#claimApi = options.claimApi ?? "https://api.slush.app/api";
|
|
25
|
+
this.#contract = options.contract ?? getDefaultContractIds(client.network);
|
|
26
|
+
}
|
|
27
|
+
linkBuilder(options) {
|
|
28
|
+
return new ZkSendLinkBuilder({
|
|
29
|
+
client: this.#client,
|
|
30
|
+
sender: options.sender,
|
|
31
|
+
keypair: options.keypair,
|
|
32
|
+
network: this.#network,
|
|
33
|
+
host: this.#host,
|
|
34
|
+
path: this.#path,
|
|
35
|
+
contract: this.#contract
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async createLinks(options) {
|
|
39
|
+
return ZkSendLinkBuilder.createLinks({
|
|
40
|
+
links: options.links,
|
|
41
|
+
transaction: options.transaction,
|
|
42
|
+
client: this.#client,
|
|
43
|
+
network: this.#network,
|
|
44
|
+
contract: this.#contract
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a link without loading its assets (synchronous)
|
|
49
|
+
*/
|
|
50
|
+
getLink(options) {
|
|
51
|
+
return new ZkSendLink({
|
|
52
|
+
client: this.#client,
|
|
53
|
+
network: this.#network,
|
|
54
|
+
host: this.#host,
|
|
55
|
+
path: this.#path,
|
|
56
|
+
claimApi: this.#claimApi,
|
|
57
|
+
contract: this.#contract,
|
|
58
|
+
...options
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Load a link and its assets
|
|
63
|
+
*/
|
|
64
|
+
async loadLink(options) {
|
|
65
|
+
const link = this.getLink(options);
|
|
66
|
+
await link.loadAssets();
|
|
67
|
+
return link;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get a link from a URL without loading assets (synchronous)
|
|
71
|
+
*/
|
|
72
|
+
getLinkFromUrl(url) {
|
|
73
|
+
const parsed = new URL(url);
|
|
74
|
+
if (!parsed.hash.startsWith("#$")) throw new Error("Invalid link URL");
|
|
75
|
+
const parsedNetwork = parsed.searchParams.get("network") === "testnet" ? "testnet" : "mainnet";
|
|
76
|
+
if (parsedNetwork !== this.#network) throw new Error(`Link network "${parsedNetwork}" does not match client network "${this.#network}"`);
|
|
77
|
+
const keypair = Ed25519Keypair.fromSecretKey(fromBase64(parsed.hash.slice(2)));
|
|
78
|
+
return new ZkSendLink({
|
|
79
|
+
client: this.#client,
|
|
80
|
+
keypair,
|
|
81
|
+
network: this.#network,
|
|
82
|
+
host: `${parsed.protocol}//${parsed.host}`,
|
|
83
|
+
path: parsed.pathname,
|
|
84
|
+
claimApi: this.#claimApi,
|
|
85
|
+
contract: this.#contract
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Load a link from a URL and its assets
|
|
90
|
+
*/
|
|
91
|
+
async loadLinkFromUrl(url) {
|
|
92
|
+
const link = this.getLinkFromUrl(url);
|
|
93
|
+
await link.loadAssets();
|
|
94
|
+
return link;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function zksend({ name = "zksend", ...options } = {}) {
|
|
98
|
+
return {
|
|
99
|
+
name,
|
|
100
|
+
register: (client) => {
|
|
101
|
+
return new ZkSendClient(client, options);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ZkSendClient, zksend };
|
|
108
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["#client","#network","#host","#path","#claimApi","#contract"],"sources":["../src/client.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ClientWithCoreApi, HaneulClientRegistration } from '@haneullabs/haneul/client';\nimport type { Keypair } from '@haneullabs/haneul/cryptography';\nimport { Ed25519Keypair } from '@haneullabs/haneul/keypairs/ed25519';\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport { fromBase64 } from '@haneullabs/haneul/utils';\n\nimport { ZkSendLink } from './links/claim.js';\nimport { ZkSendLinkBuilder } from './links/builder.js';\nimport type { ZkBagContractOptions } from './links/zk-bag.js';\nimport { getContractIds } from './links/zk-bag.js';\n\nexport type ZkSendCompatibleClient = ClientWithCoreApi;\n\nexport interface ZkSendOptions<Name extends string = 'zksend'> {\n\tname?: Name;\n\thost?: string;\n\tpath?: string;\n\tclaimApi?: string;\n\tcontract?: ZkBagContractOptions;\n}\n\nexport interface LinkBuilderOptions {\n\tsender: string;\n\tkeypair?: Keypair;\n}\n\nexport type LoadLinkOptions =\n\t| {\n\t\t\taddress: string;\n\t\t\tkeypair?: never;\n\t }\n\t| {\n\t\t\tkeypair: Keypair;\n\t\t\taddress?: never;\n\t };\n\nfunction getDefaultContractIds(clientNetwork: string): ZkBagContractOptions {\n\tif (clientNetwork === 'mainnet' || clientNetwork === 'testnet') {\n\t\treturn getContractIds(clientNetwork);\n\t}\n\tthrow new Error(\n\t\t`zkSend only has built-in contract IDs for mainnet and testnet. For network \"${clientNetwork}\", you must provide a custom contract option.`,\n\t);\n}\n\nexport class ZkSendClient {\n\t#client: ZkSendCompatibleClient;\n\t#network: string;\n\t#host: string;\n\t#path: string;\n\t#claimApi: string;\n\t#contract: ZkBagContractOptions;\n\n\tconstructor(client: ZkSendCompatibleClient, options: Omit<ZkSendOptions, 'name'> = {}) {\n\t\tthis.#client = client;\n\t\tthis.#network = client.network;\n\t\tthis.#host = options.host ?? 'https://my.slush.app';\n\t\tthis.#path = options.path ?? '/claim';\n\t\tthis.#claimApi = options.claimApi ?? 'https://api.slush.app/api';\n\t\tthis.#contract = options.contract ?? getDefaultContractIds(client.network);\n\t}\n\n\tlinkBuilder(options: LinkBuilderOptions): ZkSendLinkBuilder {\n\t\treturn new ZkSendLinkBuilder({\n\t\t\tclient: this.#client,\n\t\t\tsender: options.sender,\n\t\t\tkeypair: options.keypair,\n\t\t\tnetwork: this.#network,\n\t\t\thost: this.#host,\n\t\t\tpath: this.#path,\n\t\t\tcontract: this.#contract,\n\t\t});\n\t}\n\n\tasync createLinks(options: {\n\t\tlinks: ZkSendLinkBuilder[];\n\t\ttransaction?: Transaction;\n\t}): Promise<Transaction> {\n\t\treturn ZkSendLinkBuilder.createLinks({\n\t\t\tlinks: options.links,\n\t\t\ttransaction: options.transaction,\n\t\t\tclient: this.#client,\n\t\t\tnetwork: this.#network,\n\t\t\tcontract: this.#contract,\n\t\t});\n\t}\n\n\t/**\n\t * Get a link without loading its assets (synchronous)\n\t */\n\tgetLink(options: LoadLinkOptions): ZkSendLink {\n\t\treturn new ZkSendLink({\n\t\t\tclient: this.#client,\n\t\t\tnetwork: this.#network,\n\t\t\thost: this.#host,\n\t\t\tpath: this.#path,\n\t\t\tclaimApi: this.#claimApi,\n\t\t\tcontract: this.#contract,\n\t\t\t...options,\n\t\t});\n\t}\n\n\t/**\n\t * Load a link and its assets\n\t */\n\tasync loadLink(options: LoadLinkOptions): Promise<ZkSendLink> {\n\t\tconst link = this.getLink(options);\n\t\tawait link.loadAssets();\n\t\treturn link;\n\t}\n\n\t/**\n\t * Get a link from a URL without loading assets (synchronous)\n\t */\n\tgetLinkFromUrl(url: string): ZkSendLink {\n\t\tconst parsed = new URL(url);\n\t\tif (!parsed.hash.startsWith('#$')) {\n\t\t\tthrow new Error('Invalid link URL');\n\t\t}\n\n\t\tconst parsedNetwork = parsed.searchParams.get('network') === 'testnet' ? 'testnet' : 'mainnet';\n\n\t\tif (parsedNetwork !== this.#network) {\n\t\t\tthrow new Error(\n\t\t\t\t`Link network \"${parsedNetwork}\" does not match client network \"${this.#network}\"`,\n\t\t\t);\n\t\t}\n\n\t\tconst keypair = Ed25519Keypair.fromSecretKey(fromBase64(parsed.hash.slice(2)));\n\n\t\treturn new ZkSendLink({\n\t\t\tclient: this.#client,\n\t\t\tkeypair,\n\t\t\tnetwork: this.#network,\n\t\t\thost: `${parsed.protocol}//${parsed.host}`,\n\t\t\tpath: parsed.pathname,\n\t\t\tclaimApi: this.#claimApi,\n\t\t\tcontract: this.#contract,\n\t\t});\n\t}\n\n\t/**\n\t * Load a link from a URL and its assets\n\t */\n\tasync loadLinkFromUrl(url: string): Promise<ZkSendLink> {\n\t\tconst link = this.getLinkFromUrl(url);\n\t\tawait link.loadAssets();\n\t\treturn link;\n\t}\n}\n\nexport function zksend<Name extends string = 'zksend'>({\n\tname = 'zksend' as Name,\n\t...options\n}: ZkSendOptions<Name> = {}): HaneulClientRegistration<ZkSendCompatibleClient, Name, ZkSendClient> {\n\treturn {\n\t\tname,\n\t\tregister: (client) => {\n\t\t\treturn new ZkSendClient(client, options);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAuCA,SAAS,sBAAsB,eAA6C;AAC3E,KAAI,kBAAkB,aAAa,kBAAkB,UACpD,QAAO,eAAe,cAAc;AAErC,OAAM,IAAI,MACT,+EAA+E,cAAc,+CAC7F;;AAGF,IAAa,eAAb,MAA0B;CACzB;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,QAAgC,UAAuC,EAAE,EAAE;AACtF,QAAK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Q,MAAKD;GACb;GACA,SAAS,MAAKC;GACd,MAAM,GAAG,OAAO,SAAS,IAAI,OAAO;GACpC,MAAM,OAAO;GACb,UAAU,MAAKG;GACf,UAAU,MAAKC;GACf,CAAC;;;;;CAMH,MAAM,gBAAgB,KAAkC;EACvD,MAAM,OAAO,KAAK,eAAe,IAAI;AACrC,QAAM,KAAK,YAAY;AACvB,SAAO;;;AAIT,SAAgB,OAAuC,EACtD,OAAO,UACP,GAAG,YACqB,EAAE,EAAwE;AAClG,QAAO;EACN;EACA,WAAW,WAAW;AACrB,UAAO,IAAI,aAAa,QAAQ,QAAQ;;EAEzC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MAINNET_CONTRACT_IDS, TESTNET_CONTRACT_IDS, ZkBag, ZkBagContractOptions } from "./links/zk-bag.mjs";
|
|
2
|
+
import { CreateZkSendLinkOptions, ZkSendLinkBuilder, ZkSendLinkBuilderOptions } from "./links/builder.mjs";
|
|
3
|
+
import { isClaimTransaction } from "./links/utils.mjs";
|
|
4
|
+
import { ZkSendLink, ZkSendLinkOptions } from "./links/claim.mjs";
|
|
5
|
+
import { LinkBuilderOptions, LoadLinkOptions, ZkSendClient, ZkSendCompatibleClient, ZkSendOptions, zksend } from "./client.mjs";
|
|
6
|
+
export { type CreateZkSendLinkOptions, type LinkBuilderOptions, type LoadLinkOptions, MAINNET_CONTRACT_IDS, TESTNET_CONTRACT_IDS, ZkBag, type ZkBagContractOptions, ZkSendClient, type ZkSendCompatibleClient, ZkSendLink, ZkSendLinkBuilder, type ZkSendLinkBuilderOptions, type ZkSendLinkOptions, type ZkSendOptions, isClaimTransaction, zksend };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MAINNET_CONTRACT_IDS, TESTNET_CONTRACT_IDS, ZkBag } from "./links/zk-bag.mjs";
|
|
2
|
+
import { ZkSendLinkBuilder } from "./links/builder.mjs";
|
|
3
|
+
import { ZkSendLink } from "./links/claim.mjs";
|
|
4
|
+
import { ZkSendClient, zksend } from "./client.mjs";
|
|
5
|
+
import { isClaimTransaction } from "./links/utils.mjs";
|
|
6
|
+
|
|
7
|
+
export { MAINNET_CONTRACT_IDS, TESTNET_CONTRACT_IDS, ZkBag, ZkSendClient, ZkSendLink, ZkSendLinkBuilder, isClaimTransaction, zksend };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ZkBagContractOptions } from "./zk-bag.mjs";
|
|
2
|
+
import { Transaction, TransactionObjectArgument } from "@haneullabs/haneul/transactions";
|
|
3
|
+
import { Keypair, Signer } from "@haneullabs/haneul/cryptography";
|
|
4
|
+
import { ClientWithCoreApi, HaneulClientTypes } from "@haneullabs/haneul/client";
|
|
5
|
+
|
|
6
|
+
//#region src/links/builder.d.ts
|
|
7
|
+
interface ZkSendLinkBuilderOptions {
|
|
8
|
+
host?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
keypair?: Keypair;
|
|
11
|
+
network?: string;
|
|
12
|
+
client: ClientWithCoreApi;
|
|
13
|
+
sender: string;
|
|
14
|
+
contract?: ZkBagContractOptions;
|
|
15
|
+
}
|
|
16
|
+
interface CreateZkSendLinkOptions {
|
|
17
|
+
transaction?: Transaction;
|
|
18
|
+
}
|
|
19
|
+
declare class ZkSendLinkBuilder {
|
|
20
|
+
#private;
|
|
21
|
+
objectIds: Set<string>;
|
|
22
|
+
objectRefs: {
|
|
23
|
+
ref: TransactionObjectArgument;
|
|
24
|
+
type: string;
|
|
25
|
+
}[];
|
|
26
|
+
balances: Map<string, bigint>;
|
|
27
|
+
sender: string;
|
|
28
|
+
network: string;
|
|
29
|
+
keypair: Keypair;
|
|
30
|
+
constructor({
|
|
31
|
+
host,
|
|
32
|
+
path,
|
|
33
|
+
keypair,
|
|
34
|
+
network,
|
|
35
|
+
client,
|
|
36
|
+
sender,
|
|
37
|
+
contract
|
|
38
|
+
}: ZkSendLinkBuilderOptions);
|
|
39
|
+
addClaimableMist(amount: bigint): void;
|
|
40
|
+
addClaimableBalance(coinType: string, amount: bigint): void;
|
|
41
|
+
addClaimableObject(id: string): void;
|
|
42
|
+
addClaimableObjectRef(ref: TransactionObjectArgument, type: string): void;
|
|
43
|
+
getLink(): string;
|
|
44
|
+
create({
|
|
45
|
+
signer,
|
|
46
|
+
...options
|
|
47
|
+
}: CreateZkSendLinkOptions & {
|
|
48
|
+
signer: Signer;
|
|
49
|
+
waitForTransaction?: boolean;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
$kind: "Transaction";
|
|
52
|
+
Transaction: HaneulClientTypes.Transaction<{
|
|
53
|
+
transaction: true;
|
|
54
|
+
effects: true;
|
|
55
|
+
}>;
|
|
56
|
+
FailedTransaction?: never;
|
|
57
|
+
}>;
|
|
58
|
+
createSendTransaction({
|
|
59
|
+
transaction
|
|
60
|
+
}?: CreateZkSendLinkOptions): Promise<Transaction>;
|
|
61
|
+
createSendToAddressTransaction({
|
|
62
|
+
transaction,
|
|
63
|
+
address
|
|
64
|
+
}: CreateZkSendLinkOptions & {
|
|
65
|
+
address: string;
|
|
66
|
+
}): Promise<Transaction>;
|
|
67
|
+
static createLinks({
|
|
68
|
+
links,
|
|
69
|
+
network,
|
|
70
|
+
client,
|
|
71
|
+
transaction,
|
|
72
|
+
contract: contractIds
|
|
73
|
+
}: {
|
|
74
|
+
transaction?: Transaction;
|
|
75
|
+
client: ClientWithCoreApi;
|
|
76
|
+
network?: string;
|
|
77
|
+
links: ZkSendLinkBuilder[];
|
|
78
|
+
contract?: ZkBagContractOptions;
|
|
79
|
+
}): Promise<Transaction>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { CreateZkSendLinkOptions, ZkSendLinkBuilder, ZkSendLinkBuilderOptions };
|
|
83
|
+
//# sourceMappingURL=builder.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.mts","names":[],"sources":["../../src/links/builder.ts"],"sourcesContent":[],"mappings":";;;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