refactor: update encodeCid and decodeCid to use ErrTuple with a CID type
This commit is contained in:
parent
2a4a246799
commit
22ccc91566
|
@ -4,15 +4,16 @@ import {
|
||||||
encodeCid as encodeCidPortal,
|
encodeCid as encodeCidPortal,
|
||||||
} from "@lumeweb/libportal";
|
} from "@lumeweb/libportal";
|
||||||
import { addContextToErr } from "#err.js";
|
import { addContextToErr } from "#err.js";
|
||||||
|
import type { CID } from "@lumeweb/libportal";
|
||||||
|
|
||||||
export function encodeCid(hash: Uint8Array, size: bigint): any;
|
export function encodeCid(hash: Uint8Array, size: bigint): ErrTuple<string>;
|
||||||
export function encodeCid(hash: string, size: bigint): any;
|
export function encodeCid(hash: string, size: bigint): ErrTuple<string>;
|
||||||
export function encodeCid(
|
export function encodeCid(
|
||||||
hash: any,
|
hash: any,
|
||||||
size: bigint,
|
size: bigint,
|
||||||
type?: number,
|
type?: number,
|
||||||
hashType?: number,
|
hashType?: number,
|
||||||
): ErrTuple {
|
): ErrTuple<CID> {
|
||||||
try {
|
try {
|
||||||
return [encodeCidPortal(hash, size, type, hashType), null];
|
return [encodeCidPortal(hash, size, type, hashType), null];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -20,7 +21,7 @@ export function encodeCid(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeCid(cid: string): ErrTuple {
|
export function decodeCid(cid: string): ErrTuple<CID> {
|
||||||
try {
|
try {
|
||||||
return [decodeCidPortal(cid), null];
|
return [decodeCidPortal(cid), null];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue