Comparing version 0.0.42 to 0.0.43
@@ -20,2 +20,3 @@ import * as constants from "./lib/constants" | ||
import getSignature from "./lib/getSignature" | ||
import verifySignature from ".li/verifySignature" | ||
import generateNewKeyPairFromHdKey from "./lib/generateNewKeyPairFromHdKey" | ||
@@ -49,2 +50,3 @@ import encryptTemplate from "./lib/encryptTemplate" | ||
getSignature, | ||
verifySignature, | ||
generateNewKeyPairFromHdKey, | ||
@@ -51,0 +53,0 @@ encryptTemplate, |
@@ -1,2 +0,2 @@ | ||
const bitcoin = require('bitcoinjs-lib') | ||
//const bitcoin = require('bitcoinjs-lib') | ||
const bitcoinMessage = require('bitcoinjs-message') | ||
@@ -13,5 +13,5 @@ /** | ||
try { | ||
// const privateKey = keyPair.d.toBuffer(32) | ||
// const privateKey = keyPair.d.toBuffer(32) | ||
//var message = 'Hey this is Ranchi Mall' | ||
const signature = bitcoinMessage.sign(message, keyPair._privateKey, keyPair.compressed) | ||
const signature = bitcoinMessage.sign(message,keyPair.privateKey, keyPair.compressed) | ||
console.log(signature.toString('base64')) | ||
@@ -18,0 +18,0 @@ return signature.toString('base64') |
{ | ||
"name": "doichain", | ||
"version": "0.0.42", | ||
"version": "0.0.43", | ||
"description": "A js-Doichain library. The goal is to fully cover the Doichain protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,2 +35,4 @@ import chai from 'chai' | ||
import getPrivateKeyFromWif from "../lib/getPrivateKeyFromWif" | ||
import getSignature from "../lib/getSignature" | ||
import verifySignature from "../lib/verifySignature" | ||
@@ -261,6 +263,6 @@ | ||
const wif = "cP3EigkzsWuyKEmxk8cC6qXYb4ZjwUo5vzvZpAPmDQ83RCgXQruj" | ||
const privateKeyOfBob2 = getPrivateKeyFromWif(wif,DOICHAIN_REGTEST) | ||
var keyPair = bitcoin.ECPair.fromWIF(wif,DOICHAIN_REGTEST) | ||
var publicKey = keyPair.publicKey.toString('hex') | ||
const privateKeyOfBob2 = getPrivateKeyFromWif(wif,DOICHAIN_REGTEST) | ||
@@ -287,3 +289,21 @@ /* function rng () { | ||
console.log(decryptedMessage2) | ||
chai.assert.equal(decryptedMessage2, message2, "encryption and decryption didn't work") | ||
}) | ||
it.only('create and verify a signature ', async () => { | ||
function rng () { | ||
return Buffer.from('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') | ||
} // get a much more secure random | ||
const keyPair = bitcoin.ECPair.makeRandom({ rng: rng }) | ||
keyPair.pu | ||
const message = "a basic test message" | ||
const signature = getSignature(message,keyPair) | ||
console.log('signature',signature) | ||
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }) | ||
console.log('address',address) | ||
const validSignature = verifySignature(message,address,signature) | ||
chai.assert.equal(true, validSignature, "signature not valid") | ||
}) | ||
}); |
195682
45
1187