@didtools/siwx
Version:
Typescript library for Sign-In With X
50 lines (49 loc) • 1.83 kB
TypeScript
import type { DateTimeString, DomainString, URIString, NetworkString, AddressString, VersionString, ChainIdString, NonceString, NonEmptyString } from './fields.js';
import { type Maybe } from 'codeco';
/**
* Parameters for SiwxMessage constructor.
*/
export interface SiwxMessageFields {
readonly domain: string;
readonly network: string;
readonly address: string;
readonly statement?: string;
readonly uri: string;
readonly version?: string | number;
readonly chainId: string | number;
readonly nonce: string | number;
readonly issuedAt: string;
readonly expirationTime?: string;
readonly notBefore?: string;
readonly requestId?: string;
readonly resources?: Array<string>;
}
export declare class SiwxMessage implements SiwxMessageFields {
readonly domain: DomainString;
readonly network: NetworkString;
readonly address: AddressString;
readonly statement?: NonEmptyString;
readonly uri: URIString;
readonly version: VersionString;
readonly chainId: ChainIdString;
readonly nonce: NonceString;
readonly issuedAt: DateTimeString;
readonly expirationTime?: DateTimeString;
readonly notBefore?: DateTimeString;
readonly requestId?: NonEmptyString;
readonly resources?: Array<URIString>;
/**
* Parse SIWx message string.
* @throws If invalid string passed.
*/
static fromString: typeof fromString;
/**
* Parse SIWx message string. Return `Maybe`, thus do not throw.
*/
static fromStringSafe: typeof fromStringSafe;
constructor(fields: SiwxMessageFields);
toString(): string;
}
export declare function fromStringSafe(input: string): Maybe<SiwxMessage>;
export declare function fromString(input: string): SiwxMessage;
export declare function toString(message: SiwxMessage): string;