Xing94 / fil-bls-sign-rs

filecoin bls sign for android
3 stars 0 forks source link

fil-bls-sign-rs

FileCoin官方Bls签名地址参考版本:Jun 16, 2020

Jni :也可以在项目文件 Cargo.toml 点击jni项目左边进入jni官方介绍

Android交叉编译mac配置

本项目是由filecoin-ffi 交叉编译版本

需自己打包Android所需的so包,cargo-config.toml 中的ndk地址为自己本地的ndk地址;

Java项目使用方法:

1.创建seed Java_com_lxx_nativerust_FilecoinBlsSignUtil_generateBlsSeed

    //输出值为已hex字符串
    String hexSeed = FilecoinBlsSignUtil.generateBlsSeed();

2.通过privateKey获取publicKey Java_com_lxx_nativerust_FilecoinBlsSignUtil_filPrivateKeyPublicKey

    //都是已hex的值
    String hexPrivateKey = Hex.toHexString(privateKeyBytes);
    String hexPublicKey = FilecoinBlsSignUtil.filPrivateKeyPublicKey(hexPrivateKey); 

3.通过seed创建私钥 Java_com_lxx_nativerust_FilecoinBlsSignUtil_filPrivateKeyGenerateWithSeed

    String hexPrivateKey = FilecoinBlsSignUtil.filPrivateKeyGenerateWithSeed(hexSeed);

4.进行bls签名 Java_com_lxx_nativerust_FilecoinBlsSignUtil_filPrivateKeySign

    /**
     * cid的方式与Secp256k1签名方式一致,需将cid的字节数组转换为hex值,传入进来,
     * 输出值为已经hex的签名的值,最后需要将其转换为base64,放到message中,传入接口
     */
    Stirng hexCidMessage = Hex.toHexString(cidBytes)
    String hexSign = FilecoinBlsSignUtil.filPrivateKeySign(hexPrivateKey,hexCidMessage);