Documentation

English
  • English
  • Russian
Mina Overview

Client SDK

This is a NodeJS client SDK that allows you to generate Mina key pairs and sign transactions and strings using Mina's key pairs. The project contains Typescript and ReasonML typings but can be used from plain NodeJS as well.


warning

Please be advised that generating key pairs with this method is unadvised and should only be used by experienced security professionals. Please use our mina-generate-keypair tool instead for creating key pairs.

Never reuse the same keypair from a testnet on mainnet!

Installation

The source code for our client SDK is open source and be seen here.

To get the client SDK installed, you will need NodeJS on your system. Make sure it is available on your machine and then use either yarn or npm to install the client SDK.

# yarn:
yarn add @o1labs/client-sdk

# npm:
npm install --save @o1labs/client-sdk

Usage

Creating a key pair is simple with our client SDK. See the snippet below to see how to get create a key pair.

NodeJS:

const MinaSDK = require("@o1labs/client-sdk");

let keys = MinaSDK.genKeys();
console.log(`Public key: ${keys.publicKey}`);
console.log(`Private key: ${keys.privateKey}`);

This will print your private key so make sure you are in a secure environment when using this method.

Please see the client SDK readme for more information on how to use our SDK.


warning

Never give out your private key and make sure they are stored safely. If you lose your private key or if a malicious actor gains access to your private key, you will lose access to your account and will lose your account funds. Always give out your public keys instead. Mina will never ask you for your private keys.


Import your account generated from the SDK

Please note that there are differences in key pair format between what the Mina client expects and what the client SDK generates. When the client SDK is used to generate a key pair, the key pair output returned are strings that aren't directly importable into our Mina client. For this, we will have to use the mina advanced wrap-key tool to format our key pair strings into a format that is directly importable to our client.

Accomplishing this takes only a few short steps.

  1. First, make sure you have a folder on your system where you can store the key files. We recommend using the ~/keys folder.
mkdir ~/keys
  1. Next, ensure the permissions are set properly in this folder, this prevents unwanted processes from accessing these files.
chmod 700 ~/keys
  1. Copy the private key output into a file in the ~/keys folder.
echo 'YOUR-PRIVATE_KEY' > ~/keys/my-wallet
  1. Ensure the permissions are set properly for the private key file, this prevents unwanted processes from accessing it.
chmod 600 ~/keys/my-wallet
  1. Use the mina advanced wrap-key tool to format your key pair into an importable format for the Mina client. Please note that using mina advanced wrap-key will force you to reset your password on your private key.
mina advanced wrap-key -privkey-path ~/keys/my-wallet

You will be prompted for a new password, as shown below.

Private key:
Password for new private key file:
Again to confirm:

This will generate a new my-wallet.pub and my-wallet file.

ls ~/keys/
my-wallet  my-wallet.pub
  1. Ensure the permissions are set properly for the newley created private key file.
chmod 600 ~/keys/my-wallet
  1. Finally, we can import the account created by the client SDK into the client.
mina accounts import -privkey-path ~/keys/my-wallet

You will be prompted for the password you entered when the account was created with mina advanced wrap-key.

The response from this command will look like this:

😄 Imported account!
Public key: B62qjaA4N9843FKM5FZk1HmeuDiojG42cbCDyZeUDQVjycULte9PFkC

Validate your private key

Now that you've created your key -- you'll want to validate that it works. It's sufficient to verify that you can sign a transaction. You can verify this using the mina-validate-keypair tool.

Run the following command:

mina-validate-keypair -privkey-path ~/keys/my-wallet