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

Commit 3130a86

Browse files
authored
feat: add validation (#4)
* add `tbdex` submodule * add `json_schema` and `path` deps * remove unused pattern * generate id using `TypeId` * use `JsonSchema` * add `Validator` * progress on `verifyOfferingRequirements()` * fix validation errors * remove print * fix serialization issue with `requiredPaymentDetails` json schema * add `decimal` dep * add `orElse` to `firstWhere()` * add more exception handling to `verifyOfferingRequirements()` * change description in `having()` * add todo about explicit parsing * update `getOffering()` and `getRfq()` to test `verifyOfferingRequirements()` * add tests for `verifyOfferingRequirements()` * refactor `initialize()` * use `json` as variable name for `jsonEncode()` * update `tbdex` submodule * use private instance to initialize validator * add just command to copy json-schemas from tbdex submodule * remove initialize validator * check in json schemas from tbdex submodule * update path to new json-schemas folder * add get, test, and analyze * delete issue template * add ci workflow * update exception message * use `@` for all commands * update ci steps * add dart to hermit * fix property access on `dynamic` * add publish to none * move private constructor * fix metadata casts * remove unused constructor
1 parent bf615e9 commit 3130a86

40 files changed

+849
-179
lines changed

.github/ISSUE_TEMPLATE/bug-report.md

-31
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

-4
This file was deleted.

.github/workflows/ci.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: true
17+
18+
- name: Init Hermit
19+
uses: cashapp/activate-hermit@v1
20+
with:
21+
cache: true
22+
23+
- name: Install Dependencies
24+
run: just get
25+
26+
- name: Run Static Analysis
27+
run: just analyze
28+
29+
- name: Run Tests
30+
run: just test

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tbdex"]
2+
path = tbdex
3+
url = [email protected]:TBD54566975/tbdex.git

Justfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schemas:
2+
@git submodule update --init --recursive
3+
@cp -r tbdex/hosted/json-schemas lib/src/protocol
4+
5+
get:
6+
@dart pub get
7+
8+
test:
9+
@dart test
10+
11+
analyze:
12+
@dart analyze

bin/.dart-3.3.3.pkg

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hermit

bin/.just-1.25.2.pkg

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hermit

bin/dart

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.dart-3.3.3.pkg

bin/dart.sym

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.dart-3.3.3.pkg

bin/dartaotruntime

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.dart-3.3.3.pkg

bin/just

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.just-1.25.2.pkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/balance.schema.json",
4+
"type": "object",
5+
"properties": {
6+
"additionalProperties": false,
7+
"currencyCode": {
8+
"type": "string",
9+
"description": "ISO 3166 currency code string"
10+
},
11+
"available": {
12+
"$ref": "definitions.json#/definitions/decimalString",
13+
"description": "The amount available to be transacted with"
14+
}
15+
},
16+
"required": [
17+
"currencyCode",
18+
"available"
19+
]
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/close.schema.json",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"properties": {
7+
"reason": {
8+
"type": "string"
9+
},
10+
"success": {
11+
"type": "boolean"
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/definitions.json",
4+
"type": "object",
5+
"definitions": {
6+
"did": {
7+
"type": "string",
8+
"pattern": "^did:([a-z0-9]+):((?:(?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))*:)*((?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))+))((;[a-zA-Z0-9_.:%-]+=[a-zA-Z0-9_.:%-]*)*)(\/[^#?]*)?([?][^#]*)?(#.*)?$"
9+
},
10+
"decimalString": {
11+
"type": "string",
12+
"pattern": "^([0-9]+(?:[.][0-9]+)?)$"
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/message.schema.json",
4+
"definitions": {
5+
"MessageMetadata": {
6+
"type": "object",
7+
"additionalProperties": false,
8+
"properties": {
9+
"from": {
10+
"$ref": "definitions.json#/definitions/did",
11+
"description": "The sender's DID"
12+
},
13+
"to": {
14+
"$ref": "definitions.json#/definitions/did",
15+
"description": "The recipient's DID"
16+
},
17+
"kind": {
18+
"type": "string",
19+
"enum": ["rfq", "quote", "order", "orderstatus", "close"],
20+
"description": "The message kind (e.g. rfq, quote)"
21+
},
22+
"id": {
23+
"type": "string",
24+
"description": "The message ID"
25+
},
26+
"exchangeId": {
27+
"type": "string",
28+
"description": "ID for a 'thread' of messages between Alice <-> PFI. Set by the first message in a thread"
29+
},
30+
"externalId": {
31+
"type": "string",
32+
"description": "Arbitrary ID for the caller to associate with the message."
33+
},
34+
"createdAt": {
35+
"type": "string",
36+
"description": "ISO8601 formatted string representing the timestamp"
37+
},
38+
"protocol": {
39+
"type": "string",
40+
"description": "Version of the protocol in use (x.x format)"
41+
}
42+
},
43+
"required": ["from", "to", "kind", "id", "exchangeId", "createdAt", "protocol"]
44+
},
45+
"Private": {
46+
"type": "object",
47+
"description": "An ephemeral JSON object used to transmit sensitive data (e.g. PII)"
48+
}
49+
},
50+
"type": "object",
51+
"properties": {
52+
"metadata": {
53+
"$ref": "#/definitions/MessageMetadata"
54+
},
55+
"data": {
56+
"type": "object",
57+
"description": "The actual message content"
58+
},
59+
"signature": {
60+
"type": "string",
61+
"description": "Signature that verifies the authenticity and integrity of a message"
62+
},
63+
"private": {
64+
"$ref": "#/definitions/Private"
65+
}
66+
},
67+
"additionalProperties": false,
68+
"required": ["metadata", "data", "signature"]
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/offering.schema.json",
4+
"type": "object",
5+
"properties": {
6+
"additionalProperties": false,
7+
"description": {
8+
"type": "string",
9+
"description": "Brief description of what is being offered."
10+
},
11+
"payin": {
12+
"type": "object",
13+
"additionalProperties": false,
14+
"properties": {
15+
"currencyCode": {
16+
"type": "string",
17+
"description": "ISO 3166 currency code string"
18+
},
19+
"min": {
20+
"$ref": "definitions.json#/definitions/decimalString",
21+
"description": "Minimum amount of currency that can be requested"
22+
},
23+
"max": {
24+
"$ref": "definitions.json#/definitions/decimalString",
25+
"description": "Maximum amount of currency that can be requested"
26+
},
27+
"methods": {
28+
"type": "array",
29+
"items": {
30+
"type": "object",
31+
"additionalProperties": false,
32+
"properties": {
33+
"kind": {
34+
"type": "string",
35+
"description": "The type of payment method. e.g. BITCOIN_ADDRESS, DEBIT_CARD, etc."
36+
},
37+
"name": {
38+
"type": "string",
39+
"description": "Payment Method name. Expected to be rendered on screen."
40+
},
41+
"description": {
42+
"type": "string",
43+
"description": "Blurb containing helpful information about the payment method. Expected to be rendered on screen. e.g. \"segwit addresses only\""
44+
},
45+
"group": {
46+
"type": "string",
47+
"description": "Value that can be used to group specific payment methods together (e.g. Mobile Money vs. Direct Bank Deposit)."
48+
},
49+
"requiredPaymentDetails": {
50+
"$ref": "http://json-schema.org/draft-07/schema",
51+
"description": "A JSON Schema containing the fields that need to be collected in order to use this payment method"
52+
},
53+
"min": {
54+
"$ref": "definitions.json#/definitions/decimalString",
55+
"description": "Minimum amount required to use this payment method."
56+
},
57+
"max": {
58+
"$ref": "definitions.json#/definitions/decimalString",
59+
"description": "Maximum amount allowed when using this payment method."
60+
},
61+
"fee": {
62+
"$ref": "definitions.json#/definitions/decimalString",
63+
"description": "Fee charged to use this payment method. Absence of this field implies that there is no _additional_ fee associated to the respective payment method."
64+
}
65+
},
66+
"required": ["kind"]
67+
}
68+
}
69+
},
70+
"required": ["currencyCode", "methods"]
71+
},
72+
"payout": {
73+
"type": "object",
74+
"additionalProperties": false,
75+
"properties": {
76+
"currencyCode": {
77+
"type": "string",
78+
"description": "ISO 3166 currency code string"
79+
},
80+
"min": {
81+
"$ref": "definitions.json#/definitions/decimalString",
82+
"description": "Minimum amount of currency that can be requested"
83+
},
84+
"max": {
85+
"$ref": "definitions.json#/definitions/decimalString",
86+
"description": "Maximum amount of currency that can be requested"
87+
},
88+
"methods": {
89+
"type": "array",
90+
"items": {
91+
"type": "object",
92+
"additionalProperties": false,
93+
"properties": {
94+
"kind": {
95+
"type": "string",
96+
"description": "The type of payment method. e.g. BITCOIN_ADDRESS, DEBIT_CARD, etc."
97+
},
98+
"name": {
99+
"type": "string",
100+
"description": "Payment Method name. Expected to be rendered on screen."
101+
},
102+
"description": {
103+
"type": "string",
104+
"description": "Blurb containing helpful information about the payment method. Expected to be rendered on screen. e.g. \"segwit addresses only\""
105+
},
106+
"group": {
107+
"type": "string",
108+
"description": "Value that can be used to group specific payment methods together (e.g. Mobile Money vs. Direct Bank Deposit)."
109+
},
110+
"requiredPaymentDetails": {
111+
"$ref": "http://json-schema.org/draft-07/schema",
112+
"description": "A JSON Schema containing the fields that need to be collected in order to use this payment method"
113+
},
114+
"min": {
115+
"$ref": "definitions.json#/definitions/decimalString",
116+
"description": "Minimum amount required to use this payment method."
117+
},
118+
"max": {
119+
"$ref": "definitions.json#/definitions/decimalString",
120+
"description": "Maximum amount allowed when using this payment method."
121+
},
122+
"fee": {
123+
"$ref": "definitions.json#/definitions/decimalString",
124+
"description": "Fee charged to use this payment method. absence of this field implies that there is no _additional_ fee associated to the respective payment method"
125+
},
126+
"estimatedSettlementTime": {
127+
"type": "number",
128+
"description": "Estimated time in seconds for the payout to be settled. e.g. 3600 for 1 hour. 0 for instant settlement.",
129+
"minimum": 0
130+
}
131+
},
132+
"required": ["kind", "estimatedSettlementTime"]
133+
}
134+
}
135+
},
136+
"required": ["currencyCode", "methods"]
137+
},
138+
"payoutUnitsPerPayinUnit": {
139+
"type": "string",
140+
"description": "Number of payout currency units for one payin currency unit (i.e 290000 USD for 1 BTC)"
141+
},
142+
"requiredClaims": {
143+
"type": "object",
144+
"description": "PresentationDefinition that describes the credential(s) the PFI requires in order to provide a quote."
145+
}
146+
},
147+
"required": [
148+
"description",
149+
"payin",
150+
"payout",
151+
"payoutUnitsPerPayinUnit"
152+
]
153+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://tbdex.dev/order.schema.json",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"properties": {}
7+
}

0 commit comments

Comments
 (0)