@zlattice/lattice-js
Version:
Lattice blockchain TypeScript SDK with dual module support (CJS + ESM)
55 lines • 2.46 kB
TypeScript
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
export declare const u8: (arr: TypedArray) => Uint8Array<ArrayBufferLike>;
export declare const u32: (arr: TypedArray) => Uint32Array<ArrayBufferLike>;
export declare const createView: (arr: TypedArray) => DataView<ArrayBufferLike>;
export declare const rotr: (word: number, shift: number) => number;
export declare const isLE: boolean;
/**
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
*/
export declare function bytesToHex(bytes: Uint8Array): string;
/**
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
*/
export declare function hexToBytes(hex: string): Uint8Array;
/**
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
*/
export declare function utf8ToBytes(str: string): Uint8Array;
export type Input = Uint8Array | string;
/**
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
* Warning: when Uint8Array is passed, it would NOT get copied.
* Keep in mind for future mutable operations.
*/
export declare function toBytes(data: Input): Uint8Array;
export declare abstract class Hash<T extends Hash<T>> {
abstract blockLen: number;
abstract outputLen: number;
abstract update(buf: Input): this;
abstract digestInto(buf: Uint8Array): void;
abstract digest(): Uint8Array;
/**
* Resets internal state. Makes Hash instance unusable.
* Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
* by user, they will need to manually call `destroy()` when zeroing is necessary.
*/
abstract destroy(): void;
/**
* Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`
* when no options are passed.
* Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal
* buffers are overwritten => causes buffer overwrite which is used for digest in some cases.
* There are no guarantees for clean-up because it's impossible in JS.
*/
abstract _cloneInto(to?: T): T;
clone(): T;
}
export type CHash = ReturnType<typeof wrapConstructor>;
export declare function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>): {
(msg: Input): Uint8Array;
outputLen: number;
blockLen: number;
create(): Hash<T>;
};
//# sourceMappingURL=utils.d.ts.map