格式化代码
This commit is contained in:
parent
218ec2ec2e
commit
a510c92155
329
src/index.ts
329
src/index.ts
@ -1,34 +1,51 @@
|
|||||||
|
|
||||||
import { singleton } from "./decorator/singleton.decorator";
|
import { singleton } from "./decorator/singleton.decorator";
|
||||||
import Web3 from 'web3';
|
import Web3 from "web3";
|
||||||
import { recoverTypedSignature, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
|
import {
|
||||||
import 'whatwg-fetch'
|
recoverTypedSignature,
|
||||||
|
signTypedData,
|
||||||
|
SignTypedDataVersion,
|
||||||
|
} from "@metamask/eth-sig-util";
|
||||||
|
import "whatwg-fetch";
|
||||||
import { AllChains } from "./data/allchain";
|
import { AllChains } from "./data/allchain";
|
||||||
import { createWalletEvents, WALLET_ACCOUNT_CHANGE, WALLET_CHAIN_CHANGE, WALLET_TOKEN_TYPE_CHANGE } from "./common/WalletEvent";
|
import {
|
||||||
|
createWalletEvents,
|
||||||
|
WALLET_ACCOUNT_CHANGE,
|
||||||
|
WALLET_CHAIN_CHANGE,
|
||||||
|
WALLET_TOKEN_TYPE_CHANGE,
|
||||||
|
} from "./common/WalletEvent";
|
||||||
import { ERC20Standard } from "./standards/ERC20Standard";
|
import { ERC20Standard } from "./standards/ERC20Standard";
|
||||||
import { ERC721Standard } from "./standards/ERC721Standard";
|
import { ERC721Standard } from "./standards/ERC721Standard";
|
||||||
import { IAccount, initAccount } from "./data/DataModel";
|
import { IAccount, initAccount } from "./data/DataModel";
|
||||||
import { loadData, saveData } from "./manage/DataManage";
|
import {
|
||||||
|
checkPassword,
|
||||||
|
loadData,
|
||||||
|
saveData,
|
||||||
|
savePassword,
|
||||||
|
} from "./manage/DataManage";
|
||||||
import { WALLET_STORAGE_KEY_NAME } from "./config/constants";
|
import { WALLET_STORAGE_KEY_NAME } from "./config/constants";
|
||||||
import { DEFALUT_TOKENS } from "./config/chain_config";
|
import { DEFALUT_TOKENS } from "./config/chain_config";
|
||||||
import { newAccount, newMnemonic, restoreWalletByMnemonic } from "./manage/WalletManage";
|
import {
|
||||||
|
newAccount,
|
||||||
|
newMnemonic,
|
||||||
|
restoreWalletByMnemonic,
|
||||||
|
} from "./manage/WalletManage";
|
||||||
import { signLogin } from "./util/sign.util";
|
import { signLogin } from "./util/sign.util";
|
||||||
|
|
||||||
|
|
||||||
var global =
|
var global =
|
||||||
(typeof globalThis !== 'undefined' && globalThis) ||
|
(typeof globalThis !== "undefined" && globalThis) ||
|
||||||
(typeof self !== 'undefined' && self) ||
|
(typeof self !== "undefined" && self) ||
|
||||||
(typeof global !== 'undefined' && global) ||
|
(typeof global !== "undefined" && global) ||
|
||||||
{}
|
{};
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
jc: {
|
jc: {
|
||||||
wallet: JCWallet;
|
wallet: JCWallet;
|
||||||
},
|
};
|
||||||
ethSigUtil: any,
|
jcwallet: JCWallet;
|
||||||
cc: any
|
ethSigUtil: any;
|
||||||
Stream: any
|
cc: any;
|
||||||
}
|
Stream: any;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// window.Buffer = require('buffer').Buffer;
|
// window.Buffer = require('buffer').Buffer;
|
||||||
@ -36,118 +53,119 @@ declare global {
|
|||||||
// window.Stream = require('stream-browserify');
|
// window.Stream = require('stream-browserify');
|
||||||
|
|
||||||
export interface IChainData {
|
export interface IChainData {
|
||||||
name: string,
|
name: string;
|
||||||
type: string,
|
type: string;
|
||||||
rpc: string,
|
rpc: string;
|
||||||
id: number,
|
id: number;
|
||||||
symbol: string,
|
symbol: string;
|
||||||
explorerurl: string
|
explorerurl: string;
|
||||||
}
|
}
|
||||||
@singleton
|
@singleton
|
||||||
export default class JCWallet {
|
export default class JCWallet {
|
||||||
web3: Web3 = null
|
web3: Web3 = null;
|
||||||
private wallet: any = null
|
private wallet: any = null;
|
||||||
private password: string = '111111'
|
private password: string = "111111";
|
||||||
private chainSet: Set<number> = new Set()
|
private chainSet: Set<number> = new Set();
|
||||||
private chainMap: Map<number, IChainData> = new Map()
|
private chainMap: Map<number, IChainData> = new Map();
|
||||||
private _currentChain: IChainData
|
private _currentChain: IChainData;
|
||||||
public erc20Standard: ERC20Standard
|
public erc20Standard: ERC20Standard;
|
||||||
public erc721Standard: ERC721Standard
|
public erc721Standard: ERC721Standard;
|
||||||
public mainHandlers = createWalletEvents()
|
public mainHandlers = createWalletEvents();
|
||||||
public data: IAccount[] = []
|
public data: IAccount[] = [];
|
||||||
public iconType = 'jazz'
|
public iconType = "jazz";
|
||||||
private accountIndex = 0
|
private accountIndex = 0;
|
||||||
|
|
||||||
constructor() {
|
constructor(password: string) {
|
||||||
// this.web3 = new Web3('https://rpc-mainnet.kcc.network')
|
// this.web3 = new Web3('https://rpc-mainnet.kcc.network')
|
||||||
|
if (!password) {
|
||||||
|
throw new Error("need password");
|
||||||
|
}
|
||||||
|
if (!checkPassword(password)) {
|
||||||
|
throw new Error("password error");
|
||||||
|
}
|
||||||
|
this.password = password;
|
||||||
|
savePassword(password);
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
this.web3 = new Web3('https://rpc-testnet.kcc.network')
|
this.web3 = new Web3("https://rpc-testnet.kcc.network");
|
||||||
console.log(`init web3 cost: ${(Date.now() - start)/ 1000}`)
|
console.log(`init web3 cost: ${(Date.now() - start) / 1000}`);
|
||||||
this.erc20Standard = new ERC20Standard(this.web3);
|
this.erc20Standard = new ERC20Standard(this.web3);
|
||||||
this.erc721Standard = new ERC721Standard(this.web3);
|
this.erc721Standard = new ERC721Standard(this.web3);
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
this.wallet = this.web3.eth.accounts.wallet.load(this.password, WALLET_STORAGE_KEY_NAME)
|
this.wallet = this.web3.eth.accounts.wallet.load(
|
||||||
console.log(`load wallet cost: ${(Date.now() - start)/ 1000}`)
|
this.password,
|
||||||
start = Date.now()
|
WALLET_STORAGE_KEY_NAME
|
||||||
this.data = loadData()
|
);
|
||||||
console.log(`init wallet ext data cost: ${(Date.now() - start)/ 1000}`)
|
console.log(`load wallet cost: ${(Date.now() - start) / 1000}`);
|
||||||
|
start = Date.now();
|
||||||
|
this.data = loadData();
|
||||||
|
console.log(`init wallet ext data cost: ${(Date.now() - start) / 1000}`);
|
||||||
window.jc = { wallet: this };
|
window.jc = { wallet: this };
|
||||||
window.cc = window.cc || {};
|
// window.cc = window.cc || {};
|
||||||
window.cc.walletCallback = (dataStr: string) => {
|
// window.cc.walletCallback = (dataStr: string) => {
|
||||||
console.log('[Native CB]::' + dataStr)
|
// console.log('[Native CB]::' + dataStr)
|
||||||
}
|
// }
|
||||||
this.init({chains: [322, 97]})
|
this.init({ chains: [322, 97], password });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public init({ chains, password }: { chains: number[]; password: string }) {
|
||||||
public init({chains}: {chains: number[]}) {
|
|
||||||
for (let chain of chains) {
|
for (let chain of chains) {
|
||||||
this.chainSet.add(chain)
|
this.chainSet.add(chain);
|
||||||
if (!this.chainMap.has(chain)) {
|
if (!this.chainMap.has(chain)) {
|
||||||
let data = AllChains.find(o => o.id === chain)
|
let data = AllChains.find((o) => o.id === chain);
|
||||||
if (data) {
|
if (data) {
|
||||||
this.chainMap.set(chain, data);
|
this.chainMap.set(chain, data);
|
||||||
if (!this._currentChain) {
|
if (!this._currentChain) {
|
||||||
this._currentChain = data
|
this._currentChain = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.wallet || this.wallet.length === 0) {
|
if (!this.wallet || this.wallet.length === 0) {
|
||||||
// this.createAccount();
|
// this.createAccount();
|
||||||
this.newWallet('111111');
|
this.newWallet(password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public newWallet(password: string) {
|
public newWallet(password: string) {
|
||||||
this.password = password
|
this.password = password;
|
||||||
newMnemonic(this.password)
|
newMnemonic(this.password);
|
||||||
this.createAccount()
|
this.createAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public restoreFromMnemonic(mnemonic: string, password: string) {
|
public restoreFromMnemonic(mnemonic: string, password: string) {
|
||||||
this.password = password
|
this.password = password;
|
||||||
this.wallet.clear()
|
this.wallet.clear();
|
||||||
restoreWalletByMnemonic(mnemonic, this.password);
|
restoreWalletByMnemonic(mnemonic, this.password);
|
||||||
this.createAccount()
|
this.createAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentChain() {
|
get currentChain() {
|
||||||
return this._currentChain
|
return this._currentChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurrentChain(chainId: number) {
|
updateCurrentChain(chainId: number) {
|
||||||
const chainData = this.chainMap.get(chainId)
|
const chainData = this.chainMap.get(chainId);
|
||||||
this._currentChain = chainData
|
this._currentChain = chainData;
|
||||||
this.web3.eth.setProvider(chainData.rpc)
|
this.web3.eth.setProvider(chainData.rpc);
|
||||||
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData)
|
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData);
|
||||||
this.updateListType('tokens')
|
this.updateListType("tokens");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateListType(type: string) {
|
updateListType(type: string) {
|
||||||
this.mainHandlers.emit(WALLET_TOKEN_TYPE_CHANGE, type)
|
this.mainHandlers.emit(WALLET_TOKEN_TYPE_CHANGE, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
get chainList() {
|
get chainList() {
|
||||||
return [...this.chainMap.values()]
|
return [...this.chainMap.values()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveLocal() {
|
public saveLocal() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public loadLocal() {
|
public loadLocal() {}
|
||||||
|
|
||||||
}
|
public saveRemote() {}
|
||||||
|
|
||||||
public saveRemove() {
|
|
||||||
|
|
||||||
}
|
public loadRemote() {}
|
||||||
|
|
||||||
public loadRemote() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public currentAccount() {
|
public currentAccount() {
|
||||||
return this.wallet[this.accountIndex];
|
return this.wallet[this.accountIndex];
|
||||||
@ -155,77 +173,77 @@ export default class JCWallet {
|
|||||||
|
|
||||||
get currentAccountData() {
|
get currentAccountData() {
|
||||||
let address = this.currentAccount().address;
|
let address = this.currentAccount().address;
|
||||||
const chain = this.currentChain.id
|
const chain = this.currentChain.id;
|
||||||
let data = this.data.find(o => o.address === address)
|
let data = this.data.find((o) => o.address === address);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw new Error('account data not found');
|
throw new Error("account data not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.tokenData[chain]) {
|
if (!data.tokenData[chain]) {
|
||||||
let tokens = DEFALUT_TOKENS[chain]
|
let tokens = DEFALUT_TOKENS[chain];
|
||||||
data.tokenData[chain] = {
|
data.tokenData[chain] = {
|
||||||
tokens,
|
tokens,
|
||||||
heros: [],
|
heros: [],
|
||||||
weapons: [],
|
weapons: [],
|
||||||
chips: []
|
chips: [],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
saveData(this.data)
|
saveData(this.data);
|
||||||
return data
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
get accounts() {
|
get accounts() {
|
||||||
return this.data
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createAccount() {
|
public createAccount() {
|
||||||
// let account = this.web3.eth.accounts.create()
|
// let account = this.web3.eth.accounts.create()
|
||||||
const index = this.getMaxIdexOfType(0);
|
const index = this.getMaxIdexOfType(0);
|
||||||
const accountNew = newAccount(this.password, index)
|
const accountNew = newAccount(this.password, index);
|
||||||
const account = this.wallet.add(accountNew)
|
const account = this.wallet.add(accountNew);
|
||||||
this.wallet.save(this.password, WALLET_STORAGE_KEY_NAME)
|
this.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
||||||
const chain = this.currentChain.id
|
const chain = this.currentChain.id;
|
||||||
let data = this.data.find(o => o.address === account.address)
|
let data = this.data.find((o) => o.address === account.address);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
const nickname = `Account ${ index + 1 }`
|
const nickname = `Account ${index + 1}`;
|
||||||
data = initAccount({
|
data = initAccount({
|
||||||
address: account.address,
|
address: account.address,
|
||||||
chain,
|
chain,
|
||||||
nickname,
|
nickname,
|
||||||
type: 0,
|
type: 0,
|
||||||
index
|
index,
|
||||||
})
|
});
|
||||||
this.data.push(data);
|
this.data.push(data);
|
||||||
saveData(this.data)
|
saveData(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.accountIndex = this.wallet.length - 1
|
this.accountIndex = this.wallet.length - 1;
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address)
|
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address);
|
||||||
return account.address
|
return account.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public importAccount(privateKey: string) {
|
public importAccount(privateKey: string) {
|
||||||
const account = this.wallet.add(privateKey);
|
const account = this.wallet.add(privateKey);
|
||||||
const chain = this.currentChain.id
|
const chain = this.currentChain.id;
|
||||||
let data = this.data.find(o => o.address === account.address)
|
let data = this.data.find((o) => o.address === account.address);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
const index = this.getMaxIdexOfType(1);
|
const index = this.getMaxIdexOfType(1);
|
||||||
const nickname = `Imported ${ index + 1 }`
|
const nickname = `Imported ${index + 1}`;
|
||||||
data = initAccount({
|
data = initAccount({
|
||||||
address: account.address,
|
address: account.address,
|
||||||
chain,
|
chain,
|
||||||
nickname,
|
nickname,
|
||||||
type: 1,
|
type: 1,
|
||||||
index
|
index,
|
||||||
})
|
});
|
||||||
this.data.push(data);
|
this.data.push(data);
|
||||||
saveData(this.data)
|
saveData(this.data);
|
||||||
}
|
}
|
||||||
this.web3.eth.accounts.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
this.web3.eth.accounts.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
||||||
this.accountIndex = this.wallet.length - 1
|
this.accountIndex = this.wallet.length - 1;
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address)
|
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, account.address);
|
||||||
return account.address
|
return account.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMaxIdexOfType(type: number) {
|
private getMaxIdexOfType(type: number) {
|
||||||
@ -236,74 +254,77 @@ export default class JCWallet {
|
|||||||
}
|
}
|
||||||
maxIdx = Math.max(this.data[i].index, maxIdx);
|
maxIdx = Math.max(this.data[i].index, maxIdx);
|
||||||
}
|
}
|
||||||
return maxIdx + 1
|
return maxIdx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public selectAccount(address: string) {
|
public selectAccount(address: string) {
|
||||||
let index = 0
|
let index = 0;
|
||||||
for (let i = 0, l = this.wallet.length; i < l ; i ++) {
|
for (let i = 0, l = this.wallet.length; i < l; i++) {
|
||||||
if (this.wallet[i].address === address) {
|
if (this.wallet[i].address === address) {
|
||||||
index = i
|
index = i;
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index !== this.accountIndex && index < this.wallet.length) {
|
if (index !== this.accountIndex && index < this.wallet.length) {
|
||||||
this.accountIndex = index
|
this.accountIndex = index;
|
||||||
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, this.wallet[index].address)
|
this.mainHandlers.emit(WALLET_ACCOUNT_CHANGE, this.wallet[index].address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendEth(to: string, amount: number | string) {
|
public async sendEth(to: string, amount: number | string) {
|
||||||
let from = this.currentAccount().address;
|
let from = this.currentAccount().address;
|
||||||
const amountToSend = this.web3.utils.toWei(amount+'', "ether");
|
const amountToSend = this.web3.utils.toWei(amount + "", "ether");
|
||||||
let gas = await this.web3.eth.estimateGas({ from, to, value: amountToSend })
|
let gas = await this.web3.eth.estimateGas({
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
value: amountToSend,
|
||||||
|
});
|
||||||
this.web3.eth.sendTransaction({ from, to, gas, value: amountToSend });
|
this.web3.eth.sendTransaction({ from, to, gas, value: amountToSend });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getBalance(address?: string) {
|
public async getBalance(address?: string) {
|
||||||
console.log('get balance with address: ', address);
|
console.log("get balance with address: ", address);
|
||||||
if (!address) {
|
if (!address) {
|
||||||
let accountData = this.wallet[this.accountIndex]
|
let accountData = this.wallet[this.accountIndex];
|
||||||
if (!accountData) {
|
if (!accountData) {
|
||||||
throw new Error('no account found')
|
throw new Error("no account found");
|
||||||
}
|
}
|
||||||
address = accountData.address
|
address = accountData.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
let balance = await this.web3.eth.getBalance(address);
|
let balance = await this.web3.eth.getBalance(address);
|
||||||
return balance
|
return balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public signTypedDataV4(signObj: any) {
|
public signTypedDataV4(signObj: any) {
|
||||||
const account = this.currentAccount()
|
const account = this.currentAccount();
|
||||||
return signTypedData({
|
return signTypedData({
|
||||||
data: signObj,
|
data: signObj,
|
||||||
privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'),
|
privateKey: Buffer.from(account.privateKey.replace("0x", ""), "hex"),
|
||||||
version: SignTypedDataVersion.V4
|
version: SignTypedDataVersion.V4,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public loginSign(nonce: string, tips: string) {
|
public loginSign(nonce: string, tips: string) {
|
||||||
const account = this.currentAccount();
|
const account = this.currentAccount();
|
||||||
return signLogin(nonce, tips, account.privateKey)
|
return signLogin(nonce, tips, account.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public recoverTypedSignatureV4(signObj: any, signature: string) {
|
public recoverTypedSignatureV4(signObj: any, signature: string) {
|
||||||
return recoverTypedSignature({
|
return recoverTypedSignature({
|
||||||
data: signObj,
|
data: signObj,
|
||||||
signature,
|
signature,
|
||||||
version: SignTypedDataVersion.V4
|
version: SignTypedDataVersion.V4,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// window.jc = window.jc || {wallet: new JCWallet()};
|
// window.jc = window.jc || {wallet: new JCWallet()};
|
||||||
|
|
||||||
export * from './common/WalletEvent'
|
export * from "./common/WalletEvent";
|
||||||
export * from './common/ZError'
|
export * from "./common/ZError";
|
||||||
export * from './config/chain_config'
|
export * from "./config/chain_config";
|
||||||
export * from './util/number.util'
|
export * from "./util/number.util";
|
||||||
export * from './util/wallet.util'
|
export * from "./util/wallet.util";
|
||||||
export * from "./data/DataModel";
|
export * from "./data/DataModel";
|
||||||
export * from './config/chain_config';
|
export * from "./config/chain_config";
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import { IAccount } from "../data/DataModel";
|
import { IAccount } from "../data/DataModel";
|
||||||
import { aesDecrypt, aesEncrypt } from "../util/crypto.util";
|
import { aesDecrypt, aesEncrypt } from "../util/crypto.util";
|
||||||
|
import sha256 from 'crypto-js/sha256'
|
||||||
|
|
||||||
const LOCAL_ACCOUNT_DATAS = 'local_account_datas'
|
const LOCAL_ACCOUNT_DATAS = 'local_account_datas'
|
||||||
const LOCAL_WALLET_MNEMONIC = 'local_wallet_mnemonic'
|
const LOCAL_WALLET_MNEMONIC = 'local_wallet_mnemonic'
|
||||||
|
const LOCAL_WALLET_PASSWORD = 'local_wallet_password';
|
||||||
|
const LOCAL_PASSWORD_SALT = '_jcwallet';
|
||||||
|
|
||||||
|
|
||||||
export function loadData(){
|
export function loadData(){
|
||||||
@ -31,9 +34,18 @@ export function loadMnemonic(password: string) {
|
|||||||
return dataStr
|
return dataStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function saveMnemonic(mnemonic: string, password: string) {
|
export function saveMnemonic(mnemonic: string, password: string) {
|
||||||
const dataStr = aesEncrypt(mnemonic, password);
|
const dataStr = aesEncrypt(mnemonic, password);
|
||||||
localStorage.setItem(LOCAL_WALLET_MNEMONIC, dataStr);
|
localStorage.setItem(LOCAL_WALLET_MNEMONIC, dataStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkPassword(password: string) {
|
||||||
|
const localStr: string = localStorage.getItem(LOCAL_WALLET_PASSWORD);
|
||||||
|
const dataStr = sha256(password + LOCAL_PASSWORD_SALT).toString();
|
||||||
|
return !localStr || localStr === dataStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function savePassword(password: string) {
|
||||||
|
const dataStr = sha256(password + LOCAL_PASSWORD_SALT).toString();
|
||||||
|
localStorage.setItem(LOCAL_WALLET_PASSWORD, dataStr);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user