Skip to content

Commit 038c0f0

Browse files
authored
Merge pull request bitcoinjs#456 from bitcoinjs/nomessage
Remove message module
2 parents 80b1b50 + de6671e commit 038c0f0

File tree

9 files changed

+5
-437
lines changed

9 files changed

+5
-437
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ The below examples are implemented as integration tests, they should be very eas
100100

101101
- [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L9)
102102
- [Generate a address from a SHA256 hash](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L20)
103-
- [Generate a address and WIF for Litecoin](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L30)
104-
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L44)
105-
- [Create a Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L51)
106-
- [Sign a Bitcoin message](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/advanced.js#L8)
107-
- [Verify a Bitcoin message](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/advanced.js#L16)
103+
- [Generate a address and WIF for Litecoin](https://github.com/bitcoin/bitcoinjs-lib/blob/master/test/integration/basic.js#L29)
104+
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L43)
105+
- [Create a Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/basic.js#L50)
108106
- [Create an OP RETURN transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/advanced.js#L24)
109107
- [Create a 2-of-3 multisig P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/multisig.js#L9)
110108
- [Spend from a 2-of-4 multisig P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/multisig.js#L25)

src/ecdsa.js

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -154,93 +154,8 @@ function verify (hash, signature, Q) {
154154
return v.equals(r)
155155
}
156156

157-
/**
158-
* Recover a public key from a signature.
159-
*
160-
* See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
161-
* Key Recovery Operation".
162-
*
163-
* http://www.secg.org/download/aid-780/sec1-v2.pdf
164-
*/
165-
function recoverPubKey (e, signature, i) {
166-
typeforce(types.tuple(
167-
types.BigInt,
168-
types.ECSignature,
169-
types.UInt2
170-
), arguments)
171-
172-
var n = secp256k1.n
173-
var G = secp256k1.G
174-
var r = signature.r
175-
var s = signature.s
176-
177-
if (r.signum() <= 0 || r.compareTo(n) >= 0) throw new Error('Invalid r value')
178-
if (s.signum() <= 0 || s.compareTo(n) >= 0) throw new Error('Invalid s value')
179-
180-
// A set LSB signifies that the y-coordinate is odd
181-
var isYOdd = i & 1
182-
183-
// The more significant bit specifies whether we should use the
184-
// first or second candidate key.
185-
var isSecondKey = i >> 1
186-
187-
// 1.1 Let x = r + jn
188-
var x = isSecondKey ? r.add(n) : r
189-
var R = secp256k1.pointFromX(isYOdd, x)
190-
191-
// 1.4 Check that nR is at infinity
192-
var nR = R.multiply(n)
193-
if (!secp256k1.isInfinity(nR)) throw new Error('nR is not a valid curve point')
194-
195-
// Compute r^-1
196-
var rInv = r.modInverse(n)
197-
198-
// Compute -e from e
199-
var eNeg = e.negate().mod(n)
200-
201-
// 1.6.1 Compute Q = r^-1 (sR - eG)
202-
// Q = r^-1 (sR + -eG)
203-
var Q = R.multiplyTwo(s, G, eNeg).multiply(rInv)
204-
205-
secp256k1.validate(Q)
206-
207-
return Q
208-
}
209-
210-
/**
211-
* Calculate pubkey extraction parameter.
212-
*
213-
* When extracting a pubkey from a signature, we have to
214-
* distinguish four different cases. Rather than putting this
215-
* burden on the verifier, Bitcoin includes a 2-bit value with the
216-
* signature.
217-
*
218-
* This function simply tries all four cases and returns the value
219-
* that resulted in a successful pubkey recovery.
220-
*/
221-
function calcPubKeyRecoveryParam (e, signature, Q) {
222-
typeforce(types.tuple(
223-
types.BigInt,
224-
types.ECSignature,
225-
types.ECPoint
226-
), arguments)
227-
228-
for (var i = 0; i < 4; i++) {
229-
var Qprime = recoverPubKey(e, signature, i)
230-
231-
// 1.6.2 Verify Q
232-
if (Qprime.equals(Q)) {
233-
return i
234-
}
235-
}
236-
237-
throw new Error('Unable to find valid recovery factor')
238-
}
239-
240157
module.exports = {
241-
calcPubKeyRecoveryParam: calcPubKeyRecoveryParam,
242158
deterministicGenerateK: deterministicGenerateK,
243-
recoverPubKey: recoverPubKey,
244159
sign: sign,
245160
verify: verify,
246161

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = {
99
address: require('./address'),
1010
bufferutils: require('./bufferutils'),
1111
crypto: require('./crypto'),
12-
message: require('./message'),
1312
networks: require('./networks'),
1413
opcodes: require('./opcodes.json'),
1514
script: require('./script')

src/message.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/ecdsa.js

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
var assert = require('assert')
44
var bcrypto = require('../src/crypto')
55
var ecdsa = require('../src/ecdsa')
6-
var message = require('../src/message')
7-
var networks = require('../src/networks')
86
var sinon = require('sinon')
97

108
var BigInteger = require('bigi')
@@ -83,55 +81,6 @@ describe('ecdsa', function () {
8381
})
8482
})
8583

86-
describe('recoverPubKey', function () {
87-
fixtures.valid.ecdsa.forEach(function (f) {
88-
it('recovers the pubKey for ' + f.d, function () {
89-
var d = BigInteger.fromHex(f.d)
90-
var Q = curve.G.multiply(d)
91-
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
92-
var h1 = bcrypto.sha256(f.message)
93-
var e = BigInteger.fromBuffer(h1)
94-
var Qprime = ecdsa.recoverPubKey(e, signature, f.i)
95-
96-
assert(Qprime.equals(Q))
97-
})
98-
})
99-
100-
describe('with i ∈ {0,1,2,3}', function () {
101-
var hash = message.magicHash('1111', networks.bitcoin)
102-
var e = BigInteger.fromBuffer(hash)
103-
104-
var signatureBuffer = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64')
105-
var signature = ECSignature.parseCompact(signatureBuffer).signature
106-
var points = [
107-
'03e3a8c44a8bf712f1fbacee274fb19c0239b1a9e877eff0075ea335f2be8ff380',
108-
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
109-
'03d49e765f0bc27525c51a1b98fb1c99dacd59abe85a203af90f758260550b56c5',
110-
'027eea09d46ac7fb6aa2e96f9c576677214ffdc238eb167734a9b39d1eb4c3d30d'
111-
]
112-
113-
points.forEach(function (expectedHex, i) {
114-
it('recovers an expected point for i of ' + i, function () {
115-
var Qprime = ecdsa.recoverPubKey(e, signature, i)
116-
var QprimeHex = Qprime.getEncoded().toString('hex')
117-
118-
assert.strictEqual(QprimeHex, expectedHex)
119-
})
120-
})
121-
})
122-
123-
fixtures.invalid.recoverPubKey.forEach(function (f) {
124-
it('throws on ' + f.description + ' (' + f.exception + ')', function () {
125-
var e = BigInteger.fromHex(f.e)
126-
var signature = new ECSignature(new BigInteger(f.signatureRaw.r, 16), new BigInteger(f.signatureRaw.s, 16))
127-
128-
assert.throws(function () {
129-
ecdsa.recoverPubKey(e, signature, f.i)
130-
}, new RegExp(f.exception))
131-
})
132-
})
133-
})
134-
13584
describe('sign', function () {
13685
fixtures.valid.ecdsa.forEach(function (f) {
13786
it('produces a deterministic signature for "' + f.message + '"', function () {

test/fixtures/ecdsa.json

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -125,78 +125,6 @@
125125
]
126126
},
127127
"invalid": {
128-
"recoverPubKey": [
129-
{
130-
"description": "Invalid r value (< 0)",
131-
"exception": "Invalid r value",
132-
"e": "01",
133-
"signatureRaw": {
134-
"r": "-01",
135-
"s": "02"
136-
},
137-
"i": 0
138-
},
139-
{
140-
"description": "Invalid r value (== 0)",
141-
"exception": "Invalid r value",
142-
"e": "01",
143-
"signatureRaw": {
144-
"r": "00",
145-
"s": "02"
146-
},
147-
"i": 0
148-
},
149-
{
150-
"description": "Invalid s value (< 0)",
151-
"exception": "Invalid s value",
152-
"e": "01",
153-
"signatureRaw": {
154-
"r": "02",
155-
"s": "-01"
156-
},
157-
"i": 0
158-
},
159-
{
160-
"description": "Invalid s value (== 0)",
161-
"exception": "Invalid s value",
162-
"e": "01",
163-
"signatureRaw": {
164-
"r": "02",
165-
"s": "00"
166-
},
167-
"i": 0
168-
},
169-
{
170-
"description": "Invalid r value (nR is infinity)",
171-
"exception": "nR is not a valid curve point",
172-
"e": "01",
173-
"signatureRaw": {
174-
"r": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
175-
"s": "01"
176-
},
177-
"i": 0
178-
},
179-
{
180-
"description": "Invalid curve point",
181-
"exception": "Point is not on the curve",
182-
"e": "01",
183-
"signatureRaw": {
184-
"r": "4b3b4ca85a86c47a098a223fffffffff",
185-
"s": "01"
186-
},
187-
"i": 0
188-
},
189-
{
190-
"description": "Invalid i value (> 3)",
191-
"exception": "Expected property \"2\" of type UInt2, got Number 4",
192-
"e": "01",
193-
"signatureRaw": {
194-
"r": "00",
195-
"s": "02"
196-
},
197-
"i": 4
198-
}
199-
],
200128
"verify": [
201129
{
202130
"description": "The wrong signature",

0 commit comments

Comments
 (0)