From aa3fcd65db59d04031fe1c82d5656e719b07d3cd Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Tue, 18 Apr 2023 18:26:06 +0800 Subject: [PATCH] feat: add type declaration (#277) - port type declaration from @DefinitelyTyped, and reference it from package.json - add definitions for KeyInfo, StringKeyInfo, tweak SignedXml to take a KeyInfo for `keyInfoProvider` instead of FileKeyInfo --- index.d.ts | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 99 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..2166a10a --- /dev/null +++ b/index.d.ts @@ -0,0 +1,98 @@ +// Type definitions for @node-saml/xml-crypto +// Project: https://github.com/node-saml/xml-crypto#readme +// Original definitions by: Eric Heikes +// Max Chehab + +/// + +import { SelectedValue } from 'xpath'; + +export class HashAlgorithm { + getAlgorithmName(): string; + getHash(xml: string): string; +} + +export interface Reference { + xpath: string; + transforms?: ReadonlyArray | undefined; + digestAlgorithm?: string | undefined; + uri?: string | undefined; + digestValue?: string | undefined; + inclusiveNamespacesPrefixList?: string | undefined; + isEmptyUri?: boolean | undefined; +} + +export class SignatureAlgorithm { + getAlgorithmName(): string; + getSignature(signedInfo: Node, signingKey: Buffer): string; +} + +export class TransformationAlgorithm { + getAlgorithmName(): string; + process(node: Node): string; +} + +export class SignedXml { + static CanonicalizationAlgorithms: {[uri: string]: new () => TransformationAlgorithm }; + static HashAlgorithms: {[uri: string]: new () => HashAlgorithm}; + static SignatureAlgorithms: {[uri: string]: new () => SignatureAlgorithm}; + canonicalizationAlgorithm: string; + keyInfoProvider: KeyInfo; + references: Reference[]; + signatureAlgorithm: string; + signingKey: Buffer | string; + validationErrors: string[]; + constructor(idMode?: string | null, options?: { + canonicalizationAlgorithm?: string | undefined + idAttribute?: string | undefined + implicitTransforms?: ReadonlyArray | undefined + signatureAlgorithm?: string | undefined + }) + addReference( + xpath: string, + transforms?: ReadonlyArray, + digestAlgorithm?: string, + uri?: string, + digestValue?: string, + inclusiveNamespacesPrefixList?: string, + isEmptyUri?: boolean + ): void; + checkSignature(xml: string): boolean; + computeSignature( + xml: string, + opts?: { + prefix?: string | undefined, + attrs?: {[key: string]: any} | undefined, + location?: { + reference: string, + action: 'append' | 'prepend' | 'before' | 'after' + } | undefined, + existingPrefixes?: {[prefix: string]: string} | undefined + } + ): void; + getOriginalXmlWithIds(): string; + getSignatureXml(): string; + getSignedXml(): string; + loadSignature(signatureNode: string | Node): void; +} + +export interface KeyInfo { + getKey(keyInfo?: Node[] | null): Buffer; + getKeyInfo(key?: string, prefix?: string): string; +} + +export class FileKeyInfo implements KeyInfo { + file: string; + constructor(file?: string); + getKey(keyInfo?: Node[] | null): Buffer; + getKeyInfo(key?: string, prefix?: string): string; +} + +export class StringKeyInfo implements KeyInfo { + key: string; + constructor(key?: string); + getKey(keyInfo?: Node[] | null): Buffer; + getKeyInfo(key?: string, prefix?: string): string; +} + +export function xpath(node: Node, xpath: string): SelectedValue[]; diff --git a/package.json b/package.json index 2aaefed6..6af86819 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "url": "https://github.com/yaronn/xml-crypto.git" }, "main": "./index.js", + "types": "./index.d.ts", "directories": { "lib": "./lib" },