@0xobelisk/client 0.2.8 → 0.3.0
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 +179 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -5
- package/src/libs/suiInteractor/suiInteractor.ts +59 -9
- package/src/obelisk.ts +164 -2
- package/src/types/index.ts +79 -51
- package/src/utils/index.ts +21 -1
- package/dist/framework/bcs.d.ts +0 -3
- package/dist/framework/loader.d.ts +0 -11
- package/dist/framework/util.d.ts +0 -90
- package/dist/index.d.ts +0 -9
- 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/types.d.ts +0 -9
- 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/defaultConfig.d.ts +0 -10
- package/dist/libs/suiInteractor/index.d.ts +0 -2
- package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -204
- 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 -12
- package/dist/libs/suiRpcProvider/defaultChainConfigs.d.ts +0 -8
- package/dist/libs/suiRpcProvider/faucet.d.ts +0 -8
- package/dist/libs/suiRpcProvider/index.d.ts +0 -213
- package/dist/libs/suiRpcProvider/types.d.ts +0 -14
- package/dist/libs/suiTxBuilder/index.d.ts +0 -544
- package/dist/libs/suiTxBuilder/types.d.ts +0 -12
- package/dist/libs/suiTxBuilder/util.d.ts +0 -76
- package/dist/metadata/index.d.ts +0 -34
- package/dist/obelisk.d.ts +0 -2691
- package/dist/types/index.d.ts +0 -114
- package/dist/utils/index.d.ts +0 -1
- package/src/framework/bcs.ts +0 -6
- package/src/framework/loader.ts +0 -152
- package/src/framework/util.ts +0 -219
|
@@ -10,11 +10,21 @@ import {
|
|
|
10
10
|
getObjectVersion,
|
|
11
11
|
getSharedObjectInitialVersion,
|
|
12
12
|
DynamicFieldName,
|
|
13
|
-
SuiAddress
|
|
13
|
+
SuiAddress,
|
|
14
14
|
} from '@mysten/sui.js';
|
|
15
15
|
import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui.js/faucet';
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import {
|
|
17
|
+
SuiClient,
|
|
18
|
+
getFullnodeUrl,
|
|
19
|
+
GetBalanceParams,
|
|
20
|
+
} from '@mysten/sui.js/client';
|
|
21
|
+
import {
|
|
22
|
+
FaucetNetworkType,
|
|
23
|
+
NetworkType,
|
|
24
|
+
ObjectData,
|
|
25
|
+
ObjectFieldType,
|
|
26
|
+
EntityData,
|
|
27
|
+
} from 'src/types';
|
|
18
28
|
import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
|
|
19
29
|
import { delay } from './util';
|
|
20
30
|
|
|
@@ -78,6 +88,7 @@ export class SuiInteractor {
|
|
|
78
88
|
}
|
|
79
89
|
throw new Error('Failed to send transaction with all fullnodes');
|
|
80
90
|
}
|
|
91
|
+
|
|
81
92
|
async getObjects(ids: string[]) {
|
|
82
93
|
const options = {
|
|
83
94
|
showContent: true,
|
|
@@ -129,11 +140,50 @@ export class SuiInteractor {
|
|
|
129
140
|
return objects[0];
|
|
130
141
|
}
|
|
131
142
|
|
|
143
|
+
async getEntitiesObjects(ids: string[]) {
|
|
144
|
+
const options = {
|
|
145
|
+
showContent: true,
|
|
146
|
+
showType: true,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// const currentProviderIdx = this.providers.indexOf(this.currentProvider);
|
|
150
|
+
// const providers = [
|
|
151
|
+
// ...this.providers.slice(currentProviderIdx, this.providers.length),
|
|
152
|
+
// ...this.providers.slice(0, currentProviderIdx),
|
|
153
|
+
// ]
|
|
154
|
+
|
|
155
|
+
for (const provider of this.providers) {
|
|
156
|
+
try {
|
|
157
|
+
const objects = await provider.multiGetObjects({ ids, options });
|
|
158
|
+
const parsedObjects = objects.map((object) => {
|
|
159
|
+
const objectId = getObjectId(object);
|
|
160
|
+
const objectFields = getObjectFields(object) as ObjectFieldType;
|
|
161
|
+
const index = objectFields.name;
|
|
162
|
+
const key = objectFields.value;
|
|
163
|
+
return {
|
|
164
|
+
objectId,
|
|
165
|
+
index,
|
|
166
|
+
key,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return parsedObjects as EntityData[];
|
|
170
|
+
} catch (err) {
|
|
171
|
+
await delay(2000);
|
|
172
|
+
console.warn(
|
|
173
|
+
`Failed to get objects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
throw new Error('Failed to get objects with all fullnodes');
|
|
178
|
+
}
|
|
132
179
|
|
|
133
|
-
async getDynamicFieldObject(
|
|
180
|
+
async getDynamicFieldObject(
|
|
181
|
+
parentId: string,
|
|
182
|
+
name: string | DynamicFieldName
|
|
183
|
+
) {
|
|
134
184
|
for (const provider of this.providers) {
|
|
135
185
|
try {
|
|
136
|
-
return provider.getDynamicFieldObject({ parentId, name })
|
|
186
|
+
return provider.getDynamicFieldObject({ parentId, name });
|
|
137
187
|
} catch (err) {
|
|
138
188
|
await delay(2000);
|
|
139
189
|
console.warn(
|
|
@@ -147,7 +197,7 @@ export class SuiInteractor {
|
|
|
147
197
|
async getDynamicFields(parentId: string, cursor?: string, limit?: number) {
|
|
148
198
|
for (const provider of this.providers) {
|
|
149
199
|
try {
|
|
150
|
-
return provider.getDynamicFields({ parentId, cursor, limit })
|
|
200
|
+
return provider.getDynamicFields({ parentId, cursor, limit });
|
|
151
201
|
} catch (err) {
|
|
152
202
|
await delay(2000);
|
|
153
203
|
console.warn(
|
|
@@ -172,12 +222,12 @@ export class SuiInteractor {
|
|
|
172
222
|
throw new Error('Failed to get objects with all fullnodes');
|
|
173
223
|
}
|
|
174
224
|
|
|
175
|
-
|
|
176
225
|
async getNormalizedMoveModulesByPackage(packageId: string) {
|
|
177
226
|
for (const provider of this.providers) {
|
|
178
227
|
try {
|
|
179
|
-
return provider.getNormalizedMoveModulesByPackage({
|
|
180
|
-
|
|
228
|
+
return provider.getNormalizedMoveModulesByPackage({
|
|
229
|
+
package: packageId,
|
|
230
|
+
});
|
|
181
231
|
} catch (err) {
|
|
182
232
|
await delay(2000);
|
|
183
233
|
console.warn(
|
package/src/obelisk.ts
CHANGED
|
@@ -30,9 +30,16 @@ import {
|
|
|
30
30
|
MapMoudleFuncQuery,
|
|
31
31
|
MapMoudleFuncTx,
|
|
32
32
|
FaucetNetworkType,
|
|
33
|
+
SuiReturnValues,
|
|
34
|
+
DynamicFieldContentType,
|
|
33
35
|
} from './types';
|
|
34
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
capitalizeFirstLetter,
|
|
38
|
+
normalizeHexAddress,
|
|
39
|
+
numberToAddressHex,
|
|
40
|
+
} from './utils';
|
|
35
41
|
import keccak256 from 'keccak256';
|
|
42
|
+
import { BCS, getSuiMoveConfig, fromHEX, fromB64, fromB58 } from '@mysten/bcs';
|
|
36
43
|
|
|
37
44
|
export function isUndefined(value?: unknown): value is undefined {
|
|
38
45
|
return value === undefined;
|
|
@@ -467,11 +474,137 @@ export class Obelisk {
|
|
|
467
474
|
const name = {
|
|
468
475
|
type: 'address',
|
|
469
476
|
value: componentIdValue,
|
|
470
|
-
// value: [250,208,186,160,39,171,62,206,98,224,138,41,11,217,63,100,248,104,207,64,78,126,43,109,129,68,64,127,236,113,152,132]
|
|
471
477
|
} as DynamicFieldName;
|
|
472
478
|
return await this.suiInteractor.getDynamicFieldObject(parentId, name);
|
|
473
479
|
}
|
|
474
480
|
|
|
481
|
+
async getComponentTable(worldId: string, componentName: string) {
|
|
482
|
+
let componentMoudleName = `${componentName}_comp`;
|
|
483
|
+
const tx = new TransactionBlock();
|
|
484
|
+
let params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
485
|
+
|
|
486
|
+
const tableResult = (await this.query[componentMoudleName].data(
|
|
487
|
+
tx,
|
|
488
|
+
params
|
|
489
|
+
)) as DevInspectResults;
|
|
490
|
+
const tableId = tableResult.results as SuiReturnValues;
|
|
491
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
492
|
+
|
|
493
|
+
let value = Uint8Array.from(tableId[0].returnValues[0][0]);
|
|
494
|
+
let data = bcs.de('address', value);
|
|
495
|
+
return '0x' + data;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
async getEntities(
|
|
499
|
+
worldId: string,
|
|
500
|
+
componentName: string,
|
|
501
|
+
cursor?: string,
|
|
502
|
+
limit?: number
|
|
503
|
+
) {
|
|
504
|
+
let componentMoudleName = `${componentName}_comp`;
|
|
505
|
+
|
|
506
|
+
const tx = new TransactionBlock();
|
|
507
|
+
let params = [tx.pure(worldId)] as SuiTxArgument[];
|
|
508
|
+
|
|
509
|
+
const tableResult = (await this.query[componentMoudleName].entities(
|
|
510
|
+
tx,
|
|
511
|
+
params
|
|
512
|
+
)) as DevInspectResults;
|
|
513
|
+
const entities = tableResult.results as SuiReturnValues;
|
|
514
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
515
|
+
|
|
516
|
+
let value = Uint8Array.from(entities[0].returnValues[0][0]);
|
|
517
|
+
let tableId = '0x' + bcs.de('address', value);
|
|
518
|
+
let dynamicFields = await this.suiInteractor.getDynamicFields(
|
|
519
|
+
tableId,
|
|
520
|
+
cursor,
|
|
521
|
+
limit
|
|
522
|
+
);
|
|
523
|
+
let objectIds = dynamicFields.data.map((field) => field.objectId);
|
|
524
|
+
let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
|
|
525
|
+
return {
|
|
526
|
+
data: objectDatas,
|
|
527
|
+
nextCursor: dynamicFields.nextCursor,
|
|
528
|
+
hasNextPage: dynamicFields.hasNextPage,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async getEntity(worldId: string, componentName: string, entityId: string) {
|
|
533
|
+
let checkWorldId = normalizeHexAddress(worldId);
|
|
534
|
+
if (checkWorldId) {
|
|
535
|
+
worldId = checkWorldId;
|
|
536
|
+
} else {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let checkEntityId = normalizeHexAddress(entityId);
|
|
541
|
+
if (checkEntityId) {
|
|
542
|
+
entityId = checkEntityId;
|
|
543
|
+
} else {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const parentId = await this.getComponentTable(worldId, componentName);
|
|
548
|
+
const name = {
|
|
549
|
+
type: 'address',
|
|
550
|
+
value: entityId,
|
|
551
|
+
} as DynamicFieldName;
|
|
552
|
+
|
|
553
|
+
let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
554
|
+
parentId,
|
|
555
|
+
name
|
|
556
|
+
);
|
|
557
|
+
return dynamicFieldObject;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// async getEntityData(
|
|
561
|
+
// worldId: string,
|
|
562
|
+
// componentName: string,
|
|
563
|
+
// entityId: string
|
|
564
|
+
// ) {
|
|
565
|
+
// const parentId = await this.getComponentTable(worldId, componentName);
|
|
566
|
+
// const name = {
|
|
567
|
+
// type: 'address',
|
|
568
|
+
// value: entityId,
|
|
569
|
+
// } as DynamicFieldName;
|
|
570
|
+
|
|
571
|
+
// let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
|
|
572
|
+
// parentId,
|
|
573
|
+
// name
|
|
574
|
+
// );
|
|
575
|
+
// let componentMoudleName = `${componentName}_comp`;
|
|
576
|
+
|
|
577
|
+
// const tx = new TransactionBlock();
|
|
578
|
+
// let params = [] as SuiTxArgument[];
|
|
579
|
+
|
|
580
|
+
// const typeResult = (await this.query[componentMoudleName].types(
|
|
581
|
+
// tx,
|
|
582
|
+
// params
|
|
583
|
+
// )) as DevInspectResults;
|
|
584
|
+
// let typeReturn = typeResult.results as SuiReturnValues;
|
|
585
|
+
// console.log(typeReturn[0].returnValues[0][0]);
|
|
586
|
+
|
|
587
|
+
// const typeBCS = new BCS(getSuiMoveConfig());
|
|
588
|
+
// let typeValue = Uint8Array.from(typeReturn[0].returnValues[0][0]);
|
|
589
|
+
|
|
590
|
+
// let typeData = typeBCS.de('vector<vector<u8>>', typeValue);
|
|
591
|
+
// console.log(typeData);
|
|
592
|
+
// const entityType = String.fromCharCode(...typeData[0]);
|
|
593
|
+
|
|
594
|
+
// let dynamicFieldContent = dynamicFieldObject.data!
|
|
595
|
+
// .content as DynamicFieldContentType;
|
|
596
|
+
|
|
597
|
+
// let entityValue = dynamicFieldContent.fields['value'];
|
|
598
|
+
// const bcs = new BCS(getSuiMoveConfig());
|
|
599
|
+
// let value = Uint8Array.from(entityValue);
|
|
600
|
+
// console.log(entityType);
|
|
601
|
+
// console.log(value);
|
|
602
|
+
|
|
603
|
+
// let data = bcs.de(entityType, value);
|
|
604
|
+
// console.log(data);
|
|
605
|
+
// return data;
|
|
606
|
+
// }
|
|
607
|
+
|
|
475
608
|
async getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number) {
|
|
476
609
|
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
477
610
|
owner,
|
|
@@ -493,4 +626,33 @@ export class Obelisk {
|
|
|
493
626
|
|
|
494
627
|
return ownedObjectsRes;
|
|
495
628
|
}
|
|
629
|
+
|
|
630
|
+
async entity_key_from_object(objectId: string) {
|
|
631
|
+
let checkObjectId = normalizeHexAddress(objectId);
|
|
632
|
+
if (checkObjectId !== null) {
|
|
633
|
+
objectId = checkObjectId;
|
|
634
|
+
return objectId;
|
|
635
|
+
} else {
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async entity_key_from_bytes(bytes: Uint8Array | Buffer | string) {
|
|
641
|
+
let hashBytes = keccak256(bytes);
|
|
642
|
+
const hashU8Array: number[] = Array.from(hashBytes);
|
|
643
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
644
|
+
let value = Uint8Array.from(hashU8Array);
|
|
645
|
+
let data = bcs.de('address', value);
|
|
646
|
+
return '0x' + data;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async entity_key_from_u256(x: number) {
|
|
650
|
+
return numberToAddressHex(x);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
async formatData(type: string, value: Buffer | number[] | Uint8Array) {
|
|
654
|
+
const bcs = new BCS(getSuiMoveConfig());
|
|
655
|
+
let u8Value = Uint8Array.from(value);
|
|
656
|
+
return bcs.de(type, u8Value);
|
|
657
|
+
}
|
|
496
658
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
TransactionBlock,
|
|
10
10
|
SuiTransactionBlockResponse,
|
|
11
11
|
DevInspectResults,
|
|
12
|
-
SuiMoveNormalizedModules
|
|
12
|
+
SuiMoveNormalizedModules,
|
|
13
13
|
} from '@mysten/sui.js';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
import {
|
|
16
|
+
SuiMoveMoudleValueType,
|
|
17
|
+
SuiMoveMoudleFuncType,
|
|
18
|
+
} from '../libs/suiContractFactory/types';
|
|
18
19
|
|
|
19
20
|
export type ObeliskObjectData = {
|
|
20
21
|
objectId: string;
|
|
@@ -24,73 +25,79 @@ export type ObeliskObjectData = {
|
|
|
24
25
|
objectFields: ObjectContentFields;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
|
|
28
28
|
export type ObeliskParams = {
|
|
29
29
|
mnemonics?: string;
|
|
30
30
|
secretKey?: string;
|
|
31
31
|
fullnodeUrls?: string[];
|
|
32
32
|
faucetUrl?: string;
|
|
33
33
|
networkType?: NetworkType;
|
|
34
|
-
packageId?: string
|
|
35
|
-
metadata?: SuiMoveNormalizedModules
|
|
34
|
+
packageId?: string;
|
|
35
|
+
metadata?: SuiMoveNormalizedModules;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type ComponentFieldType = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
39
|
+
components: {
|
|
40
|
+
type: string;
|
|
41
|
+
fields: {
|
|
42
|
+
id: {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
size: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
export type ComponentValueType = {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
id: {
|
|
52
|
+
id: string;
|
|
53
|
+
};
|
|
54
|
+
name: string;
|
|
55
|
+
value: {
|
|
56
|
+
type: string;
|
|
57
|
+
fields: ComponentFieldType;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type SuiTxArgument =
|
|
62
|
+
| {
|
|
63
|
+
kind: 'Input';
|
|
64
|
+
index: number;
|
|
65
|
+
type?: 'object' | 'pure' | undefined;
|
|
66
|
+
value?: any;
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type: string;
|
|
57
|
-
fields: ComponentFieldType;
|
|
68
|
+
| {
|
|
69
|
+
kind: 'GasCoin';
|
|
58
70
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
kind: "GasCoin";
|
|
69
|
-
} | {
|
|
70
|
-
kind: "Result";
|
|
71
|
-
index: number;
|
|
72
|
-
} | {
|
|
73
|
-
kind: "NestedResult";
|
|
74
|
-
index: number;
|
|
75
|
-
resultIndex: number;
|
|
76
|
-
}
|
|
71
|
+
| {
|
|
72
|
+
kind: 'Result';
|
|
73
|
+
index: number;
|
|
74
|
+
}
|
|
75
|
+
| {
|
|
76
|
+
kind: 'NestedResult';
|
|
77
|
+
index: number;
|
|
78
|
+
resultIndex: number;
|
|
79
|
+
};
|
|
77
80
|
export type ComponentContentType = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
81
|
+
type: string;
|
|
82
|
+
fields: ComponentValueType;
|
|
83
|
+
hasPublicTransfer: boolean;
|
|
84
|
+
dataType: 'moveObject';
|
|
85
|
+
};
|
|
83
86
|
|
|
84
87
|
export interface MessageMeta {
|
|
85
88
|
readonly meta: SuiMoveMoudleFuncType;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
export interface ContractQuery extends MessageMeta {
|
|
89
|
-
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean): Promise<
|
|
92
|
+
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean): Promise<
|
|
93
|
+
DevInspectResults | TransactionBlock
|
|
94
|
+
>;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
export interface ContractTx extends MessageMeta {
|
|
93
|
-
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean):
|
|
98
|
+
(tx: TransactionBlock, params: SuiTxArgument[], isRaw?: boolean):
|
|
99
|
+
| SuiTransactionBlockResponse
|
|
100
|
+
| TransactionBlock;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
export type MapMessageTx = Record<string, ContractTx>;
|
|
@@ -102,8 +109,6 @@ export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
|
102
109
|
export type MapMoudleFuncTest = Record<string, Record<string, string>>;
|
|
103
110
|
export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
112
|
export type AccountMangerParams = {
|
|
108
113
|
mnemonics?: string;
|
|
109
114
|
secretKey?: string;
|
|
@@ -116,7 +121,7 @@ export type DerivePathParams = {
|
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
119
|
-
export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet'
|
|
124
|
+
export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet';
|
|
120
125
|
|
|
121
126
|
export type SuiKitParams = {
|
|
122
127
|
mnemonics?: string;
|
|
@@ -136,7 +141,19 @@ export type ObjectData = {
|
|
|
136
141
|
objectFields: ObjectContentFields;
|
|
137
142
|
};
|
|
138
143
|
|
|
144
|
+
export type ObjectFieldType = {
|
|
145
|
+
id: {
|
|
146
|
+
id: string;
|
|
147
|
+
};
|
|
148
|
+
name: string;
|
|
149
|
+
value: string;
|
|
150
|
+
};
|
|
139
151
|
|
|
152
|
+
export type EntityData = {
|
|
153
|
+
objectId: string;
|
|
154
|
+
index: string;
|
|
155
|
+
key: string;
|
|
156
|
+
};
|
|
140
157
|
|
|
141
158
|
export type SuiTxArg =
|
|
142
159
|
| Infer<typeof TransactionArgument>
|
|
@@ -171,3 +188,14 @@ export type SuiBasicTypes =
|
|
|
171
188
|
| 'u256';
|
|
172
189
|
|
|
173
190
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
191
|
+
|
|
192
|
+
export type SuiReturnValues = {
|
|
193
|
+
returnValues: [number[], string][];
|
|
194
|
+
}[];
|
|
195
|
+
|
|
196
|
+
export type DynamicFieldContentType = {
|
|
197
|
+
type: string;
|
|
198
|
+
fields: Record<string, any>;
|
|
199
|
+
hasPublicTransfer: boolean;
|
|
200
|
+
dataType: string;
|
|
201
|
+
};
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
export function capitalizeFirstLetter(input: string): string {
|
|
2
|
-
|
|
2
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function normalizeHexAddress(input: string): string | null {
|
|
6
|
+
const hexRegex = /^(0x)?[0-9a-fA-F]{64}$/;
|
|
7
|
+
|
|
8
|
+
if (hexRegex.test(input)) {
|
|
9
|
+
if (input.startsWith('0x')) {
|
|
10
|
+
return input;
|
|
11
|
+
} else {
|
|
12
|
+
return '0x' + input;
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function numberToAddressHex(num: number): string {
|
|
20
|
+
const hex = num.toString(16);
|
|
21
|
+
const paddedHex = '0x' + hex.padStart(64, '0');
|
|
22
|
+
return paddedHex;
|
|
3
23
|
}
|
package/dist/framework/bcs.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FieldsWithTypes, Type } from './util';
|
|
2
|
-
export type PrimitiveValue = string | number | boolean | bigint;
|
|
3
|
-
export declare class StructClassLoader {
|
|
4
|
-
#private;
|
|
5
|
-
private map;
|
|
6
|
-
register(...classes: any): void;
|
|
7
|
-
fromFields(type: Type, value: Record<string, any> | PrimitiveValue): any;
|
|
8
|
-
fromFieldsWithTypes(type: Type, value: FieldsWithTypes | PrimitiveValue): any;
|
|
9
|
-
}
|
|
10
|
-
export declare const structClassLoaderSource: StructClassLoader;
|
|
11
|
-
export declare const structClassLoaderOnchain: StructClassLoader;
|
package/dist/framework/util.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ObjectCallArg, ObjectId, TransactionArgument, TransactionBlock } from '@mysten/sui.js';
|
|
2
|
-
/** A Move type, e.g., `address`, `bool`, `u64`, `vector<u64>`, `0x2::sui::SUI`... */
|
|
3
|
-
export type Type = string;
|
|
4
|
-
export interface FieldsWithTypes {
|
|
5
|
-
fields: Record<string, any>;
|
|
6
|
-
type: string;
|
|
7
|
-
}
|
|
8
|
-
export type ObjectArg = ObjectId | ObjectCallArg | TransactionArgument;
|
|
9
|
-
export type PureArg = bigint | string | number | boolean | null | TransactionArgument | Array<PureArg>;
|
|
10
|
-
export type GenericArg = ObjectArg | PureArg | Array<ObjectArg> | Array<PureArg> | Array<GenericArg>;
|
|
11
|
-
export declare function parseTypeName(name: Type): {
|
|
12
|
-
typeName: string;
|
|
13
|
-
typeArgs: Type[];
|
|
14
|
-
};
|
|
15
|
-
export declare function obj(txb: TransactionBlock, arg: ObjectArg): {
|
|
16
|
-
kind: "Input";
|
|
17
|
-
index: number;
|
|
18
|
-
type?: "object" | "pure" | undefined;
|
|
19
|
-
value?: any;
|
|
20
|
-
} | {
|
|
21
|
-
kind: "GasCoin";
|
|
22
|
-
} | {
|
|
23
|
-
kind: "Result";
|
|
24
|
-
index: number;
|
|
25
|
-
} | {
|
|
26
|
-
kind: "NestedResult";
|
|
27
|
-
index: number;
|
|
28
|
-
resultIndex: number;
|
|
29
|
-
};
|
|
30
|
-
export declare function pure(txb: TransactionBlock, arg: PureArg, type: Type): {
|
|
31
|
-
kind: "Input";
|
|
32
|
-
index: number;
|
|
33
|
-
type?: "object" | "pure" | undefined;
|
|
34
|
-
value?: any;
|
|
35
|
-
} | {
|
|
36
|
-
kind: "GasCoin";
|
|
37
|
-
} | {
|
|
38
|
-
kind: "Result";
|
|
39
|
-
index: number;
|
|
40
|
-
} | {
|
|
41
|
-
kind: "NestedResult";
|
|
42
|
-
index: number;
|
|
43
|
-
resultIndex: number;
|
|
44
|
-
};
|
|
45
|
-
export declare function option(txb: TransactionBlock, type: Type, arg: GenericArg | null): {
|
|
46
|
-
kind: "Input";
|
|
47
|
-
index: number;
|
|
48
|
-
type?: "object" | "pure" | undefined;
|
|
49
|
-
value?: any;
|
|
50
|
-
} | {
|
|
51
|
-
kind: "GasCoin";
|
|
52
|
-
} | {
|
|
53
|
-
kind: "Result";
|
|
54
|
-
index: number;
|
|
55
|
-
} | {
|
|
56
|
-
kind: "NestedResult";
|
|
57
|
-
index: number;
|
|
58
|
-
resultIndex: number;
|
|
59
|
-
};
|
|
60
|
-
export declare function generic(txb: TransactionBlock, type: Type, arg: GenericArg): {
|
|
61
|
-
kind: "Input";
|
|
62
|
-
index: number;
|
|
63
|
-
type?: "object" | "pure" | undefined;
|
|
64
|
-
value?: any;
|
|
65
|
-
} | {
|
|
66
|
-
kind: "GasCoin";
|
|
67
|
-
} | {
|
|
68
|
-
kind: "Result";
|
|
69
|
-
index: number;
|
|
70
|
-
} | {
|
|
71
|
-
kind: "NestedResult";
|
|
72
|
-
index: number;
|
|
73
|
-
resultIndex: number;
|
|
74
|
-
};
|
|
75
|
-
export declare function vector(txb: TransactionBlock, itemType: Type, items: Array<GenericArg> | TransactionArgument): {
|
|
76
|
-
kind: "Input";
|
|
77
|
-
index: number;
|
|
78
|
-
type?: "object" | "pure" | undefined;
|
|
79
|
-
value?: any;
|
|
80
|
-
} | {
|
|
81
|
-
kind: "GasCoin";
|
|
82
|
-
} | {
|
|
83
|
-
kind: "Result";
|
|
84
|
-
index: number;
|
|
85
|
-
} | {
|
|
86
|
-
kind: "NestedResult";
|
|
87
|
-
index: number;
|
|
88
|
-
resultIndex: number;
|
|
89
|
-
};
|
|
90
|
-
export declare function typeArgIsPure(type: Type): boolean;
|
package/dist/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from '@mysten/sui.js';
|
|
2
|
-
export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
3
|
-
export * from '@mysten/bcs';
|
|
4
|
-
export { Obelisk } from './obelisk';
|
|
5
|
-
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
6
|
-
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
7
|
-
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
8
|
-
export { getMetadata } from './metadata';
|
|
9
|
-
export type * from './types';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const generateMnemonic: (numberOfWords?: 12 | 24) => string;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Ed25519Keypair } from '@mysten/sui.js';
|
|
2
|
-
import type { AccountMangerParams, DerivePathParams } from 'src/types';
|
|
3
|
-
export declare class SuiAccountManager {
|
|
4
|
-
private mnemonics;
|
|
5
|
-
private secretKey;
|
|
6
|
-
currentKeyPair: Ed25519Keypair;
|
|
7
|
-
currentAddress: string;
|
|
8
|
-
/**
|
|
9
|
-
* Support the following ways to init the SuiToolkit:
|
|
10
|
-
* 1. mnemonics
|
|
11
|
-
* 2. secretKey (base64 or hex)
|
|
12
|
-
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
13
|
-
*
|
|
14
|
-
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
15
|
-
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
16
|
-
*/
|
|
17
|
-
constructor({ mnemonics, secretKey }?: AccountMangerParams);
|
|
18
|
-
/**
|
|
19
|
-
* if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
|
|
20
|
-
* else:
|
|
21
|
-
* it will generate keyPair from the mnemonic with the given derivePathParams.
|
|
22
|
-
*/
|
|
23
|
-
getKeyPair(derivePathParams?: DerivePathParams): Ed25519Keypair;
|
|
24
|
-
/**
|
|
25
|
-
* if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.
|
|
26
|
-
* else:
|
|
27
|
-
* it will generate address from the mnemonic with the given derivePathParams.
|
|
28
|
-
*/
|
|
29
|
-
getAddress(derivePathParams?: DerivePathParams): string;
|
|
30
|
-
/**
|
|
31
|
-
* Switch the current account with the given derivePathParams.
|
|
32
|
-
* This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.
|
|
33
|
-
*/
|
|
34
|
-
switchAccount(derivePathParams: DerivePathParams): void;
|
|
35
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Ed25519Keypair } from '@mysten/sui.js';
|
|
2
|
-
import type { DerivePathParams } from 'src/types';
|
|
3
|
-
/**
|
|
4
|
-
* @description Get ed25519 derive path for SUI
|
|
5
|
-
* @param derivePathParams
|
|
6
|
-
*/
|
|
7
|
-
export declare const getDerivePathForSUI: (derivePathParams?: DerivePathParams) => string;
|
|
8
|
-
/**
|
|
9
|
-
* the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'
|
|
10
|
-
*
|
|
11
|
-
* accountIndex is the index of the account, default is 0.
|
|
12
|
-
*
|
|
13
|
-
* isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.
|
|
14
|
-
*
|
|
15
|
-
* addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.
|
|
16
|
-
*
|
|
17
|
-
* @description Get keypair from mnemonics and derive path
|
|
18
|
-
* @param mnemonics
|
|
19
|
-
* @param derivePathParams
|
|
20
|
-
*/
|
|
21
|
-
export declare const getKeyPair: (mnemonics: string, derivePathParams?: DerivePathParams) => Ed25519Keypair;
|