diff --git a/packages/web5/lib/src/dids/did_jwk/did_jwk.dart b/packages/web5/lib/src/dids/did_jwk/did_jwk.dart index 4d15a98..7c23bf4 100644 --- a/packages/web5/lib/src/dids/did_jwk/did_jwk.dart +++ b/packages/web5/lib/src/dids/did_jwk/did_jwk.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'package:web5/src/crypto.dart'; import 'package:web5/src/dids/did.dart'; @@ -60,7 +61,8 @@ class DidJwk { /// an invalid [DidResolutionResult]. /// /// Throws [FormatException] if the JWK parsing fails. - static Future resolve(Did did) async { + static Future resolve(Did did, + {HttpClient? client}) async { if (did.method != methodName) { return DidResolutionResult.withError(DidResolutionError.invalidDid); } diff --git a/packages/web5/lib/src/dids/did_method_resolver.dart b/packages/web5/lib/src/dids/did_method_resolver.dart index 9569969..1c37af3 100644 --- a/packages/web5/lib/src/dids/did_method_resolver.dart +++ b/packages/web5/lib/src/dids/did_method_resolver.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:web5/src/dids/did.dart'; import 'package:web5/src/dids/did_core.dart'; @@ -7,13 +9,16 @@ class DidMethodResolver { String name; /// The function to resolve a DID URI using this method. - Future Function(Did) resolve; + Future Function(Did, {HttpClient? client}) resolve; /// Constructs a [DidMethodResolver] with a given [name] and [resolve] function. DidMethodResolver({required this.name, required this.resolve}); - Future dereference(Did did) async { - final didResolutionResult = await resolve(did); + Future dereference( + Did did, { + HttpClient? client, + }) async { + final didResolutionResult = await resolve(did, client: client); if (didResolutionResult.hasError()) { return DidDereferenceResult.withError( diff --git a/packages/web5/lib/src/dids/did_resolver.dart b/packages/web5/lib/src/dids/did_resolver.dart index 7c35850..3ec04e6 100644 --- a/packages/web5/lib/src/dids/did_resolver.dart +++ b/packages/web5/lib/src/dids/did_resolver.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:web5/src/dids/did.dart'; import 'package:web5/src/dids/did_core.dart'; import 'package:web5/src/dids/did_dht/did_dht.dart'; @@ -27,12 +29,15 @@ class DidResolver { // Static field to hold the instance static final DidResolver _instance = DidResolver._default(); - static Future resolve(String uri) { - return _instance.resolveDid(uri); + static Future resolve(String uri, {HttpClient? client}) { + return _instance.resolveDid(uri, client: client); } - static Future dereference(String url) { - return _instance.dereferenceDid(url); + static Future dereference( + String url, { + HttpClient? client, + }) { + return _instance.dereferenceDid(url, client: client); } /// Constructs a [DidResolver] with a list of [DidMethodResolver]s. @@ -47,7 +52,7 @@ class DidResolver { /// Resolves a DID URI into a [DidResolutionResult]. /// /// Throws an [Exception] if no resolver is available for the given method. - Future resolveDid(String uri) { + Future resolveDid(String uri, {HttpClient? client}) { final Did did; try { did = Did.parse(uri); @@ -63,13 +68,16 @@ class DidResolver { throw Exception('no resolver available for did:${did.method}'); } - return resolver.resolve(did); + return resolver.resolve(did, client: client); } /// Resolves a DID URI into a [DidResolutionResult]. /// /// Throws an [Exception] if no resolver is available for the given method. - Future dereferenceDid(String url) { + Future dereferenceDid( + String url, { + HttpClient? client, + }) { final did = Did.parse(url); final resolver = methodResolvers[did.method]; @@ -77,6 +85,6 @@ class DidResolver { throw Exception('no resolver available for did:${did.method}'); } - return resolver.dereference(did); + return resolver.dereference(did, client: client); } }