SubtleCrypto.webidl (6495B)
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. 5 * 6 * The origin of this IDL file is 7 * http://www.w3.org/TR/WebCryptoAPI/ 8 */ 9 10 typedef DOMString KeyType; 11 typedef DOMString KeyUsage; 12 typedef DOMString NamedCurve; 13 typedef Uint8Array BigInteger; 14 15 /***** Algorithm dictionaries *****/ 16 17 dictionary Algorithm { 18 required DOMString name; 19 }; 20 21 [GenerateInit] 22 dictionary AesCbcParams : Algorithm { 23 required BufferSource iv; 24 }; 25 26 [GenerateInit] 27 dictionary AesCtrParams : Algorithm { 28 required BufferSource counter; 29 required [EnforceRange] octet length; 30 }; 31 32 [GenerateInit] 33 dictionary AesGcmParams : Algorithm { 34 required BufferSource iv; 35 BufferSource additionalData; 36 [EnforceRange] octet tagLength; 37 }; 38 39 dictionary HmacImportParams : Algorithm { 40 required AlgorithmIdentifier hash; 41 }; 42 43 [GenerateInit] 44 dictionary Pbkdf2Params : Algorithm { 45 required BufferSource salt; 46 required [EnforceRange] unsigned long iterations; 47 required AlgorithmIdentifier hash; 48 }; 49 50 [GenerateInit] 51 dictionary RsaHashedImportParams { 52 required AlgorithmIdentifier hash; 53 }; 54 55 dictionary AesKeyGenParams : Algorithm { 56 required [EnforceRange] unsigned short length; 57 }; 58 59 [GenerateInit] 60 dictionary HmacKeyGenParams : Algorithm { 61 required AlgorithmIdentifier hash; 62 [EnforceRange] unsigned long length; 63 }; 64 65 [GenerateInit] 66 dictionary RsaHashedKeyGenParams : Algorithm { 67 required [EnforceRange] unsigned long modulusLength; 68 required BigInteger publicExponent; 69 required AlgorithmIdentifier hash; 70 }; 71 72 [GenerateInit] 73 dictionary RsaOaepParams : Algorithm { 74 BufferSource label; 75 }; 76 77 [GenerateInit] 78 dictionary RsaPssParams : Algorithm { 79 required [EnforceRange] unsigned long saltLength; 80 }; 81 82 [GenerateInit] 83 dictionary EcKeyGenParams : Algorithm { 84 required NamedCurve namedCurve; 85 }; 86 87 [GenerateInit] 88 dictionary AesDerivedKeyParams : Algorithm { 89 required [EnforceRange] unsigned long length; 90 }; 91 92 [GenerateInit] 93 dictionary HmacDerivedKeyParams : HmacImportParams { 94 [EnforceRange] unsigned long length; 95 }; 96 97 [GenerateInit] 98 dictionary EcdhKeyDeriveParams : Algorithm { 99 required CryptoKey public; 100 }; 101 102 [GenerateInit] 103 dictionary DhImportKeyParams : Algorithm { 104 required BigInteger prime; 105 required BigInteger generator; 106 }; 107 108 [GenerateInit] 109 dictionary EcdsaParams : Algorithm { 110 required AlgorithmIdentifier hash; 111 }; 112 113 [GenerateInit] 114 dictionary EcKeyImportParams : Algorithm { 115 NamedCurve namedCurve; 116 }; 117 118 [GenerateInit] 119 dictionary HkdfParams : Algorithm { 120 required AlgorithmIdentifier hash; 121 required BufferSource salt; 122 required BufferSource info; 123 }; 124 125 /***** JWK *****/ 126 127 dictionary RsaOtherPrimesInfo { 128 // The following fields are defined in Section 6.3.2.7 of JSON Web Algorithms 129 required DOMString r; 130 required DOMString d; 131 required DOMString t; 132 }; 133 134 [GenerateInitFromJSON, GenerateToJSON] 135 dictionary JsonWebKey { 136 // The following fields are defined in Section 3.1 of JSON Web Key 137 required DOMString kty; 138 DOMString use; 139 sequence<DOMString> key_ops; 140 DOMString alg; 141 142 // The following fields are defined in JSON Web Key Parameters Registration 143 boolean ext; 144 145 // The following fields are defined in Section 6 of JSON Web Algorithms 146 DOMString crv; 147 DOMString x; 148 DOMString y; 149 DOMString d; 150 DOMString n; 151 DOMString e; 152 DOMString p; 153 DOMString q; 154 DOMString dp; 155 DOMString dq; 156 DOMString qi; 157 sequence<RsaOtherPrimesInfo> oth; 158 DOMString k; 159 }; 160 161 162 /***** The Main API *****/ 163 164 [Serializable, 165 SecureContext, 166 Exposed=(Window,Worker)] 167 interface CryptoKey { 168 readonly attribute KeyType type; 169 readonly attribute boolean extractable; 170 [Cached, Constant, Throws] readonly attribute object algorithm; 171 [Cached, Constant, Frozen] readonly attribute sequence<KeyUsage> usages; 172 }; 173 174 [GenerateConversionToJS] 175 dictionary CryptoKeyPair { 176 required CryptoKey publicKey; 177 required CryptoKey privateKey; 178 }; 179 180 typedef DOMString KeyFormat; 181 typedef (object or DOMString) AlgorithmIdentifier; 182 183 [Exposed=(Window,Worker), 184 SecureContext] 185 interface SubtleCrypto { 186 [NewObject] 187 Promise<any> encrypt(AlgorithmIdentifier algorithm, 188 CryptoKey key, 189 BufferSource data); 190 [NewObject] 191 Promise<any> decrypt(AlgorithmIdentifier algorithm, 192 CryptoKey key, 193 BufferSource data); 194 [NewObject] 195 Promise<any> sign(AlgorithmIdentifier algorithm, 196 CryptoKey key, 197 BufferSource data); 198 [NewObject] 199 Promise<any> verify(AlgorithmIdentifier algorithm, 200 CryptoKey key, 201 BufferSource signature, 202 BufferSource data); 203 [NewObject] 204 Promise<any> digest(AlgorithmIdentifier algorithm, 205 BufferSource data); 206 207 [NewObject] 208 Promise<any> generateKey(AlgorithmIdentifier algorithm, 209 boolean extractable, 210 sequence<KeyUsage> keyUsages ); 211 [NewObject] 212 Promise<any> deriveKey(AlgorithmIdentifier algorithm, 213 CryptoKey baseKey, 214 AlgorithmIdentifier derivedKeyType, 215 boolean extractable, 216 sequence<KeyUsage> keyUsages ); 217 [NewObject] 218 Promise<any> deriveBits(AlgorithmIdentifier algorithm, 219 CryptoKey baseKey, 220 optional unsigned long? length = null); 221 222 [NewObject] 223 Promise<any> importKey(KeyFormat format, 224 object keyData, 225 AlgorithmIdentifier algorithm, 226 boolean extractable, 227 sequence<KeyUsage> keyUsages ); 228 [NewObject] 229 Promise<any> exportKey(KeyFormat format, CryptoKey key); 230 231 [NewObject] 232 Promise<any> wrapKey(KeyFormat format, 233 CryptoKey key, 234 CryptoKey wrappingKey, 235 AlgorithmIdentifier wrapAlgorithm); 236 237 [NewObject] 238 Promise<any> unwrapKey(KeyFormat format, 239 BufferSource wrappedKey, 240 CryptoKey unwrappingKey, 241 AlgorithmIdentifier unwrapAlgorithm, 242 AlgorithmIdentifier unwrappedKeyAlgorithm, 243 boolean extractable, 244 sequence<KeyUsage> keyUsages ); 245 };