github.com/turingchain2020/turingchain@v1.1.21/wallet/bipwallet/btcutilecc/examples/blind/blind.go (about)

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