Keystore file
password string
privateKey
decrypt phrase
This method will map the current Account object to V3Keystore object.
encrypt Phrase
Using this function to get Harmony format address
private key string
address with length = 40
public key string
address with length = 40
getDerivedKey
NOTE: only scrypt and pbkdf2 are supported.
the passphrase
the key derivation function to be used
params for the kdf
private key String
isValidChecksumAddress
takes hex-encoded string and returns boolean if address is checksumed
Uses JS-native CSPRNG to generate a specified number of bytes.
bytes number to generate
ramdom hex string
raw address
checksumed address
Generated using TypeDoc
About this package
@harmony-js/crypot
provides a series of functions to deal with keysHow to use this package
Create a Harmony Instance
const { Harmony } = require('@harmony-js/core'); const { ChainID, ChainType } = require('@harmony-js/utils'); const hmy = new Harmony( 'http://localhost:9500', { chainType: ChainType.Harmony, chainId: ChainID.HmyLocal, }, );
Some examples
// randomBytes const bytes = hmy.crypto.randomBytes(20); console.log(bytes) // encryptPhrase const myPhrase = hmy.wallet.newMnemonic(); const pwd = '1234'; hmy.crypto.encryptPhrase(myPhrase, pwd).then((value) => { console.log(value); }) // decryptThePhrase hmy.crypto.encryptPhrase(myPhrase, pwd).then((keystore) => { hmy.crypto.decryptPhrase(JSON.parse(keystore), pwd).then((value) => { console.log(value); }) }) // generatePrivateKey const privateKey = hmy.crypto.generatePrivateKey(); console.log(privateKey) // getPubkeyFromPrivateKey const publicKey = hmy.crypto.getPubkeyFromPrivateKey(privateKey); console.log(publicKey); // getAddressFromPrivateKey const address = hmy.crypto.getAddressFromPrivateKey(privateKey); console.log(address); // getAddressFromPublicKey const address = hmy.crypto.getAddressFromPublicKey(publicKey); console.log(address); // toChecksumAddress const checksumAddr = hmy.crypto.toChecksumAddress(address); console.log(checksumAddr);