Skip to content

Commit 21bf0b5

Browse files
committed
Update README.md
1 parent ebb8615 commit 21bf0b5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
11
# js-secp256k1
22
[![Build Status](https://travis-ci.org/sc0Vu/js-secp256k1.svg?branch=master)](https://travis-ci.org/sc0Vu/js-secp256k1)
3+
[![codecov](https://codecov.io/gh/sc0Vu/js-secp256k1/branch/master/graph/badge.svg)](https://codecov.io/gh/sc0Vu/js-secp256k1)
4+
35
Compiled webassembly of bitcoin secp256k1
6+
7+
# Install
8+
9+
* install library
10+
11+
```BASH
12+
$ npm install js-secp256k1
13+
```
14+
15+
# Build with emscripten
16+
17+
You can build secp256k1 wasm yourself with emscripten. We build two version of secp256k1 - node and web. The only difference is that there is no file system in web version.
18+
19+
```BASH
20+
$ sh build.sh
21+
```
22+
23+
After build wasm files, you should build javascript library again.
24+
25+
```BASH
26+
$ npm run build
27+
```
28+
29+
# Usage
30+
31+
* Hash message
32+
```JS
33+
// for nodejs
34+
const secp256k1Async = require('js-secp256k1/dist/node-bundle')
35+
// or
36+
const secp256k1Async = require('js-secp256k1').node
37+
38+
// for browser
39+
const secp256k1Async = require('js-secp256k1/dist/browser-bundle')
40+
// or
41+
const secp256k1Async = require('js-secp256k1').browser
42+
43+
// initialize the library
44+
secp256k1 = await secp256k1Async()
45+
46+
// generate public key from private key
47+
const privKey = Buffer.from([......])
48+
let pubkey = secp256k1.privkeyToPubkey(privkey)
49+
50+
// serialize public key
51+
let compressed = true
52+
let cpubkey = secp256k1.serializePubkey(pubkey, compressed)
53+
54+
// sign
55+
// signature {
56+
// signature: <Buffer/Uint8Array>,
57+
// recovery: <int>
58+
// }
59+
let sig = secp256k1.sign(msg, privkey)
60+
61+
// verify
62+
let isVerified secp256k1.verify(msg, sig.signature, pubkey)
63+
64+
// recover
65+
let rpubkey = secp256k1.recover(msg, sig.signature, sig.recovery)
66+
```
67+
68+
# License
69+
70+
MIT
71+

0 commit comments

Comments
 (0)