declare module 'paseto.js' {
namespace Paseto {
interface IPasetoKey
{
/**
* complete construction asynchronously
*/
inject(rkey: Buffer): Promise;
inject(rkey: Buffer, cb: (err: Error) => void): void;
/**
* complete construction asynchronously using base64 encoded key
*/
base64(skey: string): Promise;
base64(skey: string, cb: (err: Error) => void): void;
/**
* complete construction asynchronously using hex encoded key
*/
hex(skey: string): Promise;
hex(skey: string, cb: (err: Error) => void): void;
/**
* complete construction asynchronously, generating key
*/
generate(): Promise;
generate(cb: (err: Error) => void): void;
/**
* return the underlying protocol object
*/
protocol(): P;
/**
* encode the raw key as b64url
*/
encode(): string;
/**
* return the raw key buffer
*/
raw(): Buffer;
}
export interface IPasetoKeyV1 extends IPasetoKey {}
export interface IPasetoKeyV2 extends IPasetoKey {}
/**
* private key for asymmetric cryptography
*/
export class PrivateKey implements IPasetoKey
{
constructor(proto: P);
public inject(rkey: Buffer): Promise;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise;
public generate(cb: (err: Error) => void): void;
public protocol(): P;
public encode(): string;
public raw(): Buffer;
public public(): Promise>;
public public(cb: (err: Error, key: PublicKey) => void): void;
}
/**
* public key for asymmetric cryptography
*/
export class PublicKey
implements IPasetoKey
{
constructor(proto: P);
public inject(rkey: Buffer): Promise;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise;
public generate(cb: (err: Error) => void): void;
public protocol(): P;
public encode(): string;
public raw(): Buffer;
}
/**
* secret key for symmetric cryptography
*/
export class SymmetricKey implements IPasetoKey
{
constructor(proto: P);
public inject(rkey: Buffer): Promise;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise;
public generate(cb: (err: Error) => void): void;
public protocol(): P;
public encode(): string;
public raw(): Buffer;
}
namespace PrivateKey {
/**
* shortcut for new PrivateKey(new V1())
*/
export class V1 extends PrivateKey {
constructor();
}
/**
* shortcut for new PrivateKey(new V2())
*/
export class V2 extends PrivateKey {
constructor();
}
}
namespace PublicKey {
/**
* shortcut for new PublicKey(new V1())
*/
export class V1 extends PublicKey {
constructor();
}
/**
* shortcut for new PublicKey(new V2())
*/
export class V2 extends PublicKey {
constructor();
}
}
namespace SymmetricKey {
/**
* shortcut for new SymmetricKey(new V1())
*/
export class V1 extends SymmetricKey {
constructor();
}
/**
* shortcut for new SymmetricKey(new V2())
*/
export class V2 extends SymmetricKey {
constructor();
}
}
interface IProtocol {
/**
* generate a private key for use with the protocol
*/
private(): Promise>;
private(cb: (err: Error, key: PrivateKey) => void): void;
/**
* generate a symmetric key for use with the protocol
*/
symmetric(): Promise>;
symmetric(cb: (err: Error, key: SymmetricKey) => void): void;
/**
* get protocol representation
*/
repr(): string;
/**
* get symmetric key length
*/
sklength(): number;
/**
* symmetric authenticated encryption
*/
encrypt(data: Buffer|string, key: SymmetricKey, footer?: Buffer|string): Promise;
encrypt(data: Buffer|string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
/**
* symmetric authenticated decryption
*/
decrypt(token: string, key: SymmetricKey, footer?: Buffer|string): Promise;
decrypt(token: string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
/**
* asymmetric authentication
*/
sign(data: Buffer|string, key: PrivateKey, footer?: Buffer|string): Promise;
sign(data: Buffer|string, key: PrivateKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
/**
* asymmetric authentication
*/
verify(token: string, key: PublicKey, footer?: Buffer|string): Promise;
verify(token: string, key: PublicKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
/**
* protocol version 1
*/
export class V1 implements IProtocol {
public private(): Promise>;
public private(cb: (err: Error, key: PrivateKey) => void): void;
public symmetric(): Promise>;
public symmetric(cb: (err: Error, key: SymmetricKey) => void): void;
public repr(): 'v1';
public sklength(): number;
public encrypt(data: Buffer|string, key: SymmetricKey, footer?: Buffer|string): Promise;
public encrypt(data: Buffer|string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public decrypt(token: string, key: SymmetricKey, footer?: Buffer|string): Promise;
public decrypt(token: string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
public sign(data: Buffer|string, key: PrivateKey, footer?: Buffer|string): Promise;
public sign(data: Buffer|string, key: PrivateKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public verify(token: string, key: PublicKey, footer?: Buffer|string): Promise;
public verify(token: string, key: PublicKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
/**
* protocol version 2
*/
export class V2 implements IProtocol {
public private(): Promise>;
public private(cb: (err: Error, key: PrivateKey) => void): void;
public symmetric(): Promise>;
public symmetric(cb: (err: Error, key: SymmetricKey) => void): void;
public repr(): 'v2';
public sklength(): number;
public encrypt(data: Buffer|string, key: SymmetricKey, footer?: Buffer|string): Promise;
public encrypt(data: Buffer|string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public decrypt(token: string, key: SymmetricKey, footer?: Buffer|string): Promise;
public decrypt(token: string, key: SymmetricKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
public sign(data: Buffer|string, key: PrivateKey, footer?: Buffer|string): Promise;
public sign(data: Buffer|string, key: PrivateKey, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public verify(token: string, key: PublicKey, footer?: Buffer|string): Promise;
public verify(token: string, key: PublicKey, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
}
export = Paseto;
}