Code Monkey home page Code Monkey logo

conseiljs's Introduction

Note: As of January 2023, ConseilJS is maintained on a best effort basis for Tezos: https://discourse.cryptonomic.tech/t/psa-conseil-conseiljs-will-now-be-maintained-on-a-best-effort-basis-for-tezos/235/2

ConseilJS-core

npm version npm Build Status Coverage Status Quality Gate Status conseiljs

A library for building decentralized applications in Typescript and Javascript, currently focused on the Tezos platform.

ConseilJS connects to Tezos nodes for live chain data and operations and to Conseil servers for high-performance analytics on blockchain data. Internally, Cryptonomic uses Nautilus for infrastructure deployments of these services. This is the library at the core of our products – Arronax, Periscope, Harpoon and certainly Galleon. There are ReasonML bindings as well.

Cryptonomic offers an infrastructure service - Nautilus Cloud which enables quick access to the Tezos platform along with products that make it easier build on it.

Sub-modules

As of version 5.0.0, ConseilJS has been split into three parts: this library, which is considered to be the core, ConseilJS-softsigner and ConseilJS-ledgersigner. This was done in an effort to make the library more portable across different environments. If neither of these additional modules meet your needs, the Signer and KeyStore interfaces can be implemented separately. In addition to a Signer and a KeyStore, fetch and logger objects are required to be provided, see below.

For more details on how to use these libraries see their respective readme files: ConseilJS-core, ConseilJS-softsigner, ConseilJS-ledgersigner. There is also an AWS KMS signer that is compatible with ConseilJS, maintained by @tacoinfra.

Use with Nodejs

Add our NPM package to your project and a signing library.

npm i conseiljs
npm i conseiljs-softsigner
import fetch from 'node-fetch';
import * as log from 'loglevel';

import { registerFetch, registerLogger, Signer, TezosMessageUtils } from 'conseiljs';
import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner';

const logger = log.getLogger('conseiljs');
logger.setLevel('debug', false);
registerLogger(logger);
registerFetch(fetch);

let signer: Signer;
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH');
signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1);

Use with React

We have a complete React application tutorial for you to check out.

Use with React Native

Project honeybadger, which is the basis for Galleon Mobile us built with ConseilJS as well. Due to limitations of react-native we re-implemented some of the necessary functionality into a separate module.

Use with Web

<html>
<head>
    <script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs/dist-web/conseiljs.min.js"
        integrity="sha256-RsfjLoUXxZo1G4OGSlIuZEkSkVnlqn1eMvAYXwYwXXnnfMyiYg/PNWqjv4oWA2tb"
        crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs-softsigner/dist-web/conseiljs-softsigner.min.js"
        integrity="sha384-V1iaajn0x/SMFcZ9Y/xNQmqQSKyll6Dzt27U6OWiv8NdbHTVaHOGHdQ8g0G68HPd"
        crossorigin="anonymous"></script>
    <script>
        //conseiljssoftsigner.
    </script>
</head>
<body>
    ...
</body>
</html>

The web version sets fetch and logger internally to window.fetch and console respectively.

A fully functional sample html page is available too.

API Overview and Examples

We have ready-to-use examples to copy/paste.

Contribute

There are many ways to contribute to this project. You can develop applications or dApps with it. You can submit bug reports or feature requests. You can ask questions about it on r/Tezos or the Tezos StackExchange. We certainly welcome pull requests as well.

Other references

Developer Handbook

Smart Contract Development Syllabus

Wiki

Riot Dev Channel

Cryptonomic Reddit

The Cryptonomic Aperiodical

@CryptonomicTech

conseiljs's People

Contributors

anonymoussprocket avatar ba205 avatar coder0377 avatar developer0623 avatar gdsoumya avatar itamarreif avatar jurajselep avatar keefertaylor avatar modev0323 avatar neocybereth avatar prathamrawat avatar romarq avatar teckhuac avatar ulrikstrid avatar umurb avatar vishakh avatar walterproof avatar yourcodesucks 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  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  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

conseiljs's Issues

Refactor branches and packages to reflect multiple environments

All code in the master branch should be compatible with the Tezos mainnet and should be published as the ConseilJS NPM package.
All code in the staging branch should be compatible with the Tezos zeronet and should be published as the ConseilJS-staging NPM package.
All code in the develop branch should be compatible with the Tezos alphanet and should be published as the ConseilJS-dev NPM package.*

The above information should be included in the root README file.

*As Cryptonomic is not yet running alphanet nodes, we must use zeronet for now.

Remove redundencies in TezosOperations module

sendTransactionOperation(), sendDelegationOperation() and sendOriginationOperation() are not following the DRY principle and should be refactored so the operation payloads are not duplicated several times.

NPM Package not available

Looking to use your client side library but it looks like the NPM package isn't available. Any idea when this will be available again?

Change managerPubKey to manager_pubkey for origination operations

