Skip to main content

@bitahon/client

The library implements core types of application-level actions for the Bitahon Protocol, as well as auxiliary classes that facilitate interactions with sessions and more.

Installation

General

To obtain the latest version, simply require the project using npm:

npm install @bitahon/client

Usage

Let's start by initializing the crypto-provider.

import {initCryptoProvider} from '@bitahon/crypto';

const provider = await import('@bitahon/browser-crypto');
initCryptoProvider(provider.default);

Additionally, it is necessary to implement the communication provider. Here, you can encode requests into QR Codes; check the IClientConnectionProvider interface.

import {
IClientConnectionProvider,
} from '@bitahon/client';

const connectionProvider: IClientConnectionProvider = {
send: async (data: Buffer) => {
// function for sending a Request that returns a Response buffers.
},
};

Session creation. You can save the session if needed; check the ClientSession class.

import {Client} from '@bitahon/client';

const client = new Client(connectionProvider);

await client.auth({
title: 'Awesome Wallet',
description: 'Wallet for Awesome Things',
});

localStorage.setItem('wallet_session', client.session.toString());

Session restoration may look like this.

import {ClientSession, Client} from '@bitahon/client';

const sessionData = localStorage.getItem('wallet_session');
const session = ClientSession.fromString(sessionData);

const client = new Client(connectionProvider, session);

An example of communication within a session, such as retrieving a public key, could be as follows:

import {bitcoin} from '@bitahon/client';

const action = new bitcoin.GetPublicKeyAction({
network: bitcoin.NETWORK_ID.BITCOIN_TESTNET,
path: "44'/1'/0'/0/0",
});

const pub = await client.request(action);
console.log(pub);

API

Interfaces

Classes

BIP32

Bip32Curve

Curveuint32
secp256k11
secp256k1-decred2
secp256k1-groestl3
secp256k1-smart4
nist256p15
ed255196
ed25519-sha37
ed25519-keccak8
curve255199

Interfaces

Classes

Functions

Actions Classes

wallet

bitcoin

ethereum

tron