Skip to content

Commit be61682

Browse files
authored
Improve exported typings (#367)
1 parent a05732d commit be61682

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

src/types.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export type CanonicalizationAlgorithmType =
1414
| "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
1515
| "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
1616
| "http://www.w3.org/2001/10/xml-exc-c14n#"
17-
| "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
17+
| "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
18+
| string;
1819

1920
export type CanonicalizationOrTransformAlgorithmType =
2021
| CanonicalizationAlgorithmType
21-
| "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
22-
| string;
22+
| "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
2323

2424
export type HashAlgorithmType =
2525
| "http://www.w3.org/2000/09/xmldsig#sha1"
@@ -38,15 +38,15 @@ export type SignatureAlgorithmType =
3838
* @param cert the certificate as a string or array of strings (see https://www.w3.org/TR/2008/REC-xmldsig-core-20080610/#sec-X509Data)
3939
* @param prefix an optional namespace alias to be used for the generated XML
4040
*/
41-
export type GetKeyInfoContentArgs = {
41+
export interface GetKeyInfoContentArgs {
4242
publicCert?: crypto.KeyLike;
4343
prefix?: string | null;
44-
};
44+
}
4545

4646
/**
4747
* Options for the SignedXml constructor.
4848
*/
49-
export type SignedXmlOptions = {
49+
export interface SignedXmlOptions {
5050
idMode?: "wssecurity";
5151
idAttribute?: string;
5252
privateKey?: crypto.KeyLike;
@@ -58,25 +58,30 @@ export type SignedXmlOptions = {
5858
keyInfoAttributes?: Record<string, string>;
5959
getKeyInfoContent?(args?: GetKeyInfoContentArgs): string | null;
6060
getCertFromKeyInfo?(keyInfo?: Node | null): string | null;
61-
};
61+
}
6262

63-
export type NamespacePrefix = {
63+
export interface NamespacePrefix {
6464
prefix: string;
6565
namespaceURI: string;
66-
};
66+
}
6767

68-
export type RenderedNamespace = {
68+
export interface RenderedNamespace {
6969
rendered: string;
7070
newDefaultNs: string;
71-
};
71+
}
7272

73-
export type CanonicalizationOrTransformationAlgorithmProcessOptions = {
73+
export interface CanonicalizationOrTransformationAlgorithmProcessOptions {
7474
defaultNs?: string;
7575
defaultNsForPrefix?: Record<string, string>;
7676
ancestorNamespaces?: NamespacePrefix[];
7777
signatureNode?: Node | null;
7878
inclusiveNamespacesPrefixList?: string[];
79-
};
79+
}
80+
81+
export interface ComputeSignatureOptionsLocation {
82+
reference?: string;
83+
action?: "append" | "prepend" | "before" | "after";
84+
}
8085

8186
/**
8287
* Options for the computeSignature method.
@@ -90,15 +95,12 @@ export type CanonicalizationOrTransformationAlgorithmProcessOptions = {
9095
* should contain one of the following values:
9196
* `append`, `prepend`, `before`, `after`
9297
*/
93-
export type ComputeSignatureOptions = {
98+
export interface ComputeSignatureOptions {
9499
prefix?: string;
95-
attrs?: { [attrName: string]: string };
96-
location?: {
97-
reference?: string;
98-
action?: "append" | "prepend" | "before" | "after";
99-
};
100-
existingPrefixes?: { [prefix: string]: string };
101-
};
100+
attrs?: Record<string, string>;
101+
location?: ComputeSignatureOptionsLocation;
102+
existingPrefixes?: Record<string, string>;
103+
}
102104

103105
/**
104106
* Represents a reference node for XML digital signature.
@@ -124,11 +126,17 @@ export interface Reference {
124126

125127
// Optional. Indicates whether the URI is empty.
126128
isEmptyUri: boolean;
129+
130+
// Optional. The type of the reference node.
131+
ancestorNamespaces?: NamespacePrefix[];
127132
}
128133

129134
/** Implement this to create a new CanonicalizationOrTransformationAlgorithm */
130135
export interface CanonicalizationOrTransformationAlgorithm {
131-
process(node: Node, options: CanonicalizationOrTransformationAlgorithmProcessOptions): Node;
136+
process(
137+
node: Node,
138+
options: CanonicalizationOrTransformationAlgorithmProcessOptions,
139+
): Node | string;
132140

133141
getAlgorithmName(): CanonicalizationOrTransformAlgorithmType;
134142

test/signature-unit-tests.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ describe("Signature unit tests", function () {
386386
sig.getKeyInfoContent = function () {
387387
return "dummy key info";
388388
};
389-
// @ts-expect-error FIXME
390389
sig.canonicalizationAlgorithm = "http://DummyCanonicalization";
391390
sig.privateKey = "";
392391

@@ -545,7 +544,6 @@ describe("Signature unit tests", function () {
545544
sig.getKeyInfoContent = function () {
546545
return "<ds:dummy>dummy key info</ds:dummy>";
547546
};
548-
// @ts-expect-error FIXME
549547
sig.canonicalizationAlgorithm = "http://DummyCanonicalization";
550548
sig.privateKey = "";
551549

0 commit comments

Comments
 (0)