-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpaseto.d.ts
270 lines (215 loc) · 9.21 KB
/
paseto.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
declare namespace Paseto {
interface IPasetoKey<P extends IProtocol> {
/**
* complete construction asynchronously
*/
inject(rkey: Buffer): Promise<void>;
inject(rkey: Buffer, cb: (err: Error) => void): void;
/**
* complete construction asynchronously using base64 encoded key
*/
base64(skey: string): Promise<void>;
base64(skey: string, cb: (err: Error) => void): void;
/**
* complete construction asynchronously using hex encoded key
*/
hex(skey: string): Promise<void>;
hex(skey: string, cb: (err: Error) => void): void;
/**
* complete construction asynchronously, generating key
*/
generate(): Promise<void>;
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;
}
interface IPasetoKeyV1 extends IPasetoKey<V1> {}
interface IPasetoKeyV2 extends IPasetoKey<V2> {}
/**
* private key for asymmetric cryptography
*/
export class PrivateKey<P extends IProtocol> implements IPasetoKey<P> {
constructor(proto: P);
public inject(rkey: Buffer): Promise<void>;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise<void>;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise<void>;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise<void>;
public generate(cb: (err: Error) => void): void;
public protocol(): P;
public encode(): string;
public raw(): Buffer;
/**
* return the corresponding public key object
*/
public public(): Promise<PublicKey<P>>;
public public(cb: (err: Error, key: PublicKey<P>) => void): void;
}
/**
* public key for asymmetric cryptography
*/
export class PublicKey<P extends IProtocol> implements IPasetoKey<P> {
constructor(proto: P);
public inject(rkey: Buffer): Promise<void>;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise<void>;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise<void>;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise<void>;
public generate(cb: (err: Error) => void): void;
public protocol(): P;
public encode(): string;
public raw(): Buffer;
}
/**
* secret key for symmetric cryptography
*/
export class SymmetricKey<P extends IProtocol> implements IPasetoKey<P> {
constructor(proto: P);
public inject(rkey: Buffer): Promise<void>;
public inject(rkey: Buffer, cb: (err: Error) => void): void;
public base64(skey: string): Promise<void>;
public base64(skey: string, cb: (err: Error) => void): void;
public hex(skey: string): Promise<void>;
public hex(skey: string, cb: (err: Error) => void): void;
public generate(): Promise<void>;
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<Paseto.V1> {
constructor();
}
/**
* shortcut for new PrivateKey(new V2())
*/
export class V2 extends PrivateKey<Paseto.V2> {
constructor();
}
}
namespace PublicKey {
/**
* shortcut for new PublicKey(new V1())
*/
export class V1 extends PublicKey<Paseto.V1> {
constructor();
}
/**
* shortcut for new PublicKey(new V2())
*/
export class V2 extends PublicKey<Paseto.V2> {
constructor();
}
}
namespace SymmetricKey {
/**
* shortcut for new SymmetricKey(new V1())
*/
export class V1 extends SymmetricKey<Paseto.V1> {
constructor();
}
/**
* shortcut for new SymmetricKey(new V2())
*/
export class V2 extends SymmetricKey<Paseto.V2> {
constructor();
}
}
interface IProtocol {
/**
* generate a private key for use with the protocol
*/
private(): Promise<PrivateKey<this>>;
private(cb: (err: Error, key: PrivateKey<this>) => void): void
/**
* generate a symmetric key for use with the protocol
*/
symmetric(): Promise<SymmetricKey<this>>;
symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
/**
* get protocol representation
*/
repr(): string;
/**
* get symmetric key length
*/
sklength(): number;
/**
* symmetric authenticated encryption
*/
encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
/**
* symmetric authenticated decryption
*/
decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
/**
* asymmetric authentication
*/
sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
/**
* asymmetric authentication
*/
verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
/**
* protocol version 1
*/
export class V1 implements IProtocol {
public private(): Promise<PrivateKey<this>>;
public private(cb: (err: Error, key: PrivateKey<this>) => void): void
public symmetric(): Promise<SymmetricKey<this>>;
public symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
public repr(): 'v1';
public sklength(): number;
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
public decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
public decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
public sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
public sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
public verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
/**
* protocol version 2
*/
export class V2 implements IProtocol {
public private(): Promise<PrivateKey<this>>;
public private(cb: (err: Error, key: PrivateKey<this>) => void): void
public symmetric(): Promise<SymmetricKey<this>>;
public symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
public repr(): 'v2';
public sklength(): number;
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
public decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
public decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
public sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
public sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
public verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
public verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
}
}
export = Paseto;