@0xobelisk/sui-client 0.5.16 → 0.5.18
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.js +360 -205
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
- package/src/index.ts +9 -8
- package/src/libs/multiSig/client.ts +2 -2
- package/src/libs/multiSig/publickey.ts +3 -3
- package/src/libs/suiAccountManager/index.ts +25 -6
- 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 +1 -1
- package/src/libs/suiInteractor/suiInteractor.ts +4 -4
- package/src/libs/suiModel/suiOwnedObject.ts +6 -4
- package/src/libs/suiModel/suiSharedObject.ts +5 -3
- package/src/libs/suiTxBuilder/index.ts +102 -84
- package/src/libs/suiTxBuilder/util.ts +113 -42
- package/src/metadata/index.ts +2 -3
- package/src/obelisk.ts +200 -91
- package/src/types/index.ts +46 -32
- package/dist/index.d.ts +0 -14
- package/dist/libs/multiSig/client.d.ts +0 -15
- package/dist/libs/multiSig/index.d.ts +0 -1
- package/dist/libs/multiSig/publickey.d.ts +0 -2
- package/dist/libs/suiAccountManager/crypto.d.ts +0 -1
- package/dist/libs/suiAccountManager/index.d.ts +0 -35
- package/dist/libs/suiAccountManager/keypair.d.ts +0 -21
- package/dist/libs/suiAccountManager/util.d.ts +0 -29
- package/dist/libs/suiContractFactory/index.d.ts +0 -20
- package/dist/libs/suiContractFactory/types.d.ts +0 -49
- package/dist/libs/suiInteractor/index.d.ts +0 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -50
- package/dist/libs/suiInteractor/util.d.ts +0 -1
- package/dist/libs/suiModel/index.d.ts +0 -2
- package/dist/libs/suiModel/suiOwnedObject.d.ts +0 -24
- package/dist/libs/suiModel/suiSharedObject.d.ts +0 -11
- package/dist/libs/suiTxBuilder/index.d.ts +0 -333
- package/dist/libs/suiTxBuilder/util.d.ts +0 -58
- package/dist/metadata/index.d.ts +0 -3
- package/dist/obelisk.d.ts +0 -136
- package/dist/types/index.d.ts +0 -152
- package/dist/utils/index.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -44,33 +44,36 @@ var __privateAdd = (obj, member, value) => {
|
|
|
44
44
|
// src/index.ts
|
|
45
45
|
var src_exports = {};
|
|
46
46
|
__export(src_exports, {
|
|
47
|
-
|
|
47
|
+
BcsType: () => import_bcs4.BcsType,
|
|
48
48
|
MultiSigClient: () => MultiSigClient,
|
|
49
49
|
Obelisk: () => Obelisk,
|
|
50
50
|
SuiAccountManager: () => SuiAccountManager,
|
|
51
51
|
SuiContractFactory: () => SuiContractFactory,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
SuiTx: () => SuiTx,
|
|
53
|
+
bcs: () => import_bcs4.bcs,
|
|
54
54
|
loadMetadata: () => loadMetadata
|
|
55
55
|
});
|
|
56
56
|
module.exports = __toCommonJS(src_exports);
|
|
57
|
-
__reExport(src_exports, require("@mysten/sui
|
|
58
|
-
__reExport(src_exports, require("@mysten/sui
|
|
59
|
-
__reExport(src_exports, require("@mysten/sui
|
|
60
|
-
__reExport(src_exports, require("@mysten/sui
|
|
61
|
-
__reExport(src_exports, require("@mysten/sui
|
|
62
|
-
__reExport(src_exports, require("@mysten/sui
|
|
57
|
+
__reExport(src_exports, require("@mysten/sui/client"), module.exports);
|
|
58
|
+
__reExport(src_exports, require("@mysten/sui/utils"), module.exports);
|
|
59
|
+
__reExport(src_exports, require("@mysten/sui/transactions"), module.exports);
|
|
60
|
+
__reExport(src_exports, require("@mysten/sui/bcs"), module.exports);
|
|
61
|
+
__reExport(src_exports, require("@mysten/sui/keypairs/ed25519"), module.exports);
|
|
62
|
+
__reExport(src_exports, require("@mysten/sui/keypairs/secp256k1"), module.exports);
|
|
63
|
+
__reExport(src_exports, require("@mysten/sui/keypairs/secp256r1"), module.exports);
|
|
63
64
|
var import_bcs4 = require("@mysten/bcs");
|
|
64
65
|
|
|
65
66
|
// src/obelisk.ts
|
|
66
|
-
var
|
|
67
|
-
var
|
|
67
|
+
var import_keccak256 = __toESM(require("keccak256"));
|
|
68
|
+
var import_client2 = require("@mysten/sui/client");
|
|
69
|
+
var import_transactions3 = require("@mysten/sui/transactions");
|
|
68
70
|
|
|
69
71
|
// src/libs/suiAccountManager/index.ts
|
|
70
|
-
var import_ed255192 = require("@mysten/sui
|
|
72
|
+
var import_ed255192 = require("@mysten/sui/keypairs/ed25519");
|
|
73
|
+
var import_cryptography = require("@mysten/sui/cryptography");
|
|
71
74
|
|
|
72
75
|
// src/libs/suiAccountManager/keypair.ts
|
|
73
|
-
var import_ed25519 = require("@mysten/sui
|
|
76
|
+
var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
|
|
74
77
|
var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
75
78
|
const {
|
|
76
79
|
accountIndex = 0,
|
|
@@ -85,7 +88,7 @@ var getKeyPair = (mnemonics, derivePathParams = {}) => {
|
|
|
85
88
|
};
|
|
86
89
|
|
|
87
90
|
// src/libs/suiAccountManager/util.ts
|
|
88
|
-
var import_utils = require("@mysten/sui
|
|
91
|
+
var import_utils = require("@mysten/sui/utils");
|
|
89
92
|
var isHex = (str) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
|
|
90
93
|
var isBase64 = (str) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);
|
|
91
94
|
var fromHEX = (hexStr) => {
|
|
@@ -137,7 +140,7 @@ var SuiAccountManager = class {
|
|
|
137
140
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
138
141
|
*
|
|
139
142
|
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
140
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
143
|
+
* @param secretKey, base64 or hex string or Bech32 string, when mnemonics is provided, secretKey will be ignored
|
|
141
144
|
*/
|
|
142
145
|
constructor({ mnemonics, secretKey } = {}) {
|
|
143
146
|
this.mnemonics = mnemonics || "";
|
|
@@ -145,11 +148,23 @@ var SuiAccountManager = class {
|
|
|
145
148
|
if (!this.mnemonics && !this.secretKey) {
|
|
146
149
|
this.mnemonics = generateMnemonic(24);
|
|
147
150
|
}
|
|
148
|
-
this.currentKeyPair = this.secretKey ?
|
|
149
|
-
normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))
|
|
150
|
-
) : getKeyPair(this.mnemonics);
|
|
151
|
+
this.currentKeyPair = this.secretKey ? this.parseSecretKey(this.secretKey) : getKeyPair(this.mnemonics);
|
|
151
152
|
this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();
|
|
152
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if the secretKey starts with bench32 format
|
|
156
|
+
*/
|
|
157
|
+
parseSecretKey(secretKey) {
|
|
158
|
+
if (secretKey.startsWith(import_cryptography.SUI_PRIVATE_KEY_PREFIX)) {
|
|
159
|
+
const { secretKey: uint8ArraySecretKey } = (0, import_cryptography.decodeSuiPrivateKey)(secretKey);
|
|
160
|
+
return import_ed255192.Ed25519Keypair.fromSecretKey(
|
|
161
|
+
normalizePrivateKey(uint8ArraySecretKey)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return import_ed255192.Ed25519Keypair.fromSecretKey(
|
|
165
|
+
normalizePrivateKey(hexOrBase64ToUint8Array(secretKey))
|
|
166
|
+
);
|
|
167
|
+
}
|
|
153
168
|
/**
|
|
154
169
|
* if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
|
|
155
170
|
* else:
|
|
@@ -183,14 +198,14 @@ var SuiAccountManager = class {
|
|
|
183
198
|
};
|
|
184
199
|
|
|
185
200
|
// src/libs/suiTxBuilder/index.ts
|
|
186
|
-
var import_transactions2 = require("@mysten/sui
|
|
187
|
-
var import_utils3 = require("@mysten/sui
|
|
201
|
+
var import_transactions2 = require("@mysten/sui/transactions");
|
|
202
|
+
var import_utils3 = require("@mysten/sui/utils");
|
|
188
203
|
|
|
189
204
|
// src/libs/suiTxBuilder/util.ts
|
|
190
|
-
var import_utils2 = require("@mysten/sui
|
|
191
|
-
var import_transactions = require("@mysten/sui
|
|
192
|
-
var import_bcs = require("@mysten/
|
|
193
|
-
var import_bcs2 = require("@mysten/bcs");
|
|
205
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
206
|
+
var import_transactions = require("@mysten/sui/transactions");
|
|
207
|
+
var import_bcs = require("@mysten/bcs");
|
|
208
|
+
var import_bcs2 = require("@mysten/sui/bcs");
|
|
194
209
|
var getDefaultSuiInputType = (value) => {
|
|
195
210
|
if (typeof value === "string" && (0, import_utils2.isValidSuiObjectId)(value)) {
|
|
196
211
|
return "object";
|
|
@@ -202,7 +217,10 @@ var getDefaultSuiInputType = (value) => {
|
|
|
202
217
|
return void 0;
|
|
203
218
|
}
|
|
204
219
|
};
|
|
205
|
-
function
|
|
220
|
+
function isPureArg(arg) {
|
|
221
|
+
return arg.Pure !== void 0;
|
|
222
|
+
}
|
|
223
|
+
function makeVecParam(tx, args, type) {
|
|
206
224
|
if (args.length === 0)
|
|
207
225
|
throw new Error("Transaction builder error: Empty array is not allowed");
|
|
208
226
|
const defaultSuiType = getDefaultSuiInputType(args[0]);
|
|
@@ -210,17 +228,33 @@ function makeVecParam(txBlock, args, type) {
|
|
|
210
228
|
const STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
|
|
211
229
|
type = type || defaultSuiType;
|
|
212
230
|
if (type === "object") {
|
|
213
|
-
const
|
|
214
|
-
(arg) => typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg) ?
|
|
231
|
+
const elements = args.map(
|
|
232
|
+
(arg) => typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg) ? tx.object((0, import_utils2.normalizeSuiObjectId)(arg)) : convertObjArg(tx, arg)
|
|
215
233
|
);
|
|
216
|
-
return
|
|
234
|
+
return tx.makeMoveVec({ elements });
|
|
217
235
|
} else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
|
|
218
|
-
|
|
236
|
+
if (type === "address") {
|
|
237
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.Address).serialize(args));
|
|
238
|
+
} else if (type === "bool") {
|
|
239
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.Bool).serialize(args));
|
|
240
|
+
} else if (type === "u8") {
|
|
241
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U8).serialize(args));
|
|
242
|
+
} else if (type === "u16") {
|
|
243
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U16).serialize(args));
|
|
244
|
+
} else if (type === "u32") {
|
|
245
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U32).serialize(args));
|
|
246
|
+
} else if (type === "u64") {
|
|
247
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U64).serialize(args));
|
|
248
|
+
} else if (type === "u128") {
|
|
249
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U128).serialize(args));
|
|
250
|
+
} else if (type === "u256") {
|
|
251
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U256).serialize(args));
|
|
252
|
+
} else {
|
|
253
|
+
return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U8).serialize(args));
|
|
254
|
+
}
|
|
219
255
|
} else {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
);
|
|
223
|
-
return txBlock.makeMoveVec({ objects, type });
|
|
256
|
+
const elements = args.map((arg) => convertObjArg(tx, arg));
|
|
257
|
+
return tx.makeMoveVec({ elements, type });
|
|
224
258
|
}
|
|
225
259
|
}
|
|
226
260
|
function isMoveVecArg(arg) {
|
|
@@ -231,48 +265,65 @@ function isMoveVecArg(arg) {
|
|
|
231
265
|
}
|
|
232
266
|
return false;
|
|
233
267
|
}
|
|
234
|
-
function convertArgs(
|
|
268
|
+
function convertArgs(tx, args) {
|
|
235
269
|
return args.map((arg) => {
|
|
236
270
|
if (typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg)) {
|
|
237
|
-
return
|
|
238
|
-
} else if (typeof arg == "object" && !(0,
|
|
239
|
-
return convertObjArg(
|
|
271
|
+
return tx.object((0, import_utils2.normalizeSuiObjectId)(arg));
|
|
272
|
+
} else if (typeof arg == "object" && !(0, import_bcs.isSerializedBcs)(arg) && !isPureArg(arg) && !isMoveVecArg(arg)) {
|
|
273
|
+
return convertObjArg(tx, arg);
|
|
240
274
|
} else if (isMoveVecArg(arg)) {
|
|
241
275
|
const vecType = "vecType" in arg;
|
|
242
|
-
return vecType ? makeVecParam(
|
|
243
|
-
} else if ((0,
|
|
276
|
+
return vecType ? makeVecParam(tx, arg.value, arg.vecType) : makeVecParam(tx, arg);
|
|
277
|
+
} else if ((0, import_bcs.isSerializedBcs)(arg)) {
|
|
244
278
|
return arg;
|
|
245
279
|
} else {
|
|
246
|
-
|
|
280
|
+
let argType = getDefaultSuiInputType(arg);
|
|
281
|
+
if (argType === "address") {
|
|
282
|
+
return tx.pure.address(arg);
|
|
283
|
+
} else if (argType === "u64") {
|
|
284
|
+
return tx.pure.u64(arg);
|
|
285
|
+
} else if (argType === "bool") {
|
|
286
|
+
return tx.pure.bool(arg);
|
|
287
|
+
} else {
|
|
288
|
+
return tx.pure.u64(arg);
|
|
289
|
+
}
|
|
247
290
|
}
|
|
248
291
|
});
|
|
249
292
|
}
|
|
250
|
-
function convertAddressArg(
|
|
293
|
+
function convertAddressArg(tx, arg) {
|
|
251
294
|
if (typeof arg === "string" && (0, import_utils2.isValidSuiAddress)(arg)) {
|
|
252
|
-
return
|
|
253
|
-
} else if (typeof arg == "object" && !(0,
|
|
254
|
-
return convertObjArg(
|
|
255
|
-
} else if (
|
|
256
|
-
return
|
|
295
|
+
return tx.pure.address((0, import_utils2.normalizeSuiAddress)(arg));
|
|
296
|
+
} else if (typeof arg == "object" && !(0, import_bcs.isSerializedBcs)(arg) && !isPureArg(arg)) {
|
|
297
|
+
return convertObjArg(tx, arg);
|
|
298
|
+
} else if (isPureArg(arg)) {
|
|
299
|
+
return tx.pure(Uint8Array.from(arg.Pure));
|
|
257
300
|
} else {
|
|
258
301
|
return arg;
|
|
259
302
|
}
|
|
260
303
|
}
|
|
261
|
-
function convertObjArg(
|
|
304
|
+
function convertObjArg(tx, arg) {
|
|
262
305
|
if (typeof arg === "string") {
|
|
263
|
-
return
|
|
306
|
+
return tx.object(arg);
|
|
264
307
|
}
|
|
265
308
|
if ("digest" in arg && "version" in arg && "objectId" in arg) {
|
|
266
|
-
return
|
|
309
|
+
return tx.objectRef(arg);
|
|
267
310
|
}
|
|
268
311
|
if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
|
|
269
|
-
return
|
|
312
|
+
return tx.sharedObjectRef(arg);
|
|
270
313
|
}
|
|
271
314
|
if ("Object" in arg) {
|
|
272
|
-
if ("
|
|
273
|
-
return
|
|
274
|
-
|
|
275
|
-
|
|
315
|
+
if ("ImmOrOwnedObject" in arg.Object) {
|
|
316
|
+
return tx.object(
|
|
317
|
+
import_transactions.Inputs.ObjectRef(arg.Object.ImmOrOwnedObject)
|
|
318
|
+
);
|
|
319
|
+
} else if ("SharedObject" in arg.Object) {
|
|
320
|
+
return tx.object(
|
|
321
|
+
import_transactions.Inputs.SharedObjectRef(
|
|
322
|
+
arg.Object.SharedObject
|
|
323
|
+
)
|
|
324
|
+
);
|
|
325
|
+
} else if ("Receiving" in arg.Object) {
|
|
326
|
+
return tx.object(import_transactions.Inputs.ReceivingRef(arg.Object.Receiving));
|
|
276
327
|
} else {
|
|
277
328
|
throw new Error("Invalid argument type");
|
|
278
329
|
}
|
|
@@ -284,108 +335,123 @@ function convertObjArg(txb, arg) {
|
|
|
284
335
|
}
|
|
285
336
|
|
|
286
337
|
// src/libs/suiTxBuilder/index.ts
|
|
287
|
-
var
|
|
338
|
+
var SuiTx = class {
|
|
288
339
|
constructor(transaction) {
|
|
289
|
-
|
|
340
|
+
if (transaction !== void 0) {
|
|
341
|
+
this.tx = import_transactions2.Transaction.from(transaction);
|
|
342
|
+
} else {
|
|
343
|
+
this.tx = new import_transactions2.Transaction();
|
|
344
|
+
}
|
|
290
345
|
}
|
|
291
346
|
/* Directly wrap methods and properties of TransactionBlock */
|
|
292
347
|
get gas() {
|
|
293
|
-
return this.
|
|
348
|
+
return this.tx.gas;
|
|
294
349
|
}
|
|
295
350
|
get blockData() {
|
|
296
|
-
return this.
|
|
351
|
+
return this.tx.blockData;
|
|
352
|
+
}
|
|
353
|
+
autoPure(value, type) {
|
|
354
|
+
if (type === void 0) {
|
|
355
|
+
return convertArgs(this.tx, [value]);
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
297
358
|
}
|
|
298
359
|
address(value) {
|
|
299
|
-
return this.
|
|
360
|
+
return this.tx.pure.address(value);
|
|
300
361
|
}
|
|
301
|
-
pure(value
|
|
302
|
-
return this.
|
|
362
|
+
pure(value) {
|
|
363
|
+
return this.tx.pure(value);
|
|
303
364
|
}
|
|
304
365
|
object(value) {
|
|
305
|
-
return this.
|
|
366
|
+
return this.tx.object(value);
|
|
306
367
|
}
|
|
307
368
|
objectRef(ref) {
|
|
308
|
-
return this.
|
|
369
|
+
return this.tx.objectRef(ref);
|
|
309
370
|
}
|
|
310
371
|
sharedObjectRef(ref) {
|
|
311
|
-
return this.
|
|
372
|
+
return this.tx.sharedObjectRef(ref);
|
|
312
373
|
}
|
|
313
374
|
setSender(sender) {
|
|
314
|
-
return this.
|
|
375
|
+
return this.tx.setSender(sender);
|
|
315
376
|
}
|
|
316
377
|
setSenderIfNotSet(sender) {
|
|
317
|
-
return this.
|
|
378
|
+
return this.tx.setSenderIfNotSet(sender);
|
|
318
379
|
}
|
|
319
380
|
setExpiration(expiration) {
|
|
320
|
-
return this.
|
|
381
|
+
return this.tx.setExpiration(expiration);
|
|
321
382
|
}
|
|
322
383
|
setGasPrice(price) {
|
|
323
|
-
return this.
|
|
384
|
+
return this.tx.setGasPrice(price);
|
|
324
385
|
}
|
|
325
386
|
setGasBudget(budget) {
|
|
326
|
-
return this.
|
|
387
|
+
return this.tx.setGasBudget(budget);
|
|
327
388
|
}
|
|
328
389
|
setGasOwner(owner) {
|
|
329
|
-
return this.
|
|
390
|
+
return this.tx.setGasOwner(owner);
|
|
330
391
|
}
|
|
331
392
|
setGasPayment(payments) {
|
|
332
|
-
return this.
|
|
393
|
+
return this.tx.setGasPayment(payments);
|
|
333
394
|
}
|
|
334
395
|
serialize() {
|
|
335
|
-
return this.
|
|
396
|
+
return this.tx.serialize();
|
|
336
397
|
}
|
|
337
398
|
sign(params) {
|
|
338
|
-
return this.
|
|
399
|
+
return this.tx.sign(params);
|
|
339
400
|
}
|
|
340
401
|
build(params = {}) {
|
|
341
|
-
return this.
|
|
402
|
+
return this.tx.build(params);
|
|
342
403
|
}
|
|
343
404
|
getDigest(params = {}) {
|
|
344
|
-
return this.
|
|
405
|
+
return this.tx.getDigest(params);
|
|
345
406
|
}
|
|
346
407
|
add(...args) {
|
|
347
|
-
return this.
|
|
408
|
+
return this.tx.add(...args);
|
|
348
409
|
}
|
|
349
410
|
publish({
|
|
350
411
|
modules,
|
|
351
412
|
dependencies
|
|
352
413
|
}) {
|
|
353
|
-
return this.
|
|
414
|
+
return this.tx.publish({ modules, dependencies });
|
|
354
415
|
}
|
|
355
416
|
upgrade({
|
|
356
417
|
modules,
|
|
357
418
|
dependencies,
|
|
358
|
-
packageId,
|
|
419
|
+
package: packageId,
|
|
359
420
|
ticket
|
|
360
421
|
}) {
|
|
361
|
-
return this.
|
|
422
|
+
return this.tx.upgrade({
|
|
423
|
+
modules,
|
|
424
|
+
dependencies,
|
|
425
|
+
package: packageId,
|
|
426
|
+
ticket
|
|
427
|
+
});
|
|
362
428
|
}
|
|
363
429
|
makeMoveVec({
|
|
364
|
-
|
|
430
|
+
elements,
|
|
365
431
|
type
|
|
366
432
|
}) {
|
|
367
|
-
return this.
|
|
433
|
+
return this.tx.makeMoveVec({ elements, type });
|
|
368
434
|
}
|
|
369
435
|
/* Override methods of TransactionBlock */
|
|
370
436
|
transferObjects(objects, address) {
|
|
371
|
-
return this.
|
|
372
|
-
objects.map((object) => convertObjArg(this.
|
|
373
|
-
convertAddressArg(this.
|
|
437
|
+
return this.tx.transferObjects(
|
|
438
|
+
objects.map((object) => convertObjArg(this.tx, object)),
|
|
439
|
+
convertAddressArg(this.tx, address)
|
|
374
440
|
);
|
|
375
441
|
}
|
|
376
442
|
splitCoins(coin, amounts) {
|
|
377
|
-
const res = this.
|
|
378
|
-
convertObjArg(this.
|
|
379
|
-
convertArgs(this.
|
|
443
|
+
const res = this.tx.splitCoins(
|
|
444
|
+
convertObjArg(this.tx, coin),
|
|
445
|
+
convertArgs(this.tx, amounts)
|
|
380
446
|
);
|
|
381
447
|
return amounts.map((_, i) => res[i]);
|
|
382
448
|
}
|
|
383
449
|
mergeCoins(destination, sources) {
|
|
384
|
-
const destinationObject = convertObjArg(this.
|
|
450
|
+
const destinationObject = convertObjArg(this.tx, destination);
|
|
385
451
|
const sourceObjects = sources.map(
|
|
386
|
-
(source) => convertObjArg(this.
|
|
452
|
+
(source) => convertObjArg(this.tx, source)
|
|
387
453
|
);
|
|
388
|
-
return this.
|
|
454
|
+
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
389
455
|
}
|
|
390
456
|
/**
|
|
391
457
|
* @description Move call
|
|
@@ -400,8 +466,8 @@ var SuiTxBlock = class {
|
|
|
400
466
|
throw new Error(
|
|
401
467
|
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
402
468
|
);
|
|
403
|
-
const convertedArgs = convertArgs(this.
|
|
404
|
-
return this.
|
|
469
|
+
const convertedArgs = convertArgs(this.tx, args);
|
|
470
|
+
return this.tx.moveCall({
|
|
405
471
|
target,
|
|
406
472
|
arguments: convertedArgs,
|
|
407
473
|
typeArguments: typeArgs
|
|
@@ -414,15 +480,15 @@ var SuiTxBlock = class {
|
|
|
414
480
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
415
481
|
);
|
|
416
482
|
}
|
|
417
|
-
const coins = this.
|
|
418
|
-
this.
|
|
419
|
-
convertArgs(this.
|
|
483
|
+
const coins = this.tx.splitCoins(
|
|
484
|
+
this.tx.gas,
|
|
485
|
+
convertArgs(this.tx, amounts)
|
|
420
486
|
);
|
|
421
487
|
const recipientObjects = recipients.map(
|
|
422
|
-
(recipient) => convertAddressArg(this.
|
|
488
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
423
489
|
);
|
|
424
490
|
recipientObjects.forEach((address, index) => {
|
|
425
|
-
this.
|
|
491
|
+
this.tx.transferObjects([coins[index]], address);
|
|
426
492
|
});
|
|
427
493
|
return this;
|
|
428
494
|
}
|
|
@@ -430,32 +496,29 @@ var SuiTxBlock = class {
|
|
|
430
496
|
return this.transferSuiToMany([address], [amount]);
|
|
431
497
|
}
|
|
432
498
|
takeAmountFromCoins(coins, amount) {
|
|
433
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
499
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
434
500
|
const mergedCoin = coinObjects[0];
|
|
435
501
|
if (coins.length > 1) {
|
|
436
|
-
this.
|
|
502
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
437
503
|
}
|
|
438
|
-
const [sendCoin] = this.
|
|
504
|
+
const [sendCoin] = this.tx.splitCoins(
|
|
439
505
|
mergedCoin,
|
|
440
|
-
convertArgs(this.
|
|
506
|
+
convertArgs(this.tx, [amount])
|
|
441
507
|
);
|
|
442
508
|
return [sendCoin, mergedCoin];
|
|
443
509
|
}
|
|
444
510
|
splitSUIFromGas(amounts) {
|
|
445
|
-
return this.
|
|
446
|
-
this.txBlock.gas,
|
|
447
|
-
convertArgs(this.txBlock, amounts)
|
|
448
|
-
);
|
|
511
|
+
return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
|
|
449
512
|
}
|
|
450
513
|
splitMultiCoins(coins, amounts) {
|
|
451
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
514
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
452
515
|
const mergedCoin = coinObjects[0];
|
|
453
516
|
if (coins.length > 1) {
|
|
454
|
-
this.
|
|
517
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
455
518
|
}
|
|
456
|
-
const splitedCoins = this.
|
|
519
|
+
const splitedCoins = this.tx.splitCoins(
|
|
457
520
|
mergedCoin,
|
|
458
|
-
convertArgs(this.
|
|
521
|
+
convertArgs(this.tx, amounts)
|
|
459
522
|
);
|
|
460
523
|
return { splitedCoins, mergedCoin };
|
|
461
524
|
}
|
|
@@ -465,45 +528,42 @@ var SuiTxBlock = class {
|
|
|
465
528
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
466
529
|
);
|
|
467
530
|
}
|
|
468
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
531
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
469
532
|
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
470
533
|
coinObjects,
|
|
471
534
|
amounts
|
|
472
535
|
);
|
|
473
536
|
const recipientObjects = recipients.map(
|
|
474
|
-
(recipient) => convertAddressArg(this.
|
|
537
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
475
538
|
);
|
|
476
539
|
recipientObjects.forEach((address, index) => {
|
|
477
|
-
this.
|
|
540
|
+
this.tx.transferObjects([splitedCoins[index]], address);
|
|
478
541
|
});
|
|
479
|
-
this.
|
|
480
|
-
[mergedCoin],
|
|
481
|
-
convertAddressArg(this.txBlock, sender)
|
|
482
|
-
);
|
|
542
|
+
this.tx.transferObjects([mergedCoin], convertAddressArg(this.tx, sender));
|
|
483
543
|
return this;
|
|
484
544
|
}
|
|
485
545
|
transferCoin(coins, sender, recipient, amount) {
|
|
486
546
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
487
547
|
}
|
|
488
548
|
stakeSui(amount, validatorAddr) {
|
|
489
|
-
const [stakeCoin] = this.
|
|
490
|
-
this.
|
|
491
|
-
convertArgs(this.
|
|
549
|
+
const [stakeCoin] = this.tx.splitCoins(
|
|
550
|
+
this.tx.gas,
|
|
551
|
+
convertArgs(this.tx, [amount])
|
|
492
552
|
);
|
|
493
|
-
return this.
|
|
553
|
+
return this.tx.moveCall({
|
|
494
554
|
target: "0x3::sui_system::request_add_stake",
|
|
495
|
-
arguments: convertArgs(this.
|
|
555
|
+
arguments: convertArgs(this.tx, [
|
|
496
556
|
import_utils3.SUI_SYSTEM_STATE_OBJECT_ID,
|
|
497
557
|
stakeCoin,
|
|
498
|
-
this.
|
|
558
|
+
this.tx.pure.address(validatorAddr.toString())
|
|
499
559
|
])
|
|
500
560
|
});
|
|
501
561
|
}
|
|
502
562
|
};
|
|
503
563
|
|
|
504
564
|
// src/libs/suiInteractor/suiInteractor.ts
|
|
505
|
-
var import_client = require("@mysten/sui
|
|
506
|
-
var import_faucet = require("@mysten/sui
|
|
565
|
+
var import_client = require("@mysten/sui/client");
|
|
566
|
+
var import_faucet = require("@mysten/sui/faucet");
|
|
507
567
|
|
|
508
568
|
// src/libs/suiModel/suiOwnedObject.ts
|
|
509
569
|
var SuiOwnedObject = class {
|
|
@@ -525,8 +585,10 @@ var SuiOwnedObject = class {
|
|
|
525
585
|
return this.objectId;
|
|
526
586
|
}
|
|
527
587
|
return {
|
|
588
|
+
$kind: "Object",
|
|
528
589
|
Object: {
|
|
529
|
-
|
|
590
|
+
$kind: "ImmOrOwnedObject",
|
|
591
|
+
ImmOrOwnedObject: {
|
|
530
592
|
objectId: this.objectId,
|
|
531
593
|
version: this.version,
|
|
532
594
|
digest: this.digest
|
|
@@ -565,8 +627,10 @@ var SuiSharedObject = class {
|
|
|
565
627
|
return this.objectId;
|
|
566
628
|
}
|
|
567
629
|
return {
|
|
630
|
+
$kind: "Object",
|
|
568
631
|
Object: {
|
|
569
|
-
|
|
632
|
+
$kind: "SharedObject",
|
|
633
|
+
SharedObject: {
|
|
570
634
|
objectId: this.objectId,
|
|
571
635
|
initialSharedVersion: this.initialSharedVersion,
|
|
572
636
|
mutable
|
|
@@ -926,7 +990,6 @@ function numberToAddressHex(num) {
|
|
|
926
990
|
}
|
|
927
991
|
|
|
928
992
|
// src/obelisk.ts
|
|
929
|
-
var import_keccak256 = __toESM(require("keccak256"));
|
|
930
993
|
var import_bcs3 = require("@mysten/bcs");
|
|
931
994
|
function isUndefined(value) {
|
|
932
995
|
return value === void 0;
|
|
@@ -952,7 +1015,7 @@ function createTx(meta, fn) {
|
|
|
952
1015
|
}
|
|
953
1016
|
);
|
|
954
1017
|
}
|
|
955
|
-
var _query, _tx, _exec, _read;
|
|
1018
|
+
var _query, _tx, _struct, _exec, _read;
|
|
956
1019
|
var Obelisk = class {
|
|
957
1020
|
/**
|
|
958
1021
|
* Support the following ways to init the ObeliskClient:
|
|
@@ -961,7 +1024,7 @@ var Obelisk = class {
|
|
|
961
1024
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
962
1025
|
*
|
|
963
1026
|
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
964
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
1027
|
+
* @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
|
|
965
1028
|
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
966
1029
|
* @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
967
1030
|
* @param packageId
|
|
@@ -976,6 +1039,7 @@ var Obelisk = class {
|
|
|
976
1039
|
} = {}) {
|
|
977
1040
|
__privateAdd(this, _query, {});
|
|
978
1041
|
__privateAdd(this, _tx, {});
|
|
1042
|
+
__privateAdd(this, _struct, {});
|
|
979
1043
|
__privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
|
|
980
1044
|
if (isRaw === true) {
|
|
981
1045
|
return tx.moveCall({
|
|
@@ -1012,33 +1076,37 @@ var Obelisk = class {
|
|
|
1012
1076
|
this.packageId = packageId;
|
|
1013
1077
|
if (metadata !== void 0) {
|
|
1014
1078
|
this.metadata = metadata;
|
|
1015
|
-
Object.values(metadata).forEach(
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1079
|
+
Object.values(metadata).forEach(
|
|
1080
|
+
(moudlevalue) => {
|
|
1081
|
+
const data = moudlevalue;
|
|
1082
|
+
const moduleName = data.name;
|
|
1083
|
+
Object.entries(data.exposedFunctions).forEach(
|
|
1084
|
+
([funcName, funcvalue]) => {
|
|
1085
|
+
const meta = funcvalue;
|
|
1086
|
+
meta.moduleName = moduleName;
|
|
1087
|
+
meta.funcName = funcName;
|
|
1088
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1089
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
1090
|
+
}
|
|
1091
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1092
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1093
|
+
meta,
|
|
1094
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1098
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
1099
|
+
}
|
|
1100
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1101
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1102
|
+
meta,
|
|
1103
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1042
1110
|
}
|
|
1043
1111
|
this.contractFactory = new SuiContractFactory({
|
|
1044
1112
|
packageId,
|
|
@@ -1051,6 +1119,9 @@ var Obelisk = class {
|
|
|
1051
1119
|
get tx() {
|
|
1052
1120
|
return __privateGet(this, _tx);
|
|
1053
1121
|
}
|
|
1122
|
+
get struct() {
|
|
1123
|
+
return __privateGet(this, _struct);
|
|
1124
|
+
}
|
|
1054
1125
|
/**
|
|
1055
1126
|
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
1056
1127
|
* else:
|
|
@@ -1083,11 +1154,20 @@ var Obelisk = class {
|
|
|
1083
1154
|
getMetadata() {
|
|
1084
1155
|
return this.contractFactory.metadata;
|
|
1085
1156
|
}
|
|
1157
|
+
getNetwork() {
|
|
1158
|
+
return this.suiInteractor.network;
|
|
1159
|
+
}
|
|
1086
1160
|
/**
|
|
1087
1161
|
* Request some SUI from faucet
|
|
1088
1162
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
1089
1163
|
*/
|
|
1090
|
-
async requestFaucet(address, network) {
|
|
1164
|
+
async requestFaucet(address, network, derivePathParams) {
|
|
1165
|
+
if (address === void 0) {
|
|
1166
|
+
address = this.accountManager.getAddress(derivePathParams);
|
|
1167
|
+
}
|
|
1168
|
+
if (network === void 0) {
|
|
1169
|
+
network = this.getNetwork();
|
|
1170
|
+
}
|
|
1091
1171
|
return this.suiInteractor.requestFaucet(address, network);
|
|
1092
1172
|
}
|
|
1093
1173
|
async getBalance(coinType, derivePathParams) {
|
|
@@ -1111,18 +1191,21 @@ var Obelisk = class {
|
|
|
1111
1191
|
return this.suiInteractor.getObjects(objectIds);
|
|
1112
1192
|
}
|
|
1113
1193
|
async signTxn(tx, derivePathParams) {
|
|
1114
|
-
if (tx instanceof
|
|
1194
|
+
if (tx instanceof SuiTx || tx instanceof import_transactions3.Transaction) {
|
|
1115
1195
|
tx.setSender(this.getAddress(derivePathParams));
|
|
1116
1196
|
}
|
|
1117
|
-
const txBlock = tx instanceof
|
|
1118
|
-
const txBytes = txBlock instanceof import_transactions3.
|
|
1197
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
1198
|
+
const txBytes = txBlock instanceof import_transactions3.Transaction ? await txBlock.build({ client: this.client() }) : txBlock;
|
|
1119
1199
|
const keyPair = this.getKeypair(derivePathParams);
|
|
1120
|
-
return await keyPair.
|
|
1200
|
+
return await keyPair.signTransaction(txBytes);
|
|
1121
1201
|
}
|
|
1122
1202
|
async signAndSendTxn(tx, derivePathParams) {
|
|
1123
1203
|
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
1124
1204
|
return this.suiInteractor.sendTx(bytes, signature);
|
|
1125
1205
|
}
|
|
1206
|
+
async sendTxn(transactionBlock, signature) {
|
|
1207
|
+
return this.suiInteractor.sendTx(transactionBlock, signature);
|
|
1208
|
+
}
|
|
1126
1209
|
/**
|
|
1127
1210
|
* Transfer the given amount of SUI to the recipient
|
|
1128
1211
|
* @param recipient
|
|
@@ -1130,7 +1213,7 @@ var Obelisk = class {
|
|
|
1130
1213
|
* @param derivePathParams
|
|
1131
1214
|
*/
|
|
1132
1215
|
async transferSui(recipient, amount, derivePathParams) {
|
|
1133
|
-
const tx = new
|
|
1216
|
+
const tx = new SuiTx();
|
|
1134
1217
|
tx.transferSui(recipient, amount);
|
|
1135
1218
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1136
1219
|
}
|
|
@@ -1141,7 +1224,7 @@ var Obelisk = class {
|
|
|
1141
1224
|
* @param derivePathParams
|
|
1142
1225
|
*/
|
|
1143
1226
|
async transferSuiToMany(recipients, amounts, derivePathParams) {
|
|
1144
|
-
const tx = new
|
|
1227
|
+
const tx = new SuiTx();
|
|
1145
1228
|
tx.transferSuiToMany(recipients, amounts);
|
|
1146
1229
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1147
1230
|
}
|
|
@@ -1153,7 +1236,7 @@ var Obelisk = class {
|
|
|
1153
1236
|
* @param derivePathParams the derive path params for the current signer
|
|
1154
1237
|
*/
|
|
1155
1238
|
async transferCoinToMany(recipients, amounts, coinType, derivePathParams) {
|
|
1156
|
-
const tx = new
|
|
1239
|
+
const tx = new SuiTx();
|
|
1157
1240
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
1158
1241
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
1159
1242
|
const coins = await this.suiInteractor.selectCoins(
|
|
@@ -1178,7 +1261,7 @@ var Obelisk = class {
|
|
|
1178
1261
|
);
|
|
1179
1262
|
}
|
|
1180
1263
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
1181
|
-
const tx = new
|
|
1264
|
+
const tx = new SuiTx();
|
|
1182
1265
|
tx.transferObjects(objects, recipient);
|
|
1183
1266
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1184
1267
|
}
|
|
@@ -1189,7 +1272,7 @@ var Obelisk = class {
|
|
|
1189
1272
|
typeArguments = [],
|
|
1190
1273
|
derivePathParams
|
|
1191
1274
|
} = callParams;
|
|
1192
|
-
const tx = new
|
|
1275
|
+
const tx = new SuiTx();
|
|
1193
1276
|
tx.moveCall(target, args, typeArguments);
|
|
1194
1277
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1195
1278
|
}
|
|
@@ -1216,7 +1299,7 @@ var Obelisk = class {
|
|
|
1216
1299
|
* @param derivePathParams the derive path params for the current signer
|
|
1217
1300
|
*/
|
|
1218
1301
|
async stakeSui(amount, validatorAddr, derivePathParams) {
|
|
1219
|
-
const tx = new
|
|
1302
|
+
const tx = new SuiTx();
|
|
1220
1303
|
tx.stakeSui(amount, validatorAddr);
|
|
1221
1304
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1222
1305
|
}
|
|
@@ -1228,7 +1311,7 @@ var Obelisk = class {
|
|
|
1228
1311
|
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
1229
1312
|
*/
|
|
1230
1313
|
async inspectTxn(tx, derivePathParams) {
|
|
1231
|
-
const txBlock = tx instanceof
|
|
1314
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
1232
1315
|
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
1233
1316
|
transactionBlock: txBlock,
|
|
1234
1317
|
sender: this.getAddress(derivePathParams)
|
|
@@ -1250,36 +1333,62 @@ var Obelisk = class {
|
|
|
1250
1333
|
}
|
|
1251
1334
|
async getEntity(worldId, schemaName, entityId) {
|
|
1252
1335
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1253
|
-
const tx = new import_transactions3.
|
|
1254
|
-
const params = [tx.pure(worldId)];
|
|
1336
|
+
const tx = new import_transactions3.Transaction();
|
|
1337
|
+
const params = [tx.pure.address(worldId)];
|
|
1255
1338
|
if (entityId !== void 0) {
|
|
1256
|
-
params.push(tx.pure(entityId));
|
|
1339
|
+
params.push(tx.pure.address(entityId));
|
|
1257
1340
|
}
|
|
1258
1341
|
const getResult = await this.query[schemaModuleName].get(
|
|
1259
1342
|
tx,
|
|
1260
1343
|
params
|
|
1261
1344
|
);
|
|
1262
|
-
let
|
|
1345
|
+
let returnValues = [];
|
|
1263
1346
|
if (getResult.effects.status.status === "success") {
|
|
1264
1347
|
const resultList = getResult.results[0].returnValues;
|
|
1265
1348
|
for (const res of resultList) {
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
|
|
1349
|
+
let baseValue = res[0];
|
|
1350
|
+
let baseType = res[1];
|
|
1351
|
+
const value = Uint8Array.from(baseValue);
|
|
1352
|
+
if (baseType === "address") {
|
|
1353
|
+
const Address = import_bcs3.bcs.bytes(32).transform({
|
|
1354
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1355
|
+
input: (val) => (0, import_bcs3.fromHEX)(val),
|
|
1356
|
+
output: (val) => (0, import_bcs3.toHEX)(val)
|
|
1357
|
+
});
|
|
1358
|
+
returnValues.push(Address.parse(value));
|
|
1359
|
+
} else if (baseType === "u8") {
|
|
1360
|
+
returnValues.push(import_bcs3.bcs.u8().parse(value));
|
|
1361
|
+
} else if (baseType === "u16") {
|
|
1362
|
+
returnValues.push(import_bcs3.bcs.u16().parse(value));
|
|
1363
|
+
} else if (baseType === "u32") {
|
|
1364
|
+
returnValues.push(import_bcs3.bcs.u32().parse(value));
|
|
1365
|
+
} else if (baseType === "u64") {
|
|
1366
|
+
returnValues.push(import_bcs3.bcs.u64().parse(value));
|
|
1367
|
+
} else if (baseType === "u128") {
|
|
1368
|
+
returnValues.push(import_bcs3.bcs.u128().parse(value));
|
|
1369
|
+
} else if (baseType === "u256") {
|
|
1370
|
+
returnValues.push(import_bcs3.bcs.u256().parse(value));
|
|
1371
|
+
} else if (baseType === "bool") {
|
|
1372
|
+
returnValues.push(import_bcs3.bcs.bool().parse(value));
|
|
1373
|
+
} else if (baseType === "0x1::ascii::String") {
|
|
1374
|
+
returnValues.push(import_bcs3.bcs.string().parse(value));
|
|
1375
|
+
} else if (baseType === "vector<u8>") {
|
|
1376
|
+
returnValues.push(import_bcs3.bcs.vector(import_bcs3.bcs.u8()).parse(value));
|
|
1377
|
+
} else if (baseType === "0x1::option::Option<u8>") {
|
|
1378
|
+
returnValues.push(import_bcs3.bcs.option(import_bcs3.bcs.u8()).parse(value));
|
|
1379
|
+
}
|
|
1271
1380
|
}
|
|
1272
|
-
return
|
|
1381
|
+
return returnValues;
|
|
1273
1382
|
} else {
|
|
1274
1383
|
return void 0;
|
|
1275
1384
|
}
|
|
1276
1385
|
}
|
|
1277
1386
|
async containEntity(worldId, schemaName, entityId) {
|
|
1278
1387
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1279
|
-
const tx = new import_transactions3.
|
|
1280
|
-
const params = [tx.pure(worldId)];
|
|
1388
|
+
const tx = new import_transactions3.Transaction();
|
|
1389
|
+
const params = [tx.pure.address(worldId)];
|
|
1281
1390
|
if (entityId !== void 0) {
|
|
1282
|
-
params.push(tx.pure(entityId));
|
|
1391
|
+
params.push(tx.pure.address(entityId));
|
|
1283
1392
|
}
|
|
1284
1393
|
const getResult = await this.query[schemaModuleName].contains(
|
|
1285
1394
|
tx,
|
|
@@ -1287,9 +1396,9 @@ var Obelisk = class {
|
|
|
1287
1396
|
);
|
|
1288
1397
|
if (getResult.effects.status.status === "success") {
|
|
1289
1398
|
const res = getResult.results[0].returnValues[0];
|
|
1290
|
-
|
|
1291
|
-
const value = Uint8Array.from(
|
|
1292
|
-
return bcs.
|
|
1399
|
+
let baseValue = res[0];
|
|
1400
|
+
const value = Uint8Array.from(baseValue);
|
|
1401
|
+
return import_bcs3.bcs.bool().parse(value);
|
|
1293
1402
|
} else {
|
|
1294
1403
|
return void 0;
|
|
1295
1404
|
}
|
|
@@ -1351,9 +1460,13 @@ var Obelisk = class {
|
|
|
1351
1460
|
async entity_key_from_bytes(bytes) {
|
|
1352
1461
|
const hashBytes = (0, import_keccak256.default)(bytes);
|
|
1353
1462
|
const hashU8Array = Array.from(hashBytes);
|
|
1354
|
-
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1355
1463
|
const value = Uint8Array.from(hashU8Array);
|
|
1356
|
-
const
|
|
1464
|
+
const Address = import_bcs3.bcs.bytes(32).transform({
|
|
1465
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1466
|
+
input: (val) => (0, import_bcs3.fromHEX)(val),
|
|
1467
|
+
output: (val) => (0, import_bcs3.toHEX)(val)
|
|
1468
|
+
});
|
|
1469
|
+
const data = Address.parse(value);
|
|
1357
1470
|
return "0x" + data;
|
|
1358
1471
|
}
|
|
1359
1472
|
async entity_key_from_address_with_seed(objectId, seed) {
|
|
@@ -1371,9 +1484,8 @@ var Obelisk = class {
|
|
|
1371
1484
|
const checkObjectId = normalizeHexAddress(objectId);
|
|
1372
1485
|
if (checkObjectId !== null) {
|
|
1373
1486
|
objectId = checkObjectId;
|
|
1374
|
-
const bcs = new import_bcs3.BCS((0, import_bcs3.getSuiMoveConfig)());
|
|
1375
1487
|
const bytes = Buffer.from(objectId.slice(2), "hex");
|
|
1376
|
-
const numberBytes = bcs.
|
|
1488
|
+
const numberBytes = import_bcs3.bcs.u256().serialize(x).toBytes();
|
|
1377
1489
|
return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
|
|
1378
1490
|
} else {
|
|
1379
1491
|
return void 0;
|
|
@@ -1382,23 +1494,65 @@ var Obelisk = class {
|
|
|
1382
1494
|
async entity_key_from_u256(x) {
|
|
1383
1495
|
return numberToAddressHex(x);
|
|
1384
1496
|
}
|
|
1385
|
-
async formatData(type, value) {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1497
|
+
// async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
1498
|
+
// const u8Value = Uint8Array.from(value);
|
|
1499
|
+
// return bcs.de(type, u8Value);
|
|
1500
|
+
// }
|
|
1501
|
+
async autoFormatDryValue(value) {
|
|
1502
|
+
let returnValues = [];
|
|
1503
|
+
if (value.effects.status.status === "success") {
|
|
1504
|
+
const resultList = value.results[0].returnValues;
|
|
1505
|
+
for (const res of resultList) {
|
|
1506
|
+
let baseValue = res[0];
|
|
1507
|
+
let baseType = res[1];
|
|
1508
|
+
const value2 = Uint8Array.from(baseValue);
|
|
1509
|
+
if (baseType === "address") {
|
|
1510
|
+
const Address = import_bcs3.bcs.bytes(32).transform({
|
|
1511
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1512
|
+
input: (val) => (0, import_bcs3.fromHEX)(val),
|
|
1513
|
+
output: (val) => (0, import_bcs3.toHEX)(val)
|
|
1514
|
+
});
|
|
1515
|
+
returnValues.push(Address.parse(value2));
|
|
1516
|
+
} else if (baseType === "u8") {
|
|
1517
|
+
returnValues.push(import_bcs3.bcs.u8().parse(value2));
|
|
1518
|
+
} else if (baseType === "u16") {
|
|
1519
|
+
returnValues.push(import_bcs3.bcs.u16().parse(value2));
|
|
1520
|
+
} else if (baseType === "u32") {
|
|
1521
|
+
returnValues.push(import_bcs3.bcs.u32().parse(value2));
|
|
1522
|
+
} else if (baseType === "u64") {
|
|
1523
|
+
returnValues.push(import_bcs3.bcs.u64().parse(value2));
|
|
1524
|
+
} else if (baseType === "u128") {
|
|
1525
|
+
returnValues.push(import_bcs3.bcs.u128().parse(value2));
|
|
1526
|
+
} else if (baseType === "u256") {
|
|
1527
|
+
returnValues.push(import_bcs3.bcs.u256().parse(value2));
|
|
1528
|
+
} else if (baseType === "bool") {
|
|
1529
|
+
returnValues.push(import_bcs3.bcs.bool().parse(value2));
|
|
1530
|
+
} else if (baseType === "0x1::ascii::String") {
|
|
1531
|
+
returnValues.push(import_bcs3.bcs.string().parse(value2));
|
|
1532
|
+
} else if (baseType === "vector<u8>") {
|
|
1533
|
+
returnValues.push(import_bcs3.bcs.vector(import_bcs3.bcs.u8()).parse(value2));
|
|
1534
|
+
} else if (baseType === "0x1::option::Option<u8>") {
|
|
1535
|
+
returnValues.push(import_bcs3.bcs.option(import_bcs3.bcs.u8()).parse(value2));
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return returnValues;
|
|
1539
|
+
} else {
|
|
1540
|
+
return void 0;
|
|
1541
|
+
}
|
|
1389
1542
|
}
|
|
1390
1543
|
};
|
|
1391
1544
|
_query = new WeakMap();
|
|
1392
1545
|
_tx = new WeakMap();
|
|
1546
|
+
_struct = new WeakMap();
|
|
1393
1547
|
_exec = new WeakMap();
|
|
1394
1548
|
_read = new WeakMap();
|
|
1395
1549
|
|
|
1396
1550
|
// src/libs/multiSig/client.ts
|
|
1397
|
-
var import_multisig = require("@mysten/sui
|
|
1551
|
+
var import_multisig = require("@mysten/sui/multisig");
|
|
1398
1552
|
|
|
1399
1553
|
// src/libs/multiSig/publickey.ts
|
|
1400
|
-
var import_ed255193 = require("@mysten/sui
|
|
1401
|
-
var import_utils5 = require("@mysten/sui
|
|
1554
|
+
var import_ed255193 = require("@mysten/sui/keypairs/ed25519");
|
|
1555
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
1402
1556
|
function ed25519PublicKeyFromBase64(rawPubkey) {
|
|
1403
1557
|
let bytes = (0, import_utils5.fromB64)(rawPubkey);
|
|
1404
1558
|
if (bytes.length !== 32 && bytes.length !== 33)
|
|
@@ -1435,7 +1589,7 @@ var MultiSigClient = class _MultiSigClient {
|
|
|
1435
1589
|
};
|
|
1436
1590
|
|
|
1437
1591
|
// src/metadata/index.ts
|
|
1438
|
-
var import_client4 = require("@mysten/sui
|
|
1592
|
+
var import_client4 = require("@mysten/sui/client");
|
|
1439
1593
|
async function loadMetadata(networkType, packageId) {
|
|
1440
1594
|
const fullnodeUrls = [(0, import_client4.getFullnodeUrl)(networkType)];
|
|
1441
1595
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
@@ -1450,19 +1604,20 @@ async function loadMetadata(networkType, packageId) {
|
|
|
1450
1604
|
}
|
|
1451
1605
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1452
1606
|
0 && (module.exports = {
|
|
1453
|
-
|
|
1607
|
+
BcsType,
|
|
1454
1608
|
MultiSigClient,
|
|
1455
1609
|
Obelisk,
|
|
1456
1610
|
SuiAccountManager,
|
|
1457
1611
|
SuiContractFactory,
|
|
1458
|
-
|
|
1459
|
-
|
|
1612
|
+
SuiTx,
|
|
1613
|
+
bcs,
|
|
1460
1614
|
loadMetadata,
|
|
1461
|
-
...require("@mysten/sui
|
|
1462
|
-
...require("@mysten/sui
|
|
1463
|
-
...require("@mysten/sui
|
|
1464
|
-
...require("@mysten/sui
|
|
1465
|
-
...require("@mysten/sui
|
|
1466
|
-
...require("@mysten/sui
|
|
1615
|
+
...require("@mysten/sui/client"),
|
|
1616
|
+
...require("@mysten/sui/utils"),
|
|
1617
|
+
...require("@mysten/sui/transactions"),
|
|
1618
|
+
...require("@mysten/sui/bcs"),
|
|
1619
|
+
...require("@mysten/sui/keypairs/ed25519"),
|
|
1620
|
+
...require("@mysten/sui/keypairs/secp256k1"),
|
|
1621
|
+
...require("@mysten/sui/keypairs/secp256r1")
|
|
1467
1622
|
});
|
|
1468
1623
|
//# sourceMappingURL=index.js.map
|