Skip to content

Commit

Permalink
docs: document vm.deriveKey
Browse files Browse the repository at this point in the history
Closes #452
  • Loading branch information
onbjerg committed Aug 15, 2022
1 parent 48a6456 commit 99df027
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Expand Up @@ -243,6 +243,7 @@
- [`addr`](./cheatcodes/addr.md)
- [`sign`](./cheatcodes/sign.md)
- [`label`](./cheatcodes/label.md)
- [`deriveKey`](./cheatcodes/derive-key.md)
- [Snapshots](./cheatcodes/snapshots.md)
- [RPC](./cheatcodes/rpc.md)
- [Forge Standard Library Reference](./reference/forge-std/README.md)
Expand Down
7 changes: 7 additions & 0 deletions src/cheatcodes/README.md
Expand Up @@ -70,6 +70,13 @@ interface CheatCodes {
// Computes address for a given private key
function addr(uint256 privateKey) external returns (address);
// Derive a private key from a provided mnenomic string,
// or mnenomic file path, at the derivation path m/44'/60'/0'/0/{index}.
function deriveKey(string calldata, uint32) external returns (uint256);
// Derive a private key from a provided mnenomic string, or mnenomic file path,
// at the derivation path {path}{index}
function deriveKey(string calldata, string calldata, uint32) external returns (uint256);
// Gets the nonce of an account
function getNonce(address account) external returns (uint64);
Expand Down
41 changes: 41 additions & 0 deletions src/cheatcodes/derive-key.md
@@ -0,0 +1,41 @@
## `deriveKey`

### Signature

```solidity
function deriveKey(
string calldata mnemonic,
uint32 index
) external returns (uint256);
```

```solidity
function deriveKey(
string calldata mnemonic,
string calldata path,
uint32 index
) external returns (uint256);
```

### Description

Derive a private key from a given mnemonic or mnemonic file path.

The first signature derives at the derivation path `m/44'/60'/0'/0/{index}`.
The second signature allows you to specify the derivation path as the second parameter.

### Examples

Derive the private key from the test mnemonic at path `m/44'/60'/0'/0/0`:

```solidity
string memory mnemonic = "test test test test test test test test test test test junk";
uint256 privateKey = vm.deriveKey(mnemonic, 0);
```

Derive the private key from the test mnemonic at path `m/44'/60'/0'/1/0`:

```solidity
string memory mnemonic = "test test test test test test test test test test test junk";
uint256 privateKey = vm.deriveKey(mnemonic, "m/44'/60'/0'/1/", 0);
```
1 change: 1 addition & 0 deletions src/cheatcodes/utilities.md
Expand Up @@ -3,3 +3,4 @@
- [`addr`](./addr.md)
- [`sign`](./sign.md)
- [`label`](./label.md)
- [`deriveKey`](./derive-key.md)

0 comments on commit 99df027

Please sign in to comment.