Skip to content

Commit

Permalink
feat: add type declaration (#277)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
LoneRifle authored Apr 18, 2023
1 parent a48ebd0 commit aa3fcd6
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
98 changes: 98 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/eheikes>
// Max Chehab <https://github.com/maxchehab>

/// <reference types="node" />

import { SelectedValue } from 'xpath';

export class HashAlgorithm {
getAlgorithmName(): string;
getHash(xml: string): string;
}

export interface Reference {
xpath: string;
transforms?: ReadonlyArray<string> | 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<string> | undefined
signatureAlgorithm?: string | undefined
})
addReference(
xpath: string,
transforms?: ReadonlyArray<string>,
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[];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"url": "https://github.com/yaronn/xml-crypto.git"
},
"main": "./index.js",
"types": "./index.d.ts",
"directories": {
"lib": "./lib"
},
Expand Down

0 comments on commit aa3fcd6

Please sign in to comment.