suidouble 1.6.0-1 → 1.6.0-2

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
@@ -46,13 +46,18 @@ Main class to interact with blockchain is SuiMaster:
46
46
  const { SuiMaster } = require('suidouble');
47
47
  ```
48
48
 
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):
49
+ You can initialize it directly, if you have keypair, secret phrase, or privateKey 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
52
  keypair: Ed25519Keypair || Secp256r1Keypair || Secp256k1Keypair,
53
53
  debug: true, // echo testing messages to console
54
54
  client: 'test', // 'test', 'dev', 'local', 'main' or instance of this lib's SuiLocalTestValidator
55
55
  });
56
+ const suiMaster = new SuiMaster({
57
+ debug: false,
58
+ privateKey: 'suiprivkey1qpwly9xrfsv50mqug706s40l58klez5q6mpchq4f5ldzktjyr4x7yhj9lf2',
59
+ client: 'dev',
60
+ });
56
61
  const suiMaster = new SuiMaster({
57
62
  debug: false,
58
63
  phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
package/lib/SuiMaster.js CHANGED
@@ -14,6 +14,7 @@ const { Secp256r1Keypair } = require('@mysten/sui/keypairs/secp256r1');
14
14
  const { Secp256k1Keypair } = require('@mysten/sui/keypairs/secp256k1');
15
15
  const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui/faucet');
16
16
  const { Transaction, Commands } = require('@mysten/sui/transactions');
17
+ const { decodeSuiPrivateKey } = require('@mysten/sui/cryptography');
17
18
 
18
19
 
19
20
  class SuiMaster extends SuiCommonMethods {
@@ -36,6 +37,17 @@ class SuiMaster extends SuiCommonMethods {
36
37
  }
37
38
  } else if (params.keypair) {
38
39
  this._keypair = params.keypair;
40
+ } else if (params.privateKey) {
41
+ const parsed = decodeSuiPrivateKey(params.privateKey);
42
+ if (parsed && parsed.schema) {
43
+ if (parsed.schema === 'ED25519') {
44
+ this._keypair = Ed25519Keypair.fromSecretKey(parsed.secretKey);
45
+ } else if (parsed.schema == 'Secp256k1') {
46
+ this._keypair = Secp256k1Keypair.fromSecretKey(parsed.secretKey);
47
+ } else if (parsed.schema == 'Secp256r1') {
48
+ this._keypair = Secp256r1Keypair.fromSecretKey(parsed.secretKey);
49
+ }
50
+ }
39
51
  } else if (params.phrase) {
40
52
  if (params.keypairAlgo && (''+params.keypairAlgo).toLowerCase() == 'secp256r1') {
41
53
  if (!params.accountIndex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "1.6.0-1",
3
+ "version": "1.6.0-2",
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": {
@@ -33,6 +33,5 @@
33
33
  "fs": false,
34
34
  "path": false
35
35
  },
36
- "tap": {
37
- }
36
+ "tap": {}
38
37
  }
@@ -39,6 +39,15 @@ 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 privateKey works ok', async t => {
43
+ const privateKey = 'suiprivkey1qpwly9xrfsv50mqug706s40l58klez5q6mpchq4f5ldzktjyr4x7yhj9lf2';
44
+ const suiMaster = new SuiMaster({client: 'test', privateKey: privateKey});
45
+ await suiMaster.initialize();
46
+
47
+ t.equal(`${suiMaster.address}`, `0x4d07e4a382dcb69288a8a4589e8fc0534378dad76b75565fda0c1e9ada45b7d1`, 'by privateKey generated ok');
48
+ });
49
+
50
+
42
51
  test('keypair generation with seed phrase works ok', async t => {
43
52
  // Ed25519
44
53
  const phrase = 'seek weekend run rival noodle dog alone mosquito decide hover aerobic fiction'; // 0x2bfe9c35ca9400c42e24e4b424cbd2dfb51bcb7c2487e1b4694ff53d8ca00262