integration: nonce is not shared
This commit is contained in:
parent
3bf4e27545
commit
b56bbce472
2 changed files with 9 additions and 8 deletions
|
@ -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)
|
- [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)
|
- [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 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)
|
- [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#L53)
|
- [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#L100)
|
- [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
|
## Projects utilizing BitcoinJS
|
||||||
|
|
|
@ -12,8 +12,8 @@ describe('bitcoinjs-lib (crypto)', function () {
|
||||||
var G = bitcoin.ECPair.curve.G
|
var G = bitcoin.ECPair.curve.G
|
||||||
var n = bitcoin.ECPair.curve.n
|
var n = bitcoin.ECPair.curve.n
|
||||||
|
|
||||||
function stealthSend (Q, nonce) {
|
function stealthSend (Q) {
|
||||||
var noncePair = new bitcoin.ECPair(bigi.fromBuffer(nonce))
|
var noncePair = bitcoin.ECPair.makeRandom()
|
||||||
var e = noncePair.d
|
var e = noncePair.d
|
||||||
var eQ = Q.multiply(e)
|
var eQ = Q.multiply(e)
|
||||||
var c = bigi.fromBuffer(bitcoin.crypto.sha256(eQ.getEncoded()))
|
var c = bigi.fromBuffer(bitcoin.crypto.sha256(eQ.getEncoded()))
|
||||||
|
@ -38,10 +38,11 @@ describe('bitcoinjs-lib (crypto)', function () {
|
||||||
|
|
||||||
// receiver private key
|
// receiver private key
|
||||||
var receiver = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss')
|
var receiver = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss')
|
||||||
var nonce = crypto.randomBytes(32)
|
|
||||||
|
|
||||||
var stealthS = stealthSend(receiver.Q, nonce)
|
var stealthS = stealthSend(receiver.Q) // public, done by sender
|
||||||
var stealthR = stealthReceive(receiver.d, stealthS.nonceQ)
|
// ... 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
|
// and check that we derived both sides correctly
|
||||||
assert.equal(stealthS.address, stealthR.keyPair.getAddress())
|
assert.equal(stealthS.address, stealthR.keyPair.getAddress())
|
||||||
|
|
Loading…
Reference in a new issue