+
+
+
+ All your funds will be lost! Do you really want to delete the wallet?
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enter parameters of transaction
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Chose the type of entering parameters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Your address:
+
+
+ {{address}}
+
+
+
+
+
+
+ Your private key:
+
+
+ {{privateKey}}
+
+
+
+
+
+
+
+
+
+
-
Name:
-
{{name}}
-
Your address:
-
{{address}}
-
-
Your private key:
-
{{privateKey}}
-
Show/Hide
-
Your public key:
-
{{publicKey}}
-
-
- Sign transaction
-
-
-
- Export private key
- Export public key
-
-
Back
-
-
Close
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/pages/BitcoinMultisigAddressPage.vue b/src/pages/BitcoinMultisigAddressPage.vue
index c59f210..cc2a881 100644
--- a/src/pages/BitcoinMultisigAddressPage.vue
+++ b/src/pages/BitcoinMultisigAddressPage.vue
@@ -1,158 +1,414 @@
-
-
Address name:
-
{{name}}
-
Your address:
-
{{address}}
-
import missing public keys, please
-
- Keys
+
+
+
+
+
+ Enter parameters of transaction
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Chose the type of entering parameters
+
+
+
+
+
+
+
+
+
+
+
+ All your funds will be lost! Do you really want to delete the wallet?
+
+
+
+
+
+
+
+
+
+
+
Your address:
+
{{address}}
+
import missing public keys, please ({{ countTEmpKeys}} / {{countHolders}})
+
+ Keys
-
- {{ item.name }}
-
-
-
-
-
-
- export public key
-
-
-
-
-
- show public key
-
-
-
-
-
-
-
-
- {{ item.name }} (your key)
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.name }}
+
+
+
+
+
+
+ export public key
+
+
+
+
+
+ show public key
+
+
+
+
+
+
+
+
+
+ {{ item.name }} (your key)
+
+
-
-
-
-
-
- export public key
-
-
-
-
-
- show public key
-
-
-
-
-
- show private key
-
-
-
-
-
-
-
- Back
- Import keys
-
+
+
+
+
+ export public key
+
+
+
+
+
+ show public key
+
+
+
+
+
+ show private key
+
+
+
+
+
+
+
+
+ Import keys
+ Back
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/BitcoinPage.vue b/src/pages/BitcoinPage.vue
index 6bfd6cf..4e12b4f 100644
--- a/src/pages/BitcoinPage.vue
+++ b/src/pages/BitcoinPage.vue
@@ -1,6 +1,25 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -16,7 +35,7 @@
-
+
@@ -55,6 +74,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -79,7 +128,7 @@
- {{ contact.name }}
+ {{ contact.name }}
@@ -91,7 +140,7 @@
- {{ multisigContact.name }}
+ {{ multisigContact.name }}
@@ -99,12 +148,13 @@
-
- New Address
-
- Back
+
+ Import private key
+ New Address
+
+ Back
-
+
diff --git a/src/pages/Index.vue b/src/pages/Index.vue
index 5b9459f..2374597 100644
--- a/src/pages/Index.vue
+++ b/src/pages/Index.vue
@@ -3,107 +3,12 @@
Bitcoin
Ethereum
+ Bitcoin Cash
-
-
+
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/src/router/routes.js b/src/router/routes.js
index d084203..8fe2668 100644
--- a/src/router/routes.js
+++ b/src/router/routes.js
@@ -11,7 +11,9 @@ const routes = [
{ path: '/EthereumAddressPage/:key?/:name?/:address?', component: () => import('pages/EthereumAddressPage.vue'), name: 'EthereumPage'},
{ path: '/BitcoinMultisigAddressPage/:key?/:signs?/:holders?/:keyList?/:address?/:name?', component: () => import('pages/BitcoinMultisigAddressPage.vue'), name: 'BitcoinMultisigPage'},
{ path: '/BitcoinAddressPage/:key?/:name?/:address?', component: () => import('pages/BitcoinAddressPage.vue'), name: 'BitcoinPage'},
+ { path: '/BCHAddressPage/:key?/:name?/:address?', component: () => import('pages/BCHAddressPage.vue'), name: 'BCHPage'},
{ path: '/addresses', component: () => import('pages/addresses.vue') },
+ { path: '/bch', component: () => import('pages/BCH.vue'), name: 'BCH' },
{ path: '/ethereum', component: () => import('pages/EthereumPage.vue'), name: 'Ethereum' },
{ path: '/startPage', component: () => import('pages/Index.vue') },
{ path: '/settingsAddress/:name?', component: () => import('pages/SettingsAddress.vue'), name: 'SettingsPage' },
diff --git a/src/scripts/BCH/ManagBD.js b/src/scripts/BCH/ManagBD.js
new file mode 100644
index 0000000..1bfa5b6
--- /dev/null
+++ b/src/scripts/BCH/ManagBD.js
@@ -0,0 +1,184 @@
+export default {
+ DownLoadAddresses() {
+ var text = []
+
+
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+ db.transaction(function(tx) {
+ //tx.executeSql('DROP TABLE IF EXISTS addresses');
+ //create table
+ tx.executeSql("CREATE TABLE IF NOT EXISTS addresses_bch (address text primary key, name text, key text)", [], function(tx, res){
+
+ db.transaction(function(tx) {
+ //retrieve data
+ tx.executeSql("SELECT * FROM addresses_bch", [], function(tx, res){
+ for(var iii = 0; iii < res.rows.length; iii++)
+ {
+ text.push({address: res.rows.item(iii).address, name: res.rows.item(iii).name, key: res.rows.item(iii).key})
+ }
+ console.log(text)
+
+ })
+ });
+ });
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ return text
+ },
+
+ DownLoadMultidigAdresses() {
+ var text = []
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+ //tx.executeSql('DROP TABLE IF EXISTS multisigAddresses');
+ //create table
+ tx.executeSql("CREATE TABLE IF NOT EXISTS multisig_addresses_bch (key text primary key, name text, address text, holders text, signs text, keylist text)", [], function(tx, res){
+
+ db.transaction(function(tx) {
+ //retrieve data
+ tx.executeSql("SELECT * FROM multisig_addresses_bch", [], function(tx, res){
+ for(var iii = 0; iii < res.rows.length; iii++)
+ {
+ text.push({key: res.rows.item(iii).key, name: res.rows.item(iii).name, address: res.rows.item(iii).address, holders: res.rows.item(iii).holders, signs: res.rows.item(iii).signs, keylist: res.rows.item(iii).keylist})
+ }
+ console.log(text)
+
+ })
+ });
+ });
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ return text
+ },
+
+ InsertAddressDb(address, name, key) {
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+
+ //insert data
+ tx.executeSql("INSERT INTO addresses_bch (address, name, key) VALUES (?,?,?)", [address, name, key]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ },
+
+ InsertMultisigDb(address, name, key, holders, signs, keylist) {
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+
+ tx.executeSql("INSERT INTO multisig_addresses_bch (key, name, address, holders, signs, keylist) VALUES (?,?,?,?,?,?)", [key, name, address, holders, signs, keylist]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ },
+ InsertAddress(oldList, newList){
+
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+
+ tx.executeSql("UPDATE multisig_addresses_bch SET keylist = ? WHERE keylist = ?", [newList, oldList]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ },
+
+ InsertMainAddress(address){
+
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+
+ tx.executeSql("UPDATE multisig_addresses_bch SET address = ? WHERE address = ?", [address, ""]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/scripts/BCH/index.js b/src/scripts/BCH/index.js
new file mode 100644
index 0000000..7319ce6
--- /dev/null
+++ b/src/scripts/BCH/index.js
@@ -0,0 +1,128 @@
+import { QrcodeStream } from 'vue-qrcode-reader'
+import managBD from './ManagBD.js'
+import settings from './settings.js'
+import Bsettings from 'src/scripts/Bitcoin/settings.js'
+var bch = require('bitcore-lib-cash');
+let bitcoin = require('bitcoinjs-lib')
+
+
+
+export default {
+ components: { QrcodeStream },
+ data () {
+ return {
+ contacts:[],
+ nets: ['livenet', 'testnet', 'regtest'],
+ multisigContacts:[],
+ importKey: false,
+ inception: false,
+ CountDialog: false,
+ CountRequared: false,
+ countHolders: '',
+ countSigns: '',
+ tab: 'addresses',
+ splitterModel: 20,
+ walletName: '',
+ chosenNet: '',
+ creating: false,
+ showCamera: false,
+ }
+ },
+
+ beforeMount(){
+ this.contacts = managBD.DownLoadAddresses();
+ this.multisigContacts = managBD.DownLoadMultidigAdresses();
+ },
+
+ methods: {
+
+ Address (name, net) {
+ const keyPair = bitcoin.ECPair.makeRandom({})
+ const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: Bsettings.data(net) })
+ console.log(address)
+ var a = new bch.Address(address);
+ console.log(a.toCashAddress())
+ this.contacts.push({ address: a, key: keyPair.toWIF(), name: name, net: net })
+ managBD.InsertAddressDb(address, name.toString(), keyPair.toWIF(), net)
+ },
+ MultisigAddress (holders, signs, name) {
+ let keyList = []
+ var yourKey = bitcoin.ECPair.makeRandom({ network: settings.data() })
+ alert('Your public key: ' + yourKey.publicKey.toString('hex'))
+ console.log('Your public key: ' + yourKey.publicKey.toString('hex'))
+ alert('Your private key: ' + yourKey.privateKey.toString('hex'))
+ console.log('Your private key: ' + yourKey.toWIF())
+ keyList.push(yourKey.publicKey)
+ for (let i = 0; i < holders - 1; i++) {
+ let newKey = prompt('Enter public key')
+ // let newKey = '026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01' // --- для electron, так как там не работает prompt
+ let publicKeyBuffer = newKey
+ alert(newKey)
+ console.log(newKey)
+ keyList.push(publicKeyBuffer)
+ }
+ const pubkeys = keyList.map(hex => Buffer.from(hex, 'hex'))
+ const { address } = bitcoin.payments.p2sh({
+ redeem: bitcoin.payments.p2ms({ m: signs, pubkeys, network: settings.data() })
+ }, settings.data())
+ alert(address)
+ console.log(address)
+ let json = JSON.stringify(keyList);
+ multisigContacts.push({ address: address, key: yourKey, holders: holders, signs: signs, keyList: keyList, name: name })
+ managBD.InsertMultisigDb()
+ },
+
+ SignTransaction(str1, str2, amount, key){
+ let tx = new bitcoin.TransactionBuilder()
+ tx.addInput(str1, 1)
+ tx.addOutput(str2, amount * 1000000)
+ tx.sign(0, key)
+ return tx.build().toHex()
+ },
+
+ /*Scan (key) {
+ cordova.plugins.barcodeScanner.scan(
+ function (result) {
+ let text = confirm('We got a barcode\n' +
+ 'Result: ' + result.text + '\n')
+ let pos1 = result.text.indexOf('"Input":"') + 8
+ let pos2 = result.text.indexOf('"Output":"') + 9
+ let pos3 = result.text.indexOf('"Amount":"') + 9
+ let str1 = result.text.substring(pos1 + 1, result.text.indexOf('"', pos1 + 1))
+ let str2 = result.text.substring(pos2 + 1, result.text.indexOf('"', pos2 + 1))
+ let amount = result.text.substring(pos3 + 1, result.text.indexOf('"', pos3 + 1))
+ let tx = this.SignTransaction(str1, str2, amount, key)
+ alert(tx)
+ if (text !== Boolean(false)) {
+ cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, tx, function (success) {
+ alert('encode success: ' + success)
+ }, function (fail) {
+ alert('encoding failed: ' + fail)
+ }
+ )
+ } else {
+ alert('error')
+ }
+ }
+ )
+ },*/
+ /*Scan(key) {
+ this.result = result
+ },*/
+ GoToMultisigAddress (key, holders, signs, keyList, address, name) {
+ console.log(keyList);
+ this.$router.push({ name: 'BitcoinMultisigPage', params: { key: key, signs: signs, holders: holders, keyList: keyList, address: address, name: name } })
+ },
+
+ GoToAddress (name, address, key) {
+ console.log(key)
+ this.$router.push({ name: 'BCHPage', params: { key: key, name: name, address: address } })
+ },
+ GoBack () {
+ this.$router.go(-1)
+ },
+ GoToSettings (name){
+ this.$router.push({ name: 'SettingsPage', params: {name: name} })
+ }
+ }
+}
diff --git a/src/scripts/BCH/settings.js b/src/scripts/BCH/settings.js
new file mode 100644
index 0000000..a44e077
--- /dev/null
+++ b/src/scripts/BCH/settings.js
@@ -0,0 +1,14 @@
+var bch = require('bitcore-lib-cash');
+import { Networks } from 'bitcore-lib-cash';
+export default {
+ data (net) {
+ switch (net){
+ case "livenet":
+ return Networks.livenet
+ case "testnet":
+ return Networks.testnet
+ default:
+ return Networks.regtest
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/scripts/BCH/transaction.js b/src/scripts/BCH/transaction.js
new file mode 100644
index 0000000..064d84f
--- /dev/null
+++ b/src/scripts/BCH/transaction.js
@@ -0,0 +1,63 @@
+import settings from "src/scripts/Bitcoin/settings.js";
+var QRious = require('QRious')
+let bitcoin = require("bitcoinjs-lib");
+var bch = require('bitcore-lib-cash');
+var Transaction = bch.Transaction;
+var Script = bch.Script;
+
+export default {
+ Transaction(hash, key, valuesend, getter, net, address) {
+ console.log(hash)
+ console.log(key)
+ console.log(Math.floor(Number(valuesend) * 100000000))
+ console.log(getter)
+ console.log(address)
+ var simpleUtxoWith100000Satoshis = {
+ address: address,
+ txId: hash,
+ outputIndex: 0,
+ script: Script.buildPublicKeyHashOut(address).toString(),
+ satoshis: Math.floor(Number(valuesend) * 100000000)
+ };
+ var tr = new Transaction()
+ .from(simpleUtxoWith100000Satoshis)
+ .to(getter, Math.floor(Number(valuesend) * 100000000))
+ .sign(key)
+ .sign(key);
+
+ console.log("transaction: " + tr)
+ var qr = new QRious({
+ element: document.getElementById('qr-transaction'),
+ value: tr.toString('hex'),
+ level: 'L',
+ size: 500,
+ })
+
+ },
+ MultisigTransaction(hash, key, getter, amount, net, signs, keyList) {
+ let tx = bitcoin.Transaction.fromHex(hash, { network: settings.data(net) })
+ const p2ms = bitcoin.payments.p2ms({ m: signs, pubkeys: keyList, network: settings.data() })
+ const multisig = bitcoin.payments.p2sh({ redeem: p2ms, network: settings.data() })
+ let data = { hash: tx.getId(), index: 1, nonWitnessUtxo: Buffer.from(str1, 'hex'), redeemScript: multisig.redeem.output }
+ const psbt = new bitcoin.Psbt({ network: settings.data() })
+ .addInput(data)
+ .addOutput({
+ address: getter,
+ value: amount * 100000000
+ })
+ .signInput(0, key)
+ const txLast = psbt.toBase64()
+ console.log(txLast)
+ psbt.validateSignaturesOfInput(0)
+ psbt.finalizeAllInputs()
+ var tr = psbt.extractTransaction().toHex()
+ console.log(psbt.extractTransaction().toHex())
+
+ var qr = new QRious({
+ element: document.getElementById('qr-transaction'),
+ value: tr,
+ level: 'L',
+ size: 500,
+ })
+ }
+}
diff --git a/src/scripts/Bitcoin/ManagBD.js b/src/scripts/Bitcoin/ManagBD.js
index ecbe85c..3663285 100644
--- a/src/scripts/Bitcoin/ManagBD.js
+++ b/src/scripts/Bitcoin/ManagBD.js
@@ -1,19 +1,30 @@
export default {
DownLoadAddresses() {
var text = []
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+
+
+ var db = null
+ /* if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {*/
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ // }
db.transaction(function(tx) {
- // tx.executeSql('DROP TABLE IF EXISTS addresses');
+ //tx.executeSql('DROP TABLE IF EXISTS addresses_bitcoin');
//create table
- tx.executeSql("CREATE TABLE IF NOT EXISTS addresses (address text primary key, name text, key text)", [], function(tx, res){
+ tx.executeSql("CREATE TABLE IF NOT EXISTS addresses_bitcoin (address text primary key, name text, key text, net text)", [], function(tx, res){
db.transaction(function(tx) {
//retrieve data
- tx.executeSql("SELECT * FROM addresses", [], function(tx, res){
+ tx.executeSql("SELECT * FROM addresses_bitcoin", [], function(tx, res){
for(var iii = 0; iii < res.rows.length; iii++)
{
- text.push({address: res.rows.item(iii).address, name: res.rows.item(iii).name, key: res.rows.item(iii).key})
+ text.push({address: res.rows.item(iii).address, name: res.rows.item(iii).name, key: res.rows.item(iii).key, net: res.rows.item(iii).net})
}
console.log(text)
@@ -31,19 +42,29 @@ export default {
DownLoadMultidigAdresses() {
var text = []
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
db.transaction(function(tx) {
- // tx.executeSql('DROP TABLE IF EXISTS multisigAddresses');
+ //tx.executeSql('DROP TABLE IF EXISTS multisig_addresses_bitcoin');
//create table
- tx.executeSql("CREATE TABLE IF NOT EXISTS multisigAddresses (key text primary key, name text, address text, holders text, signs text, keylist text)", [], function(tx, res){
+ tx.executeSql("CREATE TABLE IF NOT EXISTS multisig_addresses_bitcoin (key text primary key, name text, address text, holders text, signs text, keylist text, net text)", [], function(tx, res){
db.transaction(function(tx) {
//retrieve data
- tx.executeSql("SELECT * FROM multisigAddresses", [], function(tx, res){
+ tx.executeSql("SELECT * FROM multisig_addresses_bitcoin", [], function(tx, res){
for(var iii = 0; iii < res.rows.length; iii++)
{
- text.push({key: res.rows.item(iii).key, name: res.rows.item(iii).name, address: res.rows.item(iii).address, holders: res.rows.item(iii).holders, signs: res.rows.item(iii).signs, keylist: res.rows.item(iii).keylist})
+ text.push({key: res.rows.item(iii).key, name: res.rows.item(iii).name, address: res.rows.item(iii).address, holders: res.rows.item(iii).holders, signs: res.rows.item(iii).signs, keylist: res.rows.item(iii).keylist, net: res.rows.item(iii).net})
}
console.log(text)
@@ -59,13 +80,23 @@ export default {
return text
},
- InsertAddressDb(address, name, key) {
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ InsertAddressDb(address, name, key, net) {
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
db.transaction(function(tx) {
//insert data
- tx.executeSql("INSERT INTO addresses (address, name, key) VALUES (?,?,?)", [address, name, key]);
+ tx.executeSql("INSERT INTO addresses_bitcoin (address, name, key, net) VALUES (?,?,?,?)", [address, name, key, net]);
}, function(err){
@@ -75,12 +106,22 @@ export default {
});
},
- InsertMultisigDb(address, name, key, holders, signs, keylist) {
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ InsertMultisigDb(address, name, key, holders, signs, keylist, net) {
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
db.transaction(function(tx) {
- tx.executeSql("INSERT INTO multisigAddresses (key, name, address, holders, signs, keylist) VALUES (?,?,?,?,?,?)", [key, name, address, holders, signs, keylist]);
+ tx.executeSql("INSERT INTO multisig_addresses_bitcoin (key, name, address, holders, signs, keylist, net) VALUES (?,?,?,?,?,?,?)", [key, name, address, holders, signs, keylist, net]);
}, function(err){
@@ -91,11 +132,21 @@ export default {
},
InsertAddress(oldList, newList){
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
db.transaction(function(tx) {
- tx.executeSql("UPDATE multisigAddresses SET keylist = ? WHERE keylist = ?", [newList, oldList]);
+ tx.executeSql("UPDATE multisig_addresses_bitcoin SET keylist = ? WHERE keylist = ?", [newList, oldList]);
}, function(err){
@@ -107,11 +158,21 @@ export default {
InsertMainAddress(address){
- var db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
db.transaction(function(tx) {
- tx.executeSql("UPDATE multisigAddresses SET address = ? WHERE address = ?", [address, ""]);
+ tx.executeSql("UPDATE multisig_addresses_bitcoin SET address = ? WHERE address = ?", [address, ""]);
}, function(err){
@@ -119,5 +180,50 @@ export default {
alert("Error: " + err.message)
});
- }
+ },
+ RemoveAddressDB(name){
+ var db = null
+
+ if (navigator.userAgent.match(/(Android)/)) {
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+ } else {
+
+ db = window.openDatabase('Addresses.db', "0.1", "Addresses.db description", 200000);
+ console.log('DB: WebSQL');
+ }
+
+ db.transaction(function(tx) {
+
+ //insert data
+ tx.executeSql("DELETE FROM addresses_bitcoin WHERE name = ?", [name]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ },
+
+ RemoveMultiAddressDB(name){
+ var db = null
+
+ db = window.sqlitePlugin.openDatabase({name: "Addresses.db"});
+ console.log('DB: SQLite');
+
+
+ db.transaction(function(tx) {
+
+ //insert data
+ tx.executeSql("DELETE FROM multisig_addresses_bitcoin WHERE name = ?", [name]);
+
+ }, function(err){
+
+ //errors for all transactions are reported here
+ alert("Error: " + err.message)
+
+ });
+ }
}
\ No newline at end of file
diff --git a/src/scripts/Bitcoin/index.js b/src/scripts/Bitcoin/index.js
index b5f5113..2945a82 100644
--- a/src/scripts/Bitcoin/index.js
+++ b/src/scripts/Bitcoin/index.js
@@ -3,46 +3,14 @@ import settings from './settings.js'
import managBD from './ManagBD.js'
let bitcoin = require('bitcoinjs-lib')
-/*const contacts = [ {
- name: 'name 1',
- address: '1NeJEFzY8PbVS9RvYPfDP93iqXxHjav791',
- key: bitcoin.ECPair.makeRandom({ network: settings.data() })
-},
-{
- name: 'name 2',
- address: 'mj3GM8D2Q24XKRTdf13bB7oy2vCaS5oESk',
- key: bitcoin.ECPair.fromWIF('L4TTkYNJo6ZYW4rdLKp3gPyUnDuVrSHCTKW958HKouLymzwgE3m5')
-}]
-const multisigContacts = [ {
- name: 'name 1',
- address: '2MuvhtsnatLZbgmdBLmUNouHhd11fsvC89u',
- key: bitcoin.ECPair.makeRandom({ network: settings.data() }),
- holders: 2,
- signs: 1,
- keyList: [{ key: Buffer.from('n2t8F1D41xy6f3d2B6DtjXRRsn8dgUzQ6C'), name: 'Anna' }, { key: Buffer.from('mjgF67B4pyEHuGTLU5jS333EasUrZBaxMB'), name: 'Fred' }]
-},
-{
- name: 'name 2',
- address: '2MuvhtsnatLZbgmdBLmUNouHhd11fsvC89u',
- key: bitcoin.ECPair.fromWIF('L4TTkYNJo6ZYW4rdLKp3gPyUnDuVrSHCTKW958HKouLymzwgE3m5'),
- holders: 4,
- signs: 3,
- keyList: [{ key: Buffer.from('n2t8F1D41xy6f3d2B6DtjXRRsn8dgUzQ6C'), name: 'Bob' }, { key: Buffer.from('mjgF67B4pyEHuGTLU5jS333EasUrZBaxMB'), name: 'Kate' }]
-},
-{
- address: '2MuvhtsnatLZbgmdBLmUNouHhd11fsvC89u',
- name: 'name 3',
- key: bitcoin.ECPair.fromWIF('cP1tkWhhMbtuFPVpRcjS8s8Xae15gvUhchXWiwcWXJGfB7SCVHhq', settings.data()),
- holders: 2,
- signs: 1,
- keyList: [{ key: Buffer.from('039a696dbc7a422faa42688bfef236dd9b81585676a6c2cb185e1db39a195757d9', 'hex'), name: 'James' }, { key: Buffer.from('026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01', 'hex'), name: 'Alice' }]
-}]*/
export default {
components: { QrcodeStream },
data () {
return {
contacts:[],
+ nets: ['bitcoin', 'testnet', 'regtest'],
multisigContacts:[],
+ importKey: false,
inception: false,
CountDialog: false,
CountRequared: false,
@@ -50,7 +18,10 @@ export default {
countSigns: '',
tab: 'addresses',
splitterModel: 20,
- walletName: ''
+ walletName: '',
+ chosenNet: '',
+ creating: false,
+ showCamera: false,
}
},
@@ -60,15 +31,47 @@ export default {
},
methods: {
+ ImportKey(walletName, net) {
+ if (this.$q.platform.is.mobile){
+ cordova.plugins.barcodeScanner.scan(
+ function (resultKey) {
+ alert(resultKey.text)
+ let result = Addresses.newAddress(resultKey.text);
+ let address = result[0]
+ let pKey = result[1]
+ this.contacts.push({ address: address, key: pKey, name: walletName })
+ managBD.InsertAddressDb(address, walletName.toString(), pKey, net)
+ }
+ )
+ }
+ else {
+ this.walletNameImport = walletName
+ this.camera = 'auto'
+ this.showCamera = true
+ }
+ },
- Address (name) {
+ turnCameraOff () {
+ this.camera = 'off'
+ this.showCamera = false
+ },
+
+ async onDecode (content) {
+ alert(content)
+ let wallet = new ethers.Wallet(content);
+ let pKey = wallet.privateKey;
+ let address = wallet.address;
+ this.contacts.push({ address: address, key: pKey, name: this.walletNameImport })
+ managBD.InsertAddressDb(address, this.walletName.toString(), pKey, net)
+ this.turnCameraOff()
+ },
+ Address (name, net) {
const keyPair = bitcoin.ECPair.makeRandom()
- const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: settings.data() })
- this.contacts.push({ address: address, key: keyPair, name: name })
- alert(keyPair.toWIF())
- managBD.InsertAddressDb(address, name.toString(), keyPair.toWIF())
+ const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: settings.data(net) })
+ this.contacts.push({ address: address, key: keyPair.toWIF(), name: name, net: net })
+ managBD.InsertAddressDb(address, name.toString(), keyPair.toWIF(), net)
},
- MultisigAddress (holders, signs, name) {
+ MultisigAddress (holders, signs, name, net) {
let keyList = []
var yourKey = bitcoin.ECPair.makeRandom({ network: settings.data() })
alert('Your public key: ' + yourKey.publicKey.toString('hex'))
@@ -91,8 +94,8 @@ export default {
alert(address)
console.log(address)
let json = JSON.stringify(keyList);
- multisigContacts.push({ address: address, key: yourKey, holders: holders, signs: signs, keyList: keyList, name: name })
- managBD.InsertMultisigDb()
+ multisigContacts.push({ address: address, key: yourKey, holders: holders, signs: signs, keyList: keyList, name: name, net: net })
+ managBD.InsertMultisigDb(address, name, yourKey, holders, signs, keylist, net)
},
SignTransaction(str1, str2, amount, key){
@@ -132,13 +135,14 @@ export default {
/*Scan(key) {
this.result = result
},*/
- GoToMultisigAddress (key, holders, signs, keyList, address, name) {
- console.log(keyList);
- this.$router.push({ name: 'BitcoinMultisigPage', params: { key: key, signs: signs, holders: holders, keyList: keyList, address: address, name: name } })
+ GoToMultisigAddress (key, holders, signs, keyList, address, name, net) {
+ this.$router.push({ name: 'BitcoinMultisigPage', params: { key: key, signs: signs, holders: holders, keyList: keyList, address: address, name: name, net: net } })
},
- GoToAddress (name, address, key) {
- this.$router.push({ name: 'BitcoinPage', params: { key: key, name: name, address: address } })
+ GoToAddress (name, address, key, net) {
+ console.log(key)
+ console.log(address)
+ this.$router.push({ name: 'BitcoinPage', params: { key: key, name: name, address: address, net: net } })
},
GoBack () {
this.$router.go(-1)
diff --git a/src/scripts/Bitcoin/settings.js b/src/scripts/Bitcoin/settings.js
index 8a0b96a..592a953 100644
--- a/src/scripts/Bitcoin/settings.js
+++ b/src/scripts/Bitcoin/settings.js
@@ -1,6 +1,13 @@
let bitcoin = require('bitcoinjs-lib')
export default {
- data () {
- return bitcoin.networks.testnet
+ data (net) {
+ switch (net){
+ case "bitcoin":
+ return bitcoin.networks.bitcoin
+ case "testnet":
+ return bitcoin.networks.testnet
+ default:
+ return bitcoin.networks.regtest
+ }
}
}
\ No newline at end of file
diff --git a/src/scripts/Bitcoin/transaction.js b/src/scripts/Bitcoin/transaction.js
new file mode 100644
index 0000000..910e934
--- /dev/null
+++ b/src/scripts/Bitcoin/transaction.js
@@ -0,0 +1,75 @@
+import settings from "src/scripts/Bitcoin/settings.js";
+var QRious = require('QRious')
+let bitcoin = require("bitcoinjs-lib");
+
+export default {
+ Transaction(hash, key, valueget, valuesend, getter, net, publicKey) {
+ let tx = bitcoin.Transaction.fromHex(hash, { network: settings.data(net) })
+ const psbt = new bitcoin.Psbt({ network: settings.data(net) });
+
+ psbt.addInput({
+ // if hash is string, txid, if hash is Buffer, is reversed compared to txid
+ hash: tx.getId(),
+ index: 0,
+
+ // non-segwit inputs now require passing the whole previous tx as Buffer
+ nonWitnessUtxo: Buffer.from(
+ hash +
+ // value in satoshis (Int64LE) = 0x015f90 = 90000
+ valuesend +
+ // scriptPubkey length
+ publicKey.length +
+ // scriptPubkey
+ publicKey +
+ // locktime
+ '00000000',
+ 'hex',
+ ),
+
+ });
+
+ psbt.addOutput({
+ address: getter,
+ value: valueget * 100000000,
+ });
+ psbt.signInput(0, key);
+ psbt.validateSignaturesOfInput(0);
+ psbt.finalizeAllInputs();
+ var tr = psbt.extractTransaction().toHex()
+
+ console.log("transaction: " + tr)
+ var qr = new QRious({
+ element: document.getElementById('qr-transaction'),
+ value: tr,
+ level: 'L',
+ size: 500,
+ })
+
+ },
+ MultisigTransaction(hash, key, getter, amount, net, signs, keyList) {
+ let tx = bitcoin.Transaction.fromHex(hash, { network: settings.data(net) })
+ const p2ms = bitcoin.payments.p2ms({ m: signs, pubkeys: keyList, network: settings.data() })
+ const multisig = bitcoin.payments.p2sh({ redeem: p2ms, network: settings.data() })
+ let data = { hash: tx.getId(), index: 1, nonWitnessUtxo: Buffer.from(str1, 'hex'), redeemScript: multisig.redeem.output }
+ const psbt = new bitcoin.Psbt({ network: settings.data() })
+ .addInput(data)
+ .addOutput({
+ address: getter,
+ value: amount * 100000000
+ })
+ .signInput(0, key)
+ const txLast = psbt.toBase64()
+ console.log(txLast)
+ psbt.validateSignaturesOfInput(0)
+ psbt.finalizeAllInputs()
+ var tr = psbt.extractTransaction().toHex()
+ console.log(psbt.extractTransaction().toHex())
+
+ var qr = new QRious({
+ element: document.getElementById('qr-transaction'),
+ value: tr,
+ level: 'L',
+ size: 500,
+ })
+ }
+}