@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
21 lines (20 loc) • 941 B
JavaScript
import { InvalidTransactionHashError } from "../../common/hash.js";
import { BlockchainLayer1Enum } from "../../union/enum/domain.js";
import { createLayer1fulValidator } from "../../common/common.js";
// Tezos transaction hashes are Base58 encoded strings, typically 51 characters long, starting with 'o'.
export const tezosTransactionHashRegexp = /^o[1-9A-HJ-NP-Za-km-z]{50}$/;
export function isTezosTransactionHash(raw) {
return tezosTransactionHashRegexp.test(raw);
}
export const tezosTransactionHashValidator = createLayer1fulValidator(BlockchainLayer1Enum.TEZOS, isTezosTransactionHash);
export function toTezosTransactionHash(raw) {
const safe = toTezosTransactionHashSafe(raw);
if (!safe)
throw new InvalidTransactionHashError(BlockchainLayer1Enum.TEZOS, raw);
return safe;
}
export function toTezosTransactionHashSafe(raw) {
if (isTezosTransactionHash(raw))
return raw;
return undefined;
}