@trustwallet/wallet-core 3.1.0 → 3.1.1

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>;
@@ -255,6 +255,13 @@ export class SS58AddressType {
255
255
  static polkadot: SS58AddressType;
256
256
  static kusama: SS58AddressType;
257
257
  }
258
+ export class StoredKeyEncryption {
259
+ value: number;
260
+ static aes128Ctr: StoredKeyEncryption;
261
+ static aes128Cbc: StoredKeyEncryption;
262
+ static aes192Ctr: StoredKeyEncryption;
263
+ static aes256Ctr: StoredKeyEncryption;
264
+ }
258
265
  export class Base64 {
259
266
  static decode(string: string): Uint8Array;
260
267
  static decodeUrl(string: string): Uint8Array;
@@ -599,10 +606,14 @@ export class BitcoinMessageSigner {
599
606
  export class StoredKey {
600
607
  static load(path: string): StoredKey;
601
608
  static importPrivateKey(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
609
+ static importPrivateKeyWithEncryption(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
602
610
  static importHDWallet(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
611
+ static importHDWalletWithEncryption(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
603
612
  static importJSON(json: Uint8Array | Buffer): StoredKey;
604
613
  static createLevel(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel): StoredKey;
614
+ static createLevelAndEncryption(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel, encryption: StoredKeyEncryption): StoredKey;
605
615
  static create(name: string, password: Uint8Array | Buffer): StoredKey;
616
+ static createEncryption(name: string, password: Uint8Array | Buffer, encryption: StoredKeyEncryption): StoredKey;
606
617
  identifier(): string;
607
618
  name(): string;
608
619
  isMnemonic(): boolean;
@@ -748,6 +759,7 @@ export interface WalletCore {
748
759
  NEARAccount: typeof NEARAccount;
749
760
  Base58: typeof Base58;
750
761
  SS58AddressType: typeof SS58AddressType;
762
+ StoredKeyEncryption: typeof StoredKeyEncryption;
751
763
  Base64: typeof Base64;
752
764
  HDWallet: typeof HDWallet;
753
765
  SegwitAddress: typeof SegwitAddress;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustwallet/wallet-core",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "wallet core wasm and protobuf models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",