Skip to content

Commit 9e44d2c

Browse files
committed
Merge branch 'master' into release_4.1.3
2 parents 364b1ae + b5183d6 commit 9e44d2c

File tree

17 files changed

+2019
-403
lines changed

17 files changed

+2019
-403
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ AbbrName
288288
> The abbreviation of TRC10 token
289289
290290
TotalSupply
291-
> TotalSupply = Account Balance of Issuer + All Frozen Token Amount
291+
> TotalSupply = Account Balance of Issuer + All Frozen Token Amount
292292
> TotalSupply: Total Issuing Amount
293293
> Account Balance Of Issuer: At the time of issuance
294294
> All Frozen Token Amount: Before asset transfer and the issuance
@@ -959,7 +959,7 @@ method
959959
> The name of function and parameters, please refer to the example
960960
961961
args
962-
> Parameter value
962+
> Parameter value, if you want to call `receive`, pass '#' instead
963963
964964
isHex
965965
> The format of the parameters method and args, is hex string or not
@@ -1783,15 +1783,15 @@ Example:
17831783
In this example, the scalingFactor is 1000.
17841784

17851785
1. MINT
1786-
1786+
17871787
**In this mode, some variables must be set as follows, shieldedInputNum = 0, publicToAddress = null, toAmount = 0.**
17881788

17891789
```console
17901790
> SendShieldedTRC20Coin 1000000000000 0 null 0 1 ztron15t3c27a5ve43ssflqepa8dke36vzvccxrren4ma2lghu3hle8rtwltufnvvzrm76w042s9p5f46 1000000000000 null
17911791
```
17921792

17931793
2. TRANSFER
1794-
1794+
17951795
**In this mode, some variables must be set as follows, fromAmount = 0, publicToAddress = null,toAmount = 0.**
17961796

17971797
Transfer from one shielded address to one shielded address.
@@ -1934,10 +1934,10 @@ ivk
19341934
> The ivk of shielded address
19351935
19361936
ak
1937-
> The ak of shielded address
1937+
> The ak of shielded address. Please set this field to null, if you don't care whether the notes are spent or not.
19381938
19391939
nk
1940-
> The nk of shielded address
1940+
> The nk of shielded address. Please set this field to null, if you don't care whether the notes are spent or not.
19411941
19421942
startNum
19431943
> The starting block number of the scan
@@ -2160,7 +2160,7 @@ d :11db4baf6bd5d5afd3a8b1
21602160
Create an order to sell asset
21612161

21622162
> MarketSellAsset owner_address sell_token_id sell_token_quantity buy_token_id buy_token_quantity
2163-
2163+
21642164
ownerAddress
21652165
> The address of the account that initiated the transaction
21662166
@@ -2218,7 +2218,7 @@ GetMarketOrderByAccount TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW
22182218
}
22192219
]
22202220
}
2221-
```
2221+
```
22222222

22232223
### GetMarketOrderById
22242224

@@ -2244,7 +2244,7 @@ GetMarketOrderById fc9c64dfd48ae58952e85f05ecb8ec87f55e19402493bb2df501ae9d2da75
22442244
### GetMarketPairList
22452245

22462246
Get market pair list
2247-
2247+
22482248
Example:
22492249

