import { Transform } from 'stream' ; import { GetSigner } from '@aws-crypto/material-management-node' ; import { serializeSignatureInfo } from '@aws-crypto/serialize' ; type AWSSigner = ReturnType < GetSigner > ; export class SignatureStream extends Transform { private _signer ! : AWSSigner | undefined ; constructor ( getSigner ? ) { super ( ) ; const value = getSigner && getSigner ( ) ; Object . defineProperty ( this , '_signer' , { value , enumerable : true } ) ; } _transform ( chunk , _encoding , callback ) { this . _signer && this . _signer . update ( chunk ) ; callback ( null , chunk ) ; } _flush ( callback ) { if ( this . _signer ) { const signature = this . _signer . awsCryptoSign ( ) ; this . push ( serializeSignatureInfo ( signature ) ) ; } callback ( ) ; } }