EOS离线签名

最新版本建议用https://github.com/EOSIO/eosjs-ecc里面的签名函数来处理:

ecc.sign('hello eos', privatekey)

c++实现版本(待验证)

void SignedTransaction::sign(const std::vector<unsigned char> &pri_key, const TypeChainId &cid)
{
    std::vector<unsigned char> packedBytes = getDigestForSignature(cid);

    uint8_t packedSha256[SHA256_DIGEST_LENGTH];
    sha256_Raw(packedBytes.data(), packedBytes.size(), packedSha256);

    uint8_t signature[uECC_BYTES * 2] = { 0 };
    int recId = uECC_sign_forbc(pri_key.data(), packedSha256, signature);
    if (recId == -1) {
        // could not find recid, data probably already signed by the key before?
        return;
    } else {
        unsigned char bin[65+4] = { 0 };
        unsigned char *rmdhash = NULL;
        int binlen = 65+4;
        int headerBytes = recId + 27 + 4;
        bin[0] = (unsigned char)headerBytes;
        memcpy(bin + 1, signature, uECC_BYTES * 2);

        unsigned char temp[67] = { 0 };
        memcpy(temp, bin, 65);
        memcpy(temp + 65, "K1", 2);

        rmdhash = RMD(temp, 67);
        memcpy(bin + 1 +  uECC_BYTES * 2, rmdhash, 4);

        char sigbin[100] = { 0 };
        size_t sigbinlen = 100;
        b58enc(sigbin, &sigbinlen, bin, binlen);
        std::string sig = "SIG_K1_";
        sig += sigbin;

        signatures.push_back(sig);
    }
}

参考:https://github.com/OracleChain/EOSDevHelper.git

eosjs实现版本

/** Sign a transaction */
    public async sign({ chainId, requiredKeys, serializedTransaction }: SignatureProviderArgs) {
        const signBuf = Buffer.concat([
            new Buffer(chainId, "hex"), new Buffer(serializedTransaction), new Buffer(new Uint8Array(32)),
        ]);

        const signatures = requiredKeys.map(
            (pub) => ecc.Signature.sign(signBuf, this.keys.get(convertLegacyPublicKey(pub))).toString(),
        );

       return { signatures, serializedTransaction };

    }

说明:
const test = ecc.Signature.sign(new Buffer("0xa123","hex"),privatekey);
这个得到的就是
"SIG_K1_K9eDsXiqEMkJs8wPwEjiN6hL1h2Bm3gGQtUheidFczWNdBmDF24AUuPmiosi9CwtEW3jPFPao7HYWLJ63ic3TggjnoKtJF"
即离线签名的signatures,有了这个再push_transaction就可以完成交易了

java版本(已验证可用)

https://blog.csdn.net/liu1765686161/article/details/83308819
https://github.com/eosio/eosjs#offline-or-cold-storage-transaction:
https://eosc.app/

https://github.com/EOSIO/eosjs/blob/v16.0.8/src/write-api.js#L498-L510

https://github.com/OracleChain/EOSDevHelper

https://eosfans.io/topics/1176