summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/digest.ts13
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/getRandomValues.ts13
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/importKey.ts8
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/verifyEC2.ts8
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/verifyOKP.ts8
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/verifyRSA.ts8
6 files changed, 14 insertions, 44 deletions
diff --git a/packages/server/src/helpers/iso/isoCrypto/digest.ts b/packages/server/src/helpers/iso/isoCrypto/digest.ts
index 3571086..9a5cfae 100644
--- a/packages/server/src/helpers/iso/isoCrypto/digest.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/digest.ts
@@ -1,4 +1,4 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
import { COSEALG } from '../../cose';
import { mapCoseAlgToWebCryptoAlg } from './mapCoseAlgToWebCryptoAlg';
@@ -9,17 +9,10 @@ import { mapCoseAlgToWebCryptoAlg } from './mapCoseAlgToWebCryptoAlg';
* @param data The data to generate a digest of
* @param algorithm A COSE algorithm ID that maps to the SHA algorithm. Default: `-7` (for SHA-256)
*/
- export async function digest(data: Uint8Array, algorithm: COSEALG): Promise<Uint8Array> {
+export async function digest(data: Uint8Array, algorithm: COSEALG): Promise<Uint8Array> {
const subtleAlgorithm = mapCoseAlgToWebCryptoAlg(algorithm);
- let hashed: ArrayBuffer
- if (globalThis.crypto) {
- // We're in a browser-like runtime, use global Crypto
- hashed = await globalThis.crypto.subtle.digest(subtleAlgorithm, data);
- } else {
- // We're in Node, use Node's Crypto
- hashed = await webcrypto.subtle.digest(subtleAlgorithm, data);
- }
+ const hashed = await WebCrypto.subtle.digest(subtleAlgorithm, data);
return new Uint8Array(hashed);
}
diff --git a/packages/server/src/helpers/iso/isoCrypto/getRandomValues.ts b/packages/server/src/helpers/iso/isoCrypto/getRandomValues.ts
index c090d49..ab7454b 100644
--- a/packages/server/src/helpers/iso/isoCrypto/getRandomValues.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/getRandomValues.ts
@@ -1,18 +1,11 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
/**
* Fill up the provided bytes array with random bytes equal to its length.
*
* @returns the same bytes array passed into the method
*/
- export function getRandomValues(array: Uint8Array): Uint8Array {
- if (globalThis.crypto) {
- // We're in a browser-like runtime, use global Crypto
- globalThis.crypto.getRandomValues(array);
- } else {
- // We're in Node, use Node's Crypto
- webcrypto.getRandomValues(array);
- }
-
+export function getRandomValues(array: Uint8Array): Uint8Array {
+ WebCrypto.getRandomValues(array);
return array;
}
diff --git a/packages/server/src/helpers/iso/isoCrypto/importKey.ts b/packages/server/src/helpers/iso/isoCrypto/importKey.ts
index b9961d7..badb24f 100644
--- a/packages/server/src/helpers/iso/isoCrypto/importKey.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/importKey.ts
@@ -1,4 +1,4 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
export async function importKey(opts: {
keyData: JsonWebKey,
@@ -6,9 +6,5 @@ export async function importKey(opts: {
}): Promise<CryptoKey> {
const { keyData, algorithm } = opts;
- if (globalThis.crypto) {
- return globalThis.crypto.subtle.importKey('jwk', keyData, algorithm, false, ['verify']);
- } else {
- return webcrypto.subtle.importKey('jwk', keyData, algorithm, false, ['verify']);
- }
+ return WebCrypto.subtle.importKey('jwk', keyData, algorithm, false, ['verify']);
}
diff --git a/packages/server/src/helpers/iso/isoCrypto/verifyEC2.ts b/packages/server/src/helpers/iso/isoCrypto/verifyEC2.ts
index 3b4fbe4..0227755 100644
--- a/packages/server/src/helpers/iso/isoCrypto/verifyEC2.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/verifyEC2.ts
@@ -1,4 +1,4 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
import { ECDSASigValue } from "@peculiar/asn1-ecc";
import { AsnParser } from '@peculiar/asn1-schema';
@@ -102,11 +102,7 @@ export async function verifyEC2(opts: {
hash: { name: subtleAlg },
};
- if (globalThis.crypto) {
- return globalThis.crypto.subtle.verify(verifyAlgorithm, key, finalSignature, data);
- } else {
- return webcrypto.subtle.verify(verifyAlgorithm, key, finalSignature, data);
- }
+ return WebCrypto.subtle.verify(verifyAlgorithm, key, finalSignature, data);
}
/**
diff --git a/packages/server/src/helpers/iso/isoCrypto/verifyOKP.ts b/packages/server/src/helpers/iso/isoCrypto/verifyOKP.ts
index e610304..ec3290b 100644
--- a/packages/server/src/helpers/iso/isoCrypto/verifyOKP.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/verifyOKP.ts
@@ -1,4 +1,4 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
import { COSEPublicKeyOKP, COSEKEYS, isCOSEAlg, COSECRV } from '../../cose';
import { isoBase64URL } from '../../index';
@@ -63,9 +63,5 @@ export async function verifyOKP(opts: {
name: _crv,
};
- if (globalThis.crypto) {
- return globalThis.crypto.subtle.verify(verifyAlgorithm, key, signature, data);
- } else {
- return webcrypto.subtle.verify(verifyAlgorithm, key, signature, data);
- }
+ return WebCrypto.subtle.verify(verifyAlgorithm, key, signature, data);
}
diff --git a/packages/server/src/helpers/iso/isoCrypto/verifyRSA.ts b/packages/server/src/helpers/iso/isoCrypto/verifyRSA.ts
index c7dc4b6..178ee46 100644
--- a/packages/server/src/helpers/iso/isoCrypto/verifyRSA.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/verifyRSA.ts
@@ -1,4 +1,4 @@
-import { webcrypto } from 'node:crypto';
+import WebCrypto from '@simplewebauthn/iso-webcrypto';
import { COSEALG, COSEKEYS, COSEPublicKeyRSA, isCOSEAlg } from "../../cose";
import { mapCoseAlgToWebCryptoAlg } from "./mapCoseAlgToWebCryptoAlg";
@@ -100,9 +100,5 @@ export async function verifyRSA(opts: {
algorithm: keyAlgorithm,
});
- if (globalThis.crypto) {
- return globalThis.crypto.subtle.verify(verifyAlgorithm, key, signature, data);
- } else {
- return webcrypto.subtle.verify(verifyAlgorithm, key, signature, data);
- }
+ return WebCrypto.subtle.verify(verifyAlgorithm, key, signature, data);
}