diff --git a/types/node-forge/README.md b/types/node-forge/README.md index fcac651de8..c70966e474 100644 --- a/types/node-forge/README.md +++ b/types/node-forge/README.md @@ -27,3 +27,4 @@ BSD-2-Clause [Aakash Goenka](https://github.com/a-k-g) [Rafal2228](https://github.com/rafal2228) [Beeno Tung](https://github.com/beenotung) +[Nikita Koryabkin](https://github.com/Apologiz) diff --git a/types/node-forge/index.d.ts b/types/node-forge/index.d.ts index 88d44b169a..d362eb1c27 100644 --- a/types/node-forge/index.d.ts +++ b/types/node-forge/index.d.ts @@ -1,11 +1,12 @@ // Type definitions for node-forge 0.7.6 // Project: https://github.com/digitalbazaar/forge -// Definitions by: Seth Westphal -// Kay Schecker -// Aakash Goenka -// Rafal2228 -// Beeno Tung -// Joe Flateau +// Definitions by: Seth Westphal +// Kay Schecker +// Aakash Goenka +// Rafal2228 +// Beeno Tung +// Joe Flateau +// Nikita Koryabkin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -44,16 +45,26 @@ declare module "node-forge" { type Key = any; interface KeyPair { - publicKey: Key; - privateKey: Key; + publicKey: PublicKey; + privateKey: PrivateKey; + } + + interface PublicKey { + encrypt(data: string, scheme?: string, schemeOptions?: number): Bytes + verify(digest: string, signature: string, scheme?: string): boolean + } + + interface PrivateKey { + decrypt(data: string, scheme?: string, schemeOptions?: number): string + sign(md: string, scheme?: string): Bytes } function pemToDer(pem: PEM): util.ByteStringBuffer; - function privateKeyToPem(key: Key, maxline?: number): PEM; - function privateKeyInfoToPem(key: Key, maxline?: number): PEM; - function publicKeyToPem(key: Key, maxline?: number): PEM; - function publicKeyFromPem(pem: PEM): Key; - function privateKeyFromPem(pem: PEM): Key; + function privateKeyToPem(key: PrivateKey, maxline?: number): PEM; + function privateKeyInfoToPem(key: PrivateKey, maxline?: number): PEM; + function publicKeyToPem(key: PublicKey, maxline?: number): PEM; + function publicKeyFromPem(pem: PEM): PublicKey; + function privateKeyFromPem(pem: PEM): PrivateKey; function certificateToPem(cert: Certificate, maxline?: number): PEM; function certificateFromPem(pem: PEM, computeHash?: boolean, strict?: boolean): Certificate; @@ -99,9 +110,15 @@ declare module "node-forge" { function publicKeyFromPrivateKey(options: { privateKey: NativeBuffer }): NativeBuffer; - function sign(options: { privateKey: NativeBuffer }): NativeBuffer; + function sign(options: { + message: string, + encoding: string, + privateKey: NativeBuffer + }): NativeBuffer; function verify(options: { + message: string, + encoding: string, signature: Buffer | Uint8Array | util.ByteBuffer | string, publicKey: NativeBuffer }): boolean; @@ -474,11 +491,14 @@ declare module "node-forge" { type Algorithm = "AES-ECB" | "AES-CBC" | "AES-CFB" | "AES-OFB" | "AES-CTR" | "AES-GCM" | "3DES-ECB" | "3DES-CBC" | "DES-ECB" | "DES-CBC"; - function createCipher(algorithm: Algorithm, payload: util.ByteBuffer): BlockCipher; - function createDecipher(algorithm: Algorithm, payload: util.ByteBuffer): BlockCipher; + function createCipher(algorithm: Algorithm, payload: util.ByteBuffer | Bytes): BlockCipher; + function createDecipher(algorithm: Algorithm, payload: util.ByteBuffer | Bytes): BlockCipher; interface StartOptions { - iv?: string; + iv?: Bytes; + tag?: util.ByteStringBuffer; + tagLength?: number; + additionalData?: string; } interface BlockCipher { @@ -486,6 +506,11 @@ declare module "node-forge" { update: (payload: util.ByteBuffer) => void; finish: () => boolean; output: util.ByteStringBuffer; + mode: Mode; + } + + interface Mode { + tag: util.ByteStringBuffer; } } @@ -498,4 +523,8 @@ declare module "node-forge" { function create(any: any): any; } } + + namespace random { + function getBytesSync(length: number): Bytes; + } } diff --git a/types/node-forge/node-forge-tests.ts b/types/node-forge/node-forge-tests.ts index 575661e9aa..abc863f7ff 100644 --- a/types/node-forge/node-forge-tests.ts +++ b/types/node-forge/node-forge-tests.ts @@ -8,8 +8,8 @@ let x: string = forge.ssh.privateKeyToOpenSSH(key); let pemKey: forge.pki.PEM = publicKeyPem; let publicKeyRsa = forge.pki.publicKeyFromPem(pemKey); let privateKeyRsa = forge.pki.privateKeyFromPem(privateKeyPem); -let privateKeyRsa2 = forge.pki.privateKeyInfoToPem(privateKeyPem); -let byteBufferString = forge.pki.pemToDer(privateKeyRsa); +let privateKeyRsa2 = forge.pki.privateKeyInfoToPem(privateKeyRsa); +let byteBufferString = forge.pki.pemToDer(privateKeyPem); let certPem = forge.pki.certificateFromPem(pemKey); let cert = forge.pki.createCertificate();