Due to a recent merge in the Tezos zeronet codebase, there should be a ConseilJS deployment which constructs origination payloads compliant with zeronet.

This change should be made on a issue-specific branch which should then be merged into a zeronet branch, upon which a specific NPM package deployment can be made.

Migrate away from fsPromises library

As conseiljs is used in an Electron wallet app and Electron doesn't seem to work with fsPromises', all file operations should be reverted to using fs`.

Remove dist folder from Develop branch

Once Tezori can successfully pull from ConseilJS using the GitHub oauth url in package.json and compile the imported typescript on their end, there is no need for the compiled javascript folder, dist, to be in ConseilJS anymore.

Reveal operations should not incur fees

Currently, reveals incur fees, and since reveals are now bundled with transactions, delegations, and originations, there can be unexpected doubling of fees. We want reveals to not insure any fees, even when bundled with other operations.

Improve exception handling for wallet loading

In loadWallet() in TezosWallet, we are returning a promise which performs a set of operations. However, as one of lines could throw an exception. We do not catch any expectations so they die silently. The code should be changed so that any exception will lead to the promise being rejected.

Parse Michelson Scripts into JSON

We want users to be able to deploy smart contracts on the tezos node with conseiljs using actual Michelson scripts. To do this, we have to send a json-ified version of the Michelson code to comply with the Tezos RPC.

Get ConseilJS working as an NPM module

The NPM package settings for ConseilJS should be verified for correctness.

Any project importing conseiljs should have access to everything in TezosOperations, TezosConseilQuery, TezosNodeQuery and TezosWallet.

Add HD wallet support

The TezosWallet module was written with the option of adding HD wallet support. The logic must now be extended to allow HD support to prepare for hardware wallet support.

  • Incorporate BIP32 library for supporting derivation paths and refactor getKeysFromMnemonicAndPassphrase() to explicitly use BIP32.
  • Split getKeysFromMnemonicAndPassphrase() into two functions - getSeedFromMnemonicAndPassphrase() and getKeysFromSeed()
  • 'getKeysFromMnemonicAndPassphrase()' should also take an optional derivation path argument.
  • `getSeedFromMnemonicAndPassphrase()' should take as parameters - a fifteen or twenty-four word mnemonic, an optional passphrase, - and return a seed.
  • 'getKeysFromSeed()' should take as parameters - a seed and a derivation path- and return a key store corresponding to the root account.*
  • A new getDerivedAddress() function should take as parameters - a seed, a derivation path and an index - and return a key store corresponding to a derived account.
  • A new getAllActiveDerivedAddresses() function should take as parameters - a seed and a derivation path - and return all derived addresses which can be found on the Tezos blockchain.

HD wallet usage of the above:

  • Ask user for a mnemonic
  • Call getKeysFromMnemonicAndPassphrase() with above to get the root address and seed.
  • Call getAllActiveDerivedAddresses() with the above seed and a derivation path to get a list of all derived addresses.
  • To create a new derived address, call getKeysFromSeed() with the above seed and the next index.
  • To load an existing wallet, fetch the seed of the root address from disk and then call getAllActiveDerivedAddresses().

The Wallet interface currently supports an arbitrary number of KeyStores. Any client is free to add as many KeyStores, therefore as many seeds, to a wallet file as they want. However, in HD mode, we want a wallet file to contain no more than a single seed. Therefore, we must implement a new HDWallet interface which essentially inherits from Wallet but constrains the number of KeyStores to a maximum of one and the KeyStore object to contain a non-null seed.

Enhance invoke operation

To invoke contracts, a user will select custom fee, gas limit, and storage limits. Besides these three parameters, a user will have the option to provide additional parameters. Although we don't have the designs ready for the Galleon, I can say that it will somewhat look similar to what TezBox has at the moment:

screen shot 2018-12-19 at 4 06 52 pm

As agreed on Riot, this ticket will be implemented after we figure out the smart contract originations.

Calculate fee defaults

Rather than using static values as #69 does, calculate fee defaults.

Update the individual Reveal as well.

Error Messages: Improve Operation error handling

We need more detailed error messages, especially during the importing fundraiser account scene.

Currently, we can't display anything other than 'Provided string does not look like hex data'

Make the distinction between a delegated address and a smart contract

A delegated address and a smart contract look almost identical (both start with KT1) but they are two completely different entities. The simplest way to determine if a KT1 address is a smart contract or a delegated address is to run a getAccount and check the script field.

If script is null then this KT1 address is a delegated address
If script is not null then this KT1 address is a smart contract

We need to make this distinction to determine the following two things:

1- Did the user enter a valid address whilst invoking a contract

verificatino

If the user enters an invalid smart contract address, Tezori should warn the user.
Tezori is already making the offline checks (is the address 36 chars long, are there any special characters in the address etc.). Please add the second tier check mentioned above.

