Skip to content

Commit

Permalink
Update type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
twiss committed Feb 15, 2023
1 parent 809deee commit 9d933cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions openpgp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class CleartextMessage {
*
* @param privateKeys private keys with decrypted secret key data for signing
*/
sign(privateKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], config?: Config): void;
sign(privateKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], notations?: Notation[], config?: Config): void;

/** Verify signatures of cleartext signed message
* @param keys array of keys to verify signatures
Expand Down Expand Up @@ -285,7 +285,7 @@ export class Message<T extends MaybeStream<Data>> {
/** Sign the message (the literal data packet of the message)
@param signingKeys private keys with decrypted secret key data for signing
*/
public sign(signingKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], config?: Config): Promise<Message<T>>;
public sign(signingKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], notations?: Notation[], config?: Config): Promise<Message<T>>;

/** Unwrap compressed message
*/
Expand Down Expand Up @@ -521,14 +521,14 @@ export class SignaturePacket extends BasePacket {
public issuerFingerprint: null | Uint8Array;
public preferredAEADAlgorithms: enums.aead[] | null;
public revoked: null | boolean;
public rawNotations: RawNotation[];
public rawNotations: Notation[];
public sign(key: AnySecretKeyPacket, data: Uint8Array, date?: Date, detached?: boolean): Promise<void>;
public verify(key: AnyKeyPacket, signatureType: enums.signature, data: Uint8Array | object, date?: Date, detached?: boolean, config?: Config): Promise<void>; // throws on error
public isExpired(date?: Date): boolean;
public getExpirationTime(): Date | typeof Infinity;
}

export interface RawNotation {
export interface Notation {
name: string;
value: Uint8Array;
humanReadable: boolean;
Expand Down Expand Up @@ -604,6 +604,8 @@ interface EncryptOptions {
signingUserIDs?: MaybeArray<UserID>;
/** (optional) array of user IDs to encrypt for, e.g. { name:'Robert Receiver', email:'robert@openpgp.org' } */
encryptionUserIDs?: MaybeArray<UserID>;
/** (optional) array of notations to add to the signatures, e.g. { name: 'test@example.org', value: new TextEncoder().encode('test'), humanReadable: true } */
signatureNotations?: MaybeArray<Notation>;
config?: PartialConfig;
}

Expand Down Expand Up @@ -637,6 +639,7 @@ interface SignOptions {
signingKeyIDs?: MaybeArray<KeyID>;
date?: Date;
signingUserIDs?: MaybeArray<UserID>;
signatureNotations?: MaybeArray<Notation>;
config?: PartialConfig;
}

Expand Down
8 changes: 8 additions & 0 deletions test/typescript/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ import {
const textSignedObject: Message<string> = await sign({ signingKeys: privateKeys, message: textMessage, format: 'object' });
expect(textSignedObject).to.be.instanceOf(Message);

// Sign text message (armored)
const textSignedWithNotations: string = await sign({ signingKeys: privateKeys, message: textMessage, signatureNotations: [{
name: 'test@example.org',
value: new TextEncoder().encode('test'),
humanReadable: true
}] });
expect(textSignedWithNotations).to.include('-----BEGIN PGP MESSAGE-----');

// Verify signed text message (armored)
const signedMessage = await readMessage({ armoredMessage: textSignedArmor });
const verifiedText = await verify({ verificationKeys: publicKeys, message: signedMessage });
Expand Down

0 comments on commit 9d933cb

Please sign in to comment.