生成本地签名信息

调用 orderSign 方法生成本地签名信息,r,s,v 在返回结果中展示。

const TronWeb = require("tronweb");

const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.shasta.trongrid.io");
const solidityNode = new HttpProvider("https://api.shasta.trongrid.io");
const eventServer = new HttpProvider("https://api.shasta.trongrid.io");

// crate tronWeb
function newTronWeb(privateKey) {
    let tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
    return tronWeb
}

async function orderSign(orderHash, arg2) {  // orderHash comes from response json of hashOrder
    const tronWeb = newTronWeb(arg2)
    const signature = await tronWeb.trx.sign(orderHash, tronWeb.defaultPrivateKey, true);
    const result = signature.substring(2);
    const r = "0x" + result.substring(0, 64);
    const s = "0x" + result.substring(64, 128);
    const v = parseInt(result.substring(128, 130), 16);// The signature is now comprised of r, s, and v.
    return Promise.resolve({
        r, s, v, signature
    });
}

想了解更多关于 tronweb 的信息,请点击 这里