@bsv/create-dpp-app 0.0.0-stage → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/LICENSE +203 -0
  2. package/NOTICE +2 -0
  3. package/PATENTS +12 -0
  4. package/README.md +93 -2
  5. package/dist/index.js +125 -0
  6. package/package.json +57 -4
  7. package/template/Dockerfile +37 -0
  8. package/template/README.md +389 -0
  9. package/template/_dockerignore +6 -0
  10. package/template/_env.example +122 -0
  11. package/template/_github/workflows/ci.yml +23 -0
  12. package/template/_gitignore +8 -0
  13. package/template/_prettierrc +6 -0
  14. package/template/apps/api/API.md +119 -0
  15. package/template/apps/api/package.json +39 -0
  16. package/template/apps/api/src/auth.ts +55 -0
  17. package/template/apps/api/src/bound-profiles.ts +590 -0
  18. package/template/apps/api/src/claims.ts +204 -0
  19. package/template/apps/api/src/cli.ts +99 -0
  20. package/template/apps/api/src/config.ts +180 -0
  21. package/template/apps/api/src/custody.ts +358 -0
  22. package/template/apps/api/src/dev-index.ts +120 -0
  23. package/template/apps/api/src/env-file.ts +55 -0
  24. package/template/apps/api/src/env.ts +14 -0
  25. package/template/apps/api/src/epcis/exchange.ts +434 -0
  26. package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
  27. package/template/apps/api/src/epcis/routes.ts +364 -0
  28. package/template/apps/api/src/epcis/sources.ts +142 -0
  29. package/template/apps/api/src/go-live.ts +226 -0
  30. package/template/apps/api/src/http-error.ts +15 -0
  31. package/template/apps/api/src/identifiers.ts +57 -0
  32. package/template/apps/api/src/index-client.ts +261 -0
  33. package/template/apps/api/src/index-projects.ts +53 -0
  34. package/template/apps/api/src/lifecycle-authority.ts +49 -0
  35. package/template/apps/api/src/lifecycle.ts +485 -0
  36. package/template/apps/api/src/main.ts +58 -0
  37. package/template/apps/api/src/parties.ts +68 -0
  38. package/template/apps/api/src/platform.ts +176 -0
  39. package/template/apps/api/src/portability/commands.ts +224 -0
  40. package/template/apps/api/src/portability/export.ts +708 -0
  41. package/template/apps/api/src/portability/package.ts +270 -0
  42. package/template/apps/api/src/portability/restore.ts +863 -0
  43. package/template/apps/api/src/profiles.ts +125 -0
  44. package/template/apps/api/src/reader.ts +265 -0
  45. package/template/apps/api/src/resolver.ts +159 -0
  46. package/template/apps/api/src/sector-examples.ts +390 -0
  47. package/template/apps/api/src/server.ts +613 -0
  48. package/template/apps/api/src/store.ts +426 -0
  49. package/template/apps/api/src/validation-engine.ts +172 -0
  50. package/template/apps/api/src/wallet.ts +359 -0
  51. package/template/apps/api/src/worker.ts +113 -0
  52. package/template/apps/api/src/writer.ts +603 -0
  53. package/template/apps/api/test/bound-http.test.ts +496 -0
  54. package/template/apps/api/test/bound-profiles.test.ts +547 -0
  55. package/template/apps/api/test/config.test.ts +160 -0
  56. package/template/apps/api/test/custody-journal.test.ts +415 -0
  57. package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
  58. package/template/apps/api/test/custom-profile.test.ts +167 -0
  59. package/template/apps/api/test/env-file.test.ts +53 -0
  60. package/template/apps/api/test/epcis-fixtures.ts +270 -0
  61. package/template/apps/api/test/epcis-http.test.ts +1179 -0
  62. package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
  63. package/template/apps/api/test/epcis-separation.test.ts +253 -0
  64. package/template/apps/api/test/epcis-web.test.ts +230 -0
  65. package/template/apps/api/test/exit-exercise.test.ts +1038 -0
  66. package/template/apps/api/test/external-index.test.ts +32 -0
  67. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
  68. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
  69. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
  70. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
  71. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
  72. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
  73. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
  74. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
  75. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
  76. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
  77. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
  78. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
  79. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
  80. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
  81. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
  82. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
  83. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
  84. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
  85. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
  86. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
  87. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
  88. package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
  89. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
  90. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
  91. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
  92. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
  93. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
  94. package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
  95. package/template/apps/api/test/go-live.test.ts +179 -0
  96. package/template/apps/api/test/gs1-global-setup.ts +33 -0
  97. package/template/apps/api/test/gs1-test-env.ts +5 -0
  98. package/template/apps/api/test/identifier-host.test.ts +256 -0
  99. package/template/apps/api/test/index-projects.test.ts +81 -0
  100. package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
  101. package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
  102. package/template/apps/api/test/lifecycle.test.ts +147 -0
  103. package/template/apps/api/test/manifest-notice.test.ts +36 -0
  104. package/template/apps/api/test/network-guard.ts +113 -0
  105. package/template/apps/api/test/portability.test.ts +655 -0
  106. package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
  107. package/template/apps/api/test/retired-profiles.test.ts +216 -0
  108. package/template/apps/api/test/sector-cutover.test.ts +95 -0
  109. package/template/apps/api/test/sector-forms.test.ts +420 -0
  110. package/template/apps/api/test/unjoined-index.test.ts +62 -0
  111. package/template/apps/api/test/validation-engine.test.ts +328 -0
  112. package/template/apps/api/test/wallet-monitor.test.ts +38 -0
  113. package/template/apps/api/test/writer-journal.test.ts +327 -0
  114. package/template/apps/api/tsconfig.json +9 -0
  115. package/template/apps/api/vitest.config.ts +12 -0
  116. package/template/apps/web/components.json +21 -0
  117. package/template/apps/web/index.html +12 -0
  118. package/template/apps/web/package.json +33 -0
  119. package/template/apps/web/src/app.tsx +55 -0
  120. package/template/apps/web/src/components/bits.tsx +188 -0
  121. package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
  122. package/template/apps/web/src/components/bound/field-view.tsx +237 -0
  123. package/template/apps/web/src/components/bound/pieces.tsx +169 -0
  124. package/template/apps/web/src/components/bound/readings.tsx +152 -0
  125. package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
  126. package/template/apps/web/src/components/claim-dialog.tsx +344 -0
  127. package/template/apps/web/src/components/epcis-events.tsx +119 -0
  128. package/template/apps/web/src/components/layout.tsx +135 -0
  129. package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
  130. package/template/apps/web/src/components/passport-form.tsx +244 -0
  131. package/template/apps/web/src/components/read-passport.tsx +49 -0
  132. package/template/apps/web/src/components/reading.tsx +150 -0
  133. package/template/apps/web/src/components/ui/alert.tsx +65 -0
  134. package/template/apps/web/src/components/ui/badge.tsx +47 -0
  135. package/template/apps/web/src/components/ui/button.tsx +63 -0
  136. package/template/apps/web/src/components/ui/card.tsx +91 -0
  137. package/template/apps/web/src/components/ui/dialog.tsx +156 -0
  138. package/template/apps/web/src/components/ui/input.tsx +20 -0
  139. package/template/apps/web/src/components/ui/label.tsx +21 -0
  140. package/template/apps/web/src/components/ui/select.tsx +189 -0
  141. package/template/apps/web/src/components/ui/separator.tsx +25 -0
  142. package/template/apps/web/src/components/ui/table.tsx +115 -0
  143. package/template/apps/web/src/components/ui/tabs.tsx +90 -0
  144. package/template/apps/web/src/components/ui/textarea.tsx +17 -0
  145. package/template/apps/web/src/index.css +81 -0
  146. package/template/apps/web/src/lib/api.ts +396 -0
  147. package/template/apps/web/src/lib/auth.ts +10 -0
  148. package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
  149. package/template/apps/web/src/lib/bound/display.ts +122 -0
  150. package/template/apps/web/src/lib/bound/fields.ts +128 -0
  151. package/template/apps/web/src/lib/bound/form-model.ts +521 -0
  152. package/template/apps/web/src/lib/bound/forms.ts +15 -0
  153. package/template/apps/web/src/lib/bound/identity.ts +48 -0
  154. package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
  155. package/template/apps/web/src/lib/bound/units.ts +37 -0
  156. package/template/apps/web/src/lib/epcis.ts +345 -0
  157. package/template/apps/web/src/lib/format.ts +87 -0
  158. package/template/apps/web/src/lib/lifecycle.ts +350 -0
  159. package/template/apps/web/src/lib/session.tsx +92 -0
  160. package/template/apps/web/src/lib/use-load.ts +46 -0
  161. package/template/apps/web/src/main.tsx +18 -0
  162. package/template/apps/web/src/pages/accept.tsx +113 -0
  163. package/template/apps/web/src/pages/brand.tsx +94 -0
  164. package/template/apps/web/src/pages/brands.tsx +104 -0
  165. package/template/apps/web/src/pages/events.tsx +388 -0
  166. package/template/apps/web/src/pages/home.tsx +51 -0
  167. package/template/apps/web/src/pages/new-passport.tsx +137 -0
  168. package/template/apps/web/src/pages/operations.tsx +169 -0
  169. package/template/apps/web/src/pages/passport.tsx +632 -0
  170. package/template/apps/web/src/pages/public-passport.tsx +64 -0
  171. package/template/apps/web/src/pages/sign-in.tsx +93 -0
  172. package/template/apps/web/src/pages/verify.tsx +30 -0
  173. package/template/apps/web/src/pages/wallet.tsx +141 -0
  174. package/template/apps/web/tsconfig.json +29 -0
  175. package/template/apps/web/vite.config.ts +23 -0
  176. package/template/deploy/compose.yml +38 -0
  177. package/template/package.json +48 -0
  178. package/template/tsconfig.base.json +13 -0
