suidouble 0.0.29 → 0.0.31
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 +6 -0
- package/lib/SuiMaster.js +11 -1
- package/package.json +1 -1
- package/test/sui_master_basic.test.js +25 -0
package/README.md
CHANGED
|
@@ -53,6 +53,12 @@ const suiMaster = new SuiMaster({
|
|
|
53
53
|
phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
|
|
54
54
|
provider: 'dev',
|
|
55
55
|
});
|
|
56
|
+
const suiMaster = new SuiMaster({
|
|
57
|
+
debug: false,
|
|
58
|
+
phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
|
|
59
|
+
accountIndex: 1, // derive path index (you can generate few addresses with same seed phrase)
|
|
60
|
+
provider: 'dev',
|
|
61
|
+
});
|
|
56
62
|
```
|
|
57
63
|
|
|
58
64
|
Also, there's option to generate pseudo-random phrases and wallets from strings, works like a charm for testing:
|
package/lib/SuiMaster.js
CHANGED
|
@@ -25,7 +25,13 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
25
25
|
} else if (params.keypair) {
|
|
26
26
|
this._keypair = params.keypair;
|
|
27
27
|
} else if (params.phrase) {
|
|
28
|
-
|
|
28
|
+
if (!params.accountIndex) {
|
|
29
|
+
this._keypair = sui.Ed25519Keypair.deriveKeypair(params.phrase);
|
|
30
|
+
} else {
|
|
31
|
+
// remember you can generate many addresses with same seed?
|
|
32
|
+
const derivePath = `m/44'/784'/${params.accountIndex}'/0'/0'`;
|
|
33
|
+
this._keypair = sui.Ed25519Keypair.deriveKeypair(params.phrase, derivePath);
|
|
34
|
+
}
|
|
29
35
|
|
|
30
36
|
this.log('goint to use keypair of', this._keypair.getPublicKey().toSuiAddress());
|
|
31
37
|
} else if (params.as) {
|
|
@@ -94,6 +100,10 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
94
100
|
this._packages = {};
|
|
95
101
|
}
|
|
96
102
|
|
|
103
|
+
get MIST_PER_SUI() {
|
|
104
|
+
return BigInt(sui.MIST_PER_SUI);
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
get objectStorage() {
|
|
98
108
|
return this._objectStorage;
|
|
99
109
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,6 +39,31 @@ test('pseudo-random keypairs generation works ok', async t => {
|
|
|
39
39
|
t.equal(`${suiMasterAsAdminAnother.address}`, `${suiMasterAsAdmin.address}`, 'same string should generate same pseudo-random');
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
test('keypair generation with seed phrase works ok', async t => {
|
|
43
|
+
// Ed25519
|
|
44
|
+
const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; // 0x2bfe9c35ca9400c42e24e4b424cbd2dfb51bcb7c2487e1b4694ff53d8ca00262
|
|
45
|
+
const suiMaster = new SuiMaster({provider: 'test', phrase: phrase});
|
|
46
|
+
await suiMaster.initialize();
|
|
47
|
+
|
|
48
|
+
t.equal(`${suiMaster.address}`, `0x2bfe9c35ca9400c42e24e4b424cbd2dfb51bcb7c2487e1b4694ff53d8ca00262`, 'Ed25519 generated ok');
|
|
49
|
+
|
|
50
|
+
const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1}); // default = 0
|
|
51
|
+
await suiMasterNextAccount.initialize();
|
|
52
|
+
|
|
53
|
+
t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
|
|
54
|
+
|
|
55
|
+
t.equal(`${suiMasterNextAccount.address}`, `0xa6fb5c51b751e07a3e3b3af1f40f3115004702aad5a96263ff0be9078195f43b`, 'Ed25519 next account generated ok');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('SuiMaster has MIST_PER_SUI property available as BigInt', async t => {
|
|
59
|
+
const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
|
|
60
|
+
|
|
61
|
+
t.ok(suiMaster.MIST_PER_SUI);
|
|
62
|
+
|
|
63
|
+
t.equal(typeof suiMaster.MIST_PER_SUI, 'bigint');
|
|
64
|
+
t.ok(suiMaster.MIST_PER_SUI > BigInt(0));
|
|
65
|
+
});
|
|
66
|
+
|
|
42
67
|
test('connecting to different chains', async t => {
|
|
43
68
|
const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
|
|
44
69
|
await suiMaster.initialize();
|