Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@zilliqa-js/crypto
Advanced tools
Core crypto utilities for signing/verification/hashing Zilliqa transactions.
Cryptographic abstractions for working with Zilliqa's crypto primitives
randomBytes(bytes: number): string
Safely generates random bytes.
bytes
: number
- the number of bytes to randomly generate
string
- n randomly-generated bytes (hex-encoded).
generatePrivateKey(): string
Generates a cryptographically-secure 32-byte private key.
None
string
- 32-byte hex-encoded private key.
getPubKeyFromPrivateKey(privateKey: string): string
Retrieves the public key of the given hex-encoded private key.
privateKey
: string
- 32-byte hex-encoded private key.
string
- 33-byte hex-encoded public key.
getAddressFromPrivateKey(privateKey: string): string
Retrieves the address from the given hex-encoded private key.
privateKey
: string
- 32-byte hex-encoded private key.
string
- 20-byte hex-encoded address.
compressPublicKey(publicKey: string): string
Compresses a full-length public key by using a sign byte (02 or 03).
publicKey
: string
- 65-byte hex-encoded public key.
string
- 32-byte hex-encoded public key.
getAddressFromPublicKey(publicKey: string): string
Returns the address derived from the given publicKey.
publicKey
: string
- 32-byte hex-encoded compressed public key.
string
- 20-byte hex-encoded address.
verifyPrivateKey(privateKey: string): boolean
Returns true if the given privateKey is valid.
string
- 32-byte hex-encoded private key.
boolean
sign(msg: Buffer, privateKey: string, pubKey: string): string
Generates a Schnorr signature over a Buffer
of arbitrary bytes. This function
must be used to sign all transactions to be broadcast on the blockchain.
msg
: Buffer
- arbitrary sequence of bytes to be signed. privateKey
:
string
- 32-byte hex-encoded private key. pubKey
: string
- 32-byte
hex-encoded private key.
boolean
encryptPrivateKey(kdf: KDF, privateKey: string, passphrase: string): Promise<string>
Generates a version 3 keystore file that complies with the Web3 Secret Storage definition.
kdf
: 'pbkdf2' | 'scrypt'
- the key derivation function. Only pbkdf2
and
scrypt
are currently supported. privateKey
: string
- 32-byte hex-encoded
private key. passphrase
: string
- the passphrase to be used to encrypt the
private key.
Promise<string>
- the stringified JSON file.
decryptPrivateKey(passphrase: string, keystore: KeystoreV3): Promise<string>
Generates a version 3 keystore file that complies with the Web3 Secret Storage definition.
passphrase
: string
- the passphrase to be used to encrypt the private key.
keystore
: KeystoreV3
- the object containing the deserialised JSON obtained
from encryptPrivateKey
.
Promise<string>
- the hex-encoded private key.
toBech32Address(address: string): string
Encodes a 20-byte hex encoded address as a bech32 address. Non-hex-encoded strings will cause an error to be thrown.
address
: string
- the 20-byte hex-encoded address. 0x
prefix optional.
string
- the bech32 encoded address. It is always prefixed by zil1
, where
1
is a separator.
0x1d19918a737306218b5cbb3241fcdcbd998c3a72 (hex) -> zil1r5verznnwvrzrz6uhveyrlxuhkvccwnju4aehf (bech32)
fromBech32Address(address: string): string
Encodes a a bech32 address as a hex-encoded string. Invalid bech32 addresses will cause an error to be thrown.
address
: string
- the 42-character bech32 address.
string
- the checksum 20-byte hex-encoded address.
zil1r5verznnwvrzrz6uhveyrlxuhkvccwnju4aehf (bech32) -> 0x1d19918a737306218b5cbb3241fcdcbd998c3a72 (hex)
interface PBKDF2Params {
salt: string;
dklen: number;
c: number;
}
interface ScryptParams {
salt: string;
dklen: number;
n: number;
r: number;
p: number;
}
type KDFParams = PBKDF2Params | ScryptParams;
interface KeystoreV3 {
address: string;
crypto: {
cipher: string;
cipherparams: {
iv: string;
};
ciphertext: string;
kdf: KDF;
kdfparams: KDFParams;
mac: string;
};
id: string;
version: 3;
}
FAQs
Core crypto utilities for signing/verification/hashing Zilliqa transactions.
The npm package @zilliqa-js/crypto receives a total of 1,596 weekly downloads. As such, @zilliqa-js/crypto popularity was classified as popular.
We found that @zilliqa-js/crypto demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.