diff --git a/webcrypto/elliptic_curve.go b/webcrypto/elliptic_curve.go index b4e1e19..c9ccc80 100644 --- a/webcrypto/elliptic_curve.go +++ b/webcrypto/elliptic_curve.go @@ -409,18 +409,23 @@ func pickEllipticCurve(k string) (elliptic.Curve, error) { } } -func exportECKey(alg string, ck *CryptoKey, format KeyFormat) (interface{}, error) { +func exportECKey(ck *CryptoKey, format KeyFormat) (interface{}, error) { if ck.handle == nil { return nil, NewError(OperationError, "key data is not accessible") } + alg, ok := ck.Algorithm.(EcKeyAlgorithm) + if !ok { + return nil, NewError(InvalidAccessError, "key algorithm is not a valid EC algorithm") + } + switch format { case RawKeyFormat: if ck.Type != PublicCryptoKeyType { return nil, NewError(InvalidAccessError, "key is not a valid elliptic curve public key") } - bytes, err := extractPublicKeyBytes(alg, ck.handle) + bytes, err := extractPublicKeyBytes(alg.Name, ck.handle) if err != nil { return nil, NewError(OperationError, "unable to extract public key data: "+err.Error()) } diff --git a/webcrypto/subtle_crypto.go b/webcrypto/subtle_crypto.go index 49e90a4..20980ee 100644 --- a/webcrypto/subtle_crypto.go +++ b/webcrypto/subtle_crypto.go @@ -881,7 +881,7 @@ func (sc *SubtleCrypto) ExportKey(format KeyFormat, key goja.Value) *goja.Promis return } case ECDH, ECDSA: - result, err = exportECKey(keyAlgorithmName, ck, format) + result, err = exportECKey(ck, format) if err != nil { reject(err) return