Also, can you please change the below offline validation rule, and only allow KT addresses to be entered in this field.

Screen Shot 2019-03-11 at 11 48 06 AM

2- To list the originated contract in the correct section

Currently, any originated contract will be listed as a Delegated Address in Tezori. Currently, any originated contract will be listed as a Delegated Address in Tezori. We need to list the smart contracts and delegated addresses separately as shown belown.

Screen Shot 2019-03-11 at 11 56 03 AM

Enforce wallet password strength

The password supplied for creating wallets must be at least eight characters long.

This should be done in createWallet() in TezosWallet.

The relevant unit test should also be added.

Validate mnemonic length for unlocking Tezos identities

getKeysFromMnemonicAndPassphrase() in CryptoUtils does not enforce a mnemonic length and this should be changed. The mnemonic should be a fifteen word string, e.g.:

clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say tenant`

The relevant unit test should also be added.

Improve code coverage

Review the Coveralls results, and expand coverage in the following:

  • /reporting/ConseilDataClient.ts
  • /reporting/ConseilMetadataClient.ts
  • /chain/tezos/TezosNodeWriter.ts

These should be unit tests, they will require nock'ed responses.

Enhance origination operation

We want to allow ConseilJS users to originate smart contracts. Here is some informational material which will help us develop this feature.

  1. Recently TezosTeam launched TST token on Tezos. Investigating their transaction and smart contracts will help.

They originated 2 contracts:
Origination Operation 1 -> Smart Contract 1
Origination Operation 2 -> Smart Contract 2

When investigated on chain, these are the fields to the operations:

screen shot 2018-12-19 at 5 03 50 pm

Script field includes the contract code written in Michelson parsed in JSON. (Serialization/Deserialization process of the Michelson code will be taken care of by the Conseil team.)
I've sent the whole json of the origination operations to you on Riot.

You may consider following this tutorial to write a simple smart contract to test.

Password characters should be enforced when wallets are created

Currently, createWallet() in TezosWallet only checks for password length but not the characters. It is, for example, possible to enter eight spaces as the password. This should be fixed by ensuring all supplied passwords only contain upper case & lower case letters, numbers or a fixed set of symbols.

Counter_in_the_past error for transactions for develop branch

For TezosHardwareOperations.spec.ts in the develop branch, when a transaction is attempted from ledger into a dummy account on alphanet, the id of the injected transaction operation reads "proto.002-PsYLVpVv.contract.counter_in_the_past". This should be amended so counters are incremented correctly.

Set fees in a principled manner

The Conseil backend now allows the calculation of high, medium and low fees based on some parameters. ConseilJS should wrap this functionality and make it available to downstream clients.

Add support for Ledger hardware wallet

This ticket requires two headline changes:

  1. The TezosOperations module has been written with the assumption that is called only by file-based wallets with access to a user's keys. Instead, it should support operation functionality without assuming the keys are transparently available.
  2. The operation signing algorithm currently requires explicit keys. There should be an alternative that submits the actual signing to a hardware device.
  3. The TezosWallet module currently only supports mnemonic-based address retrieval for file-based wallets. It should also support the BIP39 / BIP32 retrieval of addresses from hardware wallets.
  • There should be a new enum called HardwareDeviceType with a single member for now called Ledger. Options such as Trezor can added later.
  • There should be a new unlockHardwareIdentity() function should take a device type, a derivation path and an index. If the device type is 'Ledger', Ledger.js is invoked to get the corresponding public key hash.
  • A new getAllActiveDerivedHardwareAddresses() function should take as parameters - a device type, a seed and a derivation path - and return all derived addresses which can be found on the Tezos blockchain.
  • There should be a new signOperationGroupWithHardware() function which takes a forged operation, a device type, a derivation path and an index. If the device type is 'Ledger' then invokes Ledger.js to sign the operation.
  • There should be a new sendOperationWithHardware() function which is similar to sendOperation() but takes a derivation path and index instead of a key store.
  • For each sendXOperation() instance, there should be a corresponding new sendXOperationWithHardwareWallet() which does not take a KeyStore and, instead, takes a derivation path and index.

Estimating burn for operations

At the moment, only origination operation is burning gas and the gas burnt for this operation is constant, 0.257 tz.

But this might change in the future. We need to have a function to estimate the burn.

Make Ledger package a peer dependency

Ledger being a dependency in conseilJS is causing troubles with Arronax's webpack.
Make Ledger (also Trezor in the future) package a peer dependency

Use zxcvbn to enforce password strength requirements

The zxcvbn library should be used to enforce password strengths. Each supplied password should be tested and any passwords with a score of less than three should be rejected. https://github.com/dropbox/zxcvbn#usage explains the usage of the library.

  • Add new function to CryptoUtils for testing password strength.
  • Invoke the new function from encryptMessage() in 'CryptoUtils`
  • Remove the eight character check from createWallet() in TezosWallet

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.