Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ed25519 extended signing #73

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bloxbean.cardano.client.config;

import com.bloxbean.cardano.client.crypto.api.SigningProvider;
import com.bloxbean.cardano.client.crypto.api.impl.DefaultSigningProvider;
import com.bloxbean.cardano.client.crypto.api.impl.EdDSASigningProvider;
import com.bloxbean.cardano.client.crypto.bip39.DefaultEntropyProviderImpl;
import com.bloxbean.cardano.client.crypto.bip39.api.EntropyProvider;
import com.bloxbean.cardano.client.plutus.api.PlutusObjectConverter;
Expand All @@ -15,7 +15,7 @@ public enum Configuration {
private PlutusObjectConverter plutusObjectConverter;

Configuration() {
signingProvider = new DefaultSigningProvider();
signingProvider = new EdDSASigningProvider();
entropyProvider = new DefaultEntropyProviderImpl();
plutusObjectConverter = new DefaultPlutusObjectConverter();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.bloxbean.cardano.client.crypto.api.impl;

import com.bloxbean.cardano.client.crypto.CryptoException;
import com.bloxbean.cardano.client.crypto.api.SigningProvider;
import net.i2p.crypto.eddsa.EdDSAEngine;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;

import java.security.MessageDigest;
import java.security.Signature;

public class EdDSASigningProvider implements SigningProvider {
private static final EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);

/**
* Signs provided message using Ed25519 signing algorithm with ED25519 seed (private key)
*
* @param message the byte array of the message to be signed.
* @param privateKey the (32 byte) ED25519 seed (private key) of the identity whose signature is going to be generated.
*
* @return the signature bytes of the signing operation's result.
*/
@Override
public byte[] sign(byte[] message, byte[] privateKey) {
try{
Signature signature = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
signature.initSign(new EdDSAPrivateKey(new EdDSAPrivateKeySpec(privateKey, spec)));
signature.setParameter(EdDSAEngine.ONE_SHOT_MODE);
signature.update(message);
return signature.sign();
}catch(Exception e){
throw new CryptoException("Signing error", e);
}
}

/**
* Signs provided message with Ed25519 signing algorithm using BIP32-ED25519 private key
*
* @param message the byte array of the message to be signed.
* @param privateKey the (64 byte) BIP32-ED25519 private key of the identity whose signature is going to be generated.
* @param publicKey optional (kept for backwards compatibility)
*
* @return the signature bytes of the signing operation's result.
*/
@Override
public byte[] signExtended(byte[] message, byte[] privateKey, byte[] publicKey) {
try{
Signature signature = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
signature.initSign(new EdDSAPrivateKey(new EdDSAPrivateKeySpec(spec, privateKey)));
signature.setParameter(EdDSAEngine.ONE_SHOT_MODE);
signature.update(message);
return signature.sign();
}catch(Exception e){
throw new CryptoException("Extended signing error", e);
}
}
}

This file was deleted.

Loading