Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateUserID(publicKeyBytes []byte) []byte
- func CalculateUserIDHex(publicKeyBytes []byte) string
- func CheckEIP712Signature(userID string, signature []byte, chainID int64) (*gethcommon.Address, error)
- func CheckSignatureAndReturnAccountAddress(hashBytes []byte, signature []byte) (*gethcommon.Address, error)
- func GenerateAuthenticationEIP712RawDataOptions(userID string, chainID int64) ([][]byte, error)
- func GenerateSignMessage(vkPubKey []byte) string
- func Sign(userPrivKey *ecdsa.PrivateKey, vkPubKey []byte) ([]byte, error)
- type RPCSignedViewingKey
- type ViewingKey
Constants ¶
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 )
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 ¶
var EIP712EncryptionTokens = [...]string{ EIP712EncryptionToken, EIP712EncryptionTokenV2, }
EIP712EncryptionTokens is a list of all possible options for Encryption token name
Functions ¶
func CalculateUserID ¶
CalculateUserID calculates userID from a public key (we truncate it, because we want it to have length 20)
func CalculateUserIDHex ¶
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 ¶
GenerateAuthenticationEIP712RawDataOptions generates all the options or raw data messages (bytes) for an EIP-712 message used to authenticate an address with user
func GenerateSignMessage ¶
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
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