isValidAuthenticate static method
Implementation
static bool isValidAuthenticate(SessionAuthRequestParams params) {
if (params.chains.isEmpty) {
throw Errors.getInternalError(
Errors.MISSING_OR_INVALID,
context: 'authenticate() invalid chains: Must not be emtpy.',
).toSignError();
}
if (!NamespaceUtils.isValidUrl(params.uri)) {
throw Errors.getInternalError(
Errors.MISSING_OR_INVALID,
context:
'authenticate() invalid uri: ${params.uri}. Must be a valid url.',
).toSignError();
}
if (params.nonce.isEmpty) {
throw Errors.getInternalError(
Errors.MISSING_OR_INVALID,
context: 'authenticate() nonce must be nonempty.',
).toSignError();
}
if (params.type != null && params.type!.t != CacaoHeader.EIP4361) {
throw Errors.getInternalError(
Errors.MISSING_OR_INVALID,
context: 'authenticate() type must null or ${CacaoHeader.EIP4361}.',
).toSignError();
}
final uniqueNamespaces = params.chains.map((chain) {
return NamespaceUtils.getNamespaceFromChain(chain);
}).toSet();
if (uniqueNamespaces.length > 1) {
throw Errors.getInternalError(
Errors.NON_CONFORMING_NAMESPACES,
context:
'authenticate() Multi-namespace requests are not supported. Please request single namespace only.',
).toSignError();
}
final isValidChainId = NamespaceUtils.isValidChainId(params.chains.first);
if (!isValidChainId) {
throw Errors.getInternalError(
Errors.NON_CONFORMING_NAMESPACES,
context: 'authenticate() chainId should conform to "CAIP-2" format',
).toSignError();
}
final namespace = NamespaceUtils.getNamespaceFromChain(params.chains.first);
if (namespace != 'eip155') {
throw Errors.getInternalError(
Errors.NON_CONFORMING_NAMESPACES,
context:
'authenticate() Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.',
).toSignError();
}
return true;
}