|
| 1 | +package org.tron.core.zksnark; |
| 2 | + |
| 3 | +import com.sun.jna.Pointer; |
| 4 | +import org.junit.Test; |
| 5 | +import org.tron.common.utils.ByteUtil; |
| 6 | +import org.tron.common.utils.Sha256Hash; |
| 7 | +import org.tron.common.zksnark.zen.Librustzcash; |
| 8 | +import org.tron.common.zksnark.zen.address.SpendingKey; |
| 9 | + |
| 10 | +public class SpendAuthoritySignTest { |
| 11 | + |
| 12 | + private String text = "this a test transaction"; |
| 13 | + |
| 14 | + public byte[] getHash() { |
| 15 | + return Sha256Hash.of(text.getBytes()).getBytes(); |
| 16 | + } |
| 17 | + |
| 18 | + |
| 19 | + public SpendingKey getKey() { |
| 20 | + SpendingKey sk = SpendingKey |
| 21 | + .decode("0b862f0e70048551c08518ff49a19db027d62cdeeb2fa974db91c10e6ebcdc16"); |
| 22 | + return sk; |
| 23 | + } |
| 24 | + |
| 25 | + public byte[] getAlpha() { |
| 26 | + byte[] alpha = new byte[32]; |
| 27 | + Librustzcash.librustzcashSaplingGenerateR(alpha); |
| 28 | + return alpha; |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void sign() { |
| 33 | + byte[] result = new byte[64]; |
| 34 | + Librustzcash.librustzcashSaplingSpendSig( |
| 35 | + getKey().expandedSpendingKey().getAsk(), |
| 36 | + getAlpha(), |
| 37 | + getHash(), |
| 38 | + result); |
| 39 | + System.out.println(ByteUtil.toHexString(result)); |
| 40 | + |
| 41 | + Pointer ctx = Librustzcash.librustzcashSaplingVerificationCtxInit(); |
| 42 | + |
| 43 | + Librustzcash.librustzcashSaplingCheckSpend( |
| 44 | + ctx, |
| 45 | + null, |
| 46 | + null, |
| 47 | + null, |
| 48 | + null, |
| 49 | + null, |
| 50 | + result, |
| 51 | + getHash() |
| 52 | + ); |
| 53 | + |
| 54 | +// Librustzcash.librustzcashSaplingCheckSpend( |
| 55 | +// ctx, |
| 56 | +// spendDescription.getValueCommitment().toByteArray(), |
| 57 | +// spendDescription.getAnchor().toByteArray(), |
| 58 | +// spendDescription.getNullifier().toByteArray(), |
| 59 | +// spendDescription.getRk().toByteArray(), |
| 60 | +// spendDescription.getZkproof().toByteArray(), |
| 61 | +// spendDescription.getSpendAuthoritySignature().toByteArray(), |
| 62 | +// signHash |
| 63 | +// ) |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments