-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth_test.go
55 lines (44 loc) · 1.57 KB
/
auth_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package sequence_test
import (
"context"
"testing"
"time"
"github.com/0xsequence/ethkit/ethwallet"
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
"github.com/0xsequence/go-ethauth"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/testutil"
"github.com/goware/logger"
"github.com/stretchr/testify/assert"
)
func TestEthAuthEIP6492(t *testing.T) {
signer, err := ethwallet.NewWalletFromRandomEntropy()
assert.NoError(t, err)
wallet, err := sequence.NewWalletSingleOwner(signer)
assert.NoError(t, err)
log := logger.NewLogger(logger.LogLevel_INFO)
ethAuth, err := ethauth.New(sequence.ValidateSequenceAccountProof(log))
assert.NoError(t, err)
err = ethAuth.ConfigJsonRpcProvider(testutil.DefaultTestChainOptions.NodeURL)
assert.NoError(t, err)
proof := ethauth.NewProof()
proof.Address = wallet.Address().String()
proof.Claims.App = "TestEthAuthEIP6492"
proof.Claims.IssuedAt = time.Now().Unix()
proof.Claims.ExpiresAt = proof.Claims.IssuedAt + 3600
var digest common.Hash
digest_, err := proof.Claims.MessageDigest()
assert.NoError(t, err)
copy(digest[:], digest_)
signature, err := wallet.SignDigest(context.Background(), digest, testChain.ChainID())
assert.NoError(t, err)
signature, err = sequence.EIP6492Signature(signature, wallet.GetWalletConfig())
assert.NoError(t, err)
proof.Signature = hexutil.Encode(signature)
_, err = ethAuth.EncodeProof(proof)
assert.NoError(t, err)
isValid, err := ethAuth.ValidateProof(proof)
assert.NoError(t, err)
assert.True(t, isValid)
}