# ecdsa-sig-formatter

[![Build Status](https://travis-ci.org/Brightspace/node-ecdsa-sig-formatter.svg?branch=master)](https://travis-ci.org/Brightspace/node-ecdsa-sig-formatter) [![Coverage Status](https://coveralls.io/repos/Brightspace/node-ecdsa-sig-formatter/badge.svg)](https://coveralls.io/r/Brightspace/node-ecdsa-sig-formatter)

Translate between JOSE and ASN.1/DER encodings for ECDSA signatures

## Install

```sh
npm install ecdsa-sig-formatter --save
```

## Usage

```js
var format = require('ecdsa-sig-formatter');

var derSignature = '..'; // asn.1/DER encoded ecdsa signature

var joseSignature = format.derToJose(derSignature);

```

### API

***

#### `.derToJose(Buffer|String signature, String alg)` -> `String`

Convert the ASN.1/DER encoded signature to a JOSE-style concatenated signature. Returns a *base64 url* encoded `String`.

* If *signature* is a `String`, it should be *base64* encoded
* *alg* must be one of *ES256*, *ES384* or *ES512*

***

#### `.joseToDer(Buffer|String signature, String alg)` -> `Buffer`

Convert the JOSE-style concatenated signature to an ASN.1/DER encoded signature. Returns a `Buffer`

* If *signature* is a `String`, it should be *base64 url* encoded
* *alg* must be one of *ES256*, *ES384* or *ES512*

## Contributing

1. **Fork** the repository. Committing directly against this repository is highly discouraged.
2. Make your modifications in a branch, updating and writing new unit tests as necessary in the `spec` directory.
3. Ensure that all tests pass with `npm test`
4. `rebase` your changes against master. *Do not merge*.
5. Submit a pull request to this repository. Wait for tests to run and someone to chime in.

### Code Style

This repository is configured with [EditorConfig](http://editorconfig.org/) and [ESLint](http://eslint.org) rules.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mediamagic.dev/product-docs/services/graphql-gateway/node_modules/ecdsa-sig-formatter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
