@0xobelisk/sui-client 0.4.9

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.
Files changed (47) hide show
  1. package/LICENSE +92 -0
  2. package/README.md +284 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +1311 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +1292 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
  9. package/dist/libs/suiAccountManager/index.d.ts +35 -0
  10. package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
  11. package/dist/libs/suiAccountManager/util.d.ts +29 -0
  12. package/dist/libs/suiContractFactory/index.d.ts +20 -0
  13. package/dist/libs/suiContractFactory/types.d.ts +49 -0
  14. package/dist/libs/suiInteractor/defaultConfig.d.ts +10 -0
  15. package/dist/libs/suiInteractor/index.d.ts +2 -0
  16. package/dist/libs/suiInteractor/suiInteractor.d.ts +204 -0
  17. package/dist/libs/suiInteractor/util.d.ts +1 -0
  18. package/dist/libs/suiModel/index.d.ts +2 -0
  19. package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
  20. package/dist/libs/suiModel/suiSharedObject.d.ts +12 -0
  21. package/dist/libs/suiTxBuilder/index.d.ts +544 -0
  22. package/dist/libs/suiTxBuilder/util.d.ts +76 -0
  23. package/dist/metadata/index.d.ts +34 -0
  24. package/dist/obelisk.d.ts +2568 -0
  25. package/dist/types/index.d.ts +141 -0
  26. package/dist/utils/index.d.ts +3 -0
  27. package/package.json +149 -0
  28. package/src/index.ts +9 -0
  29. package/src/libs/suiAccountManager/crypto.ts +7 -0
  30. package/src/libs/suiAccountManager/index.ts +72 -0
  31. package/src/libs/suiAccountManager/keypair.ts +38 -0
  32. package/src/libs/suiAccountManager/util.ts +70 -0
  33. package/src/libs/suiContractFactory/index.ts +120 -0
  34. package/src/libs/suiContractFactory/types.ts +61 -0
  35. package/src/libs/suiInteractor/defaultConfig.ts +32 -0
  36. package/src/libs/suiInteractor/index.ts +2 -0
  37. package/src/libs/suiInteractor/suiInteractor.ts +302 -0
  38. package/src/libs/suiInteractor/util.ts +2 -0
  39. package/src/libs/suiModel/index.ts +2 -0
  40. package/src/libs/suiModel/suiOwnedObject.ts +62 -0
  41. package/src/libs/suiModel/suiSharedObject.ts +33 -0
  42. package/src/libs/suiTxBuilder/index.ts +245 -0
  43. package/src/libs/suiTxBuilder/util.ts +84 -0
  44. package/src/metadata/index.ts +22 -0
  45. package/src/obelisk.ts +636 -0
  46. package/src/types/index.ts +211 -0
  47. package/src/utils/index.ts +23 -0
