UNPKG

@rarible/types

Version:

`@rarible/types` is a TypeScript library that provides type definitions and interfaces for the Rarible ecosystem. This package is designed to facilitate seamless integration with Rarible's APIs and services, ensuring type safety and improved developer exp

26 lines (25 loc) 993 B
import { randomBinary } from "../../../common/binary/index.js"; import { InvalidAddressError } from "../../common/address.js"; import { createLayer1fulValidator } from "../../common/common.js"; import { BlockchainLayer1Enum } from "../../union/enum/domain.js"; // example: 0x01658d9b94068f3c export const flowAddressRegExp = new RegExp(/^0*x*[0-9a-f]{16}$/); export function isFlowAddress(x) { return flowAddressRegExp.test(x); } export const flowAddressValidator = createLayer1fulValidator(BlockchainLayer1Enum.FLOW, isFlowAddress); export function toFlowAddress(value) { const safe = toFlowAddressSafe(value); if (!safe) throw new InvalidAddressError(BlockchainLayer1Enum.FLOW, value); return safe; } export function toFlowAddressSafe(raw) { if (isFlowAddress(raw)) return raw; return undefined; } export const FLOW_ZERO_ADDRESS = toFlowAddress("0x0000000000000000"); export function randomFlowAddress() { return toFlowAddress(randomBinary(8)); }