@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.
- package/LICENSE +203 -0
- package/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +93 -2
- package/dist/index.js +125 -0
- package/package.json +57 -4
- package/template/Dockerfile +37 -0
- package/template/README.md +389 -0
- package/template/_dockerignore +6 -0
- package/template/_env.example +122 -0
- package/template/_github/workflows/ci.yml +23 -0
- package/template/_gitignore +8 -0
- package/template/_prettierrc +6 -0
- package/template/apps/api/API.md +119 -0
- package/template/apps/api/package.json +39 -0
- package/template/apps/api/src/auth.ts +55 -0
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +204 -0
- package/template/apps/api/src/cli.ts +99 -0
- package/template/apps/api/src/config.ts +180 -0
- package/template/apps/api/src/custody.ts +358 -0
- package/template/apps/api/src/dev-index.ts +120 -0
- package/template/apps/api/src/env-file.ts +55 -0
- package/template/apps/api/src/env.ts +14 -0
- package/template/apps/api/src/epcis/exchange.ts +434 -0
- package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
- package/template/apps/api/src/epcis/routes.ts +364 -0
- package/template/apps/api/src/epcis/sources.ts +142 -0
- package/template/apps/api/src/go-live.ts +226 -0
- package/template/apps/api/src/http-error.ts +15 -0
- package/template/apps/api/src/identifiers.ts +57 -0
- package/template/apps/api/src/index-client.ts +261 -0
- package/template/apps/api/src/index-projects.ts +53 -0
- package/template/apps/api/src/lifecycle-authority.ts +49 -0
- package/template/apps/api/src/lifecycle.ts +485 -0
- package/template/apps/api/src/main.ts +58 -0
- package/template/apps/api/src/parties.ts +68 -0
- package/template/apps/api/src/platform.ts +176 -0
- package/template/apps/api/src/portability/commands.ts +224 -0
- package/template/apps/api/src/portability/export.ts +708 -0
- package/template/apps/api/src/portability/package.ts +270 -0
- package/template/apps/api/src/portability/restore.ts +863 -0
- package/template/apps/api/src/profiles.ts +125 -0
- package/template/apps/api/src/reader.ts +265 -0
- package/template/apps/api/src/resolver.ts +159 -0
- package/template/apps/api/src/sector-examples.ts +390 -0
- package/template/apps/api/src/server.ts +613 -0
- package/template/apps/api/src/store.ts +426 -0
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +359 -0
- package/template/apps/api/src/worker.ts +113 -0
- package/template/apps/api/src/writer.ts +603 -0
- package/template/apps/api/test/bound-http.test.ts +496 -0
- package/template/apps/api/test/bound-profiles.test.ts +547 -0
- package/template/apps/api/test/config.test.ts +160 -0
- package/template/apps/api/test/custody-journal.test.ts +415 -0
- package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
- package/template/apps/api/test/custom-profile.test.ts +167 -0
- package/template/apps/api/test/env-file.test.ts +53 -0
- package/template/apps/api/test/epcis-fixtures.ts +270 -0
- package/template/apps/api/test/epcis-http.test.ts +1179 -0
- package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
- package/template/apps/api/test/epcis-separation.test.ts +253 -0
- package/template/apps/api/test/epcis-web.test.ts +230 -0
- package/template/apps/api/test/exit-exercise.test.ts +1038 -0
- package/template/apps/api/test/external-index.test.ts +32 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
- package/template/apps/api/test/go-live.test.ts +179 -0
- package/template/apps/api/test/gs1-global-setup.ts +33 -0
- package/template/apps/api/test/gs1-test-env.ts +5 -0
- package/template/apps/api/test/identifier-host.test.ts +256 -0
- package/template/apps/api/test/index-projects.test.ts +81 -0
- package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
- package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
- package/template/apps/api/test/lifecycle.test.ts +147 -0
- package/template/apps/api/test/manifest-notice.test.ts +36 -0
- package/template/apps/api/test/network-guard.ts +113 -0
- package/template/apps/api/test/portability.test.ts +655 -0
- package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
- package/template/apps/api/test/retired-profiles.test.ts +216 -0
- package/template/apps/api/test/sector-cutover.test.ts +95 -0
- package/template/apps/api/test/sector-forms.test.ts +420 -0
- package/template/apps/api/test/unjoined-index.test.ts +62 -0
- package/template/apps/api/test/validation-engine.test.ts +328 -0
- package/template/apps/api/test/wallet-monitor.test.ts +38 -0
- package/template/apps/api/test/writer-journal.test.ts +327 -0
- package/template/apps/api/tsconfig.json +9 -0
- package/template/apps/api/vitest.config.ts +12 -0
- package/template/apps/web/components.json +21 -0
- package/template/apps/web/index.html +12 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/src/app.tsx +55 -0
- package/template/apps/web/src/components/bits.tsx +188 -0
- package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
- package/template/apps/web/src/components/bound/field-view.tsx +237 -0
- package/template/apps/web/src/components/bound/pieces.tsx +169 -0
- package/template/apps/web/src/components/bound/readings.tsx +152 -0
- package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
- package/template/apps/web/src/components/claim-dialog.tsx +344 -0
- package/template/apps/web/src/components/epcis-events.tsx +119 -0
- package/template/apps/web/src/components/layout.tsx +135 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +244 -0
- package/template/apps/web/src/components/read-passport.tsx +49 -0
- package/template/apps/web/src/components/reading.tsx +150 -0
- package/template/apps/web/src/components/ui/alert.tsx +65 -0
- package/template/apps/web/src/components/ui/badge.tsx +47 -0
- package/template/apps/web/src/components/ui/button.tsx +63 -0
- package/template/apps/web/src/components/ui/card.tsx +91 -0
- package/template/apps/web/src/components/ui/dialog.tsx +156 -0
- package/template/apps/web/src/components/ui/input.tsx +20 -0
- package/template/apps/web/src/components/ui/label.tsx +21 -0
- package/template/apps/web/src/components/ui/select.tsx +189 -0
- package/template/apps/web/src/components/ui/separator.tsx +25 -0
- package/template/apps/web/src/components/ui/table.tsx +115 -0
- package/template/apps/web/src/components/ui/tabs.tsx +90 -0
- package/template/apps/web/src/components/ui/textarea.tsx +17 -0
- package/template/apps/web/src/index.css +81 -0
- package/template/apps/web/src/lib/api.ts +396 -0
- package/template/apps/web/src/lib/auth.ts +10 -0
- package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
- package/template/apps/web/src/lib/bound/display.ts +122 -0
- package/template/apps/web/src/lib/bound/fields.ts +128 -0
- package/template/apps/web/src/lib/bound/form-model.ts +521 -0
- package/template/apps/web/src/lib/bound/forms.ts +15 -0
- package/template/apps/web/src/lib/bound/identity.ts +48 -0
- package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
- package/template/apps/web/src/lib/bound/units.ts +37 -0
- package/template/apps/web/src/lib/epcis.ts +345 -0
- package/template/apps/web/src/lib/format.ts +87 -0
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/lib/session.tsx +92 -0
- package/template/apps/web/src/lib/use-load.ts +46 -0
- package/template/apps/web/src/main.tsx +18 -0
- package/template/apps/web/src/pages/accept.tsx +113 -0
- package/template/apps/web/src/pages/brand.tsx +94 -0
- package/template/apps/web/src/pages/brands.tsx +104 -0
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/home.tsx +51 -0
- package/template/apps/web/src/pages/new-passport.tsx +137 -0
- package/template/apps/web/src/pages/operations.tsx +169 -0
- package/template/apps/web/src/pages/passport.tsx +632 -0
- package/template/apps/web/src/pages/public-passport.tsx +64 -0
- package/template/apps/web/src/pages/sign-in.tsx +93 -0
- package/template/apps/web/src/pages/verify.tsx +30 -0
- package/template/apps/web/src/pages/wallet.tsx +141 -0
- package/template/apps/web/tsconfig.json +29 -0
- package/template/apps/web/vite.config.ts +23 -0
- package/template/deploy/compose.yml +38 -0
- package/template/package.json +48 -0
- package/template/tsconfig.base.json +13 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { once } from 'node:events'
|
|
2
|
+
import type { AddressInfo } from 'node:net'
|
|
3
|
+
import { Beef, Transaction, Utils } from '@bsv/sdk'
|
|
4
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { loadConfig } from '../src/config.js'
|
|
6
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
7
|
+
import { IndexClient } from '../src/index-client.js'
|
|
8
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
9
|
+
import { createServer } from '../src/server.js'
|
|
10
|
+
import { samplePayload } from '../src/profiles.js'
|
|
11
|
+
import { MongoStore, type PassportRecord } from '../src/store.js'
|
|
12
|
+
import { pendingDuties, runDuties } from '../src/worker.js'
|
|
13
|
+
import { ActionAlreadySeen } from '../src/wallet.js'
|
|
14
|
+
import { Writer } from '../src/writer.js'
|
|
15
|
+
import { startMongo, type TestMongo } from './epcis-fixtures.js'
|
|
16
|
+
|
|
17
|
+
const config = loadConfig({ PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', NETWORK: 'test', LIVE_PUBLISHING: 'false' })
|
|
18
|
+
const identifiers = { host: config.passportHost, prefix: config.gs1Prefix }
|
|
19
|
+
let mongo: TestMongo
|
|
20
|
+
let platform: Platform
|
|
21
|
+
let primary: MongoStore
|
|
22
|
+
let secondary: MongoStore
|
|
23
|
+
let writer: Writer
|
|
24
|
+
let otherWriter: Writer
|
|
25
|
+
|
|
26
|
+
const newWriter = (store: MongoStore, index = platform.index) => new Writer({
|
|
27
|
+
store, wallet: platform.wallet, index, identifiers,
|
|
28
|
+
bound: platform.profiles, livePublishing: false, spendCapSatoshis: 20_000,
|
|
29
|
+
})
|
|
30
|
+
const brand = () => platform.parties.brand('sample-brand')
|
|
31
|
+
const id = (serial: string) => mintPassportId(identifiers, '100000001', serial)
|
|
32
|
+
const data = () => samplePayload('general@2', true)
|
|
33
|
+
const issue = (serial: string, service = writer) => service.issue({ brandId: 'sample-brand', brand: brand(), passportId: id(serial), profile: 'general@2', payload: data() })
|
|
34
|
+
const update = (service: Writer, record: PassportRecord, note: string) => service.update({ record, actor: brand(), payload: data(), eventData: { note } })
|
|
35
|
+
|
|
36
|
+
// Pause one real adapter call. Every other call still reaches the test wallet or loopback index.
|
|
37
|
+
function signal() {
|
|
38
|
+
let resolve!: () => void
|
|
39
|
+
const promise = new Promise<void>((done) => { resolve = done })
|
|
40
|
+
return { promise, resolve }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => { mongo = await startMongo() })
|
|
44
|
+
afterAll(async () => { await mongo?.stop() })
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
const db = mongo.database()
|
|
47
|
+
primary = new MongoStore(db)
|
|
48
|
+
secondary = new MongoStore(db)
|
|
49
|
+
await primary.init()
|
|
50
|
+
await secondary.init()
|
|
51
|
+
platform = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
52
|
+
writer = newWriter(primary)
|
|
53
|
+
otherWriter = newWriter(secondary)
|
|
54
|
+
})
|
|
55
|
+
afterEach(async () => { vi.restoreAllMocks(); await platform?.close() })
|
|
56
|
+
|
|
57
|
+
describe('two writers sharing the passport journal in MongoDB', () => {
|
|
58
|
+
it('keeps a pending update on the shared tip and lets another passport complete while the send is blocked', async () => {
|
|
59
|
+
const issued = await issue('CONCURRENT')
|
|
60
|
+
const stale = (await secondary.getPassport(issued.record.passportId))!
|
|
61
|
+
const reached = signal(), release = signal()
|
|
62
|
+
const realSend = platform.wallet.adapter.send.bind(platform.wallet.adapter)
|
|
63
|
+
const sends = vi.spyOn(platform.wallet.adapter, 'send').mockImplementationOnce(async (built) => {
|
|
64
|
+
reached.resolve()
|
|
65
|
+
await release.promise
|
|
66
|
+
return realSend(built)
|
|
67
|
+
})
|
|
68
|
+
const pending = update(writer, issued.record, 'first')
|
|
69
|
+
let pendingTxid: string | undefined
|
|
70
|
+
try {
|
|
71
|
+
await reached.promise
|
|
72
|
+
const journal = (await secondary.getPassport(stale.passportId))!
|
|
73
|
+
expect(journal.states.map((entry) => entry.network)).toEqual(['dry-run', 'pending'])
|
|
74
|
+
pendingTxid = journal.states.at(-1)!.txid
|
|
75
|
+
await expect(update(otherWriter, stale, 'second')).rejects.toMatchObject({ code: expect.stringMatching(/^(operation-interrupted|tip-moved)$/) })
|
|
76
|
+
expect((await secondary.getPassport(stale.passportId))!.states.at(-1)?.txid).toBe(pendingTxid)
|
|
77
|
+
expect((await issue('INDEPENDENT', otherWriter)).entry.network).toBe('dry-run')
|
|
78
|
+
expect(sends).toHaveBeenCalledTimes(2)
|
|
79
|
+
} finally { release.resolve(); await pending }
|
|
80
|
+
const saved = (await secondary.getPassport(stale.passportId))!
|
|
81
|
+
expect(saved.states.map((entry) => entry.txid)).toEqual([issued.entry.txid, pendingTxid])
|
|
82
|
+
expect(saved.states.at(-1)?.network).toBe('dry-run')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it.each(['sent', 'abandoned'] as const)('keeps the exact unanswered update until the operator resolves it as %s', async (answer) => {
|
|
86
|
+
const original = await issue('INTERRUPTED')
|
|
87
|
+
const send = vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('unanswered')
|
|
88
|
+
await expect(update(writer, original.record, 'interrupted')).rejects.toMatchObject({ code: 'network-unanswered' })
|
|
89
|
+
const retained = (await secondary.getPassport(original.record.passportId))!
|
|
90
|
+
const draft = retained.states.at(-1)!
|
|
91
|
+
expect(draft.network).toBe('unanswered')
|
|
92
|
+
expect(draft.beef).toBe(Utils.toBase64(send.mock.calls[0]![0].beef))
|
|
93
|
+
expect((await pendingDuties(secondary)).filter((duty) => duty.txid === draft.txid).map((duty) => duty.duty)).toEqual(['resolve-interrupted'])
|
|
94
|
+
await runDuties({ store: secondary, index: platform.index, writer: otherWriter })
|
|
95
|
+
await expect(update(otherWriter, retained, 'too early')).rejects.toMatchObject({ code: 'operation-interrupted' })
|
|
96
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
97
|
+
await otherWriter.resolveInterrupted(retained, draft.txid, answer)
|
|
98
|
+
const settled = (await primary.getPassport(retained.passportId))!
|
|
99
|
+
expect(settled.states.map((entry) => entry.txid)).toEqual(answer === 'sent' ? [original.entry.txid, draft.txid] : [original.entry.txid])
|
|
100
|
+
if (answer === 'sent') expect(settled.states.at(-1)).toMatchObject({ network: 'dry-run', beef: draft.beef })
|
|
101
|
+
expect((await update(writer, settled, 'continued')).state.previousTxid).toBe(settled.states.at(-1)!.txid)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('removes a refused genesis and allows a fresh issue for the same identifier', async () => {
|
|
105
|
+
vi.spyOn(platform.index, 'announce').mockResolvedValueOnce('refused')
|
|
106
|
+
const send = vi.spyOn(platform.wallet.adapter, 'send')
|
|
107
|
+
await expect(issue('RETRY-GENESIS')).rejects.toMatchObject({ code: 'index-refused' })
|
|
108
|
+
expect(send).not.toHaveBeenCalled()
|
|
109
|
+
expect(await secondary.getPassport(id('RETRY-GENESIS'))).toBeUndefined()
|
|
110
|
+
expect((await issue('RETRY-GENESIS', otherWriter)).record.states).toHaveLength(1)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('retains a sent state when an index without retraction refuses its announcement', async () => {
|
|
114
|
+
const index = new IndexClient({ ...platform.devIndex! })
|
|
115
|
+
const send = vi.spyOn(platform.wallet.adapter, 'send')
|
|
116
|
+
const announce = vi.spyOn(index, 'announce').mockResolvedValueOnce('refused')
|
|
117
|
+
const retract = vi.spyOn(index, 'retract')
|
|
118
|
+
const { entry, record } = await issue('SEND-FIRST', newWriter(primary, index))
|
|
119
|
+
expect(send).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ txid: entry.txid }))
|
|
120
|
+
expect(send.mock.invocationCallOrder[0]).toBeLessThan(announce.mock.invocationCallOrder[0]!)
|
|
121
|
+
expect(entry).toMatchObject({ network: 'dry-run', index: 'refused' })
|
|
122
|
+
await runDuties({ store: secondary, index, writer: newWriter(secondary, index) })
|
|
123
|
+
expect((await primary.getPassport(record.passportId))!.states[0]!.index).toBe('admitted')
|
|
124
|
+
expect(announce.mock.calls).toEqual([[send.mock.calls[0]![0].beef], [send.mock.calls[0]![0].beef]])
|
|
125
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
126
|
+
expect(retract).not.toHaveBeenCalled()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('discards a refused send without contacting a non-retracting index', async () => {
|
|
130
|
+
const index = new IndexClient({ ...platform.devIndex! })
|
|
131
|
+
const announce = vi.spyOn(index, 'announce')
|
|
132
|
+
const retract = vi.spyOn(index, 'retract')
|
|
133
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('refused')
|
|
134
|
+
await expect(issue('REFUSED-SEND-FIRST', newWriter(primary, index))).rejects.toMatchObject({ code: 'network-refused' })
|
|
135
|
+
expect(announce).not.toHaveBeenCalled()
|
|
136
|
+
expect(retract).not.toHaveBeenCalled()
|
|
137
|
+
expect(await secondary.getPassport(id('REFUSED-SEND-FIRST'))).toBeUndefined()
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('resumes a send-first write after the process loses its post-send journal update', async () => {
|
|
141
|
+
const index = new IndexClient({ ...platform.devIndex! })
|
|
142
|
+
const announce = vi.spyOn(index, 'announce')
|
|
143
|
+
const send = vi.spyOn(platform.wallet.adapter, 'send')
|
|
144
|
+
vi.spyOn(primary, 'recordSpend').mockRejectedValueOnce(new Error('interrupted after wallet send'))
|
|
145
|
+
await expect(issue('RECOVER-SEND-FIRST', newWriter(primary, index))).rejects.toThrow('interrupted after wallet send')
|
|
146
|
+
const pending = (await secondary.getPassport(id('RECOVER-SEND-FIRST')))!
|
|
147
|
+
const draft = pending.states[0]!
|
|
148
|
+
expect(draft).toMatchObject({ network: 'pending', index: 'not-asked' })
|
|
149
|
+
expect(announce).not.toHaveBeenCalled()
|
|
150
|
+
const resumedWriter = newWriter(secondary, index)
|
|
151
|
+
await resumedWriter.resolveInterrupted(pending, draft.txid, 'sent')
|
|
152
|
+
await runDuties({ store: secondary, writer: resumedWriter, index })
|
|
153
|
+
expect((await primary.getPassport(pending.passportId))!.states[0]).toMatchObject({ txid: draft.txid, network: 'dry-run', index: 'admitted' })
|
|
154
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
155
|
+
expect(announce).toHaveBeenCalledExactlyOnceWith(send.mock.calls[0]![0].beef)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('backfills two missed states in spend order with original BEEF after the writer clock moved backwards', async () => {
|
|
159
|
+
const send = vi.spyOn(platform.wallet.adapter, 'send')
|
|
160
|
+
const submit = platform.index.announce.bind(platform.index)
|
|
161
|
+
const announce = vi.spyOn(platform.index, 'announce').mockResolvedValue('unreachable')
|
|
162
|
+
vi.spyOn(platform.index, 'lineage').mockRejectedValue(new Error('index is offline'))
|
|
163
|
+
vi.useFakeTimers({ toFake: ['Date'] })
|
|
164
|
+
try {
|
|
165
|
+
vi.setSystemTime(new Date('2026-11-26T10:01:00Z'))
|
|
166
|
+
const genesis = await issue('BACKFILL')
|
|
167
|
+
vi.setSystemTime(new Date('2026-11-26T10:00:00Z'))
|
|
168
|
+
const next = await update(writer, genesis.record, 'offline')
|
|
169
|
+
expect(send).toHaveBeenCalledTimes(2)
|
|
170
|
+
const [genesisBytes, nextBytes] = send.mock.calls.map(([built]) => built.beef)
|
|
171
|
+
expect(Transaction.fromAtomicBEEF(nextBytes!).id('hex')).toBe(next.entry.txid)
|
|
172
|
+
expect(Beef.fromBinary(nextBytes!).findTxid(genesis.entry.txid)?.tx?.toHex()).toBe(genesis.entry.rawTx)
|
|
173
|
+
|
|
174
|
+
// The first backfill is still offline. The worker must defer the successor.
|
|
175
|
+
announce.mockClear()
|
|
176
|
+
await runDuties({ store: secondary, index: platform.index, writer: otherWriter })
|
|
177
|
+
expect(announce.mock.calls).toEqual([[genesisBytes]])
|
|
178
|
+
announce.mockClear().mockImplementation(submit)
|
|
179
|
+
await runDuties({ store: secondary, index: platform.index, writer: otherWriter })
|
|
180
|
+
expect(announce.mock.calls).toEqual([[genesisBytes], [nextBytes]])
|
|
181
|
+
expect((await primary.getPassport(next.record.passportId))!.states.map(s => s.index)).toEqual(['admitted', 'admitted'])
|
|
182
|
+
expect(send).toHaveBeenCalledTimes(2)
|
|
183
|
+
} finally { vi.useRealTimers() }
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('applies a late proof acknowledgement to its own transaction and retains the original BEEF', async () => {
|
|
187
|
+
const issued = await issue('LATE-PROOF')
|
|
188
|
+
const reached = signal(), release = signal()
|
|
189
|
+
const push = platform.index.pushProof.bind(platform.index)
|
|
190
|
+
vi.spyOn(platform.index, 'pushProof').mockImplementationOnce(async (txid, path) => {
|
|
191
|
+
reached.resolve()
|
|
192
|
+
await release.promise
|
|
193
|
+
return push(txid, path)
|
|
194
|
+
})
|
|
195
|
+
const proving = otherWriter.prove((await secondary.getPassport(issued.record.passportId))!, issued.entry.txid)
|
|
196
|
+
let nextTxid: string
|
|
197
|
+
try {
|
|
198
|
+
await reached.promise
|
|
199
|
+
const latest = (await primary.getPassport(issued.record.passportId))!
|
|
200
|
+
nextTxid = (await update(writer, latest, 'during proof')).entry.txid
|
|
201
|
+
} finally { release.resolve(); await proving }
|
|
202
|
+
const { states } = (await secondary.getPassport(issued.record.passportId))!
|
|
203
|
+
expect(states.map((entry) => entry.txid)).toEqual([issued.entry.txid, nextTxid])
|
|
204
|
+
expect(states[0]).toMatchObject({ rawTx: issued.entry.rawTx, sentBeef: issued.entry.beef, proofPushed: true })
|
|
205
|
+
expect(states[0]!.beef).not.toBe(issued.entry.beef)
|
|
206
|
+
expect(states[1]!.proof).toBeUndefined()
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('preserves an appended state when the worker receives a late index announcement', async () => {
|
|
210
|
+
const announce = platform.index.announce.bind(platform.index)
|
|
211
|
+
const requests = vi.spyOn(platform.index, 'announce').mockResolvedValueOnce('unreachable').mockResolvedValueOnce('unreachable')
|
|
212
|
+
const issued = await issue('LATE-ANNOUNCEMENT')
|
|
213
|
+
expect(issued.entry.index).toBe('unreachable')
|
|
214
|
+
const reached = signal(), release = signal()
|
|
215
|
+
requests.mockImplementationOnce(async (bytes) => {
|
|
216
|
+
const outcome = await announce(bytes)
|
|
217
|
+
reached.resolve()
|
|
218
|
+
await release.promise
|
|
219
|
+
return outcome
|
|
220
|
+
})
|
|
221
|
+
const worker = runDuties({ store: secondary, index: platform.index, writer: otherWriter })
|
|
222
|
+
let nextTxid: string
|
|
223
|
+
try {
|
|
224
|
+
await reached.promise
|
|
225
|
+
nextTxid = (await update(writer, (await primary.getPassport(issued.record.passportId))!, 'during announcement')).entry.txid
|
|
226
|
+
} finally { release.resolve(); await worker }
|
|
227
|
+
const { states } = (await primary.getPassport(issued.record.passportId))!
|
|
228
|
+
expect(states.map((entry) => entry.txid)).toEqual([issued.entry.txid, nextTxid])
|
|
229
|
+
expect(states[0]!.index).toBe('admitted')
|
|
230
|
+
expect(states[1]!.network).toBe('dry-run')
|
|
231
|
+
expect(requests.mock.calls[2]![0]).toEqual(Utils.toArray(issued.entry.beef, 'base64'))
|
|
232
|
+
})
|
|
233
|
+
it.each(['current', 'legacy'] as const)('retains a refused %s draft until withdrawal succeeds at the original index', async (journalVersion) => {
|
|
234
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('refused')
|
|
235
|
+
const withdrawals = vi.spyOn(platform.index, 'retract').mockResolvedValueOnce({ ok: false, detail: 'temporarily offline' })
|
|
236
|
+
await expect(issue('WITHDRAWAL')).rejects.toMatchObject({ code: 'retraction-pending' })
|
|
237
|
+
const record = (await secondary.getPassport(id('WITHDRAWAL')))!
|
|
238
|
+
const draft = record.states[0]!
|
|
239
|
+
expect(draft.network).toBe('refused')
|
|
240
|
+
expect(draft.draftIndexId).toBe(platform.index.destinationId)
|
|
241
|
+
if (journalVersion === 'legacy') {
|
|
242
|
+
delete draft.draftIndexId
|
|
243
|
+
await secondary.savePassport(record)
|
|
244
|
+
}
|
|
245
|
+
expect(withdrawals).toHaveBeenCalledExactlyOnceWith(draft.txid, expect.stringContaining('the network refused'), draft.outputIndex)
|
|
246
|
+
await expect(otherWriter.resolveInterrupted(record, draft.txid, 'sent')).rejects.toMatchObject({ code: 'not-interrupted' })
|
|
247
|
+
await otherWriter.resolveInterrupted(record, draft.txid, 'abandoned')
|
|
248
|
+
expect(withdrawals.mock.calls[1]).toEqual(withdrawals.mock.calls[0])
|
|
249
|
+
expect(await primary.getPassport(record.passportId)).toBeUndefined()
|
|
250
|
+
const retry = await issue('WITHDRAWAL')
|
|
251
|
+
expect(retry.record.states).toHaveLength(1)
|
|
252
|
+
expect(retry.entry).not.toHaveProperty('draftIndexId')
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('requires the original index to reconcile a withdrawal before replacing an outstanding draft', async () => {
|
|
256
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('unanswered')
|
|
257
|
+
await expect(issue('INDEX-CHANGED')).rejects.toMatchObject({ code: 'network-unanswered' })
|
|
258
|
+
const pending = (await secondary.getPassport(id('INDEX-CHANGED')))!
|
|
259
|
+
const draft = pending.states[0]!
|
|
260
|
+
const replacement = new IndexClient({ url: 'https://replacement.example', supportsRetraction: true })
|
|
261
|
+
const wrongIndex = vi.spyOn(replacement, 'retract').mockResolvedValue({ ok: false, absent: true, detail: 'output unknown' })
|
|
262
|
+
const discard = vi.spyOn(platform.wallet.adapter, 'discard')
|
|
263
|
+
await expect(newWriter(secondary, replacement).resolveInterrupted(pending, draft.txid, 'abandoned'))
|
|
264
|
+
.rejects.toMatchObject({ code: 'retraction-index-changed' })
|
|
265
|
+
expect(wrongIndex).not.toHaveBeenCalled()
|
|
266
|
+
expect(discard).not.toHaveBeenCalled()
|
|
267
|
+
expect((await primary.getPassport(pending.passportId))!.states[0]!.network).toBe('unanswered')
|
|
268
|
+
const original = vi.spyOn(platform.index, 'retract')
|
|
269
|
+
await otherWriter.resolveInterrupted(pending, draft.txid, 'abandoned')
|
|
270
|
+
expect(original).toHaveBeenCalledExactlyOnceWith(draft.txid, expect.any(String), draft.outputIndex)
|
|
271
|
+
expect(await primary.getPassport(pending.passportId)).toBeUndefined()
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('keeps the transaction when the wallet reports it was already seen during abandonment', async () => {
|
|
275
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('unanswered')
|
|
276
|
+
await expect(issue('ALREADY-SEEN')).rejects.toMatchObject({ code: 'network-unanswered' })
|
|
277
|
+
const record = (await secondary.getPassport(id('ALREADY-SEEN')))!
|
|
278
|
+
const entry = record.states[0]!
|
|
279
|
+
vi.spyOn(platform.wallet.adapter, 'discard').mockRejectedValueOnce(new ActionAlreadySeen('seen by the wallet'))
|
|
280
|
+
const withdrawn = vi.spyOn(platform.index, 'retract')
|
|
281
|
+
await expect(otherWriter.resolveInterrupted(record, entry.txid, 'abandoned')).rejects.toMatchObject({ code: 'network-seen' })
|
|
282
|
+
expect(withdrawn).not.toHaveBeenCalled()
|
|
283
|
+
expect((await primary.getPassport(record.passportId))!.states[0]).toMatchObject({ rawTx: entry.rawTx, beef: entry.beef, network: 'unanswered' })
|
|
284
|
+
expect((await writer.resolveInterrupted(record, entry.txid, 'sent')).states[0]!.network).toBe('dry-run')
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
it('shows a pending genesis and keeps an unanswered update out of the current public payload', async () => {
|
|
288
|
+
const api = createServer({ platform: { ...platform, store: primary, writer } })
|
|
289
|
+
const server = api.listen(0, '127.0.0.1')
|
|
290
|
+
await once(server, 'listening')
|
|
291
|
+
const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}/api/passports/${encodeURIComponent(id('PENDING-VIEW'))}`
|
|
292
|
+
try {
|
|
293
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('unanswered')
|
|
294
|
+
await expect(issue('PENDING-VIEW')).rejects.toMatchObject({ code: 'network-unanswered' })
|
|
295
|
+
const draft = (await primary.getPassport(id('PENDING-VIEW')))!
|
|
296
|
+
const pending = await (await fetch(url)).json()
|
|
297
|
+
expect(pending.status).toBe('awaiting-send')
|
|
298
|
+
expect(pending).not.toHaveProperty('payload')
|
|
299
|
+
const issued = await writer.resolveInterrupted(draft, draft.states[0]!.txid, 'sent')
|
|
300
|
+
vi.spyOn(platform.wallet.adapter, 'send').mockResolvedValueOnce('unanswered')
|
|
301
|
+
const payload = { ...data(), name: 'Unanswered change' }
|
|
302
|
+
await expect(writer.update({ record: issued, actor: brand(), payload })).rejects.toMatchObject({ code: 'network-unanswered' })
|
|
303
|
+
const current = await (await fetch(url)).json()
|
|
304
|
+
expect(current.payload).toEqual(JSON.parse(issued.states[0]!.payloadPublic))
|
|
305
|
+
expect(current.states.map((state: { network: string }) => state.network)).toEqual(['dry-run', 'unanswered'])
|
|
306
|
+
} finally {
|
|
307
|
+
server.closeAllConnections()
|
|
308
|
+
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('refuses to carry a missing or damaged committed owner tier on a public update or retirement', async () => {
|
|
313
|
+
const { record } = await issue('COMMITTED-TIER')
|
|
314
|
+
for (const damage of ['missing', 'ciphertext', 'digest']) {
|
|
315
|
+
const changed = structuredClone(record)
|
|
316
|
+
const original = changed.states[0]!.ownerTier!
|
|
317
|
+
if (damage === 'missing') delete changed.states[0]!.ownerTier
|
|
318
|
+
if (damage === 'ciphertext') original.ciphertext = Buffer.from('truncated ciphertext').toString('base64')
|
|
319
|
+
if (damage === 'digest') original.hash = '00'.repeat(32)
|
|
320
|
+
await primary.savePassport(changed)
|
|
321
|
+
await expect(writer.update({ record: changed, actor: brand(), payload: data() })).rejects.toMatchObject({ code: 'owner-tier-unsound' })
|
|
322
|
+
await expect(writer.retire({ record: changed, actor: brand(), reason: 'recycled' })).rejects.toMatchObject({ code: 'owner-tier-unsound' })
|
|
323
|
+
expect((await primary.getPassport(record.passportId))!.states).toHaveLength(1)
|
|
324
|
+
}
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
include: ['test/**/*.test.ts'],
|
|
6
|
+
testTimeout: 60_000,
|
|
7
|
+
hookTimeout: 60_000,
|
|
8
|
+
// The pinned GS1 files the EPCIS tests validate against are provisioned once, before any test, and never skipped.
|
|
9
|
+
globalSetup: ['./test/gs1-global-setup.ts'],
|
|
10
|
+
setupFiles: ['./test/gs1-test-env.ts'],
|
|
11
|
+
},
|
|
12
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/index.css",
|
|
9
|
+
"baseColor": "neutral",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"iconLibrary": "lucide",
|
|
14
|
+
"aliases": {
|
|
15
|
+
"components": "@/components",
|
|
16
|
+
"utils": "@/lib/utils",
|
|
17
|
+
"ui": "@/components/ui",
|
|
18
|
+
"lib": "@/lib",
|
|
19
|
+
"hooks": "@/hooks"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Digital Product Passports</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "web",
|
|
3
|
+
"private": true,
|
|
4
|
+
"description": "The web app: brand dashboard, passport pages, hand-on acceptance, public verification",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"build": "tsc -p tsconfig.json --noEmit && vite build",
|
|
10
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
11
|
+
"preview": "vite preview"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"better-auth": "1.7.7",
|
|
15
|
+
"class-variance-authority": "^0.7.1",
|
|
16
|
+
"cn": "^0.4.0",
|
|
17
|
+
"lucide-react": "^1.54.0",
|
|
18
|
+
"radix-ui": "^1.7.0",
|
|
19
|
+
"react": "19.3.0",
|
|
20
|
+
"react-dom": "19.3.0",
|
|
21
|
+
"react-router": "8.4.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
25
|
+
"@types/node": "^22.20.3",
|
|
26
|
+
"@types/react": "^19.2.0",
|
|
27
|
+
"@types/react-dom": "^19.2.0",
|
|
28
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
29
|
+
"tailwindcss": "^4.3.3",
|
|
30
|
+
"typescript": "^7.0.2",
|
|
31
|
+
"vite": "^8.3.4"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The routes. A label's QR code carries the identifier, whose own path,
|
|
2
|
+
// /01/<gtin>/21/<serial>, the API answers as a resolver: it redirects a
|
|
3
|
+
// browser to the public passport page under /passport, at the same path.
|
|
4
|
+
import { Link, Route, Routes } from 'react-router'
|
|
5
|
+
import { Layout } from '@/components/layout'
|
|
6
|
+
import { Accept } from '@/pages/accept'
|
|
7
|
+
import { Brand } from '@/pages/brand'
|
|
8
|
+
import { Brands } from '@/pages/brands'
|
|
9
|
+
import { Events } from '@/pages/events'
|
|
10
|
+
import { Home } from '@/pages/home'
|
|
11
|
+
import { NewPassport } from '@/pages/new-passport'
|
|
12
|
+
import { Operations } from '@/pages/operations'
|
|
13
|
+
import { Passport } from '@/pages/passport'
|
|
14
|
+
import { PublicPassport, PublicProduct } from '@/pages/public-passport'
|
|
15
|
+
import { SignIn } from '@/pages/sign-in'
|
|
16
|
+
import { Verify } from '@/pages/verify'
|
|
17
|
+
import { Wallet } from '@/pages/wallet'
|
|
18
|
+
|
|
19
|
+
function NotFound() {
|
|
20
|
+
return (
|
|
21
|
+
<div className="space-y-2">
|
|
22
|
+
<h1 className="text-2xl font-semibold">Not found</h1>
|
|
23
|
+
<p className="text-sm text-muted-foreground">
|
|
24
|
+
There is no page here.{' '}
|
|
25
|
+
<Link to="/" className="underline underline-offset-4">
|
|
26
|
+
Home
|
|
27
|
+
</Link>
|
|
28
|
+
</p>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function App() {
|
|
34
|
+
return (
|
|
35
|
+
<Routes>
|
|
36
|
+
<Route element={<Layout />}>
|
|
37
|
+
<Route index element={<Home />} />
|
|
38
|
+
<Route path="sign-in" element={<SignIn mode="sign-in" />} />
|
|
39
|
+
<Route path="sign-up" element={<SignIn mode="sign-up" />} />
|
|
40
|
+
<Route path="brands" element={<Brands />} />
|
|
41
|
+
<Route path="brands/:brandId" element={<Brand />} />
|
|
42
|
+
<Route path="brands/:brandId/new" element={<NewPassport />} />
|
|
43
|
+
<Route path="passports/:ref" element={<Passport />} />
|
|
44
|
+
<Route path="passport/01/:gtin/21/:serial" element={<PublicPassport />} />
|
|
45
|
+
<Route path="passport/01/:gtin" element={<PublicProduct />} />
|
|
46
|
+
<Route path="verify" element={<Verify />} />
|
|
47
|
+
<Route path="accept/:requestId" element={<Accept />} />
|
|
48
|
+
<Route path="events" element={<Events />} />
|
|
49
|
+
<Route path="operations" element={<Operations />} />
|
|
50
|
+
<Route path="wallet" element={<Wallet />} />
|
|
51
|
+
<Route path="*" element={<NotFound />} />
|
|
52
|
+
</Route>
|
|
53
|
+
</Routes>
|
|
54
|
+
)
|
|
55
|
+
}
|