- 新增 tools/fisco-realnode/:真链实证期用过的 Python SDK 发送器 (fj-sdk/)、Java JNI 独立交叉验证探针 (jni/)、TARS 编解码辅助 (tars/), 作为审计轨迹留档,便于回看签名口径根因。 - 新增 example.chain.json(非密钥,可入库)与 README.md 索引:明确 规范入口 (selftest-fisco-contract.py 主门禁第22条) 与审计轨迹的分工、 复现所需环境变量、下载项、密钥与诚实边界。 - .gitignore 屏蔽私钥 (*.pem/*.key)、下载型二进制 (jar/tar.gz) 与大证据 blob,防止密钥或体积大的文件进 git 历史。
61 lines
2.4 KiB
Java
61 lines
2.4 KiB
Java
import org.fisco.bcos.sdk.jni.common.JniLibLoader;
|
|
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionStructBuilderJniObj;
|
|
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionDataV1;
|
|
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionBuilderJniObj;
|
|
import org.fisco.bcos.sdk.jni.utilities.keypair.KeyPairJniObj;
|
|
import java.nio.file.*;
|
|
|
|
/**
|
|
* 官方 SDK 正确用法的最小复现。
|
|
* 严格照抄 DefaultTransactionManager.createTransactionData 的调用序列:
|
|
* 1) calcTransactionDataStructHash(cryptoType, data)
|
|
* 2) signTransactionDataHash(jniKeyPair, hash)
|
|
* 3) createEncodedTransaction(data, signature, hash, attribute, extraData)
|
|
*/
|
|
public class OffReal {
|
|
static final int SM = 0;
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
JniLibLoader.loadJniLibrary();
|
|
String abi = new String(Files.readAllBytes(Paths.get(args[0])), "utf-8");
|
|
byte[] input = Files.readAllBytes(Paths.get(args[1]));
|
|
String nonce = args[2];
|
|
String privHex = args[3];
|
|
long gasLimit = Long.parseLong(args[4]);
|
|
int attribute = Integer.parseInt(args[5]);
|
|
|
|
// 用真实私钥建 JNI 密钥对
|
|
byte[] priv = new byte[32];
|
|
for (int i = 0; i < 32; i++) priv[i] = (byte) Integer.parseInt(privHex.substring(i*2, i*2+2), 16);
|
|
long kp = KeyPairJniObj.createJniKeyPair(SM, priv);
|
|
System.out.println("JNI_PUB=" + KeyPairJniObj.getJniKeyPairPubKey(kp));
|
|
|
|
TransactionDataV1 d = new TransactionDataV1();
|
|
d.setVersion(1);
|
|
d.setChainId("chain0");
|
|
d.setGroupId("group0");
|
|
d.setNonce(nonce);
|
|
d.setTo("");
|
|
d.setAbi(abi);
|
|
d.setBlockLimit(500);
|
|
d.setInput(input);
|
|
d.setValue("0x0");
|
|
d.setGasPrice("0x0");
|
|
d.setGasLimit(gasLimit);
|
|
d.setMaxFeePerGas("0x0");
|
|
d.setMaxPriorityFeePerGas("0x0");
|
|
|
|
String hash = TransactionStructBuilderJniObj.calcTransactionDataStructHash(SM, d);
|
|
System.out.println("OFFICIAL_HASH=" + hash);
|
|
|
|
String signature = TransactionBuilderJniObj.signTransactionDataHash(kp, hash);
|
|
System.out.println("OFFICIAL_SIG=" + signature);
|
|
|
|
String tx = TransactionStructBuilderJniObj.createEncodedTransaction(
|
|
d, signature, hash.substring(2), attribute, "");
|
|
System.out.println("OFFICIAL_TX=" + tx);
|
|
|
|
KeyPairJniObj.destroyJniKeyPair(kp);
|
|
}
|
|
}
|