import { PublicClient, Transport, Chain, TypedData, Address } from 'viem'; import { Hex, ByteArray } from 'viem/src/types/misc'; interface VerifyParams { /** Signature of the message signed by the wallet */ signature: Hex | ByteArray; /** RFC 4501 dns authority that is requesting the signing. */ domain?: string; /** Randomized token used to prevent replay attacks, at least 8 alphanumeric characters. */ nonce?: string; /**ISO 8601 datetime string of the current time. */ time?: string; } declare const VerifyParamsKeys: Array; interface VerifyOpts { /** ethers provider to be used for EIP-1271 validation */ publicClient?: PublicClient; /** If the library should reject promises on errors, defaults to false */ suppressExceptions?: boolean; /** Enables a custom verification function that will be ran alongside EIP-1271 check. */ verificationFallback?: (params: VerifyParams, opts: VerifyOpts, message: SiwViemMessage, EIP1271Promise: Promise) => Promise; } declare const VerifyOptsKeys: Array; /** * Returned on verifications. */ interface SiwViemResponse { /** Boolean representing if the message was verified with success. */ success: boolean; /** If present `success` MUST be false and will provide extra information on the failure reason. */ error?: SiwViemError; /** Original message that was verified. */ data: SiwViemMessage; } /** * Interface used to return errors in SiwViemResponses. */ declare class SiwViemError { constructor(type: SiwViemErrorType | string, expected?: string, received?: string); /** Type of the error. */ type: SiwViemErrorType | string; /** Expected value or condition to pass. */ expected?: string; /** Received value that caused the failure. */ received?: string; } /** * Possible message error types. */ declare enum SiwViemErrorType { /** `expirationTime` is present and in the past. */ EXPIRED_MESSAGE = "Expired message.", /** `domain` is not a valid authority or is empty. */ INVALID_DOMAIN = "Invalid domain.", /** `domain` don't match the domain provided for verification. */ DOMAIN_MISMATCH = "Domain does not match provided domain for verification.", /** `nonce` don't match the nonce provided for verification. */ NONCE_MISMATCH = "Nonce does not match provided nonce for verification.", /** `address` does not conform to EIP-55 or is not a valid address. */ INVALID_ADDRESS = "Invalid address.", /** `uri` does not conform to RFC 3986. */ INVALID_URI = "URI does not conform to RFC 3986.", /** `nonce` is smaller then 8 characters or is not alphanumeric */ INVALID_NONCE = "Nonce size smaller then 8 characters or is not alphanumeric.", /** `notBefore` is present and in the future. */ NOT_YET_VALID_MESSAGE = "Message is not valid yet.", /** Signature doesn't match the address of the message. */ INVALID_SIGNATURE = "Signature does not match address of the message.", /** `expirationTime`, `notBefore` or `issuedAt` not complient to ISO-8601. */ INVALID_TIME_FORMAT = "Invalid time format.", /** `version` is not 1. */ INVALID_MESSAGE_VERSION = "Invalid message version.", /** Thrown when some required field is missing. */ UNABLE_TO_PARSE = "Unable to parse the message." } declare enum SignatureType { CONTRACT_SIGNATURE = "CONTRACT_SIGNATURE", APPROVED_HASH = "APPROVED_HASH", EOA = "EOA", ETH_SIGN = "ETH_SIGN" } interface TransactionServiceSafeMessage { created: string; modified: string; messageHash: string; message: string | TypedData; proposedBy: string; safeAppId: number | null; confirmations: { created: string; modified: string; owner: string; signature: string; signatureType: SignatureType; }[]; preparedSignature: string; } declare class SiwViemMessage { /**RFC 4501 dns authority that is requesting the signing. */ domain: string; /**Ethereum address performing the signing conformant to capitalization * encoded checksum specified in EIP-55 where applicable. */ address: Address; /**Human-readable ASCII assertion that the user will sign, and it must not * contain `\n`. */ statement?: string | null; /**RFC 3986 URI referring to the resource that is the subject of the signing * (as in the __subject__ of a claim). */ uri: string; /**Current version of the message. */ version: string; /**EIP-155 Chain ID to which the session is bound, and the network where * Contract Accounts must be resolved. */ chainId: number | string; /**Randomized token used to prevent replay attacks, at least 8 alphanumeric * characters. */ nonce?: string | null; /**ISO 8601 datetime string of the current time. */ issuedAt?: string; /**ISO 8601 datetime string that, if present, indicates when the signed * authentication message is no longer valid. */ expirationTime?: string | null; /**ISO 8601 datetime string that, if present, indicates when the signed * authentication message will become valid. */ notBefore?: string | null; /**System-specific identifier that may be used to uniquely refer to the * sign-in request. */ requestId?: string | null; /**List of information or references to information the user wishes to have * resolved as part of authentication by the relying party. They are * expressed as RFC 3986 URIs separated by `\n- `. */ resources?: Array | null; /** * Creates a parsed Sign-In with Ethereum Message (EIP-4361) object from a * string or an object. If a string is used an ABNF parser is called to * validate the parameter, otherwise the fields are attributed. * @param param {string | SiwViemMessage} Sign message as a string or an object. */ constructor(param: string | Partial); /** * This function can be used to retrieve an EIP-4361 formated message for * signature, although you can call it directly it's advised to use * [prepareMessage()] instead which will resolve to the correct method based * on the [type] attribute of this object, in case of other formats being * implemented. * @returns {string} EIP-4361 formated message, ready for EIP-191 signing. */ toMessage(): string; /** * This method parses all the fields in the object and creates a messaging for signing * message according with the type defined. * @returns {string} Returns a message ready to be signed according with the * type defined in the object. */ prepareMessage(): string; /** * Verifies the integrity of the object by matching its signature. * @param params Parameters to verify the integrity of the message, signature is required. * @param opts Options to be used for verification. * @returns {Promise} This object if valid. */ verify(params: VerifyParams, opts?: VerifyOpts): Promise; /** * Validates the parameters provided for the verification process. * @param params The parameters to be validated. * @throws {Error} Throws an error if the provided keys in params are invalid. */ private validateParams; /** * Validates the options provided for the verification process. * @param opts The options to be validated. * @throws {Error} Throws an error if the provided keys in opts are invalid. */ private validateOpts; /** * Checks the domain binding of the object against the provided domain. * @param domain The domain to be checked. * @throws {SiwViemError} Throws an error if the domain doesn't match the object's domain. */ private validateDomainBinding; /** * Checks the nonce binding of the object against the provided nonce. * @param nonce The nonce to be checked. * @throws {SiwViemError} Throws an error if the nonce doesn't match the object's nonce. */ private validateNonceBinding; /** * Validates if the provided message time is within the valid range. * @param time The time of the message to be validated. * @throws {Error} Throws an error if the provided time is not valid. * @throws {SiwViemError} Throws an error if the time is either not yet valid or expired. */ private validateMessageTime; /** * Validates the provided signature against the message. * @param params Parameters to verify the integrity of the message, signature is required. * @param opts Options to be used for verification. * @throws {SiwViemError} Throws an error if the signature is invalid or the recovered address doesn't match. */ private validateSignature; /** * Validates the values of this object fields. * @throws Throws an {ErrorType} if a field is invalid. */ private validateMessage; } /** * This method calls the EIP-1271 method for Smart Contract wallets * @param message The EIP-4361 parsed message * @param signature Wallet signature * @param publicClient Web3 public client able to perform a contract check (Web3/Viem). * @returns {Promise} Checks for the smart contract (if it exists) if * the signature is valid for given address. */ declare const checkContractWalletSignature: (message: SiwViemMessage, signature: Hex | ByteArray, publicClient: PublicClient) => Promise; /** * A function to assert if given value is null or undefined * @param value any value to have it's existence checked * @returns A boolean containing the result of the validation */ declare const exists: (value: unknown) => boolean; /** * This method leverages a native CSPRNG with support for both browser and Node.js * environments in order generate a cryptographically secure nonce for use in the * SiwViemMessage in order to prevent replay attacks. * * 96 bits has been chosen as a number to sufficiently balance size and security considerations * relative to the lifespan of it's usage. * * @returns cryptographically generated random nonce with 96 bits of entropy encoded with * an alphanumeric character set. */ declare const generateNonce: () => string; /** * This method matches the given date string against the ISO-8601 regex and also * performs checks if it's a valid date. * @param inputDate any string to be validated against ISO-8601 * @returns boolean indicating if the providade date is valid and conformant to ISO-8601 */ declare const isValidISO8601Date: (inputDate: string) => boolean; declare const checkInvalidKeys: >(obj: T, keys: (keyof T)[]) => (keyof T)[]; export { SiwViemError, SiwViemErrorType, SiwViemMessage, SiwViemResponse, TransactionServiceSafeMessage, VerifyOpts, VerifyOptsKeys, VerifyParams, VerifyParamsKeys, checkContractWalletSignature, checkInvalidKeys, exists, generateNonce, isValidISO8601Date };