Browse Source

钱包工具类

master
vee 4 years ago
parent
commit
9375985e8a
  1. 12
      pages/menu/backUp/transPaw/index.vue
  2. 2
      pages/menu/collection/index.vue
  3. 2
      unpackage/dist/dev/app-plus/app-config-service.js
  4. 9586
      unpackage/dist/dev/app-plus/app-service.js
  5. 7460
      unpackage/dist/dev/app-plus/app-view.js
  6. 2
      unpackage/dist/dev/app-plus/manifest.json
  7. 0
      unpackage/dist/dev/app-plus/static/img/copy_24px_outlined.e8932d3c.svg
  8. 0
      unpackage/dist/dev/app-plus/static/img/more_vert_24px_outlined.427f4df0.svg
  9. 2
      unpackage/dist/dev/app-plus/view.css
  10. 4
      unpackage/dist/dev/app-plus/view.umd.min.js
  11. 167
      utils/TokenUtil.js
  12. 92
      utils/WalletUtil.js

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

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

2
pages/menu/collection/index.vue

@ -21,7 +21,7 @@
</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>

2
unpackage/dist/dev/app-plus/app-config-service.js

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

2
unpackage/dist/dev/app-plus/manifest.json

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__1ECBEE1","name":"BITCOOO","version":{"name":"1.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#fff"},"compatible":{"ignoreVersion":true},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"distribute":{"icons":{"android":{"hdpi":"unpackage/res/icons/72x72.png","xhdpi":"unpackage/res/icons/96x96.png","xxhdpi":"unpackage/res/icons/144x144.png","xxxhdpi":"unpackage/res/icons/192x192.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"}}},"splashscreen":{"androidStyle":"default","iosStyle":"default","android":{"hdpi":"","xhdpi":"","xxhdpi":""}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"]},"apple":{},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.2.12","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__1ECBEE1","name":"BITCOOO","version":{"name":"1.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#fff"},"compatible":{"ignoreVersion":true},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"distribute":{"icons":{"android":{"hdpi":"unpackage/res/icons/72x72.png","xhdpi":"unpackage/res/icons/96x96.png","xxhdpi":"unpackage/res/icons/144x144.png","xxxhdpi":"unpackage/res/icons/192x192.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"}}},"splashscreen":{"androidStyle":"default","iosStyle":"default","android":{"hdpi":"","xhdpi":"","xxhdpi":""}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"]},"apple":{},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.1.22","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}

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

92
utils/WalletUtil.js

@ -0,0 +1,92 @@
impor 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