fix: Align types with webcrypto-core and TS
This commit is contained in:
parent
e768b168c5
commit
37dff397d5
|
@ -6,7 +6,10 @@ export class Crypto extends core.Crypto {
|
|||
|
||||
public subtle = new SubtleCrypto();
|
||||
|
||||
public getRandomValues<T extends ArrayBufferView>(array: T): T {
|
||||
public getRandomValues<T extends ArrayBufferView | null>(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;
|
||||
|
|
|
@ -125,12 +125,12 @@ export class AesCmacProvider extends core.AesCmacProvider {
|
|||
return setCryptoKey(key);
|
||||
}
|
||||
|
||||
public async onSign(algorithm: AesCmacParams, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
public async onSign(algorithm: core.AesCmacParams, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
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<boolean> {
|
||||
public async onVerify(algorithm: core.AesCmacParams, key: AesCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
|
||||
const signature2 = await this.sign(algorithm, key, data);
|
||||
return Buffer.from(signature).compare(Buffer.from(signature2)) === 0;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { EdCrypto } from "./crypto";
|
|||
|
||||
export class EcdhEsProvider extends core.EcdhEsProvider {
|
||||
|
||||
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
const keys = await EdCrypto.generateKey(
|
||||
{
|
||||
name: this.name,
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
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<ArrayBuffer> {
|
||||
return EdCrypto.sign(algorithm, getCryptoKey(key) as EdPrivateKey, new Uint8Array(data));
|
||||
}
|
||||
|
||||
|
||||
public async onVerify(algorithm: EcdsaParams, key: CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
|
||||
return EdCrypto.verify(algorithm, getCryptoKey(key) as EdPublicKey, new Uint8Array(signature), new Uint8Array(data));
|
||||
}
|
||||
|
||||
|
||||
public async onExportKey(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey> {
|
||||
return EdCrypto.exportKey(format, getCryptoKey(key));
|
||||
}
|
||||
|
||||
|
||||
public async onImportKey(format: KeyFormat, keyData: ArrayBuffer | JsonWebKey, algorithm: EcKeyImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKey> {
|
||||
const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
|
||||
return setCryptoKey(key);
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public static async generateKey(algorithm: RsaHashedKeyGenParams | RsaKeyGenParams, extractable: boolean, keyUsages: string[]): Promise<core.CryptoKeyPair> {
|
||||
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,
|
||||
};
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: RsaKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
const keys = await RsaCrypto.generateKey(
|
||||
{
|
||||
...algorithm,
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
const keys = await RsaCrypto.generateKey(
|
||||
{
|
||||
...algorithm,
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
const keys = await RsaCrypto.generateKey(
|
||||
{
|
||||
...algorithm,
|
||||
|
|
|
@ -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<CryptoKeyPair> {
|
||||
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
|
||||
const keys = await RsaCrypto.generateKey(
|
||||
{
|
||||
...algorithm,
|
||||
|
|
Reference in New Issue