Giter Club home page Giter Club logo

quorum.js's Introduction

quorum.js: JavaScript API for Quorum

quorum.js is an extension for web3.js which adds support for APIs specific to Quorum.

⚠️ Project Deprecation Notice ⚠️

quorum.js library will be deprecated on December 31st 2021, date from when we will stop supporting the project.

quorum.js library is deprecated and replaced by web3js-quorum that offers wider compatibility with the Quorum stack including both Besu and GoQuorum.

From now on, we encourage all users with active projects using quorum.js to migrate to web3js-quorum. Please refer to migration instructions.

We will continue to support quorum.js in particular fixing bugs until the end of 2021.

If you have any questions or concerns, please reach out to the ConsenSys protocol engineering team on #Discord or by email.

Features

  • Provide js applications with easy access to all Quorum-specific APIs (including private transaction, consensus, and permissioning APIs)
  • Works with web3.js smart contract wrappers

Requirements

Installation

npm install quorum-js

Quickstart

The Quorum-specific API methods provided by quorum.js are accessed in one of two ways:

Extending web3 object

const Web3 = require("web3");
const quorumjs = require("quorum-js");

const web3 = new Web3("http://localhost:22000");

quorumjs.extend(web3);

web3.quorum.eth.sendRawPrivateTransaction(signedTx, args);

This makes Quorum-specific API methods available through the web3.quorum object.

RawTransactionManager object

Additional private transaction-specific APIs require access to a Privacy Manager:

const Web3 = require("web3");
const quorumjs = require("quorum-js");

const web3 = new Web3("http://localhost:22000");

const enclaveOptions = {
  privateUrl: "http://localhost:9081" // Tessera ThirdParty server url, use ipcPath if using Constellation
};

const txnMngr = quorumjs.RawTransactionManager(web3, enclaveOptions);

txnMngr.sendRawTransaction(args);

Documentation

For full usage and API details see the documentation.

Examples

The 7nodes-test directory contains examples of quorum.js usage. These scripts can be tested with a running 7nodes test network.

Getting Help

Stuck at some step? Please join our slack community for support.

quorum.js's People

Contributors

0xigor avatar achraf17 avatar amalrajmani avatar antonydenyer avatar baptiste-b-pegasys avatar bmcd avatar chris-j-h avatar cruzmolina avatar fixanoid avatar namtruong avatar nicolae-leonte-go avatar nmvalera avatar prd-fox avatar satpalsandhu61 avatar sebaraba avatar trung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quorum.js's Issues

Expose storeRawRequest and sendRawRequest via txnManager

Expose/export storeRawRequest and sendRawRequest via txnManager in order to allow external signing for transactions.
In addition we should also expose setPrivate (to make it easy to set the private flag after the transaction is sgined externally).

