@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) • 926 B
JavaScript
import { createLayer1fulValidator } from "../../common/common.js";
import { InvalidTransactionHashError } from "../../common/hash.js";
import { BlockchainLayer1Enum } from "../../union/enum/domain.js";
// Aptos transaction hashes are hex encoded strings, typically 66 characters long.
export const aptosTransactionHashRegexp = new RegExp(/^0[xX][0-9a-fA-F]{64}$/);
export function isAptosTransactionHash(raw) {
return aptosTransactionHashRegexp.test(raw);
}
export const aptosTransactionHashValidator = createLayer1fulValidator(BlockchainLayer1Enum.APTOS, isAptosTransactionHash);
export function toAptosTransactionHash(raw) {
const safe = toAptosTransactionHashSafe(raw);
if (!safe)
throw new InvalidTransactionHashError(BlockchainLayer1Enum.APTOS, raw);
return safe;
}
export function toAptosTransactionHashSafe(raw) {
if (isAptosTransactionHash(raw))
return raw;
return undefined;
}