/** * @dev Simplifies interaction with the StealthPay contracts */ import { BigNumberish, ContractTransaction, JsonRpcSigner, Overrides, StaticJsonRpcProvider, TransactionResponse, Wallet } from '../ethers'; import { KeyPair } from './KeyPair'; import { RandomNumber } from './RandomNumber'; import { StealthPay as StealthPayContract } from '@cryptoadong/stealthpay-contracts-core/typechain'; import type { Announcement, ChainConfig, EthersProvider, ScanOverrides, SendOverrides, SubgraphAnnouncement, UserAnnouncement, AnnouncementDetail } from '../types'; export declare class StealthPay { readonly provider: EthersProvider; readonly chainConfig: ChainConfig; readonly stealthpayContract: StealthPayContract; readonly fallbackProvider: StaticJsonRpcProvider; /** * @notice Create StealthPay instance to interact with the StealthPay contracts * @param provider ethers provider to use * @param chainConfig The chain configuration of the network or a network ID to use a default one */ constructor(provider: EthersProvider, chainConfig: ChainConfig | number); /** * @notice Returns a signer with a valid provider * @param signer Signer that may or may not have an associated provider */ getConnectedSigner(signer: JsonRpcSigner | Wallet): JsonRpcSigner | Wallet; /** * @notice Send funds to a recipient via StealthPay * @dev If sending tokens, make sure to handle the approvals before calling this method * @dev The provider used for sending the transaction is the one associated with the StealthPay instance * @dev Fetching the latest toll and including that value on top of `amount` is automatically handled * @param signer Signer to send transaction from * @param token Address of token to send, excluding toll. Use 'ETH' or '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' * to send Ether * @param amount Amount to send, in units of that token (e.g. use 1e6 to send 1 USDC) * @param recipientId Identifier of recipient, e.g. their ENS name * @param overrides Override the gas limit, gas price, nonce, or advanced mode. * When `advanced` is false it looks for public keys in StealthKeyRegistry, and when true it recovers * them from on-chain transaction when true */ send(signer: JsonRpcSigner | Wallet, token: string, amount: BigNumberish, recipientId: string, overrides?: SendOverrides): Promise<{ tx: ContractTransaction; stealthKeyPair: KeyPair; }>; /** * @notice Withdraw ETH or tokens to a specified destination address with a regular transaction * @dev The provider used for sending the transaction is the one associated with the StealthPay instance * @dev This method does not relay meta-transactions and requires signer to have ETH * @param spendingPrivateKey Receiver's spending private key * @param token Address of token to withdraw, * @param destination Address where funds will be withdrawn to * @param overrides Override the gas limit, gas price, or nonce */ withdraw(spendingPrivateKey: string, token: string, destination: string, overrides?: Overrides): Promise; /** * @notice Withdraw tokens by sending a meta-transaction on behalf of a user * @dev The provider used for sending the transaction is the one associated with the StealthPay instance * @dev This method does not relay meta-transactions and requires signer to have ETH * @param signer Signer to send transaction from * @param stealthAddr Stealth address funds were sent to * @param destination Address where funds will be withdrawn to * @param token Address of token to withdraw * @param sponsor Address that receives sponsorFee * @param sponsorFee Fee for relayer * @param v v-component of signature * @param r r-component of signature * @param s s-component of signature * @param overrides Override the gas limit, gas price, or nonce */ withdrawOnBehalf(signer: JsonRpcSigner | Wallet, stealthAddr: string, destination: string, token: string, sponsor: string, sponsorFee: BigNumberish, v: number, r: string, s: string, overrides?: Overrides): Promise; /** * @notice Withdraw tokens by relaying a user's meta-transaction */ relayWithdrawOnBehalf(): Promise; /** * @notice Fetches all StealthPay event logs using The Graph, if available, falling back to RPC if not * @param overrides Override the start and end block used for scanning; ignored if using The Graph * @returns A list of Announcement events supplemented with additional metadata, such as the sender, block, * timestamp, and txhash */ fetchAllAnnouncements(overrides?: ScanOverrides): Promise; /** * @notice Fetches all StealthPay event logs using The Graph * @dev Currently ignores the start and end block parameters and returns all events; this may change in a * future version * @param startBlock Ignored * @param endBlock Ignored * @returns A list of Announcement events supplemented with additional metadata, such as the sender, block, * timestamp, txhash, and the subgraph identifier */ fetchAllAnnouncementsFromSubgraph(startBlock: string | number, endBlock: string | number): Promise; /** * @notice Fetches all StealthPay event logs between specified blocks using the standard RPC provider * @param startBlock Block number to begin scanning for events * @param endBlock Block number to end scanning for events, or 'latest' * @returns A list of Announcement events supplemented with additional metadata, such as the sender, block, * timestamp, and txhash */ fetchAllAnnouncementFromLogs(startBlock: string | number, endBlock: string | number): Promise; /** * @notice Scans all StealthPay event logs for funds sent to the specified address * @dev This is a convenience method that first runs `fetchAllAnnouncements`, then filters them through * the static helper `isAnnouncementForUser`. The latter is CPU intensive and this method will block while * all announcements are processed. To avoid performance issues, you may need to run fetching and filtering * steps separately, and use chunking, web workers, or other threading strategies. * @param spendingPublicKey Receiver's spending private key * @param viewingPrivateKey Receiver's viewing public key * @param overrides Override the start and end block used for scanning */ scan(spendingPublicKey: string, viewingPrivateKey: string, overrides?: ScanOverrides): Promise<{ userAnnouncements: UserAnnouncement[]; }>; /** * @notice If the provided announcement is for the user with the specified keys, return true and the decoded * random number * @param spendingPublicKey Receiver's spending private key * @param viewingPrivateKey Receiver's viewing public key * @param announcement Parameters emitted in the announcement event */ static isAnnouncementForUser(spendingPublicKey: string, viewingPrivateKey: string, announcement: Announcement): { isForUser: boolean; randomNumber: string; }; /** * @notice Asks a user to sign a message to generate two StealthPay-specific private keys for them * @dev Only safe for use with wallets that implement deterministic ECDSA signatures as specified by RFC 6979 (which * might be all of them?) * @param signer Signer to sign message from * @returns Two KeyPair instances, for the spendingKeyPair and viewingKeyPair */ generatePrivateKeys(signer: JsonRpcSigner | Wallet): Promise<{ spendingKeyPair: KeyPair; viewingKeyPair: KeyPair; }>; /** * @notice Helper method to return the stealth wallet from a receiver's private key and a random number * @param spendingPrivateKey Receiver's spending private key * @param randomNumber Number to multiply by, as class RandomNumber or hex string with 0x prefix */ static computeStealthPrivateKey(spendingPrivateKey: string, randomNumber: RandomNumber | string): string; /** * @notice Sign a transaction to be used with withdrawTokenOnBehalf * @dev Return type is an ethers Signature: { r: string; s: string; _vs: string, recoveryParam: number; v: number; } * @param spendingPrivateKey Receiver's spending private key that is doing the signing * @param chainId Chain ID where contract is deployed * @param contract StealthPay contract address that withdrawal transaction will be sent to * @param acceptor Withdrawal destination * @param token Address of token to withdraw * @param sponsor Address of relayer * @param sponsorFee Amount sent to sponsor * @param hook Address of post withdraw hook contract * @param data Call data to be past to post withdraw hook */ static signWithdraw(spendingPrivateKey: string, chainId: number, contract: string, acceptor: string, token: string, sponsor: string, sponsorFee: BigNumberish, hook?: string, data?: string): Promise; }