Crypto Module
Table of contents
Classes
Interfaces
Type Aliases
Variables
Functions
- bigInt2Buffer
 - calcDepthFromNumLeaves
 - deepCopyBigIntArray
 - formatPrivKeyForBabyJub
 - genEcdhSharedKey
 - genKeypair
 - genPrivKey
 - genPubKey
 - genRandomBabyJubValue
 - genRandomSalt
 - genTreeCommitment
 - genTreeProof
 - hash13
 - hash2
 - hash3
 - hash4
 - hash5
 - hashLeftRight
 - hashN
 - hashOne
 - packPubKey
 - poseidonDecrypt
 - poseidonDecryptWithoutCheck
 - poseidonEncrypt
 - sha256Hash
 - sign
 - stringifyBigInts
 - unpackPubKey
 - unstringifyBigInts
 - verifySignature
 
Type Aliases
Ciphertext
Ƭ Ciphertext<N>: N[]
Type parameters
| Name | Type | 
|---|---|
N | bigint | 
Defined in
EcdhSharedKey
Ƭ EcdhSharedKey<N>: [N, N]
Type parameters
| Name | Type | 
|---|---|
N | bigint | 
Defined in
Leaf
Ƭ Leaf: bigint
Defined in
PathElements
Ƭ PathElements: bigint[][]
Defined in
Plaintext
Ƭ Plaintext<N>: N[]
Type parameters
| Name | Type | 
|---|---|
N | bigint | 
Defined in
Point
Ƭ Point<N>: [N, N]
Type parameters
| Name | Type | 
|---|---|
N | SnarkBigNumber | 
Defined in
PrivKey
Ƭ PrivKey: SnarkBigNumber
Defined in
PubKey
Ƭ PubKey<N>: [N, N]
Type parameters
| Name | Type | 
|---|---|
N | bigint | 
Defined in
Variables
NOTHING_UP_MY_SLEEVE
• Const NOTHING_UP_MY_SLEEVE: bigint
Defined in
SNARK_FIELD_SIZE
• Const SNARK_FIELD_SIZE: bigint = r
Defined in
Functions
bigInt2Buffer
▸ bigInt2Buffer(i): Buffer
Convert a BigInt to a Buffer
Parameters
| Name | Type | Description | 
|---|---|---|
i | bigint | the bigint to convert | 
Returns
Buffer
the buffer
Defined in
calcDepthFromNumLeaves
▸ calcDepthFromNumLeaves(hashLength, numLeaves): number
Calculate the depth of a tree given the number of leaves
Parameters
| Name | Type | Description | 
|---|---|---|
hashLength | number | the hashing function param length | 
numLeaves | number | how many leaves | 
Returns
number
the depth
Defined in
deepCopyBigIntArray
▸ deepCopyBigIntArray(arr): bigint[]
Create a copy of a bigint array
Parameters
| Name | Type | Description | 
|---|---|---|
arr | bigint[] | the array of bigints to copy | 
Returns
bigint[]
a deep copy of the array
Defined in
formatPrivKeyForBabyJub
▸ formatPrivKeyForBabyJub(privKey): bigint
An internal function which formats a random private key to be compatible with the BabyJub curve. This is the format which should be passed into the PubKey and other circuits.
Parameters
| Name | Type | Description | 
|---|---|---|
privKey | SnarkBigNumber | A private key generated using genPrivKey() | 
Returns
bigint
A BabyJub-compatible private key.
Defined in
genEcdhSharedKey
▸ genEcdhSharedKey(privKey, pubKey): EcdhSharedKey
Generates an Elliptic-Curve Diffie–Hellman (ECDH) shared key given a private key and a public key.
Parameters
| Name | Type | Description | 
|---|---|---|
privKey | SnarkBigNumber | A private key generated using genPrivKey() | 
pubKey | PubKey | A public key generated using genPubKey() | 
Returns
The ECDH shared key.
Defined in
genKeypair
▸ genKeypair(): Keypair
Generates a keypair.
Returns
a keypair
Defined in
genPrivKey
▸ genPrivKey(): bigint
Generate a private key
Returns
bigint
A random seed for a private key.
Defined in
genPubKey
▸ genPubKey(privKey): PubKey
Parameters
| Name | Type | Description | 
|---|---|---|
privKey | SnarkBigNumber | A private key generated using genPrivKey() | 
Returns
A public key associated with the private key
Defined in
genRandomBabyJubValue
▸ genRandomBabyJubValue(): bigint
Returns a BabyJub-compatible random value. We create it by first generating a random value (initially 256 bits large) modulo the snark field size as described in EIP197. This results in a key size of roughly 253 bits and no more than 254 bits. To prevent modulo bias, we then use this efficient algorithm: http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/crypt/arc4random_uniform.c
Returns
bigint
A BabyJub-compatible random value.
Defined in
genRandomSalt
▸ genRandomSalt(): bigint
Generate a random value
Returns
bigint
A BabyJub-compatible salt.