cardano-uri-parser
Version:
A modular, type-safe Cardano URI parser supporting CIP-13, claim, stake, browse, and future authorities.
79 lines (74 loc) • 2.06 kB
text/typescript
interface ClaimUri {
type: "claim";
version: number;
faucet_url: string;
code?: string | null;
}
interface StakeUri {
type: "stake";
pools: {
[pool_id: string]: number;
};
}
interface BrowseUri {
type: "browse";
scheme: string;
namespaced_domain: string;
app_path: string;
queryParams: Record<string, string>;
url: string;
}
type BlockUri = {
type: "block";
block_hash?: string;
block_height?: number;
};
type TransactionUri = {
type: "transaction";
tx_hash: string | "self";
output_index?: number;
metadata?: {
label?: string;
};
};
interface AddressUri {
type: 'address';
address: string;
address_type?: string;
is_testnet?: boolean;
}
interface PayUri {
type: 'pay';
address: string;
lovelace?: number;
paymentId?: string;
note?: string;
tokens?: {
assetId: string;
quantity: number;
}[];
}
interface DefaultUri {
type: "payment";
address: string;
amount?: number;
era: "byron" | "shelley";
network: "mainnet" | "testnet";
}
type CardanoUri = AddressUri | BrowseUri | BlockUri | ClaimUri | PayUri | StakeUri | TransactionUri | DefaultUri;
declare function parse(uri: string): CardanoUri;
declare function safeParse(uri: string): CardanoUri | null;
declare class CardanoUriError extends Error {
type: string;
details?: any;
constructor(type: string, message: string, details?: any);
}
declare function isValidHex64(value: string): boolean;
declare function isValidBlockHeight(value: string): boolean;
declare function isValidMetadataLabel(value: string): boolean;
declare function classifyCardanoAddress(value: string): {
valid: boolean;
type?: string;
is_testnet?: boolean;
};
export { type AddressUri, type BlockUri, type BrowseUri, type CardanoUri, CardanoUriError, type ClaimUri, type DefaultUri, type PayUri, type StakeUri, type TransactionUri, classifyCardanoAddress, isValidBlockHeight, isValidHex64, isValidMetadataLabel, parse, safeParse };