增加本地网络配置
This commit is contained in:
parent
c32e60076a
commit
c83682e16e
18
README.md
18
README.md
@ -24,4 +24,20 @@
|
||||
|
||||
4. JazzIcon的hashicon
|
||||
|
||||
5. 使用WalletConnect与第三方钱包交互
|
||||
5. 使用WalletConnect与第三方钱包交互
|
||||
|
||||
## 第三方包的修改
|
||||
|
||||
```
|
||||
// 理论上npm install时候会根据patches里的更改,自动修改第三方包
|
||||
// 如果没有的话, 就运行如下命令
|
||||
npm run postinstall
|
||||
|
||||
// 签名方法的修改
|
||||
web3.eth.signTransaction
|
||||
@ethereumjs/tx/node_modules/ethereumjs-util/dist.browser/signature.js的ecsign方法
|
||||
|
||||
@metamask/eth-sig-util/signTypedData
|
||||
@metamask/eth-sig-util/node_modules/ethereumjs-util/dist/signature.js的ecsign方法
|
||||
|
||||
```
|
@ -73,6 +73,26 @@ export const DEFALUT_TOKENS = {
|
||||
decimal: 18,
|
||||
},
|
||||
],
|
||||
1338: [
|
||||
{
|
||||
type: "eth",
|
||||
address: "eth",
|
||||
symbol: "ETH",
|
||||
decimal: 18,
|
||||
},
|
||||
{
|
||||
type: "erc20",
|
||||
address: "0x4d46f75Be6E98dBA8E8384802a68d550DeB69770",
|
||||
symbol: "CEC",
|
||||
decimal: 18,
|
||||
},
|
||||
{
|
||||
type: "erc20",
|
||||
address: "0xb3212b66C337F83D277172D891Daf31776FF9D79",
|
||||
symbol: "CEG",
|
||||
decimal: 18,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const DEFAULT_NFT_TYPES = {
|
||||
@ -148,6 +168,24 @@ export const DEFAULT_NFT_TYPES = {
|
||||
type: "erc1155",
|
||||
},
|
||||
},
|
||||
1338: {
|
||||
hero: {
|
||||
address: "0xCd36bFD6f5c9685A5b1DD953E8279eeC7d41e1E1",
|
||||
type: "erc721",
|
||||
},
|
||||
weapon: {
|
||||
address: "0xf1486cC376555A5035cFa85A761279c9876Daddc",
|
||||
type: "erc721",
|
||||
},
|
||||
chip: {
|
||||
address: "0xc56a7B89639738382abF20E1829d1ff1a4e21e33",
|
||||
type: "erc1155",
|
||||
},
|
||||
shard: {
|
||||
address: "0x8BaA4d31B46a272b5a90F192Dcf20348E1845719",
|
||||
type: "erc1155",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const JC_CONTRACTS = {
|
||||
@ -171,4 +209,9 @@ export const JC_CONTRACTS = {
|
||||
evolveFactory: "0x07Bad070e403a4Bad2Eec3BA3894c4524d3d2674",
|
||||
minterFactory: "0x5ecEFA2707e3f09B9A169ae696B36Df8dB7410ED",
|
||||
},
|
||||
1338: {
|
||||
nftMall: "0x68731C006E8a7Fa45c6eAb579f8F7507b10f5571",
|
||||
evolveFactory: "0xa390Fa8d4F032cCfCeC1CFF34f2eb549928DcEad",
|
||||
minterFactory: "0x0DB24A927FFC3622884B7A3B6f1C694ED8092A01",
|
||||
},
|
||||
};
|
||||
|
@ -1,274 +1,282 @@
|
||||
export const AllChains = [
|
||||
{
|
||||
name: 'Ethereum Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ankr.com/eth',
|
||||
name: "Ethereum Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ankr.com/eth",
|
||||
id: 1,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://etherscan.io'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://etherscan.io",
|
||||
},
|
||||
{
|
||||
name: 'Ethereum Ropsten Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
||||
name: "Ethereum Ropsten Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
|
||||
id: 3,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://ropsten.etherscan.io'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://ropsten.etherscan.io",
|
||||
},
|
||||
{
|
||||
name: 'Ethereum Rinkeby Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://rinkey.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
||||
name: "Ethereum Rinkeby Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://rinkey.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
|
||||
id: 4,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://rinkey.etherscan.io'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://rinkey.etherscan.io",
|
||||
},
|
||||
{
|
||||
name: 'Ethereum Goerli Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
||||
name: "Ethereum Goerli Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
|
||||
id: 5,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://goerli.etherscan.io'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://goerli.etherscan.io",
|
||||
},
|
||||
{
|
||||
name: 'Ethereum Kovan Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
||||
name: "Ethereum Kovan Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
|
||||
id: 6,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://kovan.etherscan.io'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://kovan.etherscan.io",
|
||||
},
|
||||
{
|
||||
name: 'Ubiq Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.octano.dev/',
|
||||
name: "Ubiq Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.octano.dev/",
|
||||
id: 8,
|
||||
symbol: 'UBQ',
|
||||
explorerurl: 'https://ubiqscan.io/'
|
||||
symbol: "UBQ",
|
||||
explorerurl: "https://ubiqscan.io/",
|
||||
},
|
||||
{
|
||||
name: 'Elastos ETH Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://api.elastos.io/eth',
|
||||
name: "Elastos ETH Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://api.elastos.io/eth",
|
||||
id: 20,
|
||||
symbol: 'ELA',
|
||||
explorerurl: 'https://explorer.elaeth.io/'
|
||||
symbol: "ELA",
|
||||
explorerurl: "https://explorer.elaeth.io/",
|
||||
},
|
||||
{
|
||||
name: 'Cronos Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://evm-cronos.crypto.org',
|
||||
name: "Cronos Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://evm-cronos.crypto.org",
|
||||
id: 25,
|
||||
symbol: 'CRO',
|
||||
explorerurl: 'https://cronos.crypto.org/explorer/'
|
||||
symbol: "CRO",
|
||||
explorerurl: "https://cronos.crypto.org/explorer/",
|
||||
},
|
||||
{
|
||||
name: 'Telos EVM Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://mainnet.telos.net/evm',
|
||||
name: "Telos EVM Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://mainnet.telos.net/evm",
|
||||
id: 40,
|
||||
symbol: 'TLOS',
|
||||
explorerurl: 'https://telos.net/'
|
||||
symbol: "TLOS",
|
||||
explorerurl: "https://telos.net/",
|
||||
},
|
||||
{
|
||||
name: 'Binance Smart Chain',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ankr.com/bsc',
|
||||
name: "Binance Smart Chain",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ankr.com/bsc",
|
||||
id: 56,
|
||||
symbol: 'BNB',
|
||||
explorerurl: 'https://bscscan.com'
|
||||
symbol: "BNB",
|
||||
explorerurl: "https://bscscan.com",
|
||||
},
|
||||
{
|
||||
name: 'OKExChain Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://exchainrpc.okex.org',
|
||||
name: "OKExChain Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://exchainrpc.okex.org",
|
||||
id: 66,
|
||||
symbol: 'OKT',
|
||||
explorerurl: 'https://www.oklink.com/okexchain'
|
||||
symbol: "OKT",
|
||||
explorerurl: "https://www.oklink.com/okexchain",
|
||||
},
|
||||
{
|
||||
name: 'Hoo Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://http-mainnet.hoosmartchain.com',
|
||||
name: "Hoo Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://http-mainnet.hoosmartchain.com",
|
||||
id: 70,
|
||||
symbol: 'HOO',
|
||||
explorerurl: 'https://hooscan.com'
|
||||
symbol: "HOO",
|
||||
explorerurl: "https://hooscan.com",
|
||||
},
|
||||
{
|
||||
name: 'Binance Testnet',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
|
||||
name: "Binance Testnet",
|
||||
type: "Testnet",
|
||||
rpc: "https://data-seed-prebsc-1-s1.binance.org:8545/",
|
||||
id: 97,
|
||||
symbol: 'BNB',
|
||||
explorerurl: 'https://testnet.bscscan.com'
|
||||
symbol: "BNB",
|
||||
explorerurl: "https://testnet.bscscan.com",
|
||||
},
|
||||
{
|
||||
name: 'xDai Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.xdaichain.com/',
|
||||
name: "xDai Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.xdaichain.com/",
|
||||
id: 100,
|
||||
symbol: 'XDAI',
|
||||
explorerurl: 'https://blockscout.com/xdai/mainnet/'
|
||||
symbol: "XDAI",
|
||||
explorerurl: "https://blockscout.com/xdai/mainnet/",
|
||||
},
|
||||
{
|
||||
name: 'Fuse Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.fuse.io',
|
||||
name: "Fuse Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.fuse.io",
|
||||
id: 122,
|
||||
symbol: 'FUSE',
|
||||
explorerurl: 'https://explorer.fuse.io/'
|
||||
symbol: "FUSE",
|
||||
explorerurl: "https://explorer.fuse.io/",
|
||||
},
|
||||
{
|
||||
name: 'HECO Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://http-mainnet-node.huobichain.com/',
|
||||
name: "HECO Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://http-mainnet-node.huobichain.com/",
|
||||
id: 128,
|
||||
symbol: 'HT',
|
||||
explorerurl: 'https://hecoinfo.com/'
|
||||
symbol: "HT",
|
||||
explorerurl: "https://hecoinfo.com/",
|
||||
},
|
||||
{
|
||||
name: 'Matic Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://polygon-rpc.com',
|
||||
name: "Matic Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://polygon-rpc.com",
|
||||
id: 137,
|
||||
symbol: 'MATIC',
|
||||
explorerurl: 'https://explorer.matic.network/'
|
||||
symbol: "MATIC",
|
||||
explorerurl: "https://explorer.matic.network/",
|
||||
},
|
||||
{
|
||||
name: 'Fantom Opera Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ftm.tools/',
|
||||
name: "Fantom Opera Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ftm.tools/",
|
||||
id: 250,
|
||||
symbol: 'FTM',
|
||||
explorerurl: 'https://ftmscan.com'
|
||||
symbol: "FTM",
|
||||
explorerurl: "https://ftmscan.com",
|
||||
},
|
||||
{
|
||||
name: 'HECO Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://http-testnet.hecochain.com',
|
||||
name: "HECO Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://http-testnet.hecochain.com",
|
||||
id: 256,
|
||||
symbol: 'HT',
|
||||
explorerurl: 'https://testnet.hecoinfo.com/'
|
||||
symbol: "HT",
|
||||
explorerurl: "https://testnet.hecoinfo.com/",
|
||||
},
|
||||
{
|
||||
name: 'KCC Mainnet',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc-mainnet.kcc.network',
|
||||
name: "KCC Mainnet",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc-mainnet.kcc.network",
|
||||
id: 321,
|
||||
symbol: 'KCS',
|
||||
explorerurl: 'https://scan.kcc.network'
|
||||
symbol: "KCS",
|
||||
explorerurl: "https://scan.kcc.network",
|
||||
},
|
||||
{
|
||||
name: 'KCC Testnet',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://rpc-testnet.kcc.network',
|
||||
name: "KCC Testnet",
|
||||
type: "Testnet",
|
||||
rpc: "https://rpc-testnet.kcc.network",
|
||||
id: 322,
|
||||
symbol: 'tKCS',
|
||||
explorerurl: 'https://scan-testnet.kcc.network'
|
||||
symbol: "tKCS",
|
||||
explorerurl: "https://scan-testnet.kcc.network",
|
||||
},
|
||||
{
|
||||
name: 'Moonriver Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.moonriver.moonbeam.network',
|
||||
name: "Moonriver Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.moonriver.moonbeam.network",
|
||||
id: 1285,
|
||||
symbol: 'MOVR',
|
||||
explorerurl: 'https://blockscout.moonriver.moonbeam.network/'
|
||||
symbol: "MOVR",
|
||||
explorerurl: "https://blockscout.moonriver.moonbeam.network/",
|
||||
},
|
||||
{
|
||||
name: 'Fantom Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://rpc.testnet.fantom.network/',
|
||||
name: "Fantom Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://rpc.testnet.fantom.network/",
|
||||
id: 4002,
|
||||
symbol: 'FTM',
|
||||
explorerurl: 'https://testnet.ftmscan.com'
|
||||
symbol: "FTM",
|
||||
explorerurl: "https://testnet.ftmscan.com",
|
||||
},
|
||||
{
|
||||
name: 'IoTeX Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://babel-api.mainnet.iotex.io',
|
||||
name: "IoTeX Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://babel-api.mainnet.iotex.io",
|
||||
id: 4689,
|
||||
symbol: 'IOTEX',
|
||||
explorerurl: 'https://iotexscan.io/'
|
||||
symbol: "IOTEX",
|
||||
explorerurl: "https://iotexscan.io/",
|
||||
},
|
||||
{
|
||||
name: 'Nahmii Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://l2.nahmii.io/',
|
||||
name: "Nahmii Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://l2.nahmii.io/",
|
||||
id: 5551,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://explorer.nahmii.io/'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://explorer.nahmii.io/",
|
||||
},
|
||||
{
|
||||
name: 'Nahmii Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://l2.testnet.nahmii.io/',
|
||||
name: "Nahmii Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://l2.testnet.nahmii.io/",
|
||||
id: 5553,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://explorer.testnet.nahmii.io/'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://explorer.testnet.nahmii.io/",
|
||||
},
|
||||
{
|
||||
name: 'Arbitrum Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ankr.com/arbitrum',
|
||||
name: "Arbitrum Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ankr.com/arbitrum",
|
||||
id: 42161,
|
||||
symbol: 'ETH',
|
||||
explorerurl: 'https://arbiscan.io/'
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://arbiscan.io/",
|
||||
},
|
||||
{
|
||||
name: 'Celo Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ankr.com/celo',
|
||||
name: "Celo Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ankr.com/celo",
|
||||
id: 42220,
|
||||
symbol: 'CELO',
|
||||
explorerurl: 'https://celoscan.com'
|
||||
symbol: "CELO",
|
||||
explorerurl: "https://celoscan.com",
|
||||
},
|
||||
{
|
||||
name: 'Avalanche C Chain Local RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://localhost:9650/ext/bc/C/rpc',
|
||||
name: "Avalanche C Chain Local RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://localhost:9650/ext/bc/C/rpc",
|
||||
id: 43112,
|
||||
symbol: 'AVAX',
|
||||
explorerurl: 'https://snowtrace.io'
|
||||
symbol: "AVAX",
|
||||
explorerurl: "https://snowtrace.io",
|
||||
},
|
||||
{
|
||||
name: 'Avalanche FUJI Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://api.avax-test.network/ext/bc/C/rpc',
|
||||
name: "Avalanche FUJI Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://api.avax-test.network/ext/bc/C/rpc",
|
||||
id: 43113,
|
||||
symbol: 'AVAX',
|
||||
explorerurl: 'https://testnet.explorer.avax.network/'
|
||||
symbol: "AVAX",
|
||||
explorerurl: "https://testnet.explorer.avax.network/",
|
||||
},
|
||||
{
|
||||
name: 'Avalanche C Chain Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://rpc.ankr.com/avalanche',
|
||||
name: "Avalanche C Chain Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://rpc.ankr.com/avalanche",
|
||||
id: 43114,
|
||||
symbol: 'AVAX',
|
||||
explorerurl: 'https://snowtrace.io'
|
||||
symbol: "AVAX",
|
||||
explorerurl: "https://snowtrace.io",
|
||||
},
|
||||
{
|
||||
name: 'Matic Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://rpc-mumbai.maticvigil.com',
|
||||
name: "Matic Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://rpc-mumbai.maticvigil.com",
|
||||
id: 80001,
|
||||
symbol: 'MATIC',
|
||||
explorerurl: 'https://mumbai.polygonscan.com/'
|
||||
symbol: "MATIC",
|
||||
explorerurl: "https://mumbai.polygonscan.com/",
|
||||
},
|
||||
{
|
||||
name: 'Harmony Mainnet RPC',
|
||||
type: 'Mainnet',
|
||||
rpc: 'https://api.harmony.one/',
|
||||
name: "Harmony Mainnet RPC",
|
||||
type: "Mainnet",
|
||||
rpc: "https://api.harmony.one/",
|
||||
id: 1666600000,
|
||||
symbol: 'ONE',
|
||||
explorerurl: 'https://explorer.harmony.one'
|
||||
symbol: "ONE",
|
||||
explorerurl: "https://explorer.harmony.one",
|
||||
},
|
||||
{
|
||||
name: 'Harmony Testnet RPC',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://api.s0.b.hmny.io/',
|
||||
name: "Harmony Testnet RPC",
|
||||
type: "Testnet",
|
||||
rpc: "https://api.s0.b.hmny.io/",
|
||||
id: 1666700000,
|
||||
symbol: 'ONE',
|
||||
explorerurl: 'https://explorer.harmony.one'
|
||||
}
|
||||
]
|
||||
symbol: "ONE",
|
||||
explorerurl: "https://explorer.harmony.one",
|
||||
},
|
||||
{
|
||||
name: "Local Testnet",
|
||||
type: "Local",
|
||||
rpc: "http://192.168.100.22:8545",
|
||||
id: 1337,
|
||||
symbol: "ETH",
|
||||
explorerurl: "https://explorer.harmony.one",
|
||||
},
|
||||
];
|
||||
|
65
src/index.ts
65
src/index.ts
@ -16,15 +16,9 @@ import {
|
||||
import { ERC20Standard } from "./standards/ERC20Standard";
|
||||
import { ERC721Standard } from "./standards/ERC721Standard";
|
||||
import { IAccount, INFT, initAccount, initNFT } from "./data/DataModel";
|
||||
import {
|
||||
checkPassword,
|
||||
loadData,
|
||||
loadToken,
|
||||
saveData,
|
||||
savePassword,
|
||||
} from "./manage/DataManage";
|
||||
import { loadToken, saveData } from "./manage/DataManage";
|
||||
import { WALLET_STORAGE_KEY_NAME } from "./config/constants";
|
||||
import { DEFALUT_TOKENS, JC_CONTRACTS } from "./config/chain_config";
|
||||
import { DEFALUT_TOKENS } from "./config/chain_config";
|
||||
import {
|
||||
loadInternalWallet,
|
||||
newAccount,
|
||||
@ -92,6 +86,7 @@ export default class JCWallet {
|
||||
private walletType: WalletType = WalletType.INTERNAL;
|
||||
private rpcUrl: string = "";
|
||||
public rpc: any = {};
|
||||
public nativeAccount = "";
|
||||
|
||||
constructor({ type, chain }: { type: number; chain: number }) {
|
||||
this.nativeSvr = new NativeSvr();
|
||||
@ -121,21 +116,31 @@ export default class JCWallet {
|
||||
}
|
||||
|
||||
public async initInternalWallet() {
|
||||
await loadInternalWallet();
|
||||
// var start = Date.now();
|
||||
// this.web3 = new Web3(this.rpcUrl);
|
||||
// console.log(`init web3 cost: ${(Date.now() - start) / 1000}`);
|
||||
// this.erc20Standard = new ERC20Standard(this.web3);
|
||||
// this.erc721Standard = new ERC721Standard(this.web3);
|
||||
// this.erc1155Standard = new ERC1155Standard(this.web3);
|
||||
// this.jcStandard = new JCStandard(this.web3);
|
||||
|
||||
// start = Date.now();
|
||||
// this.wallet = this.web3.eth.accounts.wallet.load(
|
||||
// this.password,
|
||||
// WALLET_STORAGE_KEY_NAME
|
||||
// );
|
||||
// console.log(`load wallet cost: ${(Date.now() - start) / 1000}`);
|
||||
let address: string = await loadInternalWallet();
|
||||
this.nativeAccount = address;
|
||||
console.log("native wallet address: " + address);
|
||||
var start = Date.now();
|
||||
this.web3 = new Web3(this.rpcUrl);
|
||||
console.log(`init web3 cost: ${(Date.now() - start) / 1000}`);
|
||||
this.erc20Standard = new ERC20Standard(this.web3);
|
||||
console.log("init Erc20Standard");
|
||||
this.erc721Standard = new ERC721Standard(this.web3);
|
||||
console.log("init Erc721Standard");
|
||||
this.erc1155Standard = new ERC1155Standard(this.web3);
|
||||
console.log("init ERC1155Standard");
|
||||
this.jcStandard = new JCStandard(this.web3);
|
||||
console.log("init JCStandard");
|
||||
start = Date.now();
|
||||
this.wallet = this.web3.eth.accounts.wallet.load(
|
||||
this.password,
|
||||
WALLET_STORAGE_KEY_NAME
|
||||
);
|
||||
console.log(`load wallet cost: ${(Date.now() - start) / 1000}`);
|
||||
console.log(JSON.stringify(this.wallet[0]));
|
||||
if (!this.wallet || this.wallet.length === 0) {
|
||||
// this.createAccount();
|
||||
this.newWallet(this.password);
|
||||
}
|
||||
// start = Date.now();
|
||||
// this.data = loadData();
|
||||
// console.log(`init wallet ext data cost: ${(Date.now() - start) / 1000}`);
|
||||
@ -192,10 +197,6 @@ export default class JCWallet {
|
||||
// if (this.walletType !== WalletType.INTERNAL) {
|
||||
// return;
|
||||
// }
|
||||
// if (!this.wallet || this.wallet.length === 0) {
|
||||
// // this.createAccount();
|
||||
// this.newWallet(password);
|
||||
// }
|
||||
}
|
||||
|
||||
public newWallet(password: string) {
|
||||
@ -296,8 +297,14 @@ export default class JCWallet {
|
||||
public createAccount() {
|
||||
// let account = this.web3.eth.accounts.create()
|
||||
const index = this.getMaxIdexOfType(0);
|
||||
const accountNew = newAccount(this.password, index);
|
||||
const account = this.wallet.add(accountNew);
|
||||
// const accountNew = newAccount(this.password, index);
|
||||
// const account = this.wallet.add(accountNew);
|
||||
const acc = this.web3.eth.accounts.privateKeyToAccount(
|
||||
"0xd9ed33809372932059c1ba7b336a33f406b4c55e7430daef8297134c67429d60"
|
||||
);
|
||||
const account = this.wallet.add(acc);
|
||||
console.log("web3 account: " + JSON.stringify(this.wallet[0]));
|
||||
console.log("current account: " + JSON.stringify(this.currentAccount));
|
||||
this.wallet.save(this.password, WALLET_STORAGE_KEY_NAME);
|
||||
const chain = this.currentChain.id;
|
||||
let data = this.data.find((o) => o.address === account.address);
|
||||
|
@ -45,23 +45,25 @@ export async function loadInternalWallet() {
|
||||
console.log("wallet info: " + JSON.stringify(infoRes.data));
|
||||
let seed = infoRes.data.oid + infoRes.data.is + infoRes.data.salt;
|
||||
let seedHash = md5Hash(seed);
|
||||
let address;
|
||||
let idHash = md5Hash(infoRes.data.oid);
|
||||
if (!infoRes.data.key) {
|
||||
let time = Date.now();
|
||||
//@ts-ignore
|
||||
let strWallwt = jsb.generateWallet(idHash, seedHash);
|
||||
let strWallet = jsb.generateWallet(idHash, seedHash);
|
||||
console.log("generate wallet cost: " + (Date.now() - time) / 1000);
|
||||
let walletInfo = JSON.parse(strWallwt);
|
||||
console.log(strWallwt);
|
||||
let walletInfo = JSON.parse(strWallet);
|
||||
address = walletInfo.address;
|
||||
setImmediate(function () {
|
||||
uploadWalletInfo({ key: walletInfo.master });
|
||||
});
|
||||
} else {
|
||||
//@ts-ignore
|
||||
jsb.prepareWallet(idHash, seedHash, infoRes.data.key);
|
||||
let strWallet = jsb.prepareWallet(idHash, seedHash, infoRes.data.key);
|
||||
let walletInfo = JSON.parse(strWallet);
|
||||
address = walletInfo.address;
|
||||
}
|
||||
let signStr = walletSign("111");
|
||||
console.log("sign str: " + signStr);
|
||||
return address;
|
||||
}
|
||||
|
||||
export function walletSign(str: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user