Giter Site home page Giter Site logo

nimiq / core-js Goto Github PK

View Code? Open in Web Editor NEW
993.0 98.0 208.0 14.68 MB

Official JavaScript implementation of the Nimiq protocol

Home Page: https://nimiq.com

License: Other

HTML 1.29% CSS 1.01% JavaScript 83.50% Python 0.37% Makefile 0.07% C 12.15% C++ 0.72% Go 0.26% Shell 0.34% Dockerfile 0.29%
cryptocurrency javascript nimiq

core-js's Introduction

Nimiq Blockchain Build Status

Nimiq is a frictionless payment protocol for the web.

Resources

Demo

Check out our Testnet.

Packages

Prebuilt binary packages

For users looking to run a standalone Nimiq node (which is also capable of mining), see our Downloads page for installable Linux and Windows binary packages.

NPM Packages

For developers looking to include Nimiq support on their applications, there are two npm packages available:

  • @nimiq/core: Module for use in node.js applications.
  • @nimiq/core-web: Module for use in client-side (browser) applications (includes the same files that are available from our CDN).

Quickstart

  1. Install Node.js >= v16.20.2.
  2. On Ubuntu and Debian, install git and build-essential: sudo apt-get install -y git build-essential.
  3. Install yarn globally: sudo npm install -g yarn.
  4. Install gulp globally: yarn global add gulp.
  5. Clone this repository: git clone https://github.com/nimiq/core-js.
  6. Build the project: cd core-js && yarn && yarn build.
  7. Open clients/browser/index.html in your browser.

Web Developers

Simple Web Application on top of Nimiq

A good way to get started is to have a look at the most simple web application on top of the Nimiq Blockchain.

Getting Started

Follow the Quickstart guide or make use of our CDN:

<script src="https://cdn.nimiq.com/latest/nimiq.js"></script>

Browser client

Open clients/browser/index.html in your browser or include <script src="dist/nimiq.js"></script> in your project.

Node.js client

To run a Node.js client you will need a publicly routable IP, Domain, and SSL Certificate (get a free certificate at letsencrypt.org). Start the client by running clients/nodejs/nimiq with the respective configuration.

Test and Build

Run Testsuite

  • yarn test runs browser and Node.js tests.
  • yarn test-browser runs the testsuite in your browser only.
  • yarn test-node runs the testsuite in Node.js only.

Run ESLint

yarn lint runs the ESLint javascript linter.

Build

Executing yarn build concatenates all sources into dist/{web,web-babel,web-crypto,node}.js

Contribute

If you'd like to contribute to the development of Nimiq please follow our Code of Conduct and Contributing Guidelines.

License

This project is under the Apache License 2.0.

core-js's People

Contributors

arthurgervais avatar azard avatar beeppool avatar bettelstab avatar curdbecker avatar danimoh avatar dependabot[bot] avatar donquixo13 avatar eligioo avatar fiaxh avatar jeffesquivels avatar josefschabasser avatar jsdanielh avatar kunanigaming avatar mar-v-in avatar newsfusion avatar nikhil22 avatar paberr avatar panoramicrum avatar riptl avatar robinlinus avatar ryan-rowland avatar schrnz avatar sisou avatar stefanmattern avatar styppo avatar svub avatar tobiaslins avatar tomkha avatar zhuweiyou 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  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

core-js's Issues

Weird Private Key implementation

In contrast to the PublicKey class that is well-used across the core, the PrivateKey implementation seems to be a copy-pasted version (actually in line 12 there is PublicKey instead of PrivateKey) that is never really used.

The problem is that, again in contrast to pub keys, private keys cannot be exported in 'raw' format in the subtle crypto lib we are using. Hence, while the 65 byte size of pub keys makes sense, the private key can only be represented as, e.g., 'pkcs8', which requires different handling.

Issue #2 also indicates that the private key topic is still somewhat open.

I think the current implementation is more like a stub. Depending on what we need the class for in the long run (serializing it for wallet portability maybe?), the implementation should reflect the way it is exported from the crypto lib.

TL;DR: I don't see how to use the PrivateKey class as-is (or where it is used), so either it needs additional explanation or another implementation.

BlockUtils conversion does not work both ways

I added new tests specifying the functionality of the new BlockUtils class.
Build #18 is now failing, because converting a difficulty to compact and back does not return the same difficulty.

This is easy to verify for several difficulties (e.g., 250) and the following code:
difficulty == BlockUtils.compactToDifficulty(BlockUtils.difficultyToCompact(difficulty))

Moreover, I have a question regarding valid values for difficulty:
What values are allowed for a difficulty? 0 does not seem to be valid, since BlockUtils divides by the difficulty. Is Policy.BLOCK_TARGET_MAX the maximal value?

  • Verify bug
  • Fix bug
  • Answer question regarding valid range of difficulties

pushTransaction() in Mempool is incorrectly recording sender public keys

The property for a sender public key in a transaction is senderPubKey, but Mempool.pushTransaction() is using transaction.publicKey instead, which means every transaction (after the first one) gets rejected because the code thinks they all have the same sender public key (i.e. undefined).

Exception in importPrivate in Crypto.js

The importPrivate in Crypto.js throws the following Exception:
Failed to execute 'importKey' on 'SubtleCrypto': 5 arguments required, but only 2 present.

If you want, I can add a test to the crypto.spec.js

Get balance 0 for unknown address

Currently a call to getBalance(address) in Accounts.js gives false for an unknown address. Probably getting 0 or a Balance instance with value 0 would be desirable.

Sanity of timestamp not checked

The following might be a small vulnerability:
Blocks with an arbitrary timestamp seem to get accepted as long as they are at a later date then the current head. If a malicious miner then commits a valid block with the last possible timestamp and this block becomes the new head, any block mined on top of that with a honest valid timestamp will be rejected because it is not later then the head.

Update: The malicious miner could use this issue for example by submitting valid blocks with timestamps that increment by a rather big amount, e.g. one week. Thereby, the difficulty will decrease and it will be easy for the malicious miner to mine a lot of blocks. Of course the total work doesn't imcrement that much by doing so, so another branch can outperform that malicious blockchain. However, the code must not get stuck on that malicious blockchain. A possible solution might be to not accept heads that have a timestamp much later then the current time in _isValidExtension in Blockchain.js.

Save Private Key to Wallet after Import

Importing a private key to the Wallet does not seem to be fully implemented yet.
I guess after creating a CryptoKey from an ArrayBuffer using importPrivate(privateKey) it should be stored in _keys and if the wallet is persistent also in the WalletStore ?

Update: Or probably it would be better to actually remove that import method and then do importing by creating a new Wallet instance with the keys to import and then maybe have a setPersistent Method in the wallet that can save the keys to the WalletStore?

Add version fields to models

Primarily models persisted in the blockchain:

  • blocks
  • transactions
  • ...

Might also be relevant for models exchanged via network.

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.