INNER CODE UNIT · TypeScript
decrypt
ecies/js · src/index.ts:50
export function decrypt(
receiverRawSK: string | Uint8Array,
data: Uint8Array,
config: Config = ECIES_CONFIG
): Uint8Array {
const curve = config.ellipticCurve;
const receiverSK =
receiverRawSK instanceof Uint8Array
? new PrivateKey(receiverRawSK, curve)
: PrivateKey.fromHex(receiverRawSK, curve);
const keySize = config.ephemeralKeySize;
const ephemeralPK = new PublicKey(data.subarray(0, keySize), curve);
const encrypted = data.subarray(keySize);
const sharedKey = ephemeralPK.decapsulate(receiverSK, config.isHkdfKeyCompressed);
return symDecrypt(config, sharedKey, encrypted);
}