Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getMessage,
encryptMessage,
generateKey,
binaryStringToArray,
signMessage,
arrayToHexString
} from 'pmcrypto';
import { openpgp } from 'pmcrypto/lib/openpgp';
import { ReadableStream as PolyfillReadableStream } from 'web-streams-polyfill';
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
import { ENCRYPTION_CONFIGS, ENCRYPTION_TYPES } from '../constants';
import { generatePassphrase } from './calendarKeys';
import { createSessionKey, getEncryptedSessionKey } from '../calendar/encrypt';
import { serializeUint8Array } from '../helpers/serialization';
const toPolyfillReadable = createReadableStreamWrapper(PolyfillReadableStream);
interface UnsignedEncryptionPayload {
message: string;
privateKey: key.Key;
}
export const sign = async (data: string, privateKeys: key.Key | key.Key[]) => {
const { signature } = await signMessage({
data,
privateKeys,
armor: true,
detached: true
});
return signature;
};