@0xobelisk/sui-client 0.5.18 → 0.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -0
- package/dist/index.js +93 -134
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -104
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +15 -0
- package/dist/libs/multiSig/index.d.ts +1 -0
- package/dist/libs/multiSig/publickey.d.ts +2 -0
- package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
- package/dist/libs/suiAccountManager/index.d.ts +39 -0
- package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
- package/dist/libs/suiAccountManager/util.d.ts +29 -0
- package/dist/libs/suiContractFactory/index.d.ts +20 -0
- package/dist/libs/suiContractFactory/types.d.ts +49 -0
- package/dist/libs/suiInteractor/index.d.ts +1 -0
- package/dist/libs/suiInteractor/suiInteractor.d.ts +50 -0
- package/dist/libs/suiInteractor/util.d.ts +1 -0
- package/dist/libs/suiModel/index.d.ts +2 -0
- package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
- package/dist/libs/suiModel/suiSharedObject.d.ts +11 -0
- package/dist/libs/suiTxBuilder/index.d.ts +538 -0
- package/dist/libs/suiTxBuilder/util.d.ts +49 -0
- package/dist/metadata/index.d.ts +3 -0
- package/dist/obelisk.d.ts +140 -0
- package/dist/types/index.d.ts +202 -0
- package/dist/utils/index.d.ts +3 -0
- package/package.json +2 -5
- package/src/libs/multiSig/client.ts +1 -1
- package/src/libs/suiAccountManager/index.ts +4 -5
- package/src/libs/suiInteractor/index.ts +0 -1
- package/src/libs/suiModel/suiOwnedObject.ts +2 -2
- package/src/libs/suiModel/suiSharedObject.ts +2 -2
- package/src/libs/suiTxBuilder/index.ts +43 -49
- package/src/libs/suiTxBuilder/util.ts +65 -129
- package/src/types/index.ts +40 -16
package/dist/index.mjs
CHANGED
|
@@ -29,10 +29,6 @@ import { Transaction as Transaction2 } from "@mysten/sui/transactions";
|
|
|
29
29
|
|
|
30
30
|
// src/libs/suiAccountManager/index.ts
|
|
31
31
|
import { Ed25519Keypair as Ed25519Keypair2 } from "@mysten/sui/keypairs/ed25519";
|
|
32
|
-
import {
|
|
33
|
-
SUI_PRIVATE_KEY_PREFIX,
|
|
34
|
-
decodeSuiPrivateKey
|
|
35
|
-
} from "@mysten/sui/cryptography";
|
|
36
32
|
|
|
37
33
|
// src/libs/suiAccountManager/keypair.ts
|
|
38
34
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
@@ -94,6 +90,10 @@ var generateMnemonic = (numberOfWords = 24) => {
|
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
// src/libs/suiAccountManager/index.ts
|
|
93
|
+
import {
|
|
94
|
+
SUI_PRIVATE_KEY_PREFIX,
|
|
95
|
+
decodeSuiPrivateKey
|
|
96
|
+
} from "@mysten/sui/cryptography";
|
|
97
97
|
var SuiAccountManager = class {
|
|
98
98
|
/**
|
|
99
99
|
* Support the following ways to init the SuiToolkit:
|
|
@@ -170,9 +170,8 @@ import {
|
|
|
170
170
|
isValidSuiObjectId,
|
|
171
171
|
isValidSuiAddress
|
|
172
172
|
} from "@mysten/sui/utils";
|
|
173
|
-
import { Inputs } from "@mysten/sui/transactions";
|
|
174
|
-
import { isSerializedBcs } from "@mysten/bcs";
|
|
175
|
-
import { bcs } from "@mysten/sui/bcs";
|
|
173
|
+
import { Inputs, getPureBcsSchema } from "@mysten/sui/transactions";
|
|
174
|
+
import { SerializedBcs, bcs, isSerializedBcs } from "@mysten/bcs";
|
|
176
175
|
var getDefaultSuiInputType = (value) => {
|
|
177
176
|
if (typeof value === "string" && isValidSuiObjectId(value)) {
|
|
178
177
|
return "object";
|
|
@@ -184,10 +183,7 @@ var getDefaultSuiInputType = (value) => {
|
|
|
184
183
|
return void 0;
|
|
185
184
|
}
|
|
186
185
|
};
|
|
187
|
-
function
|
|
188
|
-
return arg.Pure !== void 0;
|
|
189
|
-
}
|
|
190
|
-
function makeVecParam(tx, args, type) {
|
|
186
|
+
function makeVecParam(txBlock, args, type) {
|
|
191
187
|
if (args.length === 0)
|
|
192
188
|
throw new Error("Transaction builder error: Empty array is not allowed");
|
|
193
189
|
const defaultSuiType = getDefaultSuiInputType(args[0]);
|
|
@@ -196,32 +192,17 @@ function makeVecParam(tx, args, type) {
|
|
|
196
192
|
type = type || defaultSuiType;
|
|
197
193
|
if (type === "object") {
|
|
198
194
|
const elements = args.map(
|
|
199
|
-
(arg) => typeof arg === "string" && isValidSuiObjectId(arg) ?
|
|
195
|
+
(arg) => typeof arg === "string" && isValidSuiObjectId(arg) ? txBlock.object(normalizeSuiObjectId(arg)) : convertObjArg(txBlock, arg)
|
|
200
196
|
);
|
|
201
|
-
return
|
|
197
|
+
return txBlock.makeMoveVec({ elements });
|
|
202
198
|
} else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
199
|
+
const bcsSchema = getPureBcsSchema(type);
|
|
200
|
+
return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
|
|
222
201
|
} else {
|
|
223
|
-
const elements = args.map(
|
|
224
|
-
|
|
202
|
+
const elements = args.map(
|
|
203
|
+
(arg) => convertObjArg(txBlock, arg)
|
|
204
|
+
);
|
|
205
|
+
return txBlock.makeMoveVec({ elements, type });
|
|
225
206
|
}
|
|
226
207
|
}
|
|
227
208
|
function isMoveVecArg(arg) {
|
|
@@ -232,74 +213,61 @@ function isMoveVecArg(arg) {
|
|
|
232
213
|
}
|
|
233
214
|
return false;
|
|
234
215
|
}
|
|
235
|
-
function convertArgs(
|
|
216
|
+
function convertArgs(txBlock, args) {
|
|
236
217
|
return args.map((arg) => {
|
|
237
|
-
if (
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
} else if (isMoveVecArg(arg)) {
|
|
218
|
+
if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
|
|
219
|
+
return txBlock.pure(arg);
|
|
220
|
+
}
|
|
221
|
+
if (isMoveVecArg(arg)) {
|
|
242
222
|
const vecType = "vecType" in arg;
|
|
243
|
-
return vecType ? makeVecParam(
|
|
244
|
-
} else if (isSerializedBcs(arg)) {
|
|
245
|
-
return arg;
|
|
246
|
-
} else {
|
|
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
|
-
}
|
|
223
|
+
return vecType ? makeVecParam(txBlock, arg.value, arg.vecType) : makeVecParam(txBlock, arg);
|
|
257
224
|
}
|
|
225
|
+
return arg;
|
|
258
226
|
});
|
|
259
227
|
}
|
|
260
|
-
function convertAddressArg(
|
|
228
|
+
function convertAddressArg(txBlock, arg) {
|
|
261
229
|
if (typeof arg === "string" && isValidSuiAddress(arg)) {
|
|
262
|
-
return
|
|
263
|
-
} else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg)) {
|
|
264
|
-
return convertObjArg(tx, arg);
|
|
265
|
-
} else if (isPureArg(arg)) {
|
|
266
|
-
return tx.pure(Uint8Array.from(arg.Pure));
|
|
230
|
+
return txBlock.pure.address(normalizeSuiAddress(arg));
|
|
267
231
|
} else {
|
|
268
|
-
return arg;
|
|
232
|
+
return convertArgs(txBlock, [arg])[0];
|
|
269
233
|
}
|
|
270
234
|
}
|
|
271
|
-
function convertObjArg(
|
|
235
|
+
function convertObjArg(txb, arg) {
|
|
272
236
|
if (typeof arg === "string") {
|
|
273
|
-
return
|
|
237
|
+
return txb.object(arg);
|
|
274
238
|
}
|
|
275
239
|
if ("digest" in arg && "version" in arg && "objectId" in arg) {
|
|
276
|
-
return
|
|
240
|
+
return txb.objectRef(arg);
|
|
277
241
|
}
|
|
278
242
|
if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
|
|
279
|
-
return
|
|
243
|
+
return txb.sharedObjectRef(arg);
|
|
280
244
|
}
|
|
281
245
|
if ("Object" in arg) {
|
|
282
246
|
if ("ImmOrOwnedObject" in arg.Object) {
|
|
283
|
-
return
|
|
284
|
-
Inputs.ObjectRef(arg.Object.ImmOrOwnedObject)
|
|
285
|
-
);
|
|
247
|
+
return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
|
|
286
248
|
} else if ("SharedObject" in arg.Object) {
|
|
287
|
-
return
|
|
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));
|
|
249
|
+
return txb.object(Inputs.SharedObjectRef(arg.Object.SharedObject));
|
|
294
250
|
} else {
|
|
295
251
|
throw new Error("Invalid argument type");
|
|
296
252
|
}
|
|
297
253
|
}
|
|
298
|
-
if ("
|
|
254
|
+
if (typeof arg === "function") {
|
|
255
|
+
return arg;
|
|
256
|
+
}
|
|
257
|
+
if ("GasCoin" in arg || "Input" in arg || "Result" in arg || "NestedResult" in arg) {
|
|
299
258
|
return arg;
|
|
300
259
|
}
|
|
301
260
|
throw new Error("Invalid argument type");
|
|
302
261
|
}
|
|
262
|
+
function convertAmounts(txBlock, amounts) {
|
|
263
|
+
return amounts.map((amount) => {
|
|
264
|
+
if (typeof amount === "number" || typeof amount === "bigint") {
|
|
265
|
+
return amount;
|
|
266
|
+
} else {
|
|
267
|
+
return convertArgs(txBlock, [amount])[0];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
303
271
|
|
|
304
272
|
// src/libs/suiTxBuilder/index.ts
|
|
305
273
|
var SuiTx = class {
|
|
@@ -326,8 +294,8 @@ var SuiTx = class {
|
|
|
326
294
|
address(value) {
|
|
327
295
|
return this.tx.pure.address(value);
|
|
328
296
|
}
|
|
329
|
-
pure(
|
|
330
|
-
return this.tx.pure(
|
|
297
|
+
get pure() {
|
|
298
|
+
return this.tx.pure.bind(this.tx);
|
|
331
299
|
}
|
|
332
300
|
object(value) {
|
|
333
301
|
return this.tx.object(value);
|
|
@@ -362,6 +330,9 @@ var SuiTx = class {
|
|
|
362
330
|
serialize() {
|
|
363
331
|
return this.tx.serialize();
|
|
364
332
|
}
|
|
333
|
+
toJSON() {
|
|
334
|
+
return this.tx.toJSON();
|
|
335
|
+
}
|
|
365
336
|
sign(params) {
|
|
366
337
|
return this.tx.sign(params);
|
|
367
338
|
}
|
|
@@ -380,24 +351,11 @@ var SuiTx = class {
|
|
|
380
351
|
}) {
|
|
381
352
|
return this.tx.publish({ modules, dependencies });
|
|
382
353
|
}
|
|
383
|
-
upgrade({
|
|
384
|
-
|
|
385
|
-
dependencies,
|
|
386
|
-
package: packageId,
|
|
387
|
-
ticket
|
|
388
|
-
}) {
|
|
389
|
-
return this.tx.upgrade({
|
|
390
|
-
modules,
|
|
391
|
-
dependencies,
|
|
392
|
-
package: packageId,
|
|
393
|
-
ticket
|
|
394
|
-
});
|
|
354
|
+
upgrade(...args) {
|
|
355
|
+
return this.tx.upgrade(...args);
|
|
395
356
|
}
|
|
396
|
-
makeMoveVec({
|
|
397
|
-
|
|
398
|
-
type
|
|
399
|
-
}) {
|
|
400
|
-
return this.tx.makeMoveVec({ elements, type });
|
|
357
|
+
makeMoveVec(...args) {
|
|
358
|
+
return this.tx.makeMoveVec(...args);
|
|
401
359
|
}
|
|
402
360
|
/* Override methods of TransactionBlock */
|
|
403
361
|
transferObjects(objects, address) {
|
|
@@ -449,7 +407,9 @@ var SuiTx = class {
|
|
|
449
407
|
}
|
|
450
408
|
const coins = this.tx.splitCoins(
|
|
451
409
|
this.tx.gas,
|
|
452
|
-
|
|
410
|
+
amounts.map(
|
|
411
|
+
(amount) => typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
|
|
412
|
+
)
|
|
453
413
|
);
|
|
454
414
|
const recipientObjects = recipients.map(
|
|
455
415
|
(recipient) => convertAddressArg(this.tx, recipient)
|
|
@@ -468,10 +428,9 @@ var SuiTx = class {
|
|
|
468
428
|
if (coins.length > 1) {
|
|
469
429
|
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
470
430
|
}
|
|
471
|
-
const [sendCoin] = this.tx.splitCoins(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
);
|
|
431
|
+
const [sendCoin] = this.tx.splitCoins(mergedCoin, [
|
|
432
|
+
typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
|
|
433
|
+
]);
|
|
475
434
|
return [sendCoin, mergedCoin];
|
|
476
435
|
}
|
|
477
436
|
splitSUIFromGas(amounts) {
|
|
@@ -485,7 +444,7 @@ var SuiTx = class {
|
|
|
485
444
|
}
|
|
486
445
|
const splitedCoins = this.tx.splitCoins(
|
|
487
446
|
mergedCoin,
|
|
488
|
-
|
|
447
|
+
convertAmounts(this.tx, amounts)
|
|
489
448
|
);
|
|
490
449
|
return { splitedCoins, mergedCoin };
|
|
491
450
|
}
|
|
@@ -515,14 +474,14 @@ var SuiTx = class {
|
|
|
515
474
|
stakeSui(amount, validatorAddr) {
|
|
516
475
|
const [stakeCoin] = this.tx.splitCoins(
|
|
517
476
|
this.tx.gas,
|
|
518
|
-
|
|
477
|
+
convertAmounts(this.tx, [amount])
|
|
519
478
|
);
|
|
520
479
|
return this.tx.moveCall({
|
|
521
480
|
target: "0x3::sui_system::request_add_stake",
|
|
522
481
|
arguments: convertArgs(this.tx, [
|
|
523
|
-
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
482
|
+
this.tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
524
483
|
stakeCoin,
|
|
525
|
-
this.tx
|
|
484
|
+
convertAddressArg(this.tx, validatorAddr)
|
|
526
485
|
])
|
|
527
486
|
});
|
|
528
487
|
}
|