Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(async (material) => {
const { dispose, getSigner } = getEncryptHelper(material)
const { getCipher, messageHeader, rawHeader } = getEncryptionInfo(material, frameLength)
wrappingStream.emit('MessageHeader', messageHeader)
const encryptStream = getFramedEncryptStream(getCipher, messageHeader, dispose, plaintextLength)
const signatureStream = new SignatureStream(getSigner)
pipeline(encryptStream, signatureStream)
wrappingStream.setReadable(signatureStream)
// Flush the rawHeader through the signatureStream
rawHeader.forEach(buff => signatureStream.write(buff))
// @ts-ignore until readable-stream exports v3 types...
wrappingStream.setWritable(encryptStream)
export function getEncryptionInfo (material : NodeEncryptionMaterial, frameLength: number) {
const { kdfGetCipher } = getEncryptHelper(material)
const { encryptionContext } = material
const messageId = randomBytes(MESSAGE_ID_LENGTH)
const { id, ivLength } = material.suite
const messageHeader: MessageHeader = Object.freeze({
version: SerializationVersion.V1,
type: ObjectType.CUSTOMER_AE_DATA,
suiteId: id,
messageId,
encryptionContext,
encryptedDataKeys: Object.freeze(material.encryptedDataKeys), // freeze me please
contentType: ContentType.FRAMED_DATA,
headerIvLength: ivLength,
frameLength
})