UNPKG

evmauth

Version:

TypeScript SDK for interacting with EVMAuth smart contracts deployed to Ethereum, Radius, and other EVM-compatible networks.

568 lines 21.4 kB
import type { ContractTransactionResponse, JsonRpcProvider } from 'ethers'; import { Contract } from 'ethers'; import type { BaseMetadata, Group, Signer, TokenMetadata } from './types.js'; /** * SDK for interacting with EVMAuth smart contracts */ export declare class EVMAuth { private readonly contract; private readonly signer?; /** * Create a new instance of the EVMAuth SDK * @param contractAddress The address of the deployed EVMAuth contract * @param providerOrSigner A provider or signer instance */ constructor(contractAddress: string, providerOrSigner: JsonRpcProvider | Signer); /** * Connect a signer to the SDK * @param signer The signer to connect * @returns A new SDK instance with the signer connected */ connect(signer: Signer): EVMAuth; /** * Get the contract instance * @returns The ethers Contract instance */ getContract(): Contract; /** * Get the DEFAULT_ADMIN_ROLE constant * @returns The DEFAULT_ADMIN_ROLE bytes32 value */ DEFAULT_ADMIN_ROLE(): Promise<string>; /** * Get the TOKEN_MANAGER_ROLE constant * @returns The TOKEN_MANAGER_ROLE bytes32 value */ TOKEN_MANAGER_ROLE(): Promise<string>; /** * Get the TOKEN_MINTER_ROLE constant * @returns The TOKEN_MINTER_ROLE bytes32 value */ TOKEN_MINTER_ROLE(): Promise<string>; /** * Get the TOKEN_BURNER_ROLE constant * @returns The TOKEN_BURNER_ROLE bytes32 value */ TOKEN_BURNER_ROLE(): Promise<string>; /** * Get the BLACKLIST_MANAGER_ROLE constant * @returns The BLACKLIST_MANAGER_ROLE bytes32 value */ BLACKLIST_MANAGER_ROLE(): Promise<string>; /** * Get the FINANCE_MANAGER_ROLE constant * @returns The FINANCE_MANAGER_ROLE bytes32 value */ FINANCE_MANAGER_ROLE(): Promise<string>; /** * Get the PROJECT_ID constant * @returns The PROJECT_ID bytes32 value */ PROJECT_ID(): Promise<string>; /** * Check if an account has a specific role * @param role The role to check * @param account The account to check * @returns True if the account has the role, false otherwise */ hasRole(role: string, account: string): Promise<boolean>; /** * Grant a role to an account * @param role The role to grant * @param account The account to grant the role to * @returns The transaction response */ grantRole(role: string, account: string): Promise<ContractTransactionResponse>; /** * Grant multiple roles to an account * @param roles Array of roles to grant * @param account The account to grant the roles to * @returns The transaction response */ grantRoles(roles: string[], account: string): Promise<ContractTransactionResponse>; /** * Revoke a role from an account * @param role The role to revoke * @param account The account to revoke the role from * @returns The transaction response */ revokeRole(role: string, account: string): Promise<ContractTransactionResponse>; /** * Revoke multiple roles from an account * @param roles Array of roles to revoke * @param account The account to revoke the roles from * @returns The transaction response */ revokeRoles(roles: string[], account: string): Promise<ContractTransactionResponse>; /** * Renounce a role for an account (account must be the caller) * @param role The role to renounce * @param account The account renouncing the role * @returns The transaction response */ renounceRole(role: string, account: string): Promise<ContractTransactionResponse>; /** * Get the admin role for a specific role * @param role The role to get the admin for * @returns The admin role bytes32 value */ getRoleAdmin(role: string): Promise<string>; /** * Get metadata for a token * @param id The token ID * @returns The token metadata */ metadataOf(id: number | bigint): Promise<TokenMetadata>; /** * Get metadata for all tokens * @returns Array of token metadata */ metadataOfAll(): Promise<TokenMetadata[]>; /** * Get metadata for multiple tokens * @param ids Array of token IDs * @returns Array of token metadata */ metadataOfBatch(ids: (number | bigint)[]): Promise<TokenMetadata[]>; /** * Get base metadata for a token * @param id The token ID * @returns The base token metadata */ baseMetadataOf(id: number | bigint): Promise<BaseMetadata>; /** * Get base metadata for all tokens * @returns Array of base token metadata */ baseMetadataOfAll(): Promise<BaseMetadata[]>; /** * Get base metadata for multiple tokens * @param ids Array of token IDs * @returns Array of base token metadata */ baseMetadataOfBatch(ids: (number | bigint)[]): Promise<BaseMetadata[]>; /** * Set token metadata * @param id The token ID * @param active Whether the token is active * @param burnable Whether the token is burnable * @param transferable Whether the token is transferable * @param price The token price * @param ttl The token time-to-live * @returns The transaction response */ setMetadata(id: number | bigint, active: boolean, burnable: boolean, transferable: boolean, price: number | bigint, ttl: number | bigint): Promise<ContractTransactionResponse>; /** * Set base token metadata * @param id The token ID * @param active Whether the token is active * @param burnable Whether the token is burnable * @param transferable Whether the token is transferable * @returns The transaction response */ setBaseMetadata(id: number | bigint, active: boolean, burnable: boolean, transferable: boolean): Promise<ContractTransactionResponse>; /** * Check if a token is active * @param id The token ID * @returns True if the token is active, false otherwise */ active(id: number | bigint): Promise<boolean>; /** * Check if a token is burnable * @param id The token ID * @returns True if the token is burnable, false otherwise */ burnable(id: number | bigint): Promise<boolean>; /** * Check if a token is transferable * @param id The token ID * @returns True if the token is transferable, false otherwise */ transferable(id: number | bigint): Promise<boolean>; /** * Check if a token is for sale * @param id The token ID * @returns True if the token is for sale, false otherwise */ forSale(id: number | bigint): Promise<boolean>; /** * Get the price of a token * @param id The token ID * @returns The token price */ priceOf(id: number | bigint): Promise<bigint>; /** * Get prices for all tokens * @returns Array of token prices */ priceOfAll(): Promise<bigint[]>; /** * Get prices for multiple tokens * @param ids Array of token IDs * @returns Array of token prices */ priceOfBatch(ids: (number | bigint)[]): Promise<bigint[]>; /** * Set the price of a token * @param id The token ID * @param price The new price * @returns The transaction response */ setPriceOf(id: number | bigint, price: number | bigint): Promise<ContractTransactionResponse>; /** * Set prices for multiple tokens * @param ids Array of token IDs * @param prices Array of prices * @returns The transaction response */ setPriceOfBatch(ids: (number | bigint)[], prices: (number | bigint)[]): Promise<ContractTransactionResponse>; /** * Get the time-to-live of a token * @param id The token ID * @returns The token time-to-live */ ttlOf(id: number | bigint): Promise<bigint>; /** * Get time-to-live for all tokens * @returns Array of token time-to-live values */ ttlOfAll(): Promise<bigint[]>; /** * Get time-to-live for multiple tokens * @param ids Array of token IDs * @returns Array of token time-to-live values */ ttlOfBatch(ids: (number | bigint)[]): Promise<bigint[]>; /** * Set the time-to-live of a token * @param id The token ID * @param ttl The new time-to-live * @returns The transaction response */ setTTL(id: number | bigint, ttl: number | bigint): Promise<ContractTransactionResponse>; /** * Get the expiration time for a token * @param id The token ID * @returns The token expiration time */ expirationFor(id: number | bigint): Promise<bigint>; /** * Get the balance of a token for an account * @param account The account to check * @param id The token ID * @returns The token balance */ balanceOf(account: string, id: number | bigint): Promise<bigint>; /** * Get balances for all tokens for an account * @param account The account to check * @returns Array of token balances */ balanceOfAll(account: string): Promise<bigint[]>; /** * Get balances for multiple tokens and accounts * @param accounts Array of accounts * @param ids Array of token IDs * @returns Array of token balances */ balanceOfBatch(accounts: string[], ids: (number | bigint)[]): Promise<bigint[]>; /** * Get detailed balance information for a token and account * @param account The account to check * @param id The token ID * @returns Array of balance groups with expiration */ balanceDetailsOf(account: string, id: number | bigint): Promise<Group[]>; /** * Get detailed balance information for all tokens for an account * @param account The account to check * @returns Array of arrays of balance groups with expiration */ balanceDetailsOfAll(account: string): Promise<Group[][]>; /** * Get detailed balance information for multiple tokens and accounts * @param accounts Array of accounts * @param ids Array of token IDs * @returns Array of arrays of balance groups with expiration */ balanceDetailsOfBatch(accounts: string[], ids: (number | bigint)[]): Promise<Group[][]>; /** * Set approval for all tokens for an operator * @param operator The operator to approve * @param approved Whether to approve or revoke * @returns The transaction response */ setApprovalForAll(operator: string, approved: boolean): Promise<ContractTransactionResponse>; /** * Check if an operator is approved for all tokens by an account * @param account The account to check * @param operator The operator to check * @returns True if the operator is approved, false otherwise */ isApprovedForAll(account: string, operator: string): Promise<boolean>; /** * Safely transfer a token from one account to another * @param from The sender account * @param to The recipient account * @param id The token ID * @param value The amount to transfer * @param data Additional data * @returns The transaction response */ safeTransferFrom(from: string, to: string, id: number | bigint, value: number | bigint, data?: string): Promise<ContractTransactionResponse>; /** * Safely transfer multiple tokens from one account to another * @param from The sender account * @param to The recipient account * @param ids Array of token IDs * @param values Array of amounts to transfer * @param data Additional data * @returns The transaction response */ safeBatchTransferFrom(from: string, to: string, ids: (number | bigint)[], values: (number | bigint)[], data?: string): Promise<ContractTransactionResponse>; /** * Issue (mint) tokens to an account * @param to The recipient account * @param id The token ID * @param amount The amount to mint * @param data Additional data * @returns The transaction response */ issue(to: string, id: number | bigint, amount: number | bigint, data?: string): Promise<ContractTransactionResponse>; /** * Issue (mint) multiple tokens to an account * @param to The recipient account * @param ids Array of token IDs * @param amounts Array of amounts to mint * @param data Additional data * @returns The transaction response */ issueBatch(to: string, ids: (number | bigint)[], amounts: (number | bigint)[], data?: string): Promise<ContractTransactionResponse>; /** * Burn tokens from an account * @param from The account to burn from * @param id The token ID * @param amount The amount to burn * @returns The transaction response */ burn(from: string, id: number | bigint, amount: number | bigint): Promise<ContractTransactionResponse>; /** * Burn multiple tokens from an account * @param from The account to burn from * @param ids Array of token IDs * @param amounts Array of amounts to burn * @returns The transaction response */ burnBatch(from: string, ids: (number | bigint)[], amounts: (number | bigint)[]): Promise<ContractTransactionResponse>; /** * Purchase tokens for an account * @param account The recipient account * @param id The token ID * @param amount The amount to purchase * @param paymentAmount The amount to pay * @returns The transaction response */ purchase(account: string, id: number | bigint, amount: number | bigint, paymentAmount: number | bigint): Promise<ContractTransactionResponse>; /** * Check if an account is blacklisted * @param account The account to check * @returns True if the account is blacklisted, false otherwise */ isBlacklisted(account: string): Promise<boolean>; /** * Add an account to the blacklist * @param account The account to blacklist * @returns The transaction response */ addToBlacklist(account: string): Promise<ContractTransactionResponse>; /** * Add multiple accounts to the blacklist * @param accounts Array of accounts to blacklist * @returns The transaction response */ addBatchToBlacklist(accounts: string[]): Promise<ContractTransactionResponse>; /** * Remove an account from the blacklist * @param account The account to remove from the blacklist * @returns The transaction response */ removeFromBlacklist(account: string): Promise<ContractTransactionResponse>; /** * Remove multiple accounts from the blacklist * @param accounts Array of accounts to remove from the blacklist * @returns The transaction response */ removeBatchFromBlacklist(accounts: string[]): Promise<ContractTransactionResponse>; /** * Get the contract owner * @returns The owner address */ owner(): Promise<string>; /** * Get the default admin address * @returns The default admin address */ defaultAdmin(): Promise<string>; /** * Get the pending default admin transfer details * @returns Object containing the new admin address and schedule time */ pendingDefaultAdmin(): Promise<{ newAdmin: string; schedule: number; }>; /** * Begin a default admin transfer * @param newAdmin The new admin address * @returns The transaction response */ beginDefaultAdminTransfer(newAdmin: string): Promise<ContractTransactionResponse>; /** * Accept a default admin transfer * @returns The transaction response */ acceptDefaultAdminTransfer(): Promise<ContractTransactionResponse>; /** * Cancel a default admin transfer * @returns The transaction response */ cancelDefaultAdminTransfer(): Promise<ContractTransactionResponse>; /** * Get the default admin delay * @returns The default admin delay */ defaultAdminDelay(): Promise<number>; /** * Get the pending default admin delay change details * @returns Object containing the new delay and schedule time */ pendingDefaultAdminDelay(): Promise<{ newDelay: number; schedule: number; }>; /** * Change the default admin delay * @param newDelay The new delay * @returns The transaction response */ changeDefaultAdminDelay(newDelay: number): Promise<ContractTransactionResponse>; /** * Rollback a default admin delay change * @returns The transaction response */ rollbackDefaultAdminDelay(): Promise<ContractTransactionResponse>; /** * Get the wallet address * @returns The wallet address */ wallet(): Promise<string>; /** * Set the wallet address * @param wallet The new wallet address * @returns The transaction response */ setWallet(wallet: string): Promise<ContractTransactionResponse>; /** * Get the URI * @param id The token ID * @returns The URI */ uri(id: number | bigint): Promise<string>; /** * Set the URI * @param uri The new URI * @returns The transaction response */ setURI(uri: string): Promise<ContractTransactionResponse>; /** * Withdraw funds from the contract * @returns The transaction response */ withdraw(): Promise<ContractTransactionResponse>; private requireSigner; /** * Listen for token transfers * @param callback The callback function * @param fromFilter The sender filter (optional) * @param toFilter The recipient filter (optional) * @returns The event listener */ onTransferSingle(callback: (event: unknown) => void, fromFilter?: string | null, toFilter?: string | null): () => void; /** * Listen for batch token transfers * @param callback The callback function * @param fromFilter The sender filter (optional) * @param toFilter The recipient filter (optional) * @returns The event listener */ onTransferBatch(callback: (event: unknown) => void, fromFilter?: string | null, toFilter?: string | null): () => void; /** * Listen for approval events * @param callback The callback function * @param accountFilter The account filter (optional) * @param operatorFilter The operator filter (optional) * @returns The event listener */ onApprovalForAll(callback: (event: unknown) => void, accountFilter?: string | null, operatorFilter?: string | null): () => void; /** * Listen for token metadata update events * @param callback The callback function * @param idFilter The token ID filter (optional) * @returns The event listener */ onTokenMetadataUpdated(callback: (event: unknown) => void, idFilter?: number | bigint | null): () => void; /** * Listen for token purchase events * @param callback The callback function * @param accountFilter The account filter (optional) * @param idFilter The token ID filter (optional) * @returns The event listener */ onTokenPurchased(callback: (event: unknown) => void, accountFilter?: string | null, idFilter?: number | bigint | null): () => void; /** * Listen for blacklist events * @param callback The callback function * @param accountFilter The account filter (optional) * @returns The event listener */ onAddedToBlacklist(callback: (event: unknown) => void, accountFilter?: string | null): () => void; /** * Listen for removal from blacklist events * @param callback The callback function * @param accountFilter The account filter (optional) * @returns The event listener */ onRemovedFromBlacklist(callback: (event: unknown) => void, accountFilter?: string | null): () => void; /** * Listen for expired tokens burned events * @param callback The callback function * @param accountFilter The account filter (optional) * @param idFilter The token ID filter (optional) * @returns The event listener */ onExpiredTokensBurned(callback: (event: unknown) => void, accountFilter?: string | null, idFilter?: number | bigint | null): () => void; /** * Listen for funds withdrawn events * @param callback The callback function * @param walletFilter The wallet filter (optional) * @returns The event listener */ onFundsWithdrawn(callback: (event: unknown) => void, walletFilter?: string | null): () => void; /** * Listen for role granted events * @param callback The callback function * @param roleFilter The role filter (optional) * @param accountFilter The account filter (optional) * @returns The event listener */ onRoleGranted(callback: (event: unknown) => void, roleFilter?: string | null, accountFilter?: string | null): () => void; /** * Listen for role revoked events * @param roleFilter The role filter (optional) * @param accountFilter The account filter (optional) * @param callback The callback function * @returns The event listener */ onRoleRevoked(callback: (event: unknown) => void, roleFilter?: string | null, accountFilter?: string | null): () => void; } //# sourceMappingURL=evmauth.d.ts.map