Skip to content

Commit

Permalink
Merge pull request #20 from privy-open-source/fix/validate-name-call
Browse files Browse the repository at this point in the history
fix(ghostscript): validate rpc call name
  • Loading branch information
adenvt authored Jul 23, 2024
2 parents c113f09 + bef06f8 commit 2f20b23
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/ghoulscript/src/rpc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import * as core from '../core'

export type Core = typeof core

export type Commands = keyof Core
export type Commands = keyof Core & string

export type CommandArgs<C extends Commands> = Parameters<Core[C]>

export type CommandResult<C extends Commands> = ReturnType<Core[C]>

export async function callRPC<C extends Commands> (name: C, args: CommandArgs<C>): Promise<CommandResult<C>> {
if (typeof core[name] !== 'function')
throw new TypeError(`Invalid action: "${name}"`)

return await (core[name] as (...args: any[]) => Promise<any>)(...args)
}

0 comments on commit 2f20b23

Please sign in to comment.