Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-doichain

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-doichain - npm Package Compare versions

Comparing version 0.0.9 to 0.1.0

50

index.js

@@ -9,6 +9,10 @@ var bitcore = require('bitcore');

var names = require('./lib/names');
var constants = require('./lib/constants');
var NameInput = require('./lib/nameinput');
import constants from "./lib/constants"
import settings from "./lib/doichain/settings"
import getUrl from "./lib/doichain/getUrl"
import encryptMessage from "./lib/doichain/encryptMessage"
import getAddressOfPublicKey from "./lib/doichain/getAddressOfPublicKey"
import createWallet from "./lib/doichain/createWallet";
import createWallet from "./lib/doichain/createWallet"; //TODO replace localstorage when using not in browser
import registerPublicKey from "./lib/doichain/registerPublicKey";

@@ -18,2 +22,4 @@ import getUTXOAndBalance from "./lib/doichain/getUTXOAndBalance"

import createRawDoichainTX from "./lib/doichain/createRawDoichainTX"
import broadcastTransaction from "./lib/doichain/broadcastTransaction"
/**

@@ -48,9 +54,9 @@ * Set up bitcore specific constants, version numbers,

// https://en.bitcoin.it/wiki/Base58Check_encoding
var networkNamecoin = Networks.add({
name: 'doichain',
var doichainMainnet = bitcore.Networks.add({
name: 'doichain',
alias: 'doichain',
// https://github.com/namecoin/namecore/commit/4b33389f2ed7809404b1a96ae358e148a765ab6f
pubkeyhash: 0x34,
privatekey: 0xB4,
scripthash: 13,
pubkeyhash: 111, //mainnet 52 //111 testnet //0x34 (bitcoin?)
privatekey: 0xB4, //TODO this doesn't seem correct
scripthash: 13, //TODO please double check ?
// xpubkey: 0x043587cf,

@@ -60,12 +66,19 @@ // xprivkey: 0x04358394,

// xprivkey: null, // HD extended privkey (nonexistant in namecoin o.g.)
networkMagic: 0xf9beb4fe,
port: 8334,
dnsSeeds: [
'nmc.seed.quisquis.de',
'namecoindnsseed.digi-masters.com',
'namecoindnsseed.digi-masters.uk',
'dnsseed.namecoin.webbtc.com'
]
networkMagic: 0xf9beb4fe, //TODO please double check ?
port: 8338,
dnsSeeds: []
});
//TODO in case of mainnet please change this here.
const doichainTestnet = bitcore.Networks.add({
name: 'doichain-testnet',
alias: 'doichain-testnet',
pubkeyhash: 111, //mainnet 52 //111 testnet //0x34 (bitcoin?)
privatekey: 0xB4, //TODO please double check ?
scripthash: 13, //TODO please double check ?
networkMagic: 0xf9beb4fe, //TODO please double check ?
port: 18338,
dnsSeeds: []
});
// networkNamecoin.namecoin = networkNamecoin;

@@ -129,2 +142,6 @@

// Add some Doichain functions
bitcore.constants = constants
bitcore.settings = settings
bitcore.getUrl = getUrl
bitcore.encryptMessage = encryptMessage //encrypts a message with a public key
bitcore.createWallet = createWallet //create public and private key

@@ -135,4 +152,5 @@ bitcore.registerPublicKey = registerPublicKey //register public key on doichain validator node

bitcore.createRawDoichainTX = createRawDoichainTX //create a
bitcore.getAddressOfPublicKey = getAddressOfPublicKey
bitcore.getAddressOfPublicKey = getAddressOfPublicKey //get the (first) doichain address from a public key
bitcore.broadcastTransaction = broadcastTransaction //broadcast the transaction together with the encrypted email permission request
export default bitcore;

@@ -12,2 +12,7 @@ var bitcore = require('bitcore');

VALIDATOR_FEE: {
btc: 0.03,
satoshis: new Unit.fromBTC(0.03).satoshis
},
// this is the tx fee itself

@@ -18,2 +23,3 @@ TRANSACTION_FEE: {

},

@@ -20,0 +26,0 @@ // same as TRANSACTION_FEE, but we could add some space here

@@ -1,5 +0,30 @@

const broadcastTransaction = () => {
import getUrl from "bitcore-doichain/lib/doichain/getUrl";
const broadcastTransaction = async (nameId,tx, templateDataEncrypted,validatorPublicKey) => {
await broadcast(nameId,tx,templateDataEncrypted,validatorPublicKey)
}
const broadcast = async (nameId,tx,templateDataEncrypted,validatorPublicKey) => {
// TODO get URL of node
const url = getUrl()+"api/v1/sendrawtransaction";
const response = await fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body:JSON.stringify({
nameId:nameId,
tx:tx,
templateDataEncrypted:templateDataEncrypted,
validatorPublicKey: validatorPublicKey
})
});
const json = await response.json();
return json
}
export default broadcastTransaction

@@ -17,24 +17,21 @@ import generateNameId from "./generateNameId";

*/
const createDoichainEntry = async (getPrivatKey,from,to,data) =>{
const createDoichainEntry = async (privateKey,validatorPublicKey, from,to,data) =>{
const nameId = await generateNameId();
const message = to+from; //TODO why to+from and not from+to?
const privateKey = getPrivatKey; // TODO check if we can just use our (alice) PrivatKey here for the signature
const signature = getSignature(message, privateKey);
let dataHash = "";
if(data) dataHash = getDataHash(data);
const parts = to.split("@");
const domain = parts[parts.length-1];
const publicKey = await getPublicKey(domain);
const fromHostUrl = getUrl()
const fromHostUrlEncrypted = encryptMessage(publicKey,fromHostUrl);
const nameValue = JSON.stringify({
signature: signature,
dataHash: dataHash,
from: fromHostUrlEncrypted
});
return {nameId:nameId,nameValue:nameValue,validatorPublicKey:publicKey}
const fromHostUrl = getUrl().length>0?getUrl():"http://localhost:3000"
return await encryptMessage(privateKey,validatorPublicKey,fromHostUrl).then((fromHostUrlEncrypted)=>{
const nameValue = JSON.stringify({
signature: signature,
dataHash: dataHash,
from: fromHostUrlEncrypted
});
return {nameId:nameId,nameValue:nameValue}
})
}
export default createDoichainEntry
import bitcore from "bitcore-doichain";
const createRawDoichainTX = (nameId, nameValue, validatorAddress,changeAddress,privKeySet,utxo,fee,amount) => {
import constants from "../constants"
const createRawDoichainTX = (nameId, nameValue, validatorAddress,changeAddress,privKeySet,utxo,fee,validatorFee) => {
if(fee<0.01) throw Error("fee too low! Will not be accepted by doichain node")
if(amount<0.03) throw Error("amount too low! Will not be accepted by validator - reward,revocation, doi-storage")
if(fee<constants.NETWORK_FEE.btc) throw Error("fee too low! Will not be accepted by doichain node")
if(validatorFee<constants.VALIDATOR_FEE.btc) throw Error("amount too low! Will not be accepted by validator - reward,revocation, doi-storage")
const changeAmount = parseInt(utxo.change*100000000)
const transactionFee = constants.TRANSACTION_FEE.satoshis
const changeAmount = Math.abs(parseInt(utxo.change*100000000-transactionFee))

@@ -13,3 +14,3 @@ const tx = new bitcore.Transaction()

.nameDoi(nameId, nameValue, validatorAddress)
.to(validatorAddress, amount*100000000) // validator processing fee (reward, storage, revokaction) an output with the given amount of satoshis
.to(validatorAddress, parseInt(validatorFee*100000000)) // validator processing fee (reward, storage, revokaction) an output with the given amount of satoshis
.to(changeAddress,changeAmount)

@@ -16,0 +17,0 @@ // .change(changeAddress) // Sets up a change address where the rest of the funds will go - unfortunately not working together with name_doi

@@ -23,3 +23,3 @@ import bitcore from "bitcore-doichain";

publicKey:publicKey.toString()})
console.log('stored publicKey and privateKey into wallet', db.queryAll('wallets'))
db.commit();

@@ -26,0 +26,0 @@

@@ -1,12 +0,25 @@

import ecies from 'standard-ecies'
/**
* https://medium.com/@dealancer/how-to-using-bitcoin-key-pairs-to-for-encrypted-messaging-a0a980e627b1
* https://stackoverflow.com/questions/36598638/generating-ecdh-keys-in-the-browser-through-webcryptoapi-instead-of-the-browseri
* https://github.com/bitchan/eccrypto
*
* AES Encryption with a single shared key
* https://www.npmjs.com/package/crypto-js
*/
import CryptoJS from 'crypto-js'
import eccrypto from 'eccrypto'
import bitcore from "bitcore-doichain";
import crypto from "crypto"
const encryptMessage = (publicKey,message) => {
try {
const publicKeyBuffer = Buffer.from(publicKey, 'hex');
const messageBuffer = Buffer.from(message);
return ecies.encrypt(publicKeyBuffer, messageBuffer).toString('hex');
} catch(exception) {
throw {error:"error while encrypting fromHostUrl", exception: exception};
}
};
export default encryptMessage;
const encryptMessage = async (privateKey,publicKey,message) => {
var pubB = new Buffer(publicKey, 'hex');
var ecdhA = crypto.createECDH('secp256k1');
ecdhA.generateKeys('hex', 'compressed');
ecdhA.setPrivateKey(privateKey, 'hex');
var secret = ecdhA.computeSecret(pubB, 'hex').toString('hex')
var ciphertext = CryptoJS.AES.encrypt(message, secret);
return ciphertext.toString()
}
export default encryptMessage;

@@ -6,3 +6,3 @@ import getKeyPair from "./getKeyPair"

const nameId = getKeyPair().privateKey
return nameId
return "e/"+nameId
} catch(exception) {

@@ -9,0 +9,0 @@ throw {error:"Error during generating doichain nameId", exception: exception};

import getOptInKey from "./getOptInKey"
const getPublicKey = async (domain) => {
const optInKey = await getOptInKey(domain);
return optInKey.key
return optInKey
};
export default getPublicKey;
import settings from "./settings"
const getUrl = () =>{
let ssl = settings.ssl?settings.ssl:false
let port = settings.port?settings.port:3000
let host = settings.host?settings.host:"localhost"
let protocol = "http://";
if(ssl===true) protocol = "https://";
return protocol+host+":"+port+"/";
if(settings.host===undefined && settings.port === undefined) return "" //for development purposes (proxy,cors)
else{
let ssl = settings.ssl?settings.ssl:false
let port = settings.port?settings.port:3000
let host = settings.host?settings.host:"localhost"
let protocol = "http://";
if(ssl===true) protocol = "https://";
return protocol+host+":"+port+"/";
}
}
export default getUrl
import {fetchUrl} from 'fetch'
import getUrl from "bitcore-doichain/lib/doichain/getUrl";

@@ -22,6 +23,6 @@ export default async function getUTXOAndBalance(doichainAddress,value){

}
spendable.balanceAllUTXOs = spendableBalance
spendable.amountUsedUTXOs = spendableCurrent
spendable.change = spendableCurrent-value
spendable.change = spendableCurrent-value?spendableCurrent-value:0
spendable.utxos = spendableUTXOs

@@ -33,3 +34,3 @@ return spendable

async function listUnspent(address) {
const url = "http://localhost:3000/api/v1/listunspent?address=" + address;
const url = getUrl()+"/api/v1/listunspent?address=" + address;
const response = await fetch(url);

@@ -36,0 +37,0 @@ const json = await response.json();

@@ -5,5 +5,5 @@ const settings = {

settings:false,
port:3010,
port:4010,
host:"5.9.154.226"
}
export default settings
{
"name": "bitcore-doichain",
"version": "0.0.9",
"version": "0.1.0",
"description": "Doichain Support for Bitcore",

@@ -29,5 +29,7 @@ "author": "Brandon Roberts <brandon@bxroberts.org>",

"bs58": "^4.0.1",
"crypto": "^1.0.1",
"crypto-hashing": "^0.3.1",
"crypto-js": "^3.1.9-1",
"doichain-transaction": "^0.0.3",
"eccrypto": "^1.1.1",
"fetch": "1.1.0",

@@ -34,0 +36,0 @@ "inherits": "^2.0.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc