Java API
HSM Dinamo
Loading...
Looking for...
No entries found
BchainEdDsaSignVerify.java

Example of creating an Ed25519 XPrv BIP32 key, signing with EdDSA, and verifying with the blockchain module.

See Note on examples.
package doxy.examples;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class BchainEdDsaSignVerify {
public static void main(String[] args) throws TacException {
String ip = "127.0.0.1";
String user = "master";
String password = "12345678";
Dinamo api = new Dinamo();
api.openSession(ip, user, password);
String xprvId = "xprv_eddsa_example";
// Cria uma chave XPrv Ed25519 BIP32 (mainnet)
api.bchainCreateXPrv(TacNDJavaLib.DN_BCHAIN_BIP32_ED25519_XPRV,
TacNDJavaLib.DN_BCHAIN_VER_BIP32_MAINNET,
0,
xprvId);
System.out.println("Chave Ed25519 XPrv criada: " + xprvId);
// Dados a serem assinados
byte[] data = new byte[] {
(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
(byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08,
(byte) 0x09, (byte) 0x0A, (byte) 0x0B, (byte) 0x0C,
(byte) 0x0D, (byte) 0x0E, (byte) 0x0F, (byte) 0x10
};
// Assina os dados com EdDsa Pure
byte[] signature = api.bchainEdDsaSign(TacNDJavaLib.DN_BCHAIN_EDDSA_SIG_PURE,
TacNDJavaLib.DN_BCHAIN_EDDSA_CSTR_UNUSED,
data,
xprvId);
System.out.println("Assinatura EdDsa gerada (" + signature.length + " bytes).");
// Recupera a chave pública Ed25519 para verificação
byte[] pubKey = api.bchainGetPubKey(TacNDJavaLib.DN_BCHAIN_PBK_ED25519, xprvId);
System.out.println("Chave pública Ed25519 recuperada (" + pubKey.length + " bytes).");
// Verifica a assinatura com a chave pública
api.bchainEdDsaVerify(TacNDJavaLib.DN_BCHAIN_EDDSA_SIG_PURE,
TacNDJavaLib.DN_BCHAIN_EDDSA_CSTR_UNUSED,
data,
TacNDJavaLib.DN_BCHAIN_PBK_ED25519,
pubKey,
signature);
System.out.println("Assinatura EdDsa verificada com sucesso.");
// Remove a chave criada
api.deleteKeyIfExists(xprvId);
System.out.println("Chave Ed25519 XPrv removida: " + xprvId);
api.closeSession();
}
}