@0xobelisk/client 0.3.4 → 0.3.6

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.
@@ -0,0 +1,9 @@
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';
@@ -0,0 +1 @@
1
+ export declare const generateMnemonic: (numberOfWords?: 12 | 24) => string;
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).
3
+ * @param str
4
+ */
5
+ export declare const isHex: (str: string) => boolean;
6
+ /**
7
+ * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).
8
+ * Note that the "=" signs at the end are optional padding characters that may be present in some base64 encoded strings.
9
+ * @param str
10
+ */
11
+ export declare const isBase64: (str: string) => boolean;
12
+ /**
13
+ * Convert a hex string to Uint8Array
14
+ * @param hexStr
15
+ */
16
+ export declare const fromHEX: (hexStr: string) => Uint8Array;
17
+ /**
18
+ * @description Convert a hex or base64 string to Uint8Array
19
+ */
20
+ export declare const hexOrBase64ToUint8Array: (str: string) => Uint8Array;
21
+ /**
22
+ * normalize a private key
23
+ * A private key is a 32-byte array.
24
+ * But there are two different formats for private keys:
25
+ * 1. A 32-byte array
26
+ * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key
27
+ * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)
28
+ */
29
+ export declare const normalizePrivateKey: (key: Uint8Array) => Uint8Array;
@@ -0,0 +1,20 @@
1
+ import { SuiMoveNormalizedModules } from '@mysten/sui.js';
2
+ import type { ContractFactoryParams } from './types';
3
+ export type ApiTypes = 'promise' | 'rxjs';
4
+ export declare class SuiContractFactory {
5
+ packageId: string;
6
+ metadata: SuiMoveNormalizedModules | undefined;
7
+ /**
8
+ * Support the following ways to init the SuiToolkit:
9
+ * 1. mnemonics
10
+ * 2. secretKey (base64 or hex)
11
+ * If none of them is provided, will generate a random mnemonics with 24 words.
12
+ *
13
+ * @param mnemonics, 12 or 24 mnemonics words, separated by space
14
+ * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
15
+ */
16
+ constructor({ packageId, metadata }?: ContractFactoryParams);
17
+ getFuncByModuleName(moduleName: string): void;
18
+ getAllFunc(): void;
19
+ getAllModule(): void;
20
+ }
@@ -0,0 +1,49 @@
1
+ import { SuiMoveNormalizedModules, SuiMoveNormalizedType } from "@mysten/sui.js";
2
+ export type ContractFactoryParams = {
3
+ packageId?: string;
4
+ metadata?: SuiMoveNormalizedModules;
5
+ };
6
+ export type SuiMoveMoudleValueType = {
7
+ address: string;
8
+ name: string;
9
+ fileFormatVersion: number;
10
+ friends: {
11
+ address: string;
12
+ name: string;
13
+ }[];
14
+ structs: Record<string, {
15
+ fields: {
16
+ type: SuiMoveNormalizedType;
17
+ name: string;
18
+ }[];
19
+ abilities: {
20
+ abilities: string[];
21
+ };
22
+ typeParameters: {
23
+ constraints: {
24
+ abilities: string[];
25
+ };
26
+ isPhantom: boolean;
27
+ }[];
28
+ }>;
29
+ exposedFunctions: Record<string, {
30
+ visibility: "Private" | "Public" | "Friend";
31
+ isEntry: boolean;
32
+ typeParameters: {
33
+ abilities: string[];
34
+ }[];
35
+ parameters: SuiMoveNormalizedType[];
36
+ return: SuiMoveNormalizedType[];
37
+ }>;
38
+ };
39
+ export type SuiMoveMoudleFuncType = {
40
+ moudleName: string;
41
+ funcName: string;
42
+ visibility: "Private" | "Public" | "Friend";
43
+ isEntry: boolean;
44
+ typeParameters: {
45
+ abilities: string[];
46
+ }[];
47
+ parameters: SuiMoveNormalizedType[];
48
+ return: SuiMoveNormalizedType[];
49
+ };
@@ -0,0 +1,10 @@
1
+ import type { Connection } from '@mysten/sui.js';
2
+ import type { NetworkType } from 'src/types';
3
+ export declare const defaultGasBudget: number;
4
+ export declare const defaultGasPrice = 1000;
5
+ /**
6
+ * @description Get the default fullnode url and faucet url for the given network type
7
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
8
+ * @returns { fullNode: string, websocket: string, faucet?: string }
9
+ */
10
+ export declare const getDefaultConnection: (networkType?: NetworkType) => Connection;
@@ -0,0 +1,2 @@
1
+ export { SuiInteractor } from './suiInteractor';
2
+ export { getDefaultConnection } from './defaultConfig';
@@ -0,0 +1,205 @@
1
+ import { SuiTransactionBlockResponse, JsonRpcProvider, DynamicFieldName, SuiAddress } from '@mysten/sui.js';
2
+ import { FaucetNetworkType, NetworkType, ObjectData, EntityData } from 'src/types';
3
+ import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
4
+ /**
5
+ * `SuiTransactionSender` is used to send transaction with a given gas coin.
6
+ * It always uses the gas coin to pay for the gas,
7
+ * and update the gas coin after the transaction.
8
+ */
9
+ export declare class SuiInteractor {
10
+ readonly providers: JsonRpcProvider[];
11
+ currentProvider: JsonRpcProvider;
12
+ network?: NetworkType;
13
+ constructor(fullNodeUrls: string[], network?: NetworkType);
14
+ switchToNextProvider(): void;
15
+ sendTx(transactionBlock: Uint8Array | string, signature: string | string[]): Promise<SuiTransactionBlockResponse>;
16
+ getObjects(ids: string[]): Promise<ObjectData[]>;
17
+ getObject(id: string): Promise<ObjectData>;
18
+ getEntitiesObjects(ids: string[]): Promise<EntityData[]>;
19
+ getDynamicFieldObject(parentId: string, name: string | DynamicFieldName): Promise<{
20
+ data?: {
21
+ objectId: string;
22
+ version: string;
23
+ digest: string;
24
+ type?: string | null | undefined;
25
+ bcs?: {
26
+ type: string;
27
+ version: string;
28
+ hasPublicTransfer: boolean;
29
+ dataType: "moveObject";
30
+ bcsBytes: string;
31
+ } | {
32
+ id: string;
33
+ dataType: "package";
34
+ moduleMap: Record<string, string>;
35
+ } | null | undefined;
36
+ owner?: {
37
+ AddressOwner: string;
38
+ } | {
39
+ ObjectOwner: string;
40
+ } | {
41
+ Shared: {
42
+ initial_shared_version: string | null;
43
+ };
44
+ } | "Immutable" | null | undefined;
45
+ storageRebate?: string | null | undefined;
46
+ previousTransaction?: string | null | undefined;
47
+ content?: {
48
+ type: string;
49
+ fields: Record<string, any>;
50
+ hasPublicTransfer: boolean;
51
+ dataType: "moveObject";
52
+ } | {
53
+ disassembled: Record<string, unknown>;
54
+ dataType: "package";
55
+ } | null | undefined;
56
+ display?: Record<string, string> | {
57
+ data?: Record<string, string> | null | undefined;
58
+ error?: {
59
+ code: string;
60
+ version?: string | undefined;
61
+ digest?: string | undefined;
62
+ error?: string | undefined;
63
+ object_id?: string | undefined;
64
+ parent_object_id?: string | undefined;
65
+ } | null | undefined;
66
+ } | null | undefined;
67
+ } | null | undefined;
68
+ error?: {
69
+ code: string;
70
+ version?: string | undefined;
71
+ digest?: string | undefined;
72
+ error?: string | undefined;
73
+ object_id?: string | undefined;
74
+ parent_object_id?: string | undefined;
75
+ } | null | undefined;
76
+ }>;
77
+ getDynamicFields(parentId: string, cursor?: string, limit?: number): Promise<{
78
+ data: {
79
+ type: "DynamicField" | "DynamicObject";
80
+ objectType: string;
81
+ objectId: string;
82
+ version: number;
83
+ digest: string;
84
+ name: {
85
+ type: string;
86
+ value?: any;
87
+ };
88
+ bcsName: string;
89
+ }[];
90
+ nextCursor: string | null;
91
+ hasNextPage: boolean;
92
+ }>;
93
+ getOwnedObjects(owner: SuiAddress, cursor?: string, limit?: number): Promise<{
94
+ data: {
95
+ data?: {
96
+ objectId: string;
97
+ version: string;
98
+ digest: string;
99
+ type?: string | null | undefined;
100
+ bcs?: {
101
+ type: string;
102
+ version: string;
103
+ hasPublicTransfer: boolean;
104
+ dataType: "moveObject";
105
+ bcsBytes: string;
106
+ } | {
107
+ id: string;
108
+ dataType: "package";
109
+ moduleMap: Record<string, string>;
110
+ } | null | undefined;
111
+ owner?: "Immutable" | {
112
+ AddressOwner: string;
113
+ } | {
114
+ ObjectOwner: string;
115
+ } | {
116
+ Shared: {
117
+ initial_shared_version: string | null;
118
+ };
119
+ } | null | undefined;
120
+ storageRebate?: string | null | undefined;
121
+ previousTransaction?: string | null | undefined;
122
+ content?: {
123
+ type: string;
124
+ fields: Record<string, any>;
125
+ hasPublicTransfer: boolean;
126
+ dataType: "moveObject";
127
+ } | {
128
+ disassembled: Record<string, unknown>;
129
+ dataType: "package";
130
+ } | null | undefined;
131
+ display?: Record<string, string> | {
132
+ data?: Record<string, string> | null | undefined;
133
+ error?: {
134
+ code: string;
135
+ version?: string | undefined;
136
+ digest?: string | undefined;
137
+ error?: string | undefined;
138
+ object_id?: string | undefined;
139
+ parent_object_id?: string | undefined;
140
+ } | null | undefined;
141
+ } | null | undefined;
142
+ } | null | undefined;
143
+ error?: {
144
+ code: string;
145
+ version?: string | undefined;
146
+ digest?: string | undefined;
147
+ error?: string | undefined;
148
+ object_id?: string | undefined;
149
+ parent_object_id?: string | undefined;
150
+ } | null | undefined;
151
+ }[];
152
+ hasNextPage: boolean;
153
+ nextCursor?: string | null | undefined;
154
+ }>;
155
+ getNormalizedMoveModulesByPackage(packageId: string): Promise<Record<string, {
156
+ address: string;
157
+ name: string;
158
+ fileFormatVersion: number;
159
+ friends: {
160
+ address: string;
161
+ name: string;
162
+ }[];
163
+ structs: Record<string, {
164
+ fields: {
165
+ type: import("@mysten/sui.js").SuiMoveNormalizedType;
166
+ name: string;
167
+ }[];
168
+ abilities: {
169
+ abilities: string[];
170
+ };
171
+ typeParameters: {
172
+ constraints: {
173
+ abilities: string[];
174
+ };
175
+ isPhantom: boolean;
176
+ }[];
177
+ }>;
178
+ exposedFunctions: Record<string, {
179
+ visibility: "Private" | "Public" | "Friend";
180
+ isEntry: boolean;
181
+ typeParameters: {
182
+ abilities: string[];
183
+ }[];
184
+ parameters: import("@mysten/sui.js").SuiMoveNormalizedType[];
185
+ return: import("@mysten/sui.js").SuiMoveNormalizedType[];
186
+ }>;
187
+ }>>;
188
+ /**
189
+ * @description Update objects in a batch
190
+ * @param suiObjects
191
+ */
192
+ updateObjects(suiObjects: (SuiOwnedObject | SuiSharedObject)[]): Promise<void>;
193
+ /**
194
+ * @description Select coins that add up to the given amount.
195
+ * @param addr the address of the owner
196
+ * @param amount the amount that is needed for the coin
197
+ * @param coinType the coin type, default is '0x2::SUI::SUI'
198
+ */
199
+ selectCoins(addr: string, amount: number, coinType?: string): Promise<{
200
+ objectId: string;
201
+ digest: string;
202
+ version: string;
203
+ }[]>;
204
+ requestFaucet(address: SuiAddress, network: FaucetNetworkType): Promise<void>;
205
+ }
@@ -0,0 +1 @@
1
+ export declare const delay: (ms: number) => Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ export { SuiOwnedObject } from './suiOwnedObject';
2
+ export { SuiSharedObject } from './suiSharedObject';
@@ -0,0 +1,24 @@
1
+ import { Infer } from 'superstruct';
2
+ import { SuiTransactionBlockResponse, ObjectCallArg, ObjectId } from '@mysten/sui.js';
3
+ export declare class SuiOwnedObject {
4
+ readonly objectId: string;
5
+ version?: number | string;
6
+ digest?: string;
7
+ constructor(param: {
8
+ objectId: string;
9
+ version?: string;
10
+ digest?: string;
11
+ });
12
+ /**
13
+ * Check if the object is fully initialized.
14
+ * So that when it's used as an input, it won't be necessary to fetch from fullnode again.
15
+ * Which can save time when sending transactions.
16
+ */
17
+ isFullObject(): boolean;
18
+ asCallArg(): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId>;
19
+ /**
20
+ * Update object version & digest based on the transaction response.
21
+ * @param txResponse
22
+ */
23
+ updateFromTxResponse(txResponse: SuiTransactionBlockResponse): void;
24
+ }
@@ -0,0 +1,12 @@
1
+ import { Infer } from 'superstruct';
2
+ import { ObjectCallArg, ObjectId } from '@mysten/sui.js';
3
+ export declare class SuiSharedObject {
4
+ readonly objectId: string;
5
+ initialSharedVersion?: number | string;
6
+ constructor(param: {
7
+ objectId: string;
8
+ initialSharedVersion?: number;
9
+ mutable?: boolean;
10
+ });
11
+ asCallArg(mutable?: boolean): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId>;
12
+ }