@0xobelisk/sui-client 0.5.2 → 0.5.4
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/dist/index.d.ts +3 -1
- package/dist/index.js +343 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +331 -245
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +15 -0
- package/dist/libs/multiSig/index.d.ts +1 -0
- package/dist/libs/multiSig/publickey.d.ts +2 -0
- package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
- package/dist/libs/suiAccountManager/index.d.ts +1 -1
- package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
- package/dist/libs/suiAccountManager/util.d.ts +29 -0
- package/dist/libs/suiContractFactory/index.d.ts +20 -0
- package/dist/libs/suiContractFactory/types.d.ts +49 -0
- package/dist/libs/suiInteractor/index.d.ts +0 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +17 -177
- package/dist/libs/suiInteractor/util.d.ts +1 -0
- package/dist/libs/suiModel/index.d.ts +2 -0
- package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
- package/dist/libs/suiModel/suiSharedObject.d.ts +11 -0
- package/dist/libs/suiTxBuilder/index.d.ts +178 -374
- package/dist/libs/suiTxBuilder/util.d.ts +41 -59
- package/dist/metadata/index.d.ts +2 -33
- package/dist/obelisk.d.ts +20 -2454
- package/dist/types/index.d.ts +29 -7
- package/dist/utils/index.d.ts +3 -0
- package/package.json +22 -19
- package/src/index.ts +3 -1
- package/src/libs/multiSig/client.ts +44 -0
- package/src/libs/multiSig/index.ts +1 -0
- package/src/libs/multiSig/publickey.ts +11 -0
- package/src/libs/suiAccountManager/index.ts +1 -1
- package/src/libs/suiAccountManager/keypair.ts +1 -1
- package/src/libs/suiAccountManager/util.ts +1 -1
- package/src/libs/suiContractFactory/index.ts +1 -1
- package/src/libs/suiContractFactory/types.ts +2 -2
- package/src/libs/suiInteractor/index.ts +1 -1
- package/src/libs/suiInteractor/suiInteractor.ts +106 -111
- package/src/libs/suiModel/suiOwnedObject.ts +5 -10
- package/src/libs/suiModel/suiSharedObject.ts +4 -7
- package/src/libs/suiTxBuilder/index.ts +146 -100
- package/src/libs/suiTxBuilder/util.ts +145 -31
- package/src/metadata/index.ts +5 -3
- package/src/obelisk.ts +52 -37
- package/src/types/index.ts +54 -25
- package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
- package/src/libs/suiInteractor/defaultConfig.ts +0 -32
package/dist/index.js
CHANGED
|
@@ -44,28 +44,31 @@ var __privateAdd = (obj, member, value) => {
|
|
|
44
44
|
// src/index.ts
|
|
45
45
|
var src_exports = {};
|
|
46
46
|
__export(src_exports, {
|
|
47
|
-
BCS: () =>
|
|
48
|
-
Ed25519Keypair: () =>
|
|
47
|
+
BCS: () => import_bcs4.BCS,
|
|
48
|
+
Ed25519Keypair: () => import_ed255194.Ed25519Keypair,
|
|
49
|
+
MultiSigClient: () => MultiSigClient,
|
|
49
50
|
Obelisk: () => Obelisk,
|
|
50
51
|
SuiAccountManager: () => SuiAccountManager,
|
|
51
52
|
SuiContractFactory: () => SuiContractFactory,
|
|
52
53
|
SuiTxBlock: () => SuiTxBlock,
|
|
53
|
-
getSuiMoveConfig: () =>
|
|
54
|
+
getSuiMoveConfig: () => import_bcs4.getSuiMoveConfig,
|
|
54
55
|
loadMetadata: () => loadMetadata
|
|
55
56
|
});
|
|
56
57
|
module.exports = __toCommonJS(src_exports);
|
|
57
|
-
__reExport(src_exports, require("@mysten/sui.js"), module.exports);
|
|
58
|
-
|
|
59
|
-
var
|
|
58
|
+
__reExport(src_exports, require("@mysten/sui.js/utils"), module.exports);
|
|
59
|
+
__reExport(src_exports, require("@mysten/sui.js/transactions"), module.exports);
|
|
60
|
+
var import_ed255194 = require("@mysten/sui.js/keypairs/ed25519");
|
|
61
|
+
var import_bcs4 = require("@mysten/bcs");
|
|
60
62
|
|
|
61
63
|
// src/obelisk.ts
|
|
62
|
-
var
|
|
64
|
+
var import_client2 = require("@mysten/sui.js/client");
|
|
65
|
+
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
63
66
|
|
|
64
67
|
// src/libs/suiAccountManager/index.ts
|
|
65
|
-
var
|
|
68
|
+
var import_ed255192 = require("@mysten/sui.js/keypairs/ed25519");
|
|
66
69
|
|
|
67
70
|
// src/libs/suiAccountManager/keypair.ts
|
|
68
|
-
var
|
|
71
|
+
var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
|
|
69
72
|
var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
70
73
|
const {
|
|
71
74
|
accountIndex = 0,
|
|
@@ -76,11 +79,11 @@ var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
|
76
79
|
};
|
|
77
80
|
var getKeyPair = (mnemonics, derivePathParams = {}) => {
|
|
78
81
|
const derivePath = getDerivePathForSUI(derivePathParams);
|
|
79
|
-
return
|
|
82
|
+
return import_ed25519.Ed25519Keypair.deriveKeypair(mnemonics, derivePath);
|
|
80
83
|
};
|
|
81
84
|
|
|
82
85
|
// src/libs/suiAccountManager/util.ts
|
|
83
|
-
var
|
|
86
|
+
var import_utils = require("@mysten/sui.js/utils");
|
|
84
87
|
var isHex = (str) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
|
|
85
88
|
var isBase64 = (str) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);
|
|
86
89
|
var fromHEX = (hexStr) => {
|
|
@@ -97,7 +100,7 @@ var hexOrBase64ToUint8Array = (str) => {
|
|
|
97
100
|
if (isHex(str)) {
|
|
98
101
|
return fromHEX(str);
|
|
99
102
|
} else if (isBase64(str)) {
|
|
100
|
-
return (0,
|
|
103
|
+
return (0, import_utils.fromB64)(str);
|
|
101
104
|
} else {
|
|
102
105
|
throw new Error("The string is not a valid hex or base64 string.");
|
|
103
106
|
}
|
|
@@ -140,7 +143,7 @@ var SuiAccountManager = class {
|
|
|
140
143
|
if (!this.mnemonics && !this.secretKey) {
|
|
141
144
|
this.mnemonics = generateMnemonic(24);
|
|
142
145
|
}
|
|
143
|
-
this.currentKeyPair = this.secretKey ?
|
|
146
|
+
this.currentKeyPair = this.secretKey ? import_ed255192.Ed25519Keypair.fromSecretKey(
|
|
144
147
|
normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))
|
|
145
148
|
) : getKeyPair(this.mnemonics);
|
|
146
149
|
this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();
|
|
@@ -178,61 +181,118 @@ var SuiAccountManager = class {
|
|
|
178
181
|
};
|
|
179
182
|
|
|
180
183
|
// src/libs/suiTxBuilder/index.ts
|
|
181
|
-
var
|
|
184
|
+
var import_transactions2 = require("@mysten/sui.js/transactions");
|
|
185
|
+
var import_utils3 = require("@mysten/sui.js/utils");
|
|
182
186
|
|
|
183
187
|
// src/libs/suiTxBuilder/util.ts
|
|
184
|
-
var
|
|
188
|
+
var import_utils2 = require("@mysten/sui.js/utils");
|
|
189
|
+
var import_transactions = require("@mysten/sui.js/transactions");
|
|
190
|
+
var import_bcs = require("@mysten/sui.js/bcs");
|
|
191
|
+
var import_bcs2 = require("@mysten/bcs");
|
|
185
192
|
var getDefaultSuiInputType = (value) => {
|
|
186
|
-
if (typeof value === "string" &&
|
|
193
|
+
if (typeof value === "string" && (0, import_utils2.isValidSuiObjectId)(value)) {
|
|
187
194
|
return "object";
|
|
188
195
|
} else if (typeof value === "number" || typeof value === "bigint") {
|
|
189
196
|
return "u64";
|
|
190
197
|
} else if (typeof value === "boolean") {
|
|
191
198
|
return "bool";
|
|
192
199
|
} else {
|
|
193
|
-
return
|
|
200
|
+
return void 0;
|
|
194
201
|
}
|
|
195
202
|
};
|
|
196
203
|
function makeVecParam(txBlock, args, type) {
|
|
197
204
|
if (args.length === 0)
|
|
198
205
|
throw new Error("Transaction builder error: Empty array is not allowed");
|
|
199
206
|
const defaultSuiType = getDefaultSuiInputType(args[0]);
|
|
200
|
-
|
|
207
|
+
const VECTOR_REGEX = /^vector<(.+)>$/;
|
|
208
|
+
const STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
|
|
209
|
+
type = type || defaultSuiType;
|
|
210
|
+
if (type === "object") {
|
|
201
211
|
const objects = args.map(
|
|
202
|
-
(arg) => typeof arg === "string" ? txBlock.object((0,
|
|
212
|
+
(arg) => typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg) ? txBlock.object((0, import_utils2.normalizeSuiObjectId)(arg)) : convertObjArg(txBlock, arg)
|
|
203
213
|
);
|
|
204
214
|
return txBlock.makeMoveVec({ objects });
|
|
215
|
+
} else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
|
|
216
|
+
return txBlock.pure(args, `vector<${type}>`);
|
|
205
217
|
} else {
|
|
206
|
-
const
|
|
207
|
-
|
|
218
|
+
const objects = args.map(
|
|
219
|
+
(arg) => convertObjArg(txBlock, arg)
|
|
220
|
+
);
|
|
221
|
+
return txBlock.makeMoveVec({ objects, type });
|
|
208
222
|
}
|
|
209
223
|
}
|
|
210
224
|
function isMoveVecArg(arg) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
225
|
+
if (typeof arg === "object" && "vecType" in arg && "value" in arg) {
|
|
226
|
+
return true;
|
|
227
|
+
} else if (Array.isArray(arg)) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
214
231
|
}
|
|
215
232
|
function convertArgs(txBlock, args) {
|
|
216
233
|
return args.map((arg) => {
|
|
217
|
-
if (typeof arg === "string" &&
|
|
218
|
-
return txBlock.object((0,
|
|
234
|
+
if (typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg)) {
|
|
235
|
+
return txBlock.object((0, import_utils2.normalizeSuiObjectId)(arg));
|
|
236
|
+
} else if (typeof arg == "object" && !(0, import_bcs2.isSerializedBcs)(arg) && !(0, import_bcs.isPureArg)(arg) && !isMoveVecArg(arg)) {
|
|
237
|
+
return convertObjArg(txBlock, arg);
|
|
219
238
|
} else if (isMoveVecArg(arg)) {
|
|
220
|
-
const vecType =
|
|
221
|
-
return vecType ? makeVecParam(txBlock, arg.value, vecType) : makeVecParam(txBlock, arg);
|
|
222
|
-
} else if (
|
|
223
|
-
return txBlock.pure(arg);
|
|
224
|
-
} else {
|
|
239
|
+
const vecType = "vecType" in arg;
|
|
240
|
+
return vecType ? makeVecParam(txBlock, arg.value, arg.vecType) : makeVecParam(txBlock, arg);
|
|
241
|
+
} else if ((0, import_bcs2.isSerializedBcs)(arg)) {
|
|
225
242
|
return arg;
|
|
243
|
+
} else {
|
|
244
|
+
return txBlock.pure(arg);
|
|
226
245
|
}
|
|
227
246
|
});
|
|
228
247
|
}
|
|
248
|
+
function convertAddressArg(txBlock, arg) {
|
|
249
|
+
if (typeof arg === "string" && (0, import_utils2.isValidSuiAddress)(arg)) {
|
|
250
|
+
return txBlock.pure.address((0, import_utils2.normalizeSuiAddress)(arg));
|
|
251
|
+
} else if (typeof arg == "object" && !(0, import_bcs2.isSerializedBcs)(arg) && !(0, import_bcs.isPureArg)(arg)) {
|
|
252
|
+
return convertObjArg(txBlock, arg);
|
|
253
|
+
} else if ((0, import_bcs.isPureArg)(arg)) {
|
|
254
|
+
return txBlock.pure(arg);
|
|
255
|
+
} else {
|
|
256
|
+
return arg;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function convertObjArg(txb, arg) {
|
|
260
|
+
if (typeof arg === "string") {
|
|
261
|
+
return txb.object(arg);
|
|
262
|
+
}
|
|
263
|
+
if ("digest" in arg && "version" in arg && "objectId" in arg) {
|
|
264
|
+
return txb.objectRef(arg);
|
|
265
|
+
}
|
|
266
|
+
if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
|
|
267
|
+
return txb.sharedObjectRef(arg);
|
|
268
|
+
}
|
|
269
|
+
if ("Object" in arg) {
|
|
270
|
+
if ("ImmOrOwned" in arg.Object) {
|
|
271
|
+
return txb.object(import_transactions.Inputs.ObjectRef(arg.Object.ImmOrOwned));
|
|
272
|
+
} else if ("Shared" in arg.Object) {
|
|
273
|
+
return txb.object(import_transactions.Inputs.SharedObjectRef(arg.Object.Shared));
|
|
274
|
+
} else {
|
|
275
|
+
throw new Error("Invalid argument type");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if ("kind" in arg) {
|
|
279
|
+
return arg;
|
|
280
|
+
}
|
|
281
|
+
throw new Error("Invalid argument type");
|
|
282
|
+
}
|
|
229
283
|
|
|
230
284
|
// src/libs/suiTxBuilder/index.ts
|
|
231
285
|
var SuiTxBlock = class {
|
|
232
286
|
constructor(transaction) {
|
|
233
|
-
this.txBlock = new
|
|
287
|
+
this.txBlock = new import_transactions2.TransactionBlock(transaction);
|
|
288
|
+
}
|
|
289
|
+
/* Directly wrap methods and properties of TransactionBlock */
|
|
290
|
+
get gas() {
|
|
291
|
+
return this.txBlock.gas;
|
|
292
|
+
}
|
|
293
|
+
get blockData() {
|
|
294
|
+
return this.txBlock.blockData;
|
|
234
295
|
}
|
|
235
|
-
//======== override methods of TransactionBlock ============
|
|
236
296
|
address(value) {
|
|
237
297
|
return this.txBlock.pure(value, "address");
|
|
238
298
|
}
|
|
@@ -269,59 +329,69 @@ var SuiTxBlock = class {
|
|
|
269
329
|
setGasPayment(payments) {
|
|
270
330
|
return this.txBlock.setGasPayment(payments);
|
|
271
331
|
}
|
|
272
|
-
add(transaction) {
|
|
273
|
-
return this.txBlock.add(transaction);
|
|
274
|
-
}
|
|
275
332
|
serialize() {
|
|
276
333
|
return this.txBlock.serialize();
|
|
277
334
|
}
|
|
335
|
+
sign(params) {
|
|
336
|
+
return this.txBlock.sign(params);
|
|
337
|
+
}
|
|
278
338
|
build(params = {}) {
|
|
279
339
|
return this.txBlock.build(params);
|
|
280
340
|
}
|
|
281
|
-
getDigest(
|
|
282
|
-
return this.txBlock.getDigest(
|
|
341
|
+
getDigest(params = {}) {
|
|
342
|
+
return this.txBlock.getDigest(params);
|
|
283
343
|
}
|
|
284
|
-
|
|
285
|
-
return this.txBlock.
|
|
344
|
+
add(...args) {
|
|
345
|
+
return this.txBlock.add(...args);
|
|
286
346
|
}
|
|
287
|
-
|
|
288
|
-
|
|
347
|
+
publish({
|
|
348
|
+
modules,
|
|
349
|
+
dependencies
|
|
350
|
+
}) {
|
|
351
|
+
return this.txBlock.publish({ modules, dependencies });
|
|
289
352
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
353
|
+
upgrade({
|
|
354
|
+
modules,
|
|
355
|
+
dependencies,
|
|
356
|
+
packageId,
|
|
357
|
+
ticket
|
|
358
|
+
}) {
|
|
359
|
+
return this.txBlock.upgrade({ modules, dependencies, packageId, ticket });
|
|
360
|
+
}
|
|
361
|
+
makeMoveVec({
|
|
362
|
+
objects,
|
|
363
|
+
type
|
|
364
|
+
}) {
|
|
365
|
+
return this.txBlock.makeMoveVec({ objects, type });
|
|
366
|
+
}
|
|
367
|
+
/* Override methods of TransactionBlock */
|
|
368
|
+
transferObjects(objects, address) {
|
|
369
|
+
return this.txBlock.transferObjects(
|
|
370
|
+
objects.map((object) => convertObjArg(this.txBlock, object)),
|
|
371
|
+
convertAddressArg(this.txBlock, address)
|
|
372
|
+
);
|
|
294
373
|
}
|
|
295
374
|
splitCoins(coin, amounts) {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
coinObject,
|
|
300
|
-
amounts.map((m) => tx.pure(m))
|
|
375
|
+
const res = this.txBlock.splitCoins(
|
|
376
|
+
convertObjArg(this.txBlock, coin),
|
|
377
|
+
convertArgs(this.txBlock, amounts)
|
|
301
378
|
);
|
|
302
379
|
return amounts.map((_, i) => res[i]);
|
|
303
380
|
}
|
|
304
381
|
mergeCoins(destination, sources) {
|
|
305
|
-
const destinationObject =
|
|
306
|
-
const sourceObjects =
|
|
382
|
+
const destinationObject = convertObjArg(this.txBlock, destination);
|
|
383
|
+
const sourceObjects = sources.map(
|
|
384
|
+
(source) => convertObjArg(this.txBlock, source)
|
|
385
|
+
);
|
|
307
386
|
return this.txBlock.mergeCoins(destinationObject, sourceObjects);
|
|
308
387
|
}
|
|
309
|
-
publish(...args) {
|
|
310
|
-
return this.txBlock.publish(...args);
|
|
311
|
-
}
|
|
312
|
-
upgrade(...args) {
|
|
313
|
-
return this.txBlock.upgrade(...args);
|
|
314
|
-
}
|
|
315
|
-
makeMoveVec(...args) {
|
|
316
|
-
return this.txBlock.makeMoveVec(...args);
|
|
317
|
-
}
|
|
318
388
|
/**
|
|
319
389
|
* @description Move call
|
|
320
390
|
* @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`
|
|
321
391
|
* @param args the arguments of the move call, such as `['0x1', '0x2']`
|
|
322
|
-
* @param
|
|
392
|
+
* @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`
|
|
323
393
|
*/
|
|
324
|
-
moveCall(target, args = [],
|
|
394
|
+
moveCall(target, args = [], typeArgs = []) {
|
|
325
395
|
const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;
|
|
326
396
|
const match = target.match(regex);
|
|
327
397
|
if (match === null)
|
|
@@ -329,104 +399,111 @@ var SuiTxBlock = class {
|
|
|
329
399
|
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
330
400
|
);
|
|
331
401
|
const convertedArgs = convertArgs(this.txBlock, args);
|
|
332
|
-
|
|
333
|
-
return tx.moveCall({
|
|
402
|
+
return this.txBlock.moveCall({
|
|
334
403
|
target,
|
|
335
404
|
arguments: convertedArgs,
|
|
336
|
-
typeArguments
|
|
405
|
+
typeArguments: typeArgs
|
|
337
406
|
});
|
|
338
407
|
}
|
|
339
|
-
|
|
408
|
+
/* Enhance methods of TransactionBlock */
|
|
340
409
|
transferSuiToMany(recipients, amounts) {
|
|
341
410
|
if (recipients.length !== amounts.length) {
|
|
342
411
|
throw new Error(
|
|
343
412
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
344
413
|
);
|
|
345
414
|
}
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
415
|
+
const coins = this.txBlock.splitCoins(
|
|
416
|
+
this.txBlock.gas,
|
|
417
|
+
convertArgs(this.txBlock, amounts)
|
|
418
|
+
);
|
|
419
|
+
const recipientObjects = recipients.map(
|
|
420
|
+
(recipient) => convertAddressArg(this.txBlock, recipient)
|
|
350
421
|
);
|
|
351
|
-
|
|
352
|
-
|
|
422
|
+
recipientObjects.forEach((address, index) => {
|
|
423
|
+
this.txBlock.transferObjects([coins[index]], address);
|
|
353
424
|
});
|
|
354
425
|
return this;
|
|
355
426
|
}
|
|
356
|
-
transferSui(
|
|
357
|
-
return this.transferSuiToMany([
|
|
427
|
+
transferSui(address, amount) {
|
|
428
|
+
return this.transferSuiToMany([address], [amount]);
|
|
358
429
|
}
|
|
359
430
|
takeAmountFromCoins(coins, amount) {
|
|
360
|
-
const
|
|
361
|
-
const coinObjects = convertArgs(this.txBlock, coins);
|
|
431
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
|
|
362
432
|
const mergedCoin = coinObjects[0];
|
|
363
433
|
if (coins.length > 1) {
|
|
364
|
-
|
|
434
|
+
this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
365
435
|
}
|
|
366
|
-
const [sendCoin] =
|
|
436
|
+
const [sendCoin] = this.txBlock.splitCoins(
|
|
437
|
+
mergedCoin,
|
|
438
|
+
convertArgs(this.txBlock, [amount])
|
|
439
|
+
);
|
|
367
440
|
return [sendCoin, mergedCoin];
|
|
368
441
|
}
|
|
369
442
|
splitSUIFromGas(amounts) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
amounts.map((m) => tx.pure(m))
|
|
443
|
+
return this.txBlock.splitCoins(
|
|
444
|
+
this.txBlock.gas,
|
|
445
|
+
convertArgs(this.txBlock, amounts)
|
|
374
446
|
);
|
|
375
447
|
}
|
|
376
448
|
splitMultiCoins(coins, amounts) {
|
|
377
|
-
const
|
|
378
|
-
const coinObjects = convertArgs(this.txBlock, coins);
|
|
449
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
|
|
379
450
|
const mergedCoin = coinObjects[0];
|
|
380
451
|
if (coins.length > 1) {
|
|
381
|
-
|
|
452
|
+
this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
382
453
|
}
|
|
383
|
-
const splitedCoins =
|
|
454
|
+
const splitedCoins = this.txBlock.splitCoins(
|
|
384
455
|
mergedCoin,
|
|
385
|
-
|
|
456
|
+
convertArgs(this.txBlock, amounts)
|
|
386
457
|
);
|
|
387
458
|
return { splitedCoins, mergedCoin };
|
|
388
459
|
}
|
|
389
|
-
transferCoinToMany(
|
|
460
|
+
transferCoinToMany(coins, sender, recipients, amounts) {
|
|
390
461
|
if (recipients.length !== amounts.length) {
|
|
391
462
|
throw new Error(
|
|
392
463
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
393
464
|
);
|
|
394
465
|
}
|
|
395
|
-
const
|
|
466
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
|
|
396
467
|
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
397
|
-
|
|
468
|
+
coinObjects,
|
|
398
469
|
amounts
|
|
399
470
|
);
|
|
400
|
-
recipients.
|
|
401
|
-
|
|
471
|
+
const recipientObjects = recipients.map(
|
|
472
|
+
(recipient) => convertAddressArg(this.txBlock, recipient)
|
|
473
|
+
);
|
|
474
|
+
recipientObjects.forEach((address, index) => {
|
|
475
|
+
this.txBlock.transferObjects([splitedCoins[index]], address);
|
|
402
476
|
});
|
|
403
|
-
|
|
477
|
+
this.txBlock.transferObjects(
|
|
478
|
+
[mergedCoin],
|
|
479
|
+
convertAddressArg(this.txBlock, sender)
|
|
480
|
+
);
|
|
404
481
|
return this;
|
|
405
482
|
}
|
|
406
|
-
transferCoin(
|
|
407
|
-
return this.transferCoinToMany(
|
|
483
|
+
transferCoin(coins, sender, recipient, amount) {
|
|
484
|
+
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
408
485
|
}
|
|
409
486
|
stakeSui(amount, validatorAddr) {
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
487
|
+
const [stakeCoin] = this.txBlock.splitCoins(
|
|
488
|
+
this.txBlock.gas,
|
|
489
|
+
convertArgs(this.txBlock, [amount])
|
|
490
|
+
);
|
|
491
|
+
return this.txBlock.moveCall({
|
|
413
492
|
target: "0x3::sui_system::request_add_stake",
|
|
414
|
-
arguments: [
|
|
415
|
-
|
|
493
|
+
arguments: convertArgs(this.txBlock, [
|
|
494
|
+
import_utils3.SUI_SYSTEM_STATE_OBJECT_ID,
|
|
416
495
|
stakeCoin,
|
|
417
|
-
|
|
418
|
-
]
|
|
496
|
+
this.txBlock.pure(validatorAddr)
|
|
497
|
+
])
|
|
419
498
|
});
|
|
420
|
-
return tx;
|
|
421
499
|
}
|
|
422
500
|
};
|
|
423
501
|
|
|
424
502
|
// src/libs/suiInteractor/suiInteractor.ts
|
|
425
|
-
var
|
|
503
|
+
var import_client = require("@mysten/sui.js/client");
|
|
426
504
|
var import_faucet = require("@mysten/sui.js/faucet");
|
|
427
505
|
|
|
428
506
|
// src/libs/suiModel/suiOwnedObject.ts
|
|
429
|
-
var import_sui6 = require("@mysten/sui.js");
|
|
430
507
|
var SuiOwnedObject = class {
|
|
431
508
|
constructor(param) {
|
|
432
509
|
this.objectId = param.objectId;
|
|
@@ -460,7 +537,7 @@ var SuiOwnedObject = class {
|
|
|
460
537
|
* @param txResponse
|
|
461
538
|
*/
|
|
462
539
|
updateFromTxResponse(txResponse) {
|
|
463
|
-
const changes =
|
|
540
|
+
const changes = txResponse.objectChanges;
|
|
464
541
|
if (!changes) {
|
|
465
542
|
throw new Error("Bad transaction response!");
|
|
466
543
|
}
|
|
@@ -505,15 +582,16 @@ var SuiInteractor = class {
|
|
|
505
582
|
constructor(fullNodeUrls, network) {
|
|
506
583
|
if (fullNodeUrls.length === 0)
|
|
507
584
|
throw new Error("fullNodeUrls must not be empty");
|
|
508
|
-
this.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
585
|
+
this.fullNodes = fullNodeUrls;
|
|
586
|
+
this.clients = fullNodeUrls.map((url) => new import_client.SuiClient({ url }));
|
|
587
|
+
this.currentFullNode = fullNodeUrls[0];
|
|
588
|
+
this.currentClient = this.clients[0];
|
|
512
589
|
this.network = network;
|
|
513
590
|
}
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
this.
|
|
591
|
+
switchToNextClient() {
|
|
592
|
+
const currentClientIdx = this.clients.indexOf(this.currentClient);
|
|
593
|
+
this.currentClient = this.clients[(currentClientIdx + 1) % this.clients.length];
|
|
594
|
+
this.currentFullNode = this.fullNodes[(currentClientIdx + 1) % this.clients.length];
|
|
517
595
|
}
|
|
518
596
|
async sendTx(transactionBlock, signature) {
|
|
519
597
|
const txResOptions = {
|
|
@@ -522,56 +600,43 @@ var SuiInteractor = class {
|
|
|
522
600
|
showObjectChanges: true,
|
|
523
601
|
showBalanceChanges: true
|
|
524
602
|
};
|
|
525
|
-
for (const
|
|
603
|
+
for (const clientIdx in this.clients) {
|
|
526
604
|
try {
|
|
527
|
-
|
|
605
|
+
return await this.clients[clientIdx].executeTransactionBlock({
|
|
528
606
|
transactionBlock,
|
|
529
607
|
signature,
|
|
530
608
|
options: txResOptions
|
|
531
609
|
});
|
|
532
|
-
return res;
|
|
533
610
|
} catch (err) {
|
|
534
611
|
console.warn(
|
|
535
|
-
`Failed to send transaction with fullnode ${
|
|
612
|
+
`Failed to send transaction with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
536
613
|
);
|
|
537
614
|
await delay(2e3);
|
|
538
615
|
}
|
|
539
616
|
}
|
|
540
617
|
throw new Error("Failed to send transaction with all fullnodes");
|
|
541
618
|
}
|
|
542
|
-
async getObjects(ids) {
|
|
543
|
-
const
|
|
619
|
+
async getObjects(ids, options) {
|
|
620
|
+
const opts = options ?? {
|
|
544
621
|
showContent: true,
|
|
545
622
|
showDisplay: true,
|
|
546
623
|
showType: true,
|
|
547
624
|
showOwner: true
|
|
548
625
|
};
|
|
549
|
-
for (const
|
|
626
|
+
for (const clientIdx in this.clients) {
|
|
550
627
|
try {
|
|
551
|
-
const objects = await
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const objectType = (0, import_sui7.getObjectType)(object);
|
|
555
|
-
const objectVersion = (0, import_sui7.getObjectVersion)(object);
|
|
556
|
-
const objectDigest = object.data ? object.data.digest : void 0;
|
|
557
|
-
const initialSharedVersion = (0, import_sui7.getSharedObjectInitialVersion)(object);
|
|
558
|
-
const objectFields = (0, import_sui7.getObjectFields)(object);
|
|
559
|
-
const objectDisplay = (0, import_sui7.getObjectDisplay)(object);
|
|
560
|
-
return {
|
|
561
|
-
objectId,
|
|
562
|
-
objectType,
|
|
563
|
-
objectVersion,
|
|
564
|
-
objectDigest,
|
|
565
|
-
objectFields,
|
|
566
|
-
objectDisplay,
|
|
567
|
-
initialSharedVersion
|
|
568
|
-
};
|
|
628
|
+
const objects = await this.clients[clientIdx].multiGetObjects({
|
|
629
|
+
ids,
|
|
630
|
+
options: opts
|
|
569
631
|
});
|
|
632
|
+
const parsedObjects = objects.map((object) => {
|
|
633
|
+
return object.data;
|
|
634
|
+
}).filter((object) => object !== null && object !== void 0);
|
|
570
635
|
return parsedObjects;
|
|
571
636
|
} catch (err) {
|
|
572
637
|
await delay(2e3);
|
|
573
638
|
console.warn(
|
|
574
|
-
`Failed to get objects with fullnode ${
|
|
639
|
+
`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
575
640
|
);
|
|
576
641
|
}
|
|
577
642
|
}
|
|
@@ -581,84 +646,88 @@ var SuiInteractor = class {
|
|
|
581
646
|
const objects = await this.getObjects([id]);
|
|
582
647
|
return objects[0];
|
|
583
648
|
}
|
|
584
|
-
// async getEntitiesObjects(ids: string[]) {
|
|
585
|
-
// const options = {
|
|
586
|
-
// showContent: true,
|
|
587
|
-
// showType: true,
|
|
588
|
-
// };
|
|
589
|
-
// for (const provider of this.providers) {
|
|
590
|
-
// try {
|
|
591
|
-
// const objects = await provider.multiGetObjects({ ids, options });
|
|
592
|
-
// const parsedObjects = objects.map((object) => {
|
|
593
|
-
// const objectId = getObjectId(object);
|
|
594
|
-
// const objectFields = getObjectFields(object) as ObjectFieldType;
|
|
595
|
-
// const index = objectFields.name;
|
|
596
|
-
// const key = objectFields.value;
|
|
597
|
-
// return {
|
|
598
|
-
// objectId,
|
|
599
|
-
// index,
|
|
600
|
-
// key,
|
|
601
|
-
// };
|
|
602
|
-
// });
|
|
603
|
-
// return parsedObjects as EntityData[];
|
|
604
|
-
// } catch (err) {
|
|
605
|
-
// await delay(2000);
|
|
606
|
-
// console.warn(
|
|
607
|
-
// `Failed to get EntitiesObjects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
608
|
-
// );
|
|
609
|
-
// }
|
|
610
|
-
// }
|
|
611
|
-
// throw new Error('Failed to get EntitiesObjects with all fullnodes');
|
|
612
|
-
// }
|
|
613
649
|
async getDynamicFieldObject(parentId, name) {
|
|
614
|
-
for (const
|
|
650
|
+
for (const clientIdx in this.clients) {
|
|
615
651
|
try {
|
|
616
|
-
return
|
|
652
|
+
return await this.clients[clientIdx].getDynamicFieldObject({
|
|
653
|
+
parentId,
|
|
654
|
+
name
|
|
655
|
+
});
|
|
617
656
|
} catch (err) {
|
|
618
657
|
await delay(2e3);
|
|
619
658
|
console.warn(
|
|
620
|
-
`Failed to get DynamicFieldObject with fullnode ${
|
|
659
|
+
`Failed to get DynamicFieldObject with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
621
660
|
);
|
|
622
661
|
}
|
|
623
662
|
}
|
|
624
663
|
throw new Error("Failed to get DynamicFieldObject with all fullnodes");
|
|
625
664
|
}
|
|
626
665
|
async getDynamicFields(parentId, cursor, limit) {
|
|
627
|
-
for (const
|
|
666
|
+
for (const clientIdx in this.clients) {
|
|
628
667
|
try {
|
|
629
|
-
return
|
|
668
|
+
return await this.clients[clientIdx].getDynamicFields({
|
|
669
|
+
parentId,
|
|
670
|
+
cursor,
|
|
671
|
+
limit
|
|
672
|
+
});
|
|
630
673
|
} catch (err) {
|
|
631
674
|
await delay(2e3);
|
|
632
675
|
console.warn(
|
|
633
|
-
`Failed to get DynamicFields with fullnode ${
|
|
676
|
+
`Failed to get DynamicFields with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
634
677
|
);
|
|
635
678
|
}
|
|
636
679
|
}
|
|
637
680
|
throw new Error("Failed to get DynamicFields with all fullnodes");
|
|
638
681
|
}
|
|
682
|
+
async getTxDetails(digest) {
|
|
683
|
+
for (const clientIdx in this.clients) {
|
|
684
|
+
try {
|
|
685
|
+
const txResOptions = {
|
|
686
|
+
showEvents: true,
|
|
687
|
+
showEffects: true,
|
|
688
|
+
showObjectChanges: true,
|
|
689
|
+
showBalanceChanges: true
|
|
690
|
+
};
|
|
691
|
+
return await this.clients[clientIdx].getTransactionBlock({
|
|
692
|
+
digest,
|
|
693
|
+
options: txResOptions
|
|
694
|
+
});
|
|
695
|
+
} catch (err) {
|
|
696
|
+
await delay(2e3);
|
|
697
|
+
console.warn(
|
|
698
|
+
`Failed to get TransactionBlocks with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
throw new Error("Failed to get TransactionBlocks with all fullnodes");
|
|
703
|
+
}
|
|
639
704
|
async getOwnedObjects(owner, cursor, limit) {
|
|
640
|
-
for (const
|
|
705
|
+
for (const clientIdx in this.clients) {
|
|
641
706
|
try {
|
|
642
|
-
return await
|
|
707
|
+
return await this.clients[clientIdx].getOwnedObjects({
|
|
708
|
+
owner,
|
|
709
|
+
cursor,
|
|
710
|
+
limit
|
|
711
|
+
});
|
|
643
712
|
} catch (err) {
|
|
644
713
|
await delay(2e3);
|
|
645
714
|
console.warn(
|
|
646
|
-
`Failed to get OwnedObjects with fullnode ${
|
|
715
|
+
`Failed to get OwnedObjects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
647
716
|
);
|
|
648
717
|
}
|
|
649
718
|
}
|
|
650
719
|
throw new Error("Failed to get OwnedObjects with all fullnodes");
|
|
651
720
|
}
|
|
652
721
|
async getNormalizedMoveModulesByPackage(packageId) {
|
|
653
|
-
for (const
|
|
722
|
+
for (const clientIdx in this.clients) {
|
|
654
723
|
try {
|
|
655
|
-
return
|
|
724
|
+
return await this.clients[clientIdx].getNormalizedMoveModulesByPackage({
|
|
656
725
|
package: packageId
|
|
657
726
|
});
|
|
658
727
|
} catch (err) {
|
|
659
728
|
await delay(2e3);
|
|
660
729
|
console.warn(
|
|
661
|
-
`Failed to get NormalizedMoveModules with fullnode ${
|
|
730
|
+
`Failed to get NormalizedMoveModules with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
662
731
|
);
|
|
663
732
|
}
|
|
664
733
|
}
|
|
@@ -673,13 +742,17 @@ var SuiInteractor = class {
|
|
|
673
742
|
const objects = await this.getObjects(objectIds);
|
|
674
743
|
for (const object of objects) {
|
|
675
744
|
const suiObject = suiObjects.find(
|
|
676
|
-
(obj) => obj.objectId === object
|
|
745
|
+
(obj) => obj.objectId === object?.objectId
|
|
677
746
|
);
|
|
678
747
|
if (suiObject instanceof SuiSharedObject) {
|
|
679
|
-
|
|
748
|
+
if (object.owner && typeof object.owner === "object" && "Shared" in object.owner) {
|
|
749
|
+
suiObject.initialSharedVersion = object.owner.Shared.initial_shared_version;
|
|
750
|
+
} else {
|
|
751
|
+
suiObject.initialSharedVersion = void 0;
|
|
752
|
+
}
|
|
680
753
|
} else if (suiObject instanceof SuiOwnedObject) {
|
|
681
|
-
suiObject.version = object
|
|
682
|
-
suiObject.digest = object
|
|
754
|
+
suiObject.version = object?.version;
|
|
755
|
+
suiObject.digest = object?.digest;
|
|
683
756
|
}
|
|
684
757
|
}
|
|
685
758
|
}
|
|
@@ -694,7 +767,7 @@ var SuiInteractor = class {
|
|
|
694
767
|
let totalAmount = 0;
|
|
695
768
|
let hasNext = true, nextCursor = null;
|
|
696
769
|
while (hasNext && totalAmount < amount) {
|
|
697
|
-
const coins = await this.
|
|
770
|
+
const coins = await this.currentClient.getCoins({
|
|
698
771
|
owner: addr,
|
|
699
772
|
coinType,
|
|
700
773
|
cursor: nextCursor
|
|
@@ -727,24 +800,6 @@ var SuiInteractor = class {
|
|
|
727
800
|
}
|
|
728
801
|
};
|
|
729
802
|
|
|
730
|
-
// src/libs/suiInteractor/defaultConfig.ts
|
|
731
|
-
var import_sui8 = require("@mysten/sui.js");
|
|
732
|
-
var defaultGasBudget = 10 ** 8;
|
|
733
|
-
var getDefaultConnection = (networkType = "devnet") => {
|
|
734
|
-
switch (networkType) {
|
|
735
|
-
case "localnet":
|
|
736
|
-
return import_sui8.localnetConnection;
|
|
737
|
-
case "devnet":
|
|
738
|
-
return import_sui8.devnetConnection;
|
|
739
|
-
case "testnet":
|
|
740
|
-
return import_sui8.testnetConnection;
|
|
741
|
-
case "mainnet":
|
|
742
|
-
return import_sui8.mainnetConnection;
|
|
743
|
-
default:
|
|
744
|
-
return import_sui8.devnetConnection;
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
|
|
748
803
|
// src/libs/suiContractFactory/index.ts
|
|
749
804
|
var SuiContractFactory = class {
|
|
750
805
|
// readonly #query: MapMessageQuery<ApiTypes> = {};
|
|
@@ -843,7 +898,7 @@ function numberToAddressHex(num) {
|
|
|
843
898
|
|
|
844
899
|
// src/obelisk.ts
|
|
845
900
|
var import_keccak256 = __toESM(require("keccak256"));
|
|
846
|
-
var
|
|
901
|
+
var import_bcs3 = require("@mysten/bcs");
|
|
847
902
|
function isUndefined(value) {
|
|
848
903
|
return value === void 0;
|
|
849
904
|
}
|
|
@@ -923,7 +978,7 @@ var Obelisk = class {
|
|
|
923
978
|
return await this.inspectTxn(tx);
|
|
924
979
|
});
|
|
925
980
|
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
926
|
-
fullnodeUrls = fullnodeUrls || [
|
|
981
|
+
fullnodeUrls = fullnodeUrls || [(0, import_client2.getFullnodeUrl)(networkType ?? "mainnet")];
|
|
927
982
|
this.suiInteractor = new SuiInteractor(fullnodeUrls, networkType);
|
|
928
983
|
this.packageId = packageId;
|
|
929
984
|
if (metadata !== void 0) {
|
|
@@ -968,14 +1023,13 @@ var Obelisk = class {
|
|
|
968
1023
|
return __privateGet(this, _tx);
|
|
969
1024
|
}
|
|
970
1025
|
/**
|
|
971
|
-
* if derivePathParams is not provided or mnemonics is empty, it will return the
|
|
1026
|
+
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
972
1027
|
* else:
|
|
973
1028
|
* it will generate signer from the mnemonic with the given derivePathParams.
|
|
974
1029
|
* @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
|
|
975
1030
|
*/
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
return new import_sui9.RawSigner(keyPair, this.suiInteractor.currentProvider);
|
|
1031
|
+
getKeypair(derivePathParams) {
|
|
1032
|
+
return this.accountManager.getKeyPair(derivePathParams);
|
|
979
1033
|
}
|
|
980
1034
|
/**
|
|
981
1035
|
* @description Switch the current account with the given derivePathParams
|
|
@@ -994,9 +1048,6 @@ var Obelisk = class {
|
|
|
994
1048
|
currentAddress() {
|
|
995
1049
|
return this.accountManager.currentAddress;
|
|
996
1050
|
}
|
|
997
|
-
provider() {
|
|
998
|
-
return this.suiInteractor.currentProvider;
|
|
999
|
-
}
|
|
1000
1051
|
getPackageId() {
|
|
1001
1052
|
return this.contractFactory.packageId;
|
|
1002
1053
|
}
|
|
@@ -1012,7 +1063,10 @@ var Obelisk = class {
|
|
|
1012
1063
|
}
|
|
1013
1064
|
async getBalance(coinType, derivePathParams) {
|
|
1014
1065
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
1015
|
-
return this.suiInteractor.
|
|
1066
|
+
return this.suiInteractor.currentClient.getBalance({ owner, coinType });
|
|
1067
|
+
}
|
|
1068
|
+
client() {
|
|
1069
|
+
return this.suiInteractor.currentClient;
|
|
1016
1070
|
}
|
|
1017
1071
|
async getObject(objectId) {
|
|
1018
1072
|
return this.suiInteractor.getObject(objectId);
|
|
@@ -1021,16 +1075,17 @@ var Obelisk = class {
|
|
|
1021
1075
|
return this.suiInteractor.getObjects(objectIds);
|
|
1022
1076
|
}
|
|
1023
1077
|
async signTxn(tx, derivePathParams) {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1078
|
+
if (tx instanceof SuiTxBlock) {
|
|
1079
|
+
tx.setSender(this.getAddress(derivePathParams));
|
|
1080
|
+
}
|
|
1081
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
1082
|
+
const txBytes = txBlock instanceof import_transactions3.TransactionBlock ? await txBlock.build({ client: this.client() }) : txBlock;
|
|
1083
|
+
const keyPair = this.getKeypair(derivePathParams);
|
|
1084
|
+
return await keyPair.signTransactionBlock(txBytes);
|
|
1027
1085
|
}
|
|
1028
1086
|
async signAndSendTxn(tx, derivePathParams) {
|
|
1029
|
-
const {
|
|
1030
|
-
|
|
1031
|
-
derivePathParams
|
|
1032
|
-
);
|
|
1033
|
-
return this.suiInteractor.sendTx(transactionBlockBytes, signature);
|
|
1087
|
+
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
1088
|
+
return this.suiInteractor.sendTx(bytes, signature);
|
|
1034
1089
|
}
|
|
1035
1090
|
/**
|
|
1036
1091
|
* Transfer the given amount of SUI to the recipient
|
|
@@ -1132,9 +1187,9 @@ var Obelisk = class {
|
|
|
1132
1187
|
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
1133
1188
|
*/
|
|
1134
1189
|
async inspectTxn(tx, derivePathParams) {
|
|
1135
|
-
|
|
1136
|
-
return this.suiInteractor.
|
|
1137
|
-
transactionBlock:
|
|
1190
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
1191
|
+
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
1192
|
+
transactionBlock: txBlock,
|
|
1138
1193
|
sender: this.getAddress(derivePathParams)
|
|
1139
1194
|
});
|
|
1140
1195
|
}
|
|
@@ -1143,12 +1198,18 @@ var Obelisk = class {
|
|
|
1143
1198
|
}
|
|
1144
1199
|
async listSchemaNames(worldId) {
|
|
1145
1200
|
const worldObject = await this.getObject(worldId);
|
|
1146
|
-
const newObjectContent = worldObject.
|
|
1147
|
-
|
|
1201
|
+
const newObjectContent = worldObject.content;
|
|
1202
|
+
if (newObjectContent != null) {
|
|
1203
|
+
const objectContent = newObjectContent;
|
|
1204
|
+
const objectFields = objectContent.fields;
|
|
1205
|
+
return objectFields["schema_names"];
|
|
1206
|
+
} else {
|
|
1207
|
+
return [];
|
|
1208
|
+
}
|
|
1148
1209
|
}
|
|
1149
1210
|
async getEntity(worldId, schemaName, entityId) {
|
|
1150
1211
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1151
|
-
const tx = new
|
|
1212
|
+
const tx = new import_transactions3.TransactionBlock();
|
|
1152
1213
|
const params = [tx.pure(worldId)];
|
|
1153
1214
|
if (entityId !== void 0) {
|
|
1154
1215
|
params.push(tx.pure(entityId));
|
|
@@ -1161,7 +1222,7 @@ var Obelisk = class {
|
|
|
1161
1222
|
if (getResult.effects.status.status === "success") {
|
|
1162
1223
|
const resultList = getResult.results[0].returnValues;
|
|
1163
1224
|
for (const res of resultList) {
|
|
1164
|
-
const bcs = new
|
|
1225
|
+
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1165
1226
|
const value = Uint8Array.from(res[0]);
|
|
1166
1227
|
const bcsType = res[1].replace(/0x1::ascii::String/g, "string");
|
|
1167
1228
|
const data = bcs.de(bcsType, value);
|
|
@@ -1174,7 +1235,7 @@ var Obelisk = class {
|
|
|
1174
1235
|
}
|
|
1175
1236
|
async containEntity(worldId, schemaName, entityId) {
|
|
1176
1237
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1177
|
-
const tx = new
|
|
1238
|
+
const tx = new import_transactions3.TransactionBlock();
|
|
1178
1239
|
const params = [tx.pure(worldId)];
|
|
1179
1240
|
if (entityId !== void 0) {
|
|
1180
1241
|
params.push(tx.pure(entityId));
|
|
@@ -1185,7 +1246,7 @@ var Obelisk = class {
|
|
|
1185
1246
|
);
|
|
1186
1247
|
if (getResult.effects.status.status === "success") {
|
|
1187
1248
|
const res = getResult.results[0].returnValues[0];
|
|
1188
|
-
const bcs = new
|
|
1249
|
+
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1189
1250
|
const value = Uint8Array.from(res[0]);
|
|
1190
1251
|
return bcs.de(res[1], value);
|
|
1191
1252
|
} else {
|
|
@@ -1231,7 +1292,7 @@ var Obelisk = class {
|
|
|
1231
1292
|
const ownedObjectsRes = [];
|
|
1232
1293
|
for (const object of ownedObjects.data) {
|
|
1233
1294
|
const objectDetail = await this.getObject(object.data.objectId);
|
|
1234
|
-
if (objectDetail.
|
|
1295
|
+
if (objectDetail.type.split("::")[0] === this.contractFactory.packageId) {
|
|
1235
1296
|
ownedObjectsRes.push(objectDetail);
|
|
1236
1297
|
}
|
|
1237
1298
|
}
|
|
@@ -1249,7 +1310,7 @@ var Obelisk = class {
|
|
|
1249
1310
|
async entity_key_from_bytes(bytes) {
|
|
1250
1311
|
const hashBytes = (0, import_keccak256.default)(bytes);
|
|
1251
1312
|
const hashU8Array = Array.from(hashBytes);
|
|
1252
|
-
const bcs = new
|
|
1313
|
+
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1253
1314
|
const value = Uint8Array.from(hashU8Array);
|
|
1254
1315
|
const data = bcs.de("address", value);
|
|
1255
1316
|
return "0x" + data;
|
|
@@ -1269,7 +1330,7 @@ var Obelisk = class {
|
|
|
1269
1330
|
const checkObjectId = normalizeHexAddress(objectId);
|
|
1270
1331
|
if (checkObjectId !== null) {
|
|
1271
1332
|
objectId = checkObjectId;
|
|
1272
|
-
const bcs = new
|
|
1333
|
+
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1273
1334
|
const bytes = Buffer.from(objectId.slice(2), "hex");
|
|
1274
1335
|
const numberBytes = bcs.ser("u256", x).toBytes();
|
|
1275
1336
|
return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
|
|
@@ -1281,7 +1342,7 @@ var Obelisk = class {
|
|
|
1281
1342
|
return numberToAddressHex(x);
|
|
1282
1343
|
}
|
|
1283
1344
|
async formatData(type, value) {
|
|
1284
|
-
const bcs = new
|
|
1345
|
+
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1285
1346
|
const u8Value = Uint8Array.from(value);
|
|
1286
1347
|
return bcs.de(type, u8Value);
|
|
1287
1348
|
}
|
|
@@ -1291,9 +1352,51 @@ _tx = new WeakMap();
|
|
|
1291
1352
|
_exec = new WeakMap();
|
|
1292
1353
|
_read = new WeakMap();
|
|
1293
1354
|
|
|
1355
|
+
// src/libs/multiSig/client.ts
|
|
1356
|
+
var import_multisig = require("@mysten/sui.js/multisig");
|
|
1357
|
+
|
|
1358
|
+
// src/libs/multiSig/publickey.ts
|
|
1359
|
+
var import_ed255193 = require("@mysten/sui.js/keypairs/ed25519");
|
|
1360
|
+
var import_utils5 = require("@mysten/sui.js/utils");
|
|
1361
|
+
function ed25519PublicKeyFromBase64(rawPubkey) {
|
|
1362
|
+
let bytes = (0, import_utils5.fromB64)(rawPubkey);
|
|
1363
|
+
if (bytes.length !== 32 && bytes.length !== 33)
|
|
1364
|
+
throw "invalid pubkey length";
|
|
1365
|
+
bytes = bytes.length === 33 ? bytes.slice(1) : bytes;
|
|
1366
|
+
return new import_ed255193.Ed25519PublicKey(bytes);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/libs/multiSig/client.ts
|
|
1370
|
+
var MultiSigClient = class _MultiSigClient {
|
|
1371
|
+
constructor(pks, threshold) {
|
|
1372
|
+
this.pksWeightPairs = pks;
|
|
1373
|
+
this.threshold = threshold;
|
|
1374
|
+
this.multiSigPublicKey = import_multisig.MultiSigPublicKey.fromPublicKeys({
|
|
1375
|
+
threshold: this.threshold,
|
|
1376
|
+
publicKeys: this.pksWeightPairs
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
static fromRawEd25519PublicKeys(rawPublicKeys, weights, threshold) {
|
|
1380
|
+
const pks = rawPublicKeys.map((rawPublicKey, i) => {
|
|
1381
|
+
return {
|
|
1382
|
+
publicKey: ed25519PublicKeyFromBase64(rawPublicKey),
|
|
1383
|
+
weight: weights[i]
|
|
1384
|
+
};
|
|
1385
|
+
});
|
|
1386
|
+
return new _MultiSigClient(pks, threshold);
|
|
1387
|
+
}
|
|
1388
|
+
multiSigAddress() {
|
|
1389
|
+
return this.multiSigPublicKey.toSuiAddress();
|
|
1390
|
+
}
|
|
1391
|
+
combinePartialSigs(sigs) {
|
|
1392
|
+
return this.multiSigPublicKey.combinePartialSignatures(sigs);
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1294
1396
|
// src/metadata/index.ts
|
|
1397
|
+
var import_client4 = require("@mysten/sui.js/client");
|
|
1295
1398
|
async function loadMetadata(networkType, packageId) {
|
|
1296
|
-
const fullnodeUrls = [
|
|
1399
|
+
const fullnodeUrls = [(0, import_client4.getFullnodeUrl)(networkType)];
|
|
1297
1400
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
1298
1401
|
if (packageId !== void 0) {
|
|
1299
1402
|
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(
|
|
@@ -1308,12 +1411,14 @@ async function loadMetadata(networkType, packageId) {
|
|
|
1308
1411
|
0 && (module.exports = {
|
|
1309
1412
|
BCS,
|
|
1310
1413
|
Ed25519Keypair,
|
|
1414
|
+
MultiSigClient,
|
|
1311
1415
|
Obelisk,
|
|
1312
1416
|
SuiAccountManager,
|
|
1313
1417
|
SuiContractFactory,
|
|
1314
1418
|
SuiTxBlock,
|
|
1315
1419
|
getSuiMoveConfig,
|
|
1316
1420
|
loadMetadata,
|
|
1317
|
-
...require("@mysten/sui.js")
|
|
1421
|
+
...require("@mysten/sui.js/utils"),
|
|
1422
|
+
...require("@mysten/sui.js/transactions")
|
|
1318
1423
|
});
|
|
1319
1424
|
//# sourceMappingURL=index.js.map
|