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

doichain

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doichain - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

lib/generateSegwitAddress.js

72

index.js

@@ -21,3 +21,3 @@ import * as constants from "./lib/constants"

import verifySignature from "./lib/verifySignature"
import { generateKeyPairFromHdKey } from "./lib/generateKeyPairFromHdKey"
import {generateKeyPairFromHdKey} from "./lib/generateKeyPairFromHdKey"
import encryptTemplate from "./lib/encryptTemplate"

@@ -32,34 +32,44 @@ import {getServerStatus} from "./lib/getServerStatus";

import getBalance from "./lib/getBalance"
import generateSegwitAddress from "./lib/generateSegwitAddress"
import getInputAddress from "./lib/getInputAddress";
import hashRateFormat from "./lib/hashRateFormat"
import {isOurAddress} from './lib/isOurAddress'
import {isOurChangeAddress} from './lib/isOurChangeAddress'
export {
constants,
network,
getAddress,
createHdKeyFromMnemonic,
restoreDoichainWalletFromHdKey,
listTransactions,
listUnspent,
getBalanceOfAddresses,
getBalanceOfWallet,
decryptAES,
encryptAES,
getUnspents,
sendToAddress,
updateWalletWithUnconfirmedUtxos,
createAndSendTransaction,
getValidatorPublicKeyOfEmail,
encryptMessage,
getDataHash,
getSignature,
verifySignature,
generateKeyPairFromHdKey,
encryptTemplate,
getServerStatus,
encryptStandardECIES,
decryptStandardECIES,
createDoichainEntry,
getPrivateKeyFromWif,
generateNameId,
verify,
getBalance
constants,
network,
getAddress,
createHdKeyFromMnemonic,
restoreDoichainWalletFromHdKey,
listTransactions,
listUnspent,
getBalanceOfAddresses,
getBalanceOfWallet,
decryptAES,
encryptAES,
getUnspents,
sendToAddress,
updateWalletWithUnconfirmedUtxos,
createAndSendTransaction,
getValidatorPublicKeyOfEmail,
encryptMessage,
getDataHash,
getSignature,
verifySignature,
generateKeyPairFromHdKey,
encryptTemplate,
getServerStatus,
encryptStandardECIES,
decryptStandardECIES,
createDoichainEntry,
getPrivateKeyFromWif,
generateNameId,
verify,
getBalance,
generateSegwitAddress,
getInputAddress,
hashRateFormat,
isOurAddress,
isOurChangeAddress
}

@@ -27,1 +27,28 @@ import sb from 'satoshi-bitcoin'

export const toDOI = (schwartz) => sb.toBitcoin(schwartz)
export const myAddresses = [
{
address: "N1XBwuQkaXr45pbo8HLRZNLEkgQnade7Mk",
changeAddress: false
},
{
address: "6NZ88uvTn25fPTeZXZ7rH52p2BCtK1v6Pb",
changeAddress: false
},
{
address: "N4PcsgPFjzhgTZqBXYvtHkiDjZ3ft3us1i",
changeAddress: false
},
{
address: "18pFg2tGpcc7w2agFjcK5EZK1KecqF4guK",
changeAddress: false
},
{
address: "NJHArPJUknmNBL42ns6k61XApnAYzrRkow",
changeAddress: false
},
{
address: "Mxo7UBaf2f2kH1aLUvHWY2o7k6K3fkCj4b",
changeAddress: true,
}
]

@@ -13,3 +13,4 @@ import getUrl from "./getUrl";

const json = JSON.parse(text)
console.log("json",json)
return json
}

@@ -27,3 +27,3 @@ import {listTransactions} from "./listTransactions"

}
txs.push(tx)
txs.unshift(tx)
})

@@ -30,0 +30,0 @@ }

@@ -0,1 +1,2 @@

<<<<<<< HEAD
import getUrl from "./getUrl";

@@ -24,2 +25,140 @@

