diff --git a/packages/web5/lib/src/dids/did_web/did_web.dart b/packages/web5/lib/src/dids/did_web/did_web.dart index 0bd6f56..1784329 100644 --- a/packages/web5/lib/src/dids/did_web/did_web.dart +++ b/packages/web5/lib/src/dids/did_web/did_web.dart @@ -92,7 +92,8 @@ class DidWeb { } var resolutionUrl = Uri.decodeFull(did.id.replaceAll(':', '/')); - if (resolutionUrl.contains('localhost')) { + if (resolutionUrl.contains('localhost') || + DidWebResolver._containsIPv4(resolutionUrl)) { resolutionUrl = 'http://$resolutionUrl'; } else { resolutionUrl = 'https://$resolutionUrl'; @@ -124,6 +125,14 @@ class DidWebResolver extends DidMethodResolver { @override String get name => DidWeb.methodName; + /// checks whether a string contains an ipv4 address + ///! Note: this is only temporarily here while we test using did:web: + static bool _containsIPv4(String str) { + final ipv4Regex = RegExp(r'^(\d{1,3}\.){3}\d{1,3}'); + + return ipv4Regex.hasMatch(str); + } + @override Future resolve(Did did, {http.Client? options}) => DidWeb.resolve(did, client: options);