x25519JwkFromEd25519PrivateKey function
Converts an Ed25519 private key to a X25519 private key and then to a JWK (JSON Web Key) representation. Returns a Future that completes with the JWK.
Implementation
Future<Map<String, dynamic>> x25519JwkFromEd25519PrivateKey(
List<int> privateKey,
) async {
Uint8List x25519Pk = Uint8List.fromList(List.filled(32, 0));
Uint8List ed25519Pk =
Uint8List.fromList(publicKeyFromSeed(hex.encode(privateKey)));
TweetNaClExt.crypto_sign_ed25519_pk_to_x25519_pk(x25519Pk, ed25519Pk);
Uint8List x25519Sk = Uint8List.fromList(List.filled(32, 0));
Uint8List ed25519Sk = Uint8List.fromList(privateKey);
TweetNaClExt.crypto_sign_ed25519_sk_to_x25519_sk(x25519Sk, ed25519Sk);
final jwk = {
"kty": "OKP",
"crv": "X25519",
"x": base64Url.encode(x25519Pk),
"d": base64Url.encode(x25519Sk),
};
return jwk;
}