Keystore.decrypt
Decrypts a JSON keystore into a private key.
Supports the following key derivation functions (KDFs): - Keystore.pbkdf2
- Keystore.scrypt
Imports
Named
import { Keystore } from 'ox'
Examples
import { Keystore, Secp256k1 } from 'ox'
// JSON keystore.
const keystore = { crypto: { ... }, id: '...', version: 3 }
// Derive key from password.
const key = Keystore.pbkdf2({ password: 'testpassword' })
// Decrypt the private key.
const privateKey = await Keystore.decrypt(keystore, key)
"0x..."
Definition
function decrypt<as>(
keystore: Keystore.Keystore,
key: Key,
options?: decrypt.Options<as>,
): Promise<decrypt.ReturnType<as>>
Source: src/core/Keystore.ts
Parameters
keystore
- Type:
Keystore.Keystore
JSON keystore.
keystore.cipher
- Type:
"aes-128-ctr"
keystore.cipherparams
- Type:
{ iv: string; }
keystore.ciphertext
- Type:
string
keystore.crypto
- Type:
{ cipher: "aes-128-ctr"; ciphertext: string; cipherparams: { iv: string; }; mac: string; } & Pick
keystore.id
- Type:
string
keystore.iv
- Type:
string
keystore.mac
- Type:
string
keystore.version
- Type:
3
key
- Type:
Key
Key to use for decryption.
key.c
- Type:
number
key.dklen
- Type:
number
key.n
- Type:
number
key.p
- Type:
number
key.prf
- Type:
"hmac-sha256"
key.r
- Type:
number
key.salt
- Type:
string
options
- Type:
decrypt.Options<as>
- Optional
Decryption options.
options.as
- Type:
"Bytes" | "Hex" | as
- Optional
Output format.
Return Type
Decrypted private key.
Promise<decrypt.ReturnType<as>>