merkle-reference
Version:
This is a TS library implementing [merkle reference] specification.
79 lines • 2.7 kB
TypeScript
export { base32 };
/**
* Multiformat code for the CIDv1.
* @see https://github.com/multiformats/multicodec/blob/352d05ad430713088e867216152725f581387bc8/table.csv#L3
*/
export const CID_CODE: 1;
/**
* Multiformat code for the merkle reference.
* @see https://github.com/multiformats/multicodec/pull/357
*/
export const CODE: 7;
/**
* @see https://github.com/multiformats/multicodec/blob/master/table.csv#L9
*/
export const SHA256_CODE: 18;
/**
* Sha256 multihash digest size is 32 bytes.
* @see https://github.com/multiformats/rust-multihash/blob/4c0ef5268355308d7f083482dad1c81318db4f6b/codetable/src/hasher_impl.rs#L207
*/
export const DIGEST_SIZE: 32;
export const PREFIX_SIZE: number;
/**
* Binary representation of the merkle reference is as follows
*
* ```ts
* [MerkleReference: 0x07,
* SHA256: 0x12,
* Size: 32,
* ...(Uint8Array & {length: 32})
* ]
* ```
*
* So first 3 bytes represent a header and next 32 bytes
* represent the body.
*/
export const SIZE: number;
export function is<T extends {} | null>(source: unknown | import("./lib.js").Reference<T>): source is import("./lib.js").Reference<T>;
export function fromDigest(digest: Uint8Array): Reference<unknown>;
export function toTree<T extends {} | null>(value: import("./lib.js").Reference<T>): import("./exports.js").Reference<T>;
export function fromString<T extends {} | null, Implicit extends {} | null = never>(source: string, implicit?: Implicit): import("./lib.js").Reference<T> | Implicit;
export function fromBytes(source: Uint8Array): Reference<unknown>;
export function toDigest(reference: import("./lib.js").Reference): Uint8Array<ArrayBufferLike>;
export function toBytes(reference: import("./lib.js").Reference): Uint8Array<ArrayBufferLike>;
export function toJSON(reference: import("./lib.js").Reference): {
'/': string;
};
export function fromJSON(json: {
"/": string;
}): Reference<unknown>;
export type View<T = unknown> = Reference<T>;
import { base32 } from 'multiformats/bases/base32';
/**
* @template T
*/
declare class Reference<T> {
/** @type {WeakMap<Uint8Array, Reference<unknown>>} */
static cache: WeakMap<Uint8Array, Reference<unknown>>;
/**
* @param {Uint8Array} digest
* @param {T} [of]
*/
constructor(digest: Uint8Array, of?: T);
toString(): string;
get multihash(): {
digest: Uint8Array<ArrayBuffer>;
code: number;
length: number;
};
get bytes(): Uint8Array<ArrayBuffer>;
get "/"(): Uint8Array<ArrayBuffer>;
get version(): number;
get code(): 7;
toJSON(): {
'/': string;
};
get [Symbol.toStringTag](): string;
#private;
}
//# sourceMappingURL=reference.d.ts.map