Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Oct 24, 2024
1 parent 4f5bc62 commit ea22640
Showing 1 changed file with 73 additions and 33 deletions.
106 changes: 73 additions & 33 deletions bound/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,99 @@ npm install @tbdex/sdk

## Basic Usage

### Creating and Managing Exchanges
### Message Creation

```typescript
import {
BearerDid,
Rfq,
CreateRfqData,
} from '@tbdex/sdk';

const createRfqData: CreateRfqData = {
claims: [verifiableCredential],
offeringId,
payin: {
amount: '101',
kind: 'USD_LEDGER',
paymentDetails: null,
},
payout: {
kind: 'MOMO_MPESA',
paymentDetails: {
phoneNumber: '867-5309',
reason: 'cause',
},
},
};

const rfq = Rfq.create(pfiDidUri, bearerDid.did.uri, createRfqData);

await rfq.sign(bearerDid);
await rfq.verify();
```

### Message Parsing
```typescript

import {
Rfq,
} from '@tbdex/sdk';

const jsonMessage = "<SERIALIZED_MESSAGE>"
const rfq = Rfq.fromJSONString(jsonMessage);
```

### Http Client Create Exchange Flow
```typescript
import {
Rfq,
CreateRfqData,
BearerDid,
getOfferings,
createExchange,
getExchange
} from 'tbdex';

// Create a new Bearer DID
const bearerDid = await BearerDid.create();
getExchange,
Exchange,
} from '@tbdex/sdk';

// Step 1: Fetch offerings
console.log('1. Fetching offerings...');
const offerings = await getOfferings(pfiDidUri);
if (!offerings || offerings.length === 0) {
throw new Error('No offerings available.');
}

// Fetch available offerings
const offerings = await getOfferings('did:example:pfi123');
const offeringId = offerings[0].metadata.id;

// Create an RFQ (Request for Quote)
const rfqData: CreateRfqData = {
offeringId,
claims: ['credentialJwt'],
payin: {
amount: '100',
console.log(`Successfully fetched offering ID: ${offeringId}\n`);

// Step 2: Create exchange (RFQ)
console.log('2. Creating exchange...');
const createRfqData: CreateRfqData = {
claims: [verifiableCredential],
offeringId,
payin: {
amount: '101',
kind: 'USD_LEDGER',
paymentDetails: null
},
payout: {
paymentDetails: null,
},
payout: {
kind: 'PAYOUT_KIND',
paymentDetails: {
phoneNumber: '555-0123',
reason: 'payment'
}
}
phoneNumber: '867-5309',
reason: 'cause',
},
},
};

// Create and sign the RFQ
const rfq = Rfq.create('did:example:pfi123', bearerDid.did.uri, rfqData);
const rfq = Rfq.create(pfiDidUri, bearerDid.did.uri, createRfqData);
await rfq.sign(bearerDid);
await rfq.verify();

// Submit the RFQ to create an exchange
await createExchange(rfq);

// Get exchange details
const exchange = await getExchange(
'did:example:pfi123',
bearerDid,
rfq.metadata.exchangeId
);
const exchangeId = rfq.metadata.exchangeId;
console.log(`Created exchange with ID: ${exchangeId}\n`);
```


## Message Types

The SDK supports all tbDEX message types:
Expand Down

0 comments on commit ea22640

Please sign in to comment.