keyToJWK function
Implementation
Jwk keyToJWK(Uint8List publicKey, String keyId) {
final curveID = publicKey[0];
final key = publicKey.sublist(2, publicKey.length);
switch (curveID) {
case 0:
return Jwk.fromJson(<dynamic, dynamic>{
'kty': 'OKP',
'crv': 'Ed25519',
'x': base64Url.encode(key),
'kid': keyId,
});
case 1:
final x = key.sublist(16);
final y = key.sublist(-16);
return Jwk.fromJson(<dynamic, dynamic>{
'kty': 'EC',
'crv': 'P-256',
'x': base64Url.encode(x),
'y': base64Url.encode(y),
'kid': keyId,
});
case 2:
final x = key.sublist(16);
final y = key.sublist(-16);
return Jwk.fromJson(<dynamic, dynamic>{
'kty': 'EC',
'crv': 'secp256k1',
'x': base64Url.encode(x),
'y': base64Url.encode(y),
'kid': keyId,
});
default:
throw Exception('Curve not supported');
}
}