viewingkey

package
v0.20.5 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: AGPL-3.0 Imports: 13 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 CheckSignatureAndAddress

func CheckSignatureAndAddress(hashBytes []byte, signature []byte, address *gethcommon.Address) bool

CheckSignatureAndAddress checks if the signature is valid for hash of the message and checks if signer is an address provided to the function. It returns true if both conditions are true and false 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

func VerifySignatureEIP712

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

Types

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
	Signature  []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

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