Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bajetech/js-digitalbits-wallets
A library to make it easier to write wallets that interact with the DigitalBits blockchain.
https://github.com/bajetech/js-digitalbits-wallets
blockchain digitalbits keystore wallets
Last synced: 21 days ago
JSON representation
A library to make it easier to write wallets that interact with the DigitalBits blockchain.
- Host: GitHub
- URL: https://github.com/bajetech/js-digitalbits-wallets
- Owner: bajetech
- License: apache-2.0
- Created: 2022-01-18T07:54:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-09T03:48:10.000Z (almost 3 years ago)
- Last Synced: 2024-11-28T14:37:15.693Z (about 1 month ago)
- Topics: blockchain, digitalbits, keystore, wallets
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@bajetech/digitalbits-wallet-sdk
- Size: 654 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# js-digitalbits-wallets
> A library to make it easier to write wallets that interact with the DigitalBits blockchain.
## Installation
```bash
yarn add @bajetech/digitalbits-wallet-sdk # or npm i @bajetech/digitalbits-wallet-sdk
```## Usage
This library provides straightforward APIs for handling the following tasks:
- Fetching and formatting data from the DigitalBits blockchain network
- Encrypting and storing secret keysSome things the library will try to do well:
- Useful type definitions
- Consistent, descriptive names
- Provide one obvious, streamlined way of accomplishing each taskThis is not an attempt to replace `xdb-digitalbits-sdk`, it's meant to provide a better
API in some areas (data-fetching) and new functionality in others
(key management).## Fetching and formatting data
Our library's goal is to provide typed, consistently-named DigitalBits data through
a consistent, predictable API.Note that our goal was to name data properties to be _internally consistent_ and
intuitive, _not_ to be perfectly consistent with Frontier's responses. In some
cases (particularly around offer / trade history), properties were renamed for
clarity.```js
import { DataProvider } from "@bajetech/digitalbits-wallet-sdk";
import { Networks } from "xdb-digitalbits-sdk";// You'll use your DataProvider instance to ask for data from DigitalBits.
const dataProvider = new DataProvider({
serverUrl: "https://frontier.livenet.digitalbits.io",
accountOrKey: "<>",
networkPassphrase: Networks.PUBLIC,
});// Some class functions will fetch data directly.
const offers = await dataProvider.fetchOpenOffers({
limit: 20,
order: "desc",
});// Others will watch the network for changes and invoke callback when it happens.
dataProvider.watchAccountDetails({
onMessage: accountDetails => {
console.log("Latest account details: ", accountDetails);
},
onError: err => {
console.log("error: ", err);
},
});
```## Encrypting and storing secret keys
Our KeyManager class allows you to securely encrypt keys client-side so you're
never sending sensitive information (the user's key or password) over the wire
in a raw state.```js
import {
KeyManager,
KeyManagerPlugins,
KeyType,
} from "@bajetech/digitalbits-wallet-sdk";// To instantiate a keyManager instance, pass it an object that conforms to
// the KeyStore interface.
const keyManager = new KeyManager({
// The library comes with a sample KeyStore that stores keys in memory.
keyStore: new KeyManagerPlugins.MemoryKeyStore(),
});// Then, you need to register an encrypter to handle encrypting / decrypting keys.
// The library comes with two samples. (Don't use the Identity Encrypter in prod!)
keyManager.registerEncrypter(KeyManagerPlugins.ScryptEncrypter);// If you're writing a production wallet, you'll probably want to write your own
// KeyStore and/or Encrypter. Make sure they conform to the `KeyStore` and
// `Encrypter` interfaces defined in these docs. You can use the `PluginTesting`
// functions to make sure that your plugins meet spec!this.state.keyManager
.storeKey({
// The KeyManager takes keys that conform to our Key interface.
key: {
type: KeyType.plaintextKey,
publicKey: "<>",
privateKey: "<>",
},password: "hunter2",
encrypterName: KeyManagerPlugins.ScryptEncrypter.name,
})
.then(keyMetadata => {
console.log("Successfully encrypted and stored key: ", keyMetadata);
})
.catch(e => {
console.log("Error saving key: ", e.toString());
});
```