Skip to content

Commit 0eaff47

Browse files
committed
test about sign
1 parent 64418d4 commit 0eaff47

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

‎src/main/java/org/tron/common/zksnark/zen/address/SpendingKey.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public static byte[] generatePrivateKey(long seed) {
9696

9797

9898
public static void main(String[] args) throws Exception {
99-
// SpendingKey sk = SpendingKey
100-
// .decode("0b862f0e70048551c08518ff49a19db027d62cdeeb2fa974db91c10e6ebcdc16");
101-
SpendingKey sk = SpendingKey.random();
99+
SpendingKey sk = SpendingKey
100+
.decode("0b862f0e70048551c08518ff49a19db027d62cdeeb2fa974db91c10e6ebcdc16");
101+
// SpendingKey sk = SpendingKey.random();
102102
System.out.println(sk.encode());
103103
System.out.println(
104104
"sk.expandedSpendingKey()" + ByteUtil.toHexString(sk.expandedSpendingKey().encode()));
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)