bitcoin-address-validation
Advanced tools
Comparing version 0.2.9 to 1.0.0
@@ -7,3 +7,3 @@ 'use strict'; | ||
var bech32 = _interopDefault(require('bech32')); | ||
var hashSha256 = _interopDefault(require('hash.js/lib/hash/sha/256')); | ||
var sha = _interopDefault(require('sha.js')); | ||
var buffer = require('buffer'); | ||
@@ -13,3 +13,3 @@ | ||
const sha256 = payload => buffer.Buffer.from(hashSha256().update(payload).digest()); | ||
const sha256 = payload => buffer.Buffer.from(sha('sha256').update(payload).digest()); | ||
@@ -19,3 +19,3 @@ const addressTypes = { | ||
type: 'p2pkh', | ||
testnet: false | ||
network: 'mainnet' | ||
}, | ||
@@ -25,3 +25,3 @@ | ||
type: 'p2pkh', | ||
testnet: true | ||
network: 'testnet' | ||
}, | ||
@@ -31,3 +31,3 @@ | ||
type: 'p2sh', | ||
testnet: false | ||
network: 'mainnet' | ||
}, | ||
@@ -37,3 +37,3 @@ | ||
type: 'p2sh', | ||
testnet: true | ||
network: 'testnet' | ||
} | ||
@@ -51,3 +51,11 @@ }; | ||
if (!['bc', 'tb', 'bcrt'].includes(decoded.prefix)) { | ||
const prefixesNetwork = { | ||
bc: 'mainnet', | ||
tb: 'testnet', | ||
bcrt: 'regtest' | ||
}; | ||
const network = prefixesNetwork[decoded.prefix]; | ||
if (network === undefined) { | ||
return false; | ||
@@ -74,3 +82,3 @@ } | ||
bech32: true, | ||
testnet: decoded.prefix !== 'bc', | ||
network, | ||
address, | ||
@@ -87,5 +95,5 @@ type | ||
let decoded; | ||
let prefix = address.substr(0, 2); | ||
const prefix = address.substr(0, 2); | ||
if (prefix === 'bc' || prefix == 'tb') { | ||
if (prefix === 'bc' || prefix === 'tb') { | ||
return validateBech32(address); | ||
@@ -117,5 +125,17 @@ } | ||
return addressTypes[version] ? Object.assign({ address, bech32: false }, addressTypes[version]) : false; | ||
return addressTypes[version] | ||
? Object.assign({ address, bech32: false }, addressTypes[version]) | ||
: false; | ||
}; | ||
module.exports = validateBtcAddress; | ||
const strictValidation = (address, network) => { | ||
const validated = validateBtcAddress(address); | ||
if (!validated) return false; | ||
if (network) { | ||
if (validated.network !== network) return false; | ||
return true; | ||
} | ||
return validated; | ||
}; | ||
module.exports = strictValidation; |
import baseX from 'base-x'; | ||
import bech32 from 'bech32'; | ||
import hashSha256 from 'hash.js/lib/hash/sha/256'; | ||
import sha from 'sha.js'; | ||
import { Buffer } from 'buffer'; | ||
@@ -8,3 +8,3 @@ | ||
const sha256 = payload => Buffer.from(hashSha256().update(payload).digest()); | ||
const sha256 = payload => Buffer.from(sha('sha256').update(payload).digest()); | ||
@@ -14,3 +14,3 @@ const addressTypes = { | ||
type: 'p2pkh', | ||
testnet: false | ||
network: 'mainnet' | ||
}, | ||
@@ -20,3 +20,3 @@ | ||
type: 'p2pkh', | ||
testnet: true | ||
network: 'testnet' | ||
}, | ||
@@ -26,3 +26,3 @@ | ||
type: 'p2sh', | ||
testnet: false | ||
network: 'mainnet' | ||
}, | ||
@@ -32,3 +32,3 @@ | ||
type: 'p2sh', | ||
testnet: true | ||
network: 'testnet' | ||
} | ||
@@ -46,3 +46,11 @@ }; | ||
if (!['bc', 'tb', 'bcrt'].includes(decoded.prefix)) { | ||
const prefixesNetwork = { | ||
bc: 'mainnet', | ||
tb: 'testnet', | ||
bcrt: 'regtest' | ||
}; | ||
const network = prefixesNetwork[decoded.prefix]; | ||
if (network === undefined) { | ||
return false; | ||
@@ -69,3 +77,3 @@ } | ||
bech32: true, | ||
testnet: decoded.prefix !== 'bc', | ||
network, | ||
address, | ||
@@ -82,5 +90,5 @@ type | ||
let decoded; | ||
let prefix = address.substr(0, 2); | ||
const prefix = address.substr(0, 2); | ||
if (prefix === 'bc' || prefix == 'tb') { | ||
if (prefix === 'bc' || prefix === 'tb') { | ||
return validateBech32(address); | ||
@@ -112,5 +120,17 @@ } | ||
return addressTypes[version] ? Object.assign({ address, bech32: false }, addressTypes[version]) : false; | ||
return addressTypes[version] | ||
? Object.assign({ address, bech32: false }, addressTypes[version]) | ||
: false; | ||
}; | ||
export default validateBtcAddress; | ||
const strictValidation = (address, network) => { | ||
const validated = validateBtcAddress(address); | ||
if (!validated) return false; | ||
if (network) { | ||
if (validated.network !== network) return false; | ||
return true; | ||
} | ||
return validated; | ||
}; | ||
export default strictValidation; |
{ | ||
"name": "bitcoin-address-validation", | ||
"version": "0.2.9", | ||
"version": "1.0.0", | ||
"description": "Validate any Bitcoin address - Bech32, P2SH and P2PKH", | ||
@@ -36,2 +36,3 @@ "homepage": "https://github.com/ruigomeseu/bitcoin-address-validation", | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.3", | ||
"chai": "^4.2.0", | ||
@@ -45,3 +46,2 @@ "codecov": "^3.1.0", | ||
"eslint-plugin-react": "^7.11.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^6.1.4", | ||
@@ -58,4 +58,4 @@ "nyc": "^14.1.1", | ||
"bech32": "^1.1.3", | ||
"hash.js": "^1.1.7" | ||
"sha.js": "^2.4.11" | ||
} | ||
} |
@@ -9,3 +9,3 @@ ![](https://ruigomes.me/bitcoin-address-validation.png?v=1) | ||
[![npm](https://img.shields.io/npm/dt/bitcoin-address-validation.svg)](https://www.npmjs.com/package/bitcoin-address-validation) | ||
[![Twitter Follow](https://img.shields.io/twitter/follow/ruigomeseu.svg?style=social)](https://twitter.com/ruigomeseu) | ||
[![Twitter Follow](https://img.shields.io/twitter/follow/8bitgomes.svg?style=social)](https://twitter.com/8bitgomes) | ||
@@ -12,0 +12,0 @@ Validate Bitcoin addresses - Bech32, P2PKH and P2SH! Available for ES6 and Node.js. |
@@ -30,3 +30,3 @@ import nodeResolve from 'rollup-plugin-node-resolve'; | ||
'bech32', | ||
'hash.js/lib/hash/sha/256' | ||
'sha.js' | ||
], | ||
@@ -33,0 +33,0 @@ output: [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
99401
2981
0
+ Addedsha.js@^2.4.11
+ Addedsha.js@2.4.11(transitive)
- Removedhash.js@^1.1.7
- Removedhash.js@1.1.7(transitive)
- Removedminimalistic-assert@1.0.1(transitive)