@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) • 945 B
JavaScript
import { InvalidTransactionHashError } from "../../common/hash.js";
import { BlockchainLayer1Enum } from "../../union/enum/domain.js";
import { createLayer1fulValidator } from "../../common/common.js";
// Solana transaction hashes are Base58 encoded strings, typically 88 characters long.
export const solanaTransactionHashRegexp = new RegExp(/^[1-9A-HJ-NP-Za-km-z]{88}$/);
export function isSolanaTransactionHash(raw) {
return solanaTransactionHashRegexp.test(raw);
}
export const solanaTransactionHashValidator = createLayer1fulValidator(BlockchainLayer1Enum.SOLANA, isSolanaTransactionHash);
export function toSolanaTransactionHash(raw) {
const safe = toSolanaTransactionHashSafe(raw);
if (!safe)
throw new InvalidTransactionHashError(BlockchainLayer1Enum.SOLANA, raw);
return safe;
}
export function toSolanaTransactionHashSafe(raw) {
if (isSolanaTransactionHash(raw))
return raw;
return undefined;
}