diff --git a/src/crypto.ts b/src/crypto.ts index c450213..2b558b3 100644 --- a/src/crypto.ts +++ b/src/crypto.ts @@ -6,7 +6,10 @@ export class Crypto extends core.Crypto { public subtle = new SubtleCrypto(); - public getRandomValues(array: T): T { + public getRandomValues(array: T): T { + if (!ArrayBuffer.isView(array)) { + throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'"); + } const buffer = Buffer.from(array.buffer); crypto.randomFillSync(buffer); return array; diff --git a/src/mechs/aes/aes_cmac.ts b/src/mechs/aes/aes_cmac.ts index e1afef7..7d3955a 100644 --- a/src/mechs/aes/aes_cmac.ts +++ b/src/mechs/aes/aes_cmac.ts @@ -125,12 +125,12 @@ export class AesCmacProvider extends core.AesCmacProvider { return setCryptoKey(key); } - public async onSign(algorithm: AesCmacParams, key: AesCryptoKey, data: ArrayBuffer): Promise { + public async onSign(algorithm: core.AesCmacParams, key: AesCryptoKey, data: ArrayBuffer): Promise { const result = aesCmac(getCryptoKey(key).data, Buffer.from(data)); return new Uint8Array(result).buffer; } - public async onVerify(algorithm: AesCmacParams, key: AesCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise { + public async onVerify(algorithm: core.AesCmacParams, key: AesCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise { const signature2 = await this.sign(algorithm, key, data); return Buffer.from(signature).compare(Buffer.from(signature2)) === 0; } diff --git a/src/mechs/ed/ecdh_es.ts b/src/mechs/ed/ecdh_es.ts index 7dcc2f0..1b117bc 100644 --- a/src/mechs/ed/ecdh_es.ts +++ b/src/mechs/ed/ecdh_es.ts @@ -5,7 +5,7 @@ import { EdCrypto } from "./crypto"; export class EcdhEsProvider extends core.EcdhEsProvider { - public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await EdCrypto.generateKey( { name: this.name, diff --git a/src/mechs/ed/eddsa.ts b/src/mechs/ed/eddsa.ts index 037bee4..bc1834f 100644 --- a/src/mechs/ed/eddsa.ts +++ b/src/mechs/ed/eddsa.ts @@ -7,7 +7,7 @@ import { EdPublicKey } from "./public_key"; export class EdDsaProvider extends core.EdDsaProvider { - public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await EdCrypto.generateKey( { name: this.name, @@ -21,19 +21,19 @@ export class EdDsaProvider extends core.EdDsaProvider { publicKey: setCryptoKey(keys.publicKey as CryptoKey), }; } - + public async onSign(algorithm: EcdsaParams, key: CryptoKey, data: ArrayBuffer): Promise { return EdCrypto.sign(algorithm, getCryptoKey(key) as EdPrivateKey, new Uint8Array(data)); } - + public async onVerify(algorithm: EcdsaParams, key: CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise { return EdCrypto.verify(algorithm, getCryptoKey(key) as EdPublicKey, new Uint8Array(signature), new Uint8Array(data)); } - + public async onExportKey(format: KeyFormat, key: CryptoKey): Promise { return EdCrypto.exportKey(format, getCryptoKey(key)); } - + public async onImportKey(format: KeyFormat, keyData: ArrayBuffer | JsonWebKey, algorithm: EcKeyImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); return setCryptoKey(key); diff --git a/src/mechs/rsa/crypto.ts b/src/mechs/rsa/crypto.ts index 806ad20..503ef3a 100644 --- a/src/mechs/rsa/crypto.ts +++ b/src/mechs/rsa/crypto.ts @@ -18,7 +18,7 @@ export class RsaCrypto { public static publicKeyUsages = ["verify", "encrypt", "wrapKey"]; public static privateKeyUsages = ["sign", "decrypt", "unwrapKey"]; - public static async generateKey(algorithm: RsaHashedKeyGenParams | RsaKeyGenParams, extractable: boolean, keyUsages: string[]): Promise { + public static async generateKey(algorithm: RsaHashedKeyGenParams | RsaKeyGenParams, extractable: boolean, keyUsages: string[]): Promise { const privateKey = new RsaPrivateKey(); privateKey.algorithm = algorithm as RsaHashedKeyAlgorithm; privateKey.extractable = extractable; @@ -50,7 +50,7 @@ export class RsaCrypto { privateKey.data = keys.privateKey; publicKey.data = keys.publicKey; - const res: CryptoKeyPair = { + const res = { privateKey, publicKey, }; diff --git a/src/mechs/rsa/rsa_es.ts b/src/mechs/rsa/rsa_es.ts index 47ed1e6..9b3c85e 100644 --- a/src/mechs/rsa/rsa_es.ts +++ b/src/mechs/rsa/rsa_es.ts @@ -14,7 +14,7 @@ export class RsaEsProvider extends core.ProviderCrypto { privateKey: ["decrypt", "unwrapKey"] as core.KeyUsages, }; - public async onGenerateKey(algorithm: RsaKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: RsaKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await RsaCrypto.generateKey( { ...algorithm, diff --git a/src/mechs/rsa/rsa_oaep.ts b/src/mechs/rsa/rsa_oaep.ts index bf06e8e..b838bdf 100644 --- a/src/mechs/rsa/rsa_oaep.ts +++ b/src/mechs/rsa/rsa_oaep.ts @@ -15,7 +15,7 @@ import { RsaPublicKey } from "./public_key"; export class RsaOaepProvider extends core.RsaOaepProvider { - public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await RsaCrypto.generateKey( { ...algorithm, diff --git a/src/mechs/rsa/rsa_pss.ts b/src/mechs/rsa/rsa_pss.ts index 059fceb..767b2d6 100644 --- a/src/mechs/rsa/rsa_pss.ts +++ b/src/mechs/rsa/rsa_pss.ts @@ -6,7 +6,7 @@ import { RsaPublicKey } from "./public_key"; export class RsaPssProvider extends core.RsaPssProvider { - public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await RsaCrypto.generateKey( { ...algorithm, diff --git a/src/mechs/rsa/rsa_ssa.ts b/src/mechs/rsa/rsa_ssa.ts index 7eca5f3..6ec5709 100644 --- a/src/mechs/rsa/rsa_ssa.ts +++ b/src/mechs/rsa/rsa_ssa.ts @@ -6,7 +6,7 @@ import { RsaPublicKey } from "./public_key"; export class RsaSsaProvider extends core.RsaSsaProvider { - public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { + public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise { const keys = await RsaCrypto.generateKey( { ...algorithm,