fix: if has is a CID, override arguments with the CID properties unless we have an argument set already
This commit is contained in:
parent
f74ee39b9a
commit
2c56658a6c
15
src/cid.ts
15
src/cid.ts
|
@ -22,13 +22,26 @@ export function encodeCid(
|
||||||
hashType?: number,
|
hashType?: number,
|
||||||
raw?: boolean,
|
raw?: boolean,
|
||||||
): ErrTuple<string | Uint8Array>;
|
): ErrTuple<string | Uint8Array>;
|
||||||
|
export function encodeCid(
|
||||||
|
hash: CID,
|
||||||
|
size?: bigint,
|
||||||
|
type?: number,
|
||||||
|
hashType?: number,
|
||||||
|
raw?: boolean,
|
||||||
|
): ErrTuple<string | Uint8Array>;
|
||||||
export function encodeCid(
|
export function encodeCid(
|
||||||
hash: any,
|
hash: any,
|
||||||
size: bigint,
|
size?: bigint,
|
||||||
type?: number,
|
type?: number,
|
||||||
hashType?: number,
|
hashType?: number,
|
||||||
raw: boolean = false,
|
raw: boolean = false,
|
||||||
): ErrTuple<string | Uint8Array> {
|
): ErrTuple<string | Uint8Array> {
|
||||||
|
if (typeof hash !== "string" && !(hash instanceof Uint8Array)) {
|
||||||
|
size = hash.size;
|
||||||
|
type = type ?? hash.type;
|
||||||
|
hashType = hashType ?? hash.type;
|
||||||
|
hash = hash.hash;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return [encodeCidPortal(hash, size, type, hashType, raw), null];
|
return [encodeCidPortal(hash, size, type, hashType, raw), null];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue