@@ -11,6 +11,8 @@ const {
11
11
DataViewPrototypeGetByteOffset,
12
12
FunctionPrototypeBind,
13
13
Number,
14
+ ObjectDefineProperty,
15
+ ObjectEntries,
14
16
ObjectKeys,
15
17
ObjectPrototypeHasOwnProperty,
16
18
Promise,
@@ -63,6 +65,7 @@ const { Buffer } = require('buffer');
63
65
64
66
const {
65
67
cachedResult,
68
+ emitExperimentalWarning,
66
69
filterDuplicateStrings,
67
70
lazyDOMException,
68
71
} = require ( 'internal/util' ) ;
@@ -168,15 +171,6 @@ const kNamedCurveAliases = {
168
171
169
172
const kAesKeyLengths = [ 128 , 192 , 256 ] ;
170
173
171
- // These are the only hash algorithms we currently support via
172
- // the Web Crypto API.
173
- const kHashTypes = [
174
- 'SHA-1' ,
175
- 'SHA-256' ,
176
- 'SHA-384' ,
177
- 'SHA-512' ,
178
- ] ;
179
-
180
174
const kSupportedAlgorithms = {
181
175
'digest' : {
182
176
'SHA-1' : null ,
@@ -195,26 +189,18 @@ const kSupportedAlgorithms = {
195
189
'AES-GCM' : 'AesKeyGenParams' ,
196
190
'AES-KW' : 'AesKeyGenParams' ,
197
191
'HMAC' : 'HmacKeyGenParams' ,
198
- 'X25519' : null ,
199
- 'Ed25519' : null ,
200
- 'X448' : null ,
201
- 'Ed448' : null ,
202
192
} ,
203
193
'sign' : {
204
194
'RSASSA-PKCS1-v1_5' : null ,
205
195
'RSA-PSS' : 'RsaPssParams' ,
206
196
'ECDSA' : 'EcdsaParams' ,
207
197
'HMAC' : null ,
208
- 'Ed25519' : null ,
209
- 'Ed448' : 'Ed448Params' ,
210
198
} ,
211
199
'verify' : {
212
200
'RSASSA-PKCS1-v1_5' : null ,
213
201
'RSA-PSS' : 'RsaPssParams' ,
214
202
'ECDSA' : 'EcdsaParams' ,
215
203
'HMAC' : null ,
216
- 'Ed25519' : null ,
217
- 'Ed448' : 'Ed448Params' ,
218
204
} ,
219
205
'importKey' : {
220
206
'RSASSA-PKCS1-v1_5' : 'RsaHashedImportParams' ,
@@ -229,17 +215,11 @@ const kSupportedAlgorithms = {
229
215
'AES-CBC' : null ,
230
216
'AES-GCM' : null ,
231
217
'AES-KW' : null ,
232
- 'Ed25519' : null ,
233
- 'X25519' : null ,
234
- 'Ed448' : null ,
235
- 'X448' : null ,
236
218
} ,
237
219
'deriveBits' : {
238
220
'HKDF' : 'HkdfParams' ,
239
221
'PBKDF2' : 'Pbkdf2Params' ,
240
222
'ECDH' : 'EcdhKeyDeriveParams' ,
241
- 'X25519' : 'EcdhKeyDeriveParams' ,
242
- 'X448' : 'EcdhKeyDeriveParams' ,
243
223
} ,
244
224
'encrypt' : {
245
225
'RSA-OAEP' : 'RsaOaepParams' ,
@@ -270,6 +250,44 @@ const kSupportedAlgorithms = {
270
250
} ,
271
251
} ;
272
252
253
+ const experimentalAlgorithms = {
254
+ 'X25519' : {
255
+ generateKey : null ,
256
+ importKey : null ,
257
+ deriveBits : 'EcdhKeyDeriveParams' ,
258
+ } ,
259
+ 'Ed25519' : {
260
+ generateKey : null ,
261
+ sign : null ,
262
+ verify : null ,
263
+ importKey : null ,
264
+ } ,
265
+ 'X448' : {
266
+ generateKey : null ,
267
+ importKey : null ,
268
+ deriveBits : 'EcdhKeyDeriveParams' ,
269
+ } ,
270
+ 'Ed448' : {
271
+ generateKey : null ,
272
+ sign : 'Ed448Params' ,
273
+ verify : 'Ed448Params' ,
274
+ importKey : null ,
275
+ } ,
276
+ } ;
277
+
278
+ for ( const { 0 : name , 1 : ops } of ObjectEntries ( experimentalAlgorithms ) ) {
279
+ for ( const { 0 : op , 1 : dict } of ObjectEntries ( ops ) ) {
280
+ ObjectDefineProperty ( kSupportedAlgorithms [ op ] , name , {
281
+ get ( ) {
282
+ emitExperimentalWarning ( `The ${ name } Web Crypto API algorithm` ) ;
283
+ return dict ;
284
+ } ,
285
+ __proto__ : null ,
286
+ enumerable : true ,
287
+ } ) ;
288
+ }
289
+ }
290
+
273
291
const simpleAlgorithmDictionaries = {
274
292
AesGcmParams : { iv : 'BufferSource' , additionalData : 'BufferSource' } ,
275
293
RsaHashedKeyGenParams : { hash : 'HashAlgorithmIdentifier' } ,
@@ -594,7 +612,6 @@ module.exports = {
594
612
setEngine,
595
613
toBuf,
596
614
597
- kHashTypes,
598
615
kNamedCurveAliases,
599
616
kAesKeyLengths,
600
617
normalizeAlgorithm,
0 commit comments