Comparing version 0.6.0 to 0.7.0
@@ -0,1 +1,25 @@ | ||
<a name="0.7.0"></a> | ||
# [0.7.0](https://github.com/multiformats/js-cid/compare/v0.6.0...v0.7.0) (2019-05-09) | ||
### Bug Fixes | ||
* broken link to contributing document ([c29d12e](https://github.com/multiformats/js-cid/commit/c29d12e)) | ||
* update typedefs to reflect API changes ([63cd5f3](https://github.com/multiformats/js-cid/commit/63cd5f3)), closes [#77](https://github.com/multiformats/js-cid/issues/77) | ||
### Code Refactoring | ||
* default to base32 encoding for v1 CIDs ([2f854c7](https://github.com/multiformats/js-cid/commit/2f854c7)) | ||
### BREAKING CHANGES | ||
* The default string encoding for v1 CIDs has changed from base58btc to base32. | ||
License: MIT | ||
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> | ||
<a name="0.6.0"></a> | ||
@@ -2,0 +26,0 @@ # [0.6.0](https://github.com/multiformats/js-cid/compare/v0.5.8...v0.6.0) (2019-04-08) |
{ | ||
"name": "cids", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "CID Implementation in JavaScript", | ||
@@ -39,3 +39,3 @@ "leadMaintainer": "Volker Mische <volker.mische@gmail.com>", | ||
"multibase": "~0.6.0", | ||
"multicodec": "~0.5.0", | ||
"multicodec": "~0.5.1", | ||
"multihashes": "~0.4.14" | ||
@@ -48,3 +48,3 @@ }, | ||
"multihashing": "~0.3.3", | ||
"multihashing-async": "~0.5.2" | ||
"multihashing-async": "~0.7.0" | ||
}, | ||
@@ -61,2 +61,4 @@ "engines": { | ||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>", | ||
"Henrique Dias <hacdias@gmail.com>", | ||
"Irakli Gozalishvili <contact@gozala.io>", | ||
"Irakli Gozalishvili <rfobic@gmail.com>", | ||
@@ -63,0 +65,0 @@ "Mikeal Rogers <mikeal.rogers@gmail.com>", |
@@ -62,9 +62,9 @@ # js-cid | ||
const cid = new CID('zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY') | ||
const cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu') | ||
cid.version // 1 | ||
cid.codec // 'dag-pb' | ||
cid.multibaseName // 'base58btc' | ||
cid.multibaseName // 'base32' | ||
cid.toString() | ||
// 'zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY' | ||
// 'bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu' | ||
``` | ||
@@ -78,16 +78,15 @@ | ||
multihashing(Buffer.from('OMG!'), 'sha2-256', (err, hash) => { | ||
const cid = new CID(1, 'dag-pb', hash) | ||
console.log(cid.toString()) | ||
// zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY | ||
}) | ||
const hash = await multihashing(Buffer.from('OMG!'), 'sha2-256') | ||
const cid = new CID(1, 'dag-pb', hash) | ||
console.log(cid.toString()) | ||
// bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu | ||
``` | ||
The string form of CIDs currently defaults to `base58btc` flavour. (This is [soon to change to `base32`](https://github.com/ipfs/ipfs/issues/337). When creating a new instance you can optionally specify the default multibase to use when calling `toBaseEncodedString()` or `toString()` | ||
The string form of v1 CIDs defaults to `base32` encoding (v0 CIDs are always `base58btc` encoded). When creating a new instance you can optionally specify the default multibase to use when calling `toBaseEncodedString()` or `toString()` | ||
```js | ||
const cid = new CID(1, 'raw', hash, 'base32') | ||
const cid = new CID(1, 'raw', hash, 'base64') | ||
console.log(cid.toString()) | ||
// bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu | ||
// mAXASIN69ets85WVE0ipva5M5b2mAqAZ8LME08PeAG2MxCSuV | ||
``` | ||
@@ -98,5 +97,6 @@ | ||
```js | ||
const cid = new CID('bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy') | ||
// e.g. a base64url encoded CID | ||
const cid = new CID('uAXASIHJSUj5lkfuP5VPWf_VahvhARLRqPkF24QxY-lKaSqvV') | ||
cid.toString() | ||
// bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy | ||
// uAXASIHJSUj5lkfuP5VPWf_VahvhARLRqPkF24QxY-lKaSqvV | ||
``` | ||
@@ -127,3 +127,3 @@ | ||
`multibaseName` optional string. Must be a valid [multibase](https://github.com/multiformats/multibase/blob/master/multibase.csv) name. Default is `base58btc`. | ||
`multibaseName` optional string. Must be a valid [multibase](https://github.com/multiformats/multibase/blob/master/multibase.csv) name. Default is `base58btc` for v0 CIDs or `base32` for v1 CIDs. | ||
@@ -176,4 +176,9 @@ ### new CID(baseEncodedString) | ||
Returns a base encodec string of the CID. Defaults to the base encoding in `this.multibaseName` | ||
Returns a base encoded string of the CID. Defaults to the base encoding in `this.multibaseName`. | ||
The value of `this.multibaseName` depends on how the instance was constructed: | ||
1. If the CID was constructed from an object that already had a multibase (a string or an existing CID) then it retains that base. | ||
2. If the CID was constructed from an object that _did not_ have a multibase (a buffer, or by passing only version + codec + multihash to the constructor), then `multibaseName` will be `base58btc` for a v0 CID or `base32` for a v1 CID. | ||
#### cid.toString(base=this.multibaseName) | ||
@@ -194,3 +199,3 @@ | ||
Check out our [contributing document](https://github.com/ipfs/community/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). | ||
Check out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). | ||
@@ -197,0 +202,0 @@ Small note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification. |
@@ -49,3 +49,3 @@ 'use strict' | ||
* | ||
* @param {string|Buffer} version | ||
* @param {string|Buffer|CID} version | ||
* @param {string} [codec] | ||
@@ -63,3 +63,3 @@ * @param {Buffer} [multihash] | ||
*/ | ||
constructor (version, codec, multihash, multibaseName = 'base58btc') { | ||
constructor (version, codec, multihash, multibaseName) { | ||
if (module.exports.isCID(version)) { | ||
@@ -100,3 +100,3 @@ // version is an exising CID instance | ||
const v = parseInt(firstByte.toString('hex'), 16) | ||
if (v === 0 || v === 1) { | ||
if (v === 1) { | ||
// version is a CID buffer | ||
@@ -107,3 +107,3 @@ const cid = version | ||
this.multihash = multicodec.rmPrefix(cid.slice(1)) | ||
this.multibaseName = (v === 0) ? 'base58btc' : multibaseName | ||
this.multibaseName = 'base32' | ||
} else { | ||
@@ -140,3 +140,3 @@ // version is a raw multihash buffer, so v0 | ||
*/ | ||
this.multibaseName = multibaseName | ||
this.multibaseName = multibaseName || (version === 0 ? 'base58btc' : 'base32') | ||
@@ -143,0 +143,0 @@ CID.validateCID(this) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
802879
6107
201
Updatedmulticodec@~0.5.1