-
Notifications
You must be signed in to change notification settings - Fork 254
/
blind.go
48 lines (37 loc) · 1.07 KB
/
blind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"crypto/rand"
"fmt"
btcutil "github.com/33cn/chain33/wallet/bipwallet/btcutilecc"
)
func main() {
signer := new(btcutil.BlindSignerState)
requester := new(btcutil.BlindRequesterState)
// requester: message that needs to be blind signed
m, err := btcutil.RandFieldElement(rand.Reader)
maybePanic(err)
fmt.Printf("m = %x\n", m)
// requester: ask signer to start the protocol
Q, R := btcutil.BlindSession(signer)
fmt.Println("")
// requester: blind message
mHat := btcutil.BlindMessage(requester, Q, R, m)
// signer: create blind signature
sHat := btcutil.BlindSign(signer, R, mHat)
// requester extracts real signature
sig := btcutil.BlindExtract(requester, sHat)
sig.M = m
fmt.Printf("sig =\t%x\n\t%x\n", sig.S, sig.F.X)
// onlooker verifies signature
if btcutil.BlindVerify(Q, sig) {
fmt.Printf("valid signature\n")
}
}
func maybePanic(err error) {
if err != nil {
panic(err)
}
}