@rabby-wallet/eth-simple-keyring 5.0.0 → 5.1.0-beta.0

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 (2) hide show
  1. package/index.js +30 -8
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -35,18 +35,34 @@ class SimpleKeyring extends EventEmitter {
35
35
  super();
36
36
  this.type = type;
37
37
  this.wallets = [];
38
+ this.accounts = [];
38
39
  this.deserialize(opts);
39
40
  }
40
41
 
41
42
  serialize() {
42
- return Promise.resolve(
43
- this.wallets.map((w) =>
43
+ return Promise.resolve({
44
+ privateKeys: this.wallets.map((w) =>
44
45
  ethUtil.stripHexPrefix(ethUtil.bytesToHex(w.privateKey)),
45
46
  ),
46
- );
47
+ accounts: this.accounts,
48
+ });
49
+ }
50
+
51
+ deserialize(options = []) {
52
+ // legacy private key import
53
+ if (Array.isArray(options)) {
54
+ this.deserializePrivateKeys(options);
55
+ return;
56
+ }
57
+
58
+ const { privateKeys, accounts } = options;
59
+ if (privateKeys) {
60
+ this.deserializePrivateKeys(privateKeys);
61
+ }
62
+ this.accounts = accounts || [];
47
63
  }
48
64
 
49
- deserialize(privateKeys = []) {
65
+ deserializePrivateKeys(privateKeys = []) {
50
66
  return new Promise((resolve, reject) => {
51
67
  try {
52
68
  this.wallets = privateKeys.map((hexPrivateKey) => {
@@ -78,15 +94,21 @@ class SimpleKeyring extends EventEmitter {
78
94
  const hexWallets = newWallets.map(({ publicKey }) =>
79
95
  add0x(ethUtil.bytesToHex(ethUtil.publicToAddress(publicKey))),
80
96
  );
97
+ this.accounts = this.accounts.concat(hexWallets);
81
98
  return Promise.resolve(hexWallets);
82
99
  }
83
100
 
84
101
  getAccounts() {
85
- return Promise.resolve(
86
- this.wallets.map(({ publicKey }) => {
102
+ if (this.wallets) {
103
+ const accounts = this.wallets.map(({ publicKey }) => {
87
104
  return add0x(ethUtil.bytesToHex(ethUtil.publicToAddress(publicKey)));
88
- }),
89
- );
105
+ });
106
+
107
+ this.accounts = accounts;
108
+ return Promise.resolve(accounts);
109
+ }
110
+
111
+ return Promise.resolve(this.accounts);
90
112
  }
91
113
 
92
114
  // tx is an instance of the ethereumjs-transaction class.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/eth-simple-keyring",
3
- "version": "5.0.0",
3
+ "version": "5.1.0-beta.0",
4
4
  "description": "A simple standard interface for a series of Ethereum private keys.",
5
5
  "keywords": [
6
6
  "ethereum",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@ethereumjs/util": "^9.0.0",
34
- "@metamask/eth-sig-util": "^7.0.0",
34
+ "@metamask/eth-sig-util": "5.1.0",
35
35
  "@metamask/utils": "^8.1.0",
36
36
  "chai": "^4.3.4",
37
37
  "eth-sig-util": "^3.0.1",