@0xobelisk/sui-client 0.5.3 → 0.5.5
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 +3 -1
- package/dist/index.js +343 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +331 -245
- 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/index.d.ts +1 -1
- package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +1 -1
- package/dist/libs/suiContractFactory/types.d.ts +1 -1
- package/dist/libs/suiInteractor/index.d.ts +0 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +17 -177
- package/dist/libs/suiModel/suiOwnedObject.d.ts +4 -4
- package/dist/libs/suiModel/suiSharedObject.d.ts +4 -5
- package/dist/libs/suiTxBuilder/index.d.ts +178 -374
- package/dist/libs/suiTxBuilder/util.d.ts +41 -59
- package/dist/metadata/index.d.ts +2 -33
- package/dist/obelisk.d.ts +20 -2454
- package/dist/types/index.d.ts +28 -6
- package/package.json +22 -19
- package/src/index.ts +3 -1
- package/src/libs/multiSig/client.ts +44 -0
- package/src/libs/multiSig/index.ts +1 -0
- package/src/libs/multiSig/publickey.ts +11 -0
- package/src/libs/suiAccountManager/index.ts +1 -1
- 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 +2 -2
- package/src/libs/suiInteractor/index.ts +1 -1
- package/src/libs/suiInteractor/suiInteractor.ts +106 -111
- package/src/libs/suiModel/suiOwnedObject.ts +5 -10
- package/src/libs/suiModel/suiSharedObject.ts +4 -7
- package/src/libs/suiTxBuilder/index.ts +146 -100
- package/src/libs/suiTxBuilder/util.ts +145 -31
- package/src/metadata/index.ts +5 -3
- package/src/obelisk.ts +52 -37
- package/src/types/index.ts +53 -24
- package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
- package/src/libs/suiInteractor/defaultConfig.ts +0 -32
package/src/obelisk.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
// import { RawSigner, SuiAddress } from '@mysten/sui.js';
|
|
2
|
+
|
|
3
|
+
import { getFullnodeUrl, SuiParsedData } from '@mysten/sui.js/client';
|
|
1
4
|
import {
|
|
5
|
+
TransactionBlock,
|
|
6
|
+
TransactionResult,
|
|
7
|
+
} from '@mysten/sui.js/transactions';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
SuiTransactionBlockResponse,
|
|
2
11
|
DevInspectResults,
|
|
3
|
-
RawSigner,
|
|
4
|
-
SuiAddress,
|
|
5
12
|
SuiMoveNormalizedModules,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
SuiObjectData,
|
|
14
|
+
} from '@mysten/sui.js/client';
|
|
15
|
+
|
|
9
16
|
import { SuiAccountManager } from './libs/suiAccountManager';
|
|
10
17
|
import { SuiTxBlock } from './libs/suiTxBuilder';
|
|
11
|
-
import {
|
|
18
|
+
import { SuiInteractor } from './libs/suiInteractor';
|
|
12
19
|
|
|
13
|
-
import {
|
|
20
|
+
import { ObeliskObjectContent } from './types';
|
|
14
21
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
15
22
|
import {
|
|
16
23
|
SuiMoveMoudleFuncType,
|
|
@@ -27,7 +34,6 @@ import {
|
|
|
27
34
|
SuiTxArg,
|
|
28
35
|
SuiTxArgument,
|
|
29
36
|
SuiVecTxArg,
|
|
30
|
-
TransactionResult,
|
|
31
37
|
} from './types';
|
|
32
38
|
import { normalizeHexAddress, numberToAddressHex } from './utils';
|
|
33
39
|
import keccak256 from 'keccak256';
|
|
@@ -128,7 +134,7 @@ export class Obelisk {
|
|
|
128
134
|
// Init the account manager
|
|
129
135
|
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
130
136
|
// Init the rpc provider
|
|
131
|
-
fullnodeUrls = fullnodeUrls || [
|
|
137
|
+
fullnodeUrls = fullnodeUrls || [getFullnodeUrl(networkType ?? 'mainnet')];
|
|
132
138
|
this.suiInteractor = new SuiInteractor(fullnodeUrls, networkType);
|
|
133
139
|
|
|
134
140
|
this.packageId = packageId;
|
|
@@ -225,15 +231,15 @@ export class Obelisk {
|
|
|
225
231
|
});
|
|
226
232
|
return await this.inspectTxn(tx);
|
|
227
233
|
};
|
|
234
|
+
|
|
228
235
|
/**
|
|
229
|
-
* if derivePathParams is not provided or mnemonics is empty, it will return the
|
|
236
|
+
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
230
237
|
* else:
|
|
231
238
|
* it will generate signer from the mnemonic with the given derivePathParams.
|
|
232
239
|
* @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
|
|
233
240
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return new RawSigner(keyPair, this.suiInteractor.currentProvider);
|
|
241
|
+
getKeypair(derivePathParams?: DerivePathParams) {
|
|
242
|
+
return this.accountManager.getKeyPair(derivePathParams);
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
/**
|
|
@@ -251,14 +257,11 @@ export class Obelisk {
|
|
|
251
257
|
getAddress(derivePathParams?: DerivePathParams) {
|
|
252
258
|
return this.accountManager.getAddress(derivePathParams);
|
|
253
259
|
}
|
|
260
|
+
|
|
254
261
|
currentAddress() {
|
|
255
262
|
return this.accountManager.currentAddress;
|
|
256
263
|
}
|
|
257
264
|
|
|
258
|
-
provider() {
|
|
259
|
-
return this.suiInteractor.currentProvider;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
265
|
getPackageId() {
|
|
263
266
|
return this.contractFactory.packageId;
|
|
264
267
|
}
|
|
@@ -270,14 +273,18 @@ export class Obelisk {
|
|
|
270
273
|
* Request some SUI from faucet
|
|
271
274
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
272
275
|
*/
|
|
273
|
-
async requestFaucet(address:
|
|
276
|
+
async requestFaucet(address: string, network: FaucetNetworkType) {
|
|
274
277
|
// const addr = this.accountManager.getAddress(derivePathParams);
|
|
275
278
|
return this.suiInteractor.requestFaucet(address, network);
|
|
276
279
|
}
|
|
277
280
|
|
|
278
281
|
async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {
|
|
279
282
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
280
|
-
return this.suiInteractor.
|
|
283
|
+
return this.suiInteractor.currentClient.getBalance({ owner, coinType });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
client() {
|
|
287
|
+
return this.suiInteractor.currentClient;
|
|
281
288
|
}
|
|
282
289
|
|
|
283
290
|
async getObject(objectId: string) {
|
|
@@ -292,20 +299,24 @@ export class Obelisk {
|
|
|
292
299
|
tx: Uint8Array | TransactionBlock | SuiTxBlock,
|
|
293
300
|
derivePathParams?: DerivePathParams
|
|
294
301
|
) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
302
|
+
if (tx instanceof SuiTxBlock) {
|
|
303
|
+
tx.setSender(this.getAddress(derivePathParams));
|
|
304
|
+
}
|
|
305
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
306
|
+
const txBytes =
|
|
307
|
+
txBlock instanceof TransactionBlock
|
|
308
|
+
? await txBlock.build({ client: this.client() })
|
|
309
|
+
: txBlock;
|
|
310
|
+
const keyPair = this.getKeypair(derivePathParams);
|
|
311
|
+
return await keyPair.signTransactionBlock(txBytes);
|
|
298
312
|
}
|
|
299
313
|
|
|
300
314
|
async signAndSendTxn(
|
|
301
315
|
tx: Uint8Array | TransactionBlock | SuiTxBlock,
|
|
302
316
|
derivePathParams?: DerivePathParams
|
|
303
317
|
): Promise<SuiTransactionBlockResponse> {
|
|
304
|
-
const {
|
|
305
|
-
|
|
306
|
-
derivePathParams
|
|
307
|
-
);
|
|
308
|
-
return this.suiInteractor.sendTx(transactionBlockBytes, signature);
|
|
318
|
+
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
319
|
+
return this.suiInteractor.sendTx(bytes, signature);
|
|
309
320
|
}
|
|
310
321
|
|
|
311
322
|
/**
|
|
@@ -454,9 +465,9 @@ export class Obelisk {
|
|
|
454
465
|
tx: Uint8Array | TransactionBlock | SuiTxBlock,
|
|
455
466
|
derivePathParams?: DerivePathParams
|
|
456
467
|
): Promise<DevInspectResults> {
|
|
457
|
-
|
|
458
|
-
return this.suiInteractor.
|
|
459
|
-
transactionBlock:
|
|
468
|
+
const txBlock = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
469
|
+
return this.suiInteractor.currentClient.devInspectTransactionBlock({
|
|
470
|
+
transactionBlock: txBlock,
|
|
460
471
|
sender: this.getAddress(derivePathParams),
|
|
461
472
|
});
|
|
462
473
|
}
|
|
@@ -467,8 +478,14 @@ export class Obelisk {
|
|
|
467
478
|
|
|
468
479
|
async listSchemaNames(worldId: string) {
|
|
469
480
|
const worldObject = await this.getObject(worldId);
|
|
470
|
-
const newObjectContent = worldObject.
|
|
471
|
-
|
|
481
|
+
const newObjectContent = worldObject.content;
|
|
482
|
+
if (newObjectContent != null) {
|
|
483
|
+
const objectContent = newObjectContent as ObeliskObjectContent;
|
|
484
|
+
const objectFields = objectContent.fields as Record<string, any>;
|
|
485
|
+
return objectFields['schema_names'];
|
|
486
|
+
} else {
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
472
489
|
}
|
|
473
490
|
|
|
474
491
|
async getEntity(
|
|
@@ -567,20 +584,18 @@ export class Obelisk {
|
|
|
567
584
|
// };
|
|
568
585
|
// }
|
|
569
586
|
|
|
570
|
-
async getOwnedObjects(owner:
|
|
587
|
+
async getOwnedObjects(owner: string, cursor?: string, limit?: number) {
|
|
571
588
|
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
572
589
|
owner,
|
|
573
590
|
cursor,
|
|
574
591
|
limit
|
|
575
592
|
);
|
|
576
|
-
const ownedObjectsRes:
|
|
593
|
+
const ownedObjectsRes: SuiObjectData[] = [];
|
|
577
594
|
|
|
578
595
|
for (const object of ownedObjects.data) {
|
|
579
596
|
const objectDetail = await this.getObject(object.data!.objectId);
|
|
580
|
-
|
|
581
597
|
if (
|
|
582
|
-
objectDetail.
|
|
583
|
-
this.contractFactory.packageId
|
|
598
|
+
objectDetail.type!.split('::')[0] === this.contractFactory.packageId
|
|
584
599
|
) {
|
|
585
600
|
ownedObjectsRes.push(objectDetail);
|
|
586
601
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
DisplayFieldsResponse,
|
|
4
|
-
ObjectCallArg,
|
|
5
|
-
ObjectContentFields,
|
|
6
|
-
SharedObjectRef,
|
|
7
|
-
SuiObjectRef,
|
|
8
|
-
TransactionArgument,
|
|
1
|
+
import { ObjectContentFields } from '@mysten/sui.js/src/types';
|
|
2
|
+
import type {
|
|
9
3
|
TransactionBlock,
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
TransactionObjectArgument,
|
|
5
|
+
TransactionArgument,
|
|
6
|
+
TransactionResult,
|
|
7
|
+
} from '@mysten/sui.js/transactions';
|
|
8
|
+
import type {
|
|
9
|
+
SuiObjectRef,
|
|
12
10
|
SuiMoveNormalizedModules,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
DevInspectResults,
|
|
12
|
+
SuiTransactionBlockResponse,
|
|
13
|
+
DisplayFieldsResponse,
|
|
14
|
+
MoveStruct,
|
|
15
|
+
} from '@mysten/sui.js/client';
|
|
16
|
+
import type { SharedObjectRef, ObjectArg } from '@mysten/sui.js/bcs';
|
|
17
|
+
import type { SerializedBcs } from '@mysten/bcs';
|
|
18
|
+
// export type TransactionResult = TransactionArgument & TransactionArgument[];
|
|
16
19
|
|
|
17
20
|
import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
|
|
18
21
|
|
|
@@ -24,6 +27,13 @@ export type ObeliskObjectData = {
|
|
|
24
27
|
objectFields: ObjectContentFields;
|
|
25
28
|
};
|
|
26
29
|
|
|
30
|
+
export type ObeliskObjectContent = {
|
|
31
|
+
dataType: 'moveObject';
|
|
32
|
+
fields: MoveStruct;
|
|
33
|
+
hasPublicTransfer: boolean;
|
|
34
|
+
type: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
27
37
|
export type ObeliskParams = {
|
|
28
38
|
mnemonics?: string;
|
|
29
39
|
secretKey?: string;
|
|
@@ -145,6 +155,24 @@ export type ObjectData = {
|
|
|
145
155
|
objectDisplay: DisplayFieldsResponse;
|
|
146
156
|
objectFields: ObjectContentFields;
|
|
147
157
|
};
|
|
158
|
+
type TransactionBlockType = InstanceType<typeof TransactionBlock>;
|
|
159
|
+
|
|
160
|
+
export type PureCallArg = {
|
|
161
|
+
Pure: number[];
|
|
162
|
+
};
|
|
163
|
+
export type ObjectCallArg = {
|
|
164
|
+
Object: ObjectArg;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export type TransactionType = Parameters<TransactionBlockType['add']>;
|
|
168
|
+
|
|
169
|
+
export type TransactionPureArgument = Extract<
|
|
170
|
+
TransactionArgument,
|
|
171
|
+
{
|
|
172
|
+
kind: 'Input';
|
|
173
|
+
type: 'pure';
|
|
174
|
+
}
|
|
175
|
+
>;
|
|
148
176
|
|
|
149
177
|
export type ObjectFieldType = {
|
|
150
178
|
id: {
|
|
@@ -160,20 +188,20 @@ export type EntityData = {
|
|
|
160
188
|
key: string;
|
|
161
189
|
};
|
|
162
190
|
|
|
163
|
-
export type
|
|
164
|
-
|
|
|
165
|
-
|
|
|
191
|
+
export type SuiAddressArg =
|
|
192
|
+
| TransactionArgument
|
|
193
|
+
| SerializedBcs<any>
|
|
166
194
|
| string
|
|
167
|
-
|
|
|
168
|
-
|
|
169
|
-
|
|
195
|
+
| PureCallArg;
|
|
196
|
+
|
|
197
|
+
export type SuiTxArg = SuiAddressArg | number | bigint | boolean;
|
|
170
198
|
|
|
171
199
|
export type SuiObjectArg =
|
|
172
|
-
|
|
|
173
|
-
| Infer<typeof SuiObjectRef>
|
|
200
|
+
| TransactionObjectArgument
|
|
174
201
|
| string
|
|
175
|
-
|
|
|
176
|
-
|
|
|
202
|
+
| SharedObjectRef
|
|
203
|
+
| SuiObjectRef
|
|
204
|
+
| ObjectCallArg;
|
|
177
205
|
|
|
178
206
|
export type SuiVecTxArg =
|
|
179
207
|
| { value: SuiTxArg[]; vecType: SuiInputTypes }
|
|
@@ -190,7 +218,8 @@ export type SuiBasicTypes =
|
|
|
190
218
|
| 'u32'
|
|
191
219
|
| 'u64'
|
|
192
220
|
| 'u128'
|
|
193
|
-
| 'u256'
|
|
221
|
+
| 'u256'
|
|
222
|
+
| 'signer';
|
|
194
223
|
|
|
195
224
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
196
225
|
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Connection } from '@mysten/sui.js';
|
|
2
|
-
import type { NetworkType } from '../../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;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
localnetConnection,
|
|
3
|
-
devnetConnection,
|
|
4
|
-
testnetConnection,
|
|
5
|
-
mainnetConnection,
|
|
6
|
-
} from '@mysten/sui.js';
|
|
7
|
-
import type { Connection } from '@mysten/sui.js';
|
|
8
|
-
import type { NetworkType } from '../../types';
|
|
9
|
-
export const defaultGasBudget = 10 ** 8; // 0.1 SUI, should be enough for most of the transactions
|
|
10
|
-
export const defaultGasPrice = 1000; // 1000 MIST
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @description Get the default fullnode url and faucet url for the given network type
|
|
14
|
-
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
15
|
-
* @returns { fullNode: string, websocket: string, faucet?: string }
|
|
16
|
-
*/
|
|
17
|
-
export const getDefaultConnection = (
|
|
18
|
-
networkType: NetworkType = 'devnet'
|
|
19
|
-
): Connection => {
|
|
20
|
-
switch (networkType) {
|
|
21
|
-
case 'localnet':
|
|
22
|
-
return localnetConnection;
|
|
23
|
-
case 'devnet':
|
|
24
|
-
return devnetConnection;
|
|
25
|
-
case 'testnet':
|
|
26
|
-
return testnetConnection;
|
|
27
|
-
case 'mainnet':
|
|
28
|
-
return mainnetConnection;
|
|
29
|
-
default:
|
|
30
|
-
return devnetConnection;
|
|
31
|
-
}
|
|
32
|
-
};
|