MCPcopy Index your code
hub / github.com/ccxt/ccxt / Eddsa

Method Eddsa

java/lib/src/main/java/io/github/ccxt/base/Crypto.java:563–593  ·  view source on GitHub ↗
(Object request, Object secret, Object alg)

Source from the content-addressed store, hash-verified

561 // ====================================================
562
563 public static Object Eddsa(Object request, Object secret, Object alg) {
564 try {
565 byte[] msg = (request instanceof String) ? toUtf8(request) : (byte[]) request;
566 byte[] seed = extractEd25519Seed(secret);
567
568 // Build PKCS#8 DER encoding for the 32-byte Ed25519 seed.
569 // PKCS#8 wraps the raw seed in ASN.1: SEQUENCE { SEQUENCE { OID 1.3.101.112 }, OCTET STRING { OCTET STRING { seed } } }
570 byte[] pkcs8 = new byte[48];
571 byte[] prefix = {
572 0x30, 0x2e, // SEQUENCE (46 bytes)
573 0x02, 0x01, 0x00, // INTEGER 0 (version)
574 0x30, 0x05, // SEQUENCE (5 bytes)
575 0x06, 0x03, 0x2b, 0x65, 0x70, // OID 1.3.101.112 (Ed25519)
576 0x04, 0x22, // OCTET STRING (34 bytes)
577 0x04, 0x20 // OCTET STRING (32 bytes) - the seed
578 };
579 System.arraycopy(prefix, 0, pkcs8, 0, prefix.length);
580 System.arraycopy(seed, 0, pkcs8, prefix.length, 32);
581
582 java.security.KeyFactory kf = java.security.KeyFactory.getInstance("Ed25519");
583 java.security.PrivateKey privateKey = kf.generatePrivate(new java.security.spec.PKCS8EncodedKeySpec(pkcs8));
584
585 java.security.Signature sig = java.security.Signature.getInstance("Ed25519");
586 sig.initSign(privateKey);
587 sig.update(msg);
588 byte[] signature = sig.sign();
589 return Base64.getEncoder().encodeToString(signature);
590 } catch (Exception e) {
591 throw new RuntimeException("Ed25519 signing failed: " + e.getMessage(), e);
592 }
593 }
594
595 /**
596 * Extract the 32-byte Ed25519 seed from various secret formats:

Callers 6

eddsaMethod · 0.95
JwtMethod · 0.95
AuthenticateMethod · 0.80
WatchPrivateMethod · 0.80
AuthenticateMethod · 0.80
SignParamsMethod · 0.80

Calls 5

toUtf8Method · 0.95
extractEd25519SeedMethod · 0.95
updateMethod · 0.45
signMethod · 0.45
getEncoderMethod · 0.45

Tested by

no test coverage detected