Functions can be scripted together in a ts node env, or we might be able to run it in the browser and have buttons etc.
class StateChannelWallet {
private readonly chainProvider: ethers.Provider;
private readonly signer: ethers.Wallet;
private readonly entrypointAddress: string;
private intermediaryAddress: string;
private intermediaryBalance: bigint;
private readonly scwAddress: string;
private readonly contract: NitroSmartContractWallet;
private readonly hashStore: Map<string, Uint8Array>; // maps hash-->preimage
async getBalance(): Promise<number>
async getIntermediaryBalance(): Promise<number>
async getCurrentBlockNumber(): Promise<number>
async signUserOperation(userOp: UserOperationStruct): Promise<string>
async createNewHash(): Promise<string>
async createHTLCPayment(address, amount, hash): Promise<string> // returns signature of State
async ingestSignedStateAndPreimage(signedState,preimage) // returns a signed state with updated balances and one fewer HTLC
async ingestStateUpdate(signedstate) // countersigns signedState, stores it, returns preimage and updated signed state
}
class SCBWIntermediaryClient {
private ethereumRPCEndpoint // e.g. infura
async ingestUserOperation(userOp) // countersigns the userOp, routes it to the ethereumRPCEndpoint
async ingestStateUpdate(signedstate) // countersigns the signedState, and stores it. Shen crafts her own signed state with a corresponding HTLC (same hash, same amount, different payee, different timeout)
async ingestPreimage(preimage) // returns a signed state with updated balances, increased turnNum and one fewer HTLC
}
testscript:
const hash = Bob.createNewHash();
const signedState = alice.createHTLCPayment(bob,amount,hash)
const signedState2 = irene.ingestStateUpdate(signedState)
const preimage = Bob.ingestStateUpdate(signedState2)
Irene.ingestSignedStateAndPreimage(,preimage)
// TODO fill the rest of this out following the sequence diagram here https://www.notion.so/statechannels/EthOnline-Project-Pitch-2e8de7cecf40408984b2cf30a9dec2cf
to avoid writing a messaging system, we could simply return messages from one client and pass them into the other one.
Functions can be scripted together in a ts node env, or we might be able to run it in the browser and have buttons etc.
to avoid writing a messaging system, we could simply return messages from one client and pass them into the other one.