@@ -0,0 +1,119 @@
1
+ # The application API
2
+
3
+ JSON under `/api`. Reads are open. Writes need a signed-in member of the brand that holds the passport, or, for a recipient who accepted a hand-on, the claim code they accepted with. Sign-in is Better Auth under `/api/auth/*` (email and password, organisations as brands); without MongoDB the API runs a development session instead and every request is "Developer", a member of brand `dev-brand`.
4
+
5
+ Errors are `{ error: <code>, description: <sentence> }`. A refused write is HTTP 409 with the writer's own code (`identifier-refused`, `payload-invalid`, `index-refused`, `not-the-controller`, `retired`, `live-publishing-off`, `spend-cap`, and so on); 401 means sign in; 403 means not a member or no claim code; 404 means not in this platform's journal, or an unknown offer or state. A body that is not JSON is 400 `body-not-json`. The body is never echoed or logged.
6
+
7
+ A product document under a binding that is refused adds what the form needs to the 409: `product-invalid` and `product-not-validated` carry `cause` and `validation`, `public-view-failed` carries `validation` and `publicView`, and `public-payload-too-large` carries `byteLength` and `limit`. A view is `{ view: 'whole'|'public'|'authorised', status: 'pass'|'fail'|'not-checked', cause?, summary, steps: [{ step, status, cause?, messages }], findings: [{ severity, constraint, step, path?, message?, value?, pointer?, property? }], withheld }`. `pointer` is a JSON pointer into the product document, where the finding could be placed. `not-checked` is a check that did not run to a decision, and is never a pass.
8
+
9
+ A retired profile is refused by name. The earlier sector profiles `battery@2`, `battery@3`, `battery@4` and `textile@1` to `textile@4` are retired: `GET /api/profiles/:id` for one answers 410 `profile-retired`, and every write for a passport under one, an issue, update, offer, retire or claim, and a claim whose event binds one, answers 409 `profile-retired` with `replacedBy`, before anything is signed. A passport already in the journal under one is still served by the read routes, and its `payloadChecks` read `not-checked` with the cause `profile-retired`.
10
+
11
+ The sector bindings `eu-battery@1` and `eu-textile@1` remain available for reading and maintenance. Their catalogue entries include `issueSuccessor` with the version 2 profile. An explicit new ISSUE under either version 1 binding returns 409 `profile-superseded` with `replacedBy` naming the current edition. The issue form offers both version 2 bindings. An application-owned binding continues to require its own trusted digest.
12
+
13
+ There is no route for exporting or restoring the application. Both are operator commands, `npm run export` and `npm run restore`, run on the host with the API stopped: the API has no operator role to authorise them with (README, Export and restore).
14
+
15
+ A passport reference `:ref` is the URL-encoded passport identifier, for example `https%3A%2F%2Flocalhost%3A3000%2F01%2F09521000000011%2F21%2FA1`.
16
+
17
+ ## Open
18
+
19
+ | Route | Returns |
20
+ |---|---|
21
+ | `GET /api/health` | `{ ok, network, index, publisherKey, wallet: 'toolbox'\|'test', livePublishing, validationEngine, validationEngineKind: 'in-process'\|'service', identifiers: { host, prefix, demonstration }, signIn, devSession? }`. `validationEngine` is false when the engine cannot be used: its libraries did not load, or the validator service `VALIDATOR_URL` names did not answer. A service is asked again on each request |
22
+ | `GET /api/profiles` | `[{ id, title, description, format, issueSuccessor? }]`: the current manifest profiles (`format: 'manifest'`), which today is `general@2`, and every profile held by a registered binding (`format: 'binding'`). No retired profile is listed |
23
+ | `GET /api/profiles/:id` for a binding | `{ id, format: 'binding', title, description, bindingDigest, steps, access?: { policy, public }, contexts: [{ path, uri }], prefixes, engine: { available, kind: 'in-process'\|'service', problem? }, examples: [{ title, itemReference, serial, passportId, product }], demonstration }`. `access.public` lists the public top-level properties; every other property is restricted. `examples` are complete product documents of invented data, minted for this deployment's host and prefix |
24
+ | `GET /api/profiles/:id/codes?class=` | For a binding: `{ <class>: [{ value, label }] }`, the coded values the profile's own vocabulary defines for each class asked for, as documents write them |
25
+ | `GET /api/profiles/:id` for a manifest | `{ id, format: 'manifest', title, description, fields: [{ key, label, valueType, unit, accessTier, obligation, cardinality, codeList, constraints, note, group }], publicSchema, restrictedSchema, sample, sampleProblems }`. `sample` is a minimal public payload of placeholders and `sampleProblems` lists anything its own schema still refuses (empty for the current profiles); fields whose `accessTier` is `public` go in `payload`; every other tier goes in `ownerFields`, the restricted tier that is encrypted off chain |
26
+ | `GET /api/verify?passportId=` | The reader's result: `{ passportId, lineage: [{ op, txid, timestamp, controllerKey, actorIdentityKey, payloadPublic }], checks: [{ name, label, status, reasonCode }], report, publisherKeys, payloadChecks: [{ txid, stateIndex, profile, publicView }], product? }`. `status` is `pass`, `fail`, `unknown` or `not-applicable`; `unknown` is missing evidence, never a pass. `payloadChecks` has the public view of each state's payload, checked against that state's own passport identifier. `product`, for a payload under a binding, is `{ profile, bindingDigest, notice?, publicProduct, access? }`: the public part only. Nothing in this answer is a statement about restricted data |
27
+ | `GET /api/passports/:ref` | The journal view: `{ passportId, brandId, profile, profileRetired?: { replacedBy }, status, demonstration, holder: { party, controllerKey }, createdAt, payload, journal: { states, proven, pending, status }, states: [{ op, txid, timestamp, actor, index, refusal, network, proven, proofPushed, blockHeight }], acceptanceRecords }` |
28
+ | `GET /api/passports/:ref/claims` | `{ passportId, lifecycle, historical, discovery }`: every lifecycle claim that concerns the passport. `lifecycle` holds the EPCIS lifecycle claims (`dpp-epcis-lifecycle@1`), found by the index's anchors whose subject is the passport and among this application's claims that bind it, each verified: `foundBy`, `participation` (`item`, `class` or `not-established`), the event, the issuer and its asserted role, the bindings that name this passport, and `findings` with event structure, event semantics, product binding, signature, authority, possession, ownership, anchor commitment, inclusion and correction, each with its own state. An anchor whose claim does not bind the passport is listed with `participation: not-established`. `historical` holds the native `dpp-lifecycle-v1` claims this application issued before it moved to EPCIS lifecycle claims, each with the native signature check. `discovery` says whether the index answered and whether a registry is configured |
29
+ | `GET /api/lifecycle-claims/:id` | The exact signed bytes of an EPCIS lifecycle claim this application holds, by its `urn:sha256:` identifier, as `application/json`: what was signed, sent and anchored, verifiable with `verifyEpcisLifecycleClaim` and nothing of this application |
30
+ | `GET /api/offers/:requestId` | `{ requestId, passportId, terms, expiresAt, status }`, what a recipient sees before deciding |
31
+ | `POST /api/offers/:requestId/accept` `{ claimCode? }`, or a signed-in named recipient | `{ offer, record, transferTxid }`: the custodian-signed acceptance record and the TRANSFER it committed to |
32
+ | `POST /api/offers/:requestId/decline` `{ claimCode? }`, or a signed-in named recipient | The offer, declined; nothing is written |
33
+
34
+ ## Signed in
35
+
36
+ | Route | Body | Returns |
37
+ |---|---|---|
38
+ | `GET /api/me` | | `{ userId, email, name, brandIds, brands: [{ id, name, identityKey, did, createdAt }] }` |
39
+ | `GET /api/brands` | | The user's brands |
40
+ | `POST /api/brands` | `{ name }` | The new brand; its identity key is derived by the platform |
41
+ | `GET /api/brands/:brandId/passports` | | Journal views of the brand's passports |
42
+ | `POST /api/brands/:brandId/passports` | `{ profile, itemReference, serial, payload, ownerFields }`, or for a profile held by a binding `{ profile, itemReference, serial, product }` | The issued passport's journal view. `itemReference` is the digits after the GS1 prefix (nine for prefix 952), `serial` the item's serial. `product` is the complete product document: the API validates it against the identifier it mints, splits it, signs the public part and seals the rest |
43
+ | `POST /api/passports/:ref/update` | `{ payload, ownerFields?, eventData?, claimCode? }`, or under a binding `{ product, eventData?, claimCode? }` | The journal view after the UPDATE. Omit `ownerFields` to carry the current owner tier unchanged; send `{}` to seal an empty one. Under a binding, `product` is the new complete document. For a manifest profile the API never returns the owner tier |
44
+ | `POST /api/passports/:ref/authorised-view` | `{ claimCode? }` | For a passport under a binding, the holder's view: `{ passportId, profile, ownerTier: { status, txid, detail }, authorisedView, restrictedProduct?, product?, access? }`. `ownerTier` is the protocol's check of the stored ciphertext against the state's `payload_owner_hash`, made before anything is decrypted, and the only statement about the commitment. `authorisedView` is the two parts rejoined and checked whole; it is `not-checked` when the restricted part could not be opened. 409 `profile-not-bound` for a manifest profile |
45
+ | `POST /api/passports/:ref/offer` | `{ requestId?, terms: { word, note? }, mechanism?, recipientIdentityKey?, claimCode? }` | `{ offer, claimCode? }`. Give the one-time claim code to the recipient out of band |
46
+ | `GET /api/passports/:ref/offers` | | The passport's offers, without claim-code hashes; the brand's view, so it needs brand membership even after a hand-on |
47
+ | `POST /api/offers/:requestId/withdraw` | `{ claimCode? }` | The offer, withdrawn |
48
+ | `POST /api/passports/:ref/retire` | `{ reason, claimCode? }` | The journal view after the RETIRE |
49
+ | `POST /api/passports/:ref/states/:txid/resolve` | `{ outcome: 'sent'\|'abandoned' }` | A write interrupted between announcement and the network's answer (network `pending`, listed as a `resolve-interrupted` duty) is kept as sent, or withdrawn from the index, aborted in the wallet and removed. Only the operator knows which; never rebuild a state that was sent |
50
+ | `POST /api/passports/:ref/claims` | `{ event, assertedRole, issuerParty?, authorityScope?, submit? }`, or `{ imported: { importId, pointer }, assertedRole, issuerParty?, submit? }`, or `{ correctionOf, reason? }` | Signs an EPCIS lifecycle claim as the signed-in member and answers with its reading for this passport, as in the list. `event` is one EPCIS 2.0.1 event of the five types; `imported` names an event the EPCIS exchange retained, signed exactly as received with a `source` link to the import, and never as `observer` (409 `importer-not-observer`); `correctionOf` names a claim this application holds, and the new claim carries the same event with an EPCIS error declaration, leaving the original unchanged. The bindings come from the event's own identifiers matched to this platform's passports under the identity rules: an item identifier binds that item's passport, a quantity element's class binds at class level only. Refused with nothing signed: 400 `four-category-claims-retired` for a body with `eventType`, 400 `asserted-role-required`, 409 `event-binds-no-passport`, `passport-not-bound` (the event does not name this passport), `event-schema-invalid` or `event-schema-unavailable` (the pinned EPCIS 2.0.1 schema), `event-in-conflict`, `event-id-missing`, and `claim-refused` with the format's own reason codes. With `submit`, the exact bytes go to the registry, which anchors them once per bound passport, and its answer is under `record.registry` |
51
+ | `GET /api/operations` | | `{ duties: [{ passportId, txid, op, duty: 'announce'\|'prove'\|'push-proof'\|'resolve-interrupted', since }], passports: [{ passportId, brandId, status, journal }], profiles: { engine: { available, kind, problem? }, source: 'package'\|'bundle', refused: [{ source, code, detail }] } }`. `engine` is the validation engine as it is now. `source` says whether bound profiles are read from the profiles package or from the bundle in `PROFILE_BUNDLE_DIR`. `refused` names each profile folder or bundle that was not registered at start, and why |
52
+ | `POST /api/operations/run` | | `{ done: [sentence] }`, one pass over the duties |
53
+ | `GET /api/wallet` | | `{ kind, network, identityKey, balance, livePublishing }` |
54
+ | `POST /api/wallet/funding-address` | | `{ address, derivationPrefix, derivationSuffix, senderIdentityKey }`, a fresh address to pay |
55
+ | `POST /api/wallet/internalize` | `{ txid, funding }` | `{ satoshis }` taken in from a payment to that funding address |
56
+
57
+ To retry offer creation after a lost response, choose a request ID once (for example, a random UUID) and resend it with the same passport, holder credentials, terms, mechanism and recipient. Omit the ID to let the server choose it. IDs must be printable UTF-8 text of 1 to 128 bytes and cannot be the URL segments `.` or `..`. A matching retry returns the existing offer and its current status, including after withdrawal or transfer. A conflicting use of an ID returns `offer-request-conflict`. A different offer for the same predecessor must wait while its transfer is pending. Once the predecessor is spent, a new offer from the current holder can replace a stale open offer. A claim code is returned only on first creation. If that response was lost and the code is needed for an open offer, withdraw it and create another with a fresh ID.
58
+
59
+ For a named offer the session supplies the recipient's managed identity. That member keeps using the same session for holder actions. After acceptance, an authorised repeat returns the retained transfer transaction ID. An unsettled send requires reconciliation before the offer can be marked transferred.
60
+
61
+ `claimCode` on update, authorised-view, offer, withdraw and retire is for a recipient who holds the passport after a hand-on; a brand member omits it.
62
+
63
+ ## EPCIS exchange
64
+
65
+ Signed in, under `/api/epcis`. Every route calls `@bsv/dpp-credentials/epcis-exchange`, and the records it answers with are that module's own. An import or a pull retains data. It changes no custody, signs nothing, writes nothing on chain and never calls the wallet. An event that is retained is data a source supplied: a `valid` document passed a check of its format, and is not a signed or verified claim.
66
+
67
+ An identifier in a path, `:importId` or `:conflictId`, is the URL-encoded identifier the API gave, for example `urn%3Absv%3Adpp%3Aepcis%3Aimport%3Asha256%3A...`.
68
+
69
+ | Route | Body | Returns |
70
+ |---|---|---|
71
+ | `GET /api/epcis/status` | | `{ storage: 'mongodb'\|'file'\|'memory', artefacts: { dir, state: 'present'\|'fetched'\|'unavailable', files, remedy? }, recovery: { actions, remaining }, sources, policy }`. `artefacts` is the folder of pinned GS1 files as it is now, and `recovery` is what start-up finished or discarded |
72
+ | `GET /api/epcis/sources` | | `[{ sourceId, baseUrl, permittedOrigins, localTest, repeatListParameters, credentialConfigured, credentialScheme?, problem? }]`. It says whether a credential is set and which kind, and never carries one. `localTest` is true when plain `http` and private addresses are permitted for the source. `problem` says why a pull from the source is refused as it is configured |
73
+ | `POST /api/epcis/imports?requestId=&sourceId=&filename=` | The document, as the bytes it is, under `Content-Type: application/ld+json` or `application/json` | 201 `{ outcome: 'retained', replayed: false, resumed, record }`, or 200 with `replayed: true` when `requestId` was already used for the same bytes. `record` is the import record: `importId`, `sha256`, `byteLength`, `documentValidity`, `state`, `findings`, and per event its `arrival`, findings, `preservedExtensions` and any `conflict`. `requestId` is required and is yours to choose: sending the same bytes under it again is the same request and keeps one import. `sourceId` is the scope events are filed under, `upload` by default |
74
+ | `GET /api/epcis/imports?after=&limit=` | | `{ imports: [{ importId, sourceId, requestId, receivedAt, mediaType, byteLength, sha256, provenance, state, documentValidity, events, findings, conflicts }], next? }`. Pass `next` as `after` for the page after it |
75
+ | `GET /api/epcis/imports/:importId` | | The import record, with every finding |
76
+ | `GET /api/epcis/imports/:importId/original` | | The retained bytes, exactly as received, under the media type they arrived with. `x-content-sha256` carries their digest. Never JSON this API wrote |
77
+ | `POST /api/epcis/sources/:sourceId/pulls` | `{ queryId, query: { matchAnyEPC?, eventTypes?, eventTime?: { from?, until? }, recordTime?: { from? }, eventIds?, perPage? }, window? }` | One bounded run: the module's result, `{ outcome, reason, completion, exhausted, detail, pull, run, pages, events, localTest, leniencies, completenessLimits, ... }`, answered 200 whatever the run found. `exhausted` is true only when the source named no further page, and `completenessLimits` is never empty. Run it again under the same `queryId` to continue from the checkpoint |
78
+ | `GET /api/epcis/sources/:sourceId/pulls/:queryId` | | `{ pull, pages }`: the pull's durable state and every page it acknowledged |
79
+ | `GET /api/epcis/events?identifier=&granularity=&sourceId=&after=` | | `{ identifier, granularity, nature: 'supplied-data', notice, events: [{ association, source: { importId, sourceId, receivedAt, documentValidity, state, provenance, sha256 }, event, body }], next? }`. `identifier` is matched exactly as events write it, and `granularity` is `instance` for one item or `class` for a class or a lot. `body` is the event as the retained document holds it, extension members included. Only valid documents are indexed |
80
+ | `GET /api/epcis/conflicts` | | `{ conflicts: [{ conflictId, sourceId, identity, state: 'open'\|'resolved', bodyDigests, observations, resolutions }], importsRead, truncated }`: every event identifier held with more than one body |
81
+ | `GET /api/epcis/conflicts/:conflictId` | | One conflict |
82
+ | `POST /api/epcis/conflicts/:conflictId/resolutions` | `{ decision, disposition: 'body-selected'\|'all-retained'\|'none-relied-on', selectedBodyDigest?, decidedAt? }` | 201 `{ outcome: 'recorded', replayed: false, resolution }`, or 200 with `replayed: true` for the same decision sent again. No observation and no source is changed or removed |
83
+
84
+ A refused import answers `{ error, description, remedy?, outcome: 'refused', kept: false }` and keeps nothing, not the bytes and not a record:
85
+
86
+ | Status | `error` | When |
87
+ |---|---|---|
88
+ | 400 | `request-id-required`, `invalid-request` | No `requestId`, or a request the module cannot read |
89
+ | 409 | `request-conflict` | `requestId` is already bound to other bytes or another media type. The earlier import stands, and `existingImportId` names it |
90
+ | 413 | `oversized`, `record-too-large` | The document is past the size limit, or the record of what it holds is larger than the store keeps as one record |
91
+ | 415 | `unsupported-media-type`, `content-encoding-unsupported` | Not an EPCIS media type, or sent under a content encoding |
92
+ | 422 | `malformed-json`, `malformed-utf8`, `duplicate-key`, `depth`, `unsafe-number`, `too-many-events`, `not-an-object`, `too-many-contexts`, `contexts-oversized`, `no-canonical-form` | The bytes cannot be read safely as one EPCIS document |
93
+ | 503 | `gs1-artefact-unavailable` | The pinned GS1 files are not in the configured folder. `remedy` says how to provide them |
94
+
95
+ A document that parses safely and fails validation is not refused: it is retained with `documentValidity: 'invalid'` and its findings. A pull that is refused before anything is requested answers `{ error, description, remedy?, outcome: 'refused', requested: false }`: 400 `invalid-request`, 404 `source-unknown`, 409 `pull-conflict` when `queryId` is bound to another definition, 503 `gs1-artefact-unavailable` or `credentials-unavailable`. A run that stops because a page's record is larger than the store keeps answers 413 `record-too-large`, with every earlier page retained.
96
+
97
+ Durable event intake accepts a whole `EPCISDocument` or `EPCISQueryDocument`. A standalone event uploaded as valid JSON retains an invalid receipt, the finding `envelope-unrecognised` and its exact original bytes. It creates no observation or association. Replaying the request returns that receipt. For standalone inspection, the library parser accepts explicit envelope and context facts in `singleEvent`.
98
+
99
+ A store that fails is not a refusal. When the EPCIS store does not complete a call, on a route under `/api/epcis` that reads or writes it, the answer is 503 `{ error: 'storage-unavailable', description, outcome: 'failed', retryable: true, acknowledged: false }`, or `storage-contention` when another writer kept winning the same records. An upload or a decision answered this way was not acknowledged, and the same request may be sent again: an upload under the same `requestId` is answered as one import. A pull acknowledges page by page, so its answer carries no `acknowledged`: the pages it acknowledged before the failure are kept, and the same `queryId` run again continues after the last of them. With sign-in on, the signed-in user is looked up in the application's database before anything else, and a lookup that fails, as it does while that database is away, answers 503 `sign-in-unavailable` with `retryable: true`. Retained bytes that are altered or gone, and a store that holds a record it cannot read, answer 500 with `retained-bytes-mismatch`, `retained-bytes-missing`, `record-unreadable` or `storage-corrupt` and `retryable: false`, because sending the request again does not mend them. The store's own error is written to the log, never into an answer.
100
+
101
+ ## The passport page
102
+
103
+ ## The identifier host
104
+
105
+ Outside `/api`, and open. The API answers each passport identifier at its own path as a GS1-Conformant Resolver for GTINs, which the standard's GS1 discovery profile asks of the host an identifier is minted under. Every rule is a helper of `@bsv/dpp-profiles`, and the records are made from the journal for each request (`src/resolver.ts`).
106
+
107
+ | Route | Returns |
108
+ |---|---|
109
+ | `GET /.well-known/gs1resolver` | The resolver description file: `{ resolverRoot, supportedPrimaryKeys: ['01'], supportedLinkType, linkTypeDefaultCanBeLinkset: false, jsonLdContextLocation }` |
110
+ | `GET /01/<gtin>/21/<serial>` | 307 with `Location: /passport/01/<gtin>/21/<serial>` and the request's query string: the passport page, the item's default link under `gs1:dpp`. With `?linkType=<type>`, 307 to the link of that type, or 404 `link-type-unknown` |
111
+ | The same with `Accept: application/linkset+json`, with `?linkType=linkset`, or with `Accept: application/json` and no `linkType` | 200 `application/linkset+json`: `{ linkset: [{ anchor, <link type>: [{ href, title }] }] }`, the item first and then its GTIN, each anchored at its own identifier under `https://<PASSPORT_HOST>`, with a `Link` header that names GS1's JSON-LD context for linksets. Never a redirect |
112
+ | `GET /01/<gtin>`, a lot, or a serial no passport was issued for, under a GTIN that has passports | 307 to the product page, `/passport/01/<gtin>`, the GTIN's default link under `gs1:pip`; its linkset holds the GTIN's links only |
113
+ | `GET /eh<hexadecimal>` and `GET /ex<base 64>` | A compressed identifier that carries an SGTIN-96 or SGTIN-198 EPC binary string: decompressed, then answered as the identifier it spells |
114
+
115
+ A path under `/01` that is not a GS1 Digital Link for a GTIN, a GTIN whose check digit fails, and a compressed form that does not decode are 400 `identifier-malformed` with `reason`. A GTIN no passport was issued under is 404 `identifier-unknown`. One trailing slash is tolerated. Every answer carries `Access-Control-Allow-Origin: *` and `Vary: Accept, Accept-Language`; `HEAD` is answered as `GET` without a body, `OPTIONS` with 204, and any other method with 405.
116
+
117
+ A redirect's `Location` is a path, so it lands on this application wherever it was asked: at `PASSPORT_HOST`, behind a proxy, or at the Vite origin in development, where Vite passes these routes to the API. One difference in development: Vite answers an `OPTIONS` request itself, with its own headers.
118
+
119
+ The API serves the built web app for every other path outside `/api`, the two public pages among them: `/passport/01/<gtin>/21/<serial>` for a passport and `/passport/01/<gtin>` for a product. The passport page takes the identifier from the passport host and its own path without `/passport`, then calls `GET /api/verify` and `GET /api/passports/:ref`.
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "api",
3
+ "private": true,
4
+ "description": "The application API: owns the platform wallet, writes and reads passports with the @bsv/dpp packages, keeps the journal and runs the unattended duties",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "tsx watch src/main.ts",
9
+ "build": "tsc -p tsconfig.json",
10
+ "typecheck": "tsc -p tsconfig.json --noEmit",
11
+ "test": "vitest run",
12
+ "start": "node dist/main.js"
13
+ },
14
+ "dependencies": {
15
+ "@bsv/dpp-credentials": "0.2.0-beta.6",
16
+ "@bsv/dpp-overlay": "0.4.0-beta.13",
17
+ "@bsv/dpp-profiles": "0.3.0-beta.10",
18
+ "@bsv/dpp-protocol": "0.3.0-beta.10",
19
+ "@bsv/overlay": "2.3.1",
20
+ "@bsv/sdk": "2.8.10",
21
+ "@bsv/wallet-toolbox": "2.14.6",
22
+ "ajv": "8.20.0",
23
+ "ajv-formats": "3.0.1",
24
+ "better-auth": "1.7.7",
25
+ "express": "5.3.0",
26
+ "jsonld": "9.0.0",
27
+ "mongodb": "7.7.0",
28
+ "n3": "2.13.12",
29
+ "shacl-engine": "1.1.3"
30
+ },
31
+ "devDependencies": {
32
+ "@types/express": "^5.0.6",
33
+ "@types/node": "^22.20.3",
34
+ "mongodb-memory-server": "11.2.0",
35
+ "tsx": "^4.23.15",
36
+ "typescript": "^7.0.2",
37
+ "vitest": "^5.0.3"
38
+ }
39
+ }
@@ -0,0 +1,55 @@
1
+ // Sign-in is the guard rail on every write: the write routes spend real
2
+ // satoshis and write permanent states, so who may act for which brand must
3
+ // be decided before a key is used. Better Auth, self-hosted on the same
4
+ // MongoDB, with email and password and organisations: an organisation is a
5
+ // brand, and its members act for it. The signature itself is always made
6
+ // with a key the platform holds; sign-in only decides who may ask for it.
7
+ // At Ring 0 this platform is the only party vouching for who a member is.
8
+ import { betterAuth } from 'better-auth'
9
+ import { mongodbAdapter } from 'better-auth/adapters/mongodb'
10
+ import { fromNodeHeaders } from 'better-auth/node'
11
+ import { organization } from 'better-auth/plugins'
12
+ import type { Db } from 'mongodb'
13
+ import type { IncomingHttpHeaders } from 'node:http'
14
+
15
+ export interface AuthOptions {
16
+ db: Db
17
+ secret: string
18
+ baseURL: string
19
+ trustedOrigins?: string[]
20
+ }
21
+
22
+ export function createAuth(options: AuthOptions) {
23
+ return betterAuth({
24
+ database: mongodbAdapter(options.db),
25
+ secret: options.secret,
26
+ baseURL: options.baseURL,
27
+ basePath: '/api/auth',
28
+ trustedOrigins: options.trustedOrigins ?? [],
29
+ emailAndPassword: { enabled: true },
30
+ plugins: [organization()],
31
+ })
32
+ }
33
+
34
+ export type Auth = ReturnType<typeof createAuth>
35
+
36
+ export interface Session {
37
+ userId: string
38
+ email: string
39
+ name: string
40
+ /** The brands (organisations) this user is a member of. */
41
+ brandIds: string[]
42
+ }
43
+
44
+ /** The signed-in user behind a request, or undefined. */
45
+ export async function sessionFrom(auth: Auth, headers: IncomingHttpHeaders): Promise<Session | undefined> {
46
+ const session = await auth.api.getSession({ headers: fromNodeHeaders(headers) })
47
+ if (session == null) return undefined
48
+ const organisations = await auth.api.listOrganizations({ headers: fromNodeHeaders(headers) })
49
+ return {
50
+ userId: session.user.id,
51
+ email: session.user.email,
52
+ name: session.user.name,
53
+ brandIds: organisations.map((o) => o.id),
54
+ }
55
+ }