77 ArrayPrototypeIncludes,
88 ArrayPrototypePush,
99 MathFloor,
10- Promise,
1110 SafeSet,
1211 TypedArrayPrototypeSlice,
1312} = primordials ;
@@ -46,6 +45,7 @@ const {
4645
4746const {
4847 lazyDOMException,
48+ promisify,
4949} = require ( 'internal/util' ) ;
5050
5151const { PromiseReject } = primordials ;
@@ -57,11 +57,12 @@ const {
5757} = require ( 'internal/crypto/keys' ) ;
5858
5959const {
60- generateKey,
60+ generateKey : _generateKey ,
6161} = require ( 'internal/crypto/keygen' ) ;
6262
6363const kMaxCounterLength = 128 ;
6464const kTagLengths = [ 32 , 64 , 96 , 104 , 112 , 120 , 128 ] ;
65+ const generateKey = promisify ( _generateKey ) ;
6566
6667function getAlgorithmName ( name , length ) {
6768 switch ( name ) {
@@ -239,22 +240,19 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) {
239240 'SyntaxError' ) ;
240241 }
241242
242- return new Promise ( ( resolve , reject ) => {
243- generateKey ( 'aes' , { length } , ( err , key ) => {
244- if ( err ) {
245- return reject ( lazyDOMException (
246- 'The operation failed for an operation-specific reason ' +
247- `[${ err . message } ]` ,
248- 'OperationError' ) ) ;
249- }
250-
251- resolve ( new InternalCryptoKey (
252- key ,
253- { name, length } ,
254- ArrayFrom ( usagesSet ) ,
255- extractable ) ) ;
256- } ) ;
243+ const key = await generateKey ( 'aes' , { length } ) . catch ( ( err ) => {
244+ // TODO(@panva): add err as cause to DOMException
245+ throw lazyDOMException (
246+ 'The operation failed for an operation-specific reason' +
247+ `[${ err . message } ]` ,
248+ 'OperationError' ) ;
257249 } ) ;
250+
251+ return new InternalCryptoKey (
252+ key ,
253+ { name, length } ,
254+ ArrayFrom ( usagesSet ) ,
255+ extractable ) ;
258256}
259257
260258async function aesImportKey (