Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement 'validation' specs like CAIP-3, 22, 29 #8

Open
shrugs opened this issue May 6, 2021 · 0 comments
Open

implement 'validation' specs like CAIP-3, 22, 29 #8

shrugs opened this issue May 6, 2021 · 0 comments

Comments

@shrugs
Copy link
Contributor

shrugs commented May 6, 2021

How should 'validation' specs be implemented, ala CAIP-3, CAIP-22, CAIP-29?

Proposal

I'm imagining that we introduce more specific *Param types, plus a functional validation function that looks something like:

export interface CAIP3ChainIdParams extends ChainIDParams {
  namespace: "eip155",
}

export const isCAIP3ChainId = (params: ChainIdParams): params is CAIP3ChainIdParams => {
  if (params.namespace !== "eip155") return false;

  try {
    // must parse as decimal number
    parseInt(params.reference, 10);
  } catch {
    return false;
  }

  return true;
};

we could bring in a more extensible validation library like ajv, or write our own based on some spec we define (a ValidatorSpec?), but imo may not be worth it unless validation logic gets out of hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant