TS: add declaration for verify
with CleartextMessage
input (#1640)
Also, make `VerifyMessageResult` generic. This change should be backwards compatible since a default type is set.
This commit is contained in:
parent
29d2b701c9
commit
1eb0b42387
15
openpgp.d.ts
vendored
15
openpgp.d.ts
vendored
|
@ -228,18 +228,17 @@ export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & {
|
|||
string
|
||||
}>;
|
||||
|
||||
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T>, format: 'binary' }): Promise<VerifyMessageResult & {
|
||||
data:
|
||||
export function verify(options: VerifyOptions & { message: CleartextMessage, format?: 'utf8' }): Promise<VerifyMessageResult<string>>;
|
||||
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T>, format: 'binary' }): Promise<VerifyMessageResult<
|
||||
T extends WebStream<infer X> ? WebStream<Uint8Array> :
|
||||
T extends NodeStream<infer X> ? NodeStream<Uint8Array> :
|
||||
Uint8Array
|
||||
}>;
|
||||
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T> }): Promise<VerifyMessageResult & {
|
||||
data:
|
||||
>>;
|
||||
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T> }): Promise<VerifyMessageResult<
|
||||
T extends WebStream<infer X> ? WebStream<string> :
|
||||
T extends NodeStream<infer X> ? NodeStream<string> :
|
||||
string
|
||||
}>;
|
||||
>>;
|
||||
|
||||
/** Class that represents an OpenPGP message. Can be an encrypted message, signed message, compressed message or literal message
|
||||
*/
|
||||
|
@ -721,8 +720,8 @@ interface DecryptMessageResult {
|
|||
filename: string;
|
||||
}
|
||||
|
||||
interface VerifyMessageResult {
|
||||
data: MaybeStream<Data>;
|
||||
interface VerifyMessageResult<T extends MaybeStream<Data> = MaybeStream<Data>> {
|
||||
data: T;
|
||||
signatures: VerificationResult[];
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,12 @@ import {
|
|||
|
||||
// Sign cleartext message (armored)
|
||||
const cleartextMessage = await createCleartextMessage({ text: 'hello' });
|
||||
const verificationResult = await verify({ message: cleartextMessage, verificationKeys: publicKey });
|
||||
const verifiedCleartextData: string = verificationResult.data;
|
||||
expect(verifiedCleartextData).to.equal(cleartextMessage.getText());
|
||||
// @ts-expect-error Binary output not available for cleartext messages
|
||||
try { await verify({ message: cleartextMessage, verificationKeys: publicKey, format: 'binary' }) } catch (e) {}
|
||||
|
||||
const clearSignedArmor = await sign({ signingKeys: privateKeys, message: cleartextMessage });
|
||||
expect(clearSignedArmor).to.include('-----BEGIN PGP SIGNED MESSAGE-----');
|
||||
const clearSignedObject: CleartextMessage = await sign({ signingKeys: privateKeys, message: cleartextMessage, format: 'object' });
|
||||
|
|
Loading…
Reference in New Issue
Block a user