in modules/material-management-node/src/material_helpers.ts [88:115]
function getSigner() {
/* Precondition: The NodeEncryptionMaterial must have not been zeroed.
* hasUnencryptedDataKey will check that the unencrypted data key has been set
* *and* that it has not been zeroed. At this point it must have been set
* because the KDF function operated on it. So at this point
* we are protecting that someone has zeroed out the material
* because the Encrypt process has been complete.
*/
needs(
material.hasUnencryptedDataKey,
'Unencrypted data key has been zeroed.'
)
if (!signatureHash) throw new Error('Material does not support signature.')
const { signatureKey } = material
if (!signatureKey) throw new Error('Material does not support signature.')
const { privateKey } = signatureKey
if (typeof privateKey !== 'string')
throw new Error('Material does not support signature.')
const signer = Object.assign(
createSign(signatureHash),
// don't export the private key if we don't have to
{ awsCryptoSign: () => signer.sign(privateKey) }
)
return signer
}