isValidNamespacesRequest static method

bool isValidNamespacesRequest({
  1. required Map<String, Namespace> namespaces,
  2. required String chainId,
  3. required String method,
})

Validates the provided chainId, then gets the methods for that chainId and ensures that the method request is contained in the methods

Implementation

static bool isValidNamespacesRequest({
  required Map<String, Namespace> namespaces,
  required String chainId,
  required String method,
}) {
  // Validate the chainId
  if (!NamespaceUtils.isValidChainId(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'chain $chainId should conform to "CAIP-2" format',
    ).toSignError();
  }

  // Validate the namespaces
  isValidNamespaces(
    namespaces: namespaces,
    context: 'isValidNamespacesRequest',
  );

  List<dynamic> methods = NamespaceUtils.getNamespacesMethodsForChainId(
    namespaces: namespaces,
    chainId: chainId,
  );

  if (!methods.contains(method)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_METHODS,
      context: 'The method $method is not supported',
    ).toSignError();
  }

  return true;
}