diff --git a/types/node-rsa/index.d.ts b/types/node-rsa/index.d.ts index 63d569378d..f7e92c071b 100644 --- a/types/node-rsa/index.d.ts +++ b/types/node-rsa/index.d.ts @@ -31,7 +31,10 @@ declare class NodeRSA { /** * Export key to PEM string, PEM/DER Buffer or components. */ - exportKey(format?: NodeRSA.Format): NodeRSA.Key; + exportKey(format?: NodeRSA.FormatPem): string; + exportKey(format: NodeRSA.FormatDer): Buffer; + exportKey(format: NodeRSA.FormatComponentsPrivate): NodeRSA.KeyComponentsPrivate; + exportKey(format: NodeRSA.FormatComponentsPublic): NodeRSA.KeyComponentsPublic; isPrivate(): boolean; @@ -85,20 +88,26 @@ declare class NodeRSA { } declare namespace NodeRSA { - type Key = string | Buffer | KeyComponents; + type Key = string | Buffer | KeyComponentsPrivate | KeyComponentsPublic; type Data = string | object | any[]; - type Format = + type FormatPem = | 'private' | 'public' - | 'pkcs1' | 'pkcs1-pem' | 'pkcs1-der' - | 'pkcs1-private' | 'pkcs1-private-pem' | 'pkcs1-private-der' - | 'pkcs1-public' | 'pkcs1-public-pem' | 'pkcs1-public-der' - | 'pkcs8' | 'pkcs8-pem' | 'pkcs8-der' - | 'pkcs8-private' | 'pkcs8-private-pem' | 'pkcs8-private-der' - | 'pkcs8-public' | 'pkcs8-public-pem' | 'pkcs8-public-der' + | 'pkcs1' | 'pkcs1-pem' + | 'pkcs1-private' | 'pkcs1-private-pem' + | 'pkcs1-public' | 'pkcs1-public-pem' + | 'pkcs8' | 'pkcs8-pem' + | 'pkcs8-private' | 'pkcs8-private-pem' + | 'pkcs8-public' | 'pkcs8-public-pem'; + type FormatDer = + | 'pkcs1-der' | 'pkcs1-private-der' | 'pkcs1-public-der' + | 'pkcs8-der' | 'pkcs8-private-der' | 'pkcs8-public-der'; + type FormatComponentsPrivate = | 'components' | 'components-pem' | 'components-der' - | 'components-private' | 'components-private-pem' | 'components-private-der' + | 'components-private' | 'components-private-pem' | 'components-private-der'; + type FormatComponentsPublic = | 'components-public' | 'components-public-pem' | 'components-public-der'; + type Format = FormatPem | FormatDer | FormatComponentsPrivate | FormatComponentsPublic; type EncryptionScheme = 'pkcs1_oaep' | 'pkcs1'; @@ -124,7 +133,7 @@ declare namespace NodeRSA { | 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'latin1' | 'base64' | 'hex' | 'binary' | 'buffer'; - interface KeyComponents { + interface KeyComponentsPrivate { n: Buffer; e: Buffer | number; d: Buffer; @@ -135,6 +144,11 @@ declare namespace NodeRSA { coeff: Buffer; } + interface KeyComponentsPublic { + n: Buffer; + e: Buffer | number; + } + interface KeyBits { /** * The length of the key in bits. diff --git a/types/node-rsa/node-rsa-tests.ts b/types/node-rsa/node-rsa-tests.ts index 0f8defacbd..eac9a0397b 100644 --- a/types/node-rsa/node-rsa-tests.ts +++ b/types/node-rsa/node-rsa-tests.ts @@ -26,8 +26,10 @@ Es+KCn25OKXR/FJ5fu6A6A+MptABL3r8SEjlpLc= const keyData = '-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----'; key.importKey(keyData, 'pkcs8'); -const publicDer = key.exportKey('pkcs8-public-der'); -const privateDer = key.exportKey('pkcs1-der'); +const defaultPem: string = key.exportKey(); +const publicPem: string = key.exportKey('pkcs8-public-pem'); +const publicDer: Buffer = key.exportKey('pkcs8-public-der'); +const privateDer: Buffer = key.exportKey('pkcs1-der'); key.importKey({ n: new Buffer('0086fa9ba066685845fc03833a9699c8baefb53cfbf19052a7f10f1eaa30488cec1ceb752bdff2df9fad6c64b3498956e7dbab4035b4823c99a44cc57088a23783', 'hex'), e: 65537, @@ -39,6 +41,17 @@ key.importKey({ coeff: new Buffer('00b399675e5e81506b729a777cc03026f0b2119853dfc5eb124610c0ab82999e45', 'hex') }, 'components'); const publicComponents = key.exportKey('components-public'); +let b: Buffer = publicComponents.n; +let bn: Buffer|number = publicComponents.e; +const privateComponents = key.exportKey('components-private'); +b = privateComponents.n; +bn = privateComponents.e; +b = privateComponents.d; +b = privateComponents.p; +b = privateComponents.q; +b = privateComponents.dmp1; +b = privateComponents.dmq1; +b = privateComponents.coeff; key.isPrivate(); key.isPublic(true);