go-blindsecp256k1/README.md
README.mdRaw
1# go-blindsecp256k1 [](https://godoc.org/github.com/arnaucube/go-blindsecp256k1) [](https://goreportcard.com/report/github.com/arnaucube/go-blindsecp256k1) [](https://github.com/arnaucube/go-blindsecp256k1/actions?query=workflow%3ATest)
2
3Blind signature over [secp256k1](https://en.bitcoin.it/wiki/Secp256k1), based on *"[New Blind Signature Schemes Based on the (Elliptic Curve) Discrete Logarithm Problem](https://sci-hub.st/10.1109/iccke.2013.6682844)"* paper by Hamid Mala & Nafiseh Nezhadansari.
4
5**WARNING**: this repo is experimental, do not use in production.
6
7The implementation of this repo is compatible with https://github.com/arnaucube/blindsecp256k1-js
8
9## Usage
10
11```go
12import (
13 [...]
14 "github.com/arnaucube/go-blindsecp256k1"
15)
16
17[...]
18// errors are not handled for simplicity of the example
19
20// signer: create new signer key pair
21sk, _ := blindsecp256k1.NewPrivateKey()
22signerPubK := sk.Public()
23
24// signer: when user requests new R parameter to blind a new msg,
25// create new signerR (public) with its secret k
26k, signerR, _ := blindsecp256k1.NewRequestParameters()
27
28// user: blinds the msg using signer's R
29msg := new(big.Int).SetBytes([]byte("test"))
30msgBlinded, userSecretData, _ := blindsecp256k1.Blind(msg, signerR)
31
32// signer: signs the blinded message using its private key & secret k
33sBlind, _ := sk.BlindSign(msgBlinded, k)
34
35// user: unblinds the blinded signature
36sig := blindsecp256k1.Unblind(sBlind, userSecretData)
37
38// signature can be verified with signer PublicKey
39verified := blindsecp256k1.Verify(msg, sig, signerPubK)
40assert.True(t, verified)
41```
42
43Compression & decompression (allows to compress a point & public key (64 bytes) into 33 bytes, and a signature (96 bytes) into 65 bytes):
44```go
45p := blindsecp256k1.G // take the generator point as an example
46
47// also, instead from G, we can start from a PublicKey, which can be converted
48// into a Point with
49p = pk.Point()
50
51// compress point
52b := p.Compress()
53fmt.Println(hex.EncodeToString(b[:]))
54
55// decompress point (recovering the original point)
56p2, _ := blindsecp256k1.DecompressPoint(b)
57assert.Equal(t, p, p2)
58
59
60// compress signature
61b = sig.Compress()
62fmt.Println(hex.EncodeToString(b[:])) // 65 bytes
63
64// decompress signature
65sig2, _ := DecompressSignature(b)
66assert.Equal(t, sig, sig2)
67```
68
69## WASM usage
70WASM wrappers for browser usage can be found at the [wasm](https://github.com/arnaucube/go-blindsecp256k1/tree/master/wasm/) directory with an example in html&js.