getPrivateKeyForConnectionDidAsJwk method
Implementation
Future<Map<String, dynamic>?> getPrivateKeyForConnectionDidAsJwk(
String did) async {
if (did.startsWith('did:ethr')) {
var private = _getPrivateKeyForConnectionDidEthr(did);
if (private == null) return null;
Map<String, dynamic> key = {};
key['kid'] = '$did#${did.split(':').last}';
key['kty'] = 'EC';
key['crv'] = 'secp256k1';
key['d'] = removePaddingFromBase64(base64UrlEncode(hexToBytes(private)));
return key;
} else if (did.startsWith('did:key:z6Mk')) {
var private = await _getPrivateKeyForConnectionDidEd(did);
if (private == null) return null;
Map<String, dynamic> key = {};
key['kid'] = '$did#${did.split(':').last}';
key['kty'] = 'OKP';
key['crv'] = 'Ed25519';
key['d'] = removePaddingFromBase64(
base64UrlEncode(hexToBytes(private).sublist(0, 32)));
return key;
} else if (did.startsWith('did:key:z6LS')) {
var private = await _getPrivateKeyForConnectionDidX(did);
if (private == null) return null;
Map<String, dynamic> key = {};
key['kid'] = '$did#${did.split(':').last}';
key['kty'] = 'OKP';
key['crv'] = 'X25519';
key['d'] = removePaddingFromBase64(
base64UrlEncode(hexToBytes(private).sublist(0, 32)));
return key;
} else {
throw Exception('Unknown KeyType');
}
}