@okcontract/sdk
Version:
One-stop-shop permissionless SDK for building any blockchain frontend
39 lines (38 loc) • 1.75 kB
TypeScript
export type ByteArray = Uint8Array;
export type Hex = `0x${string}`;
export declare function isHex(value: unknown, { strict }?: {
strict?: boolean;
}): value is Hex;
/**
* Encodes a UTF-8 string into a byte array.
*
* - Docs: https://viem.sh/docs/utilities/toBytes.html#stringtobytes
*
* @param value String to encode.
* @param opts Options.
* @returns Byte array value.
*
* @example
* import { stringToBytes } from 'viem'
* const data = stringToBytes('Hello world!')
* // Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
*
* @example
* import { stringToBytes } from 'viem'
* const data = stringToBytes('Hello world!', { size: 32 })
* // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
*/
export declare function stringToBytes(value: string): ByteArray;
export declare function encodeLabelHash(hash: Hex): `[${string}]`;
export declare function encodedLabelToLabelHash(label: string): Hex | null;
/**
* @description Hashes ENS label
*
* - Since ENS labels prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS labels](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `labelHash`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize.html) function for this.
*
* @example
* labelHash('eth')
* '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0'
*/
export declare function labelHash(label: string): `0x${string}`;
export declare function packetToBytes(packet: string): ByteArray;