Added key image derivation
This commit is contained in:
parent
39e34abed6
commit
75fea6aad3
|
@ -13,3 +13,7 @@ func GetDerivationViewTagForOutputIndex(derivation PublicKey, outputIndex uint64
|
|||
h := moneroutil.Keccak256([]byte("view_tag"), derivation.AsSlice(), binary.AppendUvarint(nil, outputIndex))
|
||||
return h[0]
|
||||
}
|
||||
|
||||
func GetKeyImage(pair *KeyPair) PublicKey {
|
||||
return PublicKeyFromPoint(HashToPoint(pair.PublicKey)).Multiply(pair.PrivateKey.AsScalar())
|
||||
}
|
18
monero/crypto/derivations_test.go
Normal file
18
monero/crypto/derivations_test.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"filippo.io/edwards25519"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKeyImageRaw(t *testing.T) {
|
||||
sec, _ := hex.DecodeString("981d477fb18897fa1f784c89721a9d600bf283f06b89cb018a077f41dcefef0f")
|
||||
|
||||
scalar, _ := (&edwards25519.Scalar{}).SetCanonicalBytes(sec)
|
||||
keyImage := GetKeyImage(NewKeyPairFromPrivate(PrivateKeyFromScalar(scalar)))
|
||||
|
||||
if keyImage.String() != "a637203ec41eab772532d30420eac80612fce8e44f1758bc7e2cb1bdda815887" {
|
||||
t.Fatalf("key image expected %s, got %s", "a637203ec41eab772532d30420eac80612fce8e44f1758bc7e2cb1bdda815887", keyImage.String())
|
||||
}
|
||||
}
|
|
@ -20,8 +20,12 @@ func HashToScalar(data ...[]byte) *edwards25519.Scalar {
|
|||
return c
|
||||
}
|
||||
|
||||
func HashToPoint(data ...[]byte) *edwards25519.Point {
|
||||
h := moneroutil.Keccak256(data...)
|
||||
p, _ := (&edwards25519.Point{}).SetBytes(h[:])
|
||||
return p.ScalarMult(scalar8, p)
|
||||
func HashToPoint(publicKey PublicKey) *edwards25519.Point {
|
||||
//TODO: make this work with existing edwards25519 library
|
||||
input := moneroutil.Key(publicKey.AsBytes())
|
||||
var key moneroutil.Key
|
||||
(&input).HashToEC().ToBytes(&key)
|
||||
p, _ := (&edwards25519.Point{}).SetBytes(key[:])
|
||||
return p
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue