Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vk check #1858

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions go/common/viewingkey/viewing_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ type RPCSignedViewingKey struct {
SignatureWithAccountKey []byte
}

const (
pubKeyLen = 33
sigLen = 65
)

func (vk RPCSignedViewingKey) Validate() error {
// todo - remove this when merging to main
if vk.Account == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it compatible with the future format at this point I suppose, infer the account? Would be a throwaway code snippet but means main tools (auth client and gateway) can communicate with sepolia testnet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's discuss in planning. I don't think it's worth the effort

return fmt.Errorf("invalid account in viewing key")
}
if len(vk.PublicKey) != pubKeyLen {
return fmt.Errorf("invalid viewing key")
}
if len(vk.SignatureWithAccountKey) != sigLen {
return fmt.Errorf("invalid viewing key signature")
}
return nil
}

// GenerateViewingKeyForWallet takes an account wallet, generates a viewing key and signs the key with the acc's private key
// uses the same method of signature handling as Metamask/geth
func GenerateViewingKeyForWallet(wal wallet.Wallet) (*ViewingKey, error) {
Expand Down
5 changes: 5 additions & 0 deletions go/enclave/vkhandler/vk_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type AuthenticatedViewingKey struct {
}

func VerifyViewingKey(rpcVK *viewingkey.RPCSignedViewingKey, chainID int64) (*AuthenticatedViewingKey, error) {
err := rpcVK.Validate()
if err != nil {
return nil, err
}

vkPubKey, err := crypto.DecompressPubkey(rpcVK.PublicKey)
if err != nil {
return nil, fmt.Errorf("could not decompress viewing key bytes - %w", err)
Expand Down
Loading