@trustwallet/wallet-core 4.2.20 → 4.3.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.
@@ -36,7 +36,7 @@ function $a(a,b){var c=M;return sa||"function"!=typeof WebAssembly.instantiateSt
36
36
  function z(a,b){Object.getOwnPropertyDescriptor(g,a)||Object.defineProperty(g,a,{configurable:!0,get:function(){n("Module."+a+" has been replaced with plain "+b+" (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)")}})}
37
37
  function cb(a){return"FS_createPath"===a||"FS_createDataFile"===a||"FS_createPreloadedFile"===a||"FS_unlink"===a||"addRunDependency"===a||"FS_createLazyFile"===a||"FS_createDevice"===a||"removeRunDependency"===a}(function(a,b){"undefined"!==typeof globalThis&&Object.defineProperty(globalThis,a,{configurable:!0,get:function(){ya("`"+a+"` is not longer defined by emscripten. "+b)}})})("buffer","Please use HEAP8.buffer or wasmMemory.buffer");
38
38
  function db(a){Object.getOwnPropertyDescriptor(g,a)||Object.defineProperty(g,a,{configurable:!0,get:function(){var b="'"+a+"' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";cb(a)&&(b+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you");n(b)}})}
39
- var eb={2181780:()=>{if(void 0===g.fa)try{var a="object"===typeof window?window:self,b="undefined"!==typeof a.crypto?a.crypto:a.msCrypto;a=function(){var d=new Uint32Array(1);b.getRandomValues(d);return d[0]>>>0};a();g.fa=a}catch(d){try{var c=require("crypto");a=function(){var e=c.randomBytes(4);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0};a();g.fa=a}catch(e){throw"No secure random number generator found";}}},2182502:()=>g.fa()};
39
+ var eb={2183348:()=>{if(void 0===g.fa)try{var a="object"===typeof window?window:self,b="undefined"!==typeof a.crypto?a.crypto:a.msCrypto;a=function(){var d=new Uint32Array(1);b.getRandomValues(d);return d[0]>>>0};a();g.fa=a}catch(d){try{var c=require("crypto");a=function(){var e=c.randomBytes(4);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0};a();g.fa=a}catch(e){throw"No secure random number generator found";}}},2184070:()=>g.fa()};
40
40
  function qa(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}function fb(a){for(;0<a.length;)a.shift()(g)}function za(a){assert("number"===typeof a);return"0x"+a.toString(16).padStart(8,"0")}function ya(a){gb||(gb={});gb[a]||(gb[a]=1,w&&(a="warning: "+a),y(a))}var gb,hb=[];function ib(a){var b=hb[a];b||(a>=hb.length&&(hb.length=a+1),hb[a]=b=Ha.get(a));assert(Ha.get(a)==b,"JavaScript-side Wasm function table mirror is out of date!");return b}
41
41
  function jb(a){this.l=a-24;this.Oa=function(b){G[this.l+4>>2]=b};this.Ja=function(b){G[this.l+8>>2]=b};this.Ka=function(){F[this.l>>2]=0};this.Ea=function(){D[this.l+12>>0]=0};this.La=function(){D[this.l+13>>0]=0};this.I=function(b,c){this.Da();this.Oa(b);this.Ja(c);this.Ka();this.Ea();this.La()};this.Da=function(){G[this.l+16>>2]=0}}
42
42
  var kb=0,lb=(a,b)=>{for(var c=0,d=a.length-1;0<=d;d--){var e=a[d];"."===e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c;c--)a.unshift("..");return a},mb=a=>{var b="/"===a.charAt(0),c="/"===a.substr(-1);(a=lb(a.split("/").filter(d=>!!d),!b).join("/"))||b||(a=".");a&&c&&(a+="/");return(b?"/":"")+a},nb=a=>{var b=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(a).slice(1);a=b[0];b=b[1];if(!a&&!b)return".";b&&(b=b.substr(0,b.length-1));return a+b},ob=
Binary file
@@ -13,8 +13,13 @@ 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
+ importKeyEncoded(key: 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
  addAccountsWithDerivations(id: string, password: string, coins: Types.CoinWithDerivation[]): Promise<Types.Wallet>;
18
19
  getKey(id: string, password: string, account: Types.ActiveAccount): Promise<PrivateKey>;
19
20
  export(id: string, password: string): Promise<string | Uint8Array>;
21
+ getWalletType(id: string): Promise<Types.WalletType>;
22
+ exportMnemonic(id: string, password: string): Promise<string>;
23
+ exportPrivateKey(id: string, password: string): Promise<Uint8Array>;
24
+ exportPrivateKeyEncoded(id: string, password: string): Promise<string>;
20
25
  }
@@ -75,6 +75,19 @@ var Default = /** @class */ (function () {
75
75
  .catch(function (error) { return reject(error); });
76
76
  });
77
77
  };
78
+ Default.prototype.importKeyEncoded = function (key, name, password, coin, encryption) {
79
+ var _this = this;
80
+ return new Promise(function (resolve, reject) {
81
+ var _a = _this.core, StoredKey = _a.StoredKey, PrivateKey = _a.PrivateKey, Curve = _a.Curve, StoredKeyEncryption = _a.StoredKeyEncryption;
82
+ var pass = Buffer.from(password);
83
+ var storedKey = StoredKey.importPrivateKeyEncodedWithEncryption(key, name, pass, coin, encryption);
84
+ var wallet = _this.mapWallet(storedKey);
85
+ storedKey.delete();
86
+ _this.importWallet(wallet)
87
+ .then(function () { return resolve(wallet); })
88
+ .catch(function (error) { return reject(error); });
89
+ });
90
+ };
78
91
  Default.prototype.addAccounts = function (id, password, coins) {
79
92
  var Derivation = this.core.Derivation;
80
93
  var coins_with_derivations = coins.map(function (coin) { return ({
@@ -126,6 +139,45 @@ var Default = /** @class */ (function () {
126
139
  return value;
127
140
  });
128
141
  };
142
+ Default.prototype.getWalletType = function (id) {
143
+ return this.load(id).then(function (wallet) { return wallet.type; });
144
+ };
145
+ Default.prototype.exportMnemonic = function (id, password) {
146
+ var _this = this;
147
+ return this.load(id).then(function (wallet) {
148
+ if (wallet.type !== Types.WalletType.Mnemonic) {
149
+ throw Types.Error.UnsupportedWalletType;
150
+ }
151
+ var storedKey = _this.mapStoredKey(wallet);
152
+ var value = storedKey.decryptMnemonic(Buffer.from(password));
153
+ storedKey.delete();
154
+ return value;
155
+ });
156
+ };
157
+ Default.prototype.exportPrivateKey = function (id, password) {
158
+ var _this = this;
159
+ return this.load(id).then(function (wallet) {
160
+ if (wallet.type !== Types.WalletType.PrivateKey) {
161
+ throw Types.Error.UnsupportedWalletType;
162
+ }
163
+ var storedKey = _this.mapStoredKey(wallet);
164
+ var value = storedKey.decryptPrivateKey(Buffer.from(password));
165
+ storedKey.delete();
166
+ return value;
167
+ });
168
+ };
169
+ Default.prototype.exportPrivateKeyEncoded = function (id, password) {
170
+ var _this = this;
171
+ return this.load(id).then(function (wallet) {
172
+ if (wallet.type !== Types.WalletType.PrivateKey) {
173
+ throw Types.Error.UnsupportedWalletType;
174
+ }
175
+ var storedKey = _this.mapStoredKey(wallet);
176
+ var value = storedKey.decryptPrivateKeyEncoded(Buffer.from(password));
177
+ storedKey.delete();
178
+ return value;
179
+ });
180
+ };
129
181
  return Default;
130
182
  }());
131
183
  exports.Default = Default;
@@ -11,7 +11,8 @@ export declare enum Error {
11
11
  InvalidPassword = "invalid password",
12
12
  InvalidMnemonic = "invalid mnemonic",
13
13
  InvalidJSON = "invalid JSON",
14
- InvalidKey = "invalid key"
14
+ InvalidKey = "invalid key",
15
+ UnsupportedWalletType = "unsupported wallet type"
15
16
  }
16
17
  export interface ActiveAccount {
17
18
  address: string;
@@ -19,4 +19,5 @@ var Error;
19
19
  Error["InvalidMnemonic"] = "invalid mnemonic";
20
20
  Error["InvalidJSON"] = "invalid JSON";
21
21
  Error["InvalidKey"] = "invalid key";
22
+ Error["UnsupportedWalletType"] = "unsupported wallet type";
22
23
  })(Error = exports.Error || (exports.Error = {}));
@@ -466,6 +466,8 @@ export class Derivation {
466
466
  static solanaSolana: Derivation;
467
467
  static stratisSegwit: Derivation;
468
468
  static bitcoinTaproot: Derivation;
469
+ static pactusMainnet: Derivation;
470
+ static pactusTestnet: Derivation;
469
471
  }
470
472
  export class DerivationPath {
471
473
  static create(purpose: Purpose, coin: number, account: number, change: number, address: number): DerivationPath;
@@ -944,6 +946,8 @@ export class StoredKey {
944
946
  static load(path: string): StoredKey;
945
947
  static importPrivateKey(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
946
948
  static importPrivateKeyWithEncryption(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
949
+ static importPrivateKeyEncoded(privateKey: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
950
+ static importPrivateKeyEncodedWithEncryption(privateKey: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
947
951
  static importHDWallet(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
948
952
  static importHDWalletWithEncryption(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
949
953
  static importJSON(json: Uint8Array | Buffer): StoredKey;
@@ -955,6 +959,7 @@ export class StoredKey {
955
959
  name(): string;
956
960
  isMnemonic(): boolean;
957
961
  accountCount(): number;
962
+ hasPrivateKeyEncoded(): boolean;
958
963
  encryptionParameters(): string;
959
964
  account(index: number): Account;
960
965
  accountForCoin(coin: CoinType, wallet: HDWallet): Account;
@@ -966,6 +971,7 @@ export class StoredKey {
966
971
  removeAccountForCoinDerivationPath(coin: CoinType, derivationPath: string): void;
967
972
  store(path: string): boolean;
968
973
  decryptPrivateKey(password: Uint8Array | Buffer): Uint8Array;
974
+ decryptPrivateKeyEncoded(password: Uint8Array | Buffer): string;
969
975
  decryptMnemonic(password: Uint8Array | Buffer): string;
970
976
  privateKey(coin: CoinType, password: Uint8Array | Buffer): PrivateKey;
971
977
  wallet(password: Uint8Array | Buffer): HDWallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustwallet/wallet-core",
3
- "version": "4.2.20",
3
+ "version": "4.3.0",
4
4
  "description": "wallet core wasm and protobuf models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",