Skip to content

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

Open
@shrugs

Description

@shrugs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions