diff --git a/src/c14n-canonicalization.ts b/src/c14n-canonicalization.ts index 7625217a..03406145 100644 --- a/src/c14n-canonicalization.ts +++ b/src/c14n-canonicalization.ts @@ -1,4 +1,4 @@ -import { +import type { CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, NamespacePrefix, diff --git a/src/enveloped-signature.ts b/src/enveloped-signature.ts index ab898bd4..80a0a553 100644 --- a/src/enveloped-signature.ts +++ b/src/enveloped-signature.ts @@ -1,6 +1,6 @@ import * as xpath from "xpath"; -import { +import type { CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, CanonicalizationOrTransformAlgorithmType, diff --git a/src/exclusive-canonicalization.ts b/src/exclusive-canonicalization.ts index 06eea343..4f76c83a 100644 --- a/src/exclusive-canonicalization.ts +++ b/src/exclusive-canonicalization.ts @@ -1,4 +1,4 @@ -import { +import type { CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, NamespacePrefix, diff --git a/src/hash-algorithms.ts b/src/hash-algorithms.ts index 56f6c896..eeeb8b27 100644 --- a/src/hash-algorithms.ts +++ b/src/hash-algorithms.ts @@ -1,5 +1,5 @@ import * as crypto from "crypto"; -import { HashAlgorithm } from "./types"; +import type { HashAlgorithm } from "./types"; export class Sha1 implements HashAlgorithm { getHash = function (xml) { diff --git a/src/signature-algorithms.ts b/src/signature-algorithms.ts index 71a23ed8..46abe0eb 100644 --- a/src/signature-algorithms.ts +++ b/src/signature-algorithms.ts @@ -1,5 +1,5 @@ import * as crypto from "crypto"; -import { SignatureAlgorithm, createOptionalCallbackFunction } from "./types"; +import { type SignatureAlgorithm, createOptionalCallbackFunction } from "./types"; export class RsaSha1 implements SignatureAlgorithm { getSignature = createOptionalCallbackFunction( diff --git a/src/signed-xml.ts b/src/signed-xml.ts index b2c0ca0f..072201ff 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -1,4 +1,4 @@ -import { +import type { CanonicalizationAlgorithmType, CanonicalizationOrTransformationAlgorithm, ComputeSignatureOptions, diff --git a/src/utils.ts b/src/utils.ts index e58a95d3..2bb860a8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import * as xpath from "xpath"; -import { NamespacePrefix } from "./types"; +import type { NamespacePrefix } from "./types"; export function isArrayHasLength(array: unknown): array is unknown[] { return Array.isArray(array) && array.length > 0; @@ -207,6 +207,10 @@ function findNSPrefix(subset) { return subset.prefix || ""; } +function isElementSubset(docSubset: Node[]): docSubset is Element[] { + return docSubset.every((node) => xpath.isElement(node)) +} + /** * Extract ancestor namespaces in order to import it to root of document subset * which is being canonicalized for non-exclusive c14n. @@ -222,20 +226,17 @@ export function findAncestorNs( namespaceResolver?: XPathNSResolver ) { const docSubset = xpath.selectWithResolver(docSubsetXpath, doc, namespaceResolver); - let elementSubset: Element[] = []; if (!isArrayHasLength(docSubset)) { return []; } - if (!docSubset.every((node) => xpath.isElement(node))) { + if (!isElementSubset(docSubset)) { throw new Error("Document subset must be list of elements"); - } else { - elementSubset = docSubset as Element[]; } // Remove duplicate on ancestor namespace - const ancestorNs = collectAncestorNamespaces(elementSubset[0]); + const ancestorNs = collectAncestorNamespaces(docSubset[0]); const ancestorNsWithoutDuplicate: NamespacePrefix[] = []; for (let i = 0; i < ancestorNs.length; i++) { let notOnTheList = true;