Skip to content

Commit a1b2f8d

Browse files
authored
Merge pull request #2 from PCouaillier/ts
add node to yarn and add callback definitions
2 parents 5e3fd58 + a441d3c commit a1b2f8d

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

lib/paseto.d.ts

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ declare namespace Paseto {
44
* complete construction asynchronously
55
*/
66
inject(rkey: Buffer): Promise<void>;
7+
inject(rkey: Buffer, cb: (err: Error) => void): void;
78

89
/**
910
* complete construction asynchronously using base64 encoded key
1011
*/
1112
base64(skey: string): Promise<void>;
13+
base64(skey: string, cb: (err: Error) => void): void;
1214

1315
/**
1416
* complete construction asynchronously using hex encoded key
1517
*/
1618
hex(skey: string): Promise<void>;
19+
hex(skey: string, cb: (err: Error) => void): void;
1720

1821
/**
1922
* complete construction asynchronously, generating key
2023
*/
2124
generate(): Promise<void>;
25+
generate(cb: (err: Error) => void): void;
2226

2327
/**
2428
* return the underlying protocol object
@@ -36,34 +40,56 @@ declare namespace Paseto {
3640
raw(): Buffer;
3741
}
3842

43+
interface IPasetoKeyV1 extends IPasetoKey<V1> {}
44+
interface IPasetoKeyV2 extends IPasetoKey<V2> {}
45+
3946
/**
4047
* private key for asymmetric cryptography
4148
*/
4249
export class PrivateKey<P extends IProtocol> implements IPasetoKey<P> {
4350
constructor(proto: P);
51+
4452
public inject(rkey: Buffer): Promise<void>;
53+
public inject(rkey: Buffer, cb: (err: Error) => void): void;
54+
4555
public base64(skey: string): Promise<void>;
56+
public base64(skey: string, cb: (err: Error) => void): void;
57+
4658
public hex(skey: string): Promise<void>;
59+
public hex(skey: string, cb: (err: Error) => void): void;
60+
4761
public generate(): Promise<void>;
62+
public generate(cb: (err: Error) => void): void;
63+
4864
public protocol(): P;
4965
public encode(): string;
5066
public raw(): Buffer;
5167

5268
/**
5369
* return the corresponding public key object
5470
*/
55-
public public(): Promise<PublicKey<P>>
71+
public public(): Promise<PublicKey<P>>;
72+
public public(cb: (err: Error, key: PublicKey<P>) => void): void;
5673
}
5774

5875
/**
5976
* public key for asymmetric cryptography
6077
*/
6178
export class PublicKey<P extends IProtocol> implements IPasetoKey<P> {
6279
constructor(proto: P);
80+
6381
public inject(rkey: Buffer): Promise<void>;
82+
public inject(rkey: Buffer, cb: (err: Error) => void): void;
83+
6484
public base64(skey: string): Promise<void>;
85+
public base64(skey: string, cb: (err: Error) => void): void;
86+
6587
public hex(skey: string): Promise<void>;
88+
public hex(skey: string, cb: (err: Error) => void): void;
89+
6690
public generate(): Promise<void>;
91+
public generate(cb: (err: Error) => void): void;
92+
6793
public protocol(): P;
6894
public encode(): string;
6995
public raw(): Buffer;
@@ -74,10 +100,19 @@ declare namespace Paseto {
74100
*/
75101
export class SymmetricKey<P extends IProtocol> implements IPasetoKey<P> {
76102
constructor(proto: P);
103+
77104
public inject(rkey: Buffer): Promise<void>;
105+
public inject(rkey: Buffer, cb: (err: Error) => void): void;
106+
78107
public base64(skey: string): Promise<void>;
108+
public base64(skey: string, cb: (err: Error) => void): void;
109+
79110
public hex(skey: string): Promise<void>;
111+
public hex(skey: string, cb: (err: Error) => void): void;
112+
80113
public generate(): Promise<void>;
114+
public generate(cb: (err: Error) => void): void
115+
81116
public protocol(): P;
82117
public encode(): string;
83118
public raw(): Buffer;
@@ -136,11 +171,13 @@ declare namespace Paseto {
136171
* generate a private key for use with the protocol
137172
*/
138173
private(): Promise<PrivateKey<this>>;
174+
private(cb: (err: Error, key: PrivateKey<this>) => void): void
139175

140176
/**
141177
* generate a symmetric key for use with the protocol
142178
*/
143179
symmetric(): Promise<SymmetricKey<this>>;
180+
symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
144181

145182
/**
146183
* get protocol representation
@@ -156,49 +193,77 @@ declare namespace Paseto {
156193
* symmetric authenticated encryption
157194
*/
158195
encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
196+
encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
159197

160198
/**
161199
* symmetric authenticated decryption
162200
*/
163201
decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
202+
decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
164203

165204
/**
166205
* asymmetric authentication
167206
*/
168207
sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
208+
sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
169209

170210
/**
171211
* asymmetric authentication
172212
*/
173213
verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
214+
verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
174215
}
175216

176217
/**
177218
* protocol version 1
178219
*/
179220
export class V1 implements IProtocol {
180221
public private(): Promise<PrivateKey<this>>;
222+
public private(cb: (err: Error, key: PrivateKey<this>) => void): void
223+
181224
public symmetric(): Promise<SymmetricKey<this>>;
182-
public repr(): string;
225+
public symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
226+
227+
public repr(): 'v1';
183228
public sklength(): number;
229+
184230
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
231+
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
232+
185233
public decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
234+
public decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
235+
186236
public sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
237+
public sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
238+
187239
public verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
240+
public verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
188241
}
189242

190243
/**
191244
* protocol version 2
192245
*/
193246
export class V2 implements IProtocol {
194247
public private(): Promise<PrivateKey<this>>;
248+
public private(cb: (err: Error, key: PrivateKey<this>) => void): void
249+
195250
public symmetric(): Promise<SymmetricKey<this>>;
196-
public repr(): string;
251+
public symmetric(cb: (err: Error, key: SymmetricKey<this>) => void): void
252+
253+
public repr(): 'v2';
197254
public sklength(): number;
255+
198256
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
257+
public encrypt(data: Buffer|string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void
258+
199259
public decrypt(token: string, key: SymmetricKey<this>, footer?: Buffer|string): Promise<string>;
260+
public decrypt(token: string, key: SymmetricKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
261+
200262
public sign(data: Buffer|string, key: PrivateKey<this>, footer?: Buffer|string): Promise<string>;
263+
public sign(data: Buffer|string, key: PrivateKey<this>, footer: Buffer|string|undefined, cb: (err: Error, token: string) => void): void;
264+
201265
public verify(token: string, key: PublicKey<this>, footer?: Buffer|string): Promise<string>;
266+
public verify(token: string, key: PublicKey<this>, footer: Buffer|string|undefined, cb: (err: Error, data: string) => void): void;
202267
}
203268
}
204269

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"libsodium-wrappers-sumo": "0.7.3"
1111
},
1212
"devDependencies": {
13-
"@types/node": "^10.12.21",
13+
"@types/node": "^11.11.3",
1414
"mocha": "^5.0.1"
1515
},
1616
"scripts": {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@types/node@^11.11.3":
6+
version "11.11.3"
7+
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.3.tgz#7c6b0f8eaf16ae530795de2ad1b85d34bf2f5c58"
8+
integrity sha512-wp6IOGu1lxsfnrD+5mX6qwSwWuqsdkKKxTN4aQc4wByHAKZJf9/D4KXPQ1POUjEbnCP5LMggB0OEFNY9OTsMqg==
9+
510
balanced-match@^1.0.0:
611
version "1.0.0"
712
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

0 commit comments

Comments
 (0)