cashaddrjs
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "cashaddrjs", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Bitcoin Cash cashaddr address format support for Node.js and web browsers.", | ||
@@ -8,3 +8,4 @@ "main": "src/cashaddr.js", | ||
"build": "sh scripts/build.sh", | ||
"test": "NODE_PATH=$NODE_PATH:.. npx mocha --timeout 15000", | ||
"test": "NODE_PATH=$NODE_PATH:.. nyc --reporter=html --reporter=text npx mocha --timeout 15000", | ||
"coveralls": "npx nyc report --reporter=text-lcov | npx coveralls", | ||
"docs": "sh scripts/docs.sh" | ||
@@ -37,2 +38,3 @@ }, | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.13.1", | ||
@@ -43,2 +45,3 @@ "http-server": "^0.10.0", | ||
"mocha-eslint": "^4.1.0", | ||
"nyc": "^11.4.1", | ||
"random-js": "^1.0.8", | ||
@@ -45,0 +48,0 @@ "uglify-es": "^3.2.2", |
# CashAddr.js: The new Bitcoin Cash address format for Node.js and web browsers. | ||
[![Build Status](https://travis-ci.org/bitcoincashjs/cashaddrjs.svg?branch=master)](https://travis-ci.com/bitcoincashjs/cashaddrjs) | ||
[![Build Status](https://travis-ci.org/bitcoincashjs/cashaddrjs.svg?branch=master)](https://travis-ci.org/bitcoincashjs/cashaddrjs) [![Coverage Status](https://coveralls.io/repos/github/bitcoincashjs/cashaddrjs/badge.svg?branch=master)](https://coveralls.io/github/bitcoincashjs/cashaddrjs?branch=master) | ||
JavaScript implementation for the new CashAddr address format for Bitcoin Cash. Compliant with the original CashAddr [specification](https://github.com/Bitcoin-UAHF/spec/blob/master/cashaddr.md) which improves upon [BIP 173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki). | ||
[![NPM](https://nodei.co/npm/cashaddrjs.png?downloads=true)](https://nodei.co/npm/cashaddrjs/) | ||
JavaScript implementation for the new CashAddr address format for Bitcoin Cash. | ||
Compliant with the original CashAddr [specification](https://github.com/Bitcoin-UAHF/spec/blob/master/cashaddr.md) which improves upon [BIP 173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki). | ||
## Installation | ||
`$ npm install --save cashaddrjs` | ||
```s | ||
$ npm install --save cashaddrjs | ||
``` | ||
@@ -46,3 +52,3 @@ ## Usage | ||
... | ||
<script src="https://cdn.rawgit.com/bitcoincashjs/cashaddrjs/master/dist/cashaddrjs-0.1.0.min.js"></script> | ||
<script src="https://cdn.rawgit.com/bitcoincashjs/cashaddrjs/master/dist/cashaddrjs-0.1.1.min.js"></script> | ||
</head> | ||
@@ -57,3 +63,3 @@ ... | ||
``` | ||
```s | ||
$ npm run docs | ||
@@ -60,0 +66,0 @@ ``` |
@@ -45,3 +45,3 @@ // https://github.com/bitcoincashjs/cashaddr | ||
const [versionByte, ...hash] = convertBits(payload.slice(0, -8), 5, 8, true); | ||
ensure(getHashSize(versionByte) === hash.length, `Invalid hash length: ${address}.`); | ||
ensure(getHashSize(versionByte) === hash.length * 8, `Invalid hash size: ${address}.`); | ||
const type = getType(versionByte); | ||
@@ -94,3 +94,3 @@ return { prefix, type, hash }; | ||
function getType(versionByte) { | ||
switch (versionByte & 8) { | ||
switch (versionByte & 120) { | ||
case 0: | ||
@@ -101,3 +101,3 @@ return 'P2KH'; | ||
default: | ||
throw new Error(`Invalid version byte: ${versionByte}.`); | ||
throw new Error(`Invalid address type in version byte: ${versionByte}.`); | ||
} | ||
@@ -131,3 +131,3 @@ } | ||
default: | ||
throw new Error(`Invalid hash length: ${hash.length}.`); | ||
throw new Error(`Invalid hash size: ${hash.length}.`); | ||
} | ||
@@ -145,19 +145,19 @@ } | ||
case 0: | ||
return 20; | ||
return 160; | ||
case 1: | ||
return 24; | ||
return 192; | ||
case 2: | ||
return 28; | ||
return 224; | ||
case 3: | ||
return 32; | ||
return 256; | ||
case 4: | ||
return 40; | ||
return 320; | ||
case 5: | ||
return 48; | ||
return 384; | ||
case 6: | ||
return 56; | ||
return 448; | ||
case 7: | ||
return 64; | ||
return 512; | ||
default: | ||
throw new Error(`Invalid version byte: ${versionByte}.`); | ||
throw new Error(`Invalid hash size in version byte: ${versionByte}.`); | ||
} | ||
@@ -164,0 +164,0 @@ } |
@@ -6,3 +6,3 @@ // https://github.com/bitcoincashjs/cashaddr | ||
module.exports = (condition, message = 'Precondition failed.') => { | ||
module.exports = (condition, message) => { | ||
if (!condition) { | ||
@@ -9,0 +9,0 @@ throw new Error(message); |
@@ -49,2 +49,8 @@ // https://github.com/bitcoincashjs/cashaddr | ||
describe('#encode()', () => { | ||
it('should fail on an invalid type', () => { | ||
assert.throws(() => { | ||
cashaddr.encode(NETWORKS[0], 'some invalid type', []); | ||
}); | ||
}); | ||
it('should fail on hashes of invalid length', () => { | ||
@@ -74,7 +80,6 @@ for (let size of VALID_SIZES) { | ||
describe('#decode()', () => { | ||
it('should decode a valid address regardless of case', () => { | ||
assert.deepEqual( | ||
cashaddr.decode('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a').hash, | ||
cashaddr.decode('BITCOINCASH:QPM2QSZNHKS23Z7629MMS6S4CWEF74VCWVY22GDX6A').hash | ||
); | ||
it('should fail when the version byte is invalid', () => { | ||
assert.throws(() => { | ||
cashaddr.decode('bitcoincash:zpm2qsznhks23z7629mms6s4cwef74vcwvrqekrq9w'); | ||
}); | ||
}); | ||
@@ -88,2 +93,9 @@ | ||
it('should decode a valid address regardless of case', () => { | ||
assert.deepEqual( | ||
cashaddr.decode('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a').hash, | ||
cashaddr.decode('BITCOINCASH:QPM2QSZNHKS23Z7629MMS6S4CWEF74VCWVY22GDX6A').hash | ||
); | ||
}); | ||
it('should fail when decoding for a different network', () => { | ||
@@ -90,0 +102,0 @@ for (let network of NETWORKS) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1086072
44
1322
69
16