//#region src/errors/base.d.ts type BaseErrorParameters = { cause?: BaseError | Error | undefined; details?: string | undefined; docsBaseUrl?: string | undefined; docsPath?: string | undefined; docsSlug?: string | undefined; metaMessages?: string[] | undefined; name?: string | undefined; }; declare class BaseError extends Error { details: string; docsPath?: string | undefined; metaMessages?: string[] | undefined; shortMessage: string; name: string; constructor(shortMessage: string, args?: BaseErrorParameters); walk(): Error; walk(fn: (err: unknown) => boolean): Error | null; } //#endregion //#region src/errors/address.d.ts type InvalidAddressErrorType = InvalidAddressError & { name: "InvalidAddressError"; }; declare class InvalidAddressError extends BaseError { constructor({ address }: { address: string; }); } //#endregion //#region src/errors/siws.d.ts type SiwsInvalidMessageFieldErrorType = SiwsInvalidMessageFieldError & { name: "SiwsInvalidMessageFieldError"; }; declare class SiwsInvalidMessageFieldError extends BaseError { constructor({ field, metaMessages }: { field: string; metaMessages?: string[] | undefined; }); } //#endregion //#region src/types.d.ts /** * @description Combines members of an intersection into a readable type. * * @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg} * @example * Prettify<{ a: string } & { b: string } & { c: number, d: bigint }> * => { a: string, b: string, c: number, d: bigint } */ type Prettify = { [K in keyof T]: T[K]; } & {}; type ExactPartial = { [key in keyof type]?: type[key] | undefined; }; /** * @description SIP-X message fields * * @see https://github.com/stacksgov/sips/pull/70 */ type SiwsMessage = { /** * The Stacks address performing the signing. */ address: string; /** * The [SIP-005](https://github.com/stacksgov/sips/blob/main/sips/sip-005/sip-005-blocks-and-transactions.md) Chain ID to which the session is bound, */ chainId: number; /** * [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986) authority that is requesting the signing. */ domain: string; /** * Time when the signed authentication message is no longer valid. */ expirationTime?: Date | undefined; /** * Time when the message was generated, typically the current time. */ issuedAt?: Date | undefined; /** * A random string typically chosen by the relying party and used to prevent replay attacks. */ nonce: string; /** * Time when the signed authentication message will become valid. */ notBefore?: Date | undefined; /** * A system-specific identifier that may be used to uniquely refer to the sign-in request. */ requestId?: string | undefined; /** * A list of information or references to information the user wishes to have resolved as part of authentication by the relying party. */ resources?: string[] | undefined; /** * [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) URI scheme of the origin of the request. */ scheme?: string | undefined; /** * A human-readable ASCII assertion that the user will sign. */ statement?: string | undefined; /** * [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986) URI referring to the resource that is the subject of the signing (as in the subject of a claim). */ uri: string; /** * The current version of the SIWS Message. */ version: "1"; }; //#endregion //#region src/createSiwsMessage.d.ts type CreateSiwsMessageParameters = SiwsMessage; type CreateSiwsMessageReturnType = string; type CreateSiwsMessageErrorType = InvalidAddressErrorType | SiwsInvalidMessageFieldErrorType; /** * @description Creates SIP-X formatted message. * * @example * const message = createMessage({ * address: 'SP2X0TZ59D5SZ8ACQ6YMCHHNR2ZN51Z32E2CJ173', * chainId: 1, * domain: 'example.com', * nonce: 'foobarbaz', * uri: 'https://example.com/path', * version: '1', * }) * * @see https://github.com/stacksgov/sips/pull/70 */ export declare function createSiwsMessage(parameters: CreateSiwsMessageParameters): CreateSiwsMessageReturnType; //#endregion //#region src/generateSiwsNonce.d.ts /** * @description Generates random SIP-X nonce. * * @example * const nonce = generateNonce() * * @see https://github.com/stacksgov/sips/pull/70 * * @returns A randomly generated SIP-X nonce. */ export declare function generateSiwsNonce(): string; //#endregion //#region src/validateSiwsMessage.d.ts type ValidateSiwsMessageParameters = { /** * Stacks address to check against. */ address?: string | undefined; /** * [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986) authority to check against. */ domain?: string | undefined; /** * SIP-X message fields. */ message: ExactPartial; /** * Random string to check against. */ nonce?: string | undefined; /** * [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) URI scheme to check against. */ scheme?: string | undefined; /** * Current time to check optional `expirationTime` and `notBefore` fields. * * @default new Date() */ time?: Date | undefined; }; type ValidateSiwsMessageReturnType = boolean; /** * @description Validates SIP-X message. * * @see https://github.com/stacksgov/sips/pull/70 */ export declare function validateSiwsMessage(parameters: ValidateSiwsMessageParameters): ValidateSiwsMessageReturnType; //#endregion //#region src/verifySiwsMessage.d.ts type VerifySiwsMessageParameters = Prettify & { /** * SIP-X formatted message. */ message: string; /** * Signature to check against. */ signature: string; }>; type VerifySiwsMessageReturnType = boolean; /** * Verifies [SIP-X](https://github.com/stacksgov/sips/pull/70) formatted message was signed. * * @param parameters - {@link VerifySiwsMessageParameters} * @returns Whether or not the signature is valid. {@link VerifySiwsMessageReturnType} */ export declare function verifySiwsMessage(parameters: VerifySiwsMessageParameters): VerifySiwsMessageReturnType; //#endregion export type { CreateSiwsMessageErrorType, CreateSiwsMessageParameters, CreateSiwsMessageReturnType, ValidateSiwsMessageParameters, ValidateSiwsMessageReturnType, VerifySiwsMessageParameters, VerifySiwsMessageReturnType }; //# sourceMappingURL=index.d.ts.map