integration: nonce is not shared

This commit is contained in:
Daniel Cousens 2015-08-18 16:12:54 +10:00
parent 3bf4e27545
commit b56bbce472
2 changed files with 9 additions and 8 deletions

View file

@ -98,9 +98,9 @@ The below examples are implemented as integration tests, they should be very eas
- [Create a 2-of-3 multisig P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/multisig.js#L8)
- [Spend from a 2-of-4 multisig P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/multisig.js#L22)
- [Generate a single-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L7)
- [Generate a dual-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L51)
- [Recover a BIP32 parent private key from the parent public key and a derived non-hardened child private key](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L53)
- [Recover a Private key from duplicate R values in a signature](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L100)
- [Generate a dual-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L52)
- [Recover a BIP32 parent private key from the parent public key and a derived non-hardened child private key](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L54)
- [Recover a Private key from duplicate R values in a signature](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L101)
## Projects utilizing BitcoinJS

View file

@ -12,8 +12,8 @@ describe('bitcoinjs-lib (crypto)', function () {
var G = bitcoin.ECPair.curve.G
var n = bitcoin.ECPair.curve.n
function stealthSend (Q, nonce) {
var noncePair = new bitcoin.ECPair(bigi.fromBuffer(nonce))
function stealthSend (Q) {
var noncePair = bitcoin.ECPair.makeRandom()
var e = noncePair.d
var eQ = Q.multiply(e)
var c = bigi.fromBuffer(bitcoin.crypto.sha256(eQ.getEncoded()))
@ -38,10 +38,11 @@ describe('bitcoinjs-lib (crypto)', function () {
// receiver private key
var receiver = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss')
var nonce = crypto.randomBytes(32)
var stealthS = stealthSend(receiver.Q, nonce)
var stealthR = stealthReceive(receiver.d, stealthS.nonceQ)
var stealthS = stealthSend(receiver.Q) // public, done by sender
// ... sender now reveals nonceQ to receiver
var stealthR = stealthReceive(receiver.d, stealthS.nonceQ) // private, done by receiver
// and check that we derived both sides correctly
assert.equal(stealthS.address, stealthR.keyPair.getAddress())