@nexex/api
Version:
support trade on nexex network
48 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("@nexex/types");
var ethers_1 = require("ethers");
var signatureUtils_1 = require("./signatureUtils");
var bigNumberify = ethers_1.utils.bigNumberify, hexlify = ethers_1.utils.hexlify, solidityKeccak256 = ethers_1.utils.solidityKeccak256;
function getOrderHashHex(order) {
var orderParts = [
{ value: order.exchangeContractAddress, type: types_1.SolidityTypes.Address },
{ value: order.maker, type: types_1.SolidityTypes.Address },
{ value: order.taker, type: types_1.SolidityTypes.Address },
{ value: order.makerTokenAddress, type: types_1.SolidityTypes.Address },
{ value: order.takerTokenAddress, type: types_1.SolidityTypes.Address },
{ value: order.makerFeeRecipient, type: types_1.SolidityTypes.Address },
{
value: new ethers_1.utils.BigNumber(order.makerTokenAmount),
type: types_1.SolidityTypes.Uint256
},
{
value: bigNumberify(order.takerTokenAmount),
type: types_1.SolidityTypes.Uint256
},
{
value: bigNumberify(order.makerFeeRate),
type: types_1.SolidityTypes.Uint256
},
{
value: bigNumberify(order.takerFeeRate),
type: types_1.SolidityTypes.Uint256
},
{
value: bigNumberify(order.expirationUnixTimestampSec),
type: types_1.SolidityTypes.Uint256
},
{ value: bigNumberify(order.salt), type: types_1.SolidityTypes.Uint256 }
];
var types = orderParts.map(function (o) { return o.type; });
var values = orderParts.map(function (o) { return o.value; });
var hashBuff = solidityKeccak256(types, values);
return hexlify(hashBuff);
}
exports.getOrderHashHex = getOrderHashHex;
function isValidOrder(order) {
var hash = getOrderHashHex(order);
return signatureUtils_1.signatureUtils.isValidSignature(hash, order.ecSignature, order.maker);
}
exports.isValidOrder = isValidOrder;
//# sourceMappingURL=orderUtil.js.map