@trustwallet/wallet-core 3.1.0 → 3.1.3

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.
@@ -1,4 +1,4 @@
1
- import { WalletCore, CoinType, PrivateKey, StoredKey } from "../wallet-core";
1
+ import { WalletCore, CoinType, PrivateKey, StoredKey, StoredKeyEncryption } from "../wallet-core";
2
2
  import * as Types from "./types";
3
3
  export declare class Default implements Types.IKeyStore {
4
4
  private readonly core;
@@ -11,8 +11,8 @@ export declare class Default implements Types.IKeyStore {
11
11
  mapWallet(storedKey: StoredKey): Types.Wallet;
12
12
  mapStoredKey(wallet: Types.Wallet): StoredKey;
13
13
  importWallet(wallet: Types.Wallet): Promise<void>;
14
- import(mnemonic: string, name: string, password: string, coins: CoinType[]): Promise<Types.Wallet>;
15
- importKey(key: Uint8Array, name: string, password: string, coin: CoinType): Promise<Types.Wallet>;
14
+ import(mnemonic: string, name: string, password: string, coins: CoinType[], encryption: StoredKeyEncryption): Promise<Types.Wallet>;
15
+ importKey(key: Uint8Array, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Types.Wallet>;
16
16
  addAccounts(id: string, password: string, coins: CoinType[]): Promise<Types.Wallet>;
17
17
  getKey(id: string, password: string, account: Types.ActiveAccount): Promise<PrivateKey>;
18
18
  export(id: string, password: string): Promise<string | Uint8Array>;
@@ -38,15 +38,15 @@ var Default = /** @class */ (function () {
38
38
  Default.prototype.importWallet = function (wallet) {
39
39
  return this.storage.set(wallet.id, wallet);
40
40
  };
41
- Default.prototype.import = function (mnemonic, name, password, coins) {
41
+ Default.prototype.import = function (mnemonic, name, password, coins, encryption) {
42
42
  var _this = this;
43
43
  return new Promise(function (resolve, reject) {
44
- var _a = _this.core, Mnemonic = _a.Mnemonic, StoredKey = _a.StoredKey, HDWallet = _a.HDWallet;
44
+ var _a = _this.core, Mnemonic = _a.Mnemonic, StoredKey = _a.StoredKey, HDWallet = _a.HDWallet, StoredKeyEncryption = _a.StoredKeyEncryption;
45
45
  if (!Mnemonic.isValid(mnemonic)) {
46
46
  throw Types.Error.InvalidMnemonic;
47
47
  }
48
48
  var pass = Buffer.from(password);
49
- var storedKey = StoredKey.importHDWallet(mnemonic, name, pass, coins[0]);
49
+ var storedKey = StoredKey.importHDWalletWithEncryption(mnemonic, name, pass, coins[0], encryption);
50
50
  var hdWallet = HDWallet.createWithMnemonic(mnemonic, "");
51
51
  coins.forEach(function (coin) {
52
52
  storedKey.accountForCoin(coin, hdWallet);
@@ -59,17 +59,17 @@ var Default = /** @class */ (function () {
59
59
  .catch(function (error) { return reject(error); });
60
60
  });
61
61
  };
62
- Default.prototype.importKey = function (key, name, password, coin) {
62
+ Default.prototype.importKey = function (key, name, password, coin, encryption) {
63
63
  var _this = this;
64
64
  return new Promise(function (resolve, reject) {
65
- var _a = _this.core, StoredKey = _a.StoredKey, PrivateKey = _a.PrivateKey, Curve = _a.Curve;
65
+ var _a = _this.core, StoredKey = _a.StoredKey, PrivateKey = _a.PrivateKey, Curve = _a.Curve, StoredKeyEncryption = _a.StoredKeyEncryption;
66
66
  // FIXME: get curve from coin
67
67
  if (!PrivateKey.isValid(key, Curve.secp256k1) ||
68
68
  !PrivateKey.isValid(key, Curve.ed25519)) {
69
69
  throw Types.Error.InvalidKey;
70
70
  }
71
71
  var pass = Buffer.from(password);
72
- var storedKey = StoredKey.importPrivateKey(key, name, pass, coin);
72
+ var storedKey = StoredKey.importPrivateKeyWithEncryption(key, name, pass, coin, encryption);
73
73
  var wallet = _this.mapWallet(storedKey);
74
74
  storedKey.delete();
75
75
  _this.importWallet(wallet)
@@ -1,4 +1,4 @@
1
- import { CoinType, PrivateKey } from "../wallet-core";
1
+ import { CoinType, PrivateKey, StoredKeyEncryption } from "../wallet-core";
2
2
  export declare enum WalletType {
3
3
  Mnemonic = "mnemonic",
4
4
  PrivateKey = "privateKey",
@@ -31,8 +31,8 @@ export interface IKeyStore {
31
31
  hasWallet(id: string): Promise<boolean>;
32
32
  load(id: string): Promise<Wallet>;
33
33
  loadAll(): Promise<Wallet[]>;
34
- import(mnemonic: string, name: string, password: string, coins: CoinType[]): Promise<Wallet>;
35
- importKey(key: Uint8Array, name: string, password: string, coin: CoinType): Promise<Wallet>;
34
+ import(mnemonic: string, name: string, password: string, coins: CoinType[], encryption: StoredKeyEncryption): Promise<Wallet>;
35
+ importKey(key: Uint8Array, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Wallet>;
36
36
  importWallet(wallet: Wallet): Promise<void>;
37
37
  addAccounts(id: string, password: string, coins: CoinType[]): Promise<Wallet>;
38
38
  getKey(id: string, password: string, account: ActiveAccount): Promise<PrivateKey>;