-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* janky `did:web` resolution * address PR comments Co-Authored-By: Wes <[email protected]> * address PR comment Co-Authored-By: Wes <[email protected]> * address PR comment Co-Authored-By: Wes <[email protected]> --------- Co-authored-by: Wes <[email protected]>
- Loading branch information
1 parent
f9cef3b
commit 95eb862
Showing
12 changed files
with
136 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export 'structures/service.dart'; | ||
export 'structures/did_service.dart'; | ||
export 'structures/did_resource.dart'; | ||
export 'structures/did_document.dart'; | ||
export 'structures/resolution_result.dart'; | ||
export 'structures/dereference_result.dart'; | ||
export 'structures/verification_method.dart'; | ||
export 'structures/resolution_metadata.dart'; | ||
export 'structures/dereference_options.dart'; | ||
export 'structures/dereference_metadata.dart'; | ||
export 'structures/did_resolution_result.dart'; | ||
export 'structures/did_dereference_result.dart'; | ||
export 'structures/did_verification_method.dart'; | ||
export 'structures/did_resolution_metadata.dart'; | ||
export 'structures/did_dereference_options.dart'; | ||
export 'structures/did_dereference_metadata.dart'; | ||
export 'structures/did_document_metadata.dart'; | ||
export 'structures/verification_relationship.dart'; | ||
export 'structures/did_verification_relationship.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:web5/src/crypto/key_manager.dart'; | ||
import 'package:web5/src/dids/data_models.dart'; | ||
import 'package:web5/src/dids/did.dart'; | ||
import 'package:web5/src/dids/did_method_resolver.dart'; | ||
import 'package:web5/src/dids/did_uri.dart'; | ||
|
||
class DidWeb implements Did { | ||
@override | ||
// TODO: implement keyManager | ||
KeyManager get keyManager => throw UnimplementedError(); | ||
|
||
@override | ||
// TODO: implement uri | ||
String get uri => throw UnimplementedError(); | ||
|
||
static const String methodName = 'web'; | ||
|
||
static final resolver = DidMethodResolver(name: methodName, resolve: resolve); | ||
|
||
static Future<DidResolutionResult> resolve(String didUri) async { | ||
final DidUri parsedDidUri; | ||
|
||
try { | ||
parsedDidUri = DidUri.parse(didUri); | ||
} on Exception { | ||
return DidResolutionResult.invalidDid(); | ||
} | ||
|
||
if (parsedDidUri.method != methodName) { | ||
return DidResolutionResult.invalidDid(); | ||
} | ||
|
||
// TODO: http technically not supported. remove after temp use | ||
var resolutionUrl = parsedDidUri.id.replaceAll(':', '/'); | ||
if (resolutionUrl.contains('localhost')) { | ||
resolutionUrl = 'http://$resolutionUrl'; | ||
} else { | ||
resolutionUrl = 'https://$resolutionUrl'; | ||
} | ||
|
||
if (parsedDidUri.path != null) { | ||
resolutionUrl = '$resolutionUrl/${parsedDidUri.path}'; | ||
} else { | ||
resolutionUrl = '$resolutionUrl/.well-known'; | ||
} | ||
|
||
resolutionUrl += '/did.json'; | ||
resolutionUrl = Uri.decodeFull(resolutionUrl); | ||
|
||
final parsedUrl = Uri.parse(resolutionUrl); | ||
|
||
final httpClient = HttpClient(); | ||
final request = await httpClient.getUrl(parsedUrl); | ||
final response = await request.close(); | ||
|
||
if (response.statusCode != 200) { | ||
// TODO: change this to something more appropriate | ||
return DidResolutionResult.invalidDid(); | ||
} | ||
|
||
final str = await response.transform(utf8.decoder).join(); | ||
final jsonParsed = json.decode(str); | ||
final doc = DidDocument.fromJson(jsonParsed); | ||
|
||
return DidResolutionResult(didDocument: doc); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...c/dids/structures/dereference_result.dart → ...ds/structures/did_dereference_result.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rc/dids/structures/resolution_result.dart → ...ids/structures/did_resolution_result.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:web5/src/dids/did_web/did_web.dart'; | ||
|
||
void main() { | ||
group('DidWeb', () { | ||
test('should resolve successfully', () async { | ||
final result = await DidWeb.resolve('did:web:www.linkedin.com'); | ||
expect(result.didDocument, isNotNull); | ||
|
||
expect('did:web:www.linkedin.com', result.didDocument!.id); | ||
}); | ||
}); | ||
} |