mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Merge pull request #34666 from SardineFish/master
Fix type declare issues for openpgp.
This commit is contained in:
53
types/openpgp/index.d.ts
vendored
53
types/openpgp/index.d.ts
vendored
@@ -5,7 +5,7 @@
|
||||
// Daniel Montesinos <https://github.com/damonpam>
|
||||
// Carlos Villavicencio <https://github.com/po5i>
|
||||
// Eric Camellini <https://github.com/ecamellini>
|
||||
// SardineFIsh <https://github.com/SardineFish>
|
||||
// SardineFish <https://github.com/SardineFish>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
import BN = require("bn.js");
|
||||
@@ -1603,7 +1603,7 @@ export namespace key {
|
||||
* Returns userids
|
||||
* @returns array of userids
|
||||
*/
|
||||
getUserIds(): any[];
|
||||
getUserIds(): string[];
|
||||
|
||||
/**
|
||||
* Returns true if this is a public key
|
||||
@@ -1627,7 +1627,7 @@ export namespace key {
|
||||
* Returns ASCII armored text of key
|
||||
* @returns ASCII armor
|
||||
*/
|
||||
armor(): ReadableStream<String>;
|
||||
armor(): string;
|
||||
|
||||
/**
|
||||
* Returns last created key or key by given keyId that is available for signing and verification
|
||||
@@ -1692,7 +1692,7 @@ export namespace key {
|
||||
* @param userId, optional user ID
|
||||
* @returns
|
||||
*/
|
||||
getExpirationTime(capabilities: any, keyId: type.keyid.Keyid, userId: object): Promise<Date | Infinity | null>;
|
||||
getExpirationTime(capabilities?: any, keyId?: type.keyid.Keyid, userId?: object): Promise<Date | Infinity | null>;
|
||||
|
||||
/**
|
||||
* Returns primary user and most significant (latest valid) self signature
|
||||
@@ -1702,7 +1702,7 @@ export namespace key {
|
||||
* @param userId (optional) user ID to get instead of the primary user, if it exists
|
||||
* @returns The primary user and the self signature
|
||||
*/
|
||||
getPrimaryUser(date: Date, userId: object): Promise<{ user: User, selfCertification: packet.Signature }>;
|
||||
getPrimaryUser(date?: Date, userId?: object): Promise<{ user: User, selfCertification: packet.Signature }>;
|
||||
|
||||
/**
|
||||
* Update key with new components from specified key with same key ID:
|
||||
@@ -1828,6 +1828,8 @@ export namespace key {
|
||||
class User {
|
||||
constructor();
|
||||
|
||||
userId: packet.Userid;
|
||||
|
||||
/**
|
||||
* Transforms structured user data to packetlist
|
||||
* @returns
|
||||
@@ -4383,7 +4385,7 @@ export namespace util {
|
||||
* @param url If true, output is URL-safe
|
||||
* @returns Base-64 encoded string
|
||||
*/
|
||||
function Uint8Array_to_b64(bytes: Uint8Array, url: boolean): string;
|
||||
function Uint8Array_to_b64(bytes: Uint8Array, url?: boolean): string;
|
||||
|
||||
/**
|
||||
* Convert a hex string to an array of 8-bit integers
|
||||
@@ -4560,12 +4562,12 @@ export namespace util {
|
||||
/**
|
||||
* Format user id for internal use.
|
||||
*/
|
||||
function formatUserId(): void;
|
||||
function formatUserId(id: { name: string, email: string; comment: string }): string;
|
||||
|
||||
/**
|
||||
* Parse user id.
|
||||
*/
|
||||
function parseUserId(): void;
|
||||
function parseUserId(userId: string): { name: string, email: string; comment: string };
|
||||
|
||||
/**
|
||||
* Normalize line endings to \r\n
|
||||
@@ -4699,6 +4701,20 @@ export namespace worker {
|
||||
}
|
||||
}
|
||||
|
||||
export interface WorkerOptions {
|
||||
/**
|
||||
* relative path to the worker scripts, default: 'openpgp.worker.js'
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* number of workers to initialize
|
||||
*/
|
||||
n?: number;
|
||||
/**
|
||||
* alternative to path parameter: web workers initialized with 'openpgp.worker.js'
|
||||
*/
|
||||
workers?: any[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path for the web worker script and create an instance of the async proxy
|
||||
@@ -4706,7 +4722,7 @@ export namespace worker {
|
||||
* @param n number of workers to initialize
|
||||
* @param workers alternative to path parameter: web workers initialized with 'openpgp.worker.js'
|
||||
*/
|
||||
export function initWorker(path: string, n?: number, workers?: any[]): void;
|
||||
export function initWorker(options: WorkerOptions): void;
|
||||
|
||||
/**
|
||||
* Returns a reference to the async proxy if the worker was initialized with openpgp.initWorker()
|
||||
@@ -4880,9 +4896,6 @@ export interface EncryptOptions {
|
||||
}
|
||||
|
||||
export interface EncryptResult {
|
||||
data: string | ReadableStream<String>;
|
||||
message: message.Message;
|
||||
signature: string | ReadableStream<String> | signature.Signature;
|
||||
sessionKey: { data: Uint8Array, algorithm: string, aeadAlgorithm: string };
|
||||
}
|
||||
|
||||
@@ -4899,7 +4912,15 @@ export interface EncryptResult {
|
||||
* sessionKey: { data, algorithm, aeadAlgorithm } (if `returnSessionKey` was true)
|
||||
* }
|
||||
*/
|
||||
export function encrypt(options: EncryptOptions): Promise<EncryptResult>;
|
||||
export function encrypt(options: EncryptOptions & { armor?: true, detached?: false }): Promise<EncryptResult & { data: string }>
|
||||
export function encrypt(options: EncryptOptions & { armor?: true, detached: true }): Promise<EncryptResult & { data: string, signature: string }>
|
||||
export function encrypt(options: EncryptOptions & { armor: false, detached?: false }): Promise<EncryptResult & { message: message.Message }>
|
||||
export function encrypt(options: EncryptOptions & { armor: false, detached: true }): Promise<EncryptResult & { message: message.Message, signature: signature.Signature }>
|
||||
export function encrypt(options: EncryptOptions): Promise<EncryptResult & {
|
||||
data: string | ReadableStream<String>;
|
||||
message: message.Message;
|
||||
signature: string | ReadableStream<String> | signature.Signature;
|
||||
}>;
|
||||
|
||||
export interface DecryptOptions {
|
||||
/**
|
||||
@@ -4968,6 +4989,8 @@ export interface DecryptResult {
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
export function decrypt(options: DecryptOptions & { format: "utf8" }): Promise<DecryptOptions & { data: string | ReadableStream<String> | NodeStream }>
|
||||
export function decrypt(options: DecryptOptions & { format: "binary" }): Promise<DecryptOptions & { data: Uint8Array | ReadableStream<Uint8Array> | NodeStream }>
|
||||
export function decrypt(options: DecryptOptions): Promise<DecryptResult>;
|
||||
|
||||
export interface SignOptions {
|
||||
@@ -5021,6 +5044,10 @@ export interface SignResult {
|
||||
* signature: Signature (if `armor` was false)
|
||||
* }
|
||||
*/
|
||||
export function sign(options: SignOptions & { armor?: true, detached?: false }): Promise<{ data: string }>
|
||||
export function sign(options: SignOptions & { armor: false, detached?: false }): Promise<{ message: message.Message }>
|
||||
export function sign(options: SignOptions & { armor?: true, detached: true }): Promise<{ signature: string }>
|
||||
export function sign(options: SignOptions & { armor: false, detached: true }): Promise<{ signature: signature.Signature }>
|
||||
export function sign(options: SignOptions): Promise<SignResult>;
|
||||
|
||||
export interface VerifyOptions {
|
||||
|
||||
@@ -70,7 +70,9 @@ Promise.all(promises).then((values) => {
|
||||
// failure
|
||||
});
|
||||
|
||||
openpgp.initWorker('openpgp.worker.js');
|
||||
openpgp.initWorker({
|
||||
path: 'openpgp.worker.js'
|
||||
});
|
||||
|
||||
(async () => {
|
||||
let msgOptions: openpgp.EncryptOptions;
|
||||
@@ -84,6 +86,14 @@ openpgp.initWorker('openpgp.worker.js');
|
||||
const cipher = await openpgp.encrypt(msgOptions);
|
||||
const encrypted = cipher.message.packets.write(); // get raw encrypted packets as Uint8Array
|
||||
|
||||
let armored = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
||||
armor: true,
|
||||
privateKeys: []
|
||||
});
|
||||
let data: string = armored.data;
|
||||
// let msg: openpgp.message.Message = armored.message; // without member 'message'
|
||||
|
||||
const plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.read(encrypted),
|
||||
passwords: ['secret stuff'],
|
||||
@@ -123,6 +133,30 @@ openpgp.initWorker('openpgp.worker.js');
|
||||
const signature = signed.signature as openpgp.signature.Signature;
|
||||
const message = signed.message;
|
||||
|
||||
// Test function reload
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
detached: true
|
||||
}).then(s => s.signature/* as string*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
detached: false,
|
||||
}).then(s => s.data/* as string*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
armor: false,
|
||||
detached: true
|
||||
}).then(s => s.signature/* as openpgp.signature.Signature*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
armor: false,
|
||||
detached: false,
|
||||
}).then(s => s.message/* as openpgp.message.Message*/);
|
||||
|
||||
const verifyOptions: openpgp.VerifyOptions = {
|
||||
message,
|
||||
signature,
|
||||
|
||||
55
types/openpgp/ts3.2/index.d.ts
vendored
55
types/openpgp/ts3.2/index.d.ts
vendored
@@ -5,7 +5,7 @@
|
||||
// Daniel Montesinos <https://github.com/damonpam>
|
||||
// Carlos Villavicencio <https://github.com/po5i>
|
||||
// Eric Camellini <https://github.com/ecamellini>
|
||||
// SardineFIsh <https://github.com/SardineFish>
|
||||
// SardineFish <https://github.com/SardineFish>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import BN = require("bn.js")
|
||||
@@ -1672,7 +1672,7 @@ export namespace key {
|
||||
* Returns userids
|
||||
* @returns array of userids
|
||||
*/
|
||||
getUserIds(): any[];
|
||||
getUserIds(): string[];
|
||||
|
||||
/**
|
||||
* Returns true if this is a public key
|
||||
@@ -1696,7 +1696,7 @@ export namespace key {
|
||||
* Returns ASCII armored text of key
|
||||
* @returns ASCII armor
|
||||
*/
|
||||
armor(): ReadableStream<String>;
|
||||
armor(): string;
|
||||
|
||||
/**
|
||||
* Returns last created key or key by given keyId that is available for signing and verification
|
||||
@@ -1761,7 +1761,7 @@ export namespace key {
|
||||
* @param userId, optional user ID
|
||||
* @returns
|
||||
*/
|
||||
getExpirationTime(capabilities: any, keyId: type.keyid.Keyid, userId: object): Promise<Date | Infinity | null>;
|
||||
getExpirationTime(capabilities?: any, keyId?: type.keyid.Keyid, userId?: object): Promise<Date | Infinity | null>;
|
||||
|
||||
/**
|
||||
* Returns primary user and most significant (latest valid) self signature
|
||||
@@ -1771,7 +1771,7 @@ export namespace key {
|
||||
* @param userId (optional) user ID to get instead of the primary user, if it exists
|
||||
* @returns The primary user and the self signature
|
||||
*/
|
||||
getPrimaryUser(date: Date, userId: object): Promise<{ user: User, selfCertification: packet.Signature }>;
|
||||
getPrimaryUser(date?: Date, userId?: object): Promise<{ user: User, selfCertification: packet.Signature }>;
|
||||
|
||||
/**
|
||||
* Update key with new components from specified key with same key ID:
|
||||
@@ -1897,6 +1897,8 @@ export namespace key {
|
||||
class User {
|
||||
constructor();
|
||||
|
||||
userId: packet.Userid;
|
||||
|
||||
/**
|
||||
* Transforms structured user data to packetlist
|
||||
* @returns
|
||||
@@ -4454,7 +4456,7 @@ export namespace util {
|
||||
* @param url If true, output is URL-safe
|
||||
* @returns Base-64 encoded string
|
||||
*/
|
||||
function Uint8Array_to_b64(bytes: Uint8Array, url: boolean): string;
|
||||
function Uint8Array_to_b64(bytes: Uint8Array, url?: boolean): string;
|
||||
|
||||
/**
|
||||
* Convert a hex string to an array of 8-bit integers
|
||||
@@ -4631,12 +4633,12 @@ export namespace util {
|
||||
/**
|
||||
* Format user id for internal use.
|
||||
*/
|
||||
function formatUserId(): void;
|
||||
function formatUserId(id: { name: string, email: string; comment: string }): string;
|
||||
|
||||
/**
|
||||
* Parse user id.
|
||||
*/
|
||||
function parseUserId(): void;
|
||||
function parseUserId(userId: string): { name: string, email: string; comment: string };
|
||||
|
||||
/**
|
||||
* Normalize line endings to \r\n
|
||||
@@ -4770,6 +4772,20 @@ export namespace worker {
|
||||
}
|
||||
}
|
||||
|
||||
export interface WorkerOptions {
|
||||
/**
|
||||
* relative path to the worker scripts, default: 'openpgp.worker.js'
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* number of workers to initialize
|
||||
*/
|
||||
n?: number;
|
||||
/**
|
||||
* alternative to path parameter: web workers initialized with 'openpgp.worker.js'
|
||||
*/
|
||||
workers?: any[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path for the web worker script and create an instance of the async proxy
|
||||
@@ -4777,7 +4793,7 @@ export namespace worker {
|
||||
* @param n number of workers to initialize
|
||||
* @param workers alternative to path parameter: web workers initialized with 'openpgp.worker.js'
|
||||
*/
|
||||
export function initWorker(path: string, n?: number, workers?: any[]): void;
|
||||
export function initWorker(options: WorkerOptions): void;
|
||||
|
||||
/**
|
||||
* Returns a reference to the async proxy if the worker was initialized with openpgp.initWorker()
|
||||
@@ -4951,9 +4967,6 @@ export interface EncryptOptions {
|
||||
}
|
||||
|
||||
export interface EncryptResult {
|
||||
data: string | ReadableStream<String>;
|
||||
message: message.Message;
|
||||
signature: string | ReadableStream<String> | signature.Signature;
|
||||
sessionKey: { data: Uint8Array, algorithm: string, aeadAlgorithm: string };
|
||||
}
|
||||
|
||||
@@ -4970,7 +4983,15 @@ export interface EncryptResult {
|
||||
* sessionKey: { data, algorithm, aeadAlgorithm } (if `returnSessionKey` was true)
|
||||
* }
|
||||
*/
|
||||
export function encrypt(options: EncryptOptions): Promise<EncryptResult>;
|
||||
export function encrypt(options: EncryptOptions & { armor?: true, detached?: false }): Promise<EncryptResult & { data: string }>
|
||||
export function encrypt(options: EncryptOptions & { armor?: true, detached: true }): Promise<EncryptResult & { data: string, signature: string }>
|
||||
export function encrypt(options: EncryptOptions & { armor: false, detached?: false }): Promise<EncryptResult & { message: message.Message }>
|
||||
export function encrypt(options: EncryptOptions & { armor: false, detached: true }): Promise<EncryptResult & { message: message.Message, signature: signature.Signature }>
|
||||
export function encrypt(options: EncryptOptions): Promise<EncryptResult & {
|
||||
data: string | ReadableStream<String>;
|
||||
message: message.Message;
|
||||
signature: string | ReadableStream<String> | signature.Signature;
|
||||
}>;
|
||||
|
||||
export interface DecryptOptions {
|
||||
/**
|
||||
@@ -5039,6 +5060,8 @@ export interface DecryptResult {
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
export function decrypt(options: DecryptOptions & { format: "utf8" }): Promise<DecryptOptions & { data: string | ReadableStream<String> | NodeStream}>
|
||||
export function decrypt(options: DecryptOptions & { format: "binary" }): Promise<DecryptOptions & { data: Uint8Array | ReadableStream<Uint8Array> | NodeStream }>
|
||||
export function decrypt(options: DecryptOptions): Promise<DecryptResult>;
|
||||
|
||||
export interface SignOptions {
|
||||
@@ -5090,8 +5113,12 @@ export interface SignResult {
|
||||
* {
|
||||
* signature: string|ReadableStream<String>|NodeStream, (if `armor` was true, the default)
|
||||
* signature: Signature (if `armor` was false)
|
||||
* }
|
||||
* }{
|
||||
*/
|
||||
export function sign(options: SignOptions & { armor?: true, detached?: false }): Promise<{ data: string }>
|
||||
export function sign(options: SignOptions & { armor: false, detached?: false }): Promise<{ message: message.Message }>
|
||||
export function sign(options: SignOptions & { armor?: true, detached: true }): Promise<{ signature: string }>
|
||||
export function sign(options: SignOptions & { armor: false, detached: true }): Promise<{ signature: signature.Signature }>
|
||||
export function sign(options: SignOptions): Promise<SignResult>;
|
||||
|
||||
export interface VerifyOptions {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import openpgp from "openpgp";
|
||||
import openpgp, { encrypt } from "openpgp";
|
||||
|
||||
// Open PGP Sample codes
|
||||
|
||||
@@ -72,7 +72,9 @@ Promise.all(promises).then(function (values) {
|
||||
// failure
|
||||
});
|
||||
|
||||
openpgp.initWorker('openpgp.worker.js');
|
||||
openpgp.initWorker({
|
||||
path: 'openpgp.worker.js'
|
||||
});
|
||||
|
||||
(async () => {
|
||||
let msgOptions: openpgp.EncryptOptions;
|
||||
@@ -84,8 +86,17 @@ openpgp.initWorker('openpgp.worker.js');
|
||||
};
|
||||
|
||||
let cipher = await openpgp.encrypt(msgOptions);
|
||||
|
||||
let encrypted = cipher.message.packets.write(); // get raw encrypted packets as Uint8Array
|
||||
|
||||
let armored = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
||||
armor: true,
|
||||
privateKeys: []
|
||||
});
|
||||
let data: string = armored.data;
|
||||
// let msg: openpgp.message.Message = armored.message; // without member 'message'
|
||||
|
||||
let plain = await openpgp.decrypt({
|
||||
message: await openpgp.message.read(encrypted),
|
||||
passwords: ['secret stuff'],
|
||||
@@ -122,6 +133,30 @@ openpgp.initWorker('openpgp.worker.js');
|
||||
|
||||
const signed = await openpgp.sign(signOptions);
|
||||
|
||||
// Test function reload
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
detached: true
|
||||
}).then(s => s.signature/* as string*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
detached: false,
|
||||
}).then(s => s.data/* as string*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
armor: false,
|
||||
detached: true
|
||||
}).then(s => s.signature/* as openpgp.signature.Signature*/);
|
||||
openpgp.sign({
|
||||
message: null,
|
||||
privateKeys: [],
|
||||
armor: false,
|
||||
detached: false,
|
||||
}).then(s => s.message/* as openpgp.message.Message*/);
|
||||
|
||||
const signature = signed.signature as openpgp.signature.Signature;
|
||||
const message = signed.message;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user