suidouble 0.0.48 → 0.0.49
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
CHANGED
|
@@ -49,7 +49,7 @@ const { SuiMaster } = require('suidouble');
|
|
|
49
49
|
You can initialize it directly, if you have keypair, secret phrase and can use it in code (so on node.js side - server side or CLI apps):
|
|
50
50
|
```javascript
|
|
51
51
|
const suiMaster = new SuiMaster({
|
|
52
|
-
keypair: Ed25519Keypair,
|
|
52
|
+
keypair: Ed25519Keypair || Secp256r1Keypair || Secp256k1Keypair,
|
|
53
53
|
debug: true, // echo testing messages to console
|
|
54
54
|
provider: 'test', // 'test', 'dev', 'local', 'main' or instance of this lib's SuiLocalTestValidator, or instance of Sui's JsonRpcProvider
|
|
55
55
|
});
|
|
@@ -64,6 +64,12 @@ const suiMaster = new SuiMaster({
|
|
|
64
64
|
accountIndex: 1, // derive path index (you can generate few addresses with same seed phrase)
|
|
65
65
|
provider: 'dev',
|
|
66
66
|
});
|
|
67
|
+
const suiMaster = new SuiMaster({
|
|
68
|
+
debug: false,
|
|
69
|
+
phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
|
|
70
|
+
keypairAlgo: 'secp256k1', // 'secp256r1' or 'secp256r1' or 'ed25519' default is ed25519
|
|
71
|
+
provider: 'dev',
|
|
72
|
+
});
|
|
67
73
|
```
|
|
68
74
|
|
|
69
75
|
Also, there's option to generate pseudo-random phrases and wallets from strings, works like a charm for testing:
|
package/lib/SuiMaster.js
CHANGED
|
@@ -10,6 +10,8 @@ const SuiCoins = require('./SuiCoins.js');
|
|
|
10
10
|
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
|
|
11
11
|
const { MIST_PER_SUI } = require('@mysten/sui.js/utils');
|
|
12
12
|
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
|
|
13
|
+
const { Secp256r1Keypair } = require('@mysten/sui.js/keypairs/secp256r1');
|
|
14
|
+
const { Secp256k1Keypair } = require('@mysten/sui.js/keypairs/secp256k1');
|
|
13
15
|
const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet');
|
|
14
16
|
const { TransactionBlock,Transactions } = require('@mysten/sui.js/transactions');
|
|
15
17
|
|
|
@@ -34,14 +36,36 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
34
36
|
} else if (params.keypair) {
|
|
35
37
|
this._keypair = params.keypair;
|
|
36
38
|
} else if (params.phrase) {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
+
if (params.keypairAlgo && (''+params.keypairAlgo).toLowerCase() == 'secp256r1') {
|
|
40
|
+
if (!params.accountIndex) {
|
|
41
|
+
this._keypair = Secp256r1Keypair.deriveKeypair(params.phrase);
|
|
42
|
+
} else {
|
|
43
|
+
// remember you can generate many addresses with same seed?
|
|
44
|
+
const derivePath = `m/74'/784'/${params.accountIndex}'/0/0`;
|
|
45
|
+
this._keypair = Secp256r1Keypair.deriveKeypair(params.phrase, derivePath);
|
|
46
|
+
}
|
|
47
|
+
} else if (params.keypairAlgo && (''+params.keypairAlgo).toLowerCase() == 'secp256k1') {
|
|
48
|
+
if (!params.accountIndex) {
|
|
49
|
+
this._keypair = Secp256k1Keypair.deriveKeypair(params.phrase);
|
|
50
|
+
} else {
|
|
51
|
+
// remember you can generate many addresses with same seed?
|
|
52
|
+
const derivePath = `m/54'/784'/${params.accountIndex}'/0/0`;
|
|
53
|
+
this._keypair = Secp256k1Keypair.deriveKeypair(params.phrase, derivePath);
|
|
54
|
+
}
|
|
39
55
|
} else {
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
// default is Ed25519{
|
|
57
|
+
// default is Ed25519
|
|
58
|
+
|
|
59
|
+
if (!params.accountIndex) {
|
|
60
|
+
this._keypair = Ed25519Keypair.deriveKeypair(params.phrase);
|
|
61
|
+
} else {
|
|
62
|
+
// remember you can generate many addresses with same seed?
|
|
63
|
+
const derivePath = `m/44'/784'/${params.accountIndex}'/0'/0'`;
|
|
64
|
+
this._keypair = Ed25519Keypair.deriveKeypair(params.phrase, derivePath);
|
|
65
|
+
}
|
|
43
66
|
}
|
|
44
67
|
|
|
68
|
+
|
|
45
69
|
this.log('goint to use keypair of', this._keypair.getPublicKey().toSuiAddress());
|
|
46
70
|
} else if (params.as) {
|
|
47
71
|
// generate pseudo-random keypair
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
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": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@mysten/sui.js": "^0.
|
|
24
|
+
"@mysten/sui.js": "^0.42.0",
|
|
25
25
|
"@wallet-standard/core": "^1.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -55,6 +55,39 @@ test('keypair generation with seed phrase works ok', async t => {
|
|
|
55
55
|
t.equal(`${suiMasterNextAccount.address}`, `0xa6fb5c51b751e07a3e3b3af1f40f3115004702aad5a96263ff0be9078195f43b`, 'Ed25519 next account generated ok');
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
test('keypair generation with seed phrase works ok with secp256r1', async t => {
|
|
59
|
+
// Ed25519
|
|
60
|
+
const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; //
|
|
61
|
+
const suiMaster = new SuiMaster({provider: 'test', phrase: phrase, keypairAlgo: 'secp256r1'});
|
|
62
|
+
await suiMaster.initialize();
|
|
63
|
+
|
|
64
|
+
t.equal(`${suiMaster.address}`, `0x444f18d480b4d776d7679fae88ebb4f274941a81c3d98db430f7bd13f82e287d`, 'secp256r1 generated ok');
|
|
65
|
+
|
|
66
|
+
const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256r1'}); // default = 0
|
|
67
|
+
await suiMasterNextAccount.initialize();
|
|
68
|
+
|
|
69
|
+
t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
|
|
70
|
+
|
|
71
|
+
t.equal(`${suiMasterNextAccount.address}`, `0xae496597c64aa6b1aaa03792c0ba0a725b1212adcb0df85d22c447cd57c21c95`, 'secp256r1 next account generated ok');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
test('keypair generation with seed phrase works ok with secp256k1', async t => {
|
|
76
|
+
// Ed25519
|
|
77
|
+
const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; //
|
|
78
|
+
const suiMaster = new SuiMaster({provider: 'test', phrase: phrase, keypairAlgo: 'secp256k1'});
|
|
79
|
+
await suiMaster.initialize();
|
|
80
|
+
|
|
81
|
+
t.equal(`${suiMaster.address}`, `0x86a5dd3def25cab060af90f438842524894c7901839a954b2e9547ecc0f35ef8`, 'secp256k1 generated ok');
|
|
82
|
+
|
|
83
|
+
const suiMasterNextAccount = new SuiMaster({provider: 'test', phrase: phrase, accountIndex: 1, keypairAlgo: 'secp256k1'}); // default = 0
|
|
84
|
+
await suiMasterNextAccount.initialize();
|
|
85
|
+
|
|
86
|
+
t.notEqual(`${suiMaster.address}`, `${suiMasterNextAccount.address}`);
|
|
87
|
+
|
|
88
|
+
t.equal(`${suiMasterNextAccount.address}`, `0xc5390344b0344a3e657176eaf72ca00ecf3ed4ec791640b6fc65a11cb680c53f`, 'secp256k1 next account generated ok');
|
|
89
|
+
});
|
|
90
|
+
|
|
58
91
|
test('SuiMaster has MIST_PER_SUI property available as BigInt', async t => {
|
|
59
92
|
const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
|
|
60
93
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[move]
|
|
4
4
|
version = 0
|
|
5
5
|
manifest_digest = "F8C73BB1CA5B2EEF078E6FD0C793EF387322A4AD49DECCFE6AAD9F5F81C198C8"
|
|
6
|
-
deps_digest = "
|
|
6
|
+
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
|
|
7
7
|
|
|
8
8
|
dependencies = [
|
|
9
9
|
{ name = "Sui" },
|