Javascript SDK of WoopChain protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
sdk/packages/harmony-crypto
Ganesha Upadhyaya 5eddd0feb2 v0.1.58 2 years ago
..
src Replace scrypt-shim with scrypt.js; add test (#128) 2 years ago
test Replace scrypt-shim with scrypt.js; add test (#128) 2 years ago
LICENSE [feat] update LICENSE 6 years ago
README.md Improve README with clear examples throughout packages 4 years ago
package-lock.json v0.1.58 2 years ago
package.json v0.1.58 2 years ago
tsconfig.json fix(travis):test travis 5 years ago
tsconfig.test.json feat(test):add more test and remove unused function 5 years ago

README.md

@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);
  });
});