@trustwallet/wallet-core 4.1.7 → 4.1.8-rc1
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.
- package/dist/lib/wallet-core.js +1 -1
- package/dist/lib/wallet-core.wasm +0 -0
- package/dist/src/keystore/default-impl.d.ts +1 -0
- package/dist/src/keystore/default-impl.js +33 -3
- package/dist/src/keystore/types.d.ts +3 -1
- package/dist/src/keystore/types.js +1 -0
- package/dist/src/wallet-core.d.ts +9 -0
- package/package.json +1 -1
package/dist/lib/wallet-core.js
CHANGED
@@ -34,7 +34,7 @@ function Ra(){H++;g.monitorRunDependencies&&g.monitorRunDependencies(H);assert(!
|
|
34
34
|
function Sa(){return K.startsWith("data:application/octet-stream;base64,")}function ma(a){return a.startsWith("file://")}function M(a){return function(){var b=g.asm;assert(Na,"native function `"+a+"` called before runtime initialization");b[a]||assert(b[a],"exported native function `"+a+"` not found");return b[a].apply(null,arguments)}}var K;K="wallet-core.wasm";if(!Sa()){var Ta=K;K=g.locateFile?g.locateFile(Ta,x):x+Ta}
|
35
35
|
function Ua(){var a=K;try{if(a==K&&qa)return new Uint8Array(qa);if(ka)return ka(a);throw"both async and sync fetching of the wasm failed";}catch(b){n(b)}}
|
36
36
|
function Va(){if(!qa&&(ea||fa)){if("function"==typeof fetch&&!ma(K))return fetch(K,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+K+"'";return a.arrayBuffer()}).catch(function(){return Ua()});if(ja)return new Promise(function(a,b){ja(K,function(c){a(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return Ua()})}
|
37
|
-
var Wa,Xa,Ya={
|
37
|
+
var Wa,Xa,Ya={2106900:()=>{if(void 0===g.ea)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.ea=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.ea=a}catch(e){throw"No secure random number generator found";}}},2107622:()=>g.ea()};function Za(a){for(;0<a.length;)a.shift()(g)}
|
38
38
|
function va(a){assert("number"===typeof a);return"0x"+a.toString(16).padStart(8,"0")}function pa(a){$a||($a={});$a[a]||($a[a]=1,v&&(a="warning: "+a),y(a))}var $a;function ab(a){this.l=a-24;this.Na=function(b){G[this.l+4>>2]=b};this.Ia=function(b){G[this.l+8>>2]=b};this.Ja=function(){F[this.l>>2]=0};this.Ea=function(){D[this.l+12>>0]=0};this.Ka=function(){D[this.l+13>>0]=0};this.I=function(b,c){this.Da();this.Na(b);this.Ia(c);this.Ja();this.Ea();this.Ka()};this.Da=function(){G[this.l+16>>2]=0}}
|
39
39
|
var bb=0,cb=(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},db=a=>{var b="/"===a.charAt(0),c="/"===a.substr(-1);(a=cb(a.split("/").filter(d=>!!d),!b).join("/"))||b||(a=".");a&&c&&(a+="/");return(b?"/":"")+a},eb=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},fb=
|
40
40
|
a=>{if("/"===a)return"/";a=db(a);a=a.replace(/\/$/,"");var b=a.lastIndexOf("/");return-1===b?a:a.substr(b+1)};
|
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
|
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) {
|
@@ -886,6 +886,7 @@ export class SolanaAddress {
|
|
886
886
|
static createWithString(string: string): SolanaAddress;
|
887
887
|
description(): string;
|
888
888
|
defaultTokenAddress(tokenMintAddress: string): string;
|
889
|
+
token2022Address(tokenMintAddress: string): string;
|
889
890
|
delete(): void;
|
890
891
|
}
|
891
892
|
export class SolanaTransaction {
|
@@ -927,6 +928,8 @@ export class StoredKey {
|
|
927
928
|
static importPrivateKeyWithEncryption(privateKey: Uint8Array | Buffer, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
|
928
929
|
static importHDWallet(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
|
929
930
|
static importHDWalletWithEncryption(mnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
|
931
|
+
static importTONWallet(tonMnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType): StoredKey;
|
932
|
+
static importTONWalletWithEncryption(tonMnemonic: string, name: string, password: Uint8Array | Buffer, coin: CoinType, encryption: StoredKeyEncryption): StoredKey;
|
930
933
|
static importJSON(json: Uint8Array | Buffer): StoredKey;
|
931
934
|
static createLevel(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel): StoredKey;
|
932
935
|
static createLevelAndEncryption(name: string, password: Uint8Array | Buffer, encryptionLevel: StoredKeyEncryptionLevel, encryption: StoredKeyEncryption): StoredKey;
|
@@ -935,6 +938,7 @@ export class StoredKey {
|
|
935
938
|
identifier(): string;
|
936
939
|
name(): string;
|
937
940
|
isMnemonic(): boolean;
|
941
|
+
isTONMnemonic(): boolean;
|
938
942
|
accountCount(): number;
|
939
943
|
encryptionParameters(): string;
|
940
944
|
account(index: number): Account;
|
@@ -948,6 +952,7 @@ export class StoredKey {
|
|
948
952
|
store(path: string): boolean;
|
949
953
|
decryptPrivateKey(password: Uint8Array | Buffer): Uint8Array;
|
950
954
|
decryptMnemonic(password: Uint8Array | Buffer): string;
|
955
|
+
decryptTONMnemonic(password: Uint8Array | Buffer): string;
|
951
956
|
privateKey(coin: CoinType, password: Uint8Array | Buffer): PrivateKey;
|
952
957
|
wallet(password: Uint8Array | Buffer): HDWallet;
|
953
958
|
exportJSON(): Uint8Array;
|
@@ -981,7 +986,11 @@ export class TONMessageSigner {
|
|
981
986
|
static signMessage(privateKey: PrivateKey, message: string): string;
|
982
987
|
}
|
983
988
|
export class TONWallet {
|
989
|
+
static isValidMnemonic(mnemonic: string, passphrase: string): boolean;
|
984
990
|
static buildV4R2StateInit(publicKey: PublicKey, workchain: number, walletId: number): string;
|
991
|
+
static createWithMnemonic(mnemonic: string, passphrase: string): TONWallet;
|
992
|
+
getKey(): PrivateKey;
|
993
|
+
delete(): void;
|
985
994
|
}
|
986
995
|
export class TezosMessageSigner {
|
987
996
|
static formatMessage(message: string, url: string): string;
|