@tbd54566975/tbdex
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

tbDEX Protocol

Library that can be used to:

  • create, parse, verify, and validate the tbDEX Messages and Resources defined in the protocol specification
  • send requests to PFIs

Table of Contents

Installation

npm install @tbd54566975/tbdex

Usage

Message Creation

There's a concrete class for each Message Kind. These classes can be used to create messages. e.g.

import { DevTools, Rfq } from '@tbd54566975/tbdex'

const rfq = Rfq.create({
  metadata : { from: alice.did, to: 'did:ex:pfi' },
  data     : {
    offeringId  : 'abcd123',
    payinMethod : {
      kind           : 'DEBIT_CARD',
      paymentDetails : {
        'cardNumber'     : '1234567890123456',
        'expiryDate'     : '12/22',
        'cardHolderName' : 'Ephraim Bartholomew Winthrop',
        'cvv'            : '123'
      }
    },
    payoutMethod: {
      kind           : 'BTC_ADDRESS',
      paymentDetails : {
        btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
      }
    },
    quoteAmountSubunits : '20000',
    vcs                 : ''
  }
})

await rfq.sign(alice)

console.log(JSON.stringify(rfq, null, 2))

Message Parsing

All messages can be parsed from json into an instance of the Message Kind's class using the Message.parse method. e.g.

import { Message } from '@tbd54566975/tbdex'

const jsonMessage = "<SERIALIZED_MESSAGE>"
const message = await Message.parse(jsonMessage)

if (message.isRfq()) {
  // rfq specific logic
}

Parsing a message includes format validation and integrity checking

Message Validation

[!NOTE]

TODO: Fill Out

Integrity Check

[!NOTE]

TODO: Fill Out

Sending Requests

[!NOTE]

TODO: Fill Out

Development

Prerequisites

node and npm

This project is using node v20.3.0 and npm v9.6.7. You can verify your node and npm installation via the terminal:

$ node --version
v20.3.0
$ npm --version
9.6.7

If you don't have node installed. Feel free to choose whichever approach you feel the most comfortable with. If you don't have a preferred installation method, i'd recommend using nvm (aka node version manager). nvm allows you to install and use different versions of node. It can be installed by running brew install nvm (assuming that you have homebrew)

Once you have installed nvm, install the desired node version with nvm install vX.Y.Z.

Running Tests

[!NOTE]

Make sure you have all the prerequisites

  1. clone the repo and cd into the project directory
  2. Install all project dependencies by running npm install
  3. start the test databases using ./scripts/start-databases (requires Docker)
  4. run tests using npm run test

npm scripts

Script Description
npm run clean deletes dist dir and compiled tests
npm run test:node runs tests in node runtime
npm run test:browser runs tests in headless browsers (chrome, safari, firefox)
npm run lint runs linter without auto-fixing
npm run lint:fix runs linter and applies automatic fixes wherever possible
npm run build builds all distributions and dumps them into dist

Publishing Releases

[!NOTE]

This section is applicable to core maintainers only

[!IMPORTANT]

be sure to version bump the package in package.json before merging a PR

  1. After merging the PR, navigate to Github's tags section of this repo here Tags

  2. Click on Releases button and click Draft a new release.

  3. Click on Choose a tag, then create a new tag with the version number matching from step 3. The release title is also the same version number, i.e. v0.0.3 New release

  4. Click Generate release notes. This will auto-populate a list of all PRs merged to main since the last release. Generated release notes

  5. Click Publish release, which will kick off the Release to NPM Registry action, which you can see here

  6. After the github action is successfully completed, you will have a new version of @tbd54566975/tbdex available in the NPM registry.

Readme

Keywords

none

Package Sidebar

Install

npm i @tbd54566975/tbdex

Weekly Downloads

123

Version

0.8.0

License

Apache-2.0

Unpacked Size

9.96 MB

Total Files

111

Last publish

Collaborators

  • tbd-releases
  • kendallweihe
  • shamilovtim
  • frankhinek
  • michaelneale
  • csuwildcat
  • mistermoe
  • alrubinger
  • nitroneal
  • mktbd
  • henrytsai