diff --git a/types/node-forge/index.d.ts b/types/node-forge/index.d.ts index 7652e79b5a..a8058011d6 100644 --- a/types/node-forge/index.d.ts +++ b/types/node-forge/index.d.ts @@ -66,6 +66,35 @@ declare module "node-forge" { legacy?: boolean; }; + interface ByteBufferFingerprintOptions { + /** + * @description The type of fingerprint. If not specified, defaults to 'RSAPublicKey' + */ + type?: 'SubjectPublicKeyInfo' | 'RSAPublicKey'; + /** + * @description the delimiter to use between bytes for `hex` encoded output + */ + delimiter?: string; + /** + * @description if not specified defaults to `md.md5` + */ + md?: md.MessageDigest; + } + + interface HexFingerprintOptions extends ByteBufferFingerprintOptions { + /** + * @description if not specified, the function will return `ByteStringBuffer` + */ + encoding: 'hex'; + } + + interface BinaryFingerprintOptions extends ByteBufferFingerprintOptions { + /** + * @description if not specified, the function will return `ByteStringBuffer` + */ + encoding: 'binary'; + } + interface KeyPair { publicKey: PublicKey; privateKey: PrivateKey; @@ -374,6 +403,10 @@ declare module "node-forge" { type setRsaPublicKey = typeof rsa.setPublicKey; function wrapRsaPrivateKey(privateKey: asn1.Asn1): asn1.Asn1; + + function getPublicKeyFingerprint(publicKey: PublicKey, options?: ByteBufferFingerprintOptions): util.ByteStringBuffer; + function getPublicKeyFingerprint(publicKey: PublicKey, options: HexFingerprintOptions): Hex; + function getPublicKeyFingerprint(publicKey: PublicKey, options: BinaryFingerprintOptions): Bytes; } namespace random { diff --git a/types/node-forge/node-forge-tests.ts b/types/node-forge/node-forge-tests.ts index 9b02586f7f..309c6fd7fd 100644 --- a/types/node-forge/node-forge-tests.ts +++ b/types/node-forge/node-forge-tests.ts @@ -384,3 +384,22 @@ if (forge.util.fillString('1', 5) !== '11111') throw Error('forge.util.fillStrin privateKey }); } + +{ + let byteBuffer: forge.util.ByteBuffer = forge.pki.getPublicKeyFingerprint(cert.publicKey, { + type: 'SubjectPublicKeyInfo', + md: forge.md.sha256.create(), + }); + + let hex: forge.Hex = forge.pki.getPublicKeyFingerprint(cert.publicKey, { + type: 'SubjectPublicKeyInfo', + md: forge.md.sha256.create(), + encoding: 'hex' + }); + + let bytes: forge.Bytes = forge.pki.getPublicKeyFingerprint(cert.publicKey, { + type: 'SubjectPublicKeyInfo', + md: forge.md.sha256.create(), + encoding: 'binary' + }); +}