Skip to content

Commit a2db808

Browse files
gabeleviFacebook Github Bot
authored andcommitted
fix: Node.js definitions: supply static & constructor signatures for crypto$Verify & crypto$SIgn
Summary: The signatures for these class constructors differ very slightly to those of WritableStream. They require an algo as the first argument - and they also can be called without `new`. This PR adds declarations for both of these features. ([Source for verify](https://github.com/nodejs/node/blob/7537718460c7b964ffbbc0910b12eaff9cd8b7a8/lib/crypto.js#L293-L302), [Source for sign](https://github.com/nodejs/node/blob/7537718460c7b964ffbbc0910b12eaff9cd8b7a8/lib/crypto.js#L259-L266)) Closes facebook#2757 Differential Revision: D4266237 Pulled By: gabelevi fbshipit-source-id: 3c70af6eb29fdae834fe80961146b4254260d63e
1 parent b301a3d commit a2db808

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

lib/node.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ type crypto$Sign$private_key = string | {
442442
passphrase: string,
443443
}
444444
declare class crypto$Sign extends stream$Writable {
445+
static(algorithm: string, options?: writableStreamOptions): crypto$Sign,
446+
constructor(algorithm: string, options?: writableStreamOptions): void;
445447
sign(
446448
private_key: crypto$Sign$private_key,
447449
output_format: 'binary' | 'hex' | 'base64'
@@ -455,6 +457,8 @@ declare class crypto$Sign extends stream$Writable {
455457
}
456458

457459
declare class crypto$Verify extends stream$Writable {
460+
static(algorithm: string, options?: writableStreamOptions): crypto$Verify,
461+
constructor(algorithm: string, options?: writableStreamOptions): void;
458462
update(data: Buffer, input_encoding?: void): crypto$Verify;
459463
update(data: string, input_encoding?: 'utf8' | 'ascii' | 'binary'): crypto$Verify;
460464
verify(

tests/node_tests/node_tests.exp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ crypto/crypto.js:16
4949
^^^^^^^^^^^^^^^ call of method `write`
5050
16: hmac.write(123); // 2 errors: not a string or a Buffer
5151
^^^ number. This type is incompatible with
52-
1217: chunk: Buffer | string,
53-
^^^^^^^^^^^^^^^ union: Buffer | string. See lib: <BUILTINS>/node.js:1217
52+
1221: chunk: Buffer | string,
53+
^^^^^^^^^^^^^^^ union: Buffer | string. See lib: <BUILTINS>/node.js:1221
5454
Member 1:
55-
1217: chunk: Buffer | string,
56-
^^^^^^ Buffer. See lib: <BUILTINS>/node.js:1217
55+
1221: chunk: Buffer | string,
56+
^^^^^^ Buffer. See lib: <BUILTINS>/node.js:1221
5757
Error:
5858
16: hmac.write(123); // 2 errors: not a string or a Buffer
5959
^^^ number. This type is incompatible with
60-
1217: chunk: Buffer | string,
61-
^^^^^^ Buffer. See lib: <BUILTINS>/node.js:1217
60+
1221: chunk: Buffer | string,
61+
^^^^^^ Buffer. See lib: <BUILTINS>/node.js:1221
6262
Member 2:
63-
1217: chunk: Buffer | string,
64-
^^^^^^ string. See lib: <BUILTINS>/node.js:1217
63+
1221: chunk: Buffer | string,
64+
^^^^^^ string. See lib: <BUILTINS>/node.js:1221
6565
Error:
6666
16: hmac.write(123); // 2 errors: not a string or a Buffer
6767
^^^ number. This type is incompatible with
68-
1217: chunk: Buffer | string,
69-
^^^^^^ string. See lib: <BUILTINS>/node.js:1217
68+
1221: chunk: Buffer | string,
69+
^^^^^^ string. See lib: <BUILTINS>/node.js:1221
7070

7171
crypto/crypto.js:26
7272
26: hmac.update('foo', 'bogus'); // 1 error
@@ -127,14 +127,14 @@ crypto/crypto.js:36
127127
fs/fs.js:13
128128
13: fs.readFile("file.exp", { encoding: "blah" }, (_, data) => {
129129
^ call of method `readFile`. Could not decide which case to select
130-
790: declare function readFile(
131-
^ intersection type. See lib: <BUILTINS>/node.js:790
130+
794: declare function readFile(
131+
^ intersection type. See lib: <BUILTINS>/node.js:794
132132
Case 3 may work:
133-
799: declare function readFile(
134-
^ function type. See lib: <BUILTINS>/node.js:799
133+
803: declare function readFile(
134+
^ function type. See lib: <BUILTINS>/node.js:803
135135
But if it doesn't, case 4 looks promising too:
136-
804: declare function readFile(
137-
^ function type. See lib: <BUILTINS>/node.js:804
136+
808: declare function readFile(
137+
^ function type. See lib: <BUILTINS>/node.js:808
138138
Please provide additional annotation(s) to determine whether case 3 works (or consider merging it with case 4):
139139
13: fs.readFile("file.exp", { encoding: "blah" }, (_, data) => {
140140
^ parameter `_`

0 commit comments

Comments
 (0)