# ecdsa-secp256r1

> NIST P-256 Elliptic Curve Cryptography for Node and the Browsers

Latest version **1.3.3** (published 2018-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install ecdsa-secp256r1
pnpm add ecdsa-secp256r1
yarn add ecdsa-secp256r1
bun add ecdsa-secp256r1
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2018-10-11 |
| First published | 2018-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 23.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Improvertz |
| Maintainers | bdav24 |
| Keywords | crypto, cryptography, elliptic, ecdsa, secp256r1, nist p256, prime256v1, curve, sign, signing |

## Links

- npm: https://www.npmjs.com/package/ecdsa-secp256r1
- Repository: https://github.com/forevertz/ecdsa-secp256r1
- Homepage: https://github.com/forevertz/ecdsa-secp256r1#readme
- Issues: https://github.com/forevertz/ecdsa-secp256r1/issues
- npm.io page: https://npm.io/package/ecdsa-secp256r1

## Dependencies (2)

- [bn.js](https://npm.io/package/bn.js.md) ^4.11.8
- [asn1.js](https://npm.io/package/asn1.js.md) ^5.0.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.3.3 (latest) — 2018-10-11
- 1.3.2 — 2018-08-08
- 1.3.1 — 2018-08-03
- 1.3.0 — 2018-07-16
- 1.2.1 — 2018-07-03
- 1.2.0 — 2018-07-03
- 1.1.0 — 2018-07-02
- 1.0.1 — 2018-06-26
- 1.0.0 — 2018-06-26

## README

# ECDSA secp256r1

<a href="https://www.npmjs.com/package/ecdsa-secp256r1"><img alt="npm-status" src="https://img.shields.io/npm/v/ecdsa-secp256r1.svg?style=flat" /></a>
<a href="https://github.com/forevertz/ecdsa-secp256r1/blob/master/LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT_License-blue.svg?style=flat" /></a>

## Getting Started

```shell
$ yarn add ecdsa-secp256r1
```

## How to use

### Node.js

#### Create key

```javascript
const ECDSA = require('ecdsa-secp256r1')

const privateKey = ECDSA.generateKey()

privateKey.toJWK()
/*
{ kty: 'EC',
  crv: 'P-256',
  x: '4YdUIhIDncVu5tScgjxthiXOO_el11FWb56gR3qnhVQ',
  y: 'UyEvWOJbMZa9PtggGeRC9iQcAzOZZsyXpFE1qaF6jFk',
  d: 'TYVI2fW-nHSPGCx0MhWasg2Ggiyl1E_Kq4D1A5LmkxU' }
*/

privateKey.asPublic().toJWK()
/*
{ kty: 'EC',
  crv: 'P-256',
  x: '4YdUIhIDncVu5tScgjxthiXOO_el11FWb56gR3qnhVQ',
  y: 'UyEvWOJbMZa9PtggGeRC9iQcAzOZZsyXpFE1qaF6jFk' }
*/

privateKey.toPEM()
/*
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgTYVI2fW+nHSPGCx0
MhWasg2Ggiyl1E/Kq4D1A5LmkxWhRANCAAThh1QiEgOdxW7m1JyCPG2GJc4796XX
UVZvnqBHeqeFVFMhL1jiWzGWvT7YIBnkQvYkHAMzmWbMl6RRNamheoxZ
-----END PRIVATE KEY-----
*/

privateKey.asPublic().toPEM()
/*
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4YdUIhIDncVu5tScgjxthiXOO/el
11FWb56gR3qnhVRTIS9Y4lsxlr0+2CAZ5EL2JBwDM5lmzJekUTWpoXqMWQ==
-----END PUBLIC KEY-----
*/

privateKey.toCompressedPublicKey()
/*
A+GHVCISA53FbubUnII8bYYlzjv3pddRVm+eoEd6p4VU
*/
```

#### Sign

```javascript
const message = { text: 'hello' }
privateKey.sign(JSON.stringify(message))
/*
lY3Lf9xDtcsqom5IKu+ZyikxeYHlEuxnPfme4lMxp76NMkIm5BiLxVjbqBSo4itfT/LEuBCzMXl11cB0w/X8dA==
*/
```

#### Verify

```javascript
const key = 'A+GHVCISA53FbubUnII8bYYlzjv3pddRVm+eoEd6p4VU'
const publicKey = ECDSA.fromCompressedPublicKey(key) // or ECDSA.fromJWK
const message = { text: 'hello' }
const signature = 'lY3Lf9xDtcsqom5IKu+ZyikxeYHlEuxnPfme4lMxp76NMkIm5BiLxVjbqBSo4itfT/LEuBCzMXl11cB0w/X8dA=='

publicKey.verify(JSON.stringify(message), signature)
/*
true
*/
```

### Browsers

Support: https://caniuse.com/#feat=cryptography

```javascript
const ECDSA = require('ecdsa-secp256r1/browser')

const privateKey = await ECDSA.generateKey()

// API is the same as Node.js, except everything returns Promises
```

or

```html
<script src="/PATH/TO/browser.js"></script>
<script>
;(async function() {
  const privateKey = await ECDSA.generateKey()
  const message = { text: 'hello' }
  const signature = await privateKey.sign(JSON.stringify(message))
})()
</script>
```

### Thanks

Inspired from https://github.com/relocately/ec-key

---
_Source: https://npm.io/package/ecdsa-secp256r1 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
