Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 6c5a137

Browse files
Alan Shawvmx
Alan Shaw
authored andcommitted
docs: add docs on multibaseName value for v1 CIDs
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 2f854c7 commit 6c5a137

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ instance. Returns true if valid, false if not valid.
121121

122122
`multihash` must be a `Buffer` instance of a valid [multihash](https://github.com/multiformats/multihash).
123123

124-
`multibaseName` optional string. Must be a valid [multibase](https://github.com/multiformats/multibase/blob/master/multibase.csv) name. Default is `base58btc`.
124+
`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.
125125

126126
### new CID(baseEncodedString)
127127

@@ -169,7 +169,12 @@ Returns the CID encoded in version 1.
169169

170170
#### cid.toBaseEncodedString(base=this.multibaseName)
171171

172-
Returns a base encodec string of the CID. Defaults to the base encoding in `this.multibaseName`
172+
Returns a base encoded string of the CID. Defaults to the base encoding in `this.multibaseName`.
173+
174+
The value of `this.multibaseName` depends on how the instance was constructed:
175+
176+
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.
177+
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.
173178

174179
#### cid.toString(base=this.multibaseName)
175180

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CID {
4646
* -> construct CID by parts
4747
* ```
4848
*
49-
* @param {string|Buffer} version
49+
* @param {string|Buffer|CID} version
5050
* @param {string} [codec]
5151
* @param {Buffer} [multihash]
5252
* @param {string} [multibaseName]

0 commit comments

Comments
 (0)