viewingkey

package
v0.23.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EIP712Domain          = "EIP712Domain"
	EIP712Type            = "Authentication"
	EIP712DomainName      = "name"
	EIP712DomainVersion   = "version"
	EIP712DomainChainID   = "chainId"
	EIP712EncryptionToken = "Encryption Token"
	// EIP712EncryptionTokenV2 is used to support older versions of third party libraries
	// that don't have the support for spaces in type names
	EIP712EncryptionTokenV2  = "EncryptionToken"
	EIP712DomainNameValue    = "Ten"
	EIP712DomainVersionValue = "1.0"
	UserIDHexLength          = 40
)
View Source
const SignedMsgPrefix = "vk"

SignedMsgPrefix is the prefix added when signing the viewing key in MetaMask using the personal_sign API. Why is this needed? MetaMask has a security feature whereby if you ask it to sign something that looks like a transaction using the personal_sign API, it modifies the data being signed. The goal is to prevent hackers from asking a visitor to their website to personal_sign something that is actually a malicious transaction (e.g. theft of funds). By adding a prefix, the viewing key bytes no longer looks like a transaction hash, and thus get signed as-is.

Variables

View Source
var EIP712EncryptionTokens = [...]string{
	EIP712EncryptionToken,
	EIP712EncryptionTokenV2,
}

EIP712EncryptionTokens is a list of all possible options for Encryption token name

Functions

func CalculateUserID

func CalculateUserID(publicKeyBytes []byte) []byte

CalculateUserID calculates userID from a public key (we truncate it, because we want it to have length 20)

func CalculateUserIDHex

func CalculateUserIDHex(publicKeyBytes []byte) string

CalculateUserIDHex CalculateUserID calculates userID from a public key (we truncate it, because we want it to have length 20) and encode to hex strings

func CheckEIP712Signature added in v0.22.0

func CheckEIP712Signature(userID string, signature []byte, chainID int64) (*gethcommon.Address, error)

CheckEIP712Signature checks if signature is valid for provided userID and chainID and return address or nil if not valid

func CheckSignatureAndReturnAccountAddress added in v0.22.0

func CheckSignatureAndReturnAccountAddress(hashBytes []byte, signature []byte) (*gethcommon.Address, error)

CheckSignatureAndReturnAccountAddress checks if the signature is valid for hash of the message and checks if signer is an address provided to the function. It returns an address if the signature is valid and nil otherwise

func GenerateAuthenticationEIP712RawDataOptions

func GenerateAuthenticationEIP712RawDataOptions(userID string, chainID int64) ([][]byte, error)

GenerateAuthenticationEIP712RawDataOptions generates all the options or raw data messages (bytes) for an EIP-712 message used to authenticate an address with user

func GenerateSignMessage

func GenerateSignMessage(vkPubKey []byte) string

GenerateSignMessage creates the message to be signed vkPubKey is expected to be a []byte("0x....") to create the signing message todo (@ziga) Remove this method once old WE endpoints are removed

func Sign

func Sign(userPrivKey *ecdsa.PrivateKey, vkPubKey []byte) ([]byte, error)

Sign takes a users Private key and signs the public viewingKey hex

Types

type RPCSignedViewingKey added in v0.22.0

type RPCSignedViewingKey struct {
	Account                 *gethcommon.Address
	PublicKey               []byte
	SignatureWithAccountKey []byte
}

RPCSignedViewingKey - used for transporting a minimalist viewing key via every RPC request to a sensitive method, including Log subscriptions. only the public key and the signature are required the account address is sent as well to aid validation todo - send the type of Message that was signed instead of the Account

type ViewingKey

type ViewingKey struct {
	Account                 *gethcommon.Address // Account address that this Viewing Key is bound to - Users Pubkey address
	PrivateKey              *ecies.PrivateKey   // ViewingKey private key to encrypt data to the enclave
	PublicKey               []byte              // ViewingKey public key in decrypt data from the enclave
	SignatureWithAccountKey []byte              // ViewingKey public key signed by the Accounts Private key - Allows to retrieve the Account address
}

ViewingKey encapsulates the signed viewing key for an account for use in encrypted communication with an enclave. It is th client-side perspective of the viewing key used for decrypting incoming traffic.

func GenerateViewingKeyForWallet

func GenerateViewingKeyForWallet(wal wallet.Wallet) (*ViewingKey, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL