This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
webcrypto/packages/core/src/crypto_key.ts

31 lines
855 B
TypeScript

import * as types from "@peculiar/webcrypto-types";
const KEY_TYPES = ["secret", "private", "public"];
export class CryptoKey implements types.CryptoKey {
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();
key.algorithm = algorithm;
key.type = type;
key.extractable = extractable;
key.usages = usages;
return key;
}
public static isKeyType(data: any): data is types.KeyType {
return KEY_TYPES.indexOf(data) !== -1;
}
public algorithm: types.KeyAlgorithm = { name: "" };
public type: types.KeyType = "secret";
public usages: types.KeyUsages = [];
public extractable: boolean = false;
// @internal
public get [Symbol.toStringTag]() {
return "CryptoKey";
}
}