@0xobelisk/sui-client 0.5.17 → 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 +343 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +333 -194
- 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 +6 -5
- 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 +199 -90
- 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 -39
- 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.mjs
CHANGED
|
@@ -13,25 +13,29 @@ var __privateAdd = (obj, member, value) => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// src/index.ts
|
|
16
|
-
export * from "@mysten/sui
|
|
17
|
-
export * from "@mysten/sui
|
|
18
|
-
export * from "@mysten/sui
|
|
19
|
-
export * from "@mysten/sui
|
|
20
|
-
export * from "@mysten/sui
|
|
21
|
-
export * from "@mysten/sui
|
|
22
|
-
|
|
16
|
+
export * from "@mysten/sui/client";
|
|
17
|
+
export * from "@mysten/sui/utils";
|
|
18
|
+
export * from "@mysten/sui/transactions";
|
|
19
|
+
export * from "@mysten/sui/bcs";
|
|
20
|
+
export * from "@mysten/sui/keypairs/ed25519";
|
|
21
|
+
export * from "@mysten/sui/keypairs/secp256k1";
|
|
22
|
+
export * from "@mysten/sui/keypairs/secp256r1";
|
|
23
|
+
import { bcs as bcs3, BcsType } from "@mysten/bcs";
|
|
23
24
|
|
|
24
25
|
// src/obelisk.ts
|
|
25
|
-
import
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
} from "@mysten/sui.js/transactions";
|
|
26
|
+
import keccak256 from "keccak256";
|
|
27
|
+
import { getFullnodeUrl } from "@mysten/sui/client";
|
|
28
|
+
import { Transaction as Transaction2 } from "@mysten/sui/transactions";
|
|
29
29
|
|
|
30
30
|
// src/libs/suiAccountManager/index.ts
|
|
31
|
-
import { Ed25519Keypair as Ed25519Keypair2 } from "@mysten/sui
|
|
31
|
+
import { Ed25519Keypair as Ed25519Keypair2 } from "@mysten/sui/keypairs/ed25519";
|
|
32
|
+
import {
|
|
33
|
+
SUI_PRIVATE_KEY_PREFIX,
|
|
34
|
+
decodeSuiPrivateKey
|
|
35
|
+
} from "@mysten/sui/cryptography";
|
|
32
36
|
|
|
33
37
|
// src/libs/suiAccountManager/keypair.ts
|
|
34
|
-
import { Ed25519Keypair } from "@mysten/sui
|
|
38
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
35
39
|
var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
36
40
|
const {
|
|
37
41
|
accountIndex = 0,
|
|
@@ -46,7 +50,7 @@ var getKeyPair = (mnemonics, derivePathParams = {}) => {
|
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
// src/libs/suiAccountManager/util.ts
|
|
49
|
-
import { fromB64 } from "@mysten/sui
|
|
53
|
+
import { fromB64 } from "@mysten/sui/utils";
|
|
50
54
|
var isHex = (str) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);
|
|
51
55
|
var isBase64 = (str) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);
|
|
52
56
|
var fromHEX = (hexStr) => {
|
|
@@ -90,10 +94,6 @@ var generateMnemonic = (numberOfWords = 24) => {
|
|
|
90
94
|
};
|
|
91
95
|
|
|
92
96
|
// src/libs/suiAccountManager/index.ts
|
|
93
|
-
import {
|
|
94
|
-
SUI_PRIVATE_KEY_PREFIX,
|
|
95
|
-
decodeSuiPrivateKey
|
|
96
|
-
} from "@mysten/sui.js/cryptography";
|
|
97
97
|
var SuiAccountManager = class {
|
|
98
98
|
/**
|
|
99
99
|
* Support the following ways to init the SuiToolkit:
|
|
@@ -160,8 +160,8 @@ var SuiAccountManager = class {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
// src/libs/suiTxBuilder/index.ts
|
|
163
|
-
import {
|
|
164
|
-
import { SUI_SYSTEM_STATE_OBJECT_ID } from "@mysten/sui
|
|
163
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
164
|
+
import { SUI_SYSTEM_STATE_OBJECT_ID } from "@mysten/sui/utils";
|
|
165
165
|
|
|
166
166
|
// src/libs/suiTxBuilder/util.ts
|
|
167
167
|
import {
|
|
@@ -169,10 +169,10 @@ import {
|
|
|
169
169
|
normalizeSuiAddress,
|
|
170
170
|
isValidSuiObjectId,
|
|
171
171
|
isValidSuiAddress
|
|
172
|
-
} from "@mysten/sui
|
|
173
|
-
import { Inputs } from "@mysten/sui
|
|
174
|
-
import { isPureArg } from "@mysten/sui.js/bcs";
|
|
172
|
+
} from "@mysten/sui/utils";
|
|
173
|
+
import { Inputs } from "@mysten/sui/transactions";
|
|
175
174
|
import { isSerializedBcs } from "@mysten/bcs";
|
|
175
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
176
176
|
var getDefaultSuiInputType = (value) => {
|
|
177
177
|
if (typeof value === "string" && isValidSuiObjectId(value)) {
|
|
178
178
|
return "object";
|
|
@@ -184,7 +184,10 @@ var getDefaultSuiInputType = (value) => {
|
|
|
184
184
|
return void 0;
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
|
-
function
|
|
187
|
+
function isPureArg(arg) {
|
|
188
|
+
return arg.Pure !== void 0;
|
|
189
|
+
}
|
|
190
|
+
function makeVecParam(tx, args, type) {
|
|
188
191
|
if (args.length === 0)
|
|
189
192
|
throw new Error("Transaction builder error: Empty array is not allowed");
|
|
190
193
|
const defaultSuiType = getDefaultSuiInputType(args[0]);
|
|
@@ -192,17 +195,33 @@ function makeVecParam(txBlock, args, type) {
|
|
|
192
195
|
const STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
|
|
193
196
|
type = type || defaultSuiType;
|
|
194
197
|
if (type === "object") {
|
|
195
|
-
const
|
|
196
|
-
(arg) => typeof arg === "string" && isValidSuiObjectId(arg) ?
|
|
198
|
+
const elements = args.map(
|
|
199
|
+
(arg) => typeof arg === "string" && isValidSuiObjectId(arg) ? tx.object(normalizeSuiObjectId(arg)) : convertObjArg(tx, arg)
|
|
197
200
|
);
|
|
198
|
-
return
|
|
201
|
+
return tx.makeMoveVec({ elements });
|
|
199
202
|
} else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
|
|
200
|
-
|
|
203
|
+
if (type === "address") {
|
|
204
|
+
return tx.pure(bcs.vector(bcs.Address).serialize(args));
|
|
205
|
+
} else if (type === "bool") {
|
|
206
|
+
return tx.pure(bcs.vector(bcs.Bool).serialize(args));
|
|
207
|
+
} else if (type === "u8") {
|
|
208
|
+
return tx.pure(bcs.vector(bcs.U8).serialize(args));
|
|
209
|
+
} else if (type === "u16") {
|
|
210
|
+
return tx.pure(bcs.vector(bcs.U16).serialize(args));
|
|
211
|
+
} else if (type === "u32") {
|
|
212
|
+
return tx.pure(bcs.vector(bcs.U32).serialize(args));
|
|
213
|
+
} else if (type === "u64") {
|
|
214
|
+
return tx.pure(bcs.vector(bcs.U64).serialize(args));
|
|
215
|
+
} else if (type === "u128") {
|
|
216
|
+
return tx.pure(bcs.vector(bcs.U128).serialize(args));
|
|
217
|
+
} else if (type === "u256") {
|
|
218
|
+
return tx.pure(bcs.vector(bcs.U256).serialize(args));
|
|
219
|
+
} else {
|
|
220
|
+
return tx.pure(bcs.vector(bcs.U8).serialize(args));
|
|
221
|
+
}
|
|
201
222
|
} else {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
);
|
|
205
|
-
return txBlock.makeMoveVec({ objects, type });
|
|
223
|
+
const elements = args.map((arg) => convertObjArg(tx, arg));
|
|
224
|
+
return tx.makeMoveVec({ elements, type });
|
|
206
225
|
}
|
|
207
226
|
}
|
|
208
227
|
function isMoveVecArg(arg) {
|
|
@@ -213,48 +232,65 @@ function isMoveVecArg(arg) {
|
|
|
213
232
|
}
|
|
214
233
|
return false;
|
|
215
234
|
}
|
|
216
|
-
function convertArgs(
|
|
235
|
+
function convertArgs(tx, args) {
|
|
217
236
|
return args.map((arg) => {
|
|
218
237
|
if (typeof arg === "string" && isValidSuiObjectId(arg)) {
|
|
219
|
-
return
|
|
238
|
+
return tx.object(normalizeSuiObjectId(arg));
|
|
220
239
|
} else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg) && !isMoveVecArg(arg)) {
|
|
221
|
-
return convertObjArg(
|
|
240
|
+
return convertObjArg(tx, arg);
|
|
222
241
|
} else if (isMoveVecArg(arg)) {
|
|
223
242
|
const vecType = "vecType" in arg;
|
|
224
|
-
return vecType ? makeVecParam(
|
|
243
|
+
return vecType ? makeVecParam(tx, arg.value, arg.vecType) : makeVecParam(tx, arg);
|
|
225
244
|
} else if (isSerializedBcs(arg)) {
|
|
226
245
|
return arg;
|
|
227
246
|
} else {
|
|
228
|
-
|
|
247
|
+
let argType = getDefaultSuiInputType(arg);
|
|
248
|
+
if (argType === "address") {
|
|
249
|
+
return tx.pure.address(arg);
|
|
250
|
+
} else if (argType === "u64") {
|
|
251
|
+
return tx.pure.u64(arg);
|
|
252
|
+
} else if (argType === "bool") {
|
|
253
|
+
return tx.pure.bool(arg);
|
|
254
|
+
} else {
|
|
255
|
+
return tx.pure.u64(arg);
|
|
256
|
+
}
|
|
229
257
|
}
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
|
-
function convertAddressArg(
|
|
260
|
+
function convertAddressArg(tx, arg) {
|
|
233
261
|
if (typeof arg === "string" && isValidSuiAddress(arg)) {
|
|
234
|
-
return
|
|
262
|
+
return tx.pure.address(normalizeSuiAddress(arg));
|
|
235
263
|
} else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg)) {
|
|
236
|
-
return convertObjArg(
|
|
264
|
+
return convertObjArg(tx, arg);
|
|
237
265
|
} else if (isPureArg(arg)) {
|
|
238
|
-
return
|
|
266
|
+
return tx.pure(Uint8Array.from(arg.Pure));
|
|
239
267
|
} else {
|
|
240
268
|
return arg;
|
|
241
269
|
}
|
|
242
270
|
}
|
|
243
|
-
function convertObjArg(
|
|
271
|
+
function convertObjArg(tx, arg) {
|
|
244
272
|
if (typeof arg === "string") {
|
|
245
|
-
return
|
|
273
|
+
return tx.object(arg);
|
|
246
274
|
}
|
|
247
275
|
if ("digest" in arg && "version" in arg && "objectId" in arg) {
|
|
248
|
-
return
|
|
276
|
+
return tx.objectRef(arg);
|
|
249
277
|
}
|
|
250
278
|
if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
|
|
251
|
-
return
|
|
279
|
+
return tx.sharedObjectRef(arg);
|
|
252
280
|
}
|
|
253
281
|
if ("Object" in arg) {
|
|
254
|
-
if ("
|
|
255
|
-
return
|
|
256
|
-
|
|
257
|
-
|
|
282
|
+
if ("ImmOrOwnedObject" in arg.Object) {
|
|
283
|
+
return tx.object(
|
|
284
|
+
Inputs.ObjectRef(arg.Object.ImmOrOwnedObject)
|
|
285
|
+
);
|
|
286
|
+
} else if ("SharedObject" in arg.Object) {
|
|
287
|
+
return tx.object(
|
|
288
|
+
Inputs.SharedObjectRef(
|
|
289
|
+
arg.Object.SharedObject
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
} else if ("Receiving" in arg.Object) {
|
|
293
|
+
return tx.object(Inputs.ReceivingRef(arg.Object.Receiving));
|
|
258
294
|
} else {
|
|
259
295
|
throw new Error("Invalid argument type");
|
|
260
296
|
}
|
|
@@ -266,108 +302,123 @@ function convertObjArg(txb, arg) {
|
|
|
266
302
|
}
|
|
267
303
|
|
|
268
304
|
// src/libs/suiTxBuilder/index.ts
|
|
269
|
-
var
|
|
305
|
+
var SuiTx = class {
|
|
270
306
|
constructor(transaction) {
|
|
271
|
-
|
|
307
|
+
if (transaction !== void 0) {
|
|
308
|
+
this.tx = Transaction.from(transaction);
|
|
309
|
+
} else {
|
|
310
|
+
this.tx = new Transaction();
|
|
311
|
+
}
|
|
272
312
|
}
|
|
273
313
|
/* Directly wrap methods and properties of TransactionBlock */
|
|
274
314
|
get gas() {
|
|
275
|
-
return this.
|
|
315
|
+
return this.tx.gas;
|
|
276
316
|
}
|
|
277
317
|
get blockData() {
|
|
278
|
-
return this.
|
|
318
|
+
return this.tx.blockData;
|
|
319
|
+
}
|
|
320
|
+
autoPure(value, type) {
|
|
321
|
+
if (type === void 0) {
|
|
322
|
+
return convertArgs(this.tx, [value]);
|
|
323
|
+
}
|
|
324
|
+
return;
|
|
279
325
|
}
|
|
280
326
|
address(value) {
|
|
281
|
-
return this.
|
|
327
|
+
return this.tx.pure.address(value);
|
|
282
328
|
}
|
|
283
|
-
pure(value
|
|
284
|
-
return this.
|
|
329
|
+
pure(value) {
|
|
330
|
+
return this.tx.pure(value);
|
|
285
331
|
}
|
|
286
332
|
object(value) {
|
|
287
|
-
return this.
|
|
333
|
+
return this.tx.object(value);
|
|
288
334
|
}
|
|
289
335
|
objectRef(ref) {
|
|
290
|
-
return this.
|
|
336
|
+
return this.tx.objectRef(ref);
|
|
291
337
|
}
|
|
292
338
|
sharedObjectRef(ref) {
|
|
293
|
-
return this.
|
|
339
|
+
return this.tx.sharedObjectRef(ref);
|
|
294
340
|
}
|
|
295
341
|
setSender(sender) {
|
|
296
|
-
return this.
|
|
342
|
+
return this.tx.setSender(sender);
|
|
297
343
|
}
|
|
298
344
|
setSenderIfNotSet(sender) {
|
|
299
|
-
return this.
|
|
345
|
+
return this.tx.setSenderIfNotSet(sender);
|
|
300
346
|
}
|
|
301
347
|
setExpiration(expiration) {
|
|
302
|
-
return this.
|
|
348
|
+
return this.tx.setExpiration(expiration);
|
|
303
349
|
}
|
|
304
350
|
setGasPrice(price) {
|
|
305
|
-
return this.
|
|
351
|
+
return this.tx.setGasPrice(price);
|
|
306
352
|
}
|
|
307
353
|
setGasBudget(budget) {
|
|
308
|
-
return this.
|
|
354
|
+
return this.tx.setGasBudget(budget);
|
|
309
355
|
}
|
|
310
356
|
setGasOwner(owner) {
|
|
311
|
-
return this.
|
|
357
|
+
return this.tx.setGasOwner(owner);
|
|
312
358
|
}
|
|
313
359
|
setGasPayment(payments) {
|
|
314
|
-
return this.
|
|
360
|
+
return this.tx.setGasPayment(payments);
|
|
315
361
|
}
|
|
316
362
|
serialize() {
|
|
317
|
-
return this.
|
|
363
|
+
return this.tx.serialize();
|
|
318
364
|
}
|
|
319
365
|
sign(params) {
|
|
320
|
-
return this.
|
|
366
|
+
return this.tx.sign(params);
|
|
321
367
|
}
|
|
322
368
|
build(params = {}) {
|
|
323
|
-
return this.
|
|
369
|
+
return this.tx.build(params);
|
|
324
370
|
}
|
|
325
371
|
getDigest(params = {}) {
|
|
326
|
-
return this.
|
|
372
|
+
return this.tx.getDigest(params);
|
|
327
373
|
}
|
|
328
374
|
add(...args) {
|
|
329
|
-
return this.
|
|
375
|
+
return this.tx.add(...args);
|
|
330
376
|
}
|
|
331
377
|
publish({
|
|
332
378
|
modules,
|
|
333
379
|
dependencies
|
|
334
380
|
}) {
|
|
335
|
-
return this.
|
|
381
|
+
return this.tx.publish({ modules, dependencies });
|
|
336
382
|
}
|
|
337
383
|
upgrade({
|
|
338
384
|
modules,
|
|
339
385
|
dependencies,
|
|
340
|
-
packageId,
|
|
386
|
+
package: packageId,
|
|
341
387
|
ticket
|
|
342
388
|
}) {
|
|
343
|
-
return this.
|
|
389
|
+
return this.tx.upgrade({
|
|
390
|
+
modules,
|
|
391
|
+
dependencies,
|
|
392
|
+
package: packageId,
|
|
393
|
+
ticket
|
|
394
|
+
});
|
|
344
395
|
}
|
|
345
396
|
makeMoveVec({
|
|
346
|
-
|
|
397
|
+
elements,
|
|
347
398
|
type
|
|
348
399
|
}) {
|
|
349
|
-
return this.
|
|
400
|
+
return this.tx.makeMoveVec({ elements, type });
|
|
350
401
|
}
|
|
351
402
|
/* Override methods of TransactionBlock */
|
|
352
403
|
transferObjects(objects, address) {
|
|
353
|
-
return this.
|
|
354
|
-
objects.map((object) => convertObjArg(this.
|
|
355
|
-
convertAddressArg(this.
|
|
404
|
+
return this.tx.transferObjects(
|
|
405
|
+
objects.map((object) => convertObjArg(this.tx, object)),
|
|
406
|
+
convertAddressArg(this.tx, address)
|
|
356
407
|
);
|
|
357
408
|
}
|
|
358
409
|
splitCoins(coin, amounts) {
|
|
359
|
-
const res = this.
|
|
360
|
-
convertObjArg(this.
|
|
361
|
-
convertArgs(this.
|
|
410
|
+
const res = this.tx.splitCoins(
|
|
411
|
+
convertObjArg(this.tx, coin),
|
|
412
|
+
convertArgs(this.tx, amounts)
|
|
362
413
|
);
|
|
363
414
|
return amounts.map((_, i) => res[i]);
|
|
364
415
|
}
|
|
365
416
|
mergeCoins(destination, sources) {
|
|
366
|
-
const destinationObject = convertObjArg(this.
|
|
417
|
+
const destinationObject = convertObjArg(this.tx, destination);
|
|
367
418
|
const sourceObjects = sources.map(
|
|
368
|
-
(source) => convertObjArg(this.
|
|
419
|
+
(source) => convertObjArg(this.tx, source)
|
|
369
420
|
);
|
|
370
|
-
return this.
|
|
421
|
+
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
371
422
|
}
|
|
372
423
|
/**
|
|
373
424
|
* @description Move call
|
|
@@ -382,8 +433,8 @@ var SuiTxBlock = class {
|
|
|
382
433
|
throw new Error(
|
|
383
434
|
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
384
435
|
);
|
|
385
|
-
const convertedArgs = convertArgs(this.
|
|
386
|
-
return this.
|
|
436
|
+
const convertedArgs = convertArgs(this.tx, args);
|
|
437
|
+
return this.tx.moveCall({
|
|
387
438
|
target,
|
|
388
439
|
arguments: convertedArgs,
|
|
389
440
|
typeArguments: typeArgs
|
|
@@ -396,15 +447,15 @@ var SuiTxBlock = class {
|
|
|
396
447
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
397
448
|
);
|
|
398
449
|
}
|
|
399
|
-
const coins = this.
|
|
400
|
-
this.
|
|
401
|
-
convertArgs(this.
|
|
450
|
+
const coins = this.tx.splitCoins(
|
|
451
|
+
this.tx.gas,
|
|
452
|
+
convertArgs(this.tx, amounts)
|
|
402
453
|
);
|
|
403
454
|
const recipientObjects = recipients.map(
|
|
404
|
-
(recipient) => convertAddressArg(this.
|
|
455
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
405
456
|
);
|
|
406
457
|
recipientObjects.forEach((address, index) => {
|
|
407
|
-
this.
|
|
458
|
+
this.tx.transferObjects([coins[index]], address);
|
|
408
459
|
});
|
|
409
460
|
return this;
|
|
410
461
|
}
|
|
@@ -412,32 +463,29 @@ var SuiTxBlock = class {
|
|
|
412
463
|
return this.transferSuiToMany([address], [amount]);
|
|
413
464
|
}
|
|
414
465
|
takeAmountFromCoins(coins, amount) {
|
|
415
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
466
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
416
467
|
const mergedCoin = coinObjects[0];
|
|
417
468
|
if (coins.length > 1) {
|
|
418
|
-
this.
|
|
469
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
419
470
|
}
|
|
420
|
-
const [sendCoin] = this.
|
|
471
|
+
const [sendCoin] = this.tx.splitCoins(
|
|
421
472
|
mergedCoin,
|
|
422
|
-
convertArgs(this.
|
|
473
|
+
convertArgs(this.tx, [amount])
|
|
423
474
|
);
|
|
424
475
|
return [sendCoin, mergedCoin];
|
|
425
476
|
}
|
|
426
477
|
splitSUIFromGas(amounts) {
|
|
427
|
-
return this.
|
|
428
|
-
this.txBlock.gas,
|
|
429
|
-
convertArgs(this.txBlock, amounts)
|
|
430
|
-
);
|
|
478
|
+
return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
|
|
431
479
|
}
|
|
432
480
|
splitMultiCoins(coins, amounts) {
|
|
433
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
481
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
434
482
|
const mergedCoin = coinObjects[0];
|
|
435
483
|
if (coins.length > 1) {
|
|
436
|
-
this.
|
|
484
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
437
485
|
}
|
|
438
|
-
const splitedCoins = this.
|
|
486
|
+
const splitedCoins = this.tx.splitCoins(
|
|
439
487
|
mergedCoin,
|
|
440
|
-
convertArgs(this.
|
|
488
|
+
convertArgs(this.tx, amounts)
|
|
441
489
|
);
|
|
442
490
|
return { splitedCoins, mergedCoin };
|
|
443
491
|
}
|
|
@@ -447,45 +495,42 @@ var SuiTxBlock = class {
|
|
|
447
495
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
448
496
|
);
|
|
449
497
|
}
|
|
450
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
498
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
451
499
|
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
452
500
|
coinObjects,
|
|
453
501
|
amounts
|
|
454
502
|
);
|
|
455
503
|
const recipientObjects = recipients.map(
|
|
456
|
-
(recipient) => convertAddressArg(this.
|
|
504
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
457
505
|
);
|
|
458
506
|
recipientObjects.forEach((address, index) => {
|
|
459
|
-
this.
|
|
507
|
+
this.tx.transferObjects([splitedCoins[index]], address);
|
|
460
508
|
});
|
|
461
|
-
this.
|
|
462
|
-
[mergedCoin],
|
|
463
|
-
convertAddressArg(this.txBlock, sender)
|
|
464
|
-
);
|
|
509
|
+
this.tx.transferObjects([mergedCoin], convertAddressArg(this.tx, sender));
|
|
465
510
|
return this;
|
|
466
511
|
}
|
|
467
512
|
transferCoin(coins, sender, recipient, amount) {
|
|
468
513
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
469
514
|
}
|
|
470
515
|
stakeSui(amount, validatorAddr) {
|
|
471
|
-
const [stakeCoin] = this.
|
|
472
|
-
this.
|
|
473
|
-
convertArgs(this.
|
|
516
|
+
const [stakeCoin] = this.tx.splitCoins(
|
|
517
|
+
this.tx.gas,
|
|
518
|
+
convertArgs(this.tx, [amount])
|
|
474
519
|
);
|
|
475
|
-
return this.
|
|
520
|
+
return this.tx.moveCall({
|
|
476
521
|
target: "0x3::sui_system::request_add_stake",
|
|
477
|
-
arguments: convertArgs(this.
|
|
522
|
+
arguments: convertArgs(this.tx, [
|
|
478
523
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
479
524
|
stakeCoin,
|
|
480
|
-
this.
|
|
525
|
+
this.tx.pure.address(validatorAddr.toString())
|
|
481
526
|
])
|
|
482
527
|
});
|
|
483
528
|
}
|
|
484
529
|
};
|
|
485
530
|
|
|
486
531
|
// src/libs/suiInteractor/suiInteractor.ts
|
|
487
|
-
import { SuiClient } from "@mysten/sui
|
|
488
|
-
import { requestSuiFromFaucetV0, getFaucetHost } from "@mysten/sui
|
|
532
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
533
|
+
import { requestSuiFromFaucetV0, getFaucetHost } from "@mysten/sui/faucet";
|
|
489
534
|
|
|
490
535
|
// src/libs/suiModel/suiOwnedObject.ts
|
|
491
536
|
var SuiOwnedObject = class {
|
|
@@ -507,8 +552,10 @@ var SuiOwnedObject = class {
|
|
|
507
552
|
return this.objectId;
|
|
508
553
|
}
|
|
509
554
|
return {
|
|
555
|
+
$kind: "Object",
|
|
510
556
|
Object: {
|
|
511
|
-
|
|
557
|
+
$kind: "ImmOrOwnedObject",
|
|
558
|
+
ImmOrOwnedObject: {
|
|
512
559
|
objectId: this.objectId,
|
|
513
560
|
version: this.version,
|
|
514
561
|
digest: this.digest
|
|
@@ -547,8 +594,10 @@ var SuiSharedObject = class {
|
|
|
547
594
|
return this.objectId;
|
|
548
595
|
}
|
|
549
596
|
return {
|
|
597
|
+
$kind: "Object",
|
|
550
598
|
Object: {
|
|
551
|
-
|
|
599
|
+
$kind: "SharedObject",
|
|
600
|
+
SharedObject: {
|
|
552
601
|
objectId: this.objectId,
|
|
553
602
|
initialSharedVersion: this.initialSharedVersion,
|
|
554
603
|
mutable
|
|
@@ -908,8 +957,7 @@ function numberToAddressHex(num) {
|
|
|
908
957
|
}
|
|
909
958
|
|
|
910
959
|
// src/obelisk.ts
|
|
911
|
-
import
|
|
912
|
-
import { BCS, getSuiMoveConfig } from "@mysten/bcs";
|
|
960
|
+
import { bcs as bcs2, fromHEX as fromHEX2, toHEX } from "@mysten/bcs";
|
|
913
961
|
function isUndefined(value) {
|
|
914
962
|
return value === void 0;
|
|
915
963
|
}
|
|
@@ -934,7 +982,7 @@ function createTx(meta, fn) {
|
|
|
934
982
|
}
|
|
935
983
|
);
|
|
936
984
|
}
|
|
937
|
-
var _query, _tx, _exec, _read;
|
|
985
|
+
var _query, _tx, _struct, _exec, _read;
|
|
938
986
|
var Obelisk = class {
|
|
939
987
|
/**
|
|
940
988
|
* Support the following ways to init the ObeliskClient:
|
|
@@ -958,6 +1006,7 @@ var Obelisk = class {
|
|
|
958
1006
|
} = {}) {
|
|
959
1007
|
__privateAdd(this, _query, {});
|
|
960
1008
|
__privateAdd(this, _tx, {});
|
|
1009
|
+
__privateAdd(this, _struct, {});
|
|
961
1010
|
__privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
|
|
962
1011
|
if (isRaw === true) {
|
|
963
1012
|
return tx.moveCall({
|
|
@@ -994,33 +1043,37 @@ var Obelisk = class {
|
|
|
994
1043
|
this.packageId = packageId;
|
|
995
1044
|
if (metadata !== void 0) {
|
|
996
1045
|
this.metadata = metadata;
|
|
997
|
-
Object.values(metadata).forEach(
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1046
|
+
Object.values(metadata).forEach(
|
|
1047
|
+
(moudlevalue) => {
|
|
1048
|
+
const data = moudlevalue;
|
|
1049
|
+
const moduleName = data.name;
|
|
1050
|
+
Object.entries(data.exposedFunctions).forEach(
|
|
1051
|
+
([funcName, funcvalue]) => {
|
|
1052
|
+
const meta = funcvalue;
|
|
1053
|
+
meta.moduleName = moduleName;
|
|
1054
|
+
meta.funcName = funcName;
|
|
1055
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1056
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
1057
|
+
}
|
|
1058
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1059
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1060
|
+
meta,
|
|
1061
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1065
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
1066
|
+
}
|
|
1067
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1068
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1069
|
+
meta,
|
|
1070
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
);
|
|
1024
1077
|
}
|
|
1025
1078
|
this.contractFactory = new SuiContractFactory({
|
|
1026
1079
|
packageId,
|
|
@@ -1033,6 +1086,9 @@ var Obelisk = class {
|
|
|
1033
1086
|
get tx() {
|
|
1034
1087
|
return __privateGet(this, _tx);
|
|
1035
1088
|
}
|
|
1089
|
+
get struct() {
|
|
1090
|
+
return __privateGet(this, _struct);
|
|
1091
|
+
}
|
|
1036
1092
|
/**
|
|
1037
1093
|
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
1038
1094
|
* else:
|
|
@@ -1065,11 +1121,20 @@ var Obelisk = class {
|
|
|
1065
1121
|
getMetadata() {
|
|
1066
1122
|
return this.contractFactory.metadata;
|
|
1067
1123
|
}
|
|
1124
|
+
getNetwork() {
|
|
1125
|
+
return this.suiInteractor.network;
|
|
1126
|
+
}
|
|
1068
1127
|
/**
|
|
1069
1128
|
* Request some SUI from faucet
|
|
1070
1129
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
1071
1130
|
*/
|
|
1072
|
-
async requestFaucet(address, network) {
|
|
1131
|
+
async requestFaucet(address, network, derivePathParams) {
|
|
1132
|
+
if (address === void 0) {
|
|
1133
|
+
address = this.accountManager.getAddress(derivePathParams);
|
|
1134
|
+
}
|
|
1135
|
+
if (network === void 0) {
|
|
1136
|
+
network = this.getNetwork();
|
|
1137
|
+
}
|
|
1073
1138
|
return this.suiInteractor.requestFaucet(address, network);
|
|
1074
1139
|
}
|
|
1075
1140
|
async getBalance(coinType, derivePathParams) {
|
|
@@ -1093,18 +1158,21 @@ var Obelisk = class {
|
|
|
1093
1158
|
return this.suiInteractor.getObjects(objectIds);
|
|
1094
1159
|
}
|
|
1095
1160
|
async signTxn(tx, derivePathParams) {
|
|
1096
|
-
if (tx instanceof
|
|
1161
|
+
if (tx instanceof SuiTx || tx instanceof Transaction2) {
|
|
1097
1162
|
tx.setSender(this.getAddress(derivePathParams));
|
|
1098
1163
|
}
|
|
1099
|
-
const txBlock = tx instanceof
|
|
1100
|
-
const txBytes = txBlock instanceof
|
|
1164
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
1165
|
+
const txBytes = txBlock instanceof Transaction2 ? await txBlock.build({ client: this.client() }) : txBlock;
|
|
1101
1166
|
const keyPair = this.getKeypair(derivePathParams);
|
|
1102
|
-
return await keyPair.
|
|
1167
|
+
return await keyPair.signTransaction(txBytes);
|
|
1103
1168
|
}
|
|
1104
1169
|
async signAndSendTxn(tx, derivePathParams) {
|
|
1105
1170
|
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
1106
1171
|
return this.suiInteractor.sendTx(bytes, signature);
|
|
1107
1172
|
}
|
|
1173
|
+
async sendTxn(transactionBlock, signature) {
|
|
1174
|
+
return this.suiInteractor.sendTx(transactionBlock, signature);
|
|
1175
|
+
}
|
|
1108
1176
|
/**
|
|
1109
1177
|
* Transfer the given amount of SUI to the recipient
|
|
1110
1178
|
* @param recipient
|
|
@@ -1112,7 +1180,7 @@ var Obelisk = class {
|
|
|
1112
1180
|
* @param derivePathParams
|
|
1113
1181
|
*/
|
|
1114
1182
|
async transferSui(recipient, amount, derivePathParams) {
|
|
1115
|
-
const tx = new
|
|
1183
|
+
const tx = new SuiTx();
|
|
1116
1184
|
tx.transferSui(recipient, amount);
|
|
1117
1185
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1118
1186
|
}
|
|
@@ -1123,7 +1191,7 @@ var Obelisk = class {
|
|
|
1123
1191
|
* @param derivePathParams
|
|
1124
1192
|
*/
|
|
1125
1193
|
async transferSuiToMany(recipients, amounts, derivePathParams) {
|
|
1126
|
-
const tx = new
|
|
1194
|
+
const tx = new SuiTx();
|
|
1127
1195
|
tx.transferSuiToMany(recipients, amounts);
|
|
1128
1196
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1129
1197
|
}
|
|
@@ -1135,7 +1203,7 @@ var Obelisk = class {
|
|
|
1135
1203
|
* @param derivePathParams the derive path params for the current signer
|
|
1136
1204
|
*/
|
|
1137
1205
|
async transferCoinToMany(recipients, amounts, coinType, derivePathParams) {
|
|
1138
|
-
const tx = new
|
|
1206
|
+
const tx = new SuiTx();
|
|
1139
1207
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
1140
1208
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
1141
1209
|
const coins = await this.suiInteractor.selectCoins(
|
|
@@ -1160,7 +1228,7 @@ var Obelisk = class {
|
|
|
1160
1228
|
);
|
|
1161
1229
|
}
|
|
1162
1230
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
1163
|
-
const tx = new
|
|
1231
|
+
const tx = new SuiTx();
|
|
1164
1232
|
tx.transferObjects(objects, recipient);
|
|
1165
1233
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1166
1234
|
}
|
|
@@ -1171,7 +1239,7 @@ var Obelisk = class {
|
|
|
1171
1239
|
typeArguments = [],
|
|
1172
1240
|
derivePathParams
|
|
1173
1241
|
} = callParams;
|
|
1174
|
-
const tx = new
|
|
1242
|
+
const tx = new SuiTx();
|
|
1175
1243
|
tx.moveCall(target, args, typeArguments);
|
|
1176
1244
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1177
1245
|
}
|
|
@@ -1198,7 +1266,7 @@ var Obelisk = class {
|
|
|
1198
1266
|
* @param derivePathParams the derive path params for the current signer
|
|
1199
1267
|
*/
|
|
1200
1268
|
async stakeSui(amount, validatorAddr, derivePathParams) {
|
|
1201
|
-
const tx = new
|
|
1269
|
+
const tx = new SuiTx();
|
|
1202
1270
|
tx.stakeSui(amount, validatorAddr);
|
|
1203
1271
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1204
1272
|
}
|
|
@@ -1210,7 +1278,7 @@ var Obelisk = class {
|
|
|
1210
1278
|
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
1211
1279
|
*/
|
|
1212
1280
|
async inspectTxn(tx, derivePathParams) {
|
|
1213
|
-
const txBlock = tx instanceof
|
|
1281
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
1214
1282
|
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
1215
1283
|
transactionBlock: txBlock,
|
|
1216
1284
|
sender: this.getAddress(derivePathParams)
|
|
@@ -1232,36 +1300,62 @@ var Obelisk = class {
|
|
|
1232
1300
|
}
|
|
1233
1301
|
async getEntity(worldId, schemaName, entityId) {
|
|
1234
1302
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1235
|
-
const tx = new
|
|
1236
|
-
const params = [tx.pure(worldId)];
|
|
1303
|
+
const tx = new Transaction2();
|
|
1304
|
+
const params = [tx.pure.address(worldId)];
|
|
1237
1305
|
if (entityId !== void 0) {
|
|
1238
|
-
params.push(tx.pure(entityId));
|
|
1306
|
+
params.push(tx.pure.address(entityId));
|
|
1239
1307
|
}
|
|
1240
1308
|
const getResult = await this.query[schemaModuleName].get(
|
|
1241
1309
|
tx,
|
|
1242
1310
|
params
|
|
1243
1311
|
);
|
|
1244
|
-
let
|
|
1312
|
+
let returnValues = [];
|
|
1245
1313
|
if (getResult.effects.status.status === "success") {
|
|
1246
1314
|
const resultList = getResult.results[0].returnValues;
|
|
1247
1315
|
for (const res of resultList) {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
|
|
1316
|
+
let baseValue = res[0];
|
|
1317
|
+
let baseType = res[1];
|
|
1318
|
+
const value = Uint8Array.from(baseValue);
|
|
1319
|
+
if (baseType === "address") {
|
|
1320
|
+
const Address = bcs2.bytes(32).transform({
|
|
1321
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1322
|
+
input: (val) => fromHEX2(val),
|
|
1323
|
+
output: (val) => toHEX(val)
|
|
1324
|
+
});
|
|
1325
|
+
returnValues.push(Address.parse(value));
|
|
1326
|
+
} else if (baseType === "u8") {
|
|
1327
|
+
returnValues.push(bcs2.u8().parse(value));
|
|
1328
|
+
} else if (baseType === "u16") {
|
|
1329
|
+
returnValues.push(bcs2.u16().parse(value));
|
|
1330
|
+
} else if (baseType === "u32") {
|
|
1331
|
+
returnValues.push(bcs2.u32().parse(value));
|
|
1332
|
+
} else if (baseType === "u64") {
|
|
1333
|
+
returnValues.push(bcs2.u64().parse(value));
|
|
1334
|
+
} else if (baseType === "u128") {
|
|
1335
|
+
returnValues.push(bcs2.u128().parse(value));
|
|
1336
|
+
} else if (baseType === "u256") {
|
|
1337
|
+
returnValues.push(bcs2.u256().parse(value));
|
|
1338
|
+
} else if (baseType === "bool") {
|
|
1339
|
+
returnValues.push(bcs2.bool().parse(value));
|
|
1340
|
+
} else if (baseType === "0x1::ascii::String") {
|
|
1341
|
+
returnValues.push(bcs2.string().parse(value));
|
|
1342
|
+
} else if (baseType === "vector<u8>") {
|
|
1343
|
+
returnValues.push(bcs2.vector(bcs2.u8()).parse(value));
|
|
1344
|
+
} else if (baseType === "0x1::option::Option<u8>") {
|
|
1345
|
+
returnValues.push(bcs2.option(bcs2.u8()).parse(value));
|
|
1346
|
+
}
|
|
1253
1347
|
}
|
|
1254
|
-
return
|
|
1348
|
+
return returnValues;
|
|
1255
1349
|
} else {
|
|
1256
1350
|
return void 0;
|
|
1257
1351
|
}
|
|
1258
1352
|
}
|
|
1259
1353
|
async containEntity(worldId, schemaName, entityId) {
|
|
1260
1354
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1261
|
-
const tx = new
|
|
1262
|
-
const params = [tx.pure(worldId)];
|
|
1355
|
+
const tx = new Transaction2();
|
|
1356
|
+
const params = [tx.pure.address(worldId)];
|
|
1263
1357
|
if (entityId !== void 0) {
|
|
1264
|
-
params.push(tx.pure(entityId));
|
|
1358
|
+
params.push(tx.pure.address(entityId));
|
|
1265
1359
|
}
|
|
1266
1360
|
const getResult = await this.query[schemaModuleName].contains(
|
|
1267
1361
|
tx,
|
|
@@ -1269,9 +1363,9 @@ var Obelisk = class {
|
|
|
1269
1363
|
);
|
|
1270
1364
|
if (getResult.effects.status.status === "success") {
|
|
1271
1365
|
const res = getResult.results[0].returnValues[0];
|
|
1272
|
-
|
|
1273
|
-
const value = Uint8Array.from(
|
|
1274
|
-
return
|
|
1366
|
+
let baseValue = res[0];
|
|
1367
|
+
const value = Uint8Array.from(baseValue);
|
|
1368
|
+
return bcs2.bool().parse(value);
|
|
1275
1369
|
} else {
|
|
1276
1370
|
return void 0;
|
|
1277
1371
|
}
|
|
@@ -1333,9 +1427,13 @@ var Obelisk = class {
|
|
|
1333
1427
|
async entity_key_from_bytes(bytes) {
|
|
1334
1428
|
const hashBytes = keccak256(bytes);
|
|
1335
1429
|
const hashU8Array = Array.from(hashBytes);
|
|
1336
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
1337
1430
|
const value = Uint8Array.from(hashU8Array);
|
|
1338
|
-
const
|
|
1431
|
+
const Address = bcs2.bytes(32).transform({
|
|
1432
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1433
|
+
input: (val) => fromHEX2(val),
|
|
1434
|
+
output: (val) => toHEX(val)
|
|
1435
|
+
});
|
|
1436
|
+
const data = Address.parse(value);
|
|
1339
1437
|
return "0x" + data;
|
|
1340
1438
|
}
|
|
1341
1439
|
async entity_key_from_address_with_seed(objectId, seed) {
|
|
@@ -1353,9 +1451,8 @@ var Obelisk = class {
|
|
|
1353
1451
|
const checkObjectId = normalizeHexAddress(objectId);
|
|
1354
1452
|
if (checkObjectId !== null) {
|
|
1355
1453
|
objectId = checkObjectId;
|
|
1356
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
1357
1454
|
const bytes = Buffer.from(objectId.slice(2), "hex");
|
|
1358
|
-
const numberBytes =
|
|
1455
|
+
const numberBytes = bcs2.u256().serialize(x).toBytes();
|
|
1359
1456
|
return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
|
|
1360
1457
|
} else {
|
|
1361
1458
|
return void 0;
|
|
@@ -1364,23 +1461,65 @@ var Obelisk = class {
|
|
|
1364
1461
|
async entity_key_from_u256(x) {
|
|
1365
1462
|
return numberToAddressHex(x);
|
|
1366
1463
|
}
|
|
1367
|
-
async formatData(type, value) {
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1464
|
+
// async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
1465
|
+
// const u8Value = Uint8Array.from(value);
|
|
1466
|
+
// return bcs.de(type, u8Value);
|
|
1467
|
+
// }
|
|
1468
|
+
async autoFormatDryValue(value) {
|
|
1469
|
+
let returnValues = [];
|
|
1470
|
+
if (value.effects.status.status === "success") {
|
|
1471
|
+
const resultList = value.results[0].returnValues;
|
|
1472
|
+
for (const res of resultList) {
|
|
1473
|
+
let baseValue = res[0];
|
|
1474
|
+
let baseType = res[1];
|
|
1475
|
+
const value2 = Uint8Array.from(baseValue);
|
|
1476
|
+
if (baseType === "address") {
|
|
1477
|
+
const Address = bcs2.bytes(32).transform({
|
|
1478
|
+
// To change the input type, you need to provide a type definition for the input
|
|
1479
|
+
input: (val) => fromHEX2(val),
|
|
1480
|
+
output: (val) => toHEX(val)
|
|
1481
|
+
});
|
|
1482
|
+
returnValues.push(Address.parse(value2));
|
|
1483
|
+
} else if (baseType === "u8") {
|
|
1484
|
+
returnValues.push(bcs2.u8().parse(value2));
|
|
1485
|
+
} else if (baseType === "u16") {
|
|
1486
|
+
returnValues.push(bcs2.u16().parse(value2));
|
|
1487
|
+
} else if (baseType === "u32") {
|
|
1488
|
+
returnValues.push(bcs2.u32().parse(value2));
|
|
1489
|
+
} else if (baseType === "u64") {
|
|
1490
|
+
returnValues.push(bcs2.u64().parse(value2));
|
|
1491
|
+
} else if (baseType === "u128") {
|
|
1492
|
+
returnValues.push(bcs2.u128().parse(value2));
|
|
1493
|
+
} else if (baseType === "u256") {
|
|
1494
|
+
returnValues.push(bcs2.u256().parse(value2));
|
|
1495
|
+
} else if (baseType === "bool") {
|
|
1496
|
+
returnValues.push(bcs2.bool().parse(value2));
|
|
1497
|
+
} else if (baseType === "0x1::ascii::String") {
|
|
1498
|
+
returnValues.push(bcs2.string().parse(value2));
|
|
1499
|
+
} else if (baseType === "vector<u8>") {
|
|
1500
|
+
returnValues.push(bcs2.vector(bcs2.u8()).parse(value2));
|
|
1501
|
+
} else if (baseType === "0x1::option::Option<u8>") {
|
|
1502
|
+
returnValues.push(bcs2.option(bcs2.u8()).parse(value2));
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
return returnValues;
|
|
1506
|
+
} else {
|
|
1507
|
+
return void 0;
|
|
1508
|
+
}
|
|
1371
1509
|
}
|
|
1372
1510
|
};
|
|
1373
1511
|
_query = new WeakMap();
|
|
1374
1512
|
_tx = new WeakMap();
|
|
1513
|
+
_struct = new WeakMap();
|
|
1375
1514
|
_exec = new WeakMap();
|
|
1376
1515
|
_read = new WeakMap();
|
|
1377
1516
|
|
|
1378
1517
|
// src/libs/multiSig/client.ts
|
|
1379
|
-
import { MultiSigPublicKey } from "@mysten/sui
|
|
1518
|
+
import { MultiSigPublicKey } from "@mysten/sui/multisig";
|
|
1380
1519
|
|
|
1381
1520
|
// src/libs/multiSig/publickey.ts
|
|
1382
|
-
import { Ed25519PublicKey } from "@mysten/sui
|
|
1383
|
-
import { fromB64 as fromB642 } from "@mysten/sui
|
|
1521
|
+
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
1522
|
+
import { fromB64 as fromB642 } from "@mysten/sui/utils";
|
|
1384
1523
|
function ed25519PublicKeyFromBase64(rawPubkey) {
|
|
1385
1524
|
let bytes = fromB642(rawPubkey);
|
|
1386
1525
|
if (bytes.length !== 32 && bytes.length !== 33)
|
|
@@ -1417,7 +1556,7 @@ var MultiSigClient = class _MultiSigClient {
|
|
|
1417
1556
|
};
|
|
1418
1557
|
|
|
1419
1558
|
// src/metadata/index.ts
|
|
1420
|
-
import { getFullnodeUrl as getFullnodeUrl2 } from "@mysten/sui
|
|
1559
|
+
import { getFullnodeUrl as getFullnodeUrl2 } from "@mysten/sui/client";
|
|
1421
1560
|
async function loadMetadata(networkType, packageId) {
|
|
1422
1561
|
const fullnodeUrls = [getFullnodeUrl2(networkType)];
|
|
1423
1562
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
@@ -1431,13 +1570,13 @@ async function loadMetadata(networkType, packageId) {
|
|
|
1431
1570
|
}
|
|
1432
1571
|
}
|
|
1433
1572
|
export {
|
|
1434
|
-
|
|
1573
|
+
BcsType,
|
|
1435
1574
|
MultiSigClient,
|
|
1436
1575
|
Obelisk,
|
|
1437
1576
|
SuiAccountManager,
|
|
1438
1577
|
SuiContractFactory,
|
|
1439
|
-
|
|
1440
|
-
|
|
1578
|
+
SuiTx,
|
|
1579
|
+
bcs3 as bcs,
|
|
1441
1580
|
loadMetadata
|
|
1442
1581
|
};
|
|
1443
1582
|
//# sourceMappingURL=index.mjs.map
|