INNER CODE UNIT · TypeScript
encrypt
ecies/js · src/index.ts:19
export function encrypt(
receiverRawPK: string | Uint8Array,
data: Uint8Array,
config: Config = ECIES_CONFIG
): Uint8Array {
const curve = config.ellipticCurve;
const ephemeralSK = new PrivateKey(undefined, curve);
const receiverPK =
receiverRawPK instanceof Uint8Array
? new PublicKey(receiverRawPK, curve)
: PublicKey.fromHex(receiverRawPK, curve);
const sharedKey = ephemeralSK.encapsulate(receiverPK, config.isHkdfKeyCompressed);
const ephemeralPK = ephemeralSK.publicKey.toBytes(config.isEphemeralKeyCompressed);
const encrypted = symEncrypt(config, sharedKey, data);
return concatBytes(ephemeralPK, encrypted);