Skip to content

Commit 313b650

Browse files
committed
feat(accounts): add docs
1 parent a8d2775 commit 313b650

File tree

4 files changed

+135
-2
lines changed

4 files changed

+135
-2
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Getting Started [Start with MinaJS Accounts.]
2+
3+
:::warning
4+
For now there are only nightly builds available before we reach a beta version. You won't be able to install it from npm.
5+
:::
6+
7+
MinaJS Accounts shares an API similar to [Viem](https://viem.sh/).
8+
9+
## Installation
10+
11+
```sh
12+
$ npm install @mina-js/accounts
13+
```
14+
15+
## Utilities
16+
17+
### generateMnemonic
18+
19+
```ts twoslash
20+
import { generateMnemonic, english } from '@mina-js/accounts'
21+
22+
const mnemonic = generateMnemonic(english);
23+
```
24+
25+
### generatePrivateKey
26+
27+
```ts twoslash
28+
import { generatePrivateKey } from '@mina-js/accounts'
29+
30+
const privateKey = generatePrivateKey();
31+
```
32+
33+
### mnemonicToAccount
34+
35+
```ts twoslash
36+
import { mnemonicToAccount } from '@mina-js/accounts'
37+
38+
const account = mnemonicToAccount('your mnemonic here');
39+
```
40+
41+
### privateKeyToAccount
42+
43+
```ts twoslash
44+
import { privateKeyToAccount } from '@mina-js/accounts'
45+
46+
// Mainnet account
47+
const mainnetAccount = privateKeyToAccount({ privateKey: 'your private key here' });
48+
// Testnet account
49+
const testnetAccount = privateKeyToAccount({
50+
privateKey: 'your private key here',
51+
network: 'testnet'
52+
});
53+
```
54+
55+
### hdKeyToAccount
56+
57+
```ts twoslash
58+
import { hdKeyToAccount, hex, HDKey } from '@mina-js/accounts'
59+
60+
const hdKey = HDKey.fromMasterSeed(hex.decode("59eabf9e9..."));
61+
62+
const addressIndexAccount = hdKeyToAccount(hdKey, { addressIndex: 5 });
63+
const accountIndexAccount = hdKeyToAccount(hdKey, { accountIndex: 5 });
64+
const customPathAccount = hdKeyToAccount(hdKey, { path: "m/44'/12586'/0'/0/5" });
65+
```
66+
67+
### hex
68+
69+
Exported from `@scure/base`.
70+
71+
### HDKey
72+
73+
Exported from `@scure/bip32`.
74+
75+
## Account operations
76+
77+
### Sign a message
78+
79+
```ts twoslash
80+
import { mnemonicToAccount } from '@mina-js/accounts'
81+
82+
const account = mnemonicToAccount('your mnemonic here');
83+
84+
const signedMessage = await account.signMessage({ message: 'your message here' });
85+
```
86+
87+
### Sign a transaction
88+
89+
```ts twoslash
90+
import { mnemonicToAccount } from '@mina-js/accounts'
91+
92+
const account = mnemonicToAccount('your mnemonic here');
93+
94+
const signedTransaction = await account.signTransaction({
95+
transaction: {
96+
nonce: 1n,
97+
from: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
98+
to: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
99+
amount: 3000000000n,
100+
fee: 100000000n,
101+
}
102+
});
103+
```
104+
105+
### Sign fields
106+
107+
```ts twoslash
108+
import { mnemonicToAccount } from '@mina-js/accounts'
109+
110+
const account = mnemonicToAccount('your mnemonic here');
111+
112+
const signedFields = await account.signFields({ fields: [1n, 2n, 3n] });
113+
```
114+
115+
### Create a nullifier
116+
117+
```ts twoslash
118+
import { mnemonicToAccount } from '@mina-js/accounts'
119+
120+
const account = mnemonicToAccount('your mnemonic here');
121+
122+
const nullifier = await account.createNullifier({ message: [1n, 2n, 3n] });
123+
```
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
#TODO
1+
# MinaJS Accounts [Go from mnemonic to Mina account in seconds.]
2+
3+
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.
4+
5+
## Purpose
6+
7+
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.

apps/docs/vocs.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export default defineConfig({
9090
{
9191
text: "MinaJS Accounts",
9292
link: "/accounts",
93-
items: [{ text: "Introduction", link: "/accounts" }],
93+
items: [
94+
{ text: "Introduction", link: "/accounts" },
95+
{ text: "Getting Started", link: "/accounts/getting-started" },
96+
],
9497
},
9598
{
9699
text: "Klesia",

packages/accounts/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { HDKey } from "@scure/bip32";
2+
export { hex } from "@scure/base";
23
export { wordlist as english } from "@scure/bip39/wordlists/english";
34

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

0 commit comments

Comments
 (0)