Skip to content

Commit

Permalink
temporarily allow resolution of did:web:<ip_addr> over http (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistermoe authored May 2, 2024
1 parent ab92c4b commit 1bc9694
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/web5/lib/src/dids/did_web/did_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:<ip_addr>
static bool _containsIPv4(String str) {
final ipv4Regex = RegExp(r'^(\d{1,3}\.){3}\d{1,3}');

return ipv4Regex.hasMatch(str);
}

@override
Future<DidResolutionResult> resolve(Did did, {http.Client? options}) =>
DidWeb.resolve(did, client: options);
Expand Down

0 comments on commit 1bc9694

Please sign in to comment.