@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.
40 lines (39 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionKeyStateSigner = exports.WalletStateSigner = void 0;
const utils_1 = require("../utils");
const sign_1 = require("../utils/sign");
const accounts_1 = require("viem/accounts");
class WalletStateSigner {
constructor(walletClient) {
this.walletClient = walletClient;
}
getAddress() {
return this.walletClient.account.address;
}
async signState(channelId, state) {
const packedState = (0, utils_1.getPackedState)(channelId, state);
return this.walletClient.signMessage({ message: { raw: packedState } });
}
async signRawMessage(message) {
return this.walletClient.signMessage({ message: { raw: message } });
}
}
exports.WalletStateSigner = WalletStateSigner;
class SessionKeyStateSigner {
constructor(sessionKey) {
this.sessionKey = sessionKey;
this.account = (0, accounts_1.privateKeyToAccount)(sessionKey);
}
getAddress() {
return this.account.address;
}
async signState(channelId, state) {
const packedState = (0, utils_1.getPackedState)(channelId, state);
return (0, sign_1.signRawECDSAMessage)(packedState, this.sessionKey);
}
async signRawMessage(message) {
return (0, sign_1.signRawECDSAMessage)(message, this.sessionKey);
}
}
exports.SessionKeyStateSigner = SessionKeyStateSigner;