The README.md shows how the above methods can be used (https://github.com/jpmorganchase/quorum.js#send-raw-transactions-using-external-signer-only-available-in-tessera-with-quorum-v220) with the txnManager but they are not actually exposed.

From field in signed transaction

Why don´t you use the field "from" in this transaction?

https://docs.goquorum.com/en/latest/Getting%20Started/api/

var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')
var rawTx = {
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
// This data should be the hex value of the hash returned by Quorum's privacy transaction manager after invoking storeraw api
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
//console.log(serializedTx.toString('hex'));
//f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f
web3.eth.sendRawPrivateTransaction('0x' + serializedTx.toString('hex'), {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}, function(err, hash) {
if (!err)
console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
});

Extending web3js does not work with eth.subscribe

I'm using eth.subscribe('newBlockHeaders') which has an outputFormatter that the quorumjs.extend(web3) does not patch. I'm able to patch it manually, but maybe there is a way to make sure that this is covered by the existing extend function:

processNewBlocks() {
    var sub = this.web3.eth.subscribe('newBlockHeaders', function (error, _) {
      if (error) console.log(error);
    })
    
    if (process.env.QUORUM == 'true') {
      // Patch the output formatter for Quorum
      sub.options.subscription.outputFormatter = this.web3.eth.getBlock.method.outputFormatter;
    }
    
    sub.on('data', function(blockHeader) {
      // process blocks
    });
  }

How secure is this?

Hey I was running through the example to deployContractViaHttp-externalSigningTemplate.js?
Is this code secure to run on an actual production server?

const signAcct = web3.eth.accounts.decrypt(
  {
    address: accAddress,
    crypto: {
      cipher: "aes-128-ctr",
      ciphertext:
        "4e77046ba3f699e744acb4a89c36a3ea1158a1bd90a076d36675f4c883864377",
      cipherparams: {iv: "a8932af2a3c0225ee8e872bc0e462c11"},
      kdf: "scrypt",
      kdfparams: {
        dklen: 32,
        n: 262144,
        p: 1,
        r: 8,
        salt: "8ca49552b3e92f79c51f2cd3d38dfc723412c212e702bd337a3724e8937aff0f"
      },
      mac: "6d1354fef5aa0418389b1a5d1f5ee0050d7273292a1171c51fd02f9ecff55264"
    },
    id: "a65d1ac3-db7e-445d-a1cc-b6c5eeaa05e0",
    version: 3
  },
  ""
);
 

I wanted a safe way to send a transaction on the production server where the GETH node is running.

QuorumJS Private Signed Transactions not working

We are trying to deploy a signed private transaction using quorum js and our code looks something like this. We have followed the instructions from npm description of
the package

const web3 = new Web3(new Web3.providers.HttpProvider(address));
const quorumjs = require("quorum-js");
 
const txnManager = quorumjs.enclaves.GenericEnclave(web3, "", "http://localhost:8080", "http://localhost:9081");

We seem to be getting an error while creating the txnManager, and enclaves seem to be undefined

How to use with Azure Blockchain Service?

Hello Guys, you did some great work and I love it.

I have an Azure Blockchain Service: which is running Quorum 2.2.3

So it has all the latest updates, I am running two nodes in it (and another one for validation)

I cannot find or access Tessera to encrypt and send a private transaction, I don't know where or how to get the privateUrl or API...

const rtmViaAPI = quorumjs.RawTransactionManager(web3, {
        privateUrl: "https://x5engine.blockchain.azure.com:3200"//can't find the right endpoint sadly
      })
      const rawTransaction = {
        nonce: `0x${nonce.toString(16)}`,
        from: "0x3f833ebc25100a391C61a2D40A3f16a08c98FB0c",
        to: "0xc5bAd721fb0CDE3FBa9B952BFA8B0B703Cc822C6",
        value: `0x${(0).toString(16)}`,
        gasLimit: `0x${(4300000).toString(16)}`,
        gasPrice: `0x${(0).toString(16)}`,
        data: encoded,
        privateFor: ["llGj6iwxark5ULgJ7vh1x6mmrI8KeDbFpd28xCg1YFk="],
        // privateFrom: "nOzQJIDGKR3Qa7yBwfp4TDnHawdxJU61RtXzuy1O4lg=",
        isPrivate: true
      };
      //this is how it should be sent as private
      rtmViaAPI.sendRawTransaction(rawTransaction)
       .then(function (o, e) {
             console.log("Sending private txn using newer API");
             console.log(o, e);
        });

I have access to the nodes and can send and ready transaction perfectly.

You can see my repo and live app here and also check the logs.

Sending on node 1 as private and getting the transaction from node 2 and normally should be encrypted on it and can't be read.

So either it is enabled and I can't find where the privateUrl or endpoint is, or it is not enabled and I have to deploy the 7nodes examples which have Quorum nodes and I can access the server to enable or change the settings ( but I don't prefer this method because it will take more of my credit and I need to use Azure Blockchain Service)

Thank you

Tessera enclave issue

I've performed the following test using the 7nodes example (in raft mode with tessera as the transaction manager):
#./raft-init.sh
#./raft-start.sh tessera

Then in a node console I've executed the following:

const Web3 = require("web3");
const web3 = new Web3( new Web3.providers.HttpProvider("http://localhost:22001"));
const quorumjs = require("quorum-js");
const tessera = quorumjs.encalves.Tessera(web3, "http://localhost:9081", "http://localhost:9081");
const signAcct = web3.eth.accounts.decrypt({"address":"ed9d02e382b34818e88b88a309c7fe71e65f419d","crypto":{"cipher":"aes-128-ctr","ciphertext":"4e77046ba3f699e744acb4a89c36a3ea1158a1bd90a076d36675f4c883864377","cipherparams":{"iv":"a8932af2a3c0225ee8e872bc0e462c11"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"8ca49552b3e92f79c51f2cd3d38dfc723412c212e702bd337a3724e8937aff0f"},"mac":"6d1354fef5aa0418389b1a5d1f5ee0050d7273292a1171c51fd02f9ecff55264"},"id":"a65d1ac3-db7e-445d-a1cc-b6c5eeaa05e0","version":3}, '');
var bytecode = "0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050505b806000819055505b505b610104806100456000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605157806360fe47b11460775780636d4ce63c146097575b600080fd5b3415605b57600080fd5b606160bd565b6040518082815260200191505060405180910390f35b3415608157600080fd5b6095600480803590602001909190505060c3565b005b341560a157600080fd5b60a760ce565b6040518082815260200191505060405180910390f35b60005481565b806000819055505b50565b6000805490505b905600a165627a7a72305820d5851baab720bba574474de3d09dbeaabc674a15f4dd93b974908476542c23f00029";
const rawTransactionManager = quorumjs.RawTransactionManager(web3, tessera);
rawTransactionManager.sendRawTransaction({gasPrice: 0, gasLimit: 4300000, to: "", value: 0, data: bytecode, from: signAcct, isPrivate: true, privateFrom: "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=", privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="], nonce: 1});

After a few seconds I can see the following error in the node console:

(node:10309) UnhandledPromiseRejectionWarning: Error: Returned error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash
at Object.ErrorResponse (/home/nicolae/node_modules/web3-core-helpers/src/errors.js:29:16)
at /home/nicolae/node_modules/web3-core-requestmanager/src/index.js:140:36
at XMLHttpRequest.request.onreadystatechange (/home/nicolae/node_modules/web3-providers-http/src/index.js:96:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/nicolae/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/home/nicolae/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/home/nicolae/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage. (/home/nicolae/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
(node:10309) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

I can confirm that the /storeraw tessera API is invoked:

13:36:35.453 [grizzly-http-server-0] INFO c.q.tessera.api.filter.LoggingFilter - Enter Request : POST : /storeraw
13:36:35.567 [grizzly-http-server-0] INFO c.q.tessera.api.filter.LoggingFilter - Exit Request : POST : /storeraw
13:36:35.567 [grizzly-http-server-0] INFO c.q.tessera.api.filter.LoggingFilter - Response for storeraw : 200 OK

However - I can't see any evidence that eth_sendRawPrivateTransaction is being invoked.

How does quorum.js handle revert reason returned from the require failures of smart contract

I have raised the question in discord:
https://discord.com/channels/697535391594446898/722244032407011359/1028984434483023922

Ideally, the client side code should receive the exact message of transaction failure or validation error triggered using the require checks.

I have tried the other options using web3j references but they are not working.
web3/web3.js#1707
https://github.com/pertsev/web3_utilz/blob/master/revert%20reason/index.js
https://ethereum.stackexchange.com/questions/84545/how-to-get-reason-revert-using-web3-eth-call

https://web3js.readthedocs.io/en/v1.2.8/web3-eth.html#handlerevert

Please provide some insights into this.

Thanks in advance.

TypeError: web3.extend is not a function

The provided method extend in web3js 1.0.0.beta38 does no longer exist since Jan 26, 2019. According to its official medium
So the function quorumjs.extend(web3) doesn't work --

TypeError: web3.extend is not a function

const web3 = new Web3("http://xxxx");
const quorumjs = require("quorum-js");
quorumjs.extend(web3);

Failed sendRawTransaction doesn't return correct error message

The internals of sendRawRequest() do not catch the case where eth_sendRawPrivateTransaction failed, and attempt to retrieve a non-existent Transaction Receipt. This results in invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash being returned to the caller instead of a meaningful message.

To reproduce:

Send a signed transaction where one of the participants does not exist (or where the txn mngr is down). e.g.:

    txnMngr.sendRawRequest(privateSignedTxHex, [NON_EXISTANT_PUBLIC_KEY]).then(....)

This will fail with ERROR: sendRawRequest() failed: Error: Returned error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash.
Examining the quorum logs reveals that the actual failure is Recipient not found for key: xxxx.

external http signing template not working for private transactions

I tried deploying SimpleStorage contract on kaliedo quorum nodes(via node's json RPC address) with example you provided. I modified things that needed to modify. when I run this on node.js I ended up getting this error.

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    at Function.from (buffer.js:219:9)
    at base64toHex (C:\Users\ethdev\Desktop\qjs-dapp\lib\rawTransactionManager.js:18:19)
    at C:\Users\ethdev\Desktop\qjs-dapp\lib\rawTransactionManager.js:29:16
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

I thought it is the problem with buffer types in rawransactionManager.js module. or it is the problem with my setup?. please let me know how to fix this. quick response form u r end is highly appreciable
@fixanoid

Using constellation, failing to decode transaction in constellation.log

ERROR: constellation Failed to decode '/sendsignedtx'

CODE:
var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')
var rawTx = {
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
// This data should be the hex value of the hash returned by Quorum's privacy transaction manager after invoking storeraw api
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
//console.log(serializedTx.toString('hex'));
//f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f
web3.eth.sendRawPrivateTransaction('0x' + serializedTx.toString('hex'), {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}, function(err, hash) {
if (!err)
console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
});

Broken link in the README.md

The link mentioned in the README.md does not exists anymore:

Works out the box with web3.js' 
    [smart contract wrappers](http://docs.web3j.io/smart_contracts.html#solidity-smart-contract-wrappers)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.