update core types

This commit is contained in:
microshine 2022-05-24 00:09:47 +03:00
parent 1578e6ceeb
commit 188fa90116
63 changed files with 411 additions and 259 deletions

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
export abstract class AesProvider extends ProviderCrypto { export abstract class AesProvider extends ProviderCrypto {
@ -24,8 +24,8 @@ export abstract class AesProvider extends ProviderCrypto {
this.checkGenerateKeyParams(algorithm); this.checkGenerateKeyParams(algorithm);
} }
public abstract override onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onExportKey(format: types.KeyFormat, key: BaseCryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>; public abstract override onExportKey(format: types.KeyFormat, key: CryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>;
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
} }

View File

@ -2,9 +2,9 @@ import * as types from "@peculiar/webcrypto-types";
const KEY_TYPES = ["secret", "private", "public"]; const KEY_TYPES = ["secret", "private", "public"];
export class BaseCryptoKey implements types.CryptoKey { export class CryptoKey implements types.CryptoKey {
public static create<T extends BaseCryptoKey>(this: new () => T, algorithm: types.KeyAlgorithm, type: types.KeyType, extractable: boolean, usages: types.KeyUsages): T { public static create<T extends CryptoKey>(this: new () => T, algorithm: types.KeyAlgorithm, type: types.KeyType, extractable: boolean, usages: types.KeyUsages): T {
const key = new this(); const key = new this();
key.algorithm = algorithm; key.algorithm = algorithm;
key.type = type; key.type = type;
@ -18,10 +18,10 @@ export class BaseCryptoKey implements types.CryptoKey {
return KEY_TYPES.indexOf(data) !== -1; return KEY_TYPES.indexOf(data) !== -1;
} }
public algorithm!: types.KeyAlgorithm; public algorithm: types.KeyAlgorithm = { name: "" };
public type!: types.KeyType; public type: types.KeyType = "secret";
public usages!: types.KeyUsages; public usages: types.KeyUsages = [];
public extractable!: boolean; public extractable: boolean = false;
// @internal // @internal
public get [Symbol.toStringTag]() { public get [Symbol.toStringTag]() {

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { OperationError } from "../errors"; import { OperationError } from "../errors";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
import { BufferSource } from "pvtsutils"; import { BufferSource } from "pvtsutils";
@ -56,10 +56,10 @@ export abstract class DesProvider extends ProviderCrypto {
this.checkGenerateKeyParams(algorithm); this.checkGenerateKeyParams(algorithm);
} }
public abstract override onGenerateKey(algorithm: DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onGenerateKey(algorithm: DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onExportKey(format: types.KeyFormat, key: BaseCryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>; public abstract override onExportKey(format: types.KeyFormat, key: CryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>;
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: DesImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: DesImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onEncrypt(algorithm: DesParams, key: BaseCryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer>; public abstract override onEncrypt(algorithm: DesParams, key: CryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer>;
public abstract override onDecrypt(algorithm: DesParams, key: BaseCryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer>; public abstract override onDecrypt(algorithm: DesParams, key: CryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer>;
} }

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { OperationError } from "../errors"; import { OperationError } from "../errors";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
export abstract class EllipticProvider extends ProviderCrypto { export abstract class EllipticProvider extends ProviderCrypto {
@ -23,7 +23,7 @@ export abstract class EllipticProvider extends ProviderCrypto {
} }
public abstract override onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair>; public abstract override onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair>;
public abstract override onExportKey(format: types.KeyFormat, key: BaseCryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>; public abstract override onExportKey(format: types.KeyFormat, key: CryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>;
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
} }

View File

@ -1,5 +1,5 @@
import { AsnConvert } from "@peculiar/asn1-schema"; import { AsnConvert } from "@peculiar/asn1-schema";
import * as schema from "packages/core/src/schema"; import * as asn1 from "../schema/asn1";
export interface EcCurveParams { export interface EcCurveParams {
/** /**
@ -28,7 +28,7 @@ export class EcCurves {
private constructor() { } private constructor() { }
public static register(item: EcCurveParams) { public static register(item: EcCurveParams) {
const oid = new schema.ObjectIdentifier(); const oid = new asn1.ObjectIdentifier();
oid.value = item.id; oid.value = item.id;
const raw = AsnConvert.serialize(oid); const raw = AsnConvert.serialize(oid);
@ -61,21 +61,21 @@ export class EcCurves {
} }
EcCurves.register({ name: "P-256", id: schema.idSecp256r1, size: 256 }); EcCurves.register({ name: "P-256", id: asn1.idSecp256r1, size: 256 });
EcCurves.register({ name: "P-384", id: schema.idSecp384r1, size: 384 }); EcCurves.register({ name: "P-384", id: asn1.idSecp384r1, size: 384 });
EcCurves.register({ name: "P-521", id: schema.idSecp521r1, size: 521 }); EcCurves.register({ name: "P-521", id: asn1.idSecp521r1, size: 521 });
EcCurves.register({ name: "K-256", id: schema.idSecp256k1, size: 256 }); EcCurves.register({ name: "K-256", id: asn1.idSecp256k1, size: 256 });
EcCurves.register({ name: "brainpoolP160r1", id: schema.idBrainpoolP160r1, size: 160 }); EcCurves.register({ name: "brainpoolP160r1", id: asn1.idBrainpoolP160r1, size: 160 });
EcCurves.register({ name: "brainpoolP160t1", id: schema.idBrainpoolP160t1, size: 160 }); EcCurves.register({ name: "brainpoolP160t1", id: asn1.idBrainpoolP160t1, size: 160 });
EcCurves.register({ name: "brainpoolP192r1", id: schema.idBrainpoolP192r1, size: 192 }); EcCurves.register({ name: "brainpoolP192r1", id: asn1.idBrainpoolP192r1, size: 192 });
EcCurves.register({ name: "brainpoolP192t1", id: schema.idBrainpoolP192t1, size: 192 }); EcCurves.register({ name: "brainpoolP192t1", id: asn1.idBrainpoolP192t1, size: 192 });
EcCurves.register({ name: "brainpoolP224r1", id: schema.idBrainpoolP224r1, size: 224 }); EcCurves.register({ name: "brainpoolP224r1", id: asn1.idBrainpoolP224r1, size: 224 });
EcCurves.register({ name: "brainpoolP224t1", id: schema.idBrainpoolP224t1, size: 224 }); EcCurves.register({ name: "brainpoolP224t1", id: asn1.idBrainpoolP224t1, size: 224 });
EcCurves.register({ name: "brainpoolP256r1", id: schema.idBrainpoolP256r1, size: 256 }); EcCurves.register({ name: "brainpoolP256r1", id: asn1.idBrainpoolP256r1, size: 256 });
EcCurves.register({ name: "brainpoolP256t1", id: schema.idBrainpoolP256t1, size: 256 }); EcCurves.register({ name: "brainpoolP256t1", id: asn1.idBrainpoolP256t1, size: 256 });
EcCurves.register({ name: "brainpoolP320r1", id: schema.idBrainpoolP320r1, size: 320 }); EcCurves.register({ name: "brainpoolP320r1", id: asn1.idBrainpoolP320r1, size: 320 });
EcCurves.register({ name: "brainpoolP320t1", id: schema.idBrainpoolP320t1, size: 320 }); EcCurves.register({ name: "brainpoolP320t1", id: asn1.idBrainpoolP320t1, size: 320 });
EcCurves.register({ name: "brainpoolP384r1", id: schema.idBrainpoolP384r1, size: 384 }); EcCurves.register({ name: "brainpoolP384r1", id: asn1.idBrainpoolP384r1, size: 384 });
EcCurves.register({ name: "brainpoolP384t1", id: schema.idBrainpoolP384t1, size: 384 }); EcCurves.register({ name: "brainpoolP384t1", id: asn1.idBrainpoolP384t1, size: 384 });
EcCurves.register({ name: "brainpoolP512r1", id: schema.idBrainpoolP512r1, size: 512 }); EcCurves.register({ name: "brainpoolP512r1", id: asn1.idBrainpoolP512r1, size: 512 });
EcCurves.register({ name: "brainpoolP512t1", id: schema.idBrainpoolP512t1, size: 512 }); EcCurves.register({ name: "brainpoolP512t1", id: asn1.idBrainpoolP512t1, size: 512 });

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { OperationError } from "../errors"; import { OperationError } from "../errors";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { EllipticProvider } from "./base"; import { EllipticProvider } from "./base";
export abstract class EcdhProvider extends EllipticProvider { export abstract class EcdhProvider extends EllipticProvider {
@ -17,7 +17,7 @@ export abstract class EcdhProvider extends EllipticProvider {
public override checkAlgorithmParams(algorithm: types.EcdhKeyDeriveParams) { public override checkAlgorithmParams(algorithm: types.EcdhKeyDeriveParams) {
// public // public
this.checkRequiredProperty(algorithm, "public"); this.checkRequiredProperty(algorithm, "public");
if (!(algorithm.public instanceof BaseCryptoKey)) { if (!(algorithm.public instanceof CryptoKey)) {
throw new TypeError("public: Is not a CryptoKey"); throw new TypeError("public: Is not a CryptoKey");
} }
if (algorithm.public.type !== "public") { if (algorithm.public.type !== "public") {
@ -28,6 +28,6 @@ export abstract class EcdhProvider extends EllipticProvider {
} }
} }
public abstract override onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: BaseCryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>; public abstract override onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: CryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>;
} }

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { BufferSourceConverter } from "pvtsutils"; import { BufferSourceConverter } from "pvtsutils";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
export abstract class HkdfProvider extends ProviderCrypto { export abstract class HkdfProvider extends ProviderCrypto {
@ -35,7 +35,7 @@ export abstract class HkdfProvider extends ProviderCrypto {
} }
} }
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onDeriveBits(algorithm: types.HkdfParams, baseKey: BaseCryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>; public abstract override onDeriveBits(algorithm: types.HkdfParams, baseKey: CryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>;
} }

View File

@ -1,5 +1,5 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
export abstract class HmacProvider extends ProviderCrypto { export abstract class HmacProvider extends ProviderCrypto {
@ -49,8 +49,8 @@ export abstract class HmacProvider extends ProviderCrypto {
this.checkHashAlgorithm(algorithm.hash as types.Algorithm, this.hashAlgorithms); this.checkHashAlgorithm(algorithm.hash as types.Algorithm, this.hashAlgorithms);
} }
public abstract override onGenerateKey(algorithm: types.PreparedHashedAlgorithm<types.HmacKeyGenParams>, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onGenerateKey(algorithm: types.PreparedHashedAlgorithm<types.HmacKeyGenParams>, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onExportKey(format: types.KeyFormat, key: BaseCryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>; public abstract override onExportKey(format: types.KeyFormat, key: CryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>;
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
} }

View File

@ -1,5 +1,5 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
export abstract class Pbkdf2Provider extends ProviderCrypto { export abstract class Pbkdf2Provider extends ProviderCrypto {
@ -39,7 +39,7 @@ export abstract class Pbkdf2Provider extends ProviderCrypto {
} }
} }
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
public abstract override onDeriveBits(algorithm: types.Pbkdf2Params, baseKey: BaseCryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>; public abstract override onDeriveBits(algorithm: types.Pbkdf2Params, baseKey: CryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer>;
} }

View File

@ -1,6 +1,6 @@
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { Convert } from "pvtsutils"; import { Convert } from "pvtsutils";
import { BaseCryptoKey } from "../crypto_key"; import { CryptoKey } from "../crypto_key";
import { ProviderCrypto } from "../provider"; import { ProviderCrypto } from "../provider";
export abstract class RsaProvider extends ProviderCrypto { export abstract class RsaProvider extends ProviderCrypto {
@ -37,7 +37,7 @@ export abstract class RsaProvider extends ProviderCrypto {
} }
public abstract override onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair>; public abstract override onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair>;
public abstract override onExportKey(format: types.KeyFormat, key: BaseCryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>; public abstract override onExportKey(format: types.KeyFormat, key: CryptoKey, ...args: any[]): Promise<types.JsonWebKey | ArrayBuffer>;
public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<BaseCryptoKey>; public abstract override onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<CryptoKey>;
} }

View File

@ -1 +1,2 @@
export * from "./integer_without_paddings"; export * from "./integer_without_paddings";
export * from "./integer_converter";

View File

@ -11,4 +11,4 @@ export * from "./one_asymmetric_key";
export * from "./ed_private_key"; export * from "./ed_private_key";
export * from "./ed_public_key"; export * from "./ed_public_key";
export * from "./rfc8410"; export * from "./rfc8410";
export * as converters from "./converters"; export * from "./converters";

View File

@ -1,6 +1,7 @@
import { AsnIntegerConverter, AsnProp, AsnPropTypes } from "@peculiar/asn1-schema"; import { AsnIntegerConverter, AsnProp, AsnPropTypes, AsnType, AsnTypeTypes } from "@peculiar/asn1-schema";
import { JsonProp } from "@peculiar/json-schema"; import { JsonProp } from "@peculiar/json-schema";
import { AsnIntegerArrayBufferConverter, JsonBase64UrlArrayBufferConverter } from "../json/converters"; import { JsonBase64UrlArrayBufferConverter } from "../json/converters";
import { AsnIntegerArrayBufferConverter } from "./converters";
// RFC 3437 // RFC 3437
// https://tools.ietf.org/html/rfc3447#appendix-A.1.2 // https://tools.ietf.org/html/rfc3447#appendix-A.1.2
@ -18,6 +19,7 @@ import { AsnIntegerArrayBufferConverter, JsonBase64UrlArrayBufferConverter } fro
// otherPrimeInfos OtherPrimeInfos OPTIONAL // otherPrimeInfos OtherPrimeInfos OPTIONAL
// } // }
@AsnType({ type: AsnTypeTypes.Sequence })
export class RsaPrivateKey { export class RsaPrivateKey {
@AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerConverter }) @AsnProp({ type: AsnPropTypes.Integer, converter: AsnIntegerConverter })

View File

@ -1,6 +1,7 @@
import { AsnProp, AsnPropTypes } from "@peculiar/asn1-schema"; import { AsnProp, AsnPropTypes } from "@peculiar/asn1-schema";
import { JsonProp } from "@peculiar/json-schema"; import { JsonProp } from "@peculiar/json-schema";
import { JsonBase64UrlArrayBufferConverter, AsnIntegerArrayBufferConverter } from "../json/converters"; import { JsonBase64UrlArrayBufferConverter } from "../json/converters";
import { AsnIntegerArrayBufferConverter } from "./converters";
// RFC 3437 // RFC 3437
// https://tools.ietf.org/html/rfc3447#appendix-A.1.1 // https://tools.ietf.org/html/rfc3447#appendix-A.1.1

View File

@ -1,2 +1,2 @@
export * from "./asn1"; export * as asn1 from "./asn1";
export * from "./json"; export * as json from "./json";

View File

@ -1,2 +1 @@
export * from "./base64_url"; export * from "./base64_url";
export * from "./integer_converter";

View File

@ -3,7 +3,7 @@ import { BufferSource, BufferSourceConverter, Convert } from "pvtsutils";
import { AlgorithmError } from "./errors"; import { AlgorithmError } from "./errors";
import { ProviderCrypto } from "./provider"; import { ProviderCrypto } from "./provider";
import { ProviderStorage } from "./storage"; import { ProviderStorage } from "./storage";
import { BaseCryptoKey } from './crypto_key'; import { CryptoKey } from './crypto_key';
export class SubtleCrypto implements types.SubtleCrypto { export class SubtleCrypto implements types.SubtleCrypto {
@ -241,8 +241,8 @@ export class SubtleCrypto implements types.SubtleCrypto {
return provider; return provider;
} }
protected checkCryptoKey(key: types.CryptoKey): asserts key is BaseCryptoKey { protected checkCryptoKey(key: types.CryptoKey): asserts key is CryptoKey {
if (!(key instanceof BaseCryptoKey)) { if (!(key instanceof CryptoKey)) {
throw new TypeError(`Key is not of type 'CryptoKey'`); throw new TypeError(`Key is not of type 'CryptoKey'`);
} }
} }

View File

@ -7,19 +7,19 @@ class DesTestProvider extends core.DesProvider {
public ivSize = 8; public ivSize = 8;
public name = "DES-TEST"; public name = "DES-TEST";
public onGenerateKey(algorithm: import("../src/des").DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public onGenerateKey(algorithm: import("../src/des").DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey): Promise<types.JsonWebKey | ArrayBuffer> { public onExportKey(format: types.KeyFormat, key: core.CryptoKey): Promise<types.JsonWebKey | ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: import("../src/des").DesImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: import("../src/des").DesImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onEncrypt(algorithm: import("../src/des").DesParams, key: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public onEncrypt(algorithm: import("../src/des").DesParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onDecrypt(algorithm: import("../src/des").DesParams, key: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public onDecrypt(algorithm: import("../src/des").DesParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
} }

View File

@ -54,10 +54,10 @@ context("EC", () => {
public onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> { public onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey): Promise<types.JsonWebKey | ArrayBuffer> { public onExportKey(format: types.KeyFormat, key: core.CryptoKey): Promise<types.JsonWebKey | ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
} }
@ -115,7 +115,7 @@ context("EC", () => {
it("error if `public` is not public CryptoKey", () => { it("error if `public` is not public CryptoKey", () => {
assert.throws(() => { assert.throws(() => {
const key = new core.BaseCryptoKey(); const key = new core.CryptoKey();
key.type = "secret"; key.type = "secret";
provider.checkAlgorithmParams({ public: key } as any); provider.checkAlgorithmParams({ public: key } as any);
}, Error); }, Error);
@ -123,7 +123,7 @@ context("EC", () => {
it("error if `public` is wrong CryptoKey alg", () => { it("error if `public` is wrong CryptoKey alg", () => {
assert.throws(() => { assert.throws(() => {
const key = new core.BaseCryptoKey(); const key = new core.CryptoKey();
key.type = "public"; key.type = "public";
key.algorithm = { name: "ECDSA" }; key.algorithm = { name: "ECDSA" };
provider.checkAlgorithmParams({ public: key } as any); provider.checkAlgorithmParams({ public: key } as any);
@ -131,7 +131,7 @@ context("EC", () => {
}); });
it("correct `public`", () => { it("correct `public`", () => {
const key = new core.BaseCryptoKey(); const key = new core.CryptoKey();
key.type = "public"; key.type = "public";
key.algorithm = { name: "ECDH" }; key.algorithm = { name: "ECDH" };
provider.checkAlgorithmParams({ public: key } as any); provider.checkAlgorithmParams({ public: key } as any);
@ -171,16 +171,16 @@ context("EC", () => {
context("ECDH-ES", () => { context("ECDH-ES", () => {
class TestEcdhEsProvider extends core.EcdhEsProvider { class TestEcdhEsProvider extends core.EcdhEsProvider {
public async onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: core.BaseCryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer> { public async onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: core.CryptoKey, length: number, ...args: any[]): Promise<ArrayBuffer> {
return null as any; return null as any;
} }
public async onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair> { public async onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair> {
return null as any; return null as any;
} }
public async onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey, ...args: any[]): Promise<ArrayBuffer | types.JsonWebKey> { public async onExportKey(format: types.KeyFormat, key: core.CryptoKey, ...args: any[]): Promise<ArrayBuffer | types.JsonWebKey> {
return null as any; return null as any;
} }
public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.CryptoKey> {
return null as any; return null as any;
} }
} }
@ -199,19 +199,19 @@ context("EC", () => {
context("EdDSA", () => { context("EdDSA", () => {
class TestEdDsaProvider extends core.EdDsaProvider { class TestEdDsaProvider extends core.EdDsaProvider {
public async onSign(algorithm: types.EcdsaParams, key: core.BaseCryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer> { public async onSign(algorithm: types.EcdsaParams, key: core.CryptoKey, data: ArrayBuffer, ...args: any[]): Promise<ArrayBuffer> {
return null as any; return null as any;
} }
public async onVerify(algorithm: types.EcdsaParams, key: core.BaseCryptoKey, signature: ArrayBuffer, data: ArrayBuffer, ...args: any[]): Promise<boolean> { public async onVerify(algorithm: types.EcdsaParams, key: core.CryptoKey, signature: ArrayBuffer, data: ArrayBuffer, ...args: any[]): Promise<boolean> {
return true; return true;
} }
public async onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair> { public async onGenerateKey(algorithm: types.EcKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<types.CryptoKeyPair> {
return null as any; return null as any;
} }
public onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey, ...args: any[]): Promise<ArrayBuffer | types.JsonWebKey> { public onExportKey(format: types.KeyFormat, key: core.CryptoKey, ...args: any[]): Promise<ArrayBuffer | types.JsonWebKey> {
return null as any; return null as any;
} }
public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.BaseCryptoKey> { public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.CryptoKey> {
return null as any; return null as any;
} }
} }

View File

@ -1,7 +1,7 @@
import { AsnConvert, AsnSerializer } from "@peculiar/asn1-schema"; import { AsnConvert, AsnSerializer } from "@peculiar/asn1-schema";
import * as assert from "assert"; import * as assert from "assert";
import { Convert } from "pvtsutils"; import { Convert } from "pvtsutils";
import * as schema from "packages/core/src/schema"; import * as asn1 from "../src/schema/asn1";
context("ED", () => { context("ED", () => {
@ -10,11 +10,11 @@ context("ED", () => {
it("spki - jwk", () => { it("spki - jwk", () => {
const pem = "MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE="; const pem = "MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=";
const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), schema.PublicKeyInfo); const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), asn1.PublicKeyInfo);
const key = new schema.EdPublicKey(keyInfo.publicKey); const key = new asn1.EdPublicKey(keyInfo.publicKey);
const jwk = key.toJSON(); const jwk = key.toJSON();
const key2 = new schema.EdPublicKey(); const key2 = new asn1.EdPublicKey();
key2.fromJSON(jwk); key2.fromJSON(jwk);
assert.strictEqual( assert.strictEqual(
Convert.ToBase64(AsnSerializer.serialize(key2)), Convert.ToBase64(AsnSerializer.serialize(key2)),
@ -27,12 +27,12 @@ context("ED", () => {
it("without public key", () => { it("without public key", () => {
const pem = "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC"; const pem = "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC";
const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), schema.OneAsymmetricKey); const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), asn1.OneAsymmetricKey);
assert.strictEqual(keyInfo.publicKey, undefined); assert.strictEqual(keyInfo.publicKey, undefined);
const key = AsnConvert.parse(keyInfo.privateKey, schema.EdPrivateKey); const key = AsnConvert.parse(keyInfo.privateKey, asn1.EdPrivateKey);
const jwk = key.toJSON(); const jwk = key.toJSON();
const key2 = new schema.EdPrivateKey(); const key2 = new asn1.EdPrivateKey();
key2.fromJSON(jwk); key2.fromJSON(jwk);
assert.strictEqual( assert.strictEqual(
Convert.ToBase64(AsnSerializer.serialize(key2)), Convert.ToBase64(AsnSerializer.serialize(key2)),
@ -43,12 +43,12 @@ context("ED", () => {
it("with public key", () => { it("with public key", () => {
const pem = "MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhCoB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE="; const pem = "MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhCoB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=";
const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), schema.OneAsymmetricKey); const keyInfo = AsnConvert.parse(Convert.FromBase64(pem), asn1.OneAsymmetricKey);
assert.ok(keyInfo.publicKey); assert.ok(keyInfo.publicKey);
const key = AsnConvert.parse(keyInfo.privateKey, schema.EdPrivateKey); const key = AsnConvert.parse(keyInfo.privateKey, asn1.EdPrivateKey);
const jwk = key.toJSON(); const jwk = key.toJSON();
const key2 = new schema.EdPrivateKey(); const key2 = new asn1.EdPrivateKey();
key2.fromJSON(jwk); key2.fromJSON(jwk);
assert.strictEqual( assert.strictEqual(
Convert.ToBase64(AsnSerializer.serialize(key2)), Convert.ToBase64(AsnSerializer.serialize(key2)),

View File

@ -5,10 +5,10 @@ context("CryptoKey", () => {
context("isKeyType", () => { context("isKeyType", () => {
it("correct key type", () => { it("correct key type", () => {
assert.equal(core.BaseCryptoKey.isKeyType("secret"), true); assert.equal(core.CryptoKey.isKeyType("secret"), true);
}); });
it("incorrect key type", () => { it("incorrect key type", () => {
assert.equal(core.BaseCryptoKey.isKeyType("Secret"), false); assert.equal(core.CryptoKey.isKeyType("Secret"), false);
}); });
}); });

View File

@ -76,7 +76,7 @@ context("ProviderCrypto", () => {
context("sign", () => { context("sign", () => {
const correctKey = core.BaseCryptoKey.create( const correctKey = core.CryptoKey.create(
{ name: "custom-alg" }, { name: "custom-alg" },
"secret", "secret",
false, false,
@ -108,7 +108,7 @@ context("ProviderCrypto", () => {
await assert.rejects( await assert.rejects(
crypto.sign( crypto.sign(
{ name: "custom-alg" }, { name: "custom-alg" },
{} as core.BaseCryptoKey, {} as core.CryptoKey,
new ArrayBuffer(0), new ArrayBuffer(0),
), ),
TypeError, TypeError,
@ -119,7 +119,7 @@ context("ProviderCrypto", () => {
await assert.rejects( await assert.rejects(
crypto.sign( crypto.sign(
{ name: "custom-alg" }, { name: "custom-alg" },
core.BaseCryptoKey.create( core.CryptoKey.create(
{ name: "wrong" }, { name: "wrong" },
"secret", "secret",
true, true,
@ -135,7 +135,7 @@ context("ProviderCrypto", () => {
await assert.rejects( await assert.rejects(
crypto.sign( crypto.sign(
{ name: "custom-alg" }, { name: "custom-alg" },
core.BaseCryptoKey.create( core.CryptoKey.create(
{ name: "custom-alg" }, { name: "custom-alg" },
"secret", "secret",
true, true,
@ -153,7 +153,7 @@ context("ProviderCrypto", () => {
it("error if length is not multiple 8", () => { it("error if length is not multiple 8", () => {
const algorithm: types.Algorithm = { name: "custom-alg" }; const algorithm: types.Algorithm = { name: "custom-alg" };
const key = core.BaseCryptoKey.create(algorithm, "secret", false, ["deriveBits"]); const key = core.CryptoKey.create(algorithm, "secret", false, ["deriveBits"]);
assert.throws(() => { assert.throws(() => {
crypto.checkDeriveBits(algorithm, key, 7); crypto.checkDeriveBits(algorithm, key, 7);
}, core.OperationError); }, core.OperationError);

View File

@ -22,17 +22,17 @@ context("ASN1", () => {
}; };
it("parse", () => { it("parse", () => {
const keyInfo = AsnParser.parse(bytes, core.PrivateKeyInfo); const keyInfo = AsnParser.parse(bytes, core.asn1.PrivateKeyInfo);
const key = AsnParser.parse(keyInfo.privateKey, core.RsaPrivateKey); const key = AsnParser.parse(keyInfo.privateKey, core.asn1.RsaPrivateKey);
const jsonKey = JsonSerializer.toJSON(key); const jsonKey = JsonSerializer.toJSON(key);
assert.deepEqual(jsonKey, json); assert.deepEqual(jsonKey, json);
}); });
it("serialize", () => { it("serialize", () => {
const key = JsonParser.fromJSON(json, { targetSchema: core.RsaPrivateKey }); const key = JsonParser.fromJSON(json, { targetSchema: core.asn1.RsaPrivateKey });
const keyInfo = new core.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.privateKeyAlgorithm.parameters = null; keyInfo.privateKeyAlgorithm.parameters = null;
keyInfo.privateKey = AsnSerializer.serialize(key); keyInfo.privateKey = AsnSerializer.serialize(key);
@ -52,17 +52,17 @@ context("ASN1", () => {
}; };
it("parse", () => { it("parse", () => {
const keyInfo = AsnParser.parse(bytes, core.PublicKeyInfo); const keyInfo = AsnParser.parse(bytes, core.asn1.PublicKeyInfo);
const key = AsnParser.parse(keyInfo.publicKey, core.RsaPublicKey); const key = AsnParser.parse(keyInfo.publicKey, core.asn1.RsaPublicKey);
const jsonKey = JsonSerializer.toJSON(key); const jsonKey = JsonSerializer.toJSON(key);
assert.deepEqual(jsonKey, json); assert.deepEqual(jsonKey, json);
}); });
it("serialize", () => { it("serialize", () => {
const key = JsonParser.fromJSON(json, { targetSchema: core.RsaPublicKey }); const key = JsonParser.fromJSON(json, { targetSchema: core.asn1.RsaPublicKey });
const keyInfo = new core.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.publicKeyAlgorithm.parameters = null; keyInfo.publicKeyAlgorithm.parameters = null;
keyInfo.publicKey = AsnSerializer.serialize(key); keyInfo.publicKey = AsnSerializer.serialize(key);
@ -87,20 +87,20 @@ context("ASN1", () => {
}; };
it("parse", () => { it("parse", () => {
const keyInfo = AsnParser.parse(bytes, core.PrivateKeyInfo); const keyInfo = AsnParser.parse(bytes, core.asn1.PrivateKeyInfo);
const key = AsnParser.parse(keyInfo.privateKey, core.EcPrivateKey); const key = AsnParser.parse(keyInfo.privateKey, core.asn1.EcPrivateKey);
const jsonKey = JsonSerializer.toJSON(key); const jsonKey = JsonSerializer.toJSON(key);
assert.deepEqual(jsonKey, json); assert.deepEqual(jsonKey, json);
}); });
it("serialize", () => { it("serialize", () => {
const keyInfo = new core.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize( keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(
new core.ObjectIdentifier("1.2.840.10045.3.1.7"), new core.asn1.ObjectIdentifier("1.2.840.10045.3.1.7"),
); );
const key = JsonParser.fromJSON(json, { targetSchema: core.EcPrivateKey }); const key = JsonParser.fromJSON(json, { targetSchema: core.asn1.EcPrivateKey });
keyInfo.privateKey = AsnSerializer.serialize(key); keyInfo.privateKey = AsnSerializer.serialize(key);
const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo)); const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo));

View File

@ -1,7 +1,7 @@
import * as assert from "assert"; import * as assert from "assert";
import { Convert } from "pvtsutils"; import { Convert } from "pvtsutils";
import { AsnSerializer, AsnParser } from "@peculiar/asn1-schema"; import { AsnSerializer, AsnParser } from "@peculiar/asn1-schema";
import { EcDsaSignature } from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
interface IEcSignatureTestVector { interface IEcSignatureTestVector {
name: string; name: string;
@ -49,7 +49,7 @@ context("ASN1", () => {
context("From WebCrypto to DER", () => { context("From WebCrypto to DER", () => {
vectors.forEach((vector) => { vectors.forEach((vector) => {
it(vector.name, () => { it(vector.name, () => {
const value = EcDsaSignature.fromWebCryptoSignature(Convert.FromHex(vector.webCrypto)); const value = core.asn1.EcDsaSignature.fromWebCryptoSignature(Convert.FromHex(vector.webCrypto));
const der = AsnSerializer.serialize(value); const der = AsnSerializer.serialize(value);
assert.strictEqual(Convert.ToHex(der), vector.asn1); assert.strictEqual(Convert.ToHex(der), vector.asn1);
}); });
@ -59,7 +59,7 @@ context("ASN1", () => {
context("From DER to WebCrypto", () => { context("From DER to WebCrypto", () => {
vectors.forEach((vector) => { vectors.forEach((vector) => {
it(vector.name, () => { it(vector.name, () => {
const value = AsnParser.parse(Convert.FromHex(vector.asn1), EcDsaSignature); const value = AsnParser.parse(Convert.FromHex(vector.asn1), core.asn1.EcDsaSignature);
const signature = value.toWebCryptoSignature(); const signature = value.toWebCryptoSignature();
assert.strictEqual(Convert.ToHex(signature), vector.webCrypto); assert.strictEqual(Convert.ToHex(signature), vector.webCrypto);
}); });

View File

@ -1,7 +1,7 @@
import * as assert from "assert"; import * as assert from "assert";
import { AsnConvert } from "@peculiar/asn1-schema"; import { AsnConvert } from "@peculiar/asn1-schema";
import { JsonSerializer } from "@peculiar/json-schema"; import { JsonSerializer } from "@peculiar/json-schema";
import { CurvePrivateKey, idX25519, idX448, PrivateKeyInfo, PublicKeyInfo } from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
import { Convert } from "pvtsutils"; import { Convert } from "pvtsutils";
context("EdDSA and ECDH-ES keys", () => { context("EdDSA and ECDH-ES keys", () => {
@ -10,9 +10,9 @@ context("EdDSA and ECDH-ES keys", () => {
const b64 = "MEYCAQAwBQYDK2VvBDoEOPhm20uZC//c0wk1EEapNDcIIlgSGVxnWhwRJvT5K3+iwjtcyV2inuEihA5Soa5BO2OHh5leznW+"; const b64 = "MEYCAQAwBQYDK2VvBDoEOPhm20uZC//c0wk1EEapNDcIIlgSGVxnWhwRJvT5K3+iwjtcyV2inuEihA5Soa5BO2OHh5leznW+";
const raw = Buffer.from(b64, "base64"); const raw = Buffer.from(b64, "base64");
const pki = AsnConvert.parse(raw, PrivateKeyInfo); const pki = AsnConvert.parse(raw, core.asn1.PrivateKeyInfo);
assert.strictEqual(pki.privateKeyAlgorithm.algorithm, idX448); assert.strictEqual(pki.privateKeyAlgorithm.algorithm, core.asn1.idX448);
const privateKey = AsnConvert.parse(pki.privateKey, CurvePrivateKey); const privateKey = AsnConvert.parse(pki.privateKey, core.asn1.CurvePrivateKey);
assert.deepStrictEqual(JsonSerializer.toJSON(privateKey), { d: "-GbbS5kL_9zTCTUQRqk0NwgiWBIZXGdaHBEm9Pkrf6LCO1zJXaKe4SKEDlKhrkE7Y4eHmV7Odb4" }); assert.deepStrictEqual(JsonSerializer.toJSON(privateKey), { d: "-GbbS5kL_9zTCTUQRqk0NwgiWBIZXGdaHBEm9Pkrf6LCO1zJXaKe4SKEDlKhrkE7Y4eHmV7Odb4" });
}); });
@ -21,8 +21,8 @@ context("EdDSA and ECDH-ES keys", () => {
const b64 = "MCowBQYDK2VuAyEAR-a_Z6rz2HuBXn7m7v_pjef6nHfCWSIObVWCTr5nxjg"; const b64 = "MCowBQYDK2VuAyEAR-a_Z6rz2HuBXn7m7v_pjef6nHfCWSIObVWCTr5nxjg";
const raw = Convert.FromBase64Url(b64); const raw = Convert.FromBase64Url(b64);
const spki = AsnConvert.parse(raw, PublicKeyInfo); const spki = AsnConvert.parse(raw, core.asn1.PublicKeyInfo);
assert.strictEqual(spki.publicKeyAlgorithm.algorithm, idX25519); assert.strictEqual(spki.publicKeyAlgorithm.algorithm, core.asn1.idX25519);
assert.strictEqual(Convert.ToBase64Url(spki.publicKey), "R-a_Z6rz2HuBXn7m7v_pjef6nHfCWSIObVWCTr5nxjg"); assert.strictEqual(Convert.ToBase64Url(spki.publicKey), "R-a_Z6rz2HuBXn7m7v_pjef6nHfCWSIObVWCTr5nxjg");
}); });

View File

@ -5,37 +5,37 @@ import * as assert from "assert";
// tslint:disable:max-classes-per-file // tslint:disable:max-classes-per-file
class RsaSsaProvider extends core.RsaSsaProvider { class RsaSsaProvider extends core.RsaSsaProvider {
public onSign(algorithm: core.RsaSsaParams, key: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public onSign(algorithm: core.RsaSsaParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onVerify(algorithm: core.RsaSsaParams, key: core.BaseCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> { public onVerify(algorithm: core.RsaSsaParams, key: core.CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> { public onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey): Promise<ArrayBuffer | types.JsonWebKey> { public onExportKey(format: types.KeyFormat, key: core.CryptoKey): Promise<ArrayBuffer | types.JsonWebKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
} }
class RsaOaepProvider extends core.RsaOaepProvider { class RsaOaepProvider extends core.RsaOaepProvider {
public onEncrypt(algorithm: types.RsaOaepParams, key: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public onEncrypt(algorithm: types.RsaOaepParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onDecrypt(algorithm: types.RsaOaepParams, key: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public onDecrypt(algorithm: types.RsaOaepParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> { public onGenerateKey(algorithm: types.RsaHashedKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<types.CryptoKeyPair> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onExportKey(format: types.KeyFormat, key: core.BaseCryptoKey): Promise<ArrayBuffer | types.JsonWebKey> { public onExportKey(format: types.KeyFormat, key: core.CryptoKey): Promise<ArrayBuffer | types.JsonWebKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
} }

View File

@ -12,35 +12,35 @@ context("SubtleCrypto", () => {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onGenerateKey(algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public override async onGenerateKey(algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
return key; return key;
} }
public override async onSign(algorithm: types.Algorithm, sKey: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public override async onSign(algorithm: types.Algorithm, sKey: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onVerify(algorithm: types.Algorithm, sKey: core.BaseCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> { public override async onVerify(algorithm: types.Algorithm, sKey: core.CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
return true; return true;
} }
public override async onEncrypt(algorithm: types.Algorithm, sKey: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public override async onEncrypt(algorithm: types.Algorithm, sKey: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onDecrypt(algorithm: types.Algorithm, sKey: core.BaseCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> { public override async onDecrypt(algorithm: types.Algorithm, sKey: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onDeriveBits(algorithm: types.Algorithm, sKey: core.BaseCryptoKey, length: number): Promise<ArrayBuffer> { public override async onDeriveBits(algorithm: types.Algorithm, sKey: core.CryptoKey, length: number): Promise<ArrayBuffer> {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onExportKey(format: types.KeyFormat, sKey: core.BaseCryptoKey): Promise<types.JsonWebKey | ArrayBuffer> { public override async onExportKey(format: types.KeyFormat, sKey: core.CryptoKey): Promise<types.JsonWebKey | ArrayBuffer> {
return new ArrayBuffer(0); return new ArrayBuffer(0);
} }
public override async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public override async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
return key; return key;
} }
@ -56,7 +56,7 @@ context("SubtleCrypto", () => {
} }
const subtle = new TestSubtleCrypto(); const subtle = new TestSubtleCrypto();
const key = new core.BaseCryptoKey(); const key = new core.CryptoKey();
key.algorithm = { name: "TEST" }; key.algorithm = { name: "TEST" };
key.type = "secret", key.type = "secret",
key.usages = ["sign", "verify", "deriveKey", "deriveBits", "encrypt", "decrypt", "wrapKey", "unwrapKey"]; key.usages = ["sign", "verify", "deriveKey", "deriveBits", "encrypt", "decrypt", "wrapKey", "unwrapKey"];

View File

@ -1,2 +1,2 @@
export { BaseCryptoKey as CryptoKey } from "@peculiar/webcrypto-core"; export { CryptoKey as CryptoKey } from "@peculiar/webcrypto-core";
export { Crypto } from "./crypto"; export { Crypto } from "./crypto";

View File

@ -2,7 +2,7 @@ import { JsonProp, JsonPropTypes } from "@peculiar/json-schema";
import * as core from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
export class CryptoKey extends core.BaseCryptoKey { export class CryptoKey extends core.CryptoKey {
public data: Buffer = Buffer.alloc(0); public data: Buffer = Buffer.alloc(0);
public override algorithm: types.KeyAlgorithm = { name: "" }; public override algorithm: types.KeyAlgorithm = { name: "" };

View File

@ -6,7 +6,7 @@ import { AesCryptoKey } from "./key";
export class AesCbcProvider extends core.AesCbcProvider { export class AesCbcProvider extends core.AesCbcProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.generateKey( const key = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -30,12 +30,12 @@ export class AesCbcProvider extends core.AesCbcProvider {
return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey); return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const key = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -114,7 +114,7 @@ function aesCmac(key: Buffer, message: Buffer) {
export class AesCmacProvider extends core.AesCmacProvider { export class AesCmacProvider extends core.AesCmacProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.generateKey( const key = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -141,12 +141,12 @@ export class AesCmacProvider extends core.AesCmacProvider {
} }
public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.CryptoKey> {
const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(res); return setCryptoKey(res);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -6,7 +6,7 @@ import { AesCryptoKey } from "./key";
export class AesCtrProvider extends core.AesCtrProvider { export class AesCtrProvider extends core.AesCtrProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.generateKey( const key = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -30,12 +30,12 @@ export class AesCtrProvider extends core.AesCtrProvider {
return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey); return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[], ...args: any[]): Promise<core.CryptoKey> {
const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(res); return setCryptoKey(res);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -6,7 +6,7 @@ import { AesCryptoKey } from "./key";
export class AesEcbProvider extends core.AesEcbProvider { export class AesEcbProvider extends core.AesEcbProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.generateKey( const key = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -30,12 +30,12 @@ export class AesEcbProvider extends core.AesEcbProvider {
return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey); return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(res); return setCryptoKey(res);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -6,7 +6,7 @@ import { AesCryptoKey } from "./key";
export class AesGcmProvider extends core.AesGcmProvider { export class AesGcmProvider extends core.AesGcmProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await AesCrypto.generateKey( const key = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -30,12 +30,12 @@ export class AesGcmProvider extends core.AesGcmProvider {
return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey); return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(res); return setCryptoKey(res);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -6,7 +6,7 @@ import { AesCryptoKey } from "./key";
export class AesKwProvider extends core.AesKwProvider { export class AesKwProvider extends core.AesKwProvider {
public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.AesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const res = await AesCrypto.generateKey( const res = await AesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -22,7 +22,7 @@ export class AesKwProvider extends core.AesKwProvider {
return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey); return AesCrypto.exportKey(format, getCryptoKey(key) as AesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages); const res = await AesCrypto.importKey(format, keyData, { name: algorithm.name }, extractable, keyUsages);
return setCryptoKey(res); return setCryptoKey(res);
} }
@ -35,7 +35,7 @@ export class AesKwProvider extends core.AesKwProvider {
return AesCrypto.decrypt(algorithm, getCryptoKey(key) as AesCryptoKey, new Uint8Array(data)); return AesCrypto.decrypt(algorithm, getCryptoKey(key) as AesCryptoKey, new Uint8Array(data));
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) { if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey"); throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -13,7 +13,7 @@ export class DesCbcProvider extends core.DesProvider {
public ivSize = 8; public ivSize = 8;
public name = "DES-CBC"; public name = "DES-CBC";
public async onGenerateKey(algorithm: core.DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: core.DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await DesCrypto.generateKey( const key = await DesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -37,7 +37,7 @@ export class DesCbcProvider extends core.DesProvider {
return DesCrypto.exportKey(format, getCryptoKey(key) as DesCryptoKey); return DesCrypto.exportKey(format, getCryptoKey(key) as DesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages); const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages);
if (key.data.length !== (this.keySizeBits >> 3)) { if (key.data.length !== (this.keySizeBits >> 3)) {
throw new core.OperationError("keyData: Wrong key size"); throw new core.OperationError("keyData: Wrong key size");

View File

@ -13,7 +13,7 @@ export class DesEde3CbcProvider extends core.DesProvider {
public ivSize = 8; public ivSize = 8;
public name = "DES-EDE3-CBC"; public name = "DES-EDE3-CBC";
public async onGenerateKey(algorithm: core.DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: core.DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await DesCrypto.generateKey( const key = await DesCrypto.generateKey(
{ {
name: this.name, name: this.name,
@ -37,7 +37,7 @@ export class DesEde3CbcProvider extends core.DesProvider {
return DesCrypto.exportKey(format, getCryptoKey(key) as DesCryptoKey); return DesCrypto.exportKey(format, getCryptoKey(key) as DesCryptoKey);
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages); const key = await DesCrypto.importKey(format, keyData, { name: this.name, length: this.keySizeBits }, extractable, keyUsages);
if (key.data.length !== (this.keySizeBits >> 3)) { if (key.data.length !== (this.keySizeBits >> 3)) {
throw new core.OperationError("keyData: Wrong key size"); throw new core.OperationError("keyData: Wrong key size");

View File

@ -1,7 +1,6 @@
import { AsnParser, AsnSerializer } from "@peculiar/asn1-schema"; import { AsnParser, AsnSerializer } from "@peculiar/asn1-schema";
import { JsonParser, JsonSerializer } from "@peculiar/json-schema"; import { JsonParser, JsonSerializer } from "@peculiar/json-schema";
import * as core from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
import * as schema from "packages/core/src/schema";
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import * as crypto from "crypto"; import * as crypto from "crypto";
import { BufferSourceConverter } from "pvtsutils"; import { BufferSourceConverter } from "pvtsutils";
@ -63,7 +62,7 @@ export class EcCrypto {
}; };
const signature = signer.sign(options); const signature = signer.sign(options);
const ecSignature = AsnParser.parse(signature, schema.EcDsaSignature); const ecSignature = AsnParser.parse(signature, core.asn1.EcDsaSignature);
const signatureRaw = core.EcUtils.encodeSignature(ecSignature, core.EcCurves.get(key.algorithm.namedCurve).size); const signatureRaw = core.EcUtils.encodeSignature(ecSignature, core.EcCurves.get(key.algorithm.namedCurve).size);
@ -82,7 +81,7 @@ export class EcCrypto {
key: key.pem, key: key.pem,
}; };
const ecSignature = new schema.EcDsaSignature(); const ecSignature = new core.asn1.EcDsaSignature();
const namedCurve = core.EcCurves.get(key.algorithm.namedCurve); const namedCurve = core.EcCurves.get(key.algorithm.namedCurve);
const signaturePoint = core.EcUtils.decodeSignature(signature, namedCurve.size); const signaturePoint = core.EcUtils.decodeSignature(signature, namedCurve.size);
ecSignature.r = BufferSourceConverter.toArrayBuffer(signaturePoint.r); ecSignature.r = BufferSourceConverter.toArrayBuffer(signaturePoint.r);
@ -97,11 +96,11 @@ export class EcCrypto {
const cryptoAlg = this.getOpenSSLNamedCurve((baseKey.algorithm as types.EcKeyAlgorithm).namedCurve); const cryptoAlg = this.getOpenSSLNamedCurve((baseKey.algorithm as types.EcKeyAlgorithm).namedCurve);
const ecdh = crypto.createECDH(cryptoAlg); const ecdh = crypto.createECDH(cryptoAlg);
const asnPrivateKey = AsnParser.parse(baseKey.data, schema.PrivateKeyInfo); const asnPrivateKey = AsnParser.parse(baseKey.data, core.asn1.PrivateKeyInfo);
const asnEcPrivateKey = AsnParser.parse(asnPrivateKey.privateKey, schema.EcPrivateKey); const asnEcPrivateKey = AsnParser.parse(asnPrivateKey.privateKey, core.asn1.EcPrivateKey);
ecdh.setPrivateKey(Buffer.from(asnEcPrivateKey.privateKey)); ecdh.setPrivateKey(Buffer.from(asnEcPrivateKey.privateKey));
const asnPublicKey = AsnParser.parse((algorithm.public as CryptoKey).data, schema.PublicKeyInfo); const asnPublicKey = AsnParser.parse((algorithm.public as CryptoKey).data, core.asn1.PublicKeyInfo);
const bits = ecdh.computeSecret(Buffer.from(asnPublicKey.publicKey)); const bits = ecdh.computeSecret(Buffer.from(asnPublicKey.publicKey));
return new Uint8Array(bits).buffer.slice(0, length >> 3); return new Uint8Array(bits).buffer.slice(0, length >> 3);
@ -115,7 +114,7 @@ export class EcCrypto {
case "spki": case "spki":
return new Uint8Array(key.data).buffer; return new Uint8Array(key.data).buffer;
case "raw": { case "raw": {
const publicKeyInfo = AsnParser.parse(key.data, schema.PublicKeyInfo); const publicKeyInfo = AsnParser.parse(key.data, core.asn1.PublicKeyInfo);
return publicKeyInfo.publicKey; return publicKeyInfo.publicKey;
} }
default: default:
@ -128,26 +127,26 @@ export class EcCrypto {
case "jwk": { case "jwk": {
const jwk = keyData as types.JsonWebKey; const jwk = keyData as types.JsonWebKey;
if (jwk.d) { if (jwk.d) {
const asnKey = JsonParser.fromJSON(keyData, { targetSchema: schema.EcPrivateKey }); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: core.asn1.EcPrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else { } else {
const asnKey = JsonParser.fromJSON(keyData, { targetSchema: schema.EcPublicKey }); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: core.asn1.EcPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
} }
case "raw": { case "raw": {
const asnKey = new schema.EcPublicKey(keyData as ArrayBuffer); const asnKey = new core.asn1.EcPublicKey(keyData as ArrayBuffer);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
case "spki": { case "spki": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), schema.PublicKeyInfo); const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PublicKeyInfo);
const asnKey = new schema.EcPublicKey(keyInfo.publicKey); const asnKey = new core.asn1.EcPublicKey(keyInfo.publicKey);
this.assertKeyParameters(keyInfo.publicKeyAlgorithm.parameters, algorithm.namedCurve); this.assertKeyParameters(keyInfo.publicKeyAlgorithm.parameters, algorithm.namedCurve);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
case "pkcs8": { case "pkcs8": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), schema.PrivateKeyInfo); const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PrivateKeyInfo);
const asnKey = AsnParser.parse(keyInfo.privateKey, schema.EcPrivateKey); const asnKey = AsnParser.parse(keyInfo.privateKey, core.asn1.EcPrivateKey);
this.assertKeyParameters(keyInfo.privateKeyAlgorithm.parameters, algorithm.namedCurve); this.assertKeyParameters(keyInfo.privateKeyAlgorithm.parameters, algorithm.namedCurve);
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} }
@ -163,7 +162,7 @@ export class EcCrypto {
let namedCurveIdentifier = ""; let namedCurveIdentifier = "";
try { try {
namedCurveIdentifier = AsnParser.parse(parameters, schema.ObjectIdentifier).value; namedCurveIdentifier = AsnParser.parse(parameters, core.asn1.ObjectIdentifier).value;
} catch (e) { } catch (e) {
throw new core.CryptoError("Cannot read key info parameters"); throw new core.CryptoError("Cannot read key info parameters");
} }
@ -173,10 +172,10 @@ export class EcCrypto {
} }
} }
protected static async importPrivateKey(asnKey: schema.EcPrivateKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) { protected static async importPrivateKey(asnKey: core.asn1.EcPrivateKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) {
const keyInfo = new schema.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(new schema.ObjectIdentifier(getOidByNamedCurve(algorithm.namedCurve))); keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(new core.asn1.ObjectIdentifier(getOidByNamedCurve(algorithm.namedCurve)));
keyInfo.privateKey = AsnSerializer.serialize(asnKey); keyInfo.privateKey = AsnSerializer.serialize(asnKey);
const key = new EcPrivateKey(); const key = new EcPrivateKey();
@ -189,11 +188,11 @@ export class EcCrypto {
return key; return key;
} }
protected static async importPublicKey(asnKey: schema.EcPublicKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) { protected static async importPublicKey(asnKey: core.asn1.EcPublicKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) {
const keyInfo = new schema.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
const namedCurve = getOidByNamedCurve(algorithm.namedCurve); const namedCurve = getOidByNamedCurve(algorithm.namedCurve);
keyInfo.publicKeyAlgorithm.parameters = AsnSerializer.serialize(new schema.ObjectIdentifier(namedCurve)); keyInfo.publicKeyAlgorithm.parameters = AsnSerializer.serialize(new core.asn1.ObjectIdentifier(namedCurve));
keyInfo.publicKey = asnKey.value; keyInfo.publicKey = asnKey.value;
const key = new EcPublicKey(); const key = new EcPublicKey();

View File

@ -29,7 +29,7 @@ export class EcdhProvider extends core.EcdhProvider {
return EcCrypto.exportKey(format, getCryptoKey(key)); return EcCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -41,7 +41,7 @@ export class EcdsaProvider extends core.EcdsaProvider {
return EcCrypto.exportKey(format, getCryptoKey(key)); return EcCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await EcCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -1,7 +1,6 @@
import * as asn1Schema from "@peculiar/asn1-schema"; import * as asn1Schema from "@peculiar/asn1-schema";
import * as jsonSchema from "@peculiar/json-schema"; import * as jsonSchema from "@peculiar/json-schema";
import * as core from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
import * as schema from "packages/core/src/schema";
import * as types from "@peculiar/webcrypto-types"; import * as types from "@peculiar/webcrypto-types";
import { AsymmetricKey } from "../../keys"; import { AsymmetricKey } from "../../keys";
import { getOidByNamedCurve } from "./helper"; import { getOidByNamedCurve } from "./helper";
@ -11,8 +10,8 @@ export class EcPrivateKey extends AsymmetricKey implements jsonSchema.IJsonConve
public override algorithm!: types.EcKeyAlgorithm; public override algorithm!: types.EcKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, schema.PrivateKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);
return asn1Schema.AsnParser.parse(keyInfo.privateKey, schema.EcPrivateKey); return asn1Schema.AsnParser.parse(keyInfo.privateKey, core.asn1.EcPrivateKey);
} }
public toJSON() { public toJSON() {
@ -33,12 +32,12 @@ export class EcPrivateKey extends AsymmetricKey implements jsonSchema.IJsonConve
throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`); throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
} }
const keyInfo = new schema.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
keyInfo.privateKeyAlgorithm.parameters = asn1Schema.AsnSerializer.serialize( keyInfo.privateKeyAlgorithm.parameters = asn1Schema.AsnSerializer.serialize(
new schema.ObjectIdentifier(getOidByNamedCurve(json.crv)), new core.asn1.ObjectIdentifier(getOidByNamedCurve(json.crv)),
); );
const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: schema.EcPrivateKey }); const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.asn1.EcPrivateKey });
keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key); keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key);
this.data = Buffer.from(asn1Schema.AsnSerializer.serialize(keyInfo)); this.data = Buffer.from(asn1Schema.AsnSerializer.serialize(keyInfo));

View File

@ -12,8 +12,8 @@ export class EcPublicKey extends AsymmetricKey implements jsonSchema.IJsonConver
public override algorithm!: types.EcKeyAlgorithm; public override algorithm!: types.EcKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, schema.PublicKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PublicKeyInfo);
return new schema.EcPublicKey(keyInfo.publicKey); return new core.asn1.EcPublicKey(keyInfo.publicKey);
} }
public toJSON() { public toJSON() {
@ -34,12 +34,12 @@ export class EcPublicKey extends AsymmetricKey implements jsonSchema.IJsonConver
throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`); throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
} }
const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: schema.EcPublicKey }); const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.asn1.EcPublicKey });
const keyInfo = new schema.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";
keyInfo.publicKeyAlgorithm.parameters = asn1Schema.AsnSerializer.serialize( keyInfo.publicKeyAlgorithm.parameters = asn1Schema.AsnSerializer.serialize(
new schema.ObjectIdentifier(getOidByNamedCurve(json.crv)), new core.asn1.ObjectIdentifier(getOidByNamedCurve(json.crv)),
); );
keyInfo.publicKey = asn1Schema.AsnSerializer.toASN(key).valueHex; keyInfo.publicKey = asn1Schema.AsnSerializer.toASN(key).valueHex;

View File

@ -97,7 +97,7 @@ export class EdCrypto {
case "spki": case "spki":
return new Uint8Array(key.data).buffer; return new Uint8Array(key.data).buffer;
case "raw": { case "raw": {
const publicKeyInfo = asn1Schema.AsnParser.parse(key.data, core.PublicKeyInfo); const publicKeyInfo = asn1Schema.AsnParser.parse(key.data, core.asn1.PublicKeyInfo);
return publicKeyInfo.publicKey; return publicKeyInfo.publicKey;
} }
default: default:
@ -110,7 +110,7 @@ export class EdCrypto {
case "jwk": { case "jwk": {
const jwk = keyData as types.JsonWebKey; const jwk = keyData as types.JsonWebKey;
if (jwk.d) { if (jwk.d) {
const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: core.CurvePrivateKey }); const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: core.asn1.CurvePrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else { } else {
if (!jwk.x) { if (!jwk.x) {
@ -123,12 +123,12 @@ export class EdCrypto {
return this.importPublicKey(keyData as ArrayBuffer, algorithm, extractable, keyUsages); return this.importPublicKey(keyData as ArrayBuffer, algorithm, extractable, keyUsages);
} }
case "spki": { case "spki": {
const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.PublicKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PublicKeyInfo);
return this.importPublicKey(keyInfo.publicKey, algorithm, extractable, keyUsages); return this.importPublicKey(keyInfo.publicKey, algorithm, extractable, keyUsages);
} }
case "pkcs8": { case "pkcs8": {
const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.PrivateKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PrivateKeyInfo);
const asnKey = asn1Schema.AsnParser.parse(keyInfo.privateKey, core.CurvePrivateKey); const asnKey = asn1Schema.AsnParser.parse(keyInfo.privateKey, core.asn1.CurvePrivateKey);
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} }
default: default:
@ -136,7 +136,7 @@ export class EdCrypto {
} }
} }
protected static importPrivateKey(asnKey: core.CurvePrivateKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) { protected static importPrivateKey(asnKey: core.asn1.CurvePrivateKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) {
const key = new EdPrivateKey(); const key = new EdPrivateKey();
key.fromJSON({ key.fromJSON({
crv: algorithm.namedCurve, crv: algorithm.namedCurve,

View File

@ -21,7 +21,7 @@ export class EcdhEsProvider extends core.EcdhEsProvider {
}; };
} }
public async onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: core.BaseCryptoKey, length: number): Promise<ArrayBuffer> { public async onDeriveBits(algorithm: types.EcdhKeyDeriveParams, baseKey: core.CryptoKey, length: number): Promise<ArrayBuffer> {
const bits = await EdCrypto.deriveBits({ ...algorithm, public: getCryptoKey(algorithm.public) }, getCryptoKey(baseKey), length); const bits = await EdCrypto.deriveBits({ ...algorithm, public: getCryptoKey(algorithm.public) }, getCryptoKey(baseKey), length);
return bits; return bits;
} }
@ -30,7 +30,7 @@ export class EcdhEsProvider extends core.EcdhEsProvider {
return EdCrypto.exportKey(format, getCryptoKey(key)); return EdCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -35,7 +35,7 @@ export class EdDsaProvider extends core.EdDsaProvider {
return EdCrypto.exportKey(format, getCryptoKey(key)); return EdCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer | types.JsonWebKey, algorithm: types.EcKeyImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await EdCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -1,19 +1,18 @@
import * as core from "@peculiar/webcrypto-core"; import * as core from "@peculiar/webcrypto-core";
import * as schema from "packages/core/src/schema";
const edOIDs: { [key: string]: string; } = { const edOIDs: { [key: string]: string; } = {
// Ed448 // Ed448
[schema.idEd448]: "Ed448", [core.asn1.idEd448]: "Ed448",
"ed448": schema.idEd448, "ed448": core.asn1.idEd448,
// X448 // X448
[schema.idX448]: "X448", [core.asn1.idX448]: "X448",
"x448": schema.idX448, "x448": core.asn1.idX448,
// Ed25519 // Ed25519
[schema.idEd25519]: "Ed25519", [core.asn1.idEd25519]: "Ed25519",
"ed25519": schema.idEd25519, "ed25519": core.asn1.idEd25519,
// X25519 // X25519
[schema.idX25519]: "X25519", [core.asn1.idX25519]: "X25519",
"x25519": schema.idX25519, "x25519": core.asn1.idX25519,
}; };
export function getNamedCurveByOid(oid: string) { export function getNamedCurveByOid(oid: string) {

View File

@ -11,8 +11,8 @@ export class EdPrivateKey extends AsymmetricKey implements jsonSchema.IJsonConve
public override algorithm!: types.EcKeyAlgorithm; public override algorithm!: types.EcKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, schema.PrivateKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);
return asn1Schema.AsnParser.parse(keyInfo.privateKey, schema.CurvePrivateKey); return asn1Schema.AsnParser.parse(keyInfo.privateKey, core.asn1.CurvePrivateKey);
} }
public toJSON() { public toJSON() {
@ -33,9 +33,9 @@ export class EdPrivateKey extends AsymmetricKey implements jsonSchema.IJsonConve
throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`); throw new core.OperationError(`Cannot get named curve from JWK. Property 'crv' is required`);
} }
const keyInfo = new schema.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv); keyInfo.privateKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv);
const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: schema.CurvePrivateKey }); const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.asn1.CurvePrivateKey });
keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key); keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key);
this.data = Buffer.from(asn1Schema.AsnSerializer.serialize(keyInfo)); this.data = Buffer.from(asn1Schema.AsnSerializer.serialize(keyInfo));

View File

@ -13,7 +13,7 @@ export class EdPublicKey extends AsymmetricKey implements jsonSchema.IJsonConver
public override algorithm!: types.EcKeyAlgorithm; public override algorithm!: types.EcKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, schema.PublicKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PublicKeyInfo);
return keyInfo.publicKey; return keyInfo.publicKey;
} }
@ -40,7 +40,7 @@ export class EdPublicKey extends AsymmetricKey implements jsonSchema.IJsonConver
throw new core.OperationError(`Cannot get property from JWK. Property 'x' is required`); throw new core.OperationError(`Cannot get property from JWK. Property 'x' is required`);
} }
const keyInfo = new schema.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv); keyInfo.publicKeyAlgorithm.algorithm = getOidByNamedCurve(json.crv);
keyInfo.publicKey = pvtsutils.Convert.FromBase64Url(json.x); keyInfo.publicKey = pvtsutils.Convert.FromBase64Url(json.x);

View File

@ -7,7 +7,7 @@ import { HkdfCryptoKey } from "./key";
export class HkdfProvider extends core.HkdfProvider { export class HkdfProvider extends core.HkdfProvider {
public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
if (format.toLowerCase() !== "raw") { if (format.toLowerCase() !== "raw") {
throw new core.OperationError("Operation not supported"); throw new core.OperationError("Operation not supported");
} }
@ -44,7 +44,7 @@ export class HkdfProvider extends core.HkdfProvider {
return Buffer.concat(blocks).slice(0, byteLength); return Buffer.concat(blocks).slice(0, byteLength);
} }
public override checkCryptoKey(key: core.BaseCryptoKey, keyUsage?: types.KeyUsage) { public override checkCryptoKey(key: core.CryptoKey, keyUsage?: types.KeyUsage) {
super.checkCryptoKey(key, keyUsage); super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof HkdfCryptoKey)) { if (!(getCryptoKey(key) instanceof HkdfCryptoKey)) {
throw new TypeError("key: Is not HKDF CryptoKey"); throw new TypeError("key: Is not HKDF CryptoKey");

View File

@ -8,7 +8,7 @@ import { HmacCryptoKey } from "./key";
export class HmacProvider extends core.HmacProvider { export class HmacProvider extends core.HmacProvider {
public async onGenerateKey(algorithm: types.PreparedHashedAlgorithm<types.HmacKeyGenParams>, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onGenerateKey(algorithm: types.PreparedHashedAlgorithm<types.HmacKeyGenParams>, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const length = (algorithm.length || this.getDefaultLength(algorithm.hash.name)) >> 3 << 3; const length = (algorithm.length || this.getDefaultLength(algorithm.hash.name)) >> 3 << 3;
const key = new HmacCryptoKey(); const key = new HmacCryptoKey();
key.algorithm = { key.algorithm = {
@ -39,7 +39,7 @@ export class HmacProvider extends core.HmacProvider {
return hmac.compare(Buffer.from(signature)) === 0; return hmac.compare(Buffer.from(signature)) === 0;
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.HmacImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
let key: HmacCryptoKey; let key: HmacCryptoKey;
switch (format.toLowerCase()) { switch (format.toLowerCase()) {

View File

@ -21,7 +21,7 @@ export class Pbkdf2Provider extends core.Pbkdf2Provider {
}); });
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.Algorithm, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
if (format === "raw") { if (format === "raw") {
const key = new PbkdfCryptoKey(); const key = new PbkdfCryptoKey();
key.data = Buffer.from(keyData as ArrayBuffer); key.data = Buffer.from(keyData as ArrayBuffer);

View File

@ -77,21 +77,21 @@ export class RsaCrypto {
case "jwk": { case "jwk": {
const jwk = keyData as types.JsonWebKey; const jwk = keyData as types.JsonWebKey;
if (jwk.d) { if (jwk.d) {
const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: schema.RsaPrivateKey }); const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: core.asn1.RsaPrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else { } else {
const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: schema.RsaPublicKey }); const asnKey = jsonSchema.JsonParser.fromJSON(keyData, { targetSchema: core.asn1.RsaPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
} }
case "spki": { case "spki": {
const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), schema.PublicKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PublicKeyInfo);
const asnKey = asn1Schema.AsnParser.parse(keyInfo.publicKey, schema.RsaPublicKey); const asnKey = asn1Schema.AsnParser.parse(keyInfo.publicKey, core.asn1.RsaPublicKey);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
case "pkcs8": { case "pkcs8": {
const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), schema.PrivateKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), core.asn1.PrivateKeyInfo);
const asnKey = asn1Schema.AsnParser.parse(keyInfo.privateKey, schema.RsaPrivateKey); const asnKey = asn1Schema.AsnParser.parse(keyInfo.privateKey, core.asn1.RsaPrivateKey);
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} }
default: default:
@ -137,8 +137,8 @@ export class RsaCrypto {
} }
} }
protected static importPrivateKey(asnKey: schema.RsaPrivateKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) { protected static importPrivateKey(asnKey: core.asn1.RsaPrivateKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) {
const keyInfo = new schema.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.privateKeyAlgorithm.parameters = null; keyInfo.privateKeyAlgorithm.parameters = null;
keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(asnKey); keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(asnKey);
@ -155,8 +155,8 @@ export class RsaCrypto {
return key; return key;
} }
protected static importPublicKey(asnKey: schema.RsaPublicKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) { protected static importPublicKey(asnKey: core.asn1.RsaPublicKey, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]) {
const keyInfo = new schema.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.publicKeyAlgorithm.parameters = null; keyInfo.publicKeyAlgorithm.parameters = null;
keyInfo.publicKey = asn1Schema.AsnSerializer.serialize(asnKey); keyInfo.publicKey = asn1Schema.AsnSerializer.serialize(asnKey);

View File

@ -10,8 +10,8 @@ export class RsaPrivateKey extends AsymmetricKey {
public override algorithm!: types.RsaHashedKeyAlgorithm; public override algorithm!: types.RsaHashedKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, core.PrivateKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);
return asn1Schema.AsnParser.parse(keyInfo.privateKey, core.RsaPrivateKey); return asn1Schema.AsnParser.parse(keyInfo.privateKey, core.asn1.RsaPrivateKey);
} }
public toJSON() { public toJSON() {
@ -28,9 +28,9 @@ export class RsaPrivateKey extends AsymmetricKey {
} }
public fromJSON(json: types.JsonWebKey) { public fromJSON(json: types.JsonWebKey) {
const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.RsaPrivateKey }); const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.asn1.RsaPrivateKey });
const keyInfo = new core.PrivateKeyInfo(); const keyInfo = new core.asn1.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.privateKeyAlgorithm.parameters = null; keyInfo.privateKeyAlgorithm.parameters = null;
keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key); keyInfo.privateKey = asn1Schema.AsnSerializer.serialize(key);

View File

@ -10,8 +10,8 @@ export class RsaPublicKey extends AsymmetricKey {
public override algorithm!: types.RsaHashedKeyAlgorithm; public override algorithm!: types.RsaHashedKeyAlgorithm;
public getKey() { public getKey() {
const keyInfo = asn1Schema.AsnParser.parse(this.data, core.PublicKeyInfo); const keyInfo = asn1Schema.AsnParser.parse(this.data, core.asn1.PublicKeyInfo);
return asn1Schema.AsnParser.parse(keyInfo.publicKey, core.RsaPublicKey); return asn1Schema.AsnParser.parse(keyInfo.publicKey, core.asn1.RsaPublicKey);
} }
public toJSON() { public toJSON() {
@ -28,9 +28,9 @@ export class RsaPublicKey extends AsymmetricKey {
} }
public fromJSON(json: types.JsonWebKey) { public fromJSON(json: types.JsonWebKey) {
const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.RsaPublicKey }); const key = jsonSchema.JsonParser.fromJSON(json, { targetSchema: core.asn1.RsaPublicKey });
const keyInfo = new core.PublicKeyInfo(); const keyInfo = new core.asn1.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
keyInfo.publicKeyAlgorithm.parameters = null; keyInfo.publicKeyAlgorithm.parameters = null;
keyInfo.publicKey = asn1Schema.AsnSerializer.serialize(key); keyInfo.publicKey = asn1Schema.AsnSerializer.serialize(key);

View File

@ -148,7 +148,7 @@ export class RsaOaepProvider extends core.RsaOaepProvider {
return RsaCrypto.exportKey(format, getCryptoKey(key)); return RsaCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -39,7 +39,7 @@ export class RsaPssProvider extends core.RsaPssProvider {
return RsaCrypto.exportKey(format, getCryptoKey(key)); return RsaCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -39,7 +39,7 @@ export class RsaSsaProvider extends core.RsaSsaProvider {
return RsaCrypto.exportKey(format, getCryptoKey(key)); return RsaCrypto.exportKey(format, getCryptoKey(key));
} }
public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.BaseCryptoKey> { public async onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.RsaHashedImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages); const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key); return setCryptoKey(key);
} }

View File

@ -14,7 +14,7 @@ export function getCryptoKey(key: types.CryptoKey) {
} }
export function setCryptoKey(value: InternalCryptoKey) { export function setCryptoKey(value: InternalCryptoKey) {
const key = core.BaseCryptoKey.create(value.algorithm, value.type, value.extractable, value.usages); const key = core.CryptoKey.create(value.algorithm, value.type, value.extractable, value.usages);
Object.freeze(key); Object.freeze(key);
keyStorage.set(key, value); keyStorage.set(key, value);

View File

@ -1,2 +1,3 @@
export * from "./types";
export * from "./webcrypto_test"; export * from "./webcrypto_test";
export * as vectors from "./vectors"; export * as vectors from "./vectors";

View File

@ -0,0 +1,15 @@
// Test allows to validate that WebCrypto API from @peculiar/webcrypto-types matches to DOM WebCrypto
// NOTE: This file should be in 'exclude' option of tsconfig.json file
/// <reference lib="dom" />
import * as types from "../src";
context("Types", () => {
it("@peculiar WebCrypto matches DOM WebCrypto", () => {
const myCrypto = {} as types.Crypto;
let crypto: globalThis.Crypto = myCrypto;
});
});

View File

@ -18,6 +18,10 @@
"@peculiar/webcrypto-pkcs11": [ "@peculiar/webcrypto-pkcs11": [
"./packages/pkcs11/src" "./packages/pkcs11/src"
], ],
} },
} "skipLibCheck": true, // TODO @peculiar/x509 should use @peculiar/webcrypto-types. Remove this line when it's fixed
},
"exclude": [
"packages/types/test/types.spec.ts"
]
} }

152
yarn.lock
View File

@ -85,12 +85,110 @@
"@nodelib/fs.scandir" "2.1.5" "@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0" fastq "^1.6.0"
"@peculiar/asn1-schema@^2.1.7": "@peculiar/asn1-cms@^2.1.8":
version "2.1.7" version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-schema/-/asn1-schema-2.1.7.tgz#17d9b79f7df748ef84158ea61a24fc11d9f3f4d9" resolved "https://registry.yarnpkg.com/@peculiar/asn1-cms/-/asn1-cms-2.1.8.tgz#0f2591e46f9ee360c1f834ff191b44be49dbfc6c"
integrity sha512-RxnHrl7WgNxWPsGeSw7YUGTS3s5En7JwhdOilRpEShQJQ9TH8v1nZtslyZGX5GxgUJ1P4dnRsCnt7R5EYmvtUg== integrity sha512-xWW1thg1V+SowpYkzuJsQdKg0n/myfwxajgjXKXyxYbIUqer4+2wRAA8lz/0//Lt1cyuG/3slaewncus9QM3Yw==
dependencies: dependencies:
asn1js "^3.0.3" "@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
"@peculiar/asn1-x509-attr" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-csr@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-csr/-/asn1-csr-2.1.8.tgz#72948e87f69c8645bf379b591260a084e61f5d7c"
integrity sha512-orsY1nJ/2fopMabioLdXBZeuxlXAEkXfqBl6hEYHUG9Ia5uoAxnT5yxmn78RvbcdDqp9GBSmh653zGyYX8nuSg==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-ecc@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-ecc/-/asn1-ecc-2.1.8.tgz#3ad6d5ab44cbf2ee0ec6bcaa2575c8e9c1148947"
integrity sha512-MoIWxTP/USioOSwjDvUJL2esWzZkrYdlsLQfcWUOn5jVLe+q1nSHBubBjhXtjR9iIN0LnXQ629nTNdhLznx+jQ==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-pfx@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-pfx/-/asn1-pfx-2.1.8.tgz#1d6798c78493d23ce68d7cec0169049447e73606"
integrity sha512-iX5vI9unoR0dT3ME1SgKSHGzsGowTVOolzSz68+jRV3B6nSJljHdiriVyUXIz+pGFSShRPPgy+xagGmo9A9cYg==
dependencies:
"@peculiar/asn1-cms" "^2.1.8"
"@peculiar/asn1-pkcs8" "^2.1.8"
"@peculiar/asn1-rsa" "^2.1.8"
"@peculiar/asn1-schema" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-pkcs8@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-pkcs8/-/asn1-pkcs8-2.1.8.tgz#997cbf35f37ee661e723e96750b944f6703d57c7"
integrity sha512-2WbAoDQP8Gs0mtyzXlYbSvJ4QPiYuBNasIfpkRV4fjNNtCh80O3gdONa4B5xWWGhLbitjDE68ZigwrXlVACr1g==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-pkcs9@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-pkcs9/-/asn1-pkcs9-2.1.8.tgz#c581ece374056e029d4c719ea733a6e54b49341f"
integrity sha512-VoSWvUalTtnXpnDXItGpcWVNn5RI2iZ+poDMUEYg3qmHd9V6c/ieI3jmMbSPKlPq4uiG6BxfZwCCbDAyDa70vg==
dependencies:
"@peculiar/asn1-cms" "^2.1.8"
"@peculiar/asn1-pfx" "^2.1.8"
"@peculiar/asn1-pkcs8" "^2.1.8"
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
"@peculiar/asn1-x509-attr" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-rsa@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-rsa/-/asn1-rsa-2.1.8.tgz#26d46e83df53095387fa9d3ae5fde061f9f64590"
integrity sha512-p3RuAmbetJUy7hAOwkBsGp4vULjrpSQFZvz9OT83bkaOVHOGTzpc42Q02869hIX5eAB3LdZqct+atcpaHR6c/w==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-schema@^2.1.7", "@peculiar/asn1-schema@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-schema/-/asn1-schema-2.1.8.tgz#552300a1ed7991b22c9abf789a3920a3cb94c26b"
integrity sha512-u34H/bpqCdDuqrCVZvH0vpwFBT/dNEdNY+eE8u4IuC26yYnhDkXF4+Hliqca88Avbb7hyN2EF/eokyDdyS7G/A==
dependencies:
asn1js "^3.0.4"
pvtsutils "^1.3.2"
tslib "^2.4.0"
"@peculiar/asn1-x509-attr@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-x509-attr/-/asn1-x509-attr-2.1.8.tgz#c55d4ccfc3c1ce11e0f158f1e2ad9326961fe650"
integrity sha512-JtSjcCLOXILesj6lC3kqe2qVvRcTcWLozjO94cDVKWtLX04/QiwZbhetG9OPLaE0DFfErUz1/DC06swAO4yGRQ==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
asn1js "^3.0.4"
tslib "^2.4.0"
"@peculiar/asn1-x509@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-x509/-/asn1-x509-2.1.8.tgz#b67317ba1ee33c758ad7c6145dbaa1ddef4f1913"
integrity sha512-asAcoeZ+bjy/4/lf6gbMlfmywHpxLBa7LBE4pPCzSAKBM0IHXWa7bqsDyshtywzLW+VpA+G2m0Fs7Lt7Woh7RA==
dependencies:
"@peculiar/asn1-schema" "^2.1.8"
asn1js "^3.0.4"
ipaddr.js "^2.0.1"
pvtsutils "^1.3.2" pvtsutils "^1.3.2"
tslib "^2.4.0" tslib "^2.4.0"
@ -101,6 +199,23 @@
dependencies: dependencies:
tslib "^2.0.0" tslib "^2.0.0"
"@peculiar/x509@^1.6.4":
version "1.6.4"
resolved "https://registry.yarnpkg.com/@peculiar/x509/-/x509-1.6.4.tgz#f36567540fff082411425cc839abae38d3d2fcf6"
integrity sha512-sj9YN5LrAOyrn3lWU8KxsTQ87spVGyjypDchJrZEi8W4jiQxLoBNvFwk/D4KWNklYrgzvdoQQKIlm8Md975iQQ==
dependencies:
"@peculiar/asn1-cms" "^2.1.8"
"@peculiar/asn1-csr" "^2.1.8"
"@peculiar/asn1-ecc" "^2.1.8"
"@peculiar/asn1-pkcs9" "^2.1.8"
"@peculiar/asn1-rsa" "^2.1.8"
"@peculiar/asn1-schema" "^2.1.8"
"@peculiar/asn1-x509" "^2.1.8"
pvtsutils "^1.3.2"
reflect-metadata "^0.1.13"
tslib "^2.4.0"
tsyringe "^4.6.0"
"@rollup/pluginutils@^4.1.2": "@rollup/pluginutils@^4.1.2":
version "4.2.1" version "4.2.1"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.2.1.tgz#e6c6c3aba0744edce3fb2074922d3776c0af2a6d" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.2.1.tgz#e6c6c3aba0744edce3fb2074922d3776c0af2a6d"
@ -315,10 +430,10 @@ array-union@^2.1.0:
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==
asn1js@^3.0.3: asn1js@^3.0.4:
version "3.0.3" version "3.0.5"
resolved "https://registry.yarnpkg.com/asn1js/-/asn1js-3.0.3.tgz#fbecdcced2c046552db0c63af284eccc494e0e74" resolved "https://registry.yarnpkg.com/asn1js/-/asn1js-3.0.5.tgz#5ea36820443dbefb51cc7f88a2ebb5b462114f38"
integrity sha512-Oz62ld3K3n6KlRUr4iZSMbSFDDPCW84G1yX7b/gWK5a0Ka7ZYOmCxFpu91lFdQygkBi2Hgoft1/WxRqFrONqLA== integrity sha512-FVnvrKJwpt9LP2lAMl8qZswRNm3T4q9CON+bxldk2iwk3FFpuwhx2FfinyitizWHsVYyaY+y5JzDR0rCMV5yTQ==
dependencies: dependencies:
pvtsutils "^1.3.2" pvtsutils "^1.3.2"
pvutils "^1.1.3" pvutils "^1.1.3"
@ -890,6 +1005,11 @@ inherits@2:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
ipaddr.js@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.0.1.tgz#eca256a7a877e917aeb368b0a7497ddf42ef81c0"
integrity sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng==
is-binary-path@~2.1.0: is-binary-path@~2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
@ -1297,6 +1417,11 @@ readdirp@~3.6.0:
dependencies: dependencies:
picomatch "^2.2.1" picomatch "^2.2.1"
reflect-metadata@^0.1.13:
version "0.1.13"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==
regexpp@^3.2.0: regexpp@^3.2.0:
version "3.2.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
@ -1507,7 +1632,7 @@ tsconfig-paths@^3.14.1:
minimist "^1.2.6" minimist "^1.2.6"
strip-bom "^3.0.0" strip-bom "^3.0.0"
tslib@^1.8.1: tslib@^1.8.1, tslib@^1.9.3:
version "1.14.1" version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
@ -1524,6 +1649,13 @@ tsutils@^3.21.0:
dependencies: dependencies:
tslib "^1.8.1" tslib "^1.8.1"
tsyringe@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/tsyringe/-/tsyringe-4.6.0.tgz#14915d3d7f0db35e1cf7269bdbf7c440713c8d07"
integrity sha512-BMQAZamSfEmIQzH8WJeRu1yZGQbPSDuI9g+yEiKZFIcO46GPZuMOC2d0b52cVBdw1d++06JnDSIIZvEnogMdAw==
dependencies:
tslib "^1.9.3"
type-check@^0.4.0, type-check@~0.4.0: type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0" version "0.4.0"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"