Socket
Book a DemoInstallSign in
Socket

@harmony-js/crypto

Package Overview
Dependencies
Maintainers
3
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/crypto

crypto libraries for harmony

0.1.56
latest
npmnpm
Version published
Weekly downloads
677
-12.19%
Maintainers
3
Weekly downloads
 
Created
Source

@harmony-js/crypto

This package provides a collection of apis related to address management, kestore, encoding, and encrypt/decrypt.

Installation

npm install @harmony-js/crypto

Usage

const {
  encode,
  decode,
  randomBytes,
  toBech32,
  fromBech32,
  HarmonyAddress,
  generatePrivateKey,
  getPubkeyFromPrivateKey,
  getAddressFromPublicKey,
  getAddressFromPrivateKey,
  encryptPhrase,
  decryptPhrase
} = require('@harmony-js/crypto');
const { isPrivateKey, isAddress, isPublicKey } = require('@harmony-js/utils');

Address apis

const bytes = randomBytes(20);
const addr = new HarmonyAddress(bytes);

console.log(addr.checksum);
console.log(addr.bech32);

console.log(HarmonyAddress.isValidBech32(addr.bech32));

RLP apis

const encoded = '0x89010101010101010101';
const decoded = '0x010101010101010101';
console.log(encode(decoded));
console.log(decode(encoded));

Keystore apis

const prv = generatePrivateKey();
const pub = getPubkeyFromPrivateKey(prv);
const addr = getAddressFromPublicKey(pub);
const addrPrv = getAddressFromPrivateKey(prv);
console.log(isPrivateKey(prv));
console.log(isPublicKey(pub));
console.log(isAddress(addr));
console.log(isAddress(addrPrv));

Encrypt/decrypt apis

const { Wallet } = require('@harmony-js/account');

const myPhrase = new Wallet().newMnemonic();
console.log(myPhrase);
const pwd = '1234';
encryptPhrase(myPhrase, pwd).then((value) => {
  console.log(value);
  decryptPhrase(JSON.parse(value), pwd).then(value => {
    console.log(value);
  });
});

FAQs

Package last updated on 22 Nov 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.