@erc7824/nitrolite
Version: 
The Nitrolite SDK empowers developers to build high-performance, scalable web3 applications using state channels. It's designed to provide near-instant transactions and significantly improved user experiences by minimizing direct blockchain interactions.
96 lines (95 loc) • 2.36 kB
TypeScript
import { Account, Hex, PublicClient, WalletClient, Chain, Transport, ParseAccount, Address } from 'viem';
import { ContractAddresses } from '../abis';
import { StateSigner } from './signer';
export type ChannelId = Hex;
export type StateHash = Hex;
export type Signature = Hex;
export interface Allocation {
    destination: Address;
    token: Address;
    amount: bigint;
}
export interface Channel {
    participants: Address[];
    adjudicator: Address;
    challenge: bigint;
    nonce: bigint;
}
export declare enum ChannelStatus {
    VOID = 0,
    INITIAL = 1,
    ACTIVE = 2,
    DISPUTE = 3,
    FINAL = 4
}
export declare enum StateIntent {
    OPERATE = 0,
    INITIALIZE = 1,
    RESIZE = 2,
    FINALIZE = 3
}
export interface ChannelData {
    channel: Channel;
    status: ChannelStatus;
    wallets: [Address, Address];
    challengeExpiry: bigint;
    lastValidState: State;
}
export interface UnsignedState {
    intent: StateIntent;
    version: bigint;
    data: Hex;
    allocations: Allocation[];
}
export interface State extends UnsignedState {
    sigs: Signature[];
}
export interface FinalState extends UnsignedState {
    channelId: ChannelId;
    serverSignature: Signature;
}
export interface LegacyChannel {
    participants: [Address, Address];
    adjudicator: Address;
    challenge: bigint;
    nonce: bigint;
    chainId: number;
}
export interface LegacyState {
    intent: StateIntent;
    version: bigint;
    data: Hex;
    allocations: [Allocation, Allocation];
    sigs: Signature[];
}
export interface NitroliteClientConfig {
    publicClient: PublicClient;
    walletClient: WalletClient<Transport, Chain, ParseAccount<Account>>;
    stateSigner: StateSigner;
    addresses: ContractAddresses;
    chainId: number;
    challengeDuration: bigint;
}
export interface CreateChannelParams {
    channel: Channel;
    unsignedInitialState: UnsignedState;
    serverSignature: Signature;
}
export interface CloseChannelParams {
    stateData?: Hex;
    finalState: FinalState;
}
export interface ChallengeChannelParams {
    channelId: ChannelId;
    candidateState: State;
    proofStates?: State[];
}
export interface ResizeChannelParams {
    resizeState: FinalState;
    proofStates: State[];
}
export interface CheckpointChannelParams {
    channelId: ChannelId;
    candidateState: State;
    proofStates?: State[];
}