我已尝试如下但验证失败(代码已更新,现在可以使用)
Signature signature = Signature.getInstance("SHA512withEDDSA", "LunaProvider");
signature.setParameter(new LunaEDDSAParameterSpec(false));
signature.initSign(privateKey);
signature.update(payload);
byte[] byteArray = signature.sign();
ASN1InputStream decoder = new ASN1InputStream(byteArray);
DERSequence seq = (DERSequence) decoder.readObject();
DERInteger r = (DERInteger) seq.getObjectAt(0);
DERInteger s = (DERInteger) seq.getObjectAt(1);
LOGGER.info("R: {}", r.getValue());
LOGGER.info("S: {}", s.getValue());
decoder.close();
byte[] rByte = i2osp(r.getValue(), 32);
byte[] sByte = i2osp(s.getValue(), 32);
byte[] concat = Bytes.concat(rByte, sByte);
return concat;
不确定这是正确的做法
使用 stellar java 库进行验证
PublicKey publicKey = getPublicByAlias(publicKeyLabel);
LunaPublicKeyEC lunaPublicKeyEC = (LunaPublicKeyEC) publicKey;
byte[] pubKeySub = Arrays.copyOfRange(lunaPublicKeyEC.getP(), 2, lunaPublicKeyEC.getP().length);
org.stellar.sdk.KeyPair keyPair = org.stellar.sdk.KeyPair.fromPublicKey(pubKeySub);
boolean verified = keyPair.verify(payload, signatureByte);