@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.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) => {
|
|
@@ -98,7 +102,7 @@ var SuiAccountManager = class {
|
|
|
98
102
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
99
103
|
*
|
|
100
104
|
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
101
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
105
|
+
* @param secretKey, base64 or hex string or Bech32 string, when mnemonics is provided, secretKey will be ignored
|
|
102
106
|
*/
|
|
103
107
|
constructor({ mnemonics, secretKey } = {}) {
|
|
104
108
|
this.mnemonics = mnemonics || "";
|
|
@@ -106,11 +110,23 @@ var SuiAccountManager = class {
|
|
|
106
110
|
if (!this.mnemonics && !this.secretKey) {
|
|
107
111
|
this.mnemonics = generateMnemonic(24);
|
|
108
112
|
}
|
|
109
|
-
this.currentKeyPair = this.secretKey ?
|
|
110
|
-
normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))
|
|
111
|
-
) : getKeyPair(this.mnemonics);
|
|
113
|
+
this.currentKeyPair = this.secretKey ? this.parseSecretKey(this.secretKey) : getKeyPair(this.mnemonics);
|
|
112
114
|
this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();
|
|
113
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if the secretKey starts with bench32 format
|
|
118
|
+
*/
|
|
119
|
+
parseSecretKey(secretKey) {
|
|
120
|
+
if (secretKey.startsWith(SUI_PRIVATE_KEY_PREFIX)) {
|
|
121
|
+
const { secretKey: uint8ArraySecretKey } = decodeSuiPrivateKey(secretKey);
|
|
122
|
+
return Ed25519Keypair2.fromSecretKey(
|
|
123
|
+
normalizePrivateKey(uint8ArraySecretKey)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return Ed25519Keypair2.fromSecretKey(
|
|
127
|
+
normalizePrivateKey(hexOrBase64ToUint8Array(secretKey))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
114
130
|
/**
|
|
115
131
|
* if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
|
|
116
132
|
* else:
|
|
@@ -144,8 +160,8 @@ var SuiAccountManager = class {
|
|
|
144
160
|
};
|
|
145
161
|
|
|
146
162
|
// src/libs/suiTxBuilder/index.ts
|
|
147
|
-
import {
|
|
148
|
-
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";
|
|
149
165
|
|
|
150
166
|
// src/libs/suiTxBuilder/util.ts
|
|
151
167
|
import {
|
|
@@ -153,10 +169,10 @@ import {
|
|
|
153
169
|
normalizeSuiAddress,
|
|
154
170
|
isValidSuiObjectId,
|
|
155
171
|
isValidSuiAddress
|
|
156
|
-
} from "@mysten/sui
|
|
157
|
-
import { Inputs } from "@mysten/sui
|
|
158
|
-
import { isPureArg } from "@mysten/sui.js/bcs";
|
|
172
|
+
} from "@mysten/sui/utils";
|
|
173
|
+
import { Inputs } from "@mysten/sui/transactions";
|
|
159
174
|
import { isSerializedBcs } from "@mysten/bcs";
|
|
175
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
160
176
|
var getDefaultSuiInputType = (value) => {
|
|
161
177
|
if (typeof value === "string" && isValidSuiObjectId(value)) {
|
|
162
178
|
return "object";
|
|
@@ -168,7 +184,10 @@ var getDefaultSuiInputType = (value) => {
|
|
|
168
184
|
return void 0;
|
|
169
185
|
}
|
|
170
186
|
};
|
|
171
|
-
function
|
|
187
|
+
function isPureArg(arg) {
|
|
188
|
+
return arg.Pure !== void 0;
|
|
189
|
+
}
|
|
190
|
+
function makeVecParam(tx, args, type) {
|
|
172
191
|
if (args.length === 0)
|
|
173
192
|
throw new Error("Transaction builder error: Empty array is not allowed");
|
|
174
193
|
const defaultSuiType = getDefaultSuiInputType(args[0]);
|
|
@@ -176,17 +195,33 @@ function makeVecParam(txBlock, args, type) {
|
|
|
176
195
|
const STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
|
|
177
196
|
type = type || defaultSuiType;
|
|
178
197
|
if (type === "object") {
|
|
179
|
-
const
|
|
180
|
-
(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)
|
|
181
200
|
);
|
|
182
|
-
return
|
|
201
|
+
return tx.makeMoveVec({ elements });
|
|
183
202
|
} else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
|
|
184
|
-
|
|
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
|
+
}
|
|
185
222
|
} else {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
);
|
|
189
|
-
return txBlock.makeMoveVec({ objects, type });
|
|
223
|
+
const elements = args.map((arg) => convertObjArg(tx, arg));
|
|
224
|
+
return tx.makeMoveVec({ elements, type });
|
|
190
225
|
}
|
|
191
226
|
}
|
|
192
227
|
function isMoveVecArg(arg) {
|
|
@@ -197,48 +232,65 @@ function isMoveVecArg(arg) {
|
|
|
197
232
|
}
|
|
198
233
|
return false;
|
|
199
234
|
}
|
|
200
|
-
function convertArgs(
|
|
235
|
+
function convertArgs(tx, args) {
|
|
201
236
|
return args.map((arg) => {
|
|
202
237
|
if (typeof arg === "string" && isValidSuiObjectId(arg)) {
|
|
203
|
-
return
|
|
238
|
+
return tx.object(normalizeSuiObjectId(arg));
|
|
204
239
|
} else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg) && !isMoveVecArg(arg)) {
|
|
205
|
-
return convertObjArg(
|
|
240
|
+
return convertObjArg(tx, arg);
|
|
206
241
|
} else if (isMoveVecArg(arg)) {
|
|
207
242
|
const vecType = "vecType" in arg;
|
|
208
|
-
return vecType ? makeVecParam(
|
|
243
|
+
return vecType ? makeVecParam(tx, arg.value, arg.vecType) : makeVecParam(tx, arg);
|
|
209
244
|
} else if (isSerializedBcs(arg)) {
|
|
210
245
|
return arg;
|
|
211
246
|
} else {
|
|
212
|
-
|
|
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
|
+
}
|
|
213
257
|
}
|
|
214
258
|
});
|
|
215
259
|
}
|
|
216
|
-
function convertAddressArg(
|
|
260
|
+
function convertAddressArg(tx, arg) {
|
|
217
261
|
if (typeof arg === "string" && isValidSuiAddress(arg)) {
|
|
218
|
-
return
|
|
262
|
+
return tx.pure.address(normalizeSuiAddress(arg));
|
|
219
263
|
} else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg)) {
|
|
220
|
-
return convertObjArg(
|
|
264
|
+
return convertObjArg(tx, arg);
|
|
221
265
|
} else if (isPureArg(arg)) {
|
|
222
|
-
return
|
|
266
|
+
return tx.pure(Uint8Array.from(arg.Pure));
|
|
223
267
|
} else {
|
|
224
268
|
return arg;
|
|
225
269
|
}
|
|
226
270
|
}
|
|
227
|
-
function convertObjArg(
|
|
271
|
+
function convertObjArg(tx, arg) {
|
|
228
272
|
if (typeof arg === "string") {
|
|
229
|
-
return
|
|
273
|
+
return tx.object(arg);
|
|
230
274
|
}
|
|
231
275
|
if ("digest" in arg && "version" in arg && "objectId" in arg) {
|
|
232
|
-
return
|
|
276
|
+
return tx.objectRef(arg);
|
|
233
277
|
}
|
|
234
278
|
if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
|
|
235
|
-
return
|
|
279
|
+
return tx.sharedObjectRef(arg);
|
|
236
280
|
}
|
|
237
281
|
if ("Object" in arg) {
|
|
238
|
-
if ("
|
|
239
|
-
return
|
|
240
|
-
|
|
241
|
-
|
|
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));
|
|
242
294
|
} else {
|
|
243
295
|
throw new Error("Invalid argument type");
|
|
244
296
|
}
|
|
@@ -250,108 +302,123 @@ function convertObjArg(txb, arg) {
|
|
|
250
302
|
}
|
|
251
303
|
|
|
252
304
|
// src/libs/suiTxBuilder/index.ts
|
|
253
|
-
var
|
|
305
|
+
var SuiTx = class {
|
|
254
306
|
constructor(transaction) {
|
|
255
|
-
|
|
307
|
+
if (transaction !== void 0) {
|
|
308
|
+
this.tx = Transaction.from(transaction);
|
|
309
|
+
} else {
|
|
310
|
+
this.tx = new Transaction();
|
|
311
|
+
}
|
|
256
312
|
}
|
|
257
313
|
/* Directly wrap methods and properties of TransactionBlock */
|
|
258
314
|
get gas() {
|
|
259
|
-
return this.
|
|
315
|
+
return this.tx.gas;
|
|
260
316
|
}
|
|
261
317
|
get blockData() {
|
|
262
|
-
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;
|
|
263
325
|
}
|
|
264
326
|
address(value) {
|
|
265
|
-
return this.
|
|
327
|
+
return this.tx.pure.address(value);
|
|
266
328
|
}
|
|
267
|
-
pure(value
|
|
268
|
-
return this.
|
|
329
|
+
pure(value) {
|
|
330
|
+
return this.tx.pure(value);
|
|
269
331
|
}
|
|
270
332
|
object(value) {
|
|
271
|
-
return this.
|
|
333
|
+
return this.tx.object(value);
|
|
272
334
|
}
|
|
273
335
|
objectRef(ref) {
|
|
274
|
-
return this.
|
|
336
|
+
return this.tx.objectRef(ref);
|
|
275
337
|
}
|
|
276
338
|
sharedObjectRef(ref) {
|
|
277
|
-
return this.
|
|
339
|
+
return this.tx.sharedObjectRef(ref);
|
|
278
340
|
}
|
|
279
341
|
setSender(sender) {
|
|
280
|
-
return this.
|
|
342
|
+
return this.tx.setSender(sender);
|
|
281
343
|
}
|
|
282
344
|
setSenderIfNotSet(sender) {
|
|
283
|
-
return this.
|
|
345
|
+
return this.tx.setSenderIfNotSet(sender);
|
|
284
346
|
}
|
|
285
347
|
setExpiration(expiration) {
|
|
286
|
-
return this.
|
|
348
|
+
return this.tx.setExpiration(expiration);
|
|
287
349
|
}
|
|
288
350
|
setGasPrice(price) {
|
|
289
|
-
return this.
|
|
351
|
+
return this.tx.setGasPrice(price);
|
|
290
352
|
}
|
|
291
353
|
setGasBudget(budget) {
|
|
292
|
-
return this.
|
|
354
|
+
return this.tx.setGasBudget(budget);
|
|
293
355
|
}
|
|
294
356
|
setGasOwner(owner) {
|
|
295
|
-
return this.
|
|
357
|
+
return this.tx.setGasOwner(owner);
|
|
296
358
|
}
|
|
297
359
|
setGasPayment(payments) {
|
|
298
|
-
return this.
|
|
360
|
+
return this.tx.setGasPayment(payments);
|
|
299
361
|
}
|
|
300
362
|
serialize() {
|
|
301
|
-
return this.
|
|
363
|
+
return this.tx.serialize();
|
|
302
364
|
}
|
|
303
365
|
sign(params) {
|
|
304
|
-
return this.
|
|
366
|
+
return this.tx.sign(params);
|
|
305
367
|
}
|
|
306
368
|
build(params = {}) {
|
|
307
|
-
return this.
|
|
369
|
+
return this.tx.build(params);
|
|
308
370
|
}
|
|
309
371
|
getDigest(params = {}) {
|
|
310
|
-
return this.
|
|
372
|
+
return this.tx.getDigest(params);
|
|
311
373
|
}
|
|
312
374
|
add(...args) {
|
|
313
|
-
return this.
|
|
375
|
+
return this.tx.add(...args);
|
|
314
376
|
}
|
|
315
377
|
publish({
|
|
316
378
|
modules,
|
|
317
379
|
dependencies
|
|
318
380
|
}) {
|
|
319
|
-
return this.
|
|
381
|
+
return this.tx.publish({ modules, dependencies });
|
|
320
382
|
}
|
|
321
383
|
upgrade({
|
|
322
384
|
modules,
|
|
323
385
|
dependencies,
|
|
324
|
-
packageId,
|
|
386
|
+
package: packageId,
|
|
325
387
|
ticket
|
|
326
388
|
}) {
|
|
327
|
-
return this.
|
|
389
|
+
return this.tx.upgrade({
|
|
390
|
+
modules,
|
|
391
|
+
dependencies,
|
|
392
|
+
package: packageId,
|
|
393
|
+
ticket
|
|
394
|
+
});
|
|
328
395
|
}
|
|
329
396
|
makeMoveVec({
|
|
330
|
-
|
|
397
|
+
elements,
|
|
331
398
|
type
|
|
332
399
|
}) {
|
|
333
|
-
return this.
|
|
400
|
+
return this.tx.makeMoveVec({ elements, type });
|
|
334
401
|
}
|
|
335
402
|
/* Override methods of TransactionBlock */
|
|
336
403
|
transferObjects(objects, address) {
|
|
337
|
-
return this.
|
|
338
|
-
objects.map((object) => convertObjArg(this.
|
|
339
|
-
convertAddressArg(this.
|
|
404
|
+
return this.tx.transferObjects(
|
|
405
|
+
objects.map((object) => convertObjArg(this.tx, object)),
|
|
406
|
+
convertAddressArg(this.tx, address)
|
|
340
407
|
);
|
|
341
408
|
}
|
|
342
409
|
splitCoins(coin, amounts) {
|
|
343
|
-
const res = this.
|
|
344
|
-
convertObjArg(this.
|
|
345
|
-
convertArgs(this.
|
|
410
|
+
const res = this.tx.splitCoins(
|
|
411
|
+
convertObjArg(this.tx, coin),
|
|
412
|
+
convertArgs(this.tx, amounts)
|
|
346
413
|
);
|
|
347
414
|
return amounts.map((_, i) => res[i]);
|
|
348
415
|
}
|
|
349
416
|
mergeCoins(destination, sources) {
|
|
350
|
-
const destinationObject = convertObjArg(this.
|
|
417
|
+
const destinationObject = convertObjArg(this.tx, destination);
|
|
351
418
|
const sourceObjects = sources.map(
|
|
352
|
-
(source) => convertObjArg(this.
|
|
419
|
+
(source) => convertObjArg(this.tx, source)
|
|
353
420
|
);
|
|
354
|
-
return this.
|
|
421
|
+
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
355
422
|
}
|
|
356
423
|
/**
|
|
357
424
|
* @description Move call
|
|
@@ -366,8 +433,8 @@ var SuiTxBlock = class {
|
|
|
366
433
|
throw new Error(
|
|
367
434
|
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
368
435
|
);
|
|
369
|
-
const convertedArgs = convertArgs(this.
|
|
370
|
-
return this.
|
|
436
|
+
const convertedArgs = convertArgs(this.tx, args);
|
|
437
|
+
return this.tx.moveCall({
|
|
371
438
|
target,
|
|
372
439
|
arguments: convertedArgs,
|
|
373
440
|
typeArguments: typeArgs
|
|
@@ -380,15 +447,15 @@ var SuiTxBlock = class {
|
|
|
380
447
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
381
448
|
);
|
|
382
449
|
}
|
|
383
|
-
const coins = this.
|
|
384
|
-
this.
|
|
385
|
-
convertArgs(this.
|
|
450
|
+
const coins = this.tx.splitCoins(
|
|
451
|
+
this.tx.gas,
|
|
452
|
+
convertArgs(this.tx, amounts)
|
|
386
453
|
);
|
|
387
454
|
const recipientObjects = recipients.map(
|
|
388
|
-
(recipient) => convertAddressArg(this.
|
|
455
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
389
456
|
);
|
|
390
457
|
recipientObjects.forEach((address, index) => {
|
|
391
|
-
this.
|
|
458
|
+
this.tx.transferObjects([coins[index]], address);
|
|
392
459
|
});
|
|
393
460
|
return this;
|
|
394
461
|
}
|
|
@@ -396,32 +463,29 @@ var SuiTxBlock = class {
|
|
|
396
463
|
return this.transferSuiToMany([address], [amount]);
|
|
397
464
|
}
|
|
398
465
|
takeAmountFromCoins(coins, amount) {
|
|
399
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
466
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
400
467
|
const mergedCoin = coinObjects[0];
|
|
401
468
|
if (coins.length > 1) {
|
|
402
|
-
this.
|
|
469
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
403
470
|
}
|
|
404
|
-
const [sendCoin] = this.
|
|
471
|
+
const [sendCoin] = this.tx.splitCoins(
|
|
405
472
|
mergedCoin,
|
|
406
|
-
convertArgs(this.
|
|
473
|
+
convertArgs(this.tx, [amount])
|
|
407
474
|
);
|
|
408
475
|
return [sendCoin, mergedCoin];
|
|
409
476
|
}
|
|
410
477
|
splitSUIFromGas(amounts) {
|
|
411
|
-
return this.
|
|
412
|
-
this.txBlock.gas,
|
|
413
|
-
convertArgs(this.txBlock, amounts)
|
|
414
|
-
);
|
|
478
|
+
return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
|
|
415
479
|
}
|
|
416
480
|
splitMultiCoins(coins, amounts) {
|
|
417
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
481
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
418
482
|
const mergedCoin = coinObjects[0];
|
|
419
483
|
if (coins.length > 1) {
|
|
420
|
-
this.
|
|
484
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
421
485
|
}
|
|
422
|
-
const splitedCoins = this.
|
|
486
|
+
const splitedCoins = this.tx.splitCoins(
|
|
423
487
|
mergedCoin,
|
|
424
|
-
convertArgs(this.
|
|
488
|
+
convertArgs(this.tx, amounts)
|
|
425
489
|
);
|
|
426
490
|
return { splitedCoins, mergedCoin };
|
|
427
491
|
}
|
|
@@ -431,45 +495,42 @@ var SuiTxBlock = class {
|
|
|
431
495
|
"transferSuiToMany: recipients.length !== amounts.length"
|
|
432
496
|
);
|
|
433
497
|
}
|
|
434
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
498
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
435
499
|
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
436
500
|
coinObjects,
|
|
437
501
|
amounts
|
|
438
502
|
);
|
|
439
503
|
const recipientObjects = recipients.map(
|
|
440
|
-
(recipient) => convertAddressArg(this.
|
|
504
|
+
(recipient) => convertAddressArg(this.tx, recipient)
|
|
441
505
|
);
|
|
442
506
|
recipientObjects.forEach((address, index) => {
|
|
443
|
-
this.
|
|
507
|
+
this.tx.transferObjects([splitedCoins[index]], address);
|
|
444
508
|
});
|
|
445
|
-
this.
|
|
446
|
-
[mergedCoin],
|
|
447
|
-
convertAddressArg(this.txBlock, sender)
|
|
448
|
-
);
|
|
509
|
+
this.tx.transferObjects([mergedCoin], convertAddressArg(this.tx, sender));
|
|
449
510
|
return this;
|
|
450
511
|
}
|
|
451
512
|
transferCoin(coins, sender, recipient, amount) {
|
|
452
513
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
453
514
|
}
|
|
454
515
|
stakeSui(amount, validatorAddr) {
|
|
455
|
-
const [stakeCoin] = this.
|
|
456
|
-
this.
|
|
457
|
-
convertArgs(this.
|
|
516
|
+
const [stakeCoin] = this.tx.splitCoins(
|
|
517
|
+
this.tx.gas,
|
|
518
|
+
convertArgs(this.tx, [amount])
|
|
458
519
|
);
|
|
459
|
-
return this.
|
|
520
|
+
return this.tx.moveCall({
|
|
460
521
|
target: "0x3::sui_system::request_add_stake",
|
|
461
|
-
arguments: convertArgs(this.
|
|
522
|
+
arguments: convertArgs(this.tx, [
|
|
462
523
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
463
524
|
stakeCoin,
|
|
464
|
-
this.
|
|
525
|
+
this.tx.pure.address(validatorAddr.toString())
|
|
465
526
|
])
|
|
466
527
|
});
|
|
467
528
|
}
|
|
468
529
|
};
|
|
469
530
|
|
|
470
531
|
// src/libs/suiInteractor/suiInteractor.ts
|
|
471
|
-
import { SuiClient } from "@mysten/sui
|
|
472
|
-
import { requestSuiFromFaucetV0, getFaucetHost } from "@mysten/sui
|
|
532
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
533
|
+
import { requestSuiFromFaucetV0, getFaucetHost } from "@mysten/sui/faucet";
|
|
473
534
|
|
|
474
535
|
// src/libs/suiModel/suiOwnedObject.ts
|
|
475
536
|
var SuiOwnedObject = class {
|
|
@@ -491,8 +552,10 @@ var SuiOwnedObject = class {
|
|
|
491
552
|
return this.objectId;
|
|
492
553
|
}
|
|
493
554
|
return {
|
|
555
|
+
$kind: "Object",
|
|
494
556
|
Object: {
|
|
495
|
-
|
|
557
|
+
$kind: "ImmOrOwnedObject",
|
|
558
|
+
ImmOrOwnedObject: {
|
|
496
559
|
objectId: this.objectId,
|
|
497
560
|
version: this.version,
|
|
498
561
|
digest: this.digest
|
|
@@ -531,8 +594,10 @@ var SuiSharedObject = class {
|
|
|
531
594
|
return this.objectId;
|
|
532
595
|
}
|
|
533
596
|
return {
|
|
597
|
+
$kind: "Object",
|
|
534
598
|
Object: {
|
|
535
|
-
|
|
599
|
+
$kind: "SharedObject",
|
|
600
|
+
SharedObject: {
|
|
536
601
|
objectId: this.objectId,
|
|
537
602
|
initialSharedVersion: this.initialSharedVersion,
|
|
538
603
|
mutable
|
|
@@ -892,8 +957,7 @@ function numberToAddressHex(num) {
|
|
|
892
957
|
}
|
|
893
958
|
|
|
894
959
|
// src/obelisk.ts
|
|
895
|
-
import
|
|
896
|
-
import { BCS, getSuiMoveConfig } from "@mysten/bcs";
|
|
960
|
+
import { bcs as bcs2, fromHEX as fromHEX2, toHEX } from "@mysten/bcs";
|
|
897
961
|
function isUndefined(value) {
|
|
898
962
|
return value === void 0;
|
|
899
963
|
}
|
|
@@ -918,7 +982,7 @@ function createTx(meta, fn) {
|
|
|
918
982
|
}
|
|
919
983
|
);
|
|
920
984
|
}
|
|
921
|
-
var _query, _tx, _exec, _read;
|
|
985
|
+
var _query, _tx, _struct, _exec, _read;
|
|
922
986
|
var Obelisk = class {
|
|
923
987
|
/**
|
|
924
988
|
* Support the following ways to init the ObeliskClient:
|
|
@@ -927,7 +991,7 @@ var Obelisk = class {
|
|
|
927
991
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
928
992
|
*
|
|
929
993
|
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
930
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
994
|
+
* @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
|
|
931
995
|
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
932
996
|
* @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
933
997
|
* @param packageId
|
|
@@ -942,6 +1006,7 @@ var Obelisk = class {
|
|
|
942
1006
|
} = {}) {
|
|
943
1007
|
__privateAdd(this, _query, {});
|
|
944
1008
|
__privateAdd(this, _tx, {});
|
|
1009
|
+
__privateAdd(this, _struct, {});
|
|
945
1010
|
__privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
|
|
946
1011
|
if (isRaw === true) {
|
|
947
1012
|
return tx.moveCall({
|
|
@@ -978,33 +1043,37 @@ var Obelisk = class {
|
|
|
978
1043
|
this.packageId = packageId;
|
|
979
1044
|
if (metadata !== void 0) {
|
|
980
1045
|
this.metadata = metadata;
|
|
981
|
-
Object.values(metadata).forEach(
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
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
|
+
);
|
|
1008
1077
|
}
|
|
1009
1078
|
this.contractFactory = new SuiContractFactory({
|
|
1010
1079
|
packageId,
|
|
@@ -1017,6 +1086,9 @@ var Obelisk = class {
|
|
|
1017
1086
|
get tx() {
|
|
1018
1087
|
return __privateGet(this, _tx);
|
|
1019
1088
|
}
|
|
1089
|
+
get struct() {
|
|
1090
|
+
return __privateGet(this, _struct);
|
|
1091
|
+
}
|
|
1020
1092
|
/**
|
|
1021
1093
|
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
1022
1094
|
* else:
|
|
@@ -1049,11 +1121,20 @@ var Obelisk = class {
|
|
|
1049
1121
|
getMetadata() {
|
|
1050
1122
|
return this.contractFactory.metadata;
|
|
1051
1123
|
}
|
|
1124
|
+
getNetwork() {
|
|
1125
|
+
return this.suiInteractor.network;
|
|
1126
|
+
}
|
|
1052
1127
|
/**
|
|
1053
1128
|
* Request some SUI from faucet
|
|
1054
1129
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
1055
1130
|
*/
|
|
1056
|
-
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
|
+
}
|
|
1057
1138
|
return this.suiInteractor.requestFaucet(address, network);
|
|
1058
1139
|
}
|
|
1059
1140
|
async getBalance(coinType, derivePathParams) {
|
|
@@ -1077,18 +1158,21 @@ var Obelisk = class {
|
|
|
1077
1158
|
return this.suiInteractor.getObjects(objectIds);
|
|
1078
1159
|
}
|
|
1079
1160
|
async signTxn(tx, derivePathParams) {
|
|
1080
|
-
if (tx instanceof
|
|
1161
|
+
if (tx instanceof SuiTx || tx instanceof Transaction2) {
|
|
1081
1162
|
tx.setSender(this.getAddress(derivePathParams));
|
|
1082
1163
|
}
|
|
1083
|
-
const txBlock = tx instanceof
|
|
1084
|
-
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;
|
|
1085
1166
|
const keyPair = this.getKeypair(derivePathParams);
|
|
1086
|
-
return await keyPair.
|
|
1167
|
+
return await keyPair.signTransaction(txBytes);
|
|
1087
1168
|
}
|
|
1088
1169
|
async signAndSendTxn(tx, derivePathParams) {
|
|
1089
1170
|
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
1090
1171
|
return this.suiInteractor.sendTx(bytes, signature);
|
|
1091
1172
|
}
|
|
1173
|
+
async sendTxn(transactionBlock, signature) {
|
|
1174
|
+
return this.suiInteractor.sendTx(transactionBlock, signature);
|
|
1175
|
+
}
|
|
1092
1176
|
/**
|
|
1093
1177
|
* Transfer the given amount of SUI to the recipient
|
|
1094
1178
|
* @param recipient
|
|
@@ -1096,7 +1180,7 @@ var Obelisk = class {
|
|
|
1096
1180
|
* @param derivePathParams
|
|
1097
1181
|
*/
|
|
1098
1182
|
async transferSui(recipient, amount, derivePathParams) {
|
|
1099
|
-
const tx = new
|
|
1183
|
+
const tx = new SuiTx();
|
|
1100
1184
|
tx.transferSui(recipient, amount);
|
|
1101
1185
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1102
1186
|
}
|
|
@@ -1107,7 +1191,7 @@ var Obelisk = class {
|
|
|
1107
1191
|
* @param derivePathParams
|
|
1108
1192
|
*/
|
|
1109
1193
|
async transferSuiToMany(recipients, amounts, derivePathParams) {
|
|
1110
|
-
const tx = new
|
|
1194
|
+
const tx = new SuiTx();
|
|
1111
1195
|
tx.transferSuiToMany(recipients, amounts);
|
|
1112
1196
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1113
1197
|
}
|
|
@@ -1119,7 +1203,7 @@ var Obelisk = class {
|
|
|
1119
1203
|
* @param derivePathParams the derive path params for the current signer
|
|
1120
1204
|
*/
|
|
1121
1205
|
async transferCoinToMany(recipients, amounts, coinType, derivePathParams) {
|
|
1122
|
-
const tx = new
|
|
1206
|
+
const tx = new SuiTx();
|
|
1123
1207
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
1124
1208
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
1125
1209
|
const coins = await this.suiInteractor.selectCoins(
|
|
@@ -1144,7 +1228,7 @@ var Obelisk = class {
|
|
|
1144
1228
|
);
|
|
1145
1229
|
}
|
|
1146
1230
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
1147
|
-
const tx = new
|
|
1231
|
+
const tx = new SuiTx();
|
|
1148
1232
|
tx.transferObjects(objects, recipient);
|
|
1149
1233
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1150
1234
|
}
|
|
@@ -1155,7 +1239,7 @@ var Obelisk = class {
|
|
|
1155
1239
|
typeArguments = [],
|
|
1156
1240
|
derivePathParams
|
|
1157
1241
|
} = callParams;
|
|
1158
|
-
const tx = new
|
|
1242
|
+
const tx = new SuiTx();
|
|
1159
1243
|
tx.moveCall(target, args, typeArguments);
|
|
1160
1244
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1161
1245
|
}
|
|
@@ -1182,7 +1266,7 @@ var Obelisk = class {
|
|
|
1182
1266
|
* @param derivePathParams the derive path params for the current signer
|
|
1183
1267
|
*/
|
|
1184
1268
|
async stakeSui(amount, validatorAddr, derivePathParams) {
|
|
1185
|
-
const tx = new
|
|
1269
|
+
const tx = new SuiTx();
|
|
1186
1270
|
tx.stakeSui(amount, validatorAddr);
|
|
1187
1271
|
return this.signAndSendTxn(tx, derivePathParams);
|
|
1188
1272
|
}
|
|
@@ -1194,7 +1278,7 @@ var Obelisk = class {
|
|
|
1194
1278
|
* @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
|
|
1195
1279
|
*/
|
|
1196
1280
|
async inspectTxn(tx, derivePathParams) {
|
|
1197
|
-
const txBlock = tx instanceof
|
|
1281
|
+
const txBlock = tx instanceof SuiTx ? tx.tx : tx;
|
|
1198
1282
|
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
1199
1283
|
transactionBlock: txBlock,
|
|
1200
1284
|
sender: this.getAddress(derivePathParams)
|
|
@@ -1216,36 +1300,62 @@ var Obelisk = class {
|
|
|
1216
1300
|
}
|
|
1217
1301
|
async getEntity(worldId, schemaName, entityId) {
|
|
1218
1302
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1219
|
-
const tx = new
|
|
1220
|
-
const params = [tx.pure(worldId)];
|
|
1303
|
+
const tx = new Transaction2();
|
|
1304
|
+
const params = [tx.pure.address(worldId)];
|
|
1221
1305
|
if (entityId !== void 0) {
|
|
1222
|
-
params.push(tx.pure(entityId));
|
|
1306
|
+
params.push(tx.pure.address(entityId));
|
|
1223
1307
|
}
|
|
1224
1308
|
const getResult = await this.query[schemaModuleName].get(
|
|
1225
1309
|
tx,
|
|
1226
1310
|
params
|
|
1227
1311
|
);
|
|
1228
|
-
let
|
|
1312
|
+
let returnValues = [];
|
|
1229
1313
|
if (getResult.effects.status.status === "success") {
|
|
1230
1314
|
const resultList = getResult.results[0].returnValues;
|
|
1231
1315
|
for (const res of resultList) {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1236
|
-
|
|
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
|
+
}
|
|
1237
1347
|
}
|
|
1238
|
-
return
|
|
1348
|
+
return returnValues;
|
|
1239
1349
|
} else {
|
|
1240
1350
|
return void 0;
|
|
1241
1351
|
}
|
|
1242
1352
|
}
|
|
1243
1353
|
async containEntity(worldId, schemaName, entityId) {
|
|
1244
1354
|
const schemaModuleName = `${schemaName}_schema`;
|
|
1245
|
-
const tx = new
|
|
1246
|
-
const params = [tx.pure(worldId)];
|
|
1355
|
+
const tx = new Transaction2();
|
|
1356
|
+
const params = [tx.pure.address(worldId)];
|
|
1247
1357
|
if (entityId !== void 0) {
|
|
1248
|
-
params.push(tx.pure(entityId));
|
|
1358
|
+
params.push(tx.pure.address(entityId));
|
|
1249
1359
|
}
|
|
1250
1360
|
const getResult = await this.query[schemaModuleName].contains(
|
|
1251
1361
|
tx,
|
|
@@ -1253,9 +1363,9 @@ var Obelisk = class {
|
|
|
1253
1363
|
);
|
|
1254
1364
|
if (getResult.effects.status.status === "success") {
|
|
1255
1365
|
const res = getResult.results[0].returnValues[0];
|
|
1256
|
-
|
|
1257
|
-
const value = Uint8Array.from(
|
|
1258
|
-
return
|
|
1366
|
+
let baseValue = res[0];
|
|
1367
|
+
const value = Uint8Array.from(baseValue);
|
|
1368
|
+
return bcs2.bool().parse(value);
|
|
1259
1369
|
} else {
|
|
1260
1370
|
return void 0;
|
|
1261
1371
|
}
|
|
@@ -1317,9 +1427,13 @@ var Obelisk = class {
|
|
|
1317
1427
|
async entity_key_from_bytes(bytes) {
|
|
1318
1428
|
const hashBytes = keccak256(bytes);
|
|
1319
1429
|
const hashU8Array = Array.from(hashBytes);
|
|
1320
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
1321
1430
|
const value = Uint8Array.from(hashU8Array);
|
|
1322
|
-
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);
|
|
1323
1437
|
return "0x" + data;
|
|
1324
1438
|
}
|
|
1325
1439
|
async entity_key_from_address_with_seed(objectId, seed) {
|
|
@@ -1337,9 +1451,8 @@ var Obelisk = class {
|
|
|
1337
1451
|
const checkObjectId = normalizeHexAddress(objectId);
|
|
1338
1452
|
if (checkObjectId !== null) {
|
|
1339
1453
|
objectId = checkObjectId;
|
|
1340
|
-
const bcs = new BCS(getSuiMoveConfig());
|
|
1341
1454
|
const bytes = Buffer.from(objectId.slice(2), "hex");
|
|
1342
|
-
const numberBytes =
|
|
1455
|
+
const numberBytes = bcs2.u256().serialize(x).toBytes();
|
|
1343
1456
|
return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
|
|
1344
1457
|
} else {
|
|
1345
1458
|
return void 0;
|
|
@@ -1348,23 +1461,65 @@ var Obelisk = class {
|
|
|
1348
1461
|
async entity_key_from_u256(x) {
|
|
1349
1462
|
return numberToAddressHex(x);
|
|
1350
1463
|
}
|
|
1351
|
-
async formatData(type, value) {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
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
|
+
}
|
|
1355
1509
|
}
|
|
1356
1510
|
};
|
|
1357
1511
|
_query = new WeakMap();
|
|
1358
1512
|
_tx = new WeakMap();
|
|
1513
|
+
_struct = new WeakMap();
|
|
1359
1514
|
_exec = new WeakMap();
|
|
1360
1515
|
_read = new WeakMap();
|
|
1361
1516
|
|
|
1362
1517
|
// src/libs/multiSig/client.ts
|
|
1363
|
-
import { MultiSigPublicKey } from "@mysten/sui
|
|
1518
|
+
import { MultiSigPublicKey } from "@mysten/sui/multisig";
|
|
1364
1519
|
|
|
1365
1520
|
// src/libs/multiSig/publickey.ts
|
|
1366
|
-
import { Ed25519PublicKey } from "@mysten/sui
|
|
1367
|
-
import { fromB64 as fromB642 } from "@mysten/sui
|
|
1521
|
+
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
1522
|
+
import { fromB64 as fromB642 } from "@mysten/sui/utils";
|
|
1368
1523
|
function ed25519PublicKeyFromBase64(rawPubkey) {
|
|
1369
1524
|
let bytes = fromB642(rawPubkey);
|
|
1370
1525
|
if (bytes.length !== 32 && bytes.length !== 33)
|
|
@@ -1401,7 +1556,7 @@ var MultiSigClient = class _MultiSigClient {
|
|
|
1401
1556
|
};
|
|
1402
1557
|
|
|
1403
1558
|
// src/metadata/index.ts
|
|
1404
|
-
import { getFullnodeUrl as getFullnodeUrl2 } from "@mysten/sui
|
|
1559
|
+
import { getFullnodeUrl as getFullnodeUrl2 } from "@mysten/sui/client";
|
|
1405
1560
|
async function loadMetadata(networkType, packageId) {
|
|
1406
1561
|
const fullnodeUrls = [getFullnodeUrl2(networkType)];
|
|
1407
1562
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
@@ -1415,13 +1570,13 @@ async function loadMetadata(networkType, packageId) {
|
|
|
1415
1570
|
}
|
|
1416
1571
|
}
|
|
1417
1572
|
export {
|
|
1418
|
-
|
|
1573
|
+
BcsType,
|
|
1419
1574
|
MultiSigClient,
|
|
1420
1575
|
Obelisk,
|
|
1421
1576
|
SuiAccountManager,
|
|
1422
1577
|
SuiContractFactory,
|
|
1423
|
-
|
|
1424
|
-
|
|
1578
|
+
SuiTx,
|
|
1579
|
+
bcs3 as bcs,
|
|
1425
1580
|
loadMetadata
|
|
1426
1581
|
};
|
|
1427
1582
|
//# sourceMappingURL=index.mjs.map
|