Skip to content

Commit

Permalink
feat: Better support for pairing-friendly curves.
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Sep 17, 2021
1 parent 30390ac commit e332543
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 68 deletions.
68 changes: 52 additions & 16 deletions src/main/java/com/danubetech/keyformats/JWK_to_PrivateKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ public static Object JWK_to_anyPrivateKey(JWK jsonWebKey) {
return JWK_to_RSAPrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.secp256k1)
return JWK_to_secp256k1PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.BLS12381_G1)
return JWK_to_BLS12381_G1PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.BLS12381_G2)
return JWK_to_BLS12381_G2PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.Bls12381G1)
return JWK_to_Bls12381G1PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.Bls12381G2)
return JWK_to_Bls12381G2PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.Bls48581G1)
return JWK_to_Bls12381G1PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.Bls48581G2)
return JWK_to_Bls12381G2PrivateKey(jsonWebKey);
else if (keyType == KeyTypeName.Ed25519)
return JWK_to_Ed25519PrivateKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.X25519)
Expand Down Expand Up @@ -72,34 +76,66 @@ public static byte[] JWK_to_secp256k1PrivateKeyBytes(JWK jsonWebKey) {
return jsonWebKey.getDdecoded();
}

public static KeyPair JWK_to_BLS12381_G1PrivateKey(JWK jsonWebKey) {
public static KeyPair JWK_to_Bls12381G1PrivateKey(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return new KeyPair(jsonWebKey.getXdecoded(), jsonWebKey.getDdecoded());
}

public static byte[] JWK_to_BLS12381_G1PrivateKeyBytes(JWK jsonWebKey) {
public static byte[] JWK_to_Bls12381G1PrivateKeyBytes(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getDdecoded();
}

public static KeyPair JWK_to_BLS12381_G2PrivateKey(JWK jsonWebKey) {
public static KeyPair JWK_to_Bls12381G2PrivateKey(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return new KeyPair(jsonWebKey.getXdecoded(), jsonWebKey.getDdecoded());
}

public static byte[] JWK_to_BLS12381_G2PrivateKeyBytes(JWK jsonWebKey) {
public static byte[] JWK_to_Bls12381G2PrivateKeyBytes(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getDdecoded();
}

public static KeyPair JWK_to_Bls48581G1PrivateKey(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return new KeyPair(jsonWebKey.getXdecoded(), jsonWebKey.getDdecoded());
}

public static byte[] JWK_to_Bls48581G1PrivateKeyBytes(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getDdecoded();
}

public static KeyPair JWK_to_Bls48581G2PrivateKey(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return new KeyPair(jsonWebKey.getXdecoded(), jsonWebKey.getDdecoded());
}

public static byte[] JWK_to_Bls48581G2PrivateKeyBytes(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getDdecoded();
}
Expand Down
40 changes: 30 additions & 10 deletions src/main/java/com/danubetech/keyformats/JWK_to_PublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ public static Object JWK_to_anyPublicKey(JWK jsonWebKey) {
return JWK_to_RSAPublicKey(jsonWebKey);
else if (keyType == KeyTypeName.secp256k1)
return JWK_to_secp256k1PublicKey(jsonWebKey);
else if (keyType == KeyTypeName.BLS12381_G1)
return JWK_to_BLS12381_G2PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.BLS12381_G2)
return JWK_to_BLS12381_G2PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.Bls12381G1)
return JWK_to_Bls12381G1PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.Bls12381G2)
return JWK_to_Bls12381G2PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.Bls48581G1)
return JWK_to_Bls48581G1PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.Bls48581G2)
return JWK_to_Bls48581G2PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.Ed25519)
return JWK_to_Ed25519PublicKeyBytes(jsonWebKey);
else if (keyType == KeyTypeName.X25519)
Expand Down Expand Up @@ -88,18 +92,34 @@ public static byte[] JWK_to_secp256k1PublicKeyBytes(JWK jsonWebKey) {
return publicKeyBytes;
}

