Merge pull request #45 from PeculiarVentures:fix-type-error

Fix type error
This commit is contained in:
Miroshin Stepan 2022-03-02 21:40:57 +03:00 committed by GitHub
commit 8d65733a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 3137 additions and 9189 deletions

View File

@ -11,6 +11,9 @@
"plugin:import/warnings",
"plugin:import/typescript"
],
"ignorePatterns": [
"build/**/*"
],
"rules": {
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/camelcase": 0,

View File

@ -52,10 +52,10 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Install global dependencies
run: npm i standard-version -g
run: npm i standard-version yarn -g
- name: Install dependencies
run: npm i
run: yarn
- name: Get Prev Version
shell: bash -ex {0}
@ -76,6 +76,7 @@ jobs:
- name: Publish
if: env.PREV_VERSION != env.CURRENT_VERSION
run: |
npm run build
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

View File

@ -32,14 +32,17 @@ jobs:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install global dependencies
run: npm i yarn -g
- name: Install dependencies
run: npm install
run: yarn
- name: Run linter
run: npm run lint

1
index.d.ts vendored
View File

@ -1,6 +1,7 @@
export declare class Crypto implements globalThis.Crypto {
public subtle: SubtleCrypto;
public getRandomValues<T extends ArrayBufferView | null>(array: T): T;
public randomUUID(): string;
}
export declare class CryptoKey implements globalThis.CryptoKey {

8993
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,21 +17,13 @@
"types": "index.d.ts",
"scripts": {
"test": "mocha",
"prepare": "npm run build",
"coverage": "nyc npm test",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"build": "npm run build:module",
"build": "rollup -c",
"clear": "rimraf build/*",
"rebuild": "npm run clear && npm run build",
"build:module": "rollup -c",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint --fix . --ext .ts",
"prepub": "npm run lint && npm run rebuild",
"pub": "npm version patch && npm publish",
"postpub": "git push && git push --tags origin master",
"prepub:next": "npm run lint && npm run rebuild",
"pub:next": "npm version prerelease --preid=next && npm publish --tag next",
"postpub:next": "git push"
"lint:fix": "eslint --fix . --ext .ts"
},
"keywords": [
"webcrypto",
@ -60,30 +52,29 @@
"url": "https://github.com/PeculiarVentures/webcrypto/issues"
},
"homepage": "https://github.com/PeculiarVentures/webcrypto#readme",
"banner": "// Copyright (c) 2021, Peculiar Ventures, All rights reserved.",
"devDependencies": {
"@peculiar/webcrypto-test": "^1.0.7",
"@types/mocha": "^9.1.0",
"@types/node": "^16.11.10",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@types/node": "^17.0.21",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"coveralls": "^3.1.1",
"eslint": "^8.9.0",
"eslint": "^8.10.0",
"eslint-plugin-import": "^2.25.4",
"mocha": "^9.2.1",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.68.0",
"rollup": "^2.69.0",
"rollup-plugin-typescript2": "^0.31.2",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
"ts-node": "^10.6.0",
"typescript": "^4.6.2"
},
"dependencies": {
"@peculiar/asn1-schema": "^2.0.44",
"@peculiar/json-schema": "^1.1.12",
"pvtsutils": "^1.2.1",
"pvtsutils": "^1.2.2",
"tslib": "^2.3.1",
"webcrypto-core": "^1.4.0"
"webcrypto-core": "^1.6.0"
},
"nyc": {
"extension": [

View File

@ -2,15 +2,19 @@ import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";
const banner = [
"/**",
" * Copyright (c) 2020 Peculiar Ventures, LLC",
" */",
"/*!",
" Copyright (c) Peculiar Ventures, LLC",
"*/",
"",
].join("\n");
const input = "src/index.ts";
const external = Object.keys(pkg.dependencies);
const external = [
...["crypto", "process"],
...Object.keys(pkg.dependencies || {}),
];
export default {
export default [
{
input,
plugins: [
typescript({
@ -19,11 +23,12 @@ export default {
tsconfigOverride: {
compilerOptions: {
module: "ES2015",
removeComments: true,
}
}
}),
],
external: ["crypto", "process", ...external],
external: [...external],
output: [
{
banner,
@ -36,4 +41,5 @@ export default {
format: "es",
},
],
};
},
];

View File

@ -2,7 +2,7 @@ import { CryptoKey } from "./key";
export abstract class AsymmetricKey extends CryptoKey {
public abstract type: "public" | "private";
public abstract override type: "public" | "private";
public pem?: string;
}

View File

@ -4,15 +4,15 @@ import * as core from "webcrypto-core";
export class CryptoKey extends core.CryptoKey {
public data: Buffer = Buffer.alloc(0);
public algorithm: KeyAlgorithm = { name: "" };
public override algorithm: KeyAlgorithm = { name: "" };
@JsonProp({ name: "ext", type: JsonPropTypes.Boolean, optional: true })
public extractable = false;
public override extractable = false;
public type: KeyType = "secret";
public override type: KeyType = "secret";
@JsonProp({ name: "key_ops", type: JsonPropTypes.String, repeated: true, optional: true })
public usages: KeyUsage[] = [];
public override usages: KeyUsage[] = [];
@JsonProp({ type: JsonPropTypes.String })
protected kty = "oct";

View File

@ -2,7 +2,7 @@ import { CryptoKey } from "./key";
export class SymmetricKey extends CryptoKey {
public readonly kty = "oct";
public readonly type: "secret" = "secret";
public override readonly kty = "oct";
public override readonly type: "secret" = "secret";
}

View File

@ -34,7 +34,7 @@ export class AesCbcProvider extends core.AesCbcProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -144,7 +144,7 @@ export class AesCmacProvider extends core.AesCmacProvider {
return setCryptoKey(res);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -34,7 +34,7 @@ export class AesCtrProvider extends core.AesCtrProvider {
return setCryptoKey(res);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -34,7 +34,7 @@ export class AesEcbProvider extends core.AesEcbProvider {
return setCryptoKey(res);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -34,7 +34,7 @@ export class AesGcmProvider extends core.AesGcmProvider {
return setCryptoKey(res);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -26,15 +26,15 @@ export class AesKwProvider extends core.AesKwProvider {
return setCryptoKey(res);
}
public async onEncrypt(algorithm: Algorithm, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onEncrypt(algorithm: Algorithm, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
return AesCrypto.encrypt(algorithm, getCryptoKey(key) as AesCryptoKey, new Uint8Array(data));
}
public async onDecrypt(algorithm: Algorithm, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDecrypt(algorithm: Algorithm, key: AesCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
return AesCrypto.decrypt(algorithm, getCryptoKey(key) as AesCryptoKey, new Uint8Array(data));
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof AesCryptoKey)) {
throw new TypeError("key: Is not a AesCryptoKey");

View File

@ -5,10 +5,10 @@ import { SymmetricKey } from "../../keys";
export class AesCryptoKey extends SymmetricKey {
public algorithm!: AesKeyAlgorithm;
public override algorithm!: AesKeyAlgorithm;
@JsonProp({name: "k", converter: JsonBase64UrlConverter})
public data!: Buffer;
public override data!: Buffer;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@ -31,7 +31,7 @@ export class AesCryptoKey extends SymmetricKey {
}
}
public set alg(value: string) {
public override set alg(value: string) {
// nothing, cause set is needed for json-schema, but is not used by module
}

View File

@ -44,7 +44,7 @@ export class DesCbcProvider extends core.DesProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof DesCryptoKey)) {
throw new TypeError("key: Is not a DesCryptoKey");

View File

@ -44,7 +44,7 @@ export class DesEde3CbcProvider extends core.DesProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof DesCryptoKey)) {
throw new TypeError("key: Is not a DesCryptoKey");

View File

@ -5,10 +5,10 @@ import { SymmetricKey } from "../../keys";
export class DesCryptoKey extends SymmetricKey {
public algorithm!: core.DesKeyAlgorithm;
public override algorithm!: core.DesKeyAlgorithm;
@JsonProp({name: "k", converter: JsonBase64UrlConverter})
public data!: Buffer;
public override data!: Buffer;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@ -23,7 +23,7 @@ export class DesCryptoKey extends SymmetricKey {
}
}
public set alg(value: string) {
public override set alg(value: string) {
// nothing, cause set is needed for json-schema, but is not used by module
}

View File

@ -13,7 +13,7 @@ export class EcCrypto {
public static publicKeyUsages = ["verify"];
public static privateKeyUsages = ["sign", "deriveKey", "deriveBits"];
public static async generateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public static async generateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const privateKey = new EcPrivateKey();
privateKey.algorithm = algorithm;
privateKey.extractable = extractable;

View File

@ -7,9 +7,9 @@ import { EcPublicKey } from "./public_key";
export class EcdhProvider extends core.EcdhProvider {
public namedCurves = core.EcCurves.names;
public override namedCurves = core.EcCurves.names;
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await EcCrypto.generateKey(
{
...algorithm,
@ -33,7 +33,7 @@ export class EcdhProvider extends core.EcdhProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof EcPrivateKey || internalKey instanceof EcPublicKey)) {

View File

@ -6,9 +6,9 @@ import { EcPublicKey } from "./public_key";
export class EcdsaProvider extends core.EcdsaProvider {
public namedCurves = core.EcCurves.names;
public override namedCurves = core.EcCurves.names;
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await EcCrypto.generateKey(
{
...algorithm,
@ -40,7 +40,7 @@ export class EcdsaProvider extends core.EcdsaProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof EcPrivateKey || internalKey instanceof EcPublicKey)) {

View File

@ -6,7 +6,7 @@ import { getOidByNamedCurve } from "./helper";
export class EcPrivateKey extends AsymmetricKey implements IJsonConvertible {
public readonly type: "private" = "private";
public algorithm!: EcKeyAlgorithm;
public override algorithm!: EcKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);

View File

@ -7,7 +7,7 @@ import { getOidByNamedCurve } from "./helper";
export class EcPublicKey extends AsymmetricKey implements IJsonConvertible {
public readonly type: "public" = "public";
public algorithm!: EcKeyAlgorithm;
public override algorithm!: EcKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PublicKeyInfo);

View File

@ -12,7 +12,7 @@ export class EdCrypto {
public static publicKeyUsages = ["verify"];
public static privateKeyUsages = ["sign", "deriveKey", "deriveBits"];
public static async generateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public static async generateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const privateKey = new EdPrivateKey();
privateKey.algorithm = algorithm;
privateKey.extractable = extractable;

View File

@ -5,7 +5,7 @@ import { EdCrypto } from "./crypto";
export class EcdhEsProvider extends core.EcdhEsProvider {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await EdCrypto.generateKey(
{
name: this.name,

View File

@ -7,7 +7,7 @@ import { EdPublicKey } from "./public_key";
export class EdDsaProvider extends core.EdDsaProvider {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await EdCrypto.generateKey(
{
name: this.name,

View File

@ -6,7 +6,7 @@ import { getOidByNamedCurve } from "./helper";
export class EdPrivateKey extends AsymmetricKey implements IJsonConvertible {
public readonly type: "private" = "private";
public algorithm!: EcKeyAlgorithm;
public override algorithm!: EcKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);

View File

@ -8,7 +8,7 @@ import { getOidByNamedCurve } from "./helper";
export class EdPublicKey extends AsymmetricKey implements IJsonConvertible {
public readonly type: "public" = "public";
public algorithm!: EcKeyAlgorithm;
public override algorithm!: EcKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PublicKeyInfo);

View File

@ -43,7 +43,7 @@ export class HkdfProvider extends core.HkdfProvider {
return Buffer.concat(blocks).slice(0, byteLength);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof HkdfCryptoKey)) {
throw new TypeError("key: Is not HKDF CryptoKey");

View File

@ -2,7 +2,7 @@ import { CryptoKey } from "../../keys";
export class HkdfCryptoKey extends CryptoKey {
public data!: Buffer;
public override data!: Buffer;
public algorithm!: KeyAlgorithm;
public override algorithm!: KeyAlgorithm;
}

View File

@ -21,7 +21,7 @@ export class HmacProvider extends core.HmacProvider {
return setCryptoKey(key);
}
public async onSign(algorithm: Algorithm, key: HmacCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onSign(algorithm: Algorithm, key: HmacCryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
const hash = key.algorithm.hash.name.replace("-", "");
const hmac = crypto.createHmac(hash, getCryptoKey(key).data)
.update(Buffer.from(data)).digest();
@ -29,7 +29,7 @@ export class HmacProvider extends core.HmacProvider {
return new Uint8Array(hmac).buffer;
}
public async onVerify(algorithm: Algorithm, key: HmacCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
public override async onVerify(algorithm: Algorithm, key: HmacCryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
const hash = key.algorithm.hash.name.replace("-", "");
const hmac = crypto.createHmac(hash, getCryptoKey(key).data)
.update(Buffer.from(data)).digest();
@ -74,7 +74,7 @@ export class HmacProvider extends core.HmacProvider {
}
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof HmacCryptoKey)) {
throw new TypeError("key: Is not HMAC CryptoKey");

View File

@ -5,9 +5,9 @@ import { CryptoKey } from "../../keys";
export class HmacCryptoKey extends CryptoKey {
@JsonProp({ name: "k", converter: JsonBase64UrlConverter })
public data!: Buffer;
public override data!: Buffer;
public algorithm!: HmacKeyAlgorithm;
public override algorithm!: HmacKeyAlgorithm;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@ -16,7 +16,7 @@ export class HmacCryptoKey extends CryptoKey {
return `HS${hash.replace("SHA-", "")}`;
}
protected set alg(value: string) {
protected override set alg(value: string) {
// nothing, cause set is needed for json-schema, but is not used by module
}

View File

@ -31,7 +31,7 @@ export class Pbkdf2Provider extends core.Pbkdf2Provider {
throw new core.OperationError("format: Must be 'raw'");
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
if (!(getCryptoKey(key) instanceof PbkdfCryptoKey)) {
throw new TypeError("key: Is not PBKDF CryptoKey");

View File

@ -18,7 +18,7 @@ export class RsaCrypto {
public static publicKeyUsages = ["verify", "encrypt", "wrapKey"];
public static privateKeyUsages = ["sign", "decrypt", "unwrapKey"];
public static async generateKey(algorithm: RsaHashedKeyGenParams | RsaKeyGenParams, extractable: boolean, keyUsages: string[]): Promise<core.CryptoKeyPair> {
public static async generateKey(algorithm: RsaHashedKeyGenParams | RsaKeyGenParams, extractable: boolean, keyUsages: string[]): Promise<CryptoKeyPair> {
const privateKey = new RsaPrivateKey();
privateKey.algorithm = algorithm as RsaHashedKeyAlgorithm;
privateKey.extractable = extractable;

View File

@ -6,7 +6,7 @@ import { getJwkAlgorithm } from "./helper";
export class RsaPrivateKey extends AsymmetricKey {
public readonly type: "private" = "private";
public algorithm!: RsaHashedKeyAlgorithm;
public override algorithm!: RsaHashedKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PrivateKeyInfo);

View File

@ -6,7 +6,7 @@ import { getJwkAlgorithm } from "./helper";
export class RsaPublicKey extends AsymmetricKey {
public readonly type: "public" = "public";
public algorithm!: RsaHashedKeyAlgorithm;
public override algorithm!: RsaHashedKeyAlgorithm;
public getKey() {
const keyInfo = AsnParser.parse(this.data, core.asn1.PublicKeyInfo);

View File

@ -14,7 +14,7 @@ export class RsaEsProvider extends core.ProviderCrypto {
privateKey: ["decrypt", "unwrapKey"] as core.KeyUsages,
};
public async onGenerateKey(algorithm: RsaKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public override async onGenerateKey(algorithm: RsaKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await RsaCrypto.generateKey(
{
...algorithm,
@ -29,7 +29,7 @@ export class RsaEsProvider extends core.ProviderCrypto {
};
}
public checkGenerateKeyParams(algorithm: RsaKeyGenParams) {
public override checkGenerateKeyParams(algorithm: RsaKeyGenParams) {
// public exponent
this.checkRequiredProperty(algorithm, "publicExponent");
if (!(algorithm.publicExponent && algorithm.publicExponent instanceof Uint8Array)) {
@ -52,28 +52,28 @@ export class RsaEsProvider extends core.ProviderCrypto {
}
}
public async onEncrypt(algorithm: Algorithm, key: RsaPublicKey, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onEncrypt(algorithm: Algorithm, key: RsaPublicKey, data: ArrayBuffer): Promise<ArrayBuffer> {
const options = this.toCryptoOptions(key);
const enc = crypto.publicEncrypt(options, new Uint8Array(data));
return new Uint8Array(enc).buffer;
}
public async onDecrypt(algorithm: Algorithm, key: RsaPrivateKey, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDecrypt(algorithm: Algorithm, key: RsaPrivateKey, data: ArrayBuffer): Promise<ArrayBuffer> {
const options = this.toCryptoOptions(key);
const dec = crypto.privateDecrypt(options, new Uint8Array(data));
return new Uint8Array(dec).buffer;
}
public async onExportKey(format: KeyFormat, key: CryptoKey): Promise<JsonWebKey | ArrayBuffer> {
public override async onExportKey(format: KeyFormat, key: CryptoKey): Promise<JsonWebKey | ArrayBuffer> {
return RsaCrypto.exportKey(format, getCryptoKey(key));
}
public async onImportKey(format: KeyFormat, keyData: JsonWebKey | ArrayBuffer, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey> {
public override async onImportKey(format: KeyFormat, keyData: JsonWebKey | ArrayBuffer, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey> {
const key = await RsaCrypto.importKey(format, keyData, { ...algorithm, name: this.name }, extractable, keyUsages);
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof RsaPrivateKey || internalKey instanceof RsaPublicKey)) {

View File

@ -15,7 +15,7 @@ import { RsaPublicKey } from "./public_key";
export class RsaOaepProvider extends core.RsaOaepProvider {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await RsaCrypto.generateKey(
{
...algorithm,
@ -151,7 +151,7 @@ export class RsaOaepProvider extends core.RsaOaepProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof RsaPrivateKey || internalKey instanceof RsaPublicKey)) {

View File

@ -6,7 +6,7 @@ import { RsaPublicKey } from "./public_key";
export class RsaPssProvider extends core.RsaPssProvider {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair> {
const keys = await RsaCrypto.generateKey(
{
...algorithm,
@ -38,7 +38,7 @@ export class RsaPssProvider extends core.RsaPssProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof RsaPrivateKey || internalKey instanceof RsaPublicKey)) {

View File

@ -6,7 +6,7 @@ import { RsaPublicKey } from "./public_key";
export class RsaSsaProvider extends core.RsaSsaProvider {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<core.CryptoKeyPair> {
public async onGenerateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<globalThis.CryptoKeyPair> {
const keys = await RsaCrypto.generateKey(
{
...algorithm,
@ -38,7 +38,7 @@ export class RsaSsaProvider extends core.RsaSsaProvider {
return setCryptoKey(key);
}
public checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
public override checkCryptoKey(key: CryptoKey, keyUsage?: KeyUsage) {
super.checkCryptoKey(key, keyUsage);
const internalKey = getCryptoKey(key);
if (!(internalKey instanceof RsaPrivateKey || internalKey instanceof RsaPublicKey)) {

View File

@ -5,7 +5,7 @@ export class Sha1Provider extends core.ProviderCrypto {
public name = "SHA-1";
public usages = [];
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShaCrypto.digest(algorithm, data);
}

View File

@ -5,7 +5,7 @@ export class Sha256Provider extends core.ProviderCrypto {
public name = "SHA-256";
public usages = [];
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShaCrypto.digest(algorithm, data);
}

View File

@ -5,7 +5,7 @@ export class Sha384Provider extends core.ProviderCrypto {
public name = "SHA-384";
public usages = [];
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShaCrypto.digest(algorithm, data);
}

View File

@ -5,7 +5,7 @@ export class Sha512Provider extends core.ProviderCrypto {
public name = "SHA-512";
public usages = [];
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShaCrypto.digest(algorithm, data);
}

View File

@ -1,10 +1,12 @@
import crypto from "crypto";
import * as core from "webcrypto-core";
export class ShakeCrypto {
public static digest(algorithm: Algorithm, data: ArrayBuffer) {
const hash = crypto.createHash(algorithm.name.toLowerCase())
public static digest(algorithm: Required<core.ShakeParams>, data: ArrayBuffer) {
const hash = crypto.createHash(algorithm.name.toLowerCase(), {outputLength: algorithm.length})
.update(Buffer.from(data)).digest();
return new Uint8Array(hash).buffer;
}

View File

@ -1,11 +1,9 @@
import * as core from "webcrypto-core";
import { ShakeCrypto } from "./crypto";
export class Shake128Provider extends core.ProviderCrypto {
public name = "shake128";
public usages = [];
export class Shake128Provider extends core.Shake128Provider {
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Required<core.ShakeParams>, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShakeCrypto.digest(algorithm, data);
}

View File

@ -1,11 +1,9 @@
import * as core from "webcrypto-core";
import { ShakeCrypto } from "./crypto";
export class Shake256Provider extends core.ProviderCrypto {
public name = "shake256";
public usages = [];
export class Shake256Provider extends core.Shake256Provider {
public async onDigest(algorithm: Algorithm, data: ArrayBuffer): Promise<ArrayBuffer> {
public override async onDigest(algorithm: Required<core.ShakeParams>, data: ArrayBuffer): Promise<ArrayBuffer> {
return ShakeCrypto.digest(algorithm, data);
}

View File

@ -60,7 +60,7 @@ context("Crypto", () => {
hash: "SHA-256",
info: new Uint8Array([1, 2, 3, 4, 5]),
salt: new Uint8Array([1, 2, 3, 4, 5]),
} as globalThis.HkdfParams,
} as HkdfParams,
hkdf,
{
name: "HMAC",
@ -79,7 +79,7 @@ context("Crypto", () => {
const alg: globalThis.RsaHashedKeyGenParams = {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
publicExponent: new Uint8Array([1,0,1]),
publicExponent: new Uint8Array([1, 0, 1]),
modulusLength: 3072,
};
const keys = await crypto.subtle.generateKey(alg, false, ["sign", "verify"]);
@ -230,18 +230,38 @@ context("Crypto", () => {
const data = Buffer.from("test data");
it("shake128", async () => {
context("shake128", () => {
it("default", async () => {
const hash = await crypto.subtle.digest("shake128", data);
assert.strictEqual(Buffer.from(hash).toString("hex"), "ae3bdcf04986a8e7ddd99ac948254693");
});
it("shake256", async () => {
it("128 byte length", async () => {
const hash = await crypto.subtle.digest({ name: "shake128", length: 128 } as core.ShakeParams, data);
assert.strictEqual(Buffer.from(hash).toString("hex"), "ae3bdcf04986a8e7ddd99ac948254693fc32ca6ce3ed278c0c54127f072ba21e977d76aa76cab8f85f61c3e1fb7dab42c6b96d39f96fbd8cdcba7121e28cc97bb51f277a00398f99a9e6f11d027473cbffb3ac4ce444e2e8284caeca4e62f725d340fa3519eec7ca3eb4188607c26b0ecdf3750beba8882d6f2b734960cca914");
});
});
context("shake128", () => {
it("default", async () => {
const hash = await crypto.subtle.digest("shake256", data);
assert.strictEqual(Buffer.from(hash).toString("hex"), "be15253026b9a85e01ae54b1939284e8e514fbdad2a3bd5c1c0f437e60548e26");
});
it("256 byte length", async () => {
const hash = await crypto.subtle.digest({ name: "shake256", length: 256 } as core.ShakeParams, data);
assert.strictEqual(Buffer.from(hash).toString("hex"), "be15253026b9a85e01ae54b1939284e8e514fbdad2a3bd5c1c0f437e60548e262dd68c2a2f932847f9610eeb51f8ba1a180ca878c788e900d899538d45c9c4a6f1bf10d8502a7ccbd9fd540bd856591000700e10130673ef970ffb788afe08426648a216d032733b71e85f128f1ed9e4c8bd910b5000e8c381afb45735680eaf7cb5bf1ae4265ee0822dfe6a9426ff21e309398df57cbf5861f5947f3d261e2d4517ff0d1be988e7014a09c4312d37010cf0e47468c1cf832e6a61e9d9fe3b67e6ab265cb6d95ad7a1f863d71e0e6ed5cd17d568b86e99d84bdb970a580f551017b501ae6761d2d6de76a64385dc10f27d18c2564a6bfbfb1e3f335010bebdf8");
});
});
});
});

View File

@ -1,59 +1,19 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
"importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
"target": "es2019",
"module": "commonjs",
"lib": [
"dom"
],
"removeComments": true,
"importHelpers": true,
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"noImplicitOverride": true
},
"exclude": [
"build/**/*",
"index.d.ts"
]
}

2958
yarn.lock Normal file

File diff suppressed because it is too large Load Diff