Browse Source

代码

master
Dread 4 years ago
parent
commit
5335d472a0
  1. 12
      pages/menu/backUp/transPaw/index.vue
  2. 2
      pages/menu/collection/index.vue
  3. 19
      unpackage/dist/dev/app-plus/app-service.js
  4. 7466
      unpackage/dist/dev/app-plus/app-view.js
  5. 0
      unpackage/dist/dev/app-plus/static/img/copy_24px_outlined.e8932d3c.svg
  6. 0
      unpackage/dist/dev/app-plus/static/img/more_vert_24px_outlined.427f4df0.svg
  7. 2
      unpackage/dist/dev/app-plus/view.css
  8. 4
      unpackage/dist/dev/app-plus/view.umd.min.js
  9. 167
      utils/TokenUtil.js
  10. 92
      utils/WalletUtil.js

12
pages/menu/backUp/transPaw/index.vue

@ -65,11 +65,11 @@
setWalletInfo(e) { setWalletInfo(e) {
this.word = uni.getStorageSync('word'); this.word = uni.getStorageSync('word');
this.walletInfo = this.$Token.initialWallet(this.word, e) this.walletInfo = this.$Token.initialWallet(this.word, e)
let that=this
this.$api.getBtcBalance().then((res) => { this.$api.getBtcBalance().then((res) => {
var b = res.data.data[0] var b = res.data.data[0]
for (var k in b) { for (var k in b) {
this.btcBalance = b[k] that.btcBalance = b[k]
} }
}) })
this.walletInfo.BTC[0].balance = this.btcBalance this.walletInfo.BTC[0].balance = this.btcBalance
@ -85,7 +85,6 @@
// eth.balance = res // eth.balance = res
// this.ethBbalance = res; // this.ethBbalance = res;
// }); // });
let that=this
console.log(this.walletInfo.ETH[0].address,2222222) console.log(this.walletInfo.ETH[0].address,2222222)
this.$EthUtil.getBalance(this.walletInfo.ETH[0].address,function(res){ this.$EthUtil.getBalance(this.walletInfo.ETH[0].address,function(res){
console.log(res,787878) console.log(res,787878)
@ -104,7 +103,8 @@
name2:"ERC20-USDT", name2:"ERC20-USDT",
xname:'Tether USD', xname:'Tether USD',
contractAddress:'0xdac17f958d2ee523a2206206994597c13d831ec7', contractAddress:'0xdac17f958d2ee523a2206206994597c13d831ec7',
icon:require('@/static/tongyonh/img500.png') icon:require('@/static/tongyonh/img500.png'),
balance: 0
} }
] ]
@ -112,8 +112,8 @@
}); });
this.$TronUtil.getTronBalance(this.walletInfo.TRON[0].address).then((res) => { this.$TronUtil.getTronBalance(this.walletInfo.TRON[0].address).then((res) => {
this.walletInfo.TRON[0].balance = res that.walletInfo.TRON[0].balance = res
this.walletInfo.TRON[0].coinList = [ that.walletInfo.TRON[0].coinList = [
{ {
name: "TRX", name: "TRX",
name2: "TRX", name2: "TRX",

2
pages/menu/collection/index.vue

@ -21,7 +21,7 @@
</view> </view>
</view> </view>
</view> </view>
<image src="../../../../tongyonh/chevron_right_24px.png" mode="aspectFit" class="letImg"></image> <image src="../../../static/tongyonh/chevron_right_24px.png" mode="aspectFit" class="letImg"></image>
</view> </view>

19
unpackage/dist/dev/app-plus/app-service.js

File diff suppressed because one or more lines are too long

7466
unpackage/dist/dev/app-plus/app-view.js

File diff suppressed because one or more lines are too long

0
unpackage/dist/dev/app-plus/static/img/copy_24px_outlined.8dca7e38.svg → unpackage/dist/dev/app-plus/static/img/copy_24px_outlined.e8932d3c.svg

Before

Width:  |  Height:  |  Size: 629 B

After

Width:  |  Height:  |  Size: 629 B

0
unpackage/dist/dev/app-plus/static/img/more_vert_24px_outlined.266aaa48.svg → unpackage/dist/dev/app-plus/static/img/more_vert_24px_outlined.427f4df0.svg

Before

Width:  |  Height:  |  Size: 526 B

After

Width:  |  Height:  |  Size: 526 B

2
unpackage/dist/dev/app-plus/view.css

File diff suppressed because one or more lines are too long

4
unpackage/dist/dev/app-plus/view.umd.min.js

File diff suppressed because one or more lines are too long

167
utils/TokenUtil.js

@ -14,10 +14,10 @@ let token = {
generateMnemonic: function() { generateMnemonic: function() {
return bip39.generateMnemonic(); return bip39.generateMnemonic();
}, },
//获取Child //获取Child
getPrivateKey: function(mnemonic, hdpath) { getPrivateKey: function(mnemonic, hdpath) {
if(mnemonic.split(" ").length%12>0){ if (mnemonic.split(" ").length % 12 > 0) {
throw new Error("mnemonic error"); throw new Error("mnemonic error");
} }
let seed = bip39.mnemonicToSeedSync(mnemonic); let seed = bip39.mnemonicToSeedSync(mnemonic);
@ -25,14 +25,14 @@ let token = {
const child = node.derivePath(hdpath); const child = node.derivePath(hdpath);
let privateKey = util.bufferToHex(child.privateKey); let privateKey = util.bufferToHex(child.privateKey);
return privateKey; return privateKey;
}, },
//根据助记词生成以太坊ETH的钱包信息 //根据助记词生成以太坊ETH的钱包信息
generateEth: function(mnemonic) { generateEth: function(mnemonic) {
let privateKey = this.getPrivateKey(mnemonic, "m/44'/60'/0'/0/0"); let privateKey = this.getPrivateKey(mnemonic, "m/44'/60'/0'/0/0");
let wallet = new ethers.Wallet(privateKey); let wallet = new ethers.Wallet(privateKey);
let address = wallet.address; let address = wallet.address;
return { return {
@ -52,7 +52,7 @@ let token = {
}, },
//根据助记词生成比特币BTC钱包信息 //根据助记词生成比特币BTC钱包信息
generateBtc: function(mnemonic) { generateBtc: function(mnemonic) {
if(mnemonic.split(" ").length%12>0){ if (mnemonic.split(" ").length % 12 > 0) {
throw new Error("mnemonic error"); throw new Error("mnemonic error");
} }
let seed = bip39.mnemonicToSeedSync(mnemonic); let seed = bip39.mnemonicToSeedSync(mnemonic);
@ -60,8 +60,12 @@ let token = {
const keyPair = node.derivePath("m/44'/195'/0'/0/0"); const keyPair = node.derivePath("m/44'/195'/0'/0/0");
const privateKey = keyPair.toWIF(); const privateKey = keyPair.toWIF();
console.log("BTC私钥:", privateKey) console.log("BTC私钥:", privateKey)
let address = bitcoin.payments.p2sh({redeem: bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey })}); let address = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({
pubkey: keyPair.publicKey
})
});
//bitcoin.payments.p2pkh({ pubkey: child.publicKey }) //bitcoin.payments.p2pkh({ pubkey: child.publicKey })
//console.log(address.fromScriptHash({pubkey: keyPair.publicKey})) //console.log(address.fromScriptHash({pubkey: keyPair.publicKey}))
return { return {
@ -72,7 +76,11 @@ let token = {
//导入比特币BTC私钥 //导入比特币BTC私钥
importBtcPrivateKey: function(privateKey) { importBtcPrivateKey: function(privateKey) {
let keyPair = new bitcoin.ECPair.fromWIF(privateKey); let keyPair = new bitcoin.ECPair.fromWIF(privateKey);
let address = bitcoin.payments.p2sh({redeem: bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey })}); let address = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({
pubkey: keyPair.publicKey
})
});
//console.log(address.fromScriptHash({pubkey: keyPair.publicKey})) //console.log(address.fromScriptHash({pubkey: keyPair.publicKey}))
return { return {
'privateKey': privateKey, 'privateKey': privateKey,
@ -97,83 +105,90 @@ let token = {
'address': address 'address': address
}; };
}, },
initialWallet:function(mnemonic,password){ initialWallet: function(mnemonic, password) {
let btc=this.generateBtc(mnemonic); let btc = this.generateBtc(mnemonic);
btc.mnemonic=mnemonic; btc.mnemonic = mnemonic;
btc.password=password; btc.password = password;
btc.coinList=[{ btc.balance = 0;
name:"BTC", btc.coinList = [{
name2:"BTC", name: "BTC",
xname:'Bitcoin', name2: "BTC",
icon:require('@/static/tongyonh/bye.png') xname: 'Bitcoin',
balance: 0,
icon: require('@/static/tongyonh/bye.png')
}]; }];
let eth=this.generateEth(mnemonic); let eth = this.generateEth(mnemonic);
eth.password=password; eth.password = password;
eth.mnemonic=mnemonic; eth.balance = 0;
eth.coinList=[{ eth.mnemonic = mnemonic;
name:"ETH", eth.coinList = [{
name2:"ETH", name: "ETH",
xname:'Ethereum', name2: "ETH",
icon:require('@/static/tongyonh/Frame3299.png') xname: 'Ethereum',
}, balance: 0,
{ icon: require('@/static/tongyonh/Frame3299.png')
name:"USDT", },
name2:"ERC20-USDT", {
xname:'Tether USD', name: "USDT",
contractAddress:'0xdac17f958d2ee523a2206206994597c13d831ec7', name2: "ERC20-USDT",
icon:require('@/static/tongyonh/img500.png') xname: 'Tether USD',
} balance: 0,
contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
icon: require('@/static/tongyonh/img500.png')
}
]; ];
console.log(eth.coinList,4444) console.log(eth.coinList, 4444)
console.log(eth,2224) console.log(eth, 2224)
let tron=this.generateTron(mnemonic); let tron = this.generateTron(mnemonic);
tron.password=password; tron.password = password;
tron.mnemonic=mnemonic; tron.balance = 0;
tron.coinList=[ tron.mnemonic = mnemonic;
tron.coinList = [{
name: "TRX",
name2: "TRX",
xname: 'TRON',
balance: 0,
icon: require('@/static/tongyonh/tron1.png')
},
{ {
name:"TRX", name: "USDT",
name2:"TRX", name2: "TRC20-USDT",
xname:'TRON', xname: 'Tether USD',
icon:require('@/static/tongyonh/tron1.png') balance: 0,
}, contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
{ icon: require('@/static/tongyonh/tether_usd.png')
name:"USDT", },
name2:"TRC20-USDT",
xname:'Tether USD',
contractAddress:'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
icon:require('@/static/tongyonh/tether_usd.png')
},
]; ];
let wallrtInfo={ let wallrtInfo = {
"BTC":[ "BTC": [
btc btc
], ],
"ETH":[ "ETH": [
eth eth
], ],
"TRON":[ "TRON": [
tron tron
] ]
} }
return wallrtInfo; return wallrtInfo;
}, },
creatingWallets: function() { creatingWallets: function() {
let mnemonic = this.generateMnemonic(); let mnemonic = this.generateMnemonic();
let eth = this.generateEth(mnemonic); let eth = this.generateEth(mnemonic);
let tron = this.generateTron(mnemonic); let tron = this.generateTron(mnemonic);
let btc = this.generateBtc(mnemonic); let btc = this.generateBtc(mnemonic);
// let privateKey = this.getPrivateKey(mnemonic); // let privateKey = this.getPrivateKey(mnemonic);
return { return {
'eth': eth, 'eth': eth,
'tron': tron, 'tron': tron,
'btc': btc, 'btc': btc,
'mnemonic': mnemonic, 'mnemonic': mnemonic,
// 'privateKey': privateKey // 'privateKey': privateKey
}; };
}, },
} }
export default token export default token

92
utils/WalletUtil.js

@ -0,0 +1,92 @@
import TokenUtil from './TokenUtil.js'
let fullWallet = {
"BTC": [{
balance: 0,
name: "BTC",
coinList: [{
name: "BTC",
xname: 'Bitcoin',
balance: 0,
icon: require('@/static/tongyonh/bye.png')
}]
}],
"ETH": [
balance: 0,
name: "ETH",
coinList: [{
name: "ETH",
xname: 'Ethereum',
balance: 0,
icon: require('@/static/tongyonh/Frame3299.png')
},
{
name: "USDT",
xname: 'Tether USD',
balance: 0,
contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
icon: require('@/static/tongyonh/img500.png')
}
]
],
"TRON": [
balance: 0,
name: "TRON",
coinList: [{
name: "TRX",
xname: 'TRON',
balance: 0,
icon: require('@/static/tongyonh/tron1.png')
},
{
name: "TRC20-USDT",
xname: 'Tether USD',
balance: 0,
contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
icon: require('@/static/tongyonh/tether_usd.png')
}
]
}
let WalletUtil = {
//初次创建钱包
initialWallet: function(mnemonic, password) {
let walletInfo = fullWallet;
let btc = TokenUtil.token.generateBtc(mnemonic);
walletInfo.BTC[0].password = password;
walletInfo.BTC[0].mnemonic = mnemonic;
walletInfo.BTC[0].privateKey = btc.privateKey;
walletInfo.BTC[0].address = btc.address;
let eth = TokenUtil.token.generateEth(mnemonic)
walletInfo.ETH[0].password = password;
walletInfo.ETH[0].mnemonic = mnemonic;
walletInfo.ETH[0].privateKey = eth.privateKey;
walletInfo.ETH[0].address = eth.mnemonic;
let tron = TokenUtil.token.generateTron(mnemonic);
walletInfo.TRON[0].mnemonic = mnemonic;
walletInfo.TRON[0].password = password;
walletInfo.TRON[0].privateKey = tron.privateKey;
walletInfo.TRON[0].address = tron.mnemonic;
uni.setStorageSync('walletInfo', walletInfo);
},
//修改钱包名称
updateWalletName: function(type, address, name) {
let walletInfo = uni.getStorageSync('walletInfo');
for (var k = 0, length = walletInfo.length; k < length; k++) {
if (walletInfo[k].address === address) {
walletInfo[k].name = name
break;
}
}
uni.setStorageSync('walletInfo', walletInfo);
},
updateWalletName: function(type, address, name) {
let walletInfo = uni.getStorageSync('walletInfo');
for (var k = 0, length = walletInfo.length; k < length; k++) {
if (walletInfo[k].address === address) {
walletInfo[k].name = name
break;
}
}
uni.setStorageSync('walletInfo', walletInfo);
}
}
Loading…
Cancel
Save