@anythread/gsoc
Version:
Graffiti Several Owner Chunk implementation on Swarm network
90 lines (89 loc) • 3.58 kB
TypeScript
import { Bytes, Data, HexString, PostageBatchId, PostageStamp, PrefixedHexString, SignerFn } from './types';
import { Utils } from '@nugaon/bmt-js';
export declare const keccak256Hash: typeof Utils.keccak256Hash;
export declare function getConsensualPrivateKey(resource: string | Uint8Array): Bytes<32>;
export declare function isPostageBatchId(value: unknown): value is PostageBatchId;
export declare function isPostageStamp(value: unknown): value is PostageStamp;
export declare function isStrictlyObject(value: unknown): value is Record<string, unknown>;
export declare function makeSigner(signer: SignerFn | Uint8Array | string | unknown): SignerFn;
/**
* @notice Returns true if the segment A is within proximity order minimum of B
* @param a 32 bytes.
* @param b 32 bytes.
* @param minimum Minimum proximity order.
*/
export declare function inProximity(a: Uint8Array, b: Uint8Array, minimum: number): boolean;
/**
* Type guard for `Bytes<T>` type
*
* @param b The byte array
* @param length The length of the byte array
*/
export declare function isBytes<Length extends number>(b: unknown, length: Length): b is Bytes<Length>;
/**
* Verifies if a byte array has a certain length
*
* @param b The byte array
* @param length The specified length
*/
export declare function assertBytes<Length extends number>(b: unknown, length: Length): asserts b is Bytes<Length>;
/**
* Helper function for serialize byte arrays
*
* @param arrays Any number of byte array arguments
*/
export declare function serializeBytes(...arrays: Uint8Array[]): Uint8Array;
/**
* Converts array of number or Uint8Array to HexString without prefix.
*
* @param bytes The input array
* @param len The length of the non prefixed HexString
*/
export declare function bytesToHex<Length extends number = number>(bytes: Uint8Array, len?: Length): HexString<Length>;
/**
* Converts integer number to hex string.
*
* Optionally provides '0x' prefix or padding
*
* @param int The positive integer to be converted
* @param len The length of the non prefixed HexString
*/
export declare function intToHex<Length extends number = number>(int: number, len?: Length): HexString<Length>;
/**
* Converts a hex string to Uint8Array
*
* @param hex string input without 0x prefix!
*/
export declare function hexToBytes<Length extends number, LengthHex extends number = number>(hex: HexString<LengthHex>): Bytes<Length>;
/**
* Type guard for HexStrings.
* Requires no 0x prefix!
*
* @param s string input
* @param len expected length of the HexString
*/
export declare function isHexString<Length extends number = number>(s: unknown, len?: number): s is HexString<Length>;
/**
* Type guard for PrefixedHexStrings.
* Does enforce presence of 0x prefix!
*
* @param s string input
*/
export declare function isPrefixedHexString(s: unknown): s is PrefixedHexString;
export declare function serializePayload(userPayload: unknown): Uint8Array;
export declare function deserializePayload(data: Uint8Array): unknown;
/**
* Creates unprefixed hex string from wide range of data.
*
* @param input
* @param len of the resulting HexString WITHOUT prefix!
*/
export declare function makeHexString<L extends number>(input: string | number | Uint8Array | unknown, len?: L): HexString<L>;
export declare function wrapBytesWithHelpers(data: Uint8Array): Data;
/**
* Returns true if two byte arrays are equal
*
* @param a Byte array to compare
* @param b Byte array to compare
*/
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;