Skip to content

Commit

Permalink
fix examples to match current type declarations, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyoontbd committed Jul 12, 2023
1 parent e187b66 commit 2935af4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 105 deletions.
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/tbdex",
"version": "0.0.13",
"version": "0.0.14",
"type": "module",
"description": "Library that includes type definitions for tbdex messages",
"license": "Apache-2.0",
Expand All @@ -23,6 +23,10 @@
{
"name": "Phoebe Lew",
"url": "https://github.com/phoebe-lew"
},
{
"name": "Ethan Lee",
"url": "https://github.com/ethan-tbd"
}
],
"files": [
Expand Down
2 changes: 2 additions & 0 deletions js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export type Offering = {
payoutMethods: PaymentMethod[]
createdTime: string
}

export interface PaymentMethod {
// valid kind strings: 'CASHAPP_PAY', 'APPLE_PAY', 'BTC_ADDRESS'
kind: string
requiredPaymentDetails?: JsonSchema
feeSubunits?: string
Expand Down
193 changes: 108 additions & 85 deletions js/tbdex_types_examples.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,80 @@
import { TbDEXResource, MessageMetadata, TbDEXMessage, Status, Quote } from './src/types.js'
import { TbDEXResource, MessageMetadata, TbDEXMessage, Status, PresentationDefinitionV2 } from './src/types.js'


const presentationDefinition: PresentationDefinitionV2 = {
'id' : '2eddf25f-f79f-4105-ac81-544c988f6d78',
'name' : 'Core Personal Identity Claims',
'purpose' : 'Claims for PFI to evaluate Alice',
'input_descriptors' : [
{
'id' : '707585e4-3d74-49e7-b21e-a8e1cbf8e31b',
'purpose' : 'Claims for PFI to evaluate Alice',
'constraints' : {
'subject_is_issuer' : 'required',
'fields' : [
{
'path' : ['$.credentialSubject.givenName'],
'filter' : {
'type': 'string'
}
},
{
'path' : ['$.credentialSubject.familyName'],
'filter' : {
'type': 'string'
}
}
]
}
}
]
}

const btcPaymentSchema = {
'$schema' : 'http://json-schema.org/draft-07/schema#',
'title' : 'BTC Required Payment Details',
'type' : 'object',
'required' : [
'btcAddress'
],
'additionalProperties' : false,
'properties' : {
'btcAddress': {
'description' : 'The address you wish to receive BTC in',
'type' : 'string'
}
}
}

const _offering: TbDEXResource<'offering'> = {
id : '123',
description : 'Buy BTC with USD!',
quoteUnitsPerBaseUnit : '27000.00',
baseCurrency : {
currencyCode : 'BTC',
minSubunit : '1000',
maxSubunit : '100000000'
},
quoteCurrency: {
currencyCode : 'USD',
minSubunit : '1000',
maxSubunit : '1000'
},
kycRequirements: {
id : 'kyc',
input_descriptors : [presentationDefinition]
},
payinMethods: [{
kind : 'CASHAPP_PAY',
feeSubunits : '100'
}],
payoutMethods: [{
kind : 'BTC_ADDRESS',
requiredPaymentDetails : btcPaymentSchema,
}],
createdTime: '2023-06-27T12:34:56Z'
}

// const _offering: TbDEXResource<'offering'> = {
// id : '123',
// description : 'Buy BTC with USD!',
// baseCurrency : 'BTC',
// quoteCurrency : 'USD',
// unitPrice : '27000.00',
// baseFee : '1.00',
// min : '10.00',
// max : '1000.00',
// // here's what we want to see in your KYC VC (full name, dob)
// // maybe this is a sanctions VC? or maybe this is a silly VC that says 'send me a selfie'
// kycRequirements : 'eyJhb...MIDw',
// payinMethods : [{
// kind : PaymentMethodKind.DEBIT_CARD,
// // here's how to present your debit card info
// paymentpresentationDefinitionJwt : 'ey...IAbZ',
// fee : {
// flatFee: '1.00'
// }
// }],
// payoutMethods: [{
// kind : PaymentMethodKind.BITCOIN_ADDRESS,
// // how to present your BTC address info
// paymentpresentationDefinitionJwt : 'ey...EbqW',
// }],
// createdTime: '2023-06-27T12:34:56Z'
// }


const _metadata: MessageMetadata = {
Expand All @@ -35,40 +83,47 @@ const _metadata: MessageMetadata = {
parentId : 'rgsrew',
from : 'did:ion:fdsjaklfdsa',
to : 'did:ion:teuwoipew',
createdTime : '2023-06-26T12:34:31Z'
createdTime : '2023-06-26T12:34:56Z'
}


// const _rfq: TbDEXMessage<'rfq'> = {
// ..._metadata,
// type : 'rfq',
// body : {
// baseCurrency : 'BTC',
// quoteCurrency : 'USD',
// amount : '10.00',
// kycProof : 'eyJApQf...wqfVkg', // heres my KYC VC
// payinMethod : {
// kind : PaymentMethodKind.DEBIT_CARD,
// paymentVerifiablePresentationJwt : 'fdsafjdla'
// },
// payoutMethod: {
// kind : PaymentMethodKind.BITCOIN_ADDRESS,
// paymentVerifiablePresentationJwt : 'rewhiroew'
// }
// }
const _rfq: TbDEXMessage<'rfq'> = {
..._metadata,
type : 'rfq',
body : {
offeringId : '1',
quoteAmountSubunits : '1000',
kycProof : 'eyJApQf...wqfVkg', // KYC VP in JWT format
payinMethod : {
kind: 'CASHAPP_PAY'
},
payoutMethod: {
kind : 'BTC_ADDRESS',
paymentDetails : {
btcAddress: 'bc1dahklrjeaklf'
}
}
}

// }
}

const _quote: TbDEXMessage<'quote'> = {
..._metadata,
type : 'quote',
body : {
expiryTime : '2023-04-14T12:12:12Z',
totalFee : '2.00',
amount : '0.000383',
paymentInstructions : {
expiryTime : '2023-06-26T12:44:56Z',
base : {
currencyCode : 'BTC',
amountSubunits : '33333'
},
quote: {
currencyCode : 'USD',
amountSubunits : '1000',
feeSubunits : '100'
},
paymentInstructions: {
payin: {
link: 'stripe.com?for=alice&amount=10'
link: 'cashapp-pay.com?for=alice&amount=10'
}
}
}
Expand All @@ -79,38 +134,6 @@ const _status: TbDEXMessage<'orderStatus'> = {
..._metadata,
type : 'orderStatus',
body : {
orderStatus: Status.PENDING
orderStatus: Status.PAYIN_INITIATED
}
}


const offering1: TbDEXResource<'offering'> = {
'baseCurrency': {
'currencyCode': 'BTC',
},
'quoteCurrency': {
'currencyCode': 'USD'
},
'kycRequirements': {},
'payinMethods': [{
'kind': 'APPLE_PAY',
'feeSubunits': '300'
}],
'payoutMethods': [{
'kind': 'BTC_ADDRESS'
}],
'createdTime': 'happy time',
}

const quote1: Quote = {
'base': {
'currencyCode': 'BTC',
'amountSubunits': '10 MEELYON SATS',
},
'quote': {
'currencyCode': 'USD',
'amountSubunits': '29_000_000_000',
'feeSubunits': '300'
},
'expiryTime': 'sad time'
}
41 changes: 24 additions & 17 deletions js/tests/builders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { type Quote, type Rfq, type TbDEXMessage, PaymentMethodKind } from '../src/types.js'
import { type Quote, type Rfq, type TbDEXMessage } from '../src/types.js'

import { expect } from 'chai'
import { createMessage } from '../src/builders.js'

describe('messages builders', () => {
it('can build an rfq', () => {
const rfq: Rfq = {
offeringId : '123',
amountCents : '1000',
kycProof : 'fake-jwt',
payinMethod : {
kind: PaymentMethodKind.APPLE_PAY,
offeringId : '123',
quoteAmountSubunits : '1000',
kycProof : 'fake-jwt',
payinMethod : {
kind: 'APPLE_PAY',
},
payoutMethod: {
kind : PaymentMethodKind.BTC_ADDRESS,
kind : 'BTC_ADDRESS',
paymentDetails : {
btcAddress: 'abcd123'
}
Expand All @@ -32,14 +32,14 @@ describe('messages builders', () => {
})
it('builds the expected message for an existing thread', () => {
const rfq: Rfq = {
offeringId : '123',
amountCents : '1000',
kycProof : 'fake-jwt',
payinMethod : {
kind: PaymentMethodKind.APPLE_PAY,
offeringId : '123',
quoteAmountSubunits : '1000',
kycProof : 'fake-jwt',
payinMethod : {
kind: 'APPLE_PAY',
},
payoutMethod: {
kind : PaymentMethodKind.BTC_ADDRESS,
kind : 'BTC_ADDRESS',
paymentDetails : {
btcAddress: 'abcd123'
}
Expand All @@ -54,10 +54,17 @@ describe('messages builders', () => {
})

const quote: Quote = {
expiryTime : new Date().toISOString(),
totalFeeCents : '100',
amountCents : '1000',
paymentInstructions : { payin: { link: 'fake.link.com' } },
expiryTime : new Date().toISOString(),
base : {
currencyCode : 'BTC',
amountSubunits : '33333'
},
quote: {
currencyCode : 'USD',
amountSubunits : '1000',
feeSubunits : '100'
},
paymentInstructions: { payin: { link: 'fake.link.com' } },
}

const { from, to, threadId, parentId } = createMessage({
Expand Down

0 comments on commit 2935af4

Please sign in to comment.