public static byte[] JWK_to_BLS12381_G1PublicKeyBytes(JWK jsonWebKey) {
public static byte[] JWK_to_Bls12381G1PublicKeyBytes(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getXdecoded();
}

public static byte[] JWK_to_BLS12381_G2PublicKeyBytes(JWK jsonWebKey) {
public static byte[] JWK_to_Bls12381G2PublicKeyBytes(JWK jsonWebKey) {

if (! KeyType.EC.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.BLS12381_G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());
if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls12381G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getXdecoded();
}

public static byte[] JWK_to_Bls48581G1PublicKeyBytes(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G1.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getXdecoded();
}

public static byte[] JWK_to_Bls48581G2PublicKeyBytes(JWK jsonWebKey) {

if (! KeyType.OKP.equals(jsonWebKey.getKty())) throw new IllegalArgumentException("Incorrect key type: " + jsonWebKey.getKty());
if (! Curve.Bls48581G2.equals(jsonWebKey.getCrv())) throw new IllegalArgumentException("Incorrect curve: " + jsonWebKey.getCrv());

return jsonWebKey.getXdecoded();
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/danubetech/keyformats/PrivateKey_to_JWK.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public static JWK secp256k1PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, String
return secp256k1PrivateKey_to_JWK(privateKey, kid, use);
}

public static JWK BLS12381_G1PrivateKey_to_JWK(KeyPair privateKey, String kid, String use) {
public static JWK Bls12381G1PrivateKey_to_JWK(KeyPair privateKey, String kid, String use) {

byte[] publicKeyBytes = privateKey.publicKey;
byte[] privateKeyBytes = privateKey.secretKey;

JWK jsonWebKey = new JWK();
jsonWebKey.setKty(KeyType.EC);
jsonWebKey.setCrv(Curve.BLS12381_G1);
jsonWebKey.setKty(KeyType.OKP);
jsonWebKey.setCrv(Curve.Bls12381G1);
jsonWebKey.setKid(kid);
jsonWebKey.setUse(use);
jsonWebKey.setX(Base64.encodeBase64URLSafeString(publicKeyBytes));
Expand All @@ -84,21 +84,21 @@ public static JWK BLS12381_G1PrivateKey_to_JWK(KeyPair privateKey, String kid, S
return jsonWebKey;
}

public static JWK BLS12381_G1PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, byte[] publicKeyBytes, String kid, String use) {
public static JWK Bls12381G1PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, byte[] publicKeyBytes, String kid, String use) {

KeyPair privateKey = new KeyPair(publicKeyBytes, privateKeyBytes);

return BLS12381_G1PrivateKey_to_JWK(privateKey, kid, use);
return Bls12381G1PrivateKey_to_JWK(privateKey, kid, use);
}

public static JWK BLS12381_G2PrivateKey_to_JWK(KeyPair privateKey, String kid, String use) {
public static JWK Bls12381G2PrivateKey_to_JWK(KeyPair privateKey, String kid, String use) {

byte[] publicKeyBytes = privateKey.publicKey;
byte[] privateKeyBytes = privateKey.secretKey;

JWK jsonWebKey = new JWK();
jsonWebKey.setKty(KeyType.EC);
jsonWebKey.setCrv(Curve.BLS12381_G2);
jsonWebKey.setKty(KeyType.OKP);
jsonWebKey.setCrv(Curve.Bls12381G2);
jsonWebKey.setKid(kid);
jsonWebKey.setUse(use);
jsonWebKey.setX(Base64.encodeBase64URLSafeString(publicKeyBytes));
Expand All @@ -107,11 +107,11 @@ public static JWK BLS12381_G2PrivateKey_to_JWK(KeyPair privateKey, String kid, S
return jsonWebKey;
}

public static JWK BLS12381_G2PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, byte[] publicKeyBytes, String kid, String use) {
public static JWK Bls12381G2PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, byte[] publicKeyBytes, String kid, String use) {

KeyPair privateKey = new KeyPair(publicKeyBytes, privateKeyBytes);

return BLS12381_G2PrivateKey_to_JWK(privateKey, kid, use);
return Bls12381G2PrivateKey_to_JWK(privateKey, kid, use);
}

public static JWK Ed25519PrivateKeyBytes_to_JWK(byte[] privateKeyBytes, byte[] publicKeyBytes, String kid, String use) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/danubetech/keyformats/PublicKey_to_JWK.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,46 +62,46 @@ public static JWK secp256k1PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String k
return secp256k1PublicKey_to_JWK(publicKey, kid, use);
}

public static JWK BLS12381_G1PublicKey_to_JWK(KeyPair publicKey, String kid, String use) {
public static JWK Bls12381G1PublicKey_to_JWK(KeyPair publicKey, String kid, String use) {

byte[] publicKeyBytes = publicKey.publicKey;

JWK jsonWebKey = new JWK();
jsonWebKey.setKty(KeyType.EC);
jsonWebKey.setCrv(Curve.BLS12381_G1);
jsonWebKey.setKty(KeyType.OKP);
jsonWebKey.setCrv(Curve.Bls12381G1);
jsonWebKey.setKid(kid);
jsonWebKey.setUse(use);
jsonWebKey.setX(Base64.encodeBase64URLSafeString(publicKeyBytes));

return jsonWebKey;
}

public static JWK BLS12381_G1PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String kid, String use) {
public static JWK Bls12381G1PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String kid, String use) {

KeyPair publicKey = new KeyPair(publicKeyBytes, null);

return BLS12381_G1PublicKey_to_JWK(publicKey, kid, use);
return Bls12381G1PublicKey_to_JWK(publicKey, kid, use);
}

public static JWK BLS12381_G2PublicKey_to_JWK(KeyPair publicKey, String kid, String use) {
public static JWK Bls12381G2PublicKey_to_JWK(KeyPair publicKey, String kid, String use) {

byte[] publicKeyBytes = publicKey.publicKey;

JWK jsonWebKey = new JWK();
jsonWebKey.setKty(KeyType.EC);
jsonWebKey.setCrv(Curve.BLS12381_G2);
jsonWebKey.setKty(KeyType.OKP);
jsonWebKey.setCrv(Curve.Bls12381G2);
jsonWebKey.setKid(kid);
jsonWebKey.setUse(use);
jsonWebKey.setX(Base64.encodeBase64URLSafeString(publicKeyBytes));

return jsonWebKey;
}

public static JWK BLS12381_G2PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String kid, String use) {
public static JWK Bls12381G2PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String kid, String use) {

KeyPair publicKey = new KeyPair(publicKeyBytes, null);

return BLS12381_G2PublicKey_to_JWK(publicKey, kid, use);
return Bls12381G2PublicKey_to_JWK(publicKey, kid, use);
}

public static JWK Ed25519PublicKeyBytes_to_JWK(byte[] publicKeyBytes, String kid, String use) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static PrivateKeySigner<?> privateKeySignerForKey(KeyTypeName keyTypeName
} else if (KeyTypeName.secp256k1.equals(keyTypeName)) {

if (JWSAlgorithm.ES256K.equals(algorithm)) return new secp256k1_ES256K_PrivateKeySigner((ECKey) privateKey);
} else if (KeyTypeName.BLS12381_G1.equals(keyTypeName)) {
} else if (KeyTypeName.Bls12381G1.equals(keyTypeName)) {

if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new BLS12381_G1_BBSPlus_PrivateKeySigner((KeyPair) privateKey);
} else if (KeyTypeName.BLS12381_G2.equals(keyTypeName)) {
if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new Bls12381G1_BBSPlus_PrivateKeySigner((KeyPair) privateKey);
} else if (KeyTypeName.Bls12381G2.equals(keyTypeName)) {

if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new BLS12381_G2_BBSPlus_PrivateKeySigner((KeyPair) privateKey);
if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new Bls12381G2_BBSPlus_PrivateKeySigner((KeyPair) privateKey);
} else if (KeyTypeName.Ed25519.equals(keyTypeName)) {

if (JWSAlgorithm.EdDSA.equals(algorithm)) return new Ed25519_EdDSA_PrivateKeySigner((byte[]) privateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public static PublicKeyVerifier<?> publicKeyVerifierForKey(KeyTypeName keyTypeNa
} else if (KeyTypeName.secp256k1.equals(keyTypeName)) {

if (JWSAlgorithm.ES256K.equals(algorithm)) return new secp256k1_ES256K_PublicKeyVerifier((ECKey) publicKey);
} else if (KeyTypeName.BLS12381_G1.equals(keyTypeName)) {
} else if (KeyTypeName.Bls12381G1.equals(keyTypeName)) {

if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new BLS12381_G1_BBSPlus_PublicKeyVerifier((ECKey) publicKey);
} else if (KeyTypeName.BLS12381_G2.equals(keyTypeName)) {
if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new Bls12381G1_BBSPlus_PublicKeyVerifier((ECKey) publicKey);
} else if (KeyTypeName.Bls12381G2.equals(keyTypeName)) {

if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new BLS12381_G2_BBSPlus_PublicKeyVerifier((ECKey) publicKey);
if (JWSAlgorithm.BBSPlus.equals(algorithm)) return new Bls12381G2_BBSPlus_PublicKeyVerifier((ECKey) publicKey);
} else if (KeyTypeName.Ed25519.equals(keyTypeName)) {

if (JWSAlgorithm.EdDSA.equals(algorithm)) return new Ed25519_EdDSA_PublicKeyVerifier((byte[]) publicKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.security.GeneralSecurityException;

public class BLS12381_G1_BBSPlus_PrivateKeySigner extends PrivateKeySigner<KeyPair> {
public class Bls12381G1_BBSPlus_PrivateKeySigner extends PrivateKeySigner<KeyPair> {

public BLS12381_G1_BBSPlus_PrivateKeySigner(KeyPair privateKey) {
public Bls12381G1_BBSPlus_PrivateKeySigner(KeyPair privateKey) {

super(privateKey, JWSAlgorithm.BBSPlus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.security.GeneralSecurityException;

public class BLS12381_G1_BBSPlus_PublicKeyVerifier extends PublicKeyVerifier<ECKey> {
public class Bls12381G1_BBSPlus_PublicKeyVerifier extends PublicKeyVerifier<ECKey> {

public BLS12381_G1_BBSPlus_PublicKeyVerifier(ECKey publicKey) {
public Bls12381G1_BBSPlus_PublicKeyVerifier(ECKey publicKey) {

super(publicKey, JWSAlgorithm.BBSPlus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.security.GeneralSecurityException;

public class BLS12381_G2_BBSPlus_PrivateKeySigner extends PrivateKeySigner<KeyPair> {
public class Bls12381G2_BBSPlus_PrivateKeySigner extends PrivateKeySigner<KeyPair> {

public BLS12381_G2_BBSPlus_PrivateKeySigner(KeyPair privateKey) {
public Bls12381G2_BBSPlus_PrivateKeySigner(KeyPair privateKey) {

super(privateKey, JWSAlgorithm.BBSPlus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.security.GeneralSecurityException;

public class BLS12381_G2_BBSPlus_PublicKeyVerifier extends PublicKeyVerifier<ECKey> {
public class Bls12381G2_BBSPlus_PublicKeyVerifier extends PublicKeyVerifier<ECKey> {

public BLS12381_G2_BBSPlus_PublicKeyVerifier(ECKey publicKey) {
public Bls12381G2_BBSPlus_PublicKeyVerifier(ECKey publicKey) {

super(publicKey, JWSAlgorithm.BBSPlus);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/danubetech/keyformats/jose/Curve.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
public class Curve {

public static final String secp256k1 = "secp256k1";
public static final String BLS12381_G1 = "BLS12381_G1";
public static final String BLS12381_G2 = "BLS12381_G2";
public static final String Bls12381G1 = "Bls12381G1";
public static final String Bls12381G2 = "Bls12381G2";
public static final String Bls48581G1 = "Bls48581G1";
public static final String Bls48581G2 = "Bls48581G2";
public static final String Ed25519 = "Ed25519";
public static final String X25519 = "X25519";
public static final String P_256 = "P-256";
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/danubetech/keyformats/jose/KeyTypeName.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
public enum KeyTypeName {
RSA(KeyType.RSA),
secp256k1(Curve.secp256k1),
BLS12381_G1(Curve.BLS12381_G1),
BLS12381_G2(Curve.BLS12381_G2),
Bls12381G1(Curve.Bls12381G1),
Bls12381G2(Curve.Bls12381G2),
Bls48581G1(Curve.Bls48581G1),
Bls48581G2(Curve.Bls48581G2),
Ed25519(Curve.Ed25519),
X25519(Curve.X25519),
P_256(Curve.P_256),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static KeyTypeName keyTypeName_for_JWK(JWK jsonWebKey) {
if (KeyType.RSA.equals(jsonWebKey.getKty()))
return KeyTypeName.from(jsonWebKey.getKty()); // "RSA"
else if (KeyType.EC.equals(jsonWebKey.getKty()))
return KeyTypeName.from(jsonWebKey.getCrv()); // "secp256k1", "BLS12381_G1", "BLS12381_G2"
return KeyTypeName.from(jsonWebKey.getCrv()); // "secp256k1"
else if (KeyType.OKP.equals(jsonWebKey.getKty()))
return KeyTypeName.from(jsonWebKey.getCrv()); // "Ed25519", "X25519"
return KeyTypeName.from(jsonWebKey.getCrv()); // "Ed25519", "X25519", "Bls12381G1", "Bls12381G2", "Bls48581G1", "Bls48581G2"
else
throw new IllegalArgumentException("Unsupported key type " + jsonWebKey.getKty());
}
Expand Down

0 comments on commit e332543

Please sign in to comment.