@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.
80 lines (79 loc) • 2.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.miscParamsParsers = void 0;
const zod_1 = require("zod");
const types_1 = require("../types");
const common_1 = require("./common");
const NetworkInfoSchema = zod_1.z.object({
name: zod_1.z.string(),
chain_id: zod_1.z.number(),
custody_address: common_1.addressSchema,
adjudicator_address: common_1.addressSchema,
});
const GetConfigParamsSchema = zod_1.z
.array(zod_1.z
.object({ broker_address: common_1.addressSchema, networks: zod_1.z.array(NetworkInfoSchema) })
.strict()
.transform((raw) => ({
brokerAddress: raw.broker_address,
networks: raw.networks.map((n) => ({
name: n.name,
chainId: n.chain_id,
custodyAddress: n.custody_address,
adjudicatorAddress: n.adjudicator_address,
})),
})))
.refine((arr) => arr.length === 1)
.transform((arr) => arr[0]);
const ErrorParamsSchema = zod_1.z
.array(zod_1.z.string().transform((raw) => ({ error: raw })))
.refine((arr) => arr.length === 1)
.transform((arr) => arr[0]);
const GetRPCHistoryParamsSchema = zod_1.z
.array(zod_1.z.array(zod_1.z
.object({
id: zod_1.z.number(),
sender: common_1.addressSchema,
req_id: zod_1.z.number(),
method: zod_1.z.string(),
params: zod_1.z.string(),
timestamp: zod_1.z.number(),
req_sig: zod_1.z.array(common_1.hexSchema),
res_sig: zod_1.z.array(common_1.hexSchema),
response: zod_1.z.string(),
})
.transform((h) => ({
id: h.id,
sender: h.sender,
reqId: h.req_id,
method: h.method,
params: h.params,
timestamp: h.timestamp,
reqSig: h.req_sig,
resSig: h.res_sig,
response: h.response,
}))))
.refine((arr) => arr.length === 1)
.transform((arr) => arr[0])
.transform((arr) => arr);
const GetUserTagParamsSchema = zod_1.z
.array(zod_1.z
.object({
tag: zod_1.z.string(),
})
.strict()
.transform((raw) => ({ tag: raw.tag })))
.refine((arr) => arr.length === 1)
.transform((arr) => arr[0]);
const parseMessageParams = (params) => {
if (!Array.isArray(params) || params.length === 0)
throw new common_1.ParserParamsMissingError(types_1.RPCMethod.Message);
return params[0];
};
exports.miscParamsParsers = {
[types_1.RPCMethod.GetConfig]: (params) => GetConfigParamsSchema.parse(params),
[types_1.RPCMethod.Error]: (params) => ErrorParamsSchema.parse(params),
[types_1.RPCMethod.GetRPCHistory]: (params) => GetRPCHistoryParamsSchema.parse(params),
[types_1.RPCMethod.GetUserTag]: (params) => GetUserTagParamsSchema.parse(params),
[types_1.RPCMethod.Message]: parseMessageParams,
};