diff --git a/pages/dev-interoperability/precompiles/addr.mdx b/pages/dev-interoperability/precompiles/addr.mdx index 6e1d476..0fbc7fb 100644 --- a/pages/dev-interoperability/precompiles/addr.mdx +++ b/pages/dev-interoperability/precompiles/addr.mdx @@ -11,6 +11,64 @@ Association takes place when the wallet first signs and broadcasts any transacti ## Functions +### Transactions +- `associate`: Associates an EVM address with it's corresponding Sei native address on chain using a signature. For association via a pubkey, use `associatePubKey` instead. + ```solidity + /// Associates an account given it's signature of any custom message. + /// @param v The v component of the signature. + /// @param r The r component of the signature. + /// @param s The s component of the signature. + /// @param customMessage A custom message that was signed by the address to be associated. + /// @return Whether the association was successfully executed. + function associate( + string memory v, + string memory r, + string memory s, + string memory customMessage + ) external returns (string memory seiAddr, address evmAddr); + ``` + + Example use: + ```ts + const message = `This is a test message.`; + + // Get the hex encoded signature + const signature = await signMessageAsync({message}) + + // Get the v, r, s values + const { r, s } = secp256k1.Signature.fromCompact(signature.slice(2, 130)); + const v = hexToNumber(`0x${signature.slice(130)}`); + + // Append the Ethereum Signed Message prefix to the signed message. + // This prefix is automatically appended to the message by `sign` methods that use EDCSA, so we need to append this too. + const messageLength = Buffer.from(message, 'utf8').length; + const customMessage = `\x19Ethereum Signed Message:\n${messageLength}${message}`; + const request = { + r: numberToHex(r), + s: numberToHex(s), + v: numberToHex(v - 27), + custom_message: customMessage + }; + await contract.associate(request.v, request.r, request.s, request.custom_message) + ``` + +- `associatePubKey`: Enables a user to associate a pair of sei addresses using the public key. + ```solidity + /// Associates an account given it's compressed pubkey in hex format (excluding the '0x') + /// @param pubKeyHex The Hex-encoded compressed pubkey of the account to be associated, excluding the '0x' + /// @return Whether the association was successfully executed. + function associatePubKey( + string memory pubKeyHex + ) external returns (string memory seiAddr, address evmAddr); + ``` + Example use: + ```ts + // Create a sample ethers wallet + const newWallet = ethers.Wallet.createRandom(); + const pkWithout0x = newWallet.publicKey.slice(2) + await contract.associatePubKey(pkWithout0x) + ``` + ### Queries - `getSeiAddr`: Gets the corresponding Sei Address from the given EVM Address ```solidity