toDID method
Implementation
Map<String, dynamic> toDID() {
final address = crypto.deriveAddress(uint8ListToHex(seed!), 0);
final verificationMethods =
List<Map<String, dynamic>>.empty(growable: true);
final authentications = List<String>.empty(growable: true);
services.forEach((String serviceName, Service service) {
final purpose = service.derivationPath
.split('/')
.map((String e) => e.replaceAll("'", ''))
.elementAt(1);
// Only support of archethic derivation scheme for now
if (purpose == '650') {
final keyPair = deriveArchethicKeypair(
seed,
service.derivationPath,
0,
curve: service.curve,
);
verificationMethods.add(<String, dynamic>{
'id': 'did:archethic:$address#$serviceName',
'type': 'JsonWebKey2020',
'publicKeyJwk':
keyToJWK(Uint8List.fromList(keyPair.publicKey!), serviceName)
.toJson(),
'controller': 'did:archethic:$address',
});
authentications.add('did:archethic:$address#$serviceName');
} else {
throw Exception("Purpose '$purpose' is not yet supported");
}
});
return <String, dynamic>{
'@context': <String>[
'https://www.w3.org/ns/did/v1',
],
'id': 'did:archethic:$address',
'authentication': authentications,
'verificationMethod': verificationMethods,
};
}