Registry / security / ecdsa-sig-formatter

ecdsa-sig-formatter

JSON →
library1.0.11jsnpmunverified

Translate ECDSA signatures between ASN.1/DER and JOSE-style concatenation formats. Version 1.0.11 is the latest stable version; the package is rarely updated but widely depended on by libraries like jsonwebtoken. It converts DER-encoded signatures (common in OpenSSL, crypto libraries) to the concatenated r||s format used by JWT/JOSE standards (ES256, ES384, ES512), and vice versa. It handles base64 encoding/decoding and works with Buffer or string input. Implements no crypto logic itself, only format translation.

npm install ecdsa-sig-formatter
INSTALL
IMPORT
SIG · ECDSA-SIG-FORMATTE
E
ecdsa-sig-formatter
securityjavascriptv1.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

derToJose
✓ import { derToJose } from 'ecdsa-sig-formatter';
✗ const derToJose = require('ecdsa-sig-formatter').derToJose;
Named export. For TypeScript, use named import with ES module syntax.
joseToDer
✓ import { joseToDer } from 'ecdsa-sig-formatter';
✗ const joseToDer = require('ecdsa-sig-formatter').joseToDer;
Named export. For TypeScript, use named import with ES module syntax.
full module
✓ import * as format from 'ecdsa-sig-formatter'; format.derToJose(derSig, 'ES256');
✗ const format = require('ecdsa-sig-formatter');
ESM namespace import works; CJS require also works but is less ideal for TypeScript.

Demonstrates converting DER-encoded ECDSA signature to JOSE format and back using derToJose and joseToDer.

import { derToJose, joseToDer } from 'ecdsa-sig-formatter'; // DER-encoded signature (e.g., from crypto.createSign) const derSignature = Buffer.from( '304402202b3b6b8b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b022043b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b9b', 'hex' ); // Convert to JOSE base64url format const joseSig = derToJose(derSignature, 'ES256'); console.log('JOSE signature:', joseSig); // Convert back to DER const derSigAgain = joseToDer(joseSig, 'ES256'); console.log('DER signature:', derSigAgain.toString('hex'));
Debug
Known issues
gotchaThe alg parameter must be exactly one of 'ES256', 'ES384', or 'ES512'. Passing an invalid algorithm string will cause an error.
fix
Ensure alg is one of the supported JOSE algorithm names.
affects: >=1.0.0
gotchaInput signature string must be base64 encoded (for derToJose) or base64url encoded (for joseToDer). Otherwise, conversion may silently fail or produce incorrect output.
fix
Use appropriate base64 encoding before passing string arguments.
affects: >=1.0.0
gotchaThe package does not validate the signature itself; it assumes the input is a valid ECDSA signature in the expected format. Invalid DER or JOSE signatures may cause unexpected errors or buffers of wrong length.
fix
Validate the input signature format before calling these functions.
affects: >=1.0.0
deprecatedNo deprecation warnings have been noted, but the package is rarely updated and may be considered legacy. Consider using crypto.subtle or jose library for new projects.
fix
For new projects, evaluate if this dependency is necessary; prefer native Web Crypto API or comprehensive JWT libraries.
affects: >=1.0.11
Errors
Common errors & fixes
Error: Invalid algorithm. Supported algorithms: ES256, ES384, ES512
Passing an unsupported algorithm name (e.g., 'ES256K') to derToJose or joseToDer.
fix
Use only 'ES256', 'ES384', or 'ES512' as the second argument.
Error: Unsupported input type. Signature must be a Buffer or a string.
Passing a number, null, undefined, or object as the signature argument.
fix
Ensure the signature is either a Buffer or a string (base64 or base64url encoded).
Error: Invalid base64 string
Passing a string that is not valid base64 to derToJose when signature is a string.
fix
Ensure the string is base64 encoded (without padding or with padding) before passing to derToJose. For joseToDer, the string should be base64url encoded.
TypeError: signature must be a Buffer or a string
Calling derToJose or joseToDer with a non-string/non-Buffer argument (e.g., a Uint8Array or ArrayBuffer).
fix
Convert Uint8Array to Buffer first: Buffer.from(uint8Array).
Upgrade
Version history
1.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
26
Amazon
1
Resources
ecdsa-sig-formatter — npm install ecdsa-sig-formatter · libregistry