Compare commits

..

No commits in common. "master" and "addAsync" have entirely different histories.

4 changed files with 7492 additions and 84 deletions

View File

@ -1,29 +1,7 @@
3.1.1 / 2020-05-31
------------------
- Add safe-buffer as explicit dependency
3.1.0 / 2020-04-09
------------------
- Add async methods
3.0.0 / 2019-09-12
------------------
- Fixed backwards incompatible bug with passphrase NFC normalization
2.0.3 / 2019-05-22
------------------
- made compatible for Electron v4
2.0.2 / 2017-12-14
------------------
- use safe-buffer
- upgrade scryptsy
2.0.1 / 2017-04-20
------------------
- upgrade bs58check
- index: rm unused address parameter
2.0.0 / 2016-12-20
------------------
- removed class instantiation. Removed `coinstring` dep.

View File

@ -1,4 +1,3 @@
const BlueCrypto = require('react-native-blue-crypto');
var aes = require('browserify-aes')
var assert = require('assert')
var Buffer = require('safe-buffer').Buffer
@ -48,18 +47,6 @@ function getAddress (d, compressed) {
return bs58check.encode(payload)
}
async function scryptWrapper(secret, salt, N, r, p, dkLen, progressCallback, promiseInterval) {
if (BlueCrypto.isAvailable()) {
secret = Buffer.from(secret).toString('hex');
salt = Buffer.from(salt).toString('hex');
const hex = await BlueCrypto.scrypt(secret, salt, N, r, p, dkLen);
return Buffer.from(hex, 'hex');
} else {
// fallback to js implementation
return await scrypt.async(secret, salt, N, r, p, dkLen, progressCallback, promiseInterval);
}
}
function prepareEncryptRaw (buffer, compressed, passphrase, scryptParams) {
if (buffer.length !== 32) throw new Error('Invalid private key length')
@ -113,7 +100,7 @@ async function encryptRawAsync (buffer, compressed, passphrase, progressCallback
p
} = prepareEncryptRaw(buffer, compressed, passphrase, scryptParams)
var scryptBuf = await scryptWrapper(secret, salt, N, r, p, 64, progressCallback, promiseInterval)
var scryptBuf = await scrypt.async(secret, salt, N, r, p, 64, progressCallback, promiseInterval)
return finishEncryptRaw(buffer, compressed, salt, scryptBuf)
}
@ -185,7 +172,7 @@ function finishDecryptRaw (buffer, salt, compressed, scryptBuf) {
var d = BigInteger.fromBuffer(privateKey)
var address = getAddress(d, compressed)
var checksum = hash256(address).slice(0, 4)
assert.deepStrictEqual(salt, checksum, 'Invalid private key.')
assert.deepStrictEqual(salt, checksum)
return {
privateKey: privateKey,
@ -205,7 +192,7 @@ async function decryptRawAsync (buffer, passphrase, progressCallback, scryptPara
} = prepareDecryptRaw(buffer, progressCallback, scryptParams)
if (decryptEC === true) return decryptECMultAsync(buffer, passphrase, progressCallback, scryptParams, promiseInterval)
var scryptBuf = await scryptWrapper(passphrase.normalize('NFC'), salt, N, r, p, 64, progressCallback, promiseInterval)
var scryptBuf = await scrypt.async(passphrase.normalize('NFC'), salt, N, r, p, 64, progressCallback, promiseInterval)
return finishDecryptRaw(buffer, salt, compressed, scryptBuf)
}
@ -287,7 +274,7 @@ function getPassIntAndPoint (preFactor, ownerEntropy, hasLotSeq) {
passPoint: curve.G.multiply(passInt).getEncoded(true)
}
}
// async function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
function finishDecryptECMult (seedBPass, encryptedPart1, encryptedPart2, passInt, compressed) {
var derivedHalf1 = seedBPass.slice(0, 32)
var derivedHalf2 = seedBPass.slice(32, 64)
@ -335,27 +322,16 @@ async function decryptECMultAsync (buffer, passphrase, progressCallback, scryptP
p
} = prepareDecryptECMult(buffer, passphrase, progressCallback, scryptParams)
var preFactor = await scryptWrapper(passphrase, ownerSalt, N, r, p, 32, progressCallback, promiseInterval)
var preFactor = await scrypt.async(passphrase, ownerSalt, N, r, p, 32, progressCallback, promiseInterval)
const {
passInt,
passPoint
} = getPassIntAndPoint(preFactor, ownerEntropy, hasLotSeq)
var seedBPass = await scryptWrapper(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64, undefined, promiseInterval)
var seedBPass = await scrypt.async(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64, undefined, promiseInterval)
const res = finishDecryptECMult(seedBPass, encryptedPart1, encryptedPart2, passInt, compressed)
// added by overtorment: see https://github.com/bitcoinjs/bip38/issues/60
// verify salt matches address
var d = BigInteger.fromBuffer(res.privateKey)
var address = getAddress(d, compressed)
var checksum = hash256(address).slice(0, 4)
var salt = buffer.slice(2, 6)
assert.deepEqual(salt, checksum, 'Incorrect passphrase.')
return res
return finishDecryptECMult(seedBPass, encryptedPart1, encryptedPart2, passInt, compressed)
}
function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
@ -410,13 +386,12 @@ function verify (string) {
return true
}
// expose only async methods. they use fast BlueCrypto
module.exports = {
// decrypt: decrypt,
// decryptECMult: decryptECMult,
// decryptRaw: decryptRaw,
// encrypt: encrypt,
// encryptRaw: encryptRaw,
decrypt: decrypt,
decryptECMult: decryptECMult,
decryptRaw: decryptRaw,
encrypt: encrypt,
encryptRaw: encryptRaw,
decryptAsync: decryptAsync,
decryptECMultAsync: decryptECMultAsync,
decryptRawAsync: decryptRawAsync,

7479
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "bip38",
"version": "3.1.1",
"version": "3.1.0",
"description": "BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is impervious to brute force attacks thus protecting the user.",
"main": "index.js",
"keywords": [
@ -18,7 +18,6 @@
"buffer-xor": "^1.0.2",
"create-hash": "^1.1.1",
"ecurve": "^1.0.0",
"safe-buffer": "~5.1.1",
"scryptsy": "^2.1.0"
},
"devDependencies": {
@ -41,28 +40,5 @@
"standard": "standard",
"test": "npm run standard && npm run unit",
"unit": "mocha --ui bdd --timeout 240000"
},
"react-native": {
"path": "path-browserify",
"fs": "react-native-level-fs",
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify"
},
"browser": {
"path": "path-browserify",
"fs": "react-native-level-fs",
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify"
},
"peerDependencies": {
"react-native-blue-crypto": "*"
}
}