https://github.com/tradle/react-native-ecc
basic elliptic curve crypto for React Native
https://github.com/tradle/react-native-ecc
Last synced: 8 months ago
JSON representation
basic elliptic curve crypto for React Native
- Host: GitHub
- URL: https://github.com/tradle/react-native-ecc
- Owner: tradle
- License: mit
- Created: 2015-12-27T15:07:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-09T15:50:26.000Z (over 2 years ago)
- Last Synced: 2025-04-14T23:52:03.438Z (about 1 year ago)
- Language: Objective-C
- Size: 64.5 KB
- Stars: 42
- Watchers: 9
- Forks: 18
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-ecc
basic elliptic curve crypto for React Native
**this module is used by [Tradle](https://github.com/tradle/tim)**
## Installation
See [Linking Libraries](http://facebook.github.io/react-native/docs/linking-libraries-ios.html)
## Usage
```js
import * as ec from 'react-native-ecc'
import { Buffer } from 'buffer'
// if you want to be able to find your keys
// next time, make sure to use the same service ID
ec.setServiceID('be.excellent.to.each.other')
// optional
// ec.setAccessGroup('dsadjsakd.com.app.awesome.my')
// this library allows you to sign 32 byte hashes (e.g. sha256 hashes)
const msg = new Buffer('hey ho')
// check ec.curves for supported curves
const curve = 'p256'
ec.keyPair(curve, function (err, key) {
// pub tested for compatibility with npm library "elliptic"
const pub = key.pub
console.log('pub', key.pub.toString('hex'))
// look up the key later like this:
// const key = ec.keyFromPublic(pub)
key.sign({
data: msg,
algorithm: 'sha256'
}, function (err, sig) {
// signatures tested for compatibility with npm library "elliptic"
console.log('sig', sig.toString('hex'))
key.verify({
algorithm: 'sha256',
data: msg,
sig: sig
}, function (err, verified) {
console.log('verified:', verified)
})
})
})
```