github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/storage/mru/resource_sign.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 25 package mru 26 27 import ( 28 "crypto/ecdsa" 29 30 "github.com/ethereum/go-ethereum/common" 31 "github.com/ethereum/go-ethereum/crypto" 32 ) 33 34 const signatureLength = 65 35 36 // 37 type Signature [signatureLength]byte 38 39 // 40 type Signer interface { 41 Sign(common.Hash) (Signature, error) 42 Address() common.Address 43 } 44 45 // 46 // 47 type GenericSigner struct { 48 PrivKey *ecdsa.PrivateKey 49 address common.Address 50 } 51 52 // 53 func NewGenericSigner(privKey *ecdsa.PrivateKey) *GenericSigner { 54 return &GenericSigner{ 55 PrivKey: privKey, 56 address: crypto.PubkeyToAddress(privKey.PublicKey), 57 } 58 } 59 60 // 61 // 62 func (s *GenericSigner) Sign(data common.Hash) (signature Signature, err error) { 63 signaturebytes, err := crypto.Sign(data.Bytes(), s.PrivKey) 64 if err != nil { 65 return 66 } 67 copy(signature[:], signaturebytes) 68 return 69 } 70 71 // 72 func (s *GenericSigner) Address() common.Address { 73 return s.address 74 }