return json
=======
const bitcoin = require('bitcoinjs-lib')
const ElectrumClient = require('@codewarriorr/electrum-client-js')
import {isOurAddress} from "./isOurAddress";
import {isOurChangeAddress} from "./isOurChangeAddress";
import {getAddressOfInput} from "./getAddressOfInput"
function hex2a(hexx) {
var hex = hexx.toString();//force conversion
var str = '';
for (var i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
var scriptStrBuf = function(data) {
var stringLength = data.length / 2;
var len;
var opcode;
var bw = new BufferWriter();
if (data.length <= 252) {
bw.writeUInt8(stringLength);
opcode = stringLength;
} else if (stringLength <= 252) {
bw.writeUInt8(stringLength);
opcode = Opcode.OP_PUSHDATA1;
} else if (stringLength <= 0xffff) {
bw.writeUInt16LE(data.length);
opcode = Opcode.OP_PUSHDATA2;
} else {
bw.writeUInt32LE(data.length);
opcode = Opcode.OP_PUSHDATA4;
}
len = bufferTools.bufferToHex(bw.bufs[0]);
var chunk = {
buf: Buffer.from(data, 'hex'),
len: stringLength,
opcodenum: opcode
};
return chunk;
}
export async function listTransactions(address, network) {
console.info('listing transactions for address address', address)
let script = bitcoin.address.toOutputScript(address, network)
let hash = bitcoin.crypto.sha256(script)
let reversedHash = Buffer.from(hash.reverse())
console.log(address, ' maps to ', reversedHash.toString('hex'))
const client = new ElectrumClient("demo30122020.doi.works", 50002, "tls");
const result = [];
try {
await client.connect(
"electrum-client-js", // optional client name
"1.4.2" // optional protocol version
)
const header = await client.blockchain_headers_subscribe()
const history = await client.blockchain_scripthash_getHistory(
reversedHash.toString("hex")
)
let i = 0
for (const tx of history) {
const transaction = await client.blockchain_transaction_get(
tx.tx_hash
);
const decryptedTx = bitcoin.Transaction.fromHex(transaction);
console.log("decrypted tx with index", i)
//check all inputs and check if the address is ours or not
let isOurInput = false
decryptedTx.ins.forEach(async function(input, n) {
const inputAddress = getAddressOfInput(input)
if (isOurAddress(inputAddress)) isOurInput = true
})
const decriptedHeader = bitcoin.Block.fromHex(header.hex)
decryptedTx.outs.forEach((out, n) => {
let address, nameId, nameValue
let vout
const asm = bitcoin.script.toASM(out.script)
const asmParts = asm.split(" ")
//in case this is a name_op (e.g. OP_10 transaction this script will not work - no chance getting the address
//we don't see any results printed even tho we expect received and sent transactions - what is the reason here
if (asmParts[0] !== 'OP_10') {
address = bitcoin.address.fromOutputScript(out.script, network)
console.log('address', address)
} else {
const chunks = bitcoin.script.decompile(out.script)
nameId = Buffer.from(chunks[1]).toString()
nameValue = Buffer.from(chunks[2]).toString()
address = bitcoin.address.toBase58Check(chunks[7], network.scriptHash)
}
console.log('name_op nameId', nameId)
console.log('name_op nameValue', nameValue)
console.log('name_op address', address)
vout = {
txid: decryptedTx.getId(),
satoshi: isOurInput ? out.value * -1 : out.value,
value: isOurInput ?
1e-8 * out.value * -1 : 1e-8 * out.value,
n: n,
category: isOurInput ? "sent" : "received",
address: address,
nameId: nameId,
nameValue: nameValue,
timestamp: decriptedHeader.timestamp
}
if(isOurAddress(address) && !isOurChangeAddress(address)) result.push(vout)
// if (isOurAddress(address) && isOurInput) result.push(vout)
// if (isOurAddress(address) && !isOurInput) result.push(vout) //this is not our input, it's received
// if (!isOurAddress(address) && !isOurChangeAddress(address) && isOurInput) result.push(vout); // is our input, it's sent
})
i++
}
console.info('history length',result.length)
/* const balance = await client.blockchain_scripthash_getBalance(
reversedHash.toString("hex")
);
console.log(balance);
const unspent = await client.blockchain_scripthash_listunspent(
reversedHash.toString("hex")
);
console.log(unspent);*/
//await client.close();
} catch (err) {
console.error(err);
}
return result;
>>>>>>> e619c70 (minor unfinished changes)
}

@@ -7,3 +7,4 @@ import settings from './settings'

global.DEFAULT_NETWORK = DEFAULT_NETWORK
global.DEFAULT_SETTINGS = DEFAULT_SETTINGS
global.DEFAULT_SETTINGS = DEFAULT_SETTINGS
const ElectrumClient = require("@codewarriorr/electrum-client-js")

@@ -94,1 +95,12 @@ export const DOICHAIN = {

}
export const getElectrumClient = (setSettings=[]) => {
settings.setSettings(setSettings)
return new ElectrumClient(
settings.electrumHost,
settings.electrumPort,
settings.electrumSSL
)
}
var settings = {
testnet:true,
ssl:true,
from: 'newsletter@doichain.org',
port:443,
host:"doichain-testnet.le-space.de",
getSettings: function() {
return this
},
setSettings: function (_settings) {
this.testnet = _settings.testnet
this.from = _settings.from
this.port = _settings.port
this.host = _settings.host
this.ssl = _settings.ssl
}
}
testnet: true,
ssl: true,
from: "newsletter@doichain.org",
port: 443,
host: "doichain-testnet.le-space.de",
electrumHost: "btcpay.doi.works",
electrumPort: "50002",
electrumSSL: "ssl",
getSettings: function () {
return this;
},
setSettings: function (_settings) {
if(_settings.testnet !== undefined) this.testnet = _settings.testnet
if (_settings.from !== undefined) this.from = _settings.from
if (_settings.port !== undefined) this.port = _settings.port
if (_settings.host !== undefined) this.host = _settings.host
if (_settings.ssl !== undefined) this.ssl = _settings.ssl
if (_settings.electrumHost !== undefined) this.electrumHost = _settings.electrumHost
if (_settings.electrumPort !== undefined) this.electrumPort = _settings.electrumPort
if (_settings.electrumSSL !== undefined) this.electrumSSL = _settings.electrumSSL
}
};
export default settings
{
"name": "doichain",
"version": "0.1.12",
"version": "0.1.13",
"description": "A js-Doichain library. The goal is to fully cover the Doichain protocol",

@@ -37,2 +37,3 @@ "main": "index.js",

"dependencies": {
"@codewarriorr/electrum-client-js": "^0.1.1",
"binstring": "^0.2.1",

@@ -46,2 +47,3 @@ "bip39": "^3.0.2",

"eciesjs": "^0.3.6",
"electrum-mnemonic": "^2.0.0",
"hdkey": "^1.1.1",

@@ -48,0 +50,0 @@ "node-fetch": "^2.6.0",

@@ -47,2 +47,35 @@ import chai from 'chai'

/* it.only('should log listtransactions content', async function () {
changeNetwork('mainnet')
const address = "NJHArPJUknmNBL42ns6k61XApnAYzrRkow"
let listTransaction = await listTransactions(address)
console.log(listTransaction)
}) */
it.only('should get a transactions input', async function () {
const ElectrumClient = require('@codewarriorr/electrum-client-js')
const client = new ElectrumClient("demo30122020.doi.works", 50002, "tls");
await client.connect(
"electrum-client-js", // optional client name
"1.4.2" // optional protocol version
)
<<<<<<< HEAD
const history = await client.blockchain_scripthash_getHistory(
reversedHash.toString("hex")
)
=======
>>>>>>> e619c70 (minor unfinished changes)
const txid = "bed2d384dc8a304ab20f4e1282958171052fbc4265fefae7d9231b491c5216a4"
const transaction = await client.blockchain_transaction_get(txid);
const decryptedTx = bitcoin.Transaction.fromHex(transaction);
console.log("decrypted tx", decryptedTx)
})
it('should log listtransactionsElectrum content', async function () {
//const address = "NJHArPJUknmNBL42ns6k61XApnAYzrRkow"
const address = "bc1q7vtcp3gas4k54y5xtmg2dl7dw599s4wdqha78y"
let listTransactionElectrum = await listTransactions(address, DOICHAIN)
console.log(listTransactionElectrum)
})
it('should create a new mnemonic seed phrase', function () {

@@ -89,3 +122,3 @@ const mnemonic = generateMnemonic()

it.only('should fund the basic regtest wallet with 10 DOI ', async () => {
it('should fund the basic regtest wallet with 10 DOI ', async () => {
changeNetwork('regtest')

@@ -303,3 +336,3 @@ const hdKey = createHdKeyFromMnemonic(MNEMONIC)

it.only('create and verify a signature ', async () => {
it('create and verify a signature ', async () => {
changeNetwork('regtest')

@@ -306,0 +339,0 @@ function rng () {

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