@@ -18,13 +18,6 @@ const {
1818} = internalBinding ( 'crypto' ) ;
1919
2020const {
21- codes : {
22- ERR_MISSING_OPTION ,
23- }
24- } = require ( 'internal/errors' ) ;
25-
26- const {
27- getArrayBufferOrView,
2821 getUsagesUnion,
2922 hasAnyNotIn,
3023 jobPromise,
@@ -86,7 +79,6 @@ function verifyAcceptableEcKeyUse(name, type, usages) {
8679
8780function createECPublicKeyRaw ( namedCurve , keyData ) {
8881 const handle = new KeyObjectHandle ( ) ;
89- keyData = getArrayBufferOrView ( keyData , 'keyData' ) ;
9082
9183 if ( ! handle . initECRaw ( kNamedCurveAliases [ namedCurve ] , keyData ) ) {
9284 throw lazyDOMException ( 'Invalid keyData' , 'DataError' ) ;
@@ -215,12 +207,14 @@ async function ecImportKey(
215207 break ;
216208 }
217209 case 'jwk' : {
218- if ( keyData == null || typeof keyData !== 'object' )
219- throw lazyDOMException ( 'Invalid JWK keyData' , 'DataError' ) ;
210+ if ( ! keyData . kty )
211+ throw lazyDOMException ( 'Invalid keyData' , 'DataError' ) ;
220212 if ( keyData . kty !== 'EC' )
221- throw lazyDOMException ( 'Invalid key type ' , 'DataError' ) ;
213+ throw lazyDOMException ( 'Invalid JWK "kty" Parameter ' , 'DataError' ) ;
222214 if ( keyData . crv !== namedCurve )
223- throw lazyDOMException ( 'Named curve mismatch' , 'DataError' ) ;
215+ throw lazyDOMException (
216+ 'JWK "crv" does not match the requested algorithm' ,
217+ 'DataError' ) ;
224218
225219 if ( keyData . d !== undefined ) {
226220 verifyAcceptableEcKeyUse ( name , 'private' , usagesSet ) ;
@@ -229,37 +223,38 @@ async function ecImportKey(
229223 }
230224
231225 if ( usagesSet . size > 0 && keyData . use !== undefined ) {
232- if ( algorithm . name === 'ECDSA' && keyData . use !== 'sig' )
233- throw lazyDOMException ( 'Invalid use type' , 'DataError' ) ;
234- if ( algorithm . name === 'ECDH' && keyData . use !== 'enc' )
235- throw lazyDOMException ( 'Invalid use type' , 'DataError' ) ;
226+ const checkUse = name === 'ECDH' ? 'enc' : 'sig' ;
227+ if ( keyData . use !== checkUse )
228+ throw lazyDOMException ( 'Invalid JWK "use" Parameter' , 'DataError' ) ;
236229 }
237230
238231 validateKeyOps ( keyData . key_ops , usagesSet ) ;
239232
240233 if ( keyData . ext !== undefined &&
241234 keyData . ext === false &&
242235 extractable === true ) {
243- throw lazyDOMException ( 'JWK is not extractable' , 'DataError' ) ;
236+ throw lazyDOMException (
237+ 'JWK "ext" Parameter and extractable mismatch' ,
238+ 'DataError' ) ;
244239 }
245240
246241 if ( algorithm . name === 'ECDSA' && keyData . alg !== undefined ) {
247- if ( typeof keyData . alg !== 'string' )
248- throw lazyDOMException ( 'Invalid alg' , 'DataError' ) ;
249242 let algNamedCurve ;
250243 switch ( keyData . alg ) {
251244 case 'ES256' : algNamedCurve = 'P-256' ; break ;
252245 case 'ES384' : algNamedCurve = 'P-384' ; break ;
253246 case 'ES512' : algNamedCurve = 'P-521' ; break ;
254247 }
255248 if ( algNamedCurve !== namedCurve )
256- throw lazyDOMException ( 'Named curve mismatch' , 'DataError' ) ;
249+ throw lazyDOMException (
250+ 'JWK "alg" does not match the requested algorithm' ,
251+ 'DataError' ) ;
257252 }
258253
259254 const handle = new KeyObjectHandle ( ) ;
260255 const type = handle . initJwk ( keyData , namedCurve ) ;
261256 if ( type === undefined )
262- throw lazyDOMException ( 'Invalid JWK keyData ' , 'DataError' ) ;
257+ throw lazyDOMException ( 'Invalid JWK' , 'DataError' ) ;
263258 keyObject = type === kKeyTypePrivate ?
264259 new PrivateKeyObject ( handle ) :
265260 new PublicKeyObject ( handle ) ;
@@ -301,8 +296,6 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) {
301296 if ( key . type !== type )
302297 throw lazyDOMException ( `Key must be a ${ type } key` , 'InvalidAccessError' ) ;
303298
304- if ( hash === undefined )
305- throw new ERR_MISSING_OPTION ( 'algorithm.hash' ) ;
306299 const hashname = normalizeHashName ( hash . name ) ;
307300
308301 return jobPromise ( ( ) => new SignJob (
0 commit comments