@trustwallet/wallet-core 4.2.0-dev-rc1 → 4.2.0-dev-rc3

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.
Binary file
@@ -13,6 +13,7 @@ export declare class Default implements Types.IKeyStore {
13
13
  importWallet(wallet: Types.Wallet): Promise<void>;
14
14
  import(mnemonic: string, name: string, password: string, coins: CoinType[], encryption: StoredKeyEncryption): Promise<Types.Wallet>;
15
15
  importKey(key: Uint8Array, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Types.Wallet>;
16
+ importTON(tonMnemonic: string, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Types.Wallet>;
16
17
  addAccounts(id: string, password: string, coins: CoinType[]): Promise<Types.Wallet>;
17
18
  getKey(id: string, password: string, account: Types.ActiveAccount): Promise<PrivateKey>;
18
19
  export(id: string, password: string): Promise<string | Uint8Array>;
@@ -75,6 +75,23 @@ var Default = /** @class */ (function () {
75
75
  .catch(function (error) { return reject(error); });
76
76
  });
77
77
  };
78
+ Default.prototype.importTON = function (tonMnemonic, name, password, coin, encryption) {
79
+ var _this = this;
80
+ return new Promise(function (resolve, reject) {
81
+ var _a = _this.core, StoredKey = _a.StoredKey, TONWallet = _a.TONWallet;
82
+ var passphrase = "";
83
+ if (!TONWallet.isValidMnemonic(tonMnemonic, passphrase)) {
84
+ throw Types.Error.InvalidMnemonic;
85
+ }
86
+ var pass = Buffer.from(password);
87
+ var storedKey = StoredKey.importTONWalletWithEncryption(tonMnemonic, name, pass, coin, encryption);
88
+ var wallet = _this.mapWallet(storedKey);
89
+ storedKey.delete();
90
+ _this.importWallet(wallet)
91
+ .then(function () { return resolve(wallet); })
92
+ .catch(function (error) { return reject(error); });
93
+ });
94
+ };
78
95
  Default.prototype.addAccounts = function (id, password, coins) {
79
96
  var _this = this;
80
97
  return this.load(id).then(function (wallet) {
@@ -93,11 +110,21 @@ var Default = /** @class */ (function () {
93
110
  var _this = this;
94
111
  return this.load(id).then(function (wallet) {
95
112
  var storedKey = _this.mapStoredKey(wallet);
96
- var hdWallet = storedKey.wallet(Buffer.from(password));
97
113
  var coin = _this.core.CoinType.values["" + account.coin];
98
- var privateKey = hdWallet.getKey(coin, account.derivationPath);
114
+ var privateKey;
115
+ switch (wallet.type) {
116
+ // In case of BIP39 mnemonic, we should use the custom derivation path.
117
+ case Types.WalletType.Mnemonic:
118
+ var hdWallet = storedKey.wallet(Buffer.from(password));
119
+ privateKey = hdWallet.getKey(coin, account.derivationPath);
120
+ hdWallet.delete();
121
+ break;
122
+ // Otherwise, use the default implementation.
123
+ default:
124
+ privateKey = storedKey.privateKey(coin, Buffer.from(password));
125
+ break;
126
+ }
99
127
  storedKey.delete();
100
- hdWallet.delete();
101
128
  return privateKey;
102
129
  });
103
130
  };
@@ -113,6 +140,9 @@ var Default = /** @class */ (function () {
113
140
  case Types.WalletType.PrivateKey:
114
141
  value = storedKey.decryptPrivateKey(Buffer.from(password));
115
142
  break;
143
+ case Types.WalletType.TonMnemonic:
144
+ value = storedKey.decryptTONMnemonic(Buffer.from(password));
145
+ break;
116
146
  default:
117
147
  throw Types.Error.InvalidJSON;
118
148
  }
@@ -3,7 +3,8 @@ export declare enum WalletType {
3
3
  Mnemonic = "mnemonic",
4
4
  PrivateKey = "privateKey",
5
5
  WatchOnly = "watchOnly",
6
- Hardware = "hardware"
6
+ Hardware = "hardware",
7
+ TonMnemonic = "ton-mnemonic"
7
8
  }
8
9
  export declare enum Error {
9
10
  WalletNotFound = "wallet not found",
@@ -34,6 +35,7 @@ export interface IKeyStore {
34
35
  import(mnemonic: string, name: string, password: string, coins: CoinType[], encryption: StoredKeyEncryption): Promise<Wallet>;
35
36
  importKey(key: Uint8Array, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Wallet>;
36
37
  importWallet(wallet: Wallet): Promise<void>;
38
+ importTON(tonMnemonic: string, name: string, password: string, coin: CoinType, encryption: StoredKeyEncryption): Promise<Wallet>;
37
39
  addAccounts(id: string, password: string, coins: CoinType[]): Promise<Wallet>;
38
40
  getKey(id: string, password: string, account: ActiveAccount): Promise<PrivateKey>;
39
41
  delete(id: string, password: string): Promise<void>;
@@ -10,6 +10,7 @@ var WalletType;
10
10
  WalletType["PrivateKey"] = "privateKey";
11
11
  WalletType["WatchOnly"] = "watchOnly";
12
12
  WalletType["Hardware"] = "hardware";
13
+ WalletType["TonMnemonic"] = "ton-mnemonic";
13
14
  })(WalletType = exports.WalletType || (exports.WalletType = {}));
14
15
  var Error;
15
16
  (function (Error) {
@@ -115,6 +115,12 @@ export class Base64 {
115
115
  static encode(data: Uint8Array | Buffer): string;
116
116
  static encodeUrl(data: Uint8Array | Buffer): string;
117
117
  }
118
+ export class Bech32 {
119
+ static encode(hrp: string, data: Uint8Array | Buffer): string;
120
+ static decode(string: string): Uint8Array;
121
+ static encodeM(hrp: string, data: Uint8Array | Buffer): string;
122
+ static decodeM(string: string): Uint8Array;
123
+ }
118
124
  export class BitcoinAddress {
119
125
  static equal(lhs: BitcoinAddress, rhs: BitcoinAddress): boolean;
120
126
  static isValid(data: Uint8Array | Buffer): boolean;
@@ -223,6 +229,8 @@ export class Blockchain {
223
229
  static internetComputer: Blockchain;
224
230
  static nativeEvmos: Blockchain;
225
231
  static nativeInjective: Blockchain;
232
+ static bitcoinCash: Blockchain;
233
+ static pactus: Blockchain;
226
234
  }
227
235
  export class Cardano {
228
236
  static minAdaAmount(tokenBundle: Uint8Array | Buffer): number;
@@ -390,6 +398,7 @@ export class CoinType {
390
398
  static blast: CoinType;
391
399
  static bounceBit: CoinType;
392
400
  static zkLinkNova: CoinType;
401
+ static pactus: CoinType;
393
402
  }
394
403
  export class CoinTypeConfiguration {
395
404
  static getSymbol(type: CoinType): string;
@@ -448,6 +457,7 @@ export class Derivation {
448
457
  static litecoinLegacy: Derivation;
449
458
  static solanaSolana: Derivation;
450
459
  static stratisSegwit: Derivation;
460
+ static bitcoinTaproot: Derivation;
451
461
  }
452
462
  export class DerivationPath {
453
463
  static create(purpose: Purpose, coin: number, account: number, change: number, address: number): DerivationPath;
@@ -719,6 +729,7 @@ export class HRP {
719
729
  static harmony: HRP;
720
730
  static cardano: HRP;
721
731
  static qtum: HRP;
732
+ static pactus: HRP;
722
733
  static stratis: HRP;
723
734
  static nativeInjective: HRP;
724
735
  static osmosis: HRP;
@@ -855,6 +866,7 @@ export class Purpose {
855
866
  static bip44: Purpose;
856
867
  static bip49: Purpose;
857
868
  static bip84: Purpose;
869
+ static bip86: Purpose;
858
870
  static bip1852: Purpose;
859
871
  }
860
872
  export class RippleXAddress {
@@ -891,6 +903,10 @@ export class SolanaAddress {
891
903
  }
892
904
  export class SolanaTransaction {
893
905
  static updateBlockhashAndSign(encodedTx: string, recentBlockhash: string, privateKeys: DataVector): Uint8Array;
906
+ static getComputeUnitPrice(encodedTx: string): string;
907
+ static getComputeUnitLimit(encodedTx: string): string;
908
+ static setComputeUnitPrice(encodedTx: string, price: string): string;
909
+ static setComputeUnitLimit(encodedTx: string, limit: string): string;
894
910
  }
895
911
  export class StarkExMessageSigner {
896
912
  static signMessage(privateKey: PrivateKey, message: string): string;
@@ -928,6 +944,8 @@ export class StoredKey {
928
944
  static importPrivateKeyWithEncryption(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
929
945
  static importHDWallet(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
930
946
  static importHDWalletWithEncryption(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
947
+ static importTONWallet(tonMnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
948
+ static importTONWalletWithEncryption(tonMnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
931
949
  static importJSON(json: Uint8Array | Buffer): StoredKey;
932
950
  static createLevel(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel): StoredKey;
933
951
  static createLevelAndEncryption(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel, encryption: StoredKeyEncryption): StoredKey;
@@ -936,6 +954,7 @@ export class StoredKey {
936
954
  identifier(): string;
937
955
  name(): string;
938
956
  isMnemonic(): boolean;
957
+ isTONMnemonic(): boolean;
939
958
  accountCount(): number;
940
959
  encryptionParameters(): string;
941
960
  account(index: number): Account;
@@ -949,6 +968,7 @@ export class StoredKey {
949
968
  store(path: string): boolean;
950
969
  decryptPrivateKey(password: Uint8Array | Buffer): Uint8Array;
951
970
  decryptMnemonic(password: Uint8Array | Buffer): string;
971
+ decryptTONMnemonic(password: Uint8Array | Buffer): string;
952
972
  privateKey(coin: CoinType, password: Uint8Array | Buffer): PrivateKey;
953
973
  wallet(password: Uint8Array | Buffer): HDWallet;
954
974
  exportJSON(): Uint8Array;
@@ -982,7 +1002,11 @@ export class TONMessageSigner {
982
1002
  static signMessage(privateKey: PrivateKey, message: string): string;
983
1003
  }
984
1004
  export class TONWallet {
1005
+ static isValidMnemonic(mnemonic: string, passphrase: string): boolean;
985
1006
  static buildV4R2StateInit(publicKey: PublicKey, workchain: number, walletId: number): string;
1007
+ static createWithMnemonic(mnemonic: string, passphrase: string): TONWallet;
1008
+ getKey(): PrivateKey;
1009
+ delete(): void;
986
1010
  }
987
1011
  export class TezosMessageSigner {
988
1012
  static formatMessage(message: string, url: string): string;
@@ -1028,6 +1052,7 @@ export interface WalletCore {
1028
1052
  Base32: typeof Base32;
1029
1053
  Base58: typeof Base58;
1030
1054
  Base64: typeof Base64;
1055
+ Bech32: typeof Bech32;
1031
1056
  BitcoinAddress: typeof BitcoinAddress;
1032
1057
  BitcoinMessageSigner: typeof BitcoinMessageSigner;
1033
1058
  BitcoinScript: typeof BitcoinScript;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustwallet/wallet-core",
3
- "version": "4.2.0-dev-rc1",
3
+ "version": "4.2.0-dev-rc3",
4
4
  "description": "wallet core wasm and protobuf models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",