22502250
```console
@@ -2324,7 +2324,7 @@ GetMarketPriceByPair _ 1000001
23242324
Cancel the order
23252325

23262326
> MarketCancelOrder owner_address order_id
2327-
2327+
23282328
owner_address
23292329
> the account address who have created the order
23302330
@@ -2336,7 +2336,7 @@ Example:
23362336
```console
23372337
MarketCancelOrder TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW fc9c64dfd48ae58952e85f05ecb8ec87f55e19402493bb2df501ae9d2da75db0
23382338
```
2339-
2339+
23402340
Get the result of the contract execution with the getTransactionInfoById command:
23412341
```console
23422342
getTransactionInfoById b375787a098498623403c755b1399e82910385251b643811936d914c9f37bd27

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ compileJava.options*.compilerArgs = [
2020
repositories {
2121
mavenLocal()
2222
mavenCentral()
23+
maven { url 'https://jitpack.io' }
2324
}
2425

2526
sourceSets {
@@ -89,6 +90,7 @@ dependencies {
8990
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
9091

9192
compile group: 'org.jline', name: 'jline', version: '3.15.0'
93+
compile 'com.github.tronprotocol:zksnark-java-sdk:master-SNAPSHOT'
9294
}
9395

9496
protobuf {
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package org.tron.common.zksnark;
2+
3+
import org.tron.common.zksnark.LibrustzcashParam.BindingSigParams;
4+
import org.tron.common.zksnark.LibrustzcashParam.CheckOutputNewParams;
5+
import org.tron.common.zksnark.LibrustzcashParam.CheckOutputParams;
6+
import org.tron.common.zksnark.LibrustzcashParam.CheckSpendNewParams;
7+
import org.tron.common.zksnark.LibrustzcashParam.CheckSpendParams;
8+
import org.tron.common.zksnark.LibrustzcashParam.ComputeCmParams;
9+
import org.tron.common.zksnark.LibrustzcashParam.ComputeNfParams;
10+
import org.tron.common.zksnark.LibrustzcashParam.CrhIvkParams;
11+
import org.tron.common.zksnark.LibrustzcashParam.FinalCheckNewParams;
12+
import org.tron.common.zksnark.LibrustzcashParam.FinalCheckParams;
13+
import org.tron.common.zksnark.LibrustzcashParam.InitZksnarkParams;
14+
import org.tron.common.zksnark.LibrustzcashParam.IvkToPkdParams;
15+
import org.tron.common.zksnark.LibrustzcashParam.KaAgreeParams;
16+
import org.tron.common.zksnark.LibrustzcashParam.KaDerivepublicParams;
17+
import org.tron.common.zksnark.LibrustzcashParam.MerkleHashParams;
18+
import org.tron.common.zksnark.LibrustzcashParam.OutputProofParams;
19+
import org.tron.common.zksnark.LibrustzcashParam.SpendProofParams;
20+
import org.tron.common.zksnark.LibrustzcashParam.SpendSigParams;
21+
import org.tron.core.exception.ZksnarkException;
22+
23+
public class JLibrustzcash {
24+
private static Librustzcash INSTANCE = LibrustzcashWrapper.getInstance();
25+
26+
public static void librustzcashInitZksnarkParams(InitZksnarkParams params) {
27+
INSTANCE.librustzcashInitZksnarkParams(params.getSpend_path(),
28+
params.getSpend_hash(), params.getOutput_path(), params.getOutput_hash());
29+
}
30+
31+
public static void librustzcashCrhIvk(CrhIvkParams params) {
32+
INSTANCE.librustzcashCrhIvk(params.getAk(), params.getNk(), params.getIvk());
33+
}
34+
35+
public static boolean librustzcashKaAgree(KaAgreeParams params) {
36+
return INSTANCE.librustzcashSaplingKaAgree(params.getP(), params.getSk(), params.getResult());
37+
}
38+
39+
public static boolean librustzcashComputeCm(ComputeCmParams params) {
40+
return INSTANCE.librustzcashSaplingComputeCm(params.getD(), params.getPkD(),
41+
params.getValue(), params.getR(), params.getCm());
42+
}
43+
44+
public static boolean librustzcashComputeNf(ComputeNfParams params) {
45+
INSTANCE.librustzcashSaplingComputeNf(params.getD(), params.getPkD(), params.getValue(),
46+
params.getR(), params.getAk(), params.getNk(), params.getPosition(), params.getResult());
47+
return true;
48+
}
49+
50+
/**
51+
* @param ask the spend authorizing key,to generate ak, 32 bytes
52+
* @return ak 32 bytes
53+
*/
54+
public static byte[] librustzcashAskToAk(byte[] ask) throws ZksnarkException {
55+
LibrustzcashParam.valid32Params(ask);
56+
byte[] ak = new byte[32];
57+
INSTANCE.librustzcashAskToAk(ask, ak);
58+
return ak;
59+
}
60+
61+
/**
62+
* @param nsk the proof authorizing key, to generate nk, 32 bytes
63+
* @return 32 bytes
64+
*/
65+
public static byte[] librustzcashNskToNk(byte[] nsk) throws ZksnarkException {
66+
LibrustzcashParam.valid32Params(nsk);
67+
byte[] nk = new byte[32];
68+
INSTANCE.librustzcashNskToNk(nsk, nk);
69+
return nk;
70+
}
71+
72+
// void librustzcash_nsk_to_nk(const unsigned char *nsk, unsigned char *result);
73+
74+
/**
75+
* @return r: random number, less than r_J, 32 bytes
76+
*/
77+
public static byte[] librustzcashSaplingGenerateR(byte[] r) throws ZksnarkException {
78+
LibrustzcashParam.valid32Params(r);
79+
INSTANCE.librustzcashSaplingGenerateR(r);
80+
return r;
81+
}
82+
83+
public static boolean librustzcashSaplingKaDerivepublic(KaDerivepublicParams params) {
84+
return INSTANCE.librustzcashSaplingKaDerivepublic(params.getDiversifier(), params.getEsk(),
85+
params.getResult());
86+
}
87+
88+
public static long librustzcashSaplingProvingCtxInit() {
89+
return INSTANCE.librustzcashSaplingProvingCtxInit();
90+
}
91+
92+
/**
93+
* check validity of d
94+
*
95+
* @param d 11 bytes
96+
*/
97+
public static boolean librustzcashCheckDiversifier(byte[] d) throws ZksnarkException {
98+
LibrustzcashParam.valid11Params(d);
99+
return INSTANCE.librustzcashCheckDiversifier(d);
100+
}
101+
102+
public static boolean librustzcashSaplingSpendProof(SpendProofParams params) {
103+
return INSTANCE.librustzcashSaplingSpendProof(params.getCtx(), params.getAk(),
104+
params.getNsk(), params.getD(), params.getR(), params.getAlpha(), params.getValue(),
105+
params.getAnchor(), params.getVoucherPath(), params.getCv(), params.getRk(),
106+
params.getZkproof());
107+
}
108+
109+
public static boolean librustzcashSaplingOutputProof(OutputProofParams params) {
110+
return INSTANCE.librustzcashSaplingOutputProof(params.getCtx(), params.getEsk(),
111+
params.getD(), params.getPkD(), params.getR(), params.getValue(), params.getCv(),
112+
params.getZkproof());
113+
}
114+
115+
public static boolean librustzcashSaplingSpendSig(SpendSigParams params) {
116+
return INSTANCE.librustzcashSaplingSpendSig(params.getAsk(), params.getAlpha(),
117+
params.getSigHash(), params.getResult());
118+
}
119+
120+
public static boolean librustzcashSaplingBindingSig(BindingSigParams params) {
121+
return INSTANCE.librustzcashSaplingBindingSig(params.getCtx(),
122+
params.getValueBalance(), params.getSighash(), params.getResult());
123+
}
124+
125+
/**
126+
* convert value to 32-byte scalar
127+
*
128+
* @param value 64 bytes
129+
* @param data 32 bytes
130+
*/
131+
public static void librustzcashToScalar(byte[] value, byte[] data) throws ZksnarkException {
132+
LibrustzcashParam.validParamLength(value, 64);
133+
LibrustzcashParam.valid32Params(data);
134+
INSTANCE.librustzcashToScalar(value, data);
135+
}
136+
137+
public static void librustzcashSaplingProvingCtxFree(long ctx) {
138+
INSTANCE.librustzcashSaplingProvingCtxFree(ctx);
139+
}
140+
141+
public static long librustzcashSaplingVerificationCtxInit() {
142+
return INSTANCE.librustzcashSaplingVerificationCtxInit();
143+
}
144+
145+
public static boolean librustzcashSaplingCheckSpend(CheckSpendParams params) {
146+
return INSTANCE.librustzcashSaplingCheckSpend(params.getCtx(), params.getCv(),
147+
params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(),
148+
params.getSpendAuthSig(), params.getSighashValue());
149+
}
150+
151+
public static boolean librustzcashSaplingCheckOutput(CheckOutputParams params) {
152+
return INSTANCE.librustzcashSaplingCheckOutput(params.getCtx(), params.getCv(),
153+
params.getCm(), params.getEphemeralKey(), params.getZkproof());
154+
}
155+
156+
public static boolean librustzcashSaplingFinalCheck(FinalCheckParams params) {
157+
return INSTANCE.librustzcashSaplingFinalCheck(params.getCtx(),
158+
params.getValueBalance(), params.getBindingSig(), params.getSighashValue());
159+
}
160+
161+
public static boolean librustzcashSaplingCheckSpendNew(CheckSpendNewParams params) {
162+
return INSTANCE.librustzcashSaplingCheckSpendNew(params.getCv(),
163+
params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(),
164+
params.getSpendAuthSig(), params.getSighashValue());
165+
}
166+
167+
public static boolean librustzcashSaplingCheckOutputNew(CheckOutputNewParams params) {
168+
return INSTANCE.librustzcashSaplingCheckOutputNew(params.getCv(), params.getCm(),
169+
params.getEphemeralKey(), params.getZkproof());
170+
}
171+
172+
public static boolean librustzcashSaplingFinalCheckNew(FinalCheckNewParams params) {
173+
return INSTANCE
174+
.librustzcashSaplingFinalCheckNew(params.getValueBalance(), params.getBindingSig(),
175+
params.getSighashValue(), params.getSpendCv(), params.getSpendCvLen(),
176+
params.getOutputCv(), params.getOutputCvLen());
177+
}
178+
179+
public static void librustzcashSaplingVerificationCtxFree(long ctx) {
180+
INSTANCE.librustzcashSaplingVerificationCtxFree(ctx);
181+
}
182+
183+
public static boolean librustzcashIvkToPkd(IvkToPkdParams params) {
184+
return INSTANCE.librustzcashIvkToPkd(params.getIvk(), params.getD(), params.getPkD());
185+
}
186+
187+
public static void librustzcashMerkleHash(MerkleHashParams params) {
188+
INSTANCE.librustzcashMerkleHash(params.getDepth(), params.getA(), params.getB(),
189+
params.getResult());
190+
}
191+
192+
/**
193+
* @param result uncommitted value, 32 bytes
194+
*/
195+
public static void librustzcashTreeUncommitted(byte[] result) throws ZksnarkException {
196+
LibrustzcashParam.valid32Params(result);
197+
INSTANCE.librustzcashTreeUncommitted(result);
198+
}
199+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.tron.common.zksnark;
2+
3+
import org.tron.common.zksnark.JLibsodiumParam.Black2bSaltPersonalParams;
4+
import org.tron.common.zksnark.JLibsodiumParam.Blake2bFinalParams;
5+
import org.tron.common.zksnark.JLibsodiumParam.Blake2bInitSaltPersonalParams;
6+
import org.tron.common.zksnark.JLibsodiumParam.Blake2bUpdateParams;
7+
import org.tron.common.zksnark.JLibsodiumParam.Chacha20Poly1305IetfEncryptParams;
8+
import org.tron.common.zksnark.JLibsodiumParam.Chacha20poly1305IetfDecryptParams;
9+
10+
public class JLibsodium {
11+
public static final int CRYPTO_GENERICHASH_BLAKE2B_PERSONALBYTES = 16;
12+
public static final int CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES = 12;
13+
private static Libsodium INSTANCE = LibsodiumWrapper.getInstance();
14+
15+
public static int cryptoGenerichashBlake2bInitSaltPersonal(Blake2bInitSaltPersonalParams params) {
16+
return INSTANCE
17+
.cryptoGenerichashBlake2BInitSaltPersonal(params.getState(), params.getKey(),
18+
params.getKeyLen(), params.getOutLen(), params.getSalt(), params.getPersonal());
19+
}
20+
21+
public static int cryptoGenerichashBlake2bUpdate(Blake2bUpdateParams params) {
22+
return INSTANCE
23+
.cryptoGenerichashBlake2BUpdate(params.getState(), params.getIn(), params.getInLen());
24+
}
25+
26+
public static int cryptoGenerichashBlake2bFinal(Blake2bFinalParams params) {
27+
return INSTANCE.cryptoGenerichashBlake2BFinal(params.getState(),
28+
params.getOut(), params.getOutLen());
29+
}
30+
31+
public static int cryptoGenerichashBlack2bSaltPersonal(Black2bSaltPersonalParams params) {
32+
return INSTANCE.cryptoGenerichashBlake2BSaltPersonal(params.getOut(), params.getOutLen(),
33+
params.getIn(), params.getInLen(), params.getKey(), params.getKeyLen(),
34+
params.getSalt(),
35+
params.getPersonal());
36+
}
37+
38+
public static int cryptoAeadChacha20poly1305IetfDecrypt(
39+
Chacha20poly1305IetfDecryptParams params) {
40+
return INSTANCE
41+
.cryptoAeadChacha20Poly1305IetfDecrypt(params.getM(), params.getMLenP(),
42+
params.getNSec(),
43+
params.getC(), params.getCLen(), params.getAd(),
44+
params.getAdLen(), params.getNPub(), params.getK());
45+
}
46+
47+
public static int cryptoAeadChacha20Poly1305IetfEncrypt(
48+
Chacha20Poly1305IetfEncryptParams params) {
49+
return INSTANCE
50+
.cryptoAeadChacha20Poly1305IetfEncrypt(params.getC(), params.getCLenP(), params.getM(),
51+
params.getMLen(), params.getAd(), params.getAdLen(),
52+
params.getNSec(), params.getNPub(), params.getK());
53+
}
54+
55+
public static long initState() {
56+
return INSTANCE.cryptoGenerichashBlake2BStateInit();
57+
}
58+
59+
public static void freeState(long state) {
60+
INSTANCE.cryptoGenerichashBlake2BStateFree(state);
61+
}
62+
}

0 commit comments

Comments
 (0)