Skip to content

Commit

Permalink
feat(accounts): add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Sep 12, 2024
1 parent a8d2775 commit 313b650
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
123 changes: 123 additions & 0 deletions apps/docs/src/pages/accounts/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Getting Started [Start with MinaJS Accounts.]

:::warning
For now there are only nightly builds available before we reach a beta version. You won't be able to install it from npm.
:::

MinaJS Accounts shares an API similar to [Viem](https://viem.sh/).

## Installation

```sh
$ npm install @mina-js/accounts
```

## Utilities

### generateMnemonic

```ts twoslash
import { generateMnemonic, english } from '@mina-js/accounts'

const mnemonic = generateMnemonic(english);
```

### generatePrivateKey

```ts twoslash
import { generatePrivateKey } from '@mina-js/accounts'

const privateKey = generatePrivateKey();
```

### mnemonicToAccount

```ts twoslash
import { mnemonicToAccount } from '@mina-js/accounts'

const account = mnemonicToAccount('your mnemonic here');
```

### privateKeyToAccount

```ts twoslash
import { privateKeyToAccount } from '@mina-js/accounts'

// Mainnet account
const mainnetAccount = privateKeyToAccount({ privateKey: 'your private key here' });
// Testnet account
const testnetAccount = privateKeyToAccount({
privateKey: 'your private key here',
network: 'testnet'
});
```

### hdKeyToAccount

```ts twoslash
import { hdKeyToAccount, hex, HDKey } from '@mina-js/accounts'

const hdKey = HDKey.fromMasterSeed(hex.decode("59eabf9e9..."));

const addressIndexAccount = hdKeyToAccount(hdKey, { addressIndex: 5 });
const accountIndexAccount = hdKeyToAccount(hdKey, { accountIndex: 5 });
const customPathAccount = hdKeyToAccount(hdKey, { path: "m/44'/12586'/0'/0/5" });
```

### hex

Exported from `@scure/base`.

### HDKey

Exported from `@scure/bip32`.

## Account operations

### Sign a message

```ts twoslash
import { mnemonicToAccount } from '@mina-js/accounts'

const account = mnemonicToAccount('your mnemonic here');

const signedMessage = await account.signMessage({ message: 'your message here' });
```

### Sign a transaction

```ts twoslash
import { mnemonicToAccount } from '@mina-js/accounts'

const account = mnemonicToAccount('your mnemonic here');

const signedTransaction = await account.signTransaction({
transaction: {
nonce: 1n,
from: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
to: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
amount: 3000000000n,
fee: 100000000n,
}
});
```

### Sign fields

```ts twoslash
import { mnemonicToAccount } from '@mina-js/accounts'

const account = mnemonicToAccount('your mnemonic here');

const signedFields = await account.signFields({ fields: [1n, 2n, 3n] });
```

### Create a nullifier

```ts twoslash
import { mnemonicToAccount } from '@mina-js/accounts'

const account = mnemonicToAccount('your mnemonic here');

const nullifier = await account.createNullifier({ message: [1n, 2n, 3n] });
```
8 changes: 7 additions & 1 deletion apps/docs/src/pages/accounts/index.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#TODO
# MinaJS Accounts [Go from mnemonic to Mina account in seconds.]

The Accounts library is a wrapper and abstraction over Mina Signer and BIP39/32. It provides utilities to easily go from a mnemonic or a private key to a Mina account. It removes the need to manipulare data manually.

## Purpose

It wraps the standard base58 encoding and decoding, HD wallet libraries, and Mina Signer utilities to provide you with a handy abstraction in order to build quicker.
5 changes: 4 additions & 1 deletion apps/docs/vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export default defineConfig({
{
text: "MinaJS Accounts",
link: "/accounts",
items: [{ text: "Introduction", link: "/accounts" }],
items: [
{ text: "Introduction", link: "/accounts" },
{ text: "Getting Started", link: "/accounts/getting-started" },
],
},
{
text: "Klesia",
Expand Down
1 change: 1 addition & 0 deletions packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { HDKey } from "@scure/bip32";
export { hex } from "@scure/base";
export { wordlist as english } from "@scure/bip39/wordlists/english";

export { generateMnemonic } from "./accounts/generate-mnemonic";
Expand Down

0 comments on commit 313b650

Please sign in to comment.