-
Notifications
You must be signed in to change notification settings - Fork 0
/
stealth_test.go
34 lines (25 loc) · 1019 Bytes
/
stealth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package stealth
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1"
)
func TestGenerateStealthAddress(t *testing.T) {
suite := NewStealthSuite()
viewKey := cmtsecp256k1.GenPrivKey()
spendKey := cmtsecp256k1.GenPrivKey()
metaAddr := MetaAddress(append(viewKey.PubKey().Bytes(), spendKey.PubKey().Bytes()...))
stealthAddr, ephPubKey := suite.GenerateStealthAddress(metaAddr)
fmt.Println(stealthAddr)
fmt.Println(ephPubKey)
result := suite.CheckStealthAddress(stealthAddr, ephPubKey, viewKey, spendKey.PubKey().Bytes())
require.Equal(t, true, result)
// Test negative case
viewKey2 := cmtsecp256k1.GenPrivKey()
result = suite.CheckStealthAddress(stealthAddr, ephPubKey, viewKey2, spendKey.PubKey().Bytes())
require.Equal(t, false, result)
// Compute stealth key and check if it corresponds to the stealth address.
stealthKey := suite.ComputeStealthKey(stealthAddr, ephPubKey, viewKey, spendKey)
fmt.Println(stealthKey)
}