diff --git a/src/cid.ts b/src/cid.ts index 6baa4a10..d8b626b6 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -1,4 +1,5 @@ import { base32 } from './bases/base32.js' +import { base36 } from './bases/base36.js' import { base58btc } from './bases/base58.js' import { coerce } from './bytes.js' import * as Digest from './hashes/digest.js' @@ -402,10 +403,14 @@ function parseCIDtoBytes { const hash = await sha256.digest(textEncoder.encode('abc')) const cid = CID.create(1, 112, hash) - const parsed = CID.parse(cid.toString()) + const parsed = CID.parse(cid.toString(base32)) + digestsame(cid, parsed) + }) + + it('parse 36 encoded CIDv1', async () => { + const hash = await sha256.digest(textEncoder.encode('abc')) + const cid = CID.create(1, 112, hash) + + const parsed = CID.parse(cid.toString(base36)) digestsame(cid, parsed) }) @@ -592,7 +601,7 @@ describe('CID', () => { const hash = await sha256.digest(textEncoder.encode('abc')) const cid = CID.create(1, 112, hash) const msg = - 'To parse non base32 or base58btc encoded CID multibase decoder must be provided' + 'To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided' assert.throws(() => CID.parse(cid.toString(base64)), msg) })