onesec-bridge
Version:
A library for interacting with the onesec.to bridge
49 lines (48 loc) • 2.05 kB
TypeScript
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
import { Wallet } from 'ethers';
export interface TestSigners {
/**
* Ethers signer created from the TEST_EVM_PRIVATE_KEY environment variable
*/
evmSigner: Wallet;
/**
* ICP Secp256k1KeyIdentity created from the same TEST_EVM_PRIVATE_KEY environment variable
*/
icpIdentity: Secp256k1KeyIdentity;
}
/**
* Creates both an ethers Signer and an ICP Secp256k1KeyIdentity from the TEST_EVM_PRIVATE_KEY environment variable.
*
* This utility function is designed for testing and development purposes. It loads the .env file
* and uses the TEST_EVM_PRIVATE_KEY to create signers for both EVM chains and the Internet Computer.
*
* IMPORTANT: This function will throw an error if TEST_EVM_PRIVATE_KEY is not set. Tests using
* this function will fail if the environment variable is missing, which ensures proper test setup.
*
* @param rpcUrl The RPC URL to connect the EVM signer to. Defaults to Base mainnet.
* @returns An object containing both the EVM signer and ICP identity
* @throws Error if TEST_EVM_PRIVATE_KEY environment variable is not set or invalid
*
* @example
* ```typescript
* // Make sure you have TEST_EVM_PRIVATE_KEY in your .env file
* // TEST_EVM_PRIVATE_KEY=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
*
* const { evmSigner, icpIdentity } = createTestSigners("https://mainnet.base.org");
*
* // Use with ethers
* const evmAddress = await evmSigner.getAddress();
*
* // Use with ICP
* const principal = icpIdentity.getPrincipal();
* ```
*/
export declare function createTestSigners(rpcUrl?: string): TestSigners;
/**
* Loads environment variables and returns the TEST_EVM_PRIVATE_KEY if available.
* This is a helper function for cases where you need just the raw private key.
*
* @returns The private key from TEST_EVM_PRIVATE_KEY environment variable
* @throws Error if TEST_EVM_PRIVATE_KEY environment variable is not set
*/
export declare function getTestPrivateKey(): string;