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

Document new associate methods #131

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from 1 commit
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
58 changes: 58 additions & 0 deletions pages/dev-interoperability/precompiles/addr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 Cosmos address on chain using a signature. For association via a pubkey, use `associatePubKey` instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Cosmos -> Sei native

```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)
```

- `sendNative`: Enables a user to send native Sei to another user.
mj850 marked this conversation as resolved.
Show resolved Hide resolved
```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
Expand Down
Loading