@tbd54566975/tbdex
v0.8.0
Published
Library that includes type definitions for tbdex messages
Downloads
36
Keywords
Readme
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
- clone the repo and
cd
into the project directory - Install all project dependencies by running
npm install
- start the test databases using
./scripts/start-databases
(requires Docker) - 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
After merging the PR, navigate to Github's
tags
section of this repo hereClick on
Releases
button and clickDraft a new release
.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
Click
Generate release notes
. This will auto-populate a list of all PRs merged to main since the last release.Click
Publish release
, which will kick off theRelease to NPM Registry
action, which you can see hereAfter the github action is successfully completed, you will have a new version of
@tbd54566975/tbdex
available in the NPM registry.