javascriptcryptographyecdsajose

subtle crypto with ECDSA : Cannot create a key using the specified key usages


I wanted to import an ECDSA private key in Chrome to sign some data, tried yet with crypto.subtle.importKey: feeded the importKey with a derivated private key using secp256k1.

When trying to use the lib, I got stuck with the following error: Cannot create a key using the specified key usages.

The code:

const browserKey = await crypto.subtle.importKey(
    'raw',
    derivatedNode.privateKey, // ArrayBuffer
    {
        name: 'ECDSA',
        namedCurve: 'P-256' // Haven't found better fit for secp256k1?
    },
    false,
    ['sign']
);

Double-checked my private key, got Uint8Array(32) which seems to be usually OK with importKey.

Any help appreciated.


Solution

  • Web Cryptography API does not support the secp256k1 curve. It will also not support it in the future.