Documentation

English
  • English
  • Russian
Mina Overview

Client SDK

The Mina Client Javascript SDK allows generating keypairs, signing and verifying messages, and signing transactions that can be broadcast to the network.

The project contains Typescript and ReasonML typings but can be used from plain NodeJS as well. The following methods are available:

  • genKeys - generates a public/private keypair.
  • derivePublicKey - derives the public key of the corresponding private key.
  • signMessage - signs an arbitrary message.
  • verifyMessage - verifies that a signature matches a message.
  • signPayment - signs a payment using a private key.
  • signStakeDelegation - signs a stake delegation using a private key.

note

The client SDK enables the ability to generate and sign transactions on an air-gapped device that never exposes a private key to the internet.

Install

yarn add @o1labs/client-sdk
# or with npm:
npm install --save @o1labs/client-sdk

Usage

Typescript

import * as MinaSDK from "@o1labs/client-sdk";

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage("hello", keys);
if (MinaSDK.verifyMessage(signed)) {
    console.log("Message was verified successfully")
};

let signedPayment = MinaSDK.signPayment({
    to: keys.publicKey,
    from: keys.publicKey,
    amount: 1,
    fee: 1,
    nonce: 0
  }, keys);

NodeJS

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

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage("hello", keys);
if (MinaSDK.verifyMessage(signed)) {
    console.log("Message was verified successfully")
};

let signedPayment = MinaSDK.signPayment({
    to: keys.publicKey,
    from: keys.publicKey,
    amount: 1,
    fee: 1,
    nonce: 0
  }, keys);

ReasonML

  • Install gentype: yarn add -D gentype
  • Install bs-platform: yarn add -D bs-platform
  • Build dependencies: yarn bsb -make-world
module MinaSDK = O1labsClientSdk.CodaSDK;

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage(. "hello", keys);
if (MinaSDK.verifyMessage(. signed)) {
  Js.log("Message was verified successfully");
};

let signedPayment = MinaSDK.signPayment({
    to_: keys.publicKey,
    from: keys.publicKey,
    amount: "1",
    fee: "1",
    nonce: "0"
  }, keys);

note

When generating transactions, you will need to specify the account nonce. This is available for an account via the CLI using mina advanced get-nonce --address <PUBLIC_KEY> or using GraphQL.