/** * @dev Simplifies interaction with the Umbra contracts */ import { BigNumber, BigNumberish, Contract, ContractTransaction, JsonRpcSigner, Overrides, StaticJsonRpcProvider, TransactionResponse, Wallet } from '../ethers'; import { KeyPair } from './KeyPair'; import { RandomNumber } from './RandomNumber'; import { Umbra as UmbraContract } from '../typechain'; import type { Announcement, ChainConfig, EthersProvider, ScanOverrides, SendOverrides, SubgraphAnnouncement, UserAnnouncement, AnnouncementDetail, SendBatch } from '../types'; type AnnouncementMatchResult = { isForUser: boolean; randomNumber: string; }; /** * @notice Helper method to parse chainConfig input and return a valid chain configuration * @param chainConfig Supported chainID as number, or custom ChainConfig */ export declare const parseChainConfig: (chainConfig: ChainConfig | number) => ChainConfig; export declare class Umbra { readonly provider: EthersProvider; readonly chainConfig: ChainConfig; readonly umbraContract: UmbraContract; readonly batchSendContract: Contract | undefined; readonly fallbackProvider: StaticJsonRpcProvider; /** * @notice Create Umbra instance to interact with the Umbra 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 Umbra * @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 Umbra 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; }>; batchSend(signer: JsonRpcSigner | Wallet, sends: SendBatch[], overrides?: SendOverrides): Promise<{ tx: ContractTransaction; stealthKeyPairs: 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 Umbra 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 Umbra 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 Umbra event logs using a subgraph, if available, falling back to RPC if not * @param overrides Override the start and end block used for scanning; * @returns A list of Announcement events supplemented with additional metadata, such as the sender, block, * timestamp, and txhash */ fetchAllAnnouncements(overrides?: ScanOverrides): AsyncGenerator; /** * @notice Fetches Umbra event logs starting from the block user registered their stealth keys in using * a subgraph, if available, falling back to RPC if not * @param possibleRegisteredBlockNumber Block number when user registered their stealth keys (if known) * @param Signer Signer with provider to use for fetching the block number (if not known) from the StealthKeyRegistry contract * @param address Address of the user for fetching the block number (if not known) from the subgraph or StealthKeyRegistry contract * @param overrides Override the start and end block used for scanning; * @returns A list of Announcement events supplemented with additional metadata, such as the sender, block, * timestamp, and txhash * @dev If the registered block number is not known, it will be fetched from the subgraph or the StealthKeyRegistry contract */ fetchSomeAnnouncements(possibleRegisteredBlockNumber: number | undefined, Signer: JsonRpcSigner, address: string, overrides?: ScanOverrides): AsyncGenerator; /** * @notice Fetches all Umbra event logs using a subgraph * @param startBlock Scanning start block * @param endBlock Scannding end block * @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): AsyncGenerator; /** * @notice Fetches all Umbra 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 Umbra 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 public key * @param viewingPrivateKey Receiver's viewing private 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 * @dev Callers that scan many announcements can pass precomputed KeyPair instances to avoid repeated parsing * @param spendingPublicKey Receiver's spending public key, or a precomputed spending KeyPair * @param viewingPrivateKey Receiver's viewing private key, or a precomputed viewing KeyPair * @param announcement Parameters emitted in the announcement event */ static isAnnouncementForUser(spendingPublicKey: string, viewingPrivateKey: string, announcement: Announcement): AnnouncementMatchResult; static isAnnouncementForUser(spendingKeyPair: KeyPair, viewingKeyPair: KeyPair, announcement: Announcement): AnnouncementMatchResult; /** * @notice Matches an announcement using already-initialized key pairs for the hot scanning path * @param spendingKeyPair Receiver's spending key pair * @param viewingKeyPair Receiver's viewing key pair * @param announcement Parameters emitted in the announcement event */ private static matchAnnouncementForUser; /** * @notice Asks a user to sign a message to generate two Umbra-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; }>; prepareSend(recipientId: string, lookupOverrides?: SendOverrides): Promise<{ stealthKeyPair: KeyPair; pubKeyXCoordinate: string; encrypted: import("../types").EncryptedPayload; }>; /** * @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 Umbra 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; } export declare function assertSufficientBalance(signer: JsonRpcSigner | Wallet, token: string, tokenAmount: BigNumber): Promise; export declare function assertValidStealthAddress(stealthAddress: string): void; /** * @notice Helper method to return parsed localOverrides and LookupOverrides * @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 */ export declare function parseOverrides(overrides?: SendOverrides): { localOverrides: SendOverrides; lookupOverrides: Pick; }; export {}; //# sourceMappingURL=Umbra.d.ts.map