Skip to content

Commit

Permalink
Improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
codebycarson committed Jan 25, 2024
1 parent 82f2d47 commit 399b6bf
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions packages/metamask-snap/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
## Sei Metamask Snap
# Sei Metamask Snap

This snap is under active development and is not yet ready for use until this packages has been properly audited by a third party.
This documentation describes the functions and RPC request handler used in a MetaMask Snap to handle cryptocurrency transactions and account management using BIP44 standards.

## Testing
### `onRpcRequest`

An RPC request handler that processes different request methods including `signDirect`, `signAmino`, and `getPrivateKey`. It handles the signing of transactions both in Amino and Direct mode, and also retrieves the private key.

- **Syntax**: `onRpcRequest({ request }): Promise<TransactionSignature | PrivateKey>`
- **Parameters**:
- `request`: An object representing the RPC request.
- **Returns**: A Promise that resolves to a `TransactionSignature` or `PrivateKey`.

## RPC Methods

### `signDirect`

Signs a transaction in Direct mode.

- **Parameters**:
- `account_index`: The bip44 coin type 118 account index to use for signing.
- `signerAddress`: The address of the signer.
- `signDoc`: The document to be signed.
- **Error Handling**: Throws an error if the private key is not available or if the user denies the transaction.

### `signAmino`

Signs a transaction in Amino mode.

- **Parameters**:
- `account_index`: The bip44 coin type 118 account index to use for signing.
- `signerAddress`: The address of the signer.
- `signDoc`: The document to be signed.
- `enableExtraEntropy`: Boolean flag for extra entropy.
- `isADR36`: Boolean flag for ADR-36 compliance.
- **Error Handling**: Throws an error if the private key is not available or if the user denies the transaction.


### `getPrivateKey`

Retrieves the private key for a specified account index using MetaMask's `snap_getBip44Entropy` method and BIP44 standards and coin type 118.

- **Syntax**: `getPrivateKey(account_index: number = 0): Promise<PrivateKey>`
- **Parameters**:
- `account_index` (number, optional): The index of the account, defaulting to 0.
- **Returns**: A Promise resolving to a `PrivateKey`.


## Local development and testing

### Setup
Run `yarn` to install dependencies.
Expand All @@ -13,11 +57,9 @@ In order to run the snap locally simply run `yarn start` and the snap will be se
### Testing the snap

#### Test UI
This package has a helpful UI for testing all the exposed functions.

`cd` into the `./test-ui` directory and run `yarn` to install dependencies. Then run `yarn dev` to start the test UI. The test UI will be served at `localhost:3000`. Please checkout the README.md in that directory to learn how to set the snap ID.

#### Unit tests
Run `yarn test` to run the unit tests.

## Usage

The snap exports three functions: `signAmino`, `signDirect`, and `getPrivateKey`. These functions can be used to create a SeiWallet interface for use with the `@sei-js` packages. `@sei-js/core` has a function to do this called `getMetaMaskSnapSeiWallet`

0 comments on commit 399b6bf

Please sign in to comment.