0.2.1-next.20181114 • Published 7 years ago

@zilliqa-js/crypto v0.2.1-next.20181114

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
7 years ago

@zilliqa-js/crypto

Cryptographic abstractions for working with Zilliqa's crypto primitives

Functions

randomBytes(bytes: number): string

Safely generates bytes using Window.crypto in the browser or the built-in crypto in node.

Parameters

bytes: number - the number of bytes to randomly generate

Returns

string - n randomly-generated bytes (hex-encoded).

generatePrivateKey(): string

Generates a cryptographically-secure 32-byte private key.

Parameters

None

Returns

string - 32-byte hex-encoded private key.

getPubKeyFromPrivateKey(privateKey: string): string

Retrieves the public key of the given hex-encoded private key.

Parameters

privateKey: string - 32-byte hex-encoded private key.

Returns

string - 20-byte hex-encoded address.

getAddressFromPrivateKey(privateKey: string): string

Retrieves the address from the given hex-encoded private key.

Parameters

privateKey: string - 32-byte hex-encoded private key.

Returns

string - 20-byte hex-encoded address.

compressPublicKey(publicKey: string): string

Compresses a full-length public key by using a sign byte (02 or 03).

Parameters

publicKey: string - 65-byte hex-encoded public key.

Returns

string - 32-byte hex-encoded public key.

getAddressFromPublicKey(publicKey: string): string

Returns the address derived from the given publicKey.

Parameters

publicKey: string - 32-byte hex-encoded compressed public key.

Returns

string - 20-byte hex-encoded address.

verifyPrivateKey(privateKey: string): boolean

Returns true if the given privateKey is valid.

Parameters

string - 32-byte hex-encoded private key.

Returns

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.

Parameters

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.

Returns

boolean

encryptPrivateKey(kdf: KDF, privateKey: string, passphrase: string): Promise<string>

Generates a version 3 keystore file that complies with the Web3 Secret Storage definition.

Parameters

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.

Returns

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.

Interfaces

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

Parameters

passphrase: string - the passphrase to be used to encrypt the private key. keystore: KeystoreV3 - the object containing the deserialised JSON obtained from encryptPrivateKey.

Returns

Promise<string> - the hex-encoded private key.

3.5.0

2 years ago

3.4.4

3 years ago

3.4.0

3 years ago

3.4.3-rc.0

3 years ago

3.4.3

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.2-rc.0

3 years ago

3.4.0-rc.3

3 years ago

3.4.0-rc.1

3 years ago

3.4.0-rc.2

3 years ago

3.4.0-rc.0

3 years ago

3.3.1

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

5 years ago

2.3.0-alpha.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0-alpha.1

5 years ago

1.0.0

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha.0

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.9

6 years ago

0.8.8

6 years ago

0.8.3

6 years ago

0.8.1-alpha.2

6 years ago

0.8.1-alpha.0

6 years ago

0.7.5

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.0

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago