UNPKG

@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.

298 lines (297 loc) 10.4 kB
import { Address, Hex } from 'viem'; import { RPCMethod, GenericRPCMessage, AppDefinition, RPCChannelStatus, ChannelUpdate, TxType } from '.'; export interface AuthChallengeResponseParams { challengeMessage: string; } export type AuthChallengeRPCResponseParams = AuthChallengeResponseParams; export interface AuthChallengeResponse extends GenericRPCMessage { method: RPCMethod.AuthChallenge; params: AuthChallengeResponseParams; } export type AuthVerifyResponseParams = { address: Address; sessionKey: Address; success: boolean; } & { jwtToken: string; }; export type AuthVerifyRPCResponseParams = AuthVerifyResponseParams; export interface ErrorResponseParams { error: string; } export type ErrorRPCResponseParams = ErrorResponseParams; export interface NetworkInfo { name: string; chainId: number; custodyAddress: Address; adjudicatorAddress: Address; } export interface GetConfigResponseParams { brokerAddress: Address; networks: NetworkInfo[]; } export type GetConfigRPCResponseParams = GetConfigResponseParams; export interface GetLedgerBalancesResponseParams { asset: string; amount: string; } export type GetLedgerBalancesRPCResponseParams = GetLedgerBalancesResponseParams; export interface GetLedgerEntriesResponseParams { id: number; accountId: string; accountType: number; asset: string; participant: Address; credit: string; debit: string; createdAt: Date; } export type GetLedgerEntriesRPCResponseParams = GetLedgerEntriesResponseParams; export type GetLedgerTransactionsResponseParams = Transaction[]; export interface UserTagParams { tag: string; } export type GetUserTagRPCResponseParams = UserTagParams; export interface CreateAppSessionResponseParams { appSessionId: Hex; version: number; status: RPCChannelStatus; } export type CreateAppSessionRPCResponseParams = CreateAppSessionResponseParams; export interface SubmitAppStateResponseParams { appSessionId: Hex; version: number; status: RPCChannelStatus; } export type SubmitAppStateRPCResponseParams = SubmitAppStateResponseParams; export interface CloseAppSessionResponseParams { appSessionId: Hex; version: number; status: RPCChannelStatus; } export type CloseAppSessionRPCResponseParams = CloseAppSessionResponseParams; export interface GetAppDefinitionResponseParams extends AppDefinition { protocol: string; participants: Address[]; weights: number[]; quorum: number; challenge: number; nonce: number; } export type GetAppDefinitionRPCResponseParams = GetAppDefinitionResponseParams; export interface GetAppSessionsResponseParams { appSessionId: Hex; status: RPCChannelStatus; participants: Address[]; protocol: string; challenge: number; weights: number[]; quorum: number; version: number; nonce: number; createdAt: Date; updatedAt: Date; sessionData?: string; } export type GetAppSessionsRPCResponseParams = GetAppSessionsResponseParams; export interface ServerSignature { v: number; r: Hex; s: Hex; } export interface RPCAllocation { destination: Address; token: Address; amount: bigint; } export interface ResizeChannelResponseParams { channelId: Hex; stateData: Hex; intent: number; version: number; allocations: RPCAllocation[]; stateHash: Hex; serverSignature: ServerSignature; } export type ResizeChannelRPCResponseParams = ResizeChannelResponseParams; export interface CloseChannelResponseParams { channelId: Hex; intent: number; version: number; stateData: Hex; allocations: RPCAllocation[]; stateHash: Hex; serverSignature: ServerSignature; } export type CloseChannelRPCResponseParams = CloseChannelResponseParams; export type GetChannelsResponseParams = ChannelUpdate[]; export type GetChannelsRPCResponseParams = GetChannelsResponseParams; export interface GetRPCHistoryResponseParams { id: number; sender: Address; reqId: number; method: string; params: string; timestamp: number; reqSig: Hex[]; resSig: Hex[]; response: string; } export type GetRPCHistoryRPCResponseParams = GetRPCHistoryResponseParams; export interface GetAssetsResponseParams { token: Address; chainId: number; symbol: string; decimals: number; } export type GetAssetsRPCResponseParams = GetAssetsResponseParams; export interface ErrorResponse extends GenericRPCMessage { method: RPCMethod.Error; params: ErrorResponseParams; } export interface GetConfigResponse extends GenericRPCMessage { method: RPCMethod.GetConfig; params: GetConfigResponseParams; } export interface GetLedgerBalancesResponse extends GenericRPCMessage { method: RPCMethod.GetLedgerBalances; params: GetLedgerBalancesResponseParams[]; } export interface GetLedgerEntriesResponse extends GenericRPCMessage { method: RPCMethod.GetLedgerEntries; params: GetLedgerEntriesResponseParams[]; } export interface GetLedgerTransactionsResponse extends GenericRPCMessage { method: RPCMethod.GetLedgerTransactions; params: GetLedgerTransactionsResponseParams; } export interface GetUserTagResponse extends GenericRPCMessage { method: RPCMethod.GetUserTag; params: UserTagParams; } export interface CreateAppSessionResponse extends GenericRPCMessage { method: RPCMethod.CreateAppSession; params: CreateAppSessionResponseParams; } export interface SubmitAppStateResponse extends GenericRPCMessage { method: RPCMethod.SubmitAppState; params: SubmitAppStateResponseParams; } export interface CloseAppSessionResponse extends GenericRPCMessage { method: RPCMethod.CloseAppSession; params: CloseAppSessionResponseParams; } export interface GetAppDefinitionResponse extends GenericRPCMessage { method: RPCMethod.GetAppDefinition; params: GetAppDefinitionResponseParams; } export interface GetAppSessionsResponse extends GenericRPCMessage { method: RPCMethod.GetAppSessions; params: GetAppSessionsResponseParams[]; } export interface ResizeChannelResponse extends GenericRPCMessage { method: RPCMethod.ResizeChannel; params: ResizeChannelResponseParams; } export interface CloseChannelResponse extends GenericRPCMessage { method: RPCMethod.CloseChannel; params: CloseChannelResponseParams; } export interface GetChannelsResponse extends GenericRPCMessage { method: RPCMethod.GetChannels; params: GetChannelsResponseParams; } export interface GetRPCHistoryResponse extends GenericRPCMessage { method: RPCMethod.GetRPCHistory; params: GetRPCHistoryResponseParams[]; } export interface GetAssetsResponse extends GenericRPCMessage { method: RPCMethod.GetAssets; params: GetAssetsResponseParams[]; } export interface AssetsResponse extends GenericRPCMessage { method: RPCMethod.Assets; params: GetAssetsResponseParams[]; } export interface AuthVerifyResponse extends GenericRPCMessage { method: RPCMethod.AuthVerify; params: AuthVerifyResponseParams; } export interface AuthRequestResponseParams { challengeMessage: string; } export type AuthRequestRPCResponseParams = AuthRequestResponseParams; export interface AuthRequestResponse extends GenericRPCMessage { method: RPCMethod.AuthRequest; params: AuthRequestResponseParams; } export interface MessageResponseParams { } export type MessageRPCResponseParams = MessageResponseParams; export interface MessageResponse extends GenericRPCMessage { method: RPCMethod.Message; params: MessageResponseParams; } export interface BalanceUpdateResponseParams { asset: string; amount: string; } export type BalanceUpdateRPCResponseParams = BalanceUpdateResponseParams; export interface BalanceUpdateResponse extends GenericRPCMessage { method: RPCMethod.BalanceUpdate; params: BalanceUpdateResponseParams[]; } export type ChannelsUpdateResponseParams = ChannelUpdate; export interface ChannelsUpdateResponse extends GenericRPCMessage { method: RPCMethod.ChannelsUpdate; params: ChannelsUpdateResponseParams; } export type ChannelUpdateResponseParams = ChannelUpdate; export type ChannelUpdateRPCResponseParams = ChannelUpdateResponseParams; export interface ChannelUpdateResponse extends GenericRPCMessage { method: RPCMethod.ChannelUpdate; params: ChannelUpdateResponseParams; } export interface PingResponseParams { } export type PingRPCResponseParams = PingResponseParams; export interface PingResponse extends GenericRPCMessage { method: RPCMethod.Ping; params: PingResponseParams; } export interface PongResponseParams { } export type PongRPCResponseParams = PongResponseParams; export interface PongResponse extends GenericRPCMessage { method: RPCMethod.Pong; params: PongResponseParams; } export interface Transaction { id: number; txType: TxType; fromAccount: Address; fromAccountTag?: string; toAccount: Address; toAccountTag?: string; asset: string; amount: string; createdAt: Date; } export type TransferResponseParams = Transaction[]; export interface TransferResponse extends GenericRPCMessage { method: RPCMethod.Transfer; params: TransferResponseParams; } export type TransferNotificationResponseParams = Transaction[]; export interface TransferNotificationResponse extends GenericRPCMessage { method: RPCMethod.TransferNotification; params: TransferNotificationResponseParams; } export type RPCResponse = AuthChallengeResponse | AuthVerifyResponse | AuthRequestResponse | ErrorResponse | GetConfigResponse | GetLedgerBalancesResponse | GetLedgerEntriesResponse | GetLedgerTransactionsResponse | GetUserTagResponse | CreateAppSessionResponse | SubmitAppStateResponse | CloseAppSessionResponse | GetAppDefinitionResponse | GetAppSessionsResponse | ResizeChannelResponse | CloseChannelResponse | GetChannelsResponse | GetRPCHistoryResponse | GetAssetsResponse | AssetsResponse | PingResponse | PongResponse | MessageResponse | BalanceUpdateResponse | ChannelsUpdateResponse | ChannelUpdateResponse | TransferResponse | TransferNotificationResponse; export type ExtractResponseByMethod<M extends RPCMethod> = Extract<RPCResponse, { method: M; }>; export type RPCResponseParams = ExtractResponseByMethod<RPCMethod>['params']; export type RPCResponseParamsByMethod = { [M in RPCMethod]: ExtractResponseByMethod<M>['params']; };