-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters