How to use the 0x.js.signatureUtils.ecSignHashAsync function in 0x

To help you get started, we’ve selected a few 0x examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / testnet-faucets / src / ts / handler.ts View on Github external
makerAssetData,
            takerAssetData,
            salt: generatePseudoRandomSalt(),
            makerFeeAssetData: makerAssetData,
            takerFeeAssetData: takerAssetData,
            feeRecipientAddress: NULL_ADDRESS,
            senderAddress: NULL_ADDRESS,
            expirationTimeSeconds: new BigNumber(Date.now() + FIVE_DAYS_IN_MS)
                // tslint:disable-next-line:custom-no-magic-numbers
                .div(1000)
                .integerValue(BigNumber.ROUND_FLOOR),
            exchangeAddress: contractAddresses.exchange,
            chainId: chainConfig.chainId,
        };
        const orderHash = orderHashUtils.getOrderHashHex(order);
        const signature = await signatureUtils.ecSignHashAsync(
            chainConfig.web3Wrapper.getProvider(),
            orderHash,
            configs.DISPENSER_ADDRESS,
        );
        const signedOrder: SignedOrder = {
            ...order,
            signature,
        };
        const payload = JSON.stringify(signedOrder);
        logUtils.log(`Dispensed signed order: ${payload}`);
        res.status(constants.SUCCESS_STATUS).send(payload);
    }
}
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction.ts View on Github external
};

    const exchangeAddress = contractAddresses.exchange;
    const order: Order = {
        ...orderWithoutExchangeAddress,
        exchangeAddress,
    };
    printUtils.printOrder(order);

    // Print out the Balances and Allowances
    await printUtils.fetchAndPrintContractAllowancesAsync();
    await printUtils.fetchAndPrintContractBalancesAsync();

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);
    const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);

    const signedOrder: SignedOrder = {
        ...order,
        signature,
    };

    // This is an ABI encoded function call that the taker wishes to perform
    // in this scenario it is a fillOrder
    const fillData = contractWrappers.exchange.fillOrder.getABIEncodedTransactionData(
        signedOrder,
        takerAssetAmount,
        signedOrder.signature,
    );
    // Generate a random salt to mitigate replay attacks
    const takerTransactionSalt = generatePseudoRandomSalt();
    // The taker signs the operation data (fillOrder) with the salt
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction_cancel_order.ts View on Github external
printUtils.printOrderInfos({ order: orderInfo });

    // This is an ABI encoded function call that the taker wishes to perform
    // in this scenario it is a fillOrder
    const cancelData = contractWrappers.exchange.cancelOrder.getABIEncodedTransactionData(signedOrder);
    // Generate a random salt to mitigate replay attacks
    const makerCancelOrderTransactionSalt = generatePseudoRandomSalt();
    // The maker signs the operation data (cancelOrder) with the salt
    const zeroExTransaction = {
        data: cancelData,
        salt: makerCancelOrderTransactionSalt,
        signerAddress: maker,
        verifyingContractAddress: contractAddresses.exchange,
    };
    const executeTransactionHex = transactionHashUtils.getTransactionHashHex(zeroExTransaction);
    const makerCancelOrderSignatureHex = await signatureUtils.ecSignHashAsync(
        providerEngine,
        executeTransactionHex,
        maker,
    );
    // The sender submits this operation via executeTransaction passing in the signature from the taker
    txHash = await contractWrappers.exchange.executeTransaction.validateAndSendTransactionAsync(
        zeroExTransaction.salt,
        zeroExTransaction.signerAddress,
        zeroExTransaction.data,
        makerCancelOrderSignatureHex,
        {
            gas: TX_DEFAULTS.gas,
            from: sender,
        },
    );
    const txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('executeTransaction', txHash);
github 0xProject / 0x-starter-project / src / scenarios / fill_order_multi_asset.ts View on Github external
makerAssetData,
        takerAssetData,
        makerFee: ZERO,
        takerFee: ZERO,
    };

    printUtils.printOrder(order);

    // Print out the Balances and Allowances
    await printUtils.fetchAndPrintContractAllowancesAsync();
    await printUtils.fetchAndPrintContractBalancesAsync();
    await printUtils.fetchAndPrintERC721OwnerAsync(dummyERC721TokenContract.address, tokenId);

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);
    const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
    const signedOrder = { ...order, signature };
    // Fill the Order via 0x.js Exchange contract
    txHash = await contractWrappers.exchange.fillOrder.validateAndSendTransactionAsync(
        signedOrder,
        takerAssetAmount,
        signedOrder.signature,
        {
            from: taker,
            gas: TX_DEFAULTS.gas,
        },
    );
    const txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('fillOrder', txHash);
    printUtils.printTransaction('fillOrder', txReceipt, [['orderHash', orderHashHex]]);

    // Print the Balances
    await printUtils.fetchAndPrintContractBalancesAsync();
github 0xProject / 0x-starter-project / src / scenarios / fill_order_erc20.ts View on Github external
takerAssetAmount,
        makerAssetData,
        takerAssetData,
        makerFee: ZERO,
        takerFee: ZERO,
    };

    printUtils.printOrder(order);

    // Print out the Balances and Allowances
    await printUtils.fetchAndPrintContractAllowancesAsync();
    await printUtils.fetchAndPrintContractBalancesAsync();

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);
    const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
    const signedOrder = { ...order, signature };

    // Validate the order is Fillable before calling fillOrder
    // Fill the Order via 0x Exchange contract
    txHash = await contractWrappers.exchange.fillOrder.validateAndSendTransactionAsync(
        signedOrder,
        takerAssetAmount,
        signedOrder.signature,
        { from: taker, gas: TX_DEFAULTS.gas },
    );
    txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('fillOrder', txHash);
    printUtils.printTransaction('fillOrder', txReceipt, [['orderHash', orderHashHex]]);

    // Print the Balances
    await printUtils.fetchAndPrintContractBalancesAsync();
github 0xProject / 0x-starter-project / src / scenarios / fill_order_sra.ts View on Github external
takerAssetData,
    };
    const orderConfig = await httpClient.getOrderConfigAsync(orderConfigRequest, {
        networkId: NETWORK_CONFIGS.networkId,
    });

    // Create the order
    const order: Order = {
        salt: generatePseudoRandomSalt(),
        ...orderConfigRequest,
        ...orderConfig,
    };

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);
    const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
    const signedOrder = { ...order, signature };

    // Validate this order
    // await contractWrappers.exchange.validateOrderFillableOrThrowAsync(signedOrder);

    // Submit the order to the SRA Endpoint
    await httpClient.submitOrderAsync(signedOrder, { networkId: NETWORK_CONFIGS.networkId });

    // Taker queries the Orderbook from the Relayer
    const orderbookRequest: OrderbookRequest = { baseAssetData: makerAssetData, quoteAssetData: takerAssetData };
    const response = await httpClient.getOrderbookAsync(orderbookRequest, { networkId: NETWORK_CONFIGS.networkId });
    if (response.asks.total === 0) {
        throw new Error('No orders found on the SRA Endpoint');
    }
    const sraOrder = response.asks.records[0].order;
    printUtils.printOrder(sraOrder);
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction.ts View on Github external
const fillData = contractWrappers.exchange.fillOrder.getABIEncodedTransactionData(
        signedOrder,
        takerAssetAmount,
        signedOrder.signature,
    );
    // Generate a random salt to mitigate replay attacks
    const takerTransactionSalt = generatePseudoRandomSalt();
    // The taker signs the operation data (fillOrder) with the salt
    const zeroExTransaction = {
        data: fillData,
        salt: takerTransactionSalt,
        signerAddress: taker,
        verifyingContractAddress: contractAddresses.exchange,
    };
    const executeTransactionHex = transactionHashUtils.getTransactionHashHex(zeroExTransaction);
    const takerSignatureHex = await signatureUtils.ecSignHashAsync(providerEngine, executeTransactionHex, taker);
    // The sender submits this operation via executeTransaction passing in the signature from the taker
    txHash = await contractWrappers.exchange.executeTransaction.validateAndSendTransactionAsync(
        zeroExTransaction.salt,
        zeroExTransaction.signerAddress,
        zeroExTransaction.data,
        takerSignatureHex,
        {
            gas: TX_DEFAULTS.gas,
            from: sender,
        },
    );
    const txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('executeTransaction', txHash);
    printUtils.printTransaction('Execute Transaction fillOrder', txReceipt, [['orderHash', orderHashHex]]);

    // Print the Balances
    await printUtils.fetchAndPrintContractBalancesAsync();
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction_cancel_order.ts View on Github external
};

    const exchangeAddress = contractAddresses.exchange;
    const order: Order = {
        ...orderWithoutExchangeAddress,
        exchangeAddress,
    };
    printUtils.printOrder(order);

    // Print out the Balances and Allowances
    await printUtils.fetchAndPrintContractAllowancesAsync();
    await printUtils.fetchAndPrintContractBalancesAsync();

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);
    const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);

    const signedOrder: SignedOrder = {
        ...order,
        signature,
    };
    let orderInfo = await contractWrappers.exchange.getOrderInfo.callAsync(signedOrder);
    printUtils.printOrderInfos({ order: orderInfo });

    // This is an ABI encoded function call that the taker wishes to perform
    // in this scenario it is a fillOrder
    const cancelData = contractWrappers.exchange.cancelOrder.getABIEncodedTransactionData(signedOrder);
    // Generate a random salt to mitigate replay attacks
    const makerCancelOrderTransactionSalt = generatePseudoRandomSalt();
    // The maker signs the operation data (cancelOrder) with the salt
    const zeroExTransaction = {
        data: cancelData,