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

Tudor/validate vk #1859

Merged
merged 2 commits 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
15 changes: 15 additions & 0 deletions go/common/viewingkey/viewing_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ type RPCSignedViewingKey struct {
SignatureType SignatureType
}

const (
pubKeyLen = 33
sigLen = 65
)

func (vk RPCSignedViewingKey) Validate() error {
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
func GenerateViewingKeyForWallet(wal wallet.Wallet) (*ViewingKey, error) {
chainID := wal.ChainID().Int64()
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 @@ -25,6 +25,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