github.com/incognitochain/go-incognito-sdk@v1.0.1/privacy/key_test.go (about) 1 package privacy 2 3 import ( 4 "fmt" 5 "github.com/stretchr/testify/assert" 6 "testing" 7 ) 8 9 func TestKey(t *testing.T) { 10 for i := 0; i < 1; i++ { 11 // random seed 12 seed := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} 13 14 // generate private key from seed 15 privateKey := GeneratePrivateKey(seed) 16 17 // generate public key from private key 18 publicKey := GeneratePublicKey(privateKey) 19 20 // check public key 21 publicKeyPrime := new(Point).ScalarMultBase(new(Scalar).FromBytesS(privateKey)) 22 assert.Equal(t, publicKeyPrime.ToBytes(), SliceToArray(publicKey)) 23 24 // generate receiving key from private key 25 receivingKey := GenerateReceivingKey(privateKey) 26 27 // generate transmission key from receiving key 28 transmissionKey := GenerateTransmissionKey(receivingKey) 29 30 // decompress transmission key to transmissionKeyPoint 31 transmissionKeyPrime := new(Point).ScalarMultBase(new(Scalar).FromBytesS(receivingKey)) 32 assert.Equal(t, transmissionKeyPrime.ToBytes(), SliceToArray(transmissionKey)) 33 34 // generate payment address from private key 35 paymentAddress := GeneratePaymentAddress(privateKey) 36 assert.Equal(t, publicKey, paymentAddress.Pk) 37 assert.Equal(t, transmissionKey, paymentAddress.Tk) 38 39 // convert payment address to bytes array 40 paymentAddrBytes := paymentAddress.Bytes() 41 42 // new payment address to set bytes 43 paymentAddress2 := new(PaymentAddress) 44 paymentAddress2.SetBytes(paymentAddrBytes) 45 46 assert.Equal(t, paymentAddress.Pk, paymentAddress2.Pk) 47 assert.Equal(t, paymentAddress.Tk, paymentAddress2.Tk) 48 49 fmt.Printf("Private key: %v\n", privateKey) 50 fmt.Printf("publicKey: %v\n", publicKey) 51 fmt.Printf("receivingKey: %v\n", receivingKey) 52 fmt.Printf("transmissionKey: %v\n", transmissionKey) 53 54 } 55 }