forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly serialize CID instances (ipfs#906)
The CID version agnostic tests ipfs-inactive/interface-js-ipfs-core#413 identified some functions were not properly serializing CID instances. This PR adds `cleanCID` step to several functions and also updates the `cleanCID` function to not assume buffer CIDs are CIDv0 multihashes. depends on ipfs-inactive/interface-js-ipfs-core#413 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * fix: disable just the rule we're breaking License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * chore: update dependencies License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * fix: skip test that go-ipfs cannot pass License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
- Loading branch information
Showing
6 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
'use strict' | ||
|
||
const bs58 = require('bs58') | ||
const CID = require('cids') | ||
|
||
module.exports = function (cid) { | ||
if (Buffer.isBuffer(cid)) { | ||
cid = bs58.encode(cid) | ||
return new CID(cid).toString() | ||
} | ||
if (CID.isCID(cid)) { | ||
cid = cid.toBaseEncodedString() | ||
return cid.toString() | ||
} | ||
if (typeof cid !== 'string') { | ||
throw new Error('unexpected cid type: ' + typeof cid) | ||
} | ||
CID.validateCID(new CID(cid.split('/')[0])) | ||
new CID(cid.split('/')[0]) // eslint-disable-line no-new | ||
return cid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters