@mysten/zksend 0.2.2 → 0.3.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 +15 -0
- package/dist/cjs/channel/events.d.ts +54 -54
- package/dist/cjs/channel/index.d.ts +4 -4
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.test.d.ts +9 -1
- package/dist/cjs/links/builder.d.ts +41 -0
- package/dist/cjs/links/builder.js +264 -0
- package/dist/cjs/links/builder.js.map +7 -0
- package/dist/cjs/links/claim.d.ts +77 -0
- package/dist/cjs/links/claim.js +520 -0
- package/dist/cjs/links/claim.js.map +7 -0
- package/dist/cjs/links/utils.d.ts +17 -0
- package/dist/cjs/links/utils.js +133 -0
- package/dist/cjs/links/utils.js.map +7 -0
- package/dist/cjs/links/zk-bag.d.ts +79 -0
- package/dist/cjs/links/zk-bag.js +129 -0
- package/dist/cjs/links/zk-bag.js.map +7 -0
- package/dist/esm/channel/events.d.ts +54 -54
- package/dist/esm/channel/index.d.ts +4 -4
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +11 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.test.d.ts +9 -1
- package/dist/esm/links/builder.d.ts +41 -0
- package/dist/esm/links/builder.js +244 -0
- package/dist/esm/links/builder.js.map +7 -0
- package/dist/esm/links/claim.d.ts +77 -0
- package/dist/esm/links/claim.js +508 -0
- package/dist/esm/links/claim.js.map +7 -0
- package/dist/esm/links/utils.d.ts +17 -0
- package/dist/esm/links/utils.js +113 -0
- package/dist/esm/links/utils.js.map +7 -0
- package/dist/esm/links/zk-bag.d.ts +79 -0
- package/dist/esm/links/zk-bag.js +109 -0
- package/dist/esm/links/zk-bag.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -5
- package/dist/cjs/links.d.ts +0 -80
- package/dist/cjs/links.js +0 -374
- package/dist/cjs/links.js.map +0 -7
- package/dist/esm/links.d.ts +0 -80
- package/dist/esm/links.js +0 -362
- package/dist/esm/links.js.map +0 -7
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __accessCheck = (obj, member, msg) => {
|
|
20
|
+
if (!member.has(obj))
|
|
21
|
+
throw TypeError("Cannot " + msg);
|
|
22
|
+
};
|
|
23
|
+
var __privateGet = (obj, member, getter) => {
|
|
24
|
+
__accessCheck(obj, member, "read from private field");
|
|
25
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
26
|
+
};
|
|
27
|
+
var __privateAdd = (obj, member, value) => {
|
|
28
|
+
if (member.has(obj))
|
|
29
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
30
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
31
|
+
};
|
|
32
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
33
|
+
__accessCheck(obj, member, "write to private field");
|
|
34
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
var __privateMethod = (obj, member, method) => {
|
|
38
|
+
__accessCheck(obj, member, "access private method");
|
|
39
|
+
return method;
|
|
40
|
+
};
|
|
41
|
+
var claim_exports = {};
|
|
42
|
+
__export(claim_exports, {
|
|
43
|
+
ZkSendLink: () => ZkSendLink
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(claim_exports);
|
|
46
|
+
var import_client = require("@mysten/sui.js/client");
|
|
47
|
+
var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
|
|
48
|
+
var import_transactions = require("@mysten/sui.js/transactions");
|
|
49
|
+
var import_utils = require("@mysten/sui.js/utils");
|
|
50
|
+
var import_builder = require("./builder.js");
|
|
51
|
+
var import_zk_bag = require("./zk-bag.js");
|
|
52
|
+
var _client, _address, _keypair, _initiallyOwnedObjects, _ownedObjects, _bagObjects, _gasCoin, _hasSui, _creatorAddress, _contract, _claimApi, _network, _host, _path, _loadBag, loadBag_fn, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn, _fetch, fetch_fn, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn, _loadOwnedObjects, loadOwnedObjects_fn, _loadInitialTransactionData, loadInitialTransactionData_fn;
|
|
53
|
+
const DEFAULT_ZK_SEND_LINK_OPTIONS = {
|
|
54
|
+
host: "https://zksend.com",
|
|
55
|
+
path: "/claim",
|
|
56
|
+
network: "mainnet",
|
|
57
|
+
claimApi: "https://zksend.com/api"
|
|
58
|
+
};
|
|
59
|
+
const SUI_COIN_TYPE = (0, import_utils.normalizeStructTag)(import_utils.SUI_TYPE_ARG);
|
|
60
|
+
const SUI_COIN_OBJECT_TYPE = (0, import_utils.normalizeStructTag)("0x2::coin::Coin<0x2::sui::SUI>");
|
|
61
|
+
const _ZkSendLink = class {
|
|
62
|
+
constructor({
|
|
63
|
+
network = DEFAULT_ZK_SEND_LINK_OPTIONS.network,
|
|
64
|
+
claimApi = DEFAULT_ZK_SEND_LINK_OPTIONS.claimApi,
|
|
65
|
+
client = new import_client.SuiClient({ url: (0, import_client.getFullnodeUrl)(network) }),
|
|
66
|
+
keypair,
|
|
67
|
+
contract,
|
|
68
|
+
address,
|
|
69
|
+
host,
|
|
70
|
+
path,
|
|
71
|
+
isContractLink
|
|
72
|
+
}) {
|
|
73
|
+
__privateAdd(this, _loadBag);
|
|
74
|
+
__privateAdd(this, _createSponsoredTransactionBlock);
|
|
75
|
+
__privateAdd(this, _executeSponsoredTransactionBlock);
|
|
76
|
+
__privateAdd(this, _fetch);
|
|
77
|
+
__privateAdd(this, _listNonContractClaimableAssets);
|
|
78
|
+
__privateAdd(this, _createNonContractClaimTransaction);
|
|
79
|
+
__privateAdd(this, _loadOwnedObjects);
|
|
80
|
+
__privateAdd(this, _loadInitialTransactionData);
|
|
81
|
+
__privateAdd(this, _client, void 0);
|
|
82
|
+
__privateAdd(this, _address, void 0);
|
|
83
|
+
__privateAdd(this, _keypair, void 0);
|
|
84
|
+
__privateAdd(this, _initiallyOwnedObjects, /* @__PURE__ */ new Set());
|
|
85
|
+
__privateAdd(this, _ownedObjects, []);
|
|
86
|
+
__privateAdd(this, _bagObjects, null);
|
|
87
|
+
__privateAdd(this, _gasCoin, void 0);
|
|
88
|
+
__privateAdd(this, _hasSui, false);
|
|
89
|
+
__privateAdd(this, _creatorAddress, void 0);
|
|
90
|
+
__privateAdd(this, _contract, void 0);
|
|
91
|
+
__privateAdd(this, _claimApi, void 0);
|
|
92
|
+
__privateAdd(this, _network, void 0);
|
|
93
|
+
__privateAdd(this, _host, void 0);
|
|
94
|
+
__privateAdd(this, _path, void 0);
|
|
95
|
+
if (!keypair && !address) {
|
|
96
|
+
throw new Error("Either keypair or address must be provided");
|
|
97
|
+
}
|
|
98
|
+
__privateSet(this, _client, client);
|
|
99
|
+
__privateSet(this, _keypair, keypair);
|
|
100
|
+
__privateSet(this, _address, address ?? keypair.toSuiAddress());
|
|
101
|
+
__privateSet(this, _claimApi, claimApi);
|
|
102
|
+
__privateSet(this, _network, network);
|
|
103
|
+
__privateSet(this, _host, host);
|
|
104
|
+
__privateSet(this, _path, path);
|
|
105
|
+
if (isContractLink) {
|
|
106
|
+
if (!contract) {
|
|
107
|
+
throw new Error("Contract options are required for contract based links");
|
|
108
|
+
}
|
|
109
|
+
__privateSet(this, _contract, new import_zk_bag.ZkBag(contract.packageId, contract));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
static async fromUrl(url, {
|
|
113
|
+
contract,
|
|
114
|
+
...options
|
|
115
|
+
} = {}) {
|
|
116
|
+
const parsed = new URL(url);
|
|
117
|
+
const isContractLink = parsed.hash.startsWith("#$");
|
|
118
|
+
let link;
|
|
119
|
+
if (isContractLink) {
|
|
120
|
+
if (!contract) {
|
|
121
|
+
throw new Error("Contract options are required for contract based links");
|
|
122
|
+
}
|
|
123
|
+
const keypair = import_ed25519.Ed25519Keypair.fromSecretKey((0, import_utils.fromB64)(parsed.hash.slice(2)));
|
|
124
|
+
link = new _ZkSendLink({
|
|
125
|
+
...options,
|
|
126
|
+
keypair,
|
|
127
|
+
host: `${parsed.protocol}//${parsed.host}`,
|
|
128
|
+
path: parsed.pathname,
|
|
129
|
+
isContractLink: true,
|
|
130
|
+
contract
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
const keypair = import_ed25519.Ed25519Keypair.fromSecretKey(
|
|
134
|
+
(0, import_utils.fromB64)(isContractLink ? parsed.hash.slice(2) : parsed.hash.slice(1))
|
|
135
|
+
);
|
|
136
|
+
link = new _ZkSendLink({
|
|
137
|
+
...options,
|
|
138
|
+
keypair,
|
|
139
|
+
host: `${parsed.protocol}//${parsed.host}`,
|
|
140
|
+
path: parsed.pathname,
|
|
141
|
+
isContractLink: false
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
await link.loadOwnedData();
|
|
145
|
+
return link;
|
|
146
|
+
}
|
|
147
|
+
static async fromAddress(address, options) {
|
|
148
|
+
const link = new _ZkSendLink({
|
|
149
|
+
...options,
|
|
150
|
+
address,
|
|
151
|
+
isContractLink: true
|
|
152
|
+
});
|
|
153
|
+
await link.loadOwnedData();
|
|
154
|
+
return link;
|
|
155
|
+
}
|
|
156
|
+
async loadOwnedData() {
|
|
157
|
+
if (__privateGet(this, _contract)) {
|
|
158
|
+
await __privateMethod(this, _loadBag, loadBag_fn).call(this);
|
|
159
|
+
} else {
|
|
160
|
+
await Promise.all([__privateMethod(this, _loadInitialTransactionData, loadInitialTransactionData_fn).call(this), __privateMethod(this, _loadOwnedObjects, loadOwnedObjects_fn).call(this)]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async listClaimableAssets(address, options) {
|
|
164
|
+
if (!__privateGet(this, _contract)) {
|
|
165
|
+
return __privateMethod(this, _listNonContractClaimableAssets, listNonContractClaimableAssets_fn).call(this, address, options);
|
|
166
|
+
}
|
|
167
|
+
const coins = [];
|
|
168
|
+
const nfts = [];
|
|
169
|
+
for (const object of __privateGet(this, _bagObjects) ?? []) {
|
|
170
|
+
const type = (0, import_utils.parseStructTag)(object.type);
|
|
171
|
+
if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
172
|
+
coins.push(object);
|
|
173
|
+
} else {
|
|
174
|
+
nfts.push(object);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const balances = /* @__PURE__ */ new Map();
|
|
178
|
+
coins.forEach((coin) => {
|
|
179
|
+
if (coin.content?.dataType !== "moveObject") {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const amount = BigInt(coin.content.fields.balance);
|
|
183
|
+
const coinType = (0, import_utils.normalizeStructTag)((0, import_utils.parseStructTag)(coin.content.type).typeParams[0]);
|
|
184
|
+
if (!balances.has(coinType)) {
|
|
185
|
+
balances.set(coinType, { coinType, amount });
|
|
186
|
+
} else {
|
|
187
|
+
balances.get(coinType).amount += amount;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
balances: [...balances.values()],
|
|
192
|
+
nfts,
|
|
193
|
+
coins
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async claimAssets(address, options) {
|
|
197
|
+
if (!__privateGet(this, _keypair)) {
|
|
198
|
+
throw new Error("Cannot claim assets without links keypair");
|
|
199
|
+
}
|
|
200
|
+
const txb = this.createClaimTransaction(address, options);
|
|
201
|
+
if (!__privateGet(this, _contract) || !__privateGet(this, _bagObjects)) {
|
|
202
|
+
return __privateGet(this, _client).signAndExecuteTransactionBlock({
|
|
203
|
+
transactionBlock: txb,
|
|
204
|
+
signer: __privateGet(this, _keypair)
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const { digest } = await __privateMethod(this, _executeSponsoredTransactionBlock, executeSponsoredTransactionBlock_fn).call(this, await __privateMethod(this, _createSponsoredTransactionBlock, createSponsoredTransactionBlock_fn).call(this, txb, address, __privateGet(this, _keypair).toSuiAddress()), __privateGet(this, _keypair));
|
|
208
|
+
return __privateGet(this, _client).waitForTransactionBlock({ digest });
|
|
209
|
+
}
|
|
210
|
+
createClaimTransaction(address, {
|
|
211
|
+
reclaim,
|
|
212
|
+
...options
|
|
213
|
+
} = {}) {
|
|
214
|
+
if (!__privateGet(this, _contract)) {
|
|
215
|
+
return __privateMethod(this, _createNonContractClaimTransaction, createNonContractClaimTransaction_fn).call(this, address, options);
|
|
216
|
+
}
|
|
217
|
+
if (Object.keys(options).length > 0) {
|
|
218
|
+
throw new Error("Filtering claims is not supported for contract based links");
|
|
219
|
+
}
|
|
220
|
+
if (!__privateGet(this, _keypair) && !reclaim) {
|
|
221
|
+
throw new Error("Cannot claim assets without the links keypair");
|
|
222
|
+
}
|
|
223
|
+
const txb = new import_transactions.TransactionBlock();
|
|
224
|
+
const sender = reclaim ? address : __privateGet(this, _keypair).toSuiAddress();
|
|
225
|
+
txb.setSender(sender);
|
|
226
|
+
const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
|
|
227
|
+
const [bag, proof] = reclaim ? __privateGet(this, _contract).reclaim(txb, { arguments: [store, __privateGet(this, _address)] }) : __privateGet(this, _contract).init_claim(txb, { arguments: [store] });
|
|
228
|
+
const objectsToTransfer = [];
|
|
229
|
+
for (const object of __privateGet(this, _bagObjects) ?? []) {
|
|
230
|
+
objectsToTransfer.push(
|
|
231
|
+
__privateGet(this, _contract).claim(txb, {
|
|
232
|
+
arguments: [
|
|
233
|
+
bag,
|
|
234
|
+
proof,
|
|
235
|
+
txb.receivingRef({
|
|
236
|
+
objectId: object.objectId,
|
|
237
|
+
version: object.version,
|
|
238
|
+
digest: object.digest
|
|
239
|
+
})
|
|
240
|
+
],
|
|
241
|
+
typeArguments: [object.type]
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
__privateGet(this, _contract).finalize(txb, { arguments: [bag, proof] });
|
|
246
|
+
if (objectsToTransfer.length > 0) {
|
|
247
|
+
txb.transferObjects(objectsToTransfer, address);
|
|
248
|
+
}
|
|
249
|
+
return txb;
|
|
250
|
+
}
|
|
251
|
+
async createRegenerateTransaction(sender, options = {}) {
|
|
252
|
+
if (!__privateGet(this, _contract) || !__privateGet(this, _bagObjects)) {
|
|
253
|
+
throw new Error("Regenerating non-contract based links is not supported");
|
|
254
|
+
}
|
|
255
|
+
const txb = new import_transactions.TransactionBlock();
|
|
256
|
+
txb.setSender(sender);
|
|
257
|
+
const store = txb.object(__privateGet(this, _contract).ids.bagStoreId);
|
|
258
|
+
const newLinkKp = import_ed25519.Ed25519Keypair.generate();
|
|
259
|
+
const newLink = new import_builder.ZkSendLinkBuilder({
|
|
260
|
+
...options,
|
|
261
|
+
sender,
|
|
262
|
+
client: __privateGet(this, _client),
|
|
263
|
+
contract: __privateGet(this, _contract).ids,
|
|
264
|
+
host: __privateGet(this, _host),
|
|
265
|
+
path: __privateGet(this, _path),
|
|
266
|
+
keypair: newLinkKp
|
|
267
|
+
});
|
|
268
|
+
const to = txb.pure.address(newLinkKp.toSuiAddress());
|
|
269
|
+
__privateGet(this, _contract).update_receiver(txb, { arguments: [store, __privateGet(this, _address), to] });
|
|
270
|
+
return {
|
|
271
|
+
url: newLink.getLink(),
|
|
272
|
+
transactionBlock: txb
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
let ZkSendLink = _ZkSendLink;
|
|
277
|
+
_client = new WeakMap();
|
|
278
|
+
_address = new WeakMap();
|
|
279
|
+
_keypair = new WeakMap();
|
|
280
|
+
_initiallyOwnedObjects = new WeakMap();
|
|
281
|
+
_ownedObjects = new WeakMap();
|
|
282
|
+
_bagObjects = new WeakMap();
|
|
283
|
+
_gasCoin = new WeakMap();
|
|
284
|
+
_hasSui = new WeakMap();
|
|
285
|
+
_creatorAddress = new WeakMap();
|
|
286
|
+
_contract = new WeakMap();
|
|
287
|
+
_claimApi = new WeakMap();
|
|
288
|
+
_network = new WeakMap();
|
|
289
|
+
_host = new WeakMap();
|
|
290
|
+
_path = new WeakMap();
|
|
291
|
+
_loadBag = new WeakSet();
|
|
292
|
+
loadBag_fn = async function() {
|
|
293
|
+
if (!__privateGet(this, _contract)) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const bagField = await __privateGet(this, _client).getDynamicFieldObject({
|
|
297
|
+
parentId: __privateGet(this, _contract).ids.bagStoreTableId,
|
|
298
|
+
name: {
|
|
299
|
+
type: "address",
|
|
300
|
+
value: __privateGet(this, _address)
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
if (!bagField.data) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const itemIds = bagField.data?.content?.fields?.value?.fields?.item_ids.fields.contents;
|
|
307
|
+
if (!itemIds) {
|
|
308
|
+
throw new Error("Invalid bag field");
|
|
309
|
+
}
|
|
310
|
+
const objectsResponse = await __privateGet(this, _client).multiGetObjects({
|
|
311
|
+
ids: itemIds,
|
|
312
|
+
options: {
|
|
313
|
+
showType: true,
|
|
314
|
+
showContent: true
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
__privateSet(this, _bagObjects, objectsResponse.map((object, i) => {
|
|
318
|
+
if (!object.data) {
|
|
319
|
+
throw new Error(`Failed to load claimable object ${itemIds[i]}`);
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
objectId: object.data.objectId,
|
|
323
|
+
type: (0, import_utils.normalizeStructTag)(object.data.type),
|
|
324
|
+
version: object.data.version,
|
|
325
|
+
digest: object.data.digest,
|
|
326
|
+
content: object.data.content
|
|
327
|
+
};
|
|
328
|
+
}));
|
|
329
|
+
};
|
|
330
|
+
_createSponsoredTransactionBlock = new WeakSet();
|
|
331
|
+
createSponsoredTransactionBlock_fn = async function(txb, claimer, sender) {
|
|
332
|
+
return __privateMethod(this, _fetch, fetch_fn).call(this, "transaction-blocks/sponsor", {
|
|
333
|
+
method: "POST",
|
|
334
|
+
body: JSON.stringify({
|
|
335
|
+
network: __privateGet(this, _network),
|
|
336
|
+
sender,
|
|
337
|
+
claimer,
|
|
338
|
+
transactionBlockKindBytes: (0, import_utils.toB64)(
|
|
339
|
+
await txb.build({
|
|
340
|
+
onlyTransactionKind: true,
|
|
341
|
+
client: __privateGet(this, _client),
|
|
342
|
+
// Theses limits will get verified during the final transaction construction, so we can safely ignore them here:
|
|
343
|
+
limits: {
|
|
344
|
+
maxGasObjects: Infinity,
|
|
345
|
+
maxPureArgumentSize: Infinity,
|
|
346
|
+
maxTxGas: Infinity,
|
|
347
|
+
maxTxSizeBytes: Infinity
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
)
|
|
351
|
+
})
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
_executeSponsoredTransactionBlock = new WeakSet();
|
|
355
|
+
executeSponsoredTransactionBlock_fn = async function(input, keypair) {
|
|
356
|
+
return __privateMethod(this, _fetch, fetch_fn).call(this, `transaction-blocks/sponsor/${input.digest}`, {
|
|
357
|
+
method: "POST",
|
|
358
|
+
body: JSON.stringify({
|
|
359
|
+
signature: (await keypair.signTransactionBlock((0, import_utils.fromB64)(input.bytes))).signature
|
|
360
|
+
})
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
_fetch = new WeakSet();
|
|
364
|
+
fetch_fn = async function(path, init) {
|
|
365
|
+
const res = await fetch(`${__privateGet(this, _claimApi)}/v1/${path}`, {
|
|
366
|
+
...init,
|
|
367
|
+
headers: {
|
|
368
|
+
...init.headers,
|
|
369
|
+
"Content-Type": "application/json"
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
if (!res.ok) {
|
|
373
|
+
console.error(await res.text());
|
|
374
|
+
throw new Error(`Request to claim API failed with status code ${res.status}`);
|
|
375
|
+
}
|
|
376
|
+
const { data } = await res.json();
|
|
377
|
+
return data;
|
|
378
|
+
};
|
|
379
|
+
_listNonContractClaimableAssets = new WeakSet();
|
|
380
|
+
listNonContractClaimableAssets_fn = async function(address, options) {
|
|
381
|
+
const normalizedAddress = (0, import_utils.normalizeSuiAddress)(address);
|
|
382
|
+
const txb = this.createClaimTransaction(normalizedAddress, options);
|
|
383
|
+
if (__privateGet(this, _gasCoin) || !__privateGet(this, _hasSui)) {
|
|
384
|
+
txb.setGasPayment([]);
|
|
385
|
+
}
|
|
386
|
+
const dryRun = await __privateGet(this, _client).dryRunTransactionBlock({
|
|
387
|
+
transactionBlock: await txb.build({ client: __privateGet(this, _client) })
|
|
388
|
+
});
|
|
389
|
+
const balances = [];
|
|
390
|
+
const nfts = [];
|
|
391
|
+
const coins = [];
|
|
392
|
+
dryRun.balanceChanges.forEach((balanceChange) => {
|
|
393
|
+
if (BigInt(balanceChange.amount) > 0n && isOwner(balanceChange.owner, normalizedAddress)) {
|
|
394
|
+
balances.push({
|
|
395
|
+
coinType: (0, import_utils.normalizeStructTag)(balanceChange.coinType),
|
|
396
|
+
amount: BigInt(balanceChange.amount)
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
dryRun.objectChanges.forEach((objectChange) => {
|
|
401
|
+
if ("objectType" in objectChange) {
|
|
402
|
+
const type = (0, import_utils.parseStructTag)(objectChange.objectType);
|
|
403
|
+
if (type.address === (0, import_utils.normalizeSuiAddress)("0x2") && type.module === "coin" && type.name === "Coin") {
|
|
404
|
+
if (ownedAfterChange(objectChange, normalizedAddress)) {
|
|
405
|
+
coins.push(objectChange);
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (ownedAfterChange(objectChange, normalizedAddress)) {
|
|
411
|
+
nfts.push(objectChange);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
balances,
|
|
416
|
+
nfts,
|
|
417
|
+
coins
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
_createNonContractClaimTransaction = new WeakSet();
|
|
421
|
+
createNonContractClaimTransaction_fn = function(address, options) {
|
|
422
|
+
if (!__privateGet(this, _keypair)) {
|
|
423
|
+
throw new Error("Cannot claim assets without the links keypair");
|
|
424
|
+
}
|
|
425
|
+
const claimAll = !options?.coinTypes && !options?.objects;
|
|
426
|
+
const txb = new import_transactions.TransactionBlock();
|
|
427
|
+
txb.setSender(__privateGet(this, _keypair).toSuiAddress());
|
|
428
|
+
const coinTypes = new Set(
|
|
429
|
+
options?.coinTypes?.map((type) => (0, import_utils.normalizeStructTag)(`0x2::coin::Coin<${type}>`)) ?? []
|
|
430
|
+
);
|
|
431
|
+
const objectsToTransfer = __privateGet(this, _ownedObjects).filter((object) => {
|
|
432
|
+
if (__privateGet(this, _gasCoin)) {
|
|
433
|
+
if (object.objectId === __privateGet(this, _gasCoin).coinObjectId) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
} else if (object.type === SUI_COIN_OBJECT_TYPE) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
if (coinTypes?.has(object.type) || options?.objects?.includes(object.objectId)) {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
if (!options?.claimObjectsAddedAfterCreation && !__privateGet(this, _initiallyOwnedObjects).has(object.objectId)) {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
return claimAll;
|
|
446
|
+
}).map((object) => txb.object(object.objectId));
|
|
447
|
+
if (__privateGet(this, _gasCoin) && __privateGet(this, _creatorAddress)) {
|
|
448
|
+
txb.transferObjects([txb.gas], __privateGet(this, _creatorAddress));
|
|
449
|
+
} else if (claimAll || coinTypes?.has(SUI_COIN_TYPE)) {
|
|
450
|
+
objectsToTransfer.push(txb.gas);
|
|
451
|
+
}
|
|
452
|
+
if (objectsToTransfer.length > 0) {
|
|
453
|
+
txb.transferObjects(objectsToTransfer, address);
|
|
454
|
+
}
|
|
455
|
+
return txb;
|
|
456
|
+
};
|
|
457
|
+
_loadOwnedObjects = new WeakSet();
|
|
458
|
+
loadOwnedObjects_fn = async function() {
|
|
459
|
+
__privateSet(this, _ownedObjects, []);
|
|
460
|
+
let nextCursor;
|
|
461
|
+
do {
|
|
462
|
+
const ownedObjects = await __privateGet(this, _client).getOwnedObjects({
|
|
463
|
+
cursor: nextCursor,
|
|
464
|
+
owner: __privateGet(this, _address),
|
|
465
|
+
options: {
|
|
466
|
+
showType: true
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
nextCursor = ownedObjects.hasNextPage ? ownedObjects.nextCursor : null;
|
|
470
|
+
for (const object of ownedObjects.data) {
|
|
471
|
+
if (object.data) {
|
|
472
|
+
__privateGet(this, _ownedObjects).push({
|
|
473
|
+
objectId: (0, import_utils.normalizeSuiObjectId)(object.data.objectId),
|
|
474
|
+
version: object.data.version,
|
|
475
|
+
digest: object.data.digest,
|
|
476
|
+
type: (0, import_utils.normalizeStructTag)(object.data.type)
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
} while (nextCursor);
|
|
481
|
+
const coins = await __privateGet(this, _client).getCoins({
|
|
482
|
+
coinType: SUI_COIN_TYPE,
|
|
483
|
+
owner: __privateGet(this, _address)
|
|
484
|
+
});
|
|
485
|
+
__privateSet(this, _hasSui, coins.data.length > 0);
|
|
486
|
+
__privateSet(this, _gasCoin, coins.data.find((coin) => BigInt(coin.balance) % 1000n === 987n));
|
|
487
|
+
};
|
|
488
|
+
_loadInitialTransactionData = new WeakSet();
|
|
489
|
+
loadInitialTransactionData_fn = async function() {
|
|
490
|
+
const result = await __privateGet(this, _client).queryTransactionBlocks({
|
|
491
|
+
limit: 1,
|
|
492
|
+
order: "ascending",
|
|
493
|
+
filter: {
|
|
494
|
+
ToAddress: __privateGet(this, _address)
|
|
495
|
+
},
|
|
496
|
+
options: {
|
|
497
|
+
showObjectChanges: true,
|
|
498
|
+
showInput: true
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
result.data[0]?.objectChanges?.forEach((objectChange) => {
|
|
502
|
+
if (ownedAfterChange(objectChange, __privateGet(this, _address))) {
|
|
503
|
+
__privateGet(this, _initiallyOwnedObjects).add((0, import_utils.normalizeSuiObjectId)(objectChange.objectId));
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
__privateSet(this, _creatorAddress, result.data[0]?.transaction?.data.sender);
|
|
507
|
+
};
|
|
508
|
+
function ownedAfterChange(objectChange, address) {
|
|
509
|
+
if (objectChange.type === "transferred" && isOwner(objectChange.recipient, address)) {
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
if ((objectChange.type === "created" || objectChange.type === "mutated") && isOwner(objectChange.owner, address)) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
function isOwner(owner, address) {
|
|
518
|
+
return owner && typeof owner === "object" && "AddressOwner" in owner && (0, import_utils.normalizeSuiAddress)(owner.AddressOwner) === address;
|
|
519
|
+
}
|
|
520
|
+
//# sourceMappingURL=claim.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/links/claim.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 {\n\tCoinStruct,\n\tObjectOwner,\n\tSuiObjectChange,\n\tSuiParsedData,\n} from '@mysten/sui.js/client';\nimport type { Keypair } from '@mysten/sui.js/cryptography';\nimport { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';\nimport { TransactionBlock } from '@mysten/sui.js/transactions';\nimport {\n\tfromB64,\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tnormalizeSuiObjectId,\n\tparseStructTag,\n\tSUI_TYPE_ARG,\n\ttoB64,\n} from '@mysten/sui.js/utils';\n\nimport type { ZkSendLinkBuilderOptions } from './builder.js';\nimport { ZkSendLinkBuilder } from './builder.js';\nimport type { ZkBagContractOptions } from './zk-bag.js';\nimport { ZkBag } from './zk-bag.js';\n\nconst DEFAULT_ZK_SEND_LINK_OPTIONS = {\n\thost: 'https://zksend.com',\n\tpath: '/claim',\n\tnetwork: 'mainnet' as const,\n\tclaimApi: 'https://zksend.com/api',\n};\n\nconst SUI_COIN_TYPE = normalizeStructTag(SUI_TYPE_ARG);\nconst SUI_COIN_OBJECT_TYPE = normalizeStructTag('0x2::coin::Coin<0x2::sui::SUI>');\n\nexport type ZkSendLinkOptions = {\n\tclaimApi?: string;\n\tkeypair?: Keypair;\n\tclient?: SuiClient;\n\tnetwork?: 'mainnet' | 'testnet';\n\thost?: string;\n\tpath?: string;\n\taddress?: string;\n} & (\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) &\n\t(\n\t\t| {\n\t\t\t\tisContractLink: true;\n\t\t\t\tcontract: ZkBagContractOptions;\n\t\t }\n\t\t| {\n\t\t\t\tisContractLink: false;\n\t\t\t\tcontract?: never;\n\t\t }\n\t);\n\nexport class ZkSendLink {\n\t#client: SuiClient;\n\t#address: string;\n\t#keypair?: Keypair;\n\t#initiallyOwnedObjects = new Set<string>();\n\t#ownedObjects: Array<{\n\t\tobjectId: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t\ttype: string;\n\t}> = [];\n\t#bagObjects: Array<{\n\t\tobjectId: string;\n\t\ttype: string;\n\t\tversion: string;\n\t\tdigest: string;\n\t\tcontent: SuiParsedData;\n\t}> | null = null;\n\t#gasCoin?: CoinStruct;\n\t#hasSui = false;\n\t#creatorAddress?: string;\n\t#contract?: ZkBag<ZkBagContractOptions>;\n\t#claimApi: string;\n\t#network: 'mainnet' | 'testnet';\n\t#host?: string;\n\t#path?: string;\n\n\tconstructor({\n\t\tnetwork = DEFAULT_ZK_SEND_LINK_OPTIONS.network,\n\t\tclaimApi = DEFAULT_ZK_SEND_LINK_OPTIONS.claimApi,\n\t\tclient = new SuiClient({ url: getFullnodeUrl(network) }),\n\t\tkeypair,\n\t\tcontract,\n\t\taddress,\n\t\thost,\n\t\tpath,\n\t\tisContractLink,\n\t}: ZkSendLinkOptions) {\n\t\tif (!keypair && !address) {\n\t\t\tthrow new Error('Either keypair or address must be provided');\n\t\t}\n\n\t\tthis.#client = client;\n\t\tthis.#keypair = keypair;\n\t\tthis.#address = address ?? keypair!.toSuiAddress();\n\t\tthis.#claimApi = claimApi;\n\t\tthis.#network = network;\n\t\tthis.#host = host;\n\t\tthis.#path = path;\n\n\t\tif (isContractLink) {\n\t\t\tif (!contract) {\n\t\t\t\tthrow new Error('Contract options are required for contract based links');\n\t\t\t}\n\n\t\t\tthis.#contract = new ZkBag(contract.packageId, contract);\n\t\t}\n\t}\n\n\tstatic async fromUrl(\n\t\turl: string,\n\t\t{\n\t\t\tcontract,\n\t\t\t...options\n\t\t}: Omit<ZkSendLinkOptions, 'keypair' | 'address' | 'isContractLink'> = {},\n\t) {\n\t\tconst parsed = new URL(url);\n\t\tconst isContractLink = parsed.hash.startsWith('#$');\n\n\t\tlet link: ZkSendLink;\n\t\tif (isContractLink) {\n\t\t\tif (!contract) {\n\t\t\t\tthrow new Error('Contract options are required for contract based links');\n\t\t\t}\n\n\t\t\tconst keypair = Ed25519Keypair.fromSecretKey(fromB64(parsed.hash.slice(2)));\n\t\t\tlink = new ZkSendLink({\n\t\t\t\t...options,\n\t\t\t\tkeypair,\n\t\t\t\thost: `${parsed.protocol}//${parsed.host}`,\n\t\t\t\tpath: parsed.pathname,\n\t\t\t\tisContractLink: true,\n\t\t\t\tcontract,\n\t\t\t});\n\t\t} else {\n\t\t\tconst keypair = Ed25519Keypair.fromSecretKey(\n\t\t\t\tfromB64(isContractLink ? parsed.hash.slice(2) : parsed.hash.slice(1)),\n\t\t\t);\n\n\t\t\tlink = new ZkSendLink({\n\t\t\t\t...options,\n\t\t\t\tkeypair,\n\t\t\t\thost: `${parsed.protocol}//${parsed.host}`,\n\t\t\t\tpath: parsed.pathname,\n\t\t\t\tisContractLink: false,\n\t\t\t});\n\t\t}\n\n\t\tawait link.loadOwnedData();\n\n\t\treturn link;\n\t}\n\n\tstatic async fromAddress(\n\t\taddress: string,\n\t\toptions: Omit<ZkSendLinkOptions, 'keypair' | 'address' | 'isContractLink'> & {\n\t\t\tcontract: ZkBagContractOptions;\n\t\t},\n\t) {\n\t\tconst link = new ZkSendLink({\n\t\t\t...options,\n\t\t\taddress,\n\t\t\tisContractLink: true,\n\t\t});\n\n\t\tawait link.loadOwnedData();\n\n\t\treturn link;\n\t}\n\n\tasync loadOwnedData() {\n\t\tif (this.#contract) {\n\t\t\tawait this.#loadBag();\n\t\t} else {\n\t\t\tawait Promise.all([this.#loadInitialTransactionData(), this.#loadOwnedObjects()]);\n\t\t}\n\t}\n\n\tasync listClaimableAssets(\n\t\taddress: string,\n\t\toptions?: {\n\t\t\tclaimObjectsAddedAfterCreation?: boolean;\n\t\t\tcoinTypes?: string[];\n\t\t\tobjects?: string[];\n\t\t},\n\t) {\n\t\tif (!this.#contract) {\n\t\t\treturn this.#listNonContractClaimableAssets(address, options);\n\t\t}\n\n\t\tconst coins = [];\n\n\t\tconst nfts: {\n\t\t\tobjectId: string;\n\t\t\ttype: string;\n\t\t\tversion: string;\n\t\t\tdigest: string;\n\t\t}[] = [];\n\n\t\tfor (const object of this.#bagObjects ?? []) {\n\t\t\tconst type = parseStructTag(object.type);\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\tcoins.push(object);\n\t\t\t} else {\n\t\t\t\tnfts.push(object);\n\t\t\t}\n\t\t}\n\n\t\tconst balances = new Map<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tcoinType: string;\n\t\t\t\tamount: bigint;\n\t\t\t}\n\t\t>();\n\n\t\tcoins.forEach((coin) => {\n\t\t\tif (coin.content?.dataType !== 'moveObject') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst amount = BigInt((coin.content.fields as Record<string, string>).balance);\n\t\t\tconst coinType = normalizeStructTag(parseStructTag(coin.content.type).typeParams[0]);\n\n\t\t\tif (!balances.has(coinType)) {\n\t\t\t\tbalances.set(coinType, { coinType, amount });\n\t\t\t} else {\n\t\t\t\tbalances.get(coinType)!.amount += amount;\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tbalances: [...balances.values()],\n\t\t\tnfts,\n\t\t\tcoins,\n\t\t};\n\t}\n\n\tasync claimAssets(\n\t\taddress: string,\n\t\t/** @deprecated filtering claims is not supported in contract based links */\n\t\toptions?: {\n\t\t\tclaimObjectsAddedAfterCreation?: boolean;\n\t\t\tcoinTypes?: string[];\n\t\t\tobjects?: string[];\n\t\t},\n\t) {\n\t\tif (!this.#keypair) {\n\t\t\tthrow new Error('Cannot claim assets without links keypair');\n\t\t}\n\n\t\tconst txb = this.createClaimTransaction(address, options);\n\t\tif (!this.#contract || !this.#bagObjects) {\n\t\t\treturn this.#client.signAndExecuteTransactionBlock({\n\t\t\t\ttransactionBlock: txb,\n\t\t\t\tsigner: this.#keypair,\n\t\t\t});\n\t\t}\n\n\t\tconst { digest } = await this.#executeSponsoredTransactionBlock(\n\t\t\tawait this.#createSponsoredTransactionBlock(txb, address, this.#keypair.toSuiAddress()),\n\t\t\tthis.#keypair,\n\t\t);\n\n\t\treturn this.#client.waitForTransactionBlock({ digest });\n\t}\n\n\tcreateClaimTransaction(\n\t\taddress: string,\n\t\t{\n\t\t\treclaim,\n\t\t\t...options\n\t\t}: {\n\t\t\t/** @deprecated filtering claims is not supported in contract based links */\n\t\t\tclaimObjectsAddedAfterCreation?: boolean;\n\t\t\t/** @deprecated filtering claims is not supported in contract based links */\n\t\t\tcoinTypes?: string[];\n\t\t\t/** @deprecated filtering claims is not supported in contract based links */\n\t\t\tobjects?: string[];\n\t\t\treclaim?: boolean;\n\t\t} = {},\n\t) {\n\t\tif (!this.#contract) {\n\t\t\treturn this.#createNonContractClaimTransaction(address, options);\n\t\t}\n\n\t\tif (Object.keys(options).length > 0) {\n\t\t\tthrow new Error('Filtering claims is not supported for contract based links');\n\t\t}\n\n\t\tif (!this.#keypair && !reclaim) {\n\t\t\tthrow new Error('Cannot claim assets without the links keypair');\n\t\t}\n\n\t\tconst txb = new TransactionBlock();\n\t\tconst sender = reclaim ? address : this.#keypair!.toSuiAddress();\n\t\ttxb.setSender(sender);\n\n\t\tconst store = txb.object(this.#contract.ids.bagStoreId);\n\n\t\tconst [bag, proof] = reclaim\n\t\t\t? this.#contract.reclaim(txb, { arguments: [store, this.#address] })\n\t\t\t: this.#contract.init_claim(txb, { arguments: [store] });\n\n\t\tconst objectsToTransfer = [];\n\n\t\tfor (const object of this.#bagObjects ?? []) {\n\t\t\tobjectsToTransfer.push(\n\t\t\t\tthis.#contract.claim(txb, {\n\t\t\t\t\targuments: [\n\t\t\t\t\t\tbag,\n\t\t\t\t\t\tproof,\n\t\t\t\t\t\ttxb.receivingRef({\n\t\t\t\t\t\t\tobjectId: object.objectId,\n\t\t\t\t\t\t\tversion: object.version,\n\t\t\t\t\t\t\tdigest: object.digest,\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\ttypeArguments: [object.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tthis.#contract.finalize(txb, { arguments: [bag, proof] });\n\t\tif (objectsToTransfer.length > 0) {\n\t\t\ttxb.transferObjects(objectsToTransfer, address);\n\t\t}\n\n\t\treturn txb;\n\t}\n\n\tasync createRegenerateTransaction(\n\t\tsender: string,\n\t\toptions: Omit<ZkSendLinkBuilderOptions, 'sender'> = {},\n\t) {\n\t\tif (!this.#contract || !this.#bagObjects) {\n\t\t\tthrow new Error('Regenerating non-contract based links is not supported');\n\t\t}\n\n\t\tconst txb = new TransactionBlock();\n\t\ttxb.setSender(sender);\n\n\t\tconst store = txb.object(this.#contract.ids.bagStoreId);\n\n\t\tconst newLinkKp = Ed25519Keypair.generate();\n\n\t\tconst newLink = new ZkSendLinkBuilder({\n\t\t\t...options,\n\t\t\tsender,\n\t\t\tclient: this.#client,\n\t\t\tcontract: this.#contract.ids,\n\t\t\thost: this.#host,\n\t\t\tpath: this.#path,\n\t\t\tkeypair: newLinkKp,\n\t\t});\n\n\t\tconst to = txb.pure.address(newLinkKp.toSuiAddress());\n\n\t\tthis.#contract.update_receiver(txb, { arguments: [store, this.#address, to] });\n\n\t\treturn {\n\t\t\turl: newLink.getLink(),\n\t\t\ttransactionBlock: txb,\n\t\t};\n\t}\n\n\tasync #loadBag() {\n\t\tif (!this.#contract) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bagField = await this.#client.getDynamicFieldObject({\n\t\t\tparentId: this.#contract.ids.bagStoreTableId,\n\t\t\tname: {\n\t\t\t\ttype: 'address',\n\t\t\t\tvalue: this.#address,\n\t\t\t},\n\t\t});\n\n\t\tif (!bagField.data) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst itemIds: string[] | undefined = (bagField as any).data?.content?.fields?.value?.fields\n\t\t\t?.item_ids.fields.contents;\n\n\t\tif (!itemIds) {\n\t\t\tthrow new Error('Invalid bag field');\n\t\t}\n\n\t\tconst objectsResponse = await this.#client.multiGetObjects({\n\t\t\tids: itemIds,\n\t\t\toptions: {\n\t\t\t\tshowType: true,\n\t\t\t\tshowContent: true,\n\t\t\t},\n\t\t});\n\n\t\tthis.#bagObjects = objectsResponse.map((object, i) => {\n\t\t\tif (!object.data) {\n\t\t\t\tthrow new Error(`Failed to load claimable object ${itemIds[i]}`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tobjectId: object.data.objectId,\n\t\t\t\ttype: normalizeStructTag(object.data.type!),\n\t\t\t\tversion: object.data.version,\n\t\t\t\tdigest: object.data.digest,\n\t\t\t\tcontent: object.data.content!,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync #createSponsoredTransactionBlock(txb: TransactionBlock, claimer: string, sender: string) {\n\t\treturn this.#fetch<{ digest: string; bytes: string }>('transaction-blocks/sponsor', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tsender,\n\t\t\t\tclaimer,\n\t\t\t\ttransactionBlockKindBytes: toB64(\n\t\t\t\t\tawait txb.build({\n\t\t\t\t\t\tonlyTransactionKind: true,\n\t\t\t\t\t\tclient: this.#client,\n\t\t\t\t\t\t// Theses limits will get verified during the final transaction construction, so we can safely ignore them here:\n\t\t\t\t\t\tlimits: {\n\t\t\t\t\t\t\tmaxGasObjects: Infinity,\n\t\t\t\t\t\t\tmaxPureArgumentSize: Infinity,\n\t\t\t\t\t\t\tmaxTxGas: Infinity,\n\t\t\t\t\t\t\tmaxTxSizeBytes: Infinity,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #executeSponsoredTransactionBlock(\n\t\tinput: { digest: string; bytes: string },\n\t\tkeypair: Keypair,\n\t) {\n\t\treturn this.#fetch<{ digest: string }>(`transaction-blocks/sponsor/${input.digest}`, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({\n\t\t\t\tsignature: (await keypair.signTransactionBlock(fromB64(input.bytes))).signature,\n\t\t\t}),\n\t\t});\n\t}\n\n\tasync #fetch<T = unknown>(path: string, init: RequestInit): Promise<T> {\n\t\tconst res = await fetch(`${this.#claimApi}/v1/${path}`, {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\t...init.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tconsole.error(await res.text());\n\t\t\tthrow new Error(`Request to claim API failed with status code ${res.status}`);\n\t\t}\n\n\t\tconst { data } = await res.json();\n\n\t\treturn data as T;\n\t}\n\n\tasync #listNonContractClaimableAssets(\n\t\taddress: string,\n\t\toptions?: {\n\t\t\tclaimObjectsAddedAfterCreation?: boolean;\n\t\t\tcoinTypes?: string[];\n\t\t\tobjects?: string[];\n\t\t},\n\t) {\n\t\tconst normalizedAddress = normalizeSuiAddress(address);\n\t\tconst txb = this.createClaimTransaction(normalizedAddress, options);\n\n\t\tif (this.#gasCoin || !this.#hasSui) {\n\t\t\ttxb.setGasPayment([]);\n\t\t}\n\n\t\tconst dryRun = await this.#client.dryRunTransactionBlock({\n\t\t\ttransactionBlock: await txb.build({ client: this.#client }),\n\t\t});\n\n\t\tconst balances: {\n\t\t\tcoinType: string;\n\t\t\tamount: bigint;\n\t\t}[] = [];\n\n\t\tconst nfts: {\n\t\t\tobjectId: string;\n\t\t\ttype: string;\n\t\t\tversion: string;\n\t\t\tdigest: string;\n\t\t}[] = [];\n\n\t\tconst coins: {\n\t\t\tobjectId: string;\n\t\t\ttype: string;\n\t\t\tversion: string;\n\t\t\tdigest: string;\n\t\t}[] = [];\n\n\t\tdryRun.balanceChanges.forEach((balanceChange) => {\n\t\t\tif (BigInt(balanceChange.amount) > 0n && isOwner(balanceChange.owner, normalizedAddress)) {\n\t\t\t\tbalances.push({\n\t\t\t\t\tcoinType: normalizeStructTag(balanceChange.coinType),\n\t\t\t\t\tamount: BigInt(balanceChange.amount),\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tdryRun.objectChanges.forEach((objectChange) => {\n\t\t\tif ('objectType' in objectChange) {\n\t\t\t\tconst type = parseStructTag(objectChange.objectType);\n\n\t\t\t\tif (\n\t\t\t\t\ttype.address === normalizeSuiAddress('0x2') &&\n\t\t\t\t\ttype.module === 'coin' &&\n\t\t\t\t\ttype.name === 'Coin'\n\t\t\t\t) {\n\t\t\t\t\tif (ownedAfterChange(objectChange, normalizedAddress)) {\n\t\t\t\t\t\tcoins.push(objectChange);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ownedAfterChange(objectChange, normalizedAddress)) {\n\t\t\t\tnfts.push(objectChange);\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tbalances,\n\t\t\tnfts,\n\t\t\tcoins,\n\t\t};\n\t}\n\n\t#createNonContractClaimTransaction(\n\t\taddress: string,\n\t\toptions?: {\n\t\t\tclaimObjectsAddedAfterCreation?: boolean;\n\t\t\tcoinTypes?: string[];\n\t\t\tobjects?: string[];\n\t\t},\n\t) {\n\t\tif (!this.#keypair) {\n\t\t\tthrow new Error('Cannot claim assets without the links keypair');\n\t\t}\n\n\t\tconst claimAll = !options?.coinTypes && !options?.objects;\n\t\tconst txb = new TransactionBlock();\n\t\ttxb.setSender(this.#keypair.toSuiAddress());\n\t\tconst coinTypes = new Set(\n\t\t\toptions?.coinTypes?.map((type) => normalizeStructTag(`0x2::coin::Coin<${type}>`)) ?? [],\n\t\t);\n\n\t\tconst objectsToTransfer = this.#ownedObjects\n\t\t\t.filter((object) => {\n\t\t\t\tif (this.#gasCoin) {\n\t\t\t\t\tif (object.objectId === this.#gasCoin.coinObjectId) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} else if (object.type === SUI_COIN_OBJECT_TYPE) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (coinTypes?.has(object.type) || options?.objects?.includes(object.objectId)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t!options?.claimObjectsAddedAfterCreation &&\n\t\t\t\t\t!this.#initiallyOwnedObjects.has(object.objectId)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\treturn claimAll;\n\t\t\t})\n\t\t\t.map((object) => txb.object(object.objectId));\n\n\t\tif (this.#gasCoin && this.#creatorAddress) {\n\t\t\ttxb.transferObjects([txb.gas], this.#creatorAddress);\n\t\t} else if (claimAll || coinTypes?.has(SUI_COIN_TYPE)) {\n\t\t\tobjectsToTransfer.push(txb.gas);\n\t\t}\n\n\t\tif (objectsToTransfer.length > 0) {\n\t\t\ttxb.transferObjects(objectsToTransfer, address);\n\t\t}\n\n\t\treturn txb;\n\t}\n\n\tasync #loadOwnedObjects() {\n\t\tthis.#ownedObjects = [];\n\t\tlet nextCursor: string | null | undefined;\n\t\tdo {\n\t\t\tconst ownedObjects = await this.#client.getOwnedObjects({\n\t\t\t\tcursor: nextCursor,\n\t\t\t\towner: this.#address,\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\t// RPC response returns cursor even if there are no more pages\n\t\t\tnextCursor = ownedObjects.hasNextPage ? ownedObjects.nextCursor : null;\n\t\t\tfor (const object of ownedObjects.data) {\n\t\t\t\tif (object.data) {\n\t\t\t\t\tthis.#ownedObjects.push({\n\t\t\t\t\t\tobjectId: normalizeSuiObjectId(object.data.objectId),\n\t\t\t\t\t\tversion: object.data.version,\n\t\t\t\t\t\tdigest: object.data.digest,\n\t\t\t\t\t\ttype: normalizeStructTag(object.data.type!),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} while (nextCursor);\n\n\t\tconst coins = await this.#client.getCoins({\n\t\t\tcoinType: SUI_COIN_TYPE,\n\t\t\towner: this.#address,\n\t\t});\n\n\t\tthis.#hasSui = coins.data.length > 0;\n\t\tthis.#gasCoin = coins.data.find((coin) => BigInt(coin.balance) % 1000n === 987n);\n\t}\n\n\tasync #loadInitialTransactionData() {\n\t\tconst result = await this.#client.queryTransactionBlocks({\n\t\t\tlimit: 1,\n\t\t\torder: 'ascending',\n\t\t\tfilter: {\n\t\t\t\tToAddress: this.#address,\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tshowObjectChanges: true,\n\t\t\t\tshowInput: true,\n\t\t\t},\n\t\t});\n\n\t\tresult.data[0]?.objectChanges?.forEach((objectChange) => {\n\t\t\tif (ownedAfterChange(objectChange, this.#address)) {\n\t\t\t\tthis.#initiallyOwnedObjects.add(normalizeSuiObjectId(objectChange.objectId));\n\t\t\t}\n\t\t});\n\n\t\tthis.#creatorAddress = result.data[0]?.transaction?.data.sender;\n\t}\n}\n\nfunction 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\nfunction 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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AAO;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,MACP,WAAW,mBAAK;AAAA,IACjB;AAAA,IACA,SAAS;AAAA,MACR,mBAAmB;AAAA,MACnB,WAAW;AAAA,IACZ;AAAA,EACD,CAAC;AAED,SAAO,KAAK,CAAC,GAAG,eAAe,QAAQ,CAAC,iBAAiB;AACxD,QAAI,iBAAiB,cAAc,mBAAK,SAAQ,GAAG;AAClD,yBAAK,wBAAuB,QAAI,mCAAqB,aAAa,QAAQ,CAAC;AAAA,IAC5E;AAAA,EACD,CAAC;AAED,qBAAK,iBAAkB,OAAO,KAAK,CAAC,GAAG,aAAa,KAAK;AAC1D;AAGD,SAAS,iBACR,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;AAEA,SAAS,QAAQ,OAAoB,SAAoD;AACxF,SACC,SACA,OAAO,UAAU,YACjB,kBAAkB,aAClB,kCAAoB,MAAM,YAAY,MAAM;AAE9C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '@mysten/sui.js/graphql/schemas/2024-01';
|
|
2
|
+
import type { SuiClient } from '@mysten/sui.js/client';
|
|
3
|
+
import { ZkSendLink } from './claim.js';
|
|
4
|
+
import type { ZkBagContractOptions } from './zk-bag.js';
|
|
5
|
+
export declare function listCreatedLinks({ address, cursor, network, contract, ...linkOptions }: {
|
|
6
|
+
address: string;
|
|
7
|
+
contract: ZkBagContractOptions;
|
|
8
|
+
cursor?: string;
|
|
9
|
+
network?: 'mainnet' | 'testnet';
|
|
10
|
+
host?: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
client?: SuiClient;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
cursor: string | null;
|
|
15
|
+
hasNextPage: boolean;
|
|
16
|
+
links: ZkSendLink[];
|
|
17
|
+
}>;
|