Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/c14n-canonicalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
NamespacePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/enveloped-signature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as xpath from "xpath";

import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
CanonicalizationOrTransformAlgorithmType,
Expand Down
2 changes: 1 addition & 1 deletion src/exclusive-canonicalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
NamespacePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/hash-algorithms.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/signature-algorithms.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/signed-xml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationAlgorithmType,
CanonicalizationOrTransformationAlgorithm,
ComputeSignatureOptions,
Expand Down
13 changes: 7 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down