Add key.write() and update type definitions (#1267)

Also, mark key.keyPacket, message.packets and signature.packets private.
This commit is contained in:
Kevin Moutet 2021-03-16 13:45:17 +01:00 committed by GitHub
parent 43fb58404d
commit eba791e11e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

18
openpgp.d.ts vendored
View File

@ -25,7 +25,8 @@ export class Key {
public subKeys: SubKey[];
public users: User[];
public revocationSignatures: SignaturePacket[];
public keyPacket: PublicKeyPacket | SecretKeyPacket;
private keyPacket: PublicKeyPacket | SecretKeyPacket;
public write(): Uint8Array;
public armor(config?: Config): string;
public decrypt(passphrase: string | string[], keyId?: Keyid, config?: Config): Promise<void>; // throws on error
public encrypt(passphrase: string | string[], keyId?: Keyid, config?: Config): Promise<void>; // throws on error
@ -37,7 +38,11 @@ export class Key {
public isPublic(): boolean;
public toPublic(): Key;
public update(key: Key, config?: Config): void;
public signPrimaryUser(privateKeys: Key[], date?: Date, userId?: UserID, config?: Config): Promise<Key>
public signAllUsers(privateKeys: Key[], config?: Config): Promise<Key>
public verifyPrimaryKey(date?: Date, userId?: UserID, config?: Config): Promise<void>; // throws on error
public verifyPrimaryUser(publicKeys: Key[], date?: Date, userIds?: UserID, config?: Config): Promise<{ keyid: Keyid, valid: boolean | null }[]>;
public verifyAllUsers(publicKeys: Key[], config?: Config): Promise<{ userid: string, keyid: Keyid, valid: boolean | null }[]>;
public isRevoked(signature: SignaturePacket, key?: AnyKeyPacket, date?: Date, config?: Config): Promise<boolean>;
public revoke(reason: { flag?: enums.reasonForRevocation; string?: string; }, date?: Date, config?: Config): Promise<Key>;
public getRevocationCertificate(date?: Date, config?: Config): Promise<Stream<string> | string | undefined>;
@ -55,7 +60,7 @@ export class Key {
export class SubKey {
constructor(subKeyPacket: SecretSubkeyPacket | PublicSubkeyPacket);
public keyPacket: SecretSubkeyPacket | PublicSubkeyPacket;
private keyPacket: SecretSubkeyPacket | PublicSubkeyPacket;
public bindingSignatures: SignaturePacket[];
public revocationSignatures: SignaturePacket[];
public verify(primaryKey: PublicKeyPacket | SecretKeyPacket, date?: Date, config?: Config): Promise<SignaturePacket>;
@ -91,8 +96,9 @@ export function readSignature(options: { armoredSignature: string, config?: Part
export function readSignature(options: { binarySignature: Uint8Array, config?: PartialConfig }): Promise<Signature>;
export class Signature {
public packets: PacketList<SignaturePacket>;
private packets: PacketList<SignaturePacket>;
constructor(packetlist: PacketList<SignaturePacket>);
public write(): MaybeStream<Uint8Array>;
public armor(config?: Config): string;
}
@ -237,9 +243,13 @@ export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { m
*/
export class Message<T extends MaybeStream<Data>> {
public packets: PacketList<AnyPacket>;
private packets: PacketList<AnyPacket>;
constructor(packetlist: PacketList<AnyPacket>);
/** Returns binary representation of message
*/
public write(): MaybeStream<Uint8Array>;
/** Returns ASCII armored text of message
*/
public armor(config?: Config): string;

View File

@ -259,6 +259,14 @@ class Key {
return new Key(packetlist);
}
/**
* Returns binary encoded key
* @returns {Uint8Array} Binary key.
*/
write() {
return this.toPacketlist().write();
}
/**
* Returns ASCII armored text of key
* @param {Object} [config] - Full configuration, defaults to openpgp.config