-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first pass at dap resolution * add `collection` dep to use `firstWhereOrNull()` * remove all force unwrapping --------- Co-authored-by: Ethan Lee <[email protected]>
- Loading branch information
Showing
4 changed files
with
230 additions
and
7 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
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,47 @@ | ||
import 'dart:convert'; | ||
|
||
class RegistrationRequest { | ||
final String id; | ||
final String handle; | ||
final String did; | ||
final String domain; | ||
final String signature; | ||
|
||
RegistrationRequest({ | ||
required this.id, | ||
required this.handle, | ||
required this.did, | ||
required this.domain, | ||
required this.signature, | ||
}); | ||
|
||
factory RegistrationRequest.fromJson(String source) => | ||
RegistrationRequest.fromMap(jsonDecode(source)); | ||
|
||
factory RegistrationRequest.fromMap(Map<String, dynamic> map) { | ||
return RegistrationRequest( | ||
id: map['id'], | ||
handle: map['handle'], | ||
did: map['did'], | ||
domain: map['domain'], | ||
signature: map['signature'], | ||
); | ||
} | ||
|
||
// Converts the instance into a map | ||
Map<String, dynamic> toMap() { | ||
return { | ||
'id': id, | ||
'handle': handle, | ||
'did': did, | ||
'domain': domain, | ||
'signature': signature, | ||
}; | ||
} | ||
|
||
// Converts the instance to a JSON string | ||
String toJson() => jsonEncode(toMap()); | ||
|
||
@override | ||
String toString() => toJson(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:dap/dap.dart'; | ||
import 'package:dap/src/dap_resolver.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:web5/web5.dart'; | ||
|
||
void main() { | ||
group('DapResolver.resolve', () { | ||
test('should resolve DAP', () async { | ||
final dap = Dap.parse('@moegrammer/didpay.me'); | ||
|
||
// TODO: use mocks | ||
final resolver = DapResolver(DidResolver( | ||
methodResolvers: [DidWebResolver()], | ||
)); | ||
|
||
final result = await resolver.resolve(dap); | ||
|
||
expect(result.dap.handle, 'moegrammer'); | ||
expect(result.dap.domain, 'didpay.me'); | ||
expect(result.dap.registryDid, 'did:web:didpay.me'); | ||
expect(result.moneyAddresses.length, 1); | ||
}); | ||
}); | ||
} |