github.com/turingchain2020/turingchain@v1.1.21/wallet/bipwallet/btcutilecc/arith.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 btcutil Utility functions for Bitcoin elliptic curve cryptography. 6 package btcutil 7 8 import ( 9 "crypto/ecdsa" 10 "math/big" 11 ) 12 13 // ScalarBaseMult Multiplies the base G by a large integer. The resulting 14 // point is represented as an ECDSA public key since that's 15 // typically how they're used. 16 func ScalarBaseMult(k *big.Int) *ecdsa.PublicKey { 17 key := new(ecdsa.PublicKey) 18 key.Curve = Secp256k1() 19 key.X, key.Y = Secp256k1().ScalarBaseMult(k.Bytes()) 20 return key 21 } 22 23 // ScalarMult Multiply a large integer and a point. The resulting point 24 // is represented as an ECDSA public key. 25 func ScalarMult(k *big.Int, B *ecdsa.PublicKey) *ecdsa.PublicKey { 26 key := new(ecdsa.PublicKey) 27 key.Curve = Secp256k1() 28 key.X, key.Y = Secp256k1().ScalarMult(B.X, B.Y, k.Bytes()) 29 return key 30 } 31 32 // Add Adds two points to create a third. Points are represented as 33 // ECDSA public keys. 34 func Add(a, b *ecdsa.PublicKey) *ecdsa.PublicKey { 35 key := new(ecdsa.PublicKey) 36 key.Curve = Secp256k1() 37 key.X, key.Y = Secp256k1().Add(a.X, a.Y, b.X, b.Y) 38 return key 39 }