CryptoApi
Class representing instance of Crypto API
Methods
signData
Signs arbitrary data with the user's private key. Computes an ECDSA signature over the SHA-256 hash of data using the secp256k1 key decoded from WIF - entirely inside the WASM core, locally. Use it to prove authorship of application-level payloads; the counterpart verifySignature checks the result against the signer's public key.
Params
data
Uint8Array
arbitrary bytes to sign; they are hashed with SHA-256 before signing, so any length is fine
privateKey
string
signer's secp256k1 private key in WIF format, generated by generatePrivateKey or derived with derivePrivateKey2
Returns
Promise<Uint8Array> ·
compact ECDSA signature - pass it together with the original data to verifySignature
verifySignature
Checks whether a signature was produced over the given data by the owner of the given public key. Verifies the compact ECDSA (secp256k1, SHA-256) signature locally in the WASM core - no server involvement. Use it to authenticate payloads signed with signData; obtain the signer's public key from Connection.listContextUsers or derivePublicKey.
Params
data
Uint8Array
exact bytes that were originally passed to signData - any modification fails verification
signature
Uint8Array
compact ECDSA signature returned by signData
publicKey
string
signer's public ECC key in BASE58DER format, derived from their private key with derivePublicKey or found in UserInfo.pubKey from Connection.listContextUsers
Returns
`` ·
true when the signature matches the data and key - only then should the application trust the payload
generatePrivateKey
Generates a new private ECC (secp256k1) key - the user's identity in PrivMX. Runs locally in the WASM core: the seed (or secure random bytes) is stretched with PBKDF2 (200 000 rounds, SHA-512) over a random salt into a BIP-32 extended key, whose private part is returned in WIF format. The random salt makes the result non-deterministic even for the same seed - for repeatable derivation use derivePrivateKey2. Generate one key per user at registration, derive its public part with derivePublicKey for the Context ACL, and pass the private key to EndpointFactory.connect.
Params
randomSeed
string
optional entropy mixed into key generation; omit to use the CSPRNG alone
Returns
Promise<string> ·
private key in WIF format - store it securely and use it with EndpointFactory.connect and signData
derivePrivateKey
Deterministically derives a private ECC key from a password (legacy variant). Stretches the password with PBKDF2 locally in the WASM core, using an older derivation scheme kept only so keys created by previous SDK versions remain reachable. Use it exclusively to recover keys originally derived with this method; for anything new call derivePrivateKey2.
Params
password
string
user-supplied secret the key is derived from; the same password and salt always yield the same key
salt
string
application-chosen string mixed into the hash; must match the salt used when the key was first derived
Returns
Promise<string> ·
private key in WIF format, identical for identical inputs - usable with EndpointFactory.connect
derivePrivateKey2
Deterministically derives a private ECC (secp256k1) key from a password - the recommended path for password-based login. Runs PBKDF2 (200 000 rounds, SHA-512) over the password and salt locally in the WASM core and converts the result to a WIF private key. The same password and salt always produce the same key, and the password never leaves the browser. Use it so users can log in with familiar credentials: derive the key on every login and pass it to EndpointFactory.connect - no key storage needed.
Params
password
string
user-supplied secret the key is derived from; a stronger password means a stronger key
salt
string
application-chosen string mixed into the hash (e.g. the user's login); must be identical on every derivation to yield the same key
Returns
Promise<string> ·
private key in WIF format, identical for identical inputs - pass it to EndpointFactory.connect
derivePublicKey
Computes the public key matching a private key. Multiplies the secp256k1 base point by the decoded WIF key locally in the WASM core - a pure, deterministic EC operation. The public key is what other users (and the Bridge) see: register it in the Context ACL, list it in UserWithPubKey arrays when creating containers, and hand it to verifySignature.
Params
privateKey
string
private ECC key in WIF format, generated by generatePrivateKey or derived with derivePrivateKey2
Returns
Promise<string> ·
matching public key in BASE58DER format - used in UserWithPubKey entries and verifySignature
generateKeySymmetric
Generates a fresh random symmetric encryption key. Draws 32 random bytes (a 256-bit AES key) from the WASM core's CSPRNG - locally, with no server involvement. Use it as the key for encryptDataSymmetric / decryptDataSymmetric when the application needs to encrypt data outside of PrivMX containers.
Returns
Promise<Uint8Array> ·
32 random key bytes - pass them to encryptDataSymmetric and store them securely
encryptDataSymmetric
Encrypts a buffer with a symmetric key. Applies the core's authenticated AES-256 scheme locally in the WASM module, embedding an integrity tag so tampering is detected on decryption. Use it for application-level encryption of data you store outside PrivMX containers; reverse with decryptDataSymmetric using the same key.
Params
data
Uint8Array
plaintext bytes to encrypt; any length is accepted
symmetricKey
Uint8Array
256-bit (32-byte) key generated by generateKeySymmetric
Returns
Promise<Uint8Array> ·
ciphertext with embedded integrity data - feed it back to decryptDataSymmetric
decryptDataSymmetric
Decrypts a buffer produced by encryptDataSymmetric. Runs the core's authenticated AES-256 decryption locally in the WASM module and verifies the embedded integrity tag before returning any plaintext. Use it with the same 32-byte key the data was encrypted with; a wrong key or modified ciphertext is rejected rather than yielding garbage.
Params
data
Uint8Array
ciphertext returned by encryptDataSymmetric, including its integrity data
symmetricKey
Uint8Array
the same 256-bit key (from generateKeySymmetric) that encrypted the data
Returns
Promise<Uint8Array> ·
original plaintext bytes, ready for application use
convertPEMKeytoWIFKey
Converts a private key from PEM encoding to the WIF format used across PrivMX. Re-encodes the key material locally in the WASM core - no cryptographic transformation, only a format change. Use it to import keys generated by external tools (e.g. OpenSSL) so they can be passed to EndpointFactory.connect or signData.
Params
pemKey
string
private key in PEM format, e.g. exported by OpenSSL or another external key tool
Returns
Promise<string> ·
the same key in WIF format - accepted by EndpointFactory.connect and signData
generateBip39
Generates a fresh BIP-39 mnemonic together with the BIP-32 key it encodes. Draws strength bits of entropy locally in the WASM core, encodes them as a standard 12/24-word English mnemonic, and derives the matching BIP-32 extended key (optionally hardened with a password). Use it to give users a human-writable backup phrase: show result.mnemonic once, then use result.extKey (an ExtKey) - e.g. extKey.getPrivateKey() - for EndpointFactory.connect. Restore later with fromMnemonic.
Params
strength
number
entropy size in bits, a multiple of 32 - 128 yields 12 words, 256 yields 24 words
password
string
optional extra secret mixed into key derivation; the same password is then required by fromMnemonic
Returns
Promise<BIP39> ·
mnemonic, raw entropy, and the derived ExtKey - keep the mnemonic as backup, use the key to connect
fromMnemonic
Restores a BIP-32 key from a previously issued BIP-39 mnemonic. Validates the word list and recomputes the extended key locally in the WASM core - deterministic, so the same mnemonic and password always reproduce the same key. Use it for account recovery: ask the user for the phrase generated by generateBip39, then connect with the restored key's private part.
Params
mnemonic
string
12/24-word BIP-39 phrase produced by generateBip39 or entropyToMnemonic
password
string
the same optional password that was supplied when the mnemonic was generated - a different one yields a different key
Returns
Promise<BIP39> ·
mnemonic, entropy, and the restored ExtKey - identical to the originally generated key
fromEntropy
Builds a BIP-39 mnemonic and BIP-32 key directly from raw entropy bytes. Encodes the entropy as a standard mnemonic and derives the extended key locally in the WASM core - the byte-level equivalent of fromMnemonic. Use it when the application stores raw entropy (e.g. from mnemonicToEntropy) instead of the word list.
Params
entropy
Uint8Array
BIP-39 entropy bytes (16–32 bytes, a multiple of 4), e.g. returned by mnemonicToEntropy or from a CSPRNG
password
string
optional extra secret mixed into key derivation, as in generateBip39
Returns
Promise<BIP39> ·
mnemonic, entropy, and the derived ExtKey for use with EndpointFactory.connect
entropyToMnemonic
Encodes raw BIP-39 entropy as its mnemonic word list. Pure local conversion in the WASM core (entropy + checksum → words) - no key derivation happens. Use it to display a backup phrase for entropy the application already holds; mnemonicToEntropy performs the inverse.
Params
entropy
Uint8Array
BIP-39 entropy bytes (16–32 bytes, a multiple of 4), e.g. from BIP39.entropy returned by generateBip39
Returns
Promise<string> ·
12/24-word mnemonic - accepted by fromMnemonic and mnemonicToEntropy
mnemonicToEntropy
Decodes a BIP-39 mnemonic back into its raw entropy bytes. Pure local conversion in the WASM core (words → entropy, checksum verified) - the inverse of entropyToMnemonic. Use it when the application prefers to persist compact entropy bytes rather than the word list; restore the key later with fromEntropy.
Params
mnemonic
string
12/24-word BIP-39 phrase produced by generateBip39 or entropyToMnemonic
Returns
Promise<Uint8Array> ·
raw entropy bytes - accepted by fromEntropy and entropyToMnemonic
mnemonicToSeed
Stretches a BIP-39 mnemonic into the 64-byte seed defined by the BIP-39 standard. Runs PBKDF2 over the mnemonic and optional password locally in the WASM core, exactly as BIP-39 specifies - deterministic for the same inputs. Use the seed for interoperability with other BIP-32 wallets/tools, or feed it to ExtKey.fromSeed to build an extended key directly.
Params
mnemonic
string
12/24-word BIP-39 phrase produced by generateBip39 or entropyToMnemonic
password
string
optional passphrase mixed into the PBKDF2 derivation, as in generateBip39
Returns
Promise<Uint8Array> ·
64-byte BIP-39 seed - usable with ExtKey.fromSeed
We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.