Skip to content

Commit

Permalink
move code
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Feb 20, 2024
1 parent d8357d1 commit 8eea429
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 62 deletions.
59 changes: 0 additions & 59 deletions messagesignature_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ func GeneralIsValidSignature(walletAddress common.Address, digest common.Hash, s
return isValid, nil
}

func IsValidMessageSignature(address common.Address, message []byte, signature []byte, chainID *big.Int, provider *ethrpc.Provider, log logger.Logger) (bool, error) {
if log == nil {
log = logger.Nop()
func IsValidMessageSignature(address common.Address, message []byte, signature []byte, chainID *big.Int, provider *ethrpc.Provider, optLogger *logger.Logger) (bool, error) {
log := logger.Nop()
if optLogger != nil {
log = *optLogger
}

isValid, err := ethwallet.IsValid191Signature(address, message, signature)
Expand Down
58 changes: 58 additions & 0 deletions signature_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
package sequence_test

import (
"context"
"math/big"
"testing"

"github.com/0xsequence/ethkit/ethrpc"
"github.com/0xsequence/ethkit/ethwallet"
"github.com/0xsequence/ethkit/go-ethereum/accounts"
"github.com/0xsequence/ethkit/go-ethereum/crypto"
"github.com/0xsequence/go-sequence"
"github.com/stretchr/testify/assert"
)

const rpcURL = "https://nodes.sequence.app/mainnet"

func TestIsValidMessageSignatureEOA(t *testing.T) {
message := "hello world!"

eoa, err := ethwallet.NewWalletFromRandomEntropy()
assert.NoError(t, err)

signature, err := eoa.SignMessage([]byte(message))
assert.NoError(t, err)
assert.Len(t, signature, crypto.SignatureLength)

provider, err := ethrpc.NewProvider(rpcURL)
assert.NoError(t, err)

isValid, err := sequence.IsValidMessageSignature(eoa.Address(), []byte(message), signature, big.NewInt(1), provider, nil)
assert.NoError(t, err)
assert.True(t, isValid)
}

func TestIsValidMessageSignatureSequence(t *testing.T) {
message := "hello world!"

eoa, err := ethwallet.NewWalletFromRandomEntropy()
assert.NoError(t, err)
wallet, err := sequence.NewWalletSingleOwner(eoa)
assert.NoError(t, err)

provider, err := ethrpc.NewProvider(rpcURL)
assert.NoError(t, err)

err = wallet.Connect(provider, nil)
assert.NoError(t, err)

signature, _, err := wallet.SignMessage(context.Background(), accounts.TextHash([]byte(message)))
assert.NoError(t, err)

signature, err = sequence.EIP6492Signature(signature, wallet.GetWalletConfig())
assert.NoError(t, err)

isValid, err := sequence.IsValidMessageSignature(wallet.Address(), []byte(message), signature, big.NewInt(1), provider, nil)
assert.NoError(t, err)
assert.True(t, isValid)
}

/*
const message = "hi!"
Expand Down

0 comments on commit 8eea429

Please sign in to comment.