From d2a20610cebf439a51df497f8109efd8c4aca230 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 3 Sep 2023 13:07:59 -0400 Subject: [PATCH] refactor: add optional raw parameter --- src/cid.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cid.ts b/src/cid.ts index 38f70c9..082854f 100644 --- a/src/cid.ts +++ b/src/cid.ts @@ -14,18 +14,21 @@ export function encodeCid( size: bigint, type?: number, hashType?: number, + raw?: boolean, ); export function encodeCid( hash: string, size: bigint, type?: number, hashType?: number, + raw?: boolean, ); export function encodeCid( hash: any, size: bigint, type = CID_TYPES.RAW, hashType = CID_HASH_TYPES.BLAKE3, + raw: boolean = false, ) { if (typeof hash === "string") { hash = edUtils.hexToBytes(hash); @@ -46,6 +49,11 @@ export function encodeCid( sizeView.setBigInt64(0, size, true); const prefixedHash = Uint8Array.from([type, hashType, ...hash, ...sizeBytes]); + + if (raw) { + return prefixedHash; + } + return base58btc.encode(prefixedHash).toString(); }