New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

com.rotilho.jnano:jnano-commons

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.rotilho.jnano:jnano-commons

JNano provides a set of low level Nano operations that includes signing, seed generation, block hashing and account creation.

  • 1.5.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Build Status Codacy Badge Codacy Badge Maven Central

JNano Commons

JNano provides a set of low level Nano operations that includes signing, seed generation, block hashing and account creation.

How to use it?

Gradle compile 'com.rotilho.jnano:jnano-commons:1.4.1

Maven

<dependency>
    <groupId>com.rotilho.jnano</groupId>
    <artifactId>jnano-commons</artifactId>
    <version>1.4.1</version>
</dependency>

All low level operations are handled by NanoSeeds, NanoKeys, NanoAccounts, NanoBlocks, NanoWorks*, NanoSignatures and NanoMnemonics.

// create seed
byte[] seed = NanoSeeds.generateSeed();
assertTrue(NanoSeeds.isValid(seed));

// create private key
byte[] privateKey = NanoKeys.createPrivateKey(seed, 0);
byte[] publicKey = NanoKeys.createPublicKey(privateKey);

// create account
String account = NanoAccounts.createAccount(publicKey);
assertTrue(NanoAccounts.isValid(account));

// by default Nano account type is used, but you can also use Banano
String bananoAccount = NanoAccounts.createAccount(NanoBaseAccountType.BANANO, publicKey);
assertTrue(NanoAccounts.isValid(NanoBaseAccountType.BANANO, account));

// convert account to publicKey
assertTrue(Arrays.equals(NanoAccounts.toPublicKey(account), publicKey));

// create block hash
String hash = NanoBlocks.hashStateBlock(
        account, // account
        NanoBlocks.MAIN_NET_GENESIS, //previous block
        account, // representative
        BigInteger.ONE, // balance
        NanoAccounts.MAIN_NET_GENESIS_ACCOUNT // link: target address in this case
);
assertTrue(NanoBlocks.isValid(hash));

// sign a block hash
String signature = NanoSignatures.sign(privateKey, hash);
assertTrue(NanoSignatures.isValid(account, hash, signature));

* Java use just CPU and calculate PoW with CPU is bloody slow. For production ready application please use a work server.

Why not use string for Seed and Keys?

As stated by Baeldung, "strings in Java are immutable which means that we cannot change them using any high-level APIs. Any change on a String object will produce a new String, keeping the old one in memory.

Therefore, the password stored in a String will be available in memory until Garbage Collector clears it. We cannot control when it happens, but this period can be significantly longer than for regular objects since Strings are kept in a String Pool for re-usability purpose".

Most of the time work with byte array will be enough but if there is the need to convert it to String you can easily achieve it using NanoHelper.toHex.

If you want to reduce the time the privets keys or seed stay in memory you can use NanoHelper.wipe and clear out the byte array content.

Special thanks to
  • Harry and his Rain project which were used in the first implementation
  • Scott Lanoue for all help
  • NovaCrypto and it BIP39 which were used as inspiration

FAQs

Package last updated on 30 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc