Skip to content

Commit 329b733

Browse files
authored
fix: update types for subtlecrypto to show we support a subset of importKey/sign/verify (#568)
1 parent a030a03 commit 329b733

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

types/globals.d.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,13 +1698,47 @@ declare class SubtleCrypto {
16981698
// generateKey(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>;
16991699
// generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair | CryptoKey>;
17001700
// importKey(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>;
1701+
importKey(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | RsaHashedImportParams, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>;
17011702
// importKey(format: Exclude<KeyFormat, "jwk">, keyData: BufferSource, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
17021703
// sign(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
1704+
sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
17031705
// unwrapKey(format: KeyFormat, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, unwrappedKeyAlgorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
17041706
// verify(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
1707+
verify(algorithm: AlgorithmIdentifier, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
17051708
// wrapKey(format: KeyFormat, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams): Promise<ArrayBuffer>;
17061709
}
17071710

1711+
interface RsaHashedImportParams extends Algorithm {
1712+
hash: HashAlgorithmIdentifier;
1713+
}
1714+
type HashAlgorithmIdentifier = AlgorithmIdentifier;
1715+
1716+
interface JsonWebKey {
1717+
alg?: string;
1718+
crv?: string;
1719+
d?: string;
1720+
dp?: string;
1721+
dq?: string;
1722+
e?: string;
1723+
ext?: boolean;
1724+
k?: string;
1725+
key_ops?: string[];
1726+
kty?: string;
1727+
n?: string;
1728+
oth?: RsaOtherPrimesInfo[];
1729+
p?: string;
1730+
q?: string;
1731+
qi?: string;
1732+
use?: string;
1733+
x?: string;
1734+
y?: string;
1735+
}
1736+
1737+
interface RsaOtherPrimesInfo {
1738+
d?: string;
1739+
r?: string;
1740+
t?: string;
1741+
}
17081742

17091743
/**
17101744
* The Crypto interface as [specified by WHATWG](https://w3c.github.io/webcrypto/#crypto-interface)
@@ -1731,3 +1765,33 @@ declare var Crypto: {
17311765
*/
17321766
declare var crypto: Crypto;
17331767

1768+
/**
1769+
* The CryptoKey dictionary of the Web Crypto API represents a cryptographic key.
1770+
* Available only in secure contexts.
1771+
*
1772+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey)
1773+
*/
1774+
interface CryptoKey {
1775+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) */
1776+
readonly algorithm: KeyAlgorithm;
1777+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) */
1778+
readonly extractable: boolean;
1779+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) */
1780+
readonly type: KeyType;
1781+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) */
1782+
readonly usages: KeyUsage[];
1783+
}
1784+
1785+
declare var CryptoKey: {
1786+
prototype: CryptoKey;
1787+
new(): CryptoKey;
1788+
};
1789+
1790+
1791+
interface KeyAlgorithm {
1792+
name: string;
1793+
}
1794+
1795+
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
1796+
type KeyType = "private" | "public" | "secret";
1797+
type KeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey";

0 commit comments

Comments
 (0)