package/LICENSE ADDED
@@ -0,0 +1,92 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Obelisk Labs
11
+
12
+ Licensed Work: Obelisk Engine
13
+ The Licensed Work is (c) 2023 Obelisk Labs
14
+
15
+ -----------------------------------------------------------------------------
16
+
17
+ Terms
18
+
19
+ The Licensor hereby grants you the right to copy, modify, create derivative
20
+ works, redistribute, and make non-production use of the Licensed Work. The
21
+ Licensor may make an Additional Use Grant, above, permitting limited
22
+ production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly
25
+ available distribution of a specific version of the Licensed Work under this
26
+ License, whichever comes first, the Licensor hereby grants you rights under
27
+ the terms of the Change License, and the rights granted in the paragraph
28
+ above terminate.
29
+
30
+ If your use of the Licensed Work does not comply with the requirements
31
+ currently in effect as described in this License, you must purchase a
32
+ commercial license from the Licensor, its affiliated entities, or authorized
33
+ resellers, or you must refrain from using the Licensed Work.
34
+
35
+ All copies of the original and modified Licensed Work, and derivative works
36
+ of the Licensed Work, are subject to this License. This License applies
37
+ separately for each version of the Licensed Work and the Change Date may vary
38
+ for each version of the Licensed Work released by Licensor.
39
+
40
+ You must conspicuously display this License on each original or modified copy
41
+ of the Licensed Work. If you receive the Licensed Work in original or
42
+ modified form from a third party, the terms and conditions set forth in this
43
+ License apply to your use of that work.
44
+
45
+ Any use of the Licensed Work in violation of this License will automatically
46
+ terminate your rights under this License for the current and all other
47
+ versions of the Licensed Work.
48
+
49
+ This License does not grant you any right in any trademark or logo of
50
+ Licensor or its affiliates (provided that you may use a trademark or logo of
51
+ Licensor as expressly required by this License).
52
+
53
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
54
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
55
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
57
+ TITLE.
58
+
59
+ MariaDB hereby grants you permission to use this License’s text to license
60
+ your works, and to refer to it using the trademark "Business Source License",
61
+ as long as you comply with the Covenants of Licensor below.
62
+
63
+ -----------------------------------------------------------------------------
64
+
65
+ Covenants of Licensor
66
+
67
+ In consideration of the right to use this License’s text and the "Business
68
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
69
+ other recipients of the licensed work to be provided by Licensor:
70
+
71
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
72
+ or a license that is compatible with GPL Version 2.0 or a later version,
73
+ where "compatible" means that software provided under the Change License can
74
+ be included in a program with software provided under GPL Version 2.0 or a
75
+ later version. Licensor may specify additional Change Licenses without
76
+ limitation.
77
+
78
+ 2. To either: (a) specify an additional grant of rights to use that does not
79
+ impose any additional restriction on the right granted in this License, as
80
+ the Additional Use Grant; or (b) insert the text "None".
81
+
82
+ 3. To specify a Change Date.
83
+
84
+ 4. Not to modify this License in any other way.
85
+
86
+ -----------------------------------------------------------------------------
87
+
88
+ Notice
89
+
90
+ The Business Source License (this document, or the "License") is not an Open
91
+ Source license. However, the Licensed Work will eventually be made available
92
+ under an Open Source License, as stated in this License.
package/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # Obelisk Client SDK
2
+
3
+ Obelisk is client agnostic: any client -- a browser, a game engine, or an ios/android app -- can implement the synchronization protocol and a client-side cache to replicate Store tables, along with the necessary infrastructure to send transactions to the World.
4
+
5
+ Currently we only support browsers, Node and the COCOS game engine.
6
+
7
+ ## Getting Started
8
+
9
+ Before proceeding with the next steps, make sure you have deployed your own world contract via cli.
10
+
11
+ When the world contract is deployed successfully, it will return a PackageId (the contract's ObjectId) and a WorldId (the World Store's ObjectId).
12
+
13
+ ### Data preparation
14
+
15
+ We create a Project called Counter and declare sigleton schema called counter, which is of type `u64` and has an initial value of `0`.
16
+
17
+
18
+ ```typescript
19
+ import { ObeliskConfig } from '@0xobelisk/sui-common';
20
+
21
+ export const obeliskConfig = {
22
+ name: 'counter',
23
+ description: 'counter',
24
+ systems: ['counter_system'],
25
+ schemas: {
26
+ counter: {
27
+ valueType: 'u64',
28
+ defaultValue: 0,
29
+ },
30
+ },
31
+ sample_schema: 'u64',
32
+ } as ObeliskConfig;
33
+ ```
34
+
35
+ Through the CLI, we will generate the corresponding contract based on obelisk.config.ts At this point we need to write the system logic.
36
+
37
+ ```bash
38
+ obelisk schemagen obelisk.config.ts
39
+ ```
40
+
41
+ The next step is simply to write the system file method.
42
+
43
+ ```rust
44
+ // contracts/counter/system/counter_system.move
45
+ module counter::counter_system {
46
+ use counter::world::World;
47
+ use counter::counter_schema;
48
+
49
+ public entry fun inc(world: &mut World){
50
+ let value = counter_schema::get(world) + 1;
51
+ counter_schema::set(world,value);
52
+ }
53
+ }
54
+ ```
55
+
56
+ Finally we deploy the complete contract to devnet
57
+
58
+
59
+ ```bash
60
+ obelisk publish --network devnet --configPath obelisk.config.ts
61
+ ```
62
+
63
+ We'll get the `packageId` and `worldId` on the command line.
64
+
65
+ ### Init Obelisk Client
66
+
67
+ ```typescript
68
+ import { getMetadata, Obelisk, NetworkType } from "@0xobelisk/sui-client";
69
+
70
+ const network = "devnet" as NetworkType
71
+ const packageId = "0x804578b9eed47d461bba52c393cf148302819e2ba0a0f558356cc419b3e941ed"
72
+
73
+ const metadata = await getMetadata(network, packageId);
74
+
75
+ const obelisk = new Obelisk({
76
+ networkType: network,
77
+ packageId: packageId,
78
+ metadata: metadata,
79
+ secretKey: privkey
80
+ });
81
+ ```
82
+
83
+ ### World Tx
84
+
85
+ If you need to call a method in the system, you can do so using the `obelisk.tx.moudleName.funcName()` form.
86
+
87
+ ```typescript
88
+ import { getMetadata, Obelisk, TransactionBlock } from "@0xobelisk/sui-client";
89
+
90
+ const metadata = await getMetadata(network, packageId);
91
+
92
+ const obelisk = new Obelisk({
93
+ networkType: network,
94
+ packageId: packageId,
95
+ metadata: metadata,
96
+ secretKey: privkey
97
+ });
98
+
99
+ // Initiate transactions through the account set up by obelisk
100
+ const tx = new TransactionBlock()
101
+
102
+ const world = tx.pure(WORLD_ID)
103
+ const params = [
104
+ world,
105
+ ]
106
+
107
+ const res_tx = await obelisk.tx.counter_system.inc(tx, params)
108
+
109
+ // If you want to encapsulate the TransactionBlock
110
+ const tx = new TransactionBlock()
111
+ const world = tx.pure(WORLD_ID)
112
+ const params = [
113
+ world,
114
+ ]
115
+ // By isolating the signature from the transactionBlock construction in this way,
116
+ // the front-end wallet plugin can signAndSend() directly to the transactionBlock,
117
+ // facilitating front-end interaction.
118
+ const new_tx = await obelisk.tx.counter_system.inc(tx, params, true) as TransactionBlock;
119
+
120
+ const response = await obelisk.signAndSendTxn(
121
+ new_tx
122
+ )
123
+ ```
124
+
125
+ ### World Query
126
+
127
+ #### Query public contract view func
128
+
129
+ If your system method provides a method with no modification status and a return, then you can query it via `obelisk.query.moudleName.funcName()`.
130
+
131
+ ```typescript
132
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
133
+ const obelisk = new Obelisk({
134
+ networkType: NETWORK,
135
+ packageId: PACKAGE_ID,
136
+ metadata: metadata,
137
+ });
138
+
139
+ const tx = new TransactionBlock()
140
+ const world = tx.pure(WORLD_ID)
141
+ const params = [
142
+ world,
143
+ ]
144
+ const query_value = await obelisk.query.counter_system.get(tx, params);
145
+ ```
146
+
147
+ #### Get world
148
+
149
+ Queries the Object information of worldId.
150
+
151
+ ```typescript
152
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
153
+ const obelisk = new Obelisk({
154
+ networkType: NETWORK,
155
+ packageId: PACKAGE_ID,
156
+ metadata: metadata,
157
+ });
158
+ const world_value = await obelisk.getWorld(WORLD_ID)
159
+ ```
160
+
161
+
162
+ #### List schema names
163
+
164
+ List all schema name in the world store.
165
+
166
+ ```typescript
167
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
168
+ const obelisk = new Obelisk({
169
+ networkType: NETWORK,
170
+ packageId: PACKAGE_ID,
171
+ metadata: metadata,
172
+ });
173
+ const schemaNames = await obelisk.listSchemaNames(
174
+ '0x1541f3a2e7ac48e3e68e60bb97a7cee94e16316cc3f9043a9c0f5e6790ea3af0'
175
+ );
176
+ ```
177
+
178
+
179
+ #### Get entity
180
+
181
+ Get the entity's data based on schema name and entity id(option).
182
+
183
+ ```typescript
184
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
185
+ const obelisk = new Obelisk({
186
+ networkType: NETWORK,
187
+ packageId: PACKAGE_ID,
188
+ metadata: metadata,
189
+ });
190
+
191
+ const worldId = "0x1541f3a2e7ac48e3e68e60bb97a7cee94e16316cc3f9043a9c0f5e6790ea3af0";
192
+
193
+ // get schema entity data
194
+ const schemaName = "simple_schema"
195
+ const entityId = "0x00000000000000000000000000000000000000000000000000000000000003ed"
196
+ const entities = await obelisk.getEntity(
197
+ worldId,
198
+ schemaName,
199
+ entityId
200
+ );
201
+
202
+ // get singleton schema entity data
203
+ const singletonSchemaName = "counter"
204
+ const entities = await obelisk.getEntity(
205
+ worldId,
206
+ singletonSchemaName
207
+ );
208
+
209
+ ```
210
+
211
+
212
+ #### Contain entity
213
+
214
+ Determine if the entity exists
215
+
216
+ ```typescript
217
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
218
+ const obelisk = new Obelisk({
219
+ networkType: NETWORK,
220
+ packageId: PACKAGE_ID,
221
+ metadata: metadata,
222
+ });
223
+
224
+ const worldId = "0x1541f3a2e7ac48e3e68e60bb97a7cee94e16316cc3f9043a9c0f5e6790ea3af0";
225
+
226
+ // get schema entity data
227
+ const schemaName = "simple_schema"
228
+ const entityId = "0x00000000000000000000000000000000000000000000000000000000000003ed"
229
+ const entities = await obelisk.containEntity(
230
+ worldId,
231
+ schemaName,
232
+ entityId
233
+ );
234
+
235
+ // get singleton schema entity data
236
+ const singletonSchemaName = "counter"
237
+ const entities = await obelisk.containEntity(
238
+ worldId,
239
+ singletonSchemaName
240
+ );
241
+
242
+ ```
243
+
244
+ #### Get owned objects
245
+
246
+ Query all the objects under the current worldId that are owned by a certain address.
247
+
248
+ ```typescript
249
+ const metadata = await getMetadata(NETWORK, PACKAGE_ID);
250
+ const obelisk = new Obelisk({
251
+ networkType: NETWORK,
252
+ packageId: PACKAGE_ID,
253
+ metadata: metadata,
254
+ });
255
+
256
+ const owner = "0xfa99b5b0463fcfb7d0203c701a76da5eda21a96190eb1368ab36a437cc89195e";
257
+ const owned_objects_value = await obelisk.getOwnedObjects(owner);
258
+ ```
259
+
260
+ ### About entity key
261
+
262
+ You can customize how the key is generated in the system, but I recommend that you generate the entity key using the user's address or objectId as the associative data, as this will help you associate the generated entity with address/objectId. This will help you associate the generated entity with the user's address, and then you can quickly determine the creator of the entity by the user's address or objectId.
263
+
264
+ We provide three ways to convert entity keys, and of course you are welcome to contribute more entity key specifications.
265
+
266
+
267
+ ```typescript
268
+ // Create key based on objectId.
269
+ // You can use the user's address as the entity key,
270
+ // or you can use the Id of an object as the entity key.
271
+ //
272
+ // For example: using the objectId of the NFT as the key,
273
+ // you can set the owner of the nft as the owner of the accessed entity.
274
+ let objectAddress = await obelisk.entity_key_from_object(
275
+ '0x1541f3a2e7ac48e3e68e60bb97a7cee94e16316cc3f9043a9c0f5e6790ea3af0'
276
+ );
277
+
278
+ // hexAddress(keccak256(inputStringData))
279
+ let bytesAddress = await obelisk.entity_key_from_bytes('hello');
280
+
281
+ // hexAddress(inputNumberData)
282
+ let numberAddress = await obelisk.entity_key_from_u256(123);
283
+ ```
284
+
@@ -0,0 +1,9 @@
1
+ export * from '@mysten/sui.js';
2
+ export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
3
+ export { BCS, getSuiMoveConfig } 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 { loadMetadata } from './metadata';
9
+ export type * from './types';