Files
admin 3ad3f30929 docs(tools): 国密链真链复现脚本与证据入库,避免散落 /tmp 后丢失
- 新增 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 历史。
2026-11-08 14:53:51 +08:00

106 lines
3.9 KiB
Java

import org.fisco.bcos.sdk.jni.common.JniLibLoader;
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionBuilderJniObj;
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionDataV1;
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionStructBuilderJniObj;
import org.fisco.bcos.sdk.jni.utilities.tx.Transaction;
import org.fisco.bcos.sdk.jni.utilities.tx.TxPair;
import org.fisco.bcos.sdk.jni.utilities.signature.SignatureJniObj;
/**
* 官方 bcos-sdk-jni 地面真值对拍。
*
* 用法:
* java -cp bcos-sdk-jni.jar Oracle hash <json-file>
* java -cp bcos-sdk-jni.jar Oracle sign <json-file> <keyHex>
*/
public class Oracle {
// CryptoType: 0 = SM3/国密 (见 sdk 的 CryptoType)
static final int SM = 0;
public static void main(String[] args) throws Exception {
JniLibLoader.loadJniLibrary();
String mode = args[0];
String jsonPath = args[1];
String text = new String(java.nio.file.Files.readAllBytes(
java.nio.file.Paths.get(jsonPath)), "utf-8");
// 极简 JSON 字段读取(避免依赖外部 JSON 库):形如 "key":"value" / "key":123
String abi = jstr(text, "abi");
String to = jstr(text, "to");
String nonce = jstr(text, "nonce");
String chainId = jstr(text, "chainId");
String groupId = jstr(text, "groupId");
String inputHex = jstr(text, "input");
long blockLimit = jlong(text, "blockLimit");
long gasLimit = jlong(text, "gasLimit");
String value = jstr(text, "value");
String gasPrice = jstr(text, "gasPrice");
String maxFee = jstr(text, "maxFeePerGas");
String maxPrio = jstr(text, "maxPriorityFeePerGas");
int version = (int) jlong(text, "version");
TransactionDataV1 d = new TransactionDataV1();
d.setVersion(version);
d.setChainId(chainId);
d.setGroupId(groupId);
d.setNonce(nonce);
d.setTo(to);
d.setAbi(abi);
d.setBlockLimit(blockLimit);
d.setInput(fromHex(inputHex));
d.setValue(value);
d.setGasPrice(gasPrice);
d.setGasLimit(gasLimit);
d.setMaxFeePerGas(maxFee);
d.setMaxPriorityFeePerGas(maxPrio);
String hash = TransactionStructBuilderJniObj.calcTransactionDataStructHash(SM, d);
System.out.println("OFFICIAL_HASH=" + hash);
String encData = TransactionStructBuilderJniObj.encodeTransactionDataStruct(d);
System.out.println("OFFICIAL_TARS=" + encData);
if (mode.equals("sign")) {
String keyHex = args[2];
String encodedTx = TransactionStructBuilderJniObj.createEncodedTransaction(
d, keyHex, "", 1, "");
System.out.println("OFFICIAL_TX=" + encodedTx);
}
}
static byte[] fromHex(String h) {
if (h == null) return new byte[0];
h = h.startsWith("0x") ? h.substring(2) : h;
int n = h.length() / 2;
byte[] out = new byte[n];
for (int i = 0; i < n; i++) {
out[i] = (byte) Integer.parseInt(h.substring(i * 2, i * 2 + 2), 16);
}
return out;
}
static String jstr(String text, String key) {
String pat = "\"" + key + "\"";
int i = text.indexOf(pat);
if (i < 0) return "";
int c = text.indexOf(':', i);
int q = text.indexOf('"', c + 1);
if (q < 0) return "";
int e = text.indexOf('"', q + 1);
if (e < 0) return "";
return text.substring(q + 1, e);
}
static long jlong(String text, String key) {
String pat = "\"" + key + "\"";
int i = text.indexOf(pat);
if (i < 0) return 0;
int c = text.indexOf(':', i);
int s = c + 1;
while (s < text.length() && Character.isWhitespace(text.charAt(s))) s++;
int e = s;
while (e < text.length() && (Character.isDigit(text.charAt(e)) || text.charAt(e) == '-')) e++;
return Long.parseLong(text.substring(s, e));
}
}