@typus/typus-sdk 0.0.1

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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # typus-sdk
2
+
3
+ ## install
4
+
5
+ ```bash
6
+ npm i
7
+ ```
8
+
9
+ ## run scripts
10
+
11
+ ### simple test for important function
12
+ ```bash
13
+ npx ts-node scripts/sui.ts
14
+ ```
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@typus/typus-sdk",
3
+ "author": "Typus",
4
+ "description": "typus sdk",
5
+ "version": "0.0.1",
6
+ "dependencies": {
7
+ "@mysten/sui.js": "^0.17.1",
8
+ "fetch": "^1.1.0",
9
+ "node-fetch": "^3.3.0"
10
+ },
11
+ "main": "index.js",
12
+ "devDependencies": {},
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Typus-Lab/typus-sdk.git"
19
+ },
20
+ "license": "ISC",
21
+ "bugs": {
22
+ "url": "https://github.com/Typus-Lab/typus-sdk/issues"
23
+ },
24
+ "homepage": "https://github.com/Typus-Lab/typus-sdk#readme"
25
+ }
package/scripts/sui.ts ADDED
@@ -0,0 +1,216 @@
1
+ import { JsonRpcProvider, Ed25519Keypair, RawSigner, SuiEventEnvelope, Network, Base64DataBuffer } from '@mysten/sui.js';
2
+ import { fromB64 } from '@mysten/bcs';
3
+ import fs from "fs";
4
+ import fetch from 'cross-fetch';
5
+ const { execSync } = require('child_process');
6
+ const rpc = new JsonRpcProvider('https://fullnode.devnet.sui.io:443');
7
+ const provider = new JsonRpcProvider(Network.DEVNET);//for read only operations
8
+ const owner = "0xd28103a499003bed0b1b9ee52988ecdd2db82224";
9
+ const obj1 = "0x7e9e58daeb94bbd0450bb9ee9f00e219a1f2b734";//obj owned by owner
10
+ const obj2 = "0x74aa838eb6627c8e74b0645484abb463e6fd6669";//obj owned by owner
11
+ const obj1Digest = "tclmc0L6hewmfWxQAxSl9eUe14C82+hzE4OblKgY38U=";
12
+ const obj2Digest = "tclmc0L6hewmfWxQAxSl9eUe14C82+hzE4OblKgY38U=";
13
+ const receiver = "0x15ca0895f29101085cb26e00ede89420741b3140";
14
+ const tx1 = "GRiBgktRqgJ4MSoRhCfSm/+1R/Zh9jy4UncoQeFAu5I="
15
+ // export PRIVATEKEY=~/.sui/sui_config/sui.keystore
16
+ const secretKeysPath = process.env.PRIVATEKEY;
17
+
18
+ const subVault = "0xd3b2d3ee74afe2b5af0f810b3368955f068188e8"
19
+
20
+ const TEST_MNEMONIC = "tackle wheat jungle viable memory dwarf swift fold purpose cattle impose horn"
21
+ const VALID_SECRET_KEY = "Itk7iNFs91kXKdqVqmLrBKJItNIoSyWAOh+ZC2qaSihpxiAxNYwKPjwfresk9CSbKCmwNwvXfPQoeLL4rVa4OQ=="//'mdqVWeFekT7pqy5T49+tV12jO0m+ESW7ki4zSU9JiCgbL0kJbj5dvQ/PqcDAzZLZqzshVEs01d1KZdmLh4uZIg==';
22
+
23
+ // let secretKeys = (readJsonFile<any>(secretKeysPath as string))
24
+ // let sender = secretKeys[0]
25
+
26
+ // let keypair = Ed25519Keypair.fromSecretKey(fromB64(sender))// Error: Wrong secretKey size. Expected 64 bytes, got 65.
27
+ // let keypair = Ed25519Keypair.fromSecretKey(fromB64(VALID_SECRET_KEY))
28
+ let keypair = Ed25519Keypair.deriveKeypair(TEST_MNEMONIC);
29
+ const signer = new RawSigner(keypair, provider);
30
+
31
+ function readJsonFile<T>(filePath: string): T {
32
+ return JSON.parse(
33
+ fs.readFileSync(
34
+ filePath,
35
+ "utf-8"
36
+ )
37
+ )
38
+ }
39
+
40
+ // //Success
41
+ // (async () => {
42
+ // console.log("test for getObjectsOwnedByAddress()")
43
+
44
+ // const objects = await provider.getObjectsOwnedByAddress(
45
+ // owner
46
+ // )
47
+ // console.log(objects)
48
+ // })();
49
+
50
+ // //Success
51
+ // (async () => {
52
+ // console.log("test for getObjectsOwnedByObject()")
53
+
54
+ // const objects = await provider.getObjectsOwnedByObject(
55
+ // obj1
56
+ // )
57
+ // console.log(objects)
58
+
59
+ // //filter obj by type
60
+ // for (let object of objects) {
61
+ // if (object.type.includes("dynamic_field")) console.log("it's dynamic field object")
62
+ // }
63
+ // })();
64
+
65
+ // //Success
66
+ // (async () => {
67
+ // console.log("test for getObject() and getObjectBatch()")
68
+
69
+ // const txn = await provider.getObject(
70
+ // obj1
71
+ // );
72
+ // console.log(txn)
73
+
74
+ // // You can also fetch multiple objects in one batch request
75
+ // const txns = await provider.getObjectBatch([
76
+ // obj1,
77
+ // obj2,
78
+ // ]);
79
+ // console.log(txns)
80
+ // })();
81
+
82
+ // // Fail
83
+ // (async () => {
84
+ // console.log("test for getTransactionWithEffects() and getTransactionWithEffectsBatch()")
85
+
86
+ // const txn = await provider.getTransactionWithEffects(
87
+ // obj1Digest
88
+ // );
89
+ // console.log(txn)
90
+
91
+ // You can also fetch multiple transactions in one batch request
92
+ // const txns = await provider.getTransactionWithEffectsBatch([
93
+ // obj1Digest,
94
+ // obj2Digest,
95
+ // ]);
96
+ // console.log(txns)
97
+ // })();
98
+
99
+ // //Fail (without correct signer)
100
+ // (async () => {
101
+ // console.log("test for transferObject()")
102
+ // const transferTxn = await signer.transferObject({
103
+ // objectId: obj1,
104
+ // gasBudget: 1000,
105
+ // recipient: receiver,
106
+ // });
107
+ // console.log('transferTxn', transferTxn);
108
+ // })();
109
+
110
+ // //Fail (without correct signer)
111
+ // (async () => {
112
+ // console.log("test for executeMoveCall()")
113
+ // const moveCallTxn = await signer.executeMoveCall({
114
+ // packageObjectId: '0x2',
115
+ // module: 'devnet_nft',
116
+ // function: 'mint',
117
+ // typeArguments: [],
118
+ // arguments: [
119
+ // 'Example NFT',
120
+ // 'An NFT created by the wallet Command Line Tool',
121
+ // 'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty',
122
+ // ],
123
+ // gasBudget: 10000,
124
+ // });
125
+ // console.log('moveCallTxn', moveCallTxn);
126
+ // })();
127
+
128
+ // //Fail( Error subscribing to event)
129
+ // (async () => {
130
+ // console.log("test for subscribeEvent()")
131
+ // // calls RPC method 'sui_subscribeEvent' with params:
132
+ // // [ { SenderAddress: '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3' } ]
133
+
134
+ // const subscriptionId = await provider.subscribeEvent(
135
+ // { SenderAddress: '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3' },
136
+ // (event: SuiEventEnvelope) => {
137
+ // console.log(event)
138
+ // // handle subscription notification message here. This function is called once per subscription message.
139
+ // }
140
+ // );
141
+
142
+ // // later, to unsubscribe
143
+ // // calls RPC method 'sui_unsubscribeEvent' with params: [ subscriptionId ]
144
+ // const subFoundAndRemoved = await provider.unsubscribeEvent(subscriptionId);
145
+ // })();
146
+
147
+ // //Fail (without correct signer)
148
+ //refer: https://docs.sui.io/build/json-rpc
149
+ // (async () => {
150
+ // console.log("test for publish()")
151
+ // const compiledModules = JSON.parse(
152
+ // execSync(
153
+ // `${cliPath} move build --dump-bytecode-as-base64 --path ${packagePath}`,
154
+ // { encoding: 'utf-8' }
155
+ // )
156
+ // );
157
+ // const modulesInBytes = compiledModules.map((m) =>
158
+ // Array.from(new Base64DataBuffer(m).getData())
159
+ // );
160
+ // const publishTxn = await signer.publish({
161
+ // compiledModules: modulesInBytes,
162
+ // gasBudget: 10000,
163
+ // });
164
+ // console.log('publishTxn', publishTxn);
165
+ // })();
166
+
167
+ // //Success
168
+ // (async () => {
169
+ // console.log("test for getTransactions()") // return digest
170
+ // let txs = await provider.getTransactionsForObject(
171
+ // obj1
172
+ // )
173
+ // console.log(txs)
174
+
175
+ // let tx = await provider.getTransactionWithEffects(
176
+ // txs[0]
177
+ // )
178
+ // console.log(tx)
179
+ // })();
180
+
181
+ // //Success
182
+ // (async () => {
183
+ // console.log("test for getEvents()")//input type: EventQuery
184
+ // const senderEvents = await provider.getEvents(
185
+ // { "Transaction": tx1 },
186
+ // null,
187
+ // null,
188
+ // );
189
+ // for (let e of senderEvents.data) {
190
+ // console.log(e.event)
191
+ // }
192
+ // })();
193
+
194
+ // let packageId = "0xfbbdd33ab4c02e7a315e2477931bae4cbdf46381";
195
+ // let registry = "0x0a9d87a1b6c00415708d2f1c62784b52f797213c";
196
+ // let coin = "0x84e5c5702bfbb00a830fb43e720a3a412cc2a8db";
197
+ // console.log("test for deposit()")
198
+ // await deposit(packageId, registry, coin)
199
+ // async function deposit(packageId: string, registry: string, coin: string) {
200
+ // let txn = {
201
+ // packageObjectId: packageId,
202
+ // module: 'shark_fin',
203
+ // function: 'deposit',
204
+ // typeArguments: ["0x2::sui::SUI"],
205
+ // arguments: [
206
+ // registry,
207
+ // 0,
208
+ // true,
209
+ // coin
210
+ // ],
211
+ // gasBudget: 1000,
212
+ // }
213
+ // const moveCallTxn = await signer.executeMoveCall(txn);
214
+ // console.log('moveCallTxn', moveCallTxn);
215
+ // }
216
+
File without changes
File without changes
File without changes