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

feat: add validation #4

Merged
merged 37 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f82861c
add `tbdex` submodule
ethanwlee Mar 29, 2024
85afe97
add `json_schema` and `path` deps
ethanwlee Mar 29, 2024
c8edaee
remove unused pattern
ethanwlee Mar 29, 2024
312412f
generate id using `TypeId`
ethanwlee Mar 29, 2024
6ef095b
use `JsonSchema`
ethanwlee Mar 29, 2024
42844a7
add `Validator`
ethanwlee Mar 29, 2024
92f7da2
progress on `verifyOfferingRequirements()`
ethanwlee Mar 29, 2024
f065ff6
fix validation errors
ethanwlee Mar 29, 2024
664e8f4
remove print
ethanwlee Mar 29, 2024
873fb01
fix serialization issue with `requiredPaymentDetails` json schema
ethanwlee Mar 29, 2024
f9e127c
add `decimal` dep
ethanwlee Mar 29, 2024
3dfd5e1
add `orElse` to `firstWhere()`
ethanwlee Mar 29, 2024
a1fcb1f
add more exception handling to `verifyOfferingRequirements()`
ethanwlee Mar 29, 2024
9d68f55
change description in `having()`
ethanwlee Mar 29, 2024
ff5a484
add todo about explicit parsing
ethanwlee Mar 29, 2024
122e982
update `getOffering()` and `getRfq()` to test `verifyOfferingRequirem…
ethanwlee Mar 29, 2024
fd941ec
add tests for `verifyOfferingRequirements()`
ethanwlee Mar 29, 2024
bd9d457
refactor `initialize()`
ethanwlee Mar 29, 2024
28eb374
use `json` as variable name for `jsonEncode()`
ethanwlee Mar 29, 2024
7f6a3cd
update `tbdex` submodule
ethanwlee Mar 29, 2024
cf0ae2a
use private instance to initialize validator
ethanwlee Mar 29, 2024
9fe92cf
add just command to copy json-schemas from tbdex submodule
ethanwlee Mar 29, 2024
6f82097
remove initialize validator
ethanwlee Mar 29, 2024
d085647
check in json schemas from tbdex submodule
ethanwlee Mar 29, 2024
bfe940a
update path to new json-schemas folder
ethanwlee Mar 29, 2024
dc37978
add get, test, and analyze
ethanwlee Mar 29, 2024
80f3706
delete issue template
ethanwlee Mar 29, 2024
123b34c
add ci workflow
ethanwlee Mar 29, 2024
342ef5b
update exception message
ethanwlee Mar 29, 2024
e518f51
use `@` for all commands
ethanwlee Mar 30, 2024
fa613e0
update ci steps
ethanwlee Mar 30, 2024
2754bdc
add dart to hermit
ethanwlee Apr 1, 2024
9054022
fix property access on `dynamic`
ethanwlee Apr 1, 2024
de61000
add publish to none
ethanwlee Apr 1, 2024
b6a837d
move private constructor
ethanwlee Apr 1, 2024
08ba5d2
fix metadata casts
ethanwlee Apr 1, 2024
c041300
remove unused constructor
ethanwlee Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/ISSUE_TEMPLATE/bug-report.md

This file was deleted.

4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true

- name: Install Dependencies
run: just get

- name: Run Static Analysis
run: just analyze

- name: Run Tests
run: just test
Comment on lines +18 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tbdex"]
path = tbdex
url = [email protected]:TBD54566975/tbdex.git
12 changes: 12 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schemas:
@git submodule update --init --recursive
@cp -r tbdex/hosted/json-schemas lib/src/protocol

get:
@dart pub get

test:
@dart test

analyze:
@dart analyze
1 change: 1 addition & 0 deletions bin/.dart-3.3.3.pkg
1 change: 1 addition & 0 deletions bin/.just-1.25.2.pkg
1 change: 1 addition & 0 deletions bin/dart
1 change: 1 addition & 0 deletions bin/dart.sym
1 change: 1 addition & 0 deletions bin/dartaotruntime
1 change: 1 addition & 0 deletions bin/just
20 changes: 20 additions & 0 deletions lib/src/protocol/json-schemas/balance.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/balance.schema.json",
"type": "object",
"properties": {
"additionalProperties": false,
"currencyCode": {
"type": "string",
"description": "ISO 3166 currency code string"
},
"available": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "The amount available to be transacted with"
}
},
"required": [
"currencyCode",
"available"
]
}
14 changes: 14 additions & 0 deletions lib/src/protocol/json-schemas/close.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/close.schema.json",
"type": "object",
"additionalProperties": false,
"properties": {
"reason": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
}
15 changes: 15 additions & 0 deletions lib/src/protocol/json-schemas/definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/definitions.json",
"type": "object",
"definitions": {
"did": {
"type": "string",
"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_.:%-]*)*)(\/[^#?]*)?([?][^#]*)?(#.*)?$"
},
"decimalString": {
"type": "string",
"pattern": "^([0-9]+(?:[.][0-9]+)?)$"
}
}
}
69 changes: 69 additions & 0 deletions lib/src/protocol/json-schemas/message.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/message.schema.json",
"definitions": {
"MessageMetadata": {
"type": "object",
"additionalProperties": false,
"properties": {
"from": {
"$ref": "definitions.json#/definitions/did",
"description": "The sender's DID"
},
"to": {
"$ref": "definitions.json#/definitions/did",
"description": "The recipient's DID"
},
"kind": {
"type": "string",
"enum": ["rfq", "quote", "order", "orderstatus", "close"],
"description": "The message kind (e.g. rfq, quote)"
},
"id": {
"type": "string",
"description": "The message ID"
},
"exchangeId": {
"type": "string",
"description": "ID for a 'thread' of messages between Alice <-> PFI. Set by the first message in a thread"
},
"externalId": {
"type": "string",
"description": "Arbitrary ID for the caller to associate with the message."
},
"createdAt": {
"type": "string",
"description": "ISO8601 formatted string representing the timestamp"
},
"protocol": {
"type": "string",
"description": "Version of the protocol in use (x.x format)"
}
},
"required": ["from", "to", "kind", "id", "exchangeId", "createdAt", "protocol"]
},
"Private": {
"type": "object",
"description": "An ephemeral JSON object used to transmit sensitive data (e.g. PII)"
}
},
"type": "object",
"properties": {
"metadata": {
"$ref": "#/definitions/MessageMetadata"
},
"data": {
"type": "object",
"description": "The actual message content"
},
"signature": {
"type": "string",
"description": "Signature that verifies the authenticity and integrity of a message"
},
"private": {
"$ref": "#/definitions/Private"
}
},
"additionalProperties": false,
"required": ["metadata", "data", "signature"]
}
153 changes: 153 additions & 0 deletions lib/src/protocol/json-schemas/offering.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/offering.schema.json",
"type": "object",
"properties": {
"additionalProperties": false,
"description": {
"type": "string",
"description": "Brief description of what is being offered."
},
"payin": {
"type": "object",
"additionalProperties": false,
"properties": {
"currencyCode": {
"type": "string",
"description": "ISO 3166 currency code string"
},
"min": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Minimum amount of currency that can be requested"
},
"max": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Maximum amount of currency that can be requested"
},
"methods": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"kind": {
"type": "string",
"description": "The type of payment method. e.g. BITCOIN_ADDRESS, DEBIT_CARD, etc."
},
"name": {
"type": "string",
"description": "Payment Method name. Expected to be rendered on screen."
},
"description": {
"type": "string",
"description": "Blurb containing helpful information about the payment method. Expected to be rendered on screen. e.g. \"segwit addresses only\""
},
"group": {
"type": "string",
"description": "Value that can be used to group specific payment methods together (e.g. Mobile Money vs. Direct Bank Deposit)."
},
"requiredPaymentDetails": {
"$ref": "http://json-schema.org/draft-07/schema",
"description": "A JSON Schema containing the fields that need to be collected in order to use this payment method"
},
"min": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Minimum amount required to use this payment method."
},
"max": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Maximum amount allowed when using this payment method."
},
"fee": {
"$ref": "definitions.json#/definitions/decimalString",
"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."
}
},
"required": ["kind"]
}
}
},
"required": ["currencyCode", "methods"]
},
"payout": {
"type": "object",
"additionalProperties": false,
"properties": {
"currencyCode": {
"type": "string",
"description": "ISO 3166 currency code string"
},
"min": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Minimum amount of currency that can be requested"
},
"max": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Maximum amount of currency that can be requested"
},
"methods": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"kind": {
"type": "string",
"description": "The type of payment method. e.g. BITCOIN_ADDRESS, DEBIT_CARD, etc."
},
"name": {
"type": "string",
"description": "Payment Method name. Expected to be rendered on screen."
},
"description": {
"type": "string",
"description": "Blurb containing helpful information about the payment method. Expected to be rendered on screen. e.g. \"segwit addresses only\""
},
"group": {
"type": "string",
"description": "Value that can be used to group specific payment methods together (e.g. Mobile Money vs. Direct Bank Deposit)."
},
"requiredPaymentDetails": {
"$ref": "http://json-schema.org/draft-07/schema",
"description": "A JSON Schema containing the fields that need to be collected in order to use this payment method"
},
"min": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Minimum amount required to use this payment method."
},
"max": {
"$ref": "definitions.json#/definitions/decimalString",
"description": "Maximum amount allowed when using this payment method."
},
"fee": {
"$ref": "definitions.json#/definitions/decimalString",
"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"
},
"estimatedSettlementTime": {
"type": "number",
"description": "Estimated time in seconds for the payout to be settled. e.g. 3600 for 1 hour. 0 for instant settlement.",
"minimum": 0
}
},
"required": ["kind", "estimatedSettlementTime"]
}
}
},
"required": ["currencyCode", "methods"]
},
"payoutUnitsPerPayinUnit": {
"type": "string",
"description": "Number of payout currency units for one payin currency unit (i.e 290000 USD for 1 BTC)"
},
"requiredClaims": {
"type": "object",
"description": "PresentationDefinition that describes the credential(s) the PFI requires in order to provide a quote."
}
},
"required": [
"description",
"payin",
"payout",
"payoutUnitsPerPayinUnit"
]
}
7 changes: 7 additions & 0 deletions lib/src/protocol/json-schemas/order.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://tbdex.dev/order.schema.json",
"type": "object",
"additionalProperties": false,
"properties": {}
}
Loading
Loading