@bsv/create-dpp-app 0.1.0-beta.1 → 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/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +26 -6
- package/dist/index.js +36 -8
- package/package.json +9 -5
- package/template/Dockerfile +4 -2
- package/template/README.md +297 -42
- package/template/_env.example +82 -13
- package/template/_github/workflows/ci.yml +3 -3
- package/template/apps/api/API.md +86 -16
- package/template/apps/api/package.json +9 -4
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +175 -56
- package/template/apps/api/src/cli.ts +64 -7
- package/template/apps/api/src/config.ts +124 -10
- package/template/apps/api/src/custody.ts +241 -69
- package/template/apps/api/src/dev-index.ts +58 -9
- package/template/apps/api/src/env-file.ts +55 -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 +1 -1
- package/template/apps/api/src/index-client.ts +131 -6
- 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 +10 -2
- package/template/apps/api/src/parties.ts +2 -2
- package/template/apps/api/src/platform.ts +72 -17
- 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 +38 -13
- package/template/apps/api/src/reader.ts +172 -3
- 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 +253 -60
- package/template/apps/api/src/store.ts +198 -21
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +30 -17
- package/template/apps/api/src/worker.ts +20 -13
- package/template/apps/api/src/writer.ts +383 -131
- 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 +148 -3
- 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 +3 -2
- 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 +17 -6
- 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/vitest.config.ts +3 -0
- package/template/apps/web/src/app.tsx +8 -4
- 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 +17 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +2 -2
- package/template/apps/web/src/components/read-passport.tsx +4 -3
- package/template/apps/web/src/components/reading.tsx +32 -39
- package/template/apps/web/src/lib/api.ts +136 -26
- 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 +27 -4
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/pages/accept.tsx +8 -3
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/new-passport.tsx +25 -2
- package/template/apps/web/src/pages/operations.tsx +22 -3
- package/template/apps/web/src/pages/passport.tsx +226 -162
- package/template/apps/web/src/pages/public-passport.tsx +50 -10
- package/template/apps/web/src/pages/wallet.tsx +1 -1
- package/template/apps/web/vite.config.ts +12 -4
- package/template/deploy/compose.yml +14 -2
- package/template/package.json +9 -3
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
// EPCIS lifecycle claims through the application: issued from EPCIS event
|
|
2
|
+
// data over the API, read back from each passport they bind, anchored by a
|
|
3
|
+
// registry once per bound passport, and found again by those anchors. The
|
|
4
|
+
// claim's findings are reported one by one, and the words the web page puts
|
|
5
|
+
// on them are held to the answers here.
|
|
6
|
+
//
|
|
7
|
+
// The old way, a native claim with one of four event types picked for a
|
|
8
|
+
// passport, is not reachable from the claim route. A historical native claim
|
|
9
|
+
// a deployment still holds reads as before, labelled as historical.
|
|
10
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
11
|
+
import { tmpdir } from 'node:os'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { afterAll, beforeAll, describe, expect, it, onTestFinished, vi } from 'vitest'
|
|
14
|
+
import { Hash, Utils } from '@bsv/sdk'
|
|
15
|
+
import { signLifecycleClaim, type LifecycleClaim } from '@bsv/dpp-protocol'
|
|
16
|
+
import { verifyEpcisLifecycleClaim } from '@bsv/dpp-credentials/epcis-lifecycle'
|
|
17
|
+
import * as claimsModule from '../src/claims.js'
|
|
18
|
+
import { compareLifecycleProduct, readPassportClaims } from '../src/lifecycle.js'
|
|
19
|
+
import { openLifecycleAuthority } from '../src/lifecycle-authority.js'
|
|
20
|
+
import { managedParties } from '../src/parties.js'
|
|
21
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
22
|
+
import { boundedJson } from '../src/index-client.js'
|
|
23
|
+
import { samplePayload } from '../src/profiles.js'
|
|
24
|
+
import { MemoryStore, MongoStore, type EpcisLifecycleClaimRecord } from '../src/store.js'
|
|
25
|
+
import { HISTORICAL_LABEL, LIFECYCLE_NOTICE, correctionLabel, emptyEventForm, eventFromForm, findingRows, participationLabel, type LifecycleClaimView, type PassportClaimsReading } from '../../web/src/lib/lifecycle'
|
|
26
|
+
import { epcisDocument, startApp, startMongo, testConfig, utf8, type Answer, type TestApp } from './epcis-fixtures.js'
|
|
27
|
+
import { PALLET, PARTY, PLACE, base, classOf, sgtinOf, startTestRegistry, type Json, type TestRegistry } from './lifecycle-fixtures.js'
|
|
28
|
+
|
|
29
|
+
const policy = { host: 'passports.example.com', prefix: '952' }
|
|
30
|
+
const P = {
|
|
31
|
+
battery: mintPassportId(policy, '100000001', 'BAT-0001'),
|
|
32
|
+
battery2: mintPassportId(policy, '100000001', 'BAT-0002'),
|
|
33
|
+
moduleA: mintPassportId(policy, '100000002', 'MOD-A'),
|
|
34
|
+
moduleB: mintPassportId(policy, '100000002', 'MOD-B'),
|
|
35
|
+
pack: mintPassportId(policy, '100000003', 'PACK-01'),
|
|
36
|
+
bystander: mintPassportId(policy, '100000004', 'OTHER-01'),
|
|
37
|
+
paged: mintPassportId(policy, '100000005', 'PAGED-01'),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const grantsDir = mkdtempSync(join(tmpdir(), 'dpp-claim-grants-'))
|
|
41
|
+
let api: TestApp
|
|
42
|
+
let registry: TestRegistry
|
|
43
|
+
const ref = (passportId: string): string => encodeURIComponent(passportId)
|
|
44
|
+
const claimsOf = async (passportId: string): Promise<PassportClaimsReading> => (await api.get(`/api/passports/${ref(passportId)}/claims`)).body as PassportClaimsReading
|
|
45
|
+
const issue = async (passportId: string, body: Json): Promise<Answer> => await api.post(`/api/passports/${ref(passportId)}/claims`, body)
|
|
46
|
+
const issued = async (passportId: string, body: Json): Promise<LifecycleClaimView> => {
|
|
47
|
+
const answer = await issue(passportId, body)
|
|
48
|
+
expect(answer.status, answer.text).toBe(200)
|
|
49
|
+
return answer.body as LifecycleClaimView
|
|
50
|
+
}
|
|
51
|
+
const findOn = async (passportId: string, attestationId: string): Promise<LifecycleClaimView | undefined> => (await claimsOf(passportId)).lifecycle.find((c) => c.attestationId === attestationId)
|
|
52
|
+
|
|
53
|
+
beforeAll(async () => {
|
|
54
|
+
registry = await startTestRegistry(() => ({ url: api.platform.devIndex!.url, submitToken: api.platform.devIndex!.submitToken }))
|
|
55
|
+
const file = join(grantsDir, 'authority.json')
|
|
56
|
+
const config = testConfig({ REGISTRY_URL: registry.url, LIFECYCLE_AUTHORITY_GRANTS_FILE: file })
|
|
57
|
+
const member = managedParties(config).member('developer')
|
|
58
|
+
const grants = Object.values(P).flatMap((passportId) => ['observer', 'custodian', 'owner', 'authorised-reporter'].map((role) => ({
|
|
59
|
+
issuer: member.did, issuerKey: member.identityKey, passportId, role, purpose: 'claim', validFrom: '2026-03-01T00:00:00Z', validUntil: '2026-04-01T00:00:00Z',
|
|
60
|
+
})))
|
|
61
|
+
const deputy = managedParties(config).member('inspection-deputy')
|
|
62
|
+
grants.push(...['claim', 'error-declaration'].map((purpose) => ({ issuer: deputy.did, issuerKey: deputy.identityKey, passportId: P.battery, role: 'observer', purpose, validFrom: '2026-03-01T00:00:00Z', validUntil: '2026-04-01T00:00:00Z' })))
|
|
63
|
+
writeFileSync(file, JSON.stringify({ grants }))
|
|
64
|
+
api = await startApp({ config })
|
|
65
|
+
const brand = api.platform.parties.brand('dev-brand')
|
|
66
|
+
await api.platform.store.saveBrand({ id: 'dev-brand', name: 'Development brand', identityKey: brand.identityKey, did: brand.did, createdAt: new Date().toISOString() })
|
|
67
|
+
for (const passportId of Object.values(P)) await api.platform.writer.issue({ brandId: 'dev-brand', brand, passportId, profile: 'general@2', payload: samplePayload('general@2', true), ownerFields: {} })
|
|
68
|
+
})
|
|
69
|
+
afterAll(async () => {
|
|
70
|
+
await api?.close()
|
|
71
|
+
await registry?.close()
|
|
72
|
+
rmSync(grantsDir, { recursive: true, force: true })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('operator grants for qualified lifecycle issuance', () => {
|
|
76
|
+
it('L05/L07: passport control, a member account and a caller-supplied grant confer no physical role', async () => {
|
|
77
|
+
const controller = api.platform.parties.brand('dev-brand')
|
|
78
|
+
const member = vi.spyOn(api.platform.parties, 'member').mockReturnValue(controller)
|
|
79
|
+
const sign = vi.spyOn(controller.wallet, 'createSignature')
|
|
80
|
+
const save = vi.spyOn(api.platform.store, 'saveClaim')
|
|
81
|
+
const submit = vi.spyOn(api.platform.claims, 'submit')
|
|
82
|
+
onTestFinished(() => { member.mockRestore(); sign.mockRestore(); save.mockRestore(); submit.mockRestore() })
|
|
83
|
+
const event = { type: 'ObjectEvent', ...base(2), epcList: [P.battery], action: 'OBSERVE', bizStep: 'inspecting' }
|
|
84
|
+
const records = await api.platform.store.listClaims()
|
|
85
|
+
for (const role of ['owner', 'custodian', 'observer', 'authorised-reporter']) {
|
|
86
|
+
const result = await issue(P.battery, { event, assertedRole: role, submit: true, authorityResolver: { status: 'supported' }, grants: [{ issuer: controller.did, issuerKey: controller.identityKey, role, passportId: P.battery }] })
|
|
87
|
+
expect([result.status, result.body.error, result.body.finding.status]).toEqual([409, 'authority-unconfirmed', 'refused'])
|
|
88
|
+
}
|
|
89
|
+
expect(sign).not.toHaveBeenCalled()
|
|
90
|
+
expect(save).not.toHaveBeenCalled()
|
|
91
|
+
expect(submit).not.toHaveBeenCalled()
|
|
92
|
+
expect(await api.platform.store.listClaims()).toEqual(records)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('L06: qualified multi-product issuance needs the role grant for each signed binding', async () => {
|
|
96
|
+
const event = { type: 'ObjectEvent', ...base(23), epcList: [P.battery, P.moduleA, 'urn:epc:id:sgtin:9521234.012345.NOT-HERE'], action: 'OBSERVE' }
|
|
97
|
+
const signed = await issued(P.battery, { event, assertedRole: 'observer' })
|
|
98
|
+
expect([...(signed.authorityScope ?? [])].sort()).toEqual([P.battery, P.moduleA].sort())
|
|
99
|
+
expect(signed.findings!.authority.status).toBe('supported')
|
|
100
|
+
const deputy = api.platform.parties.member('inspection-deputy')
|
|
101
|
+
const member = vi.spyOn(api.platform.parties, 'member').mockReturnValue(deputy)
|
|
102
|
+
const sign = vi.spyOn(deputy.wallet, 'createSignature')
|
|
103
|
+
const save = vi.spyOn(api.platform.store, 'saveClaim')
|
|
104
|
+
const submit = vi.spyOn(api.platform.claims, 'submit')
|
|
105
|
+
onTestFinished(() => { member.mockRestore(); sign.mockRestore(); save.mockRestore(); submit.mockRestore() })
|
|
106
|
+
for (const [scope, code] of [[undefined, 'authority-unconfirmed'], [[P.battery], 'authority-scope-incomplete']] as const) {
|
|
107
|
+
const result = await issue(P.battery, { event, authorityScope: scope, assertedRole: 'observer', submit: true })
|
|
108
|
+
expect([result.status, result.body.error]).toEqual([409, code])
|
|
109
|
+
}
|
|
110
|
+
expect(sign).not.toHaveBeenCalled()
|
|
111
|
+
expect(save).not.toHaveBeenCalled()
|
|
112
|
+
expect(submit).not.toHaveBeenCalled()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('requires the additional grant to correct a different issuer, separately from the role grant to claim', async () => {
|
|
116
|
+
const event = { type: 'ObjectEvent', ...base(24), epcList: [P.battery], action: 'OBSERVE' }
|
|
117
|
+
const original = await issued(P.battery, { event, assertedRole: 'observer' })
|
|
118
|
+
const deputy = api.platform.parties.member('inspection-deputy')
|
|
119
|
+
const member = vi.spyOn(api.platform.parties, 'member').mockReturnValue(deputy)
|
|
120
|
+
onTestFinished(() => member.mockRestore())
|
|
121
|
+
expect((await issued(P.battery, { correctionOf: original.attestationId })).findings!.authority.status).toBe('supported')
|
|
122
|
+
const own = await issued(P.battery, { event: { ...event, ...base(25) }, assertedRole: 'observer' })
|
|
123
|
+
member.mockRestore()
|
|
124
|
+
const actor = api.platform.parties.member('developer')
|
|
125
|
+
const actorLookup = vi.spyOn(api.platform.parties, 'member').mockReturnValue(actor)
|
|
126
|
+
const sign = vi.spyOn(actor.wallet, 'createSignature')
|
|
127
|
+
onTestFinished(() => { actorLookup.mockRestore(); sign.mockRestore() })
|
|
128
|
+
const refusal = await issue(P.battery, { correctionOf: own.attestationId, submit: true })
|
|
129
|
+
expect([refusal.status, refusal.body.error]).toEqual([409, 'authority-unconfirmed'])
|
|
130
|
+
expect(sign).not.toHaveBeenCalled()
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('L06: local grants require an exact issuer, key, product, purpose and role within their validity interval', () => {
|
|
134
|
+
const signer = api.platform.parties.member('developer')
|
|
135
|
+
const other = api.platform.parties.member('other')
|
|
136
|
+
const grant = { issuer: 'did:web:factory.example', issuerKey: signer.identityKey, passportId: P.battery, role: 'owner' as const, purpose: 'claim' as const, validFrom: '2026-03-01T00:00:00Z', validUntil: '2026-04-01T00:00:00Z' }
|
|
137
|
+
const path = join(grantsDir, 'scope.json')
|
|
138
|
+
writeFileSync(path, JSON.stringify({ grants: [grant] }))
|
|
139
|
+
const resolve = openLifecycleAuthority(path)
|
|
140
|
+
const q = { ...grant, eventId: 'urn:uuid:30824161-6804-4335-a200-000000001110', eventType: 'ObjectEvent' as const, eventTime: grant.validFrom, issuedAt: '2026-11-24T00:00:00Z' }
|
|
141
|
+
expect(resolve(q)).toMatchObject({ status: 'supported' })
|
|
142
|
+
expect(resolve({ ...q, eventTime: '2026-04-01T00:59:59.999+01:00' })).toMatchObject({ status: 'supported' })
|
|
143
|
+
for (const change of [{ issuer: other.did }, { issuerKey: other.identityKey }, { passportId: P.battery2 }, { role: 'custodian' as const }, { purpose: 'error-declaration' as const }, { eventTime: '2026-02-28T23:59:59.999Z' }, { eventTime: grant.validUntil }]) {
|
|
144
|
+
expect(resolve({ ...q, ...change })).toMatchObject({ status: 'unsupported' })
|
|
145
|
+
}
|
|
146
|
+
for (const change of [{ issuer: signer.did, issuerKey: other.identityKey }, { passportId: '*' }, { issuerKey: 'invalid' }, { role: 'anything' }, { purpose: 'other' }, { validFrom: '2026-02-30T00:00:00Z' }, { validFrom: grant.validUntil }, { validUntil: undefined }, { wildcard: true }]) {
|
|
147
|
+
writeFileSync(path, JSON.stringify({ grants: [{ ...grant, ...change }] }))
|
|
148
|
+
expect(() => openLifecycleAuthority(path)).toThrow()
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('L08: the same historical bytes remain readable with absent, refusing and supported evidence', async () => {
|
|
153
|
+
const view = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(21), epcList: [P.battery], action: 'OBSERVE' }, assertedRole: 'observer' })
|
|
154
|
+
const options = { store: api.platform.store, index: api.platform.index }
|
|
155
|
+
for (const [authorityResolver, status] of [[undefined, 'unavailable'], [() => ({ status: 'unsupported' as const }), 'refused'], [api.platform.lifecyclePolicy.authorityResolver, 'supported']] as const) {
|
|
156
|
+
const reading = await readPassportClaims(P.battery, { ...options, authorityResolver })
|
|
157
|
+
const claim = reading.lifecycle.find((entry) => entry.attestationId === view.attestationId)!
|
|
158
|
+
expect(claim.findings).toMatchObject({ signature: { status: 'pass' }, authority: { status }, ownership: { status: 'not-asserted' }, possession: { status: 'not-asserted' } })
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
describe('issuing from EPCIS event data, all five types', () => {
|
|
164
|
+
it('commissioning: an ObjectEvent with ADD, signed by the member as observer, every finding on its own', async () => {
|
|
165
|
+
const event = { type: 'ObjectEvent', ...base(2), epcList: [P.battery], action: 'ADD', bizStep: 'commissioning', disposition: 'active', readPoint: { id: PLACE.factory }, bizLocation: { id: PLACE.factory } }
|
|
166
|
+
const view = await issued(P.battery, { event, assertedRole: 'observer' })
|
|
167
|
+
expect(view).toMatchObject({ claimFormat: 'dpp-epcis-lifecycle@1', eventType: 'ObjectEvent', participation: 'item', foundBy: ['this-application'], held: true, assertedRole: 'observer', authorityScope: [P.battery] })
|
|
168
|
+
expect(view.event).toEqual(event)
|
|
169
|
+
const f = view.findings!
|
|
170
|
+
expect([f.eventStructure.status, f.eventSemantics.status, f.productBinding.status, f.signature.status]).toEqual(['pass', 'pass', 'pass', 'pass'])
|
|
171
|
+
// The configured grant independently supports this member for the product and role at the event time.
|
|
172
|
+
expect(f.authority).toMatchObject({ status: 'supported' })
|
|
173
|
+
expect([f.possession.status, f.ownership.status]).toEqual(['not-asserted', 'not-asserted'])
|
|
174
|
+
// Not sent to a registry: no anchor and no inclusion, and they say so.
|
|
175
|
+
expect([f.anchorCommitment.status, f.inclusion.status]).toEqual(['unknown', 'unknown'])
|
|
176
|
+
expect(f.correction).toMatchObject({ status: 'unknown', reasonCode: 'x-related-incomplete' })
|
|
177
|
+
expect((await findOn(P.battery, view.attestationId))?.findings?.correction.status).toBe('none')
|
|
178
|
+
// The bytes are retrievable exactly, and verify without this application.
|
|
179
|
+
const bytes = await api.get(`/api/lifecycle-claims/${ref(view.attestationId)}`)
|
|
180
|
+
expect(bytes.headers.get('content-type')).toMatch(/^application\/json/)
|
|
181
|
+
expect(`urn:sha256:${Utils.toHex(Hash.sha256(Array.from(bytes.bytes)))}`).toBe(view.attestationId)
|
|
182
|
+
expect((await verifyEpcisLifecycleClaim(bytes.text)).findings.signature.status).toBe('pass')
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('manufacturing: a TransformationEvent has no action, binds its inputs and output, and reads back from each of them', async () => {
|
|
186
|
+
const event = { type: 'TransformationEvent', ...base(3), inputEPCList: [P.moduleA, sgtinOf(P.moduleB)], outputEPCList: [P.pack], bizStep: 'commissioning', disposition: 'active', readPoint: { id: PLACE.factory } }
|
|
187
|
+
const view = await issued(P.pack, { event, assertedRole: 'observer', submit: true })
|
|
188
|
+
expect(view.event).not.toHaveProperty('action')
|
|
189
|
+
expect(view.boundPassports).toEqual([P.moduleA, P.moduleB, P.pack].sort())
|
|
190
|
+
// The registry anchored the exact bytes once per bound passport, in one transaction.
|
|
191
|
+
expect(view.record?.registry).toMatchObject({ accepted: true, attestationId: view.attestationId })
|
|
192
|
+
expect(registry.anchors.at(-1)!.outputs).toHaveLength(3)
|
|
193
|
+
for (const passportId of [P.moduleA, P.moduleB, P.pack]) {
|
|
194
|
+
const found = await findOn(passportId, view.attestationId)
|
|
195
|
+
expect(found, passportId).toMatchObject({ participation: 'item', foundBy: ['anchor', 'this-application'] })
|
|
196
|
+
expect(found!.findings!.anchorCommitment.status).toBe('pass')
|
|
197
|
+
expect(found!.findings!.anchorCommitment.detail).toMatchObject({ coveredPassports: [P.moduleA, P.moduleB, P.pack].sort(), uncoveredPassports: [] })
|
|
198
|
+
// Nothing in this test is mined, and nothing is said about inclusion.
|
|
199
|
+
expect(found!.findings!.inclusion.status).toBe('unknown')
|
|
200
|
+
}
|
|
201
|
+
// An EPC URN of the module binds the same passport as its Digital Link: the identity rules compare the item, not the spelling.
|
|
202
|
+
expect((await findOn(P.moduleB, view.attestationId))!.bindingsHere).toEqual([expect.objectContaining({ field: 'inputEPCList', identifier: sgtinOf(P.moduleB), level: 'instance', status: 'pass' })])
|
|
203
|
+
// An action on a transformation is refused, as EPCIS 2.0.1 refuses it. Nothing is signed.
|
|
204
|
+
const refused = await issue(P.pack, { event: { ...event, ...base(3), action: 'ADD' }, assertedRole: 'observer' })
|
|
205
|
+
expect(refused.status).toBe(409)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('packing: an AggregationEvent keeps the container and its contents, and binds each content passport', async () => {
|
|
209
|
+
const view = await issued(P.battery, { event: { type: 'AggregationEvent', ...base(4), parentID: PALLET, childEPCs: [P.battery, P.battery2], action: 'ADD', bizStep: 'packing', disposition: 'in_progress', readPoint: { id: PLACE.factory } }, assertedRole: 'observer' })
|
|
210
|
+
expect(view.boundPassports).toEqual([P.battery, P.battery2].sort())
|
|
211
|
+
expect((await findOn(P.battery2, view.attestationId))?.participation).toBe('item')
|
|
212
|
+
expect((view.event as Json).parentID).toBe(PALLET)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('a TransactionEvent associates the item with a named business transaction, not with a sale', async () => {
|
|
216
|
+
const view = await issued(P.battery, { event: { type: 'TransactionEvent', ...base(5), bizTransactionList: [{ type: 'po', bizTransaction: 'https://example.org/orders/PO-1001' }], epcList: [P.battery], action: 'ADD', bizStep: 'accepting', disposition: 'in_progress' }, assertedRole: 'authorised-reporter' })
|
|
217
|
+
expect(view.eventType).toBe('TransactionEvent')
|
|
218
|
+
expect([view.findings!.ownership.status, view.findings!.possession.status]).toEqual(['not-asserted', 'not-asserted'])
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('an AssociationEvent records an assembly and binds parent and component', async () => {
|
|
222
|
+
const view = await issued(P.pack, { event: { type: 'AssociationEvent', ...base(6), parentID: P.pack, childEPCs: [P.battery2], action: 'ADD', bizStep: 'assembling', disposition: 'active', readPoint: { id: PLACE.workshop } }, assertedRole: 'observer' })
|
|
223
|
+
expect(view.bindingsHere).toEqual([expect.objectContaining({ field: 'parentID', identifier: P.pack, status: 'pass' })])
|
|
224
|
+
expect((await findOn(P.battery2, view.attestationId))?.bindingsHere).toEqual([expect.objectContaining({ field: 'childEPCs', status: 'pass' })])
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
describe('the representative cases', () => {
|
|
229
|
+
it('shipping with separate owning and possessing roles: possession passes to the carrier, ownership to the retailer, and each is its own finding', async () => {
|
|
230
|
+
const event = {
|
|
231
|
+
type: 'ObjectEvent', ...base(7), epcList: [P.battery], action: 'OBSERVE', bizStep: 'shipping', disposition: 'in_transit', readPoint: { id: PLACE.factory },
|
|
232
|
+
sourceList: [{ type: 'owning_party', source: PARTY.maker }, { type: 'possessing_party', source: PARTY.maker }],
|
|
233
|
+
destinationList: [{ type: 'owning_party', destination: PARTY.retailer }, { type: 'possessing_party', destination: PARTY.carrier }],
|
|
234
|
+
}
|
|
235
|
+
const view = await issued(P.battery, { event, assertedRole: 'custodian', issuerParty: PARTY.carrier })
|
|
236
|
+
expect(view.findings!.possession).toMatchObject({ status: 'asserted', from: [PARTY.maker], to: [PARTY.carrier] })
|
|
237
|
+
expect(view.findings!.ownership).toMatchObject({ status: 'asserted', from: [PARTY.maker], to: [PARTY.retailer] })
|
|
238
|
+
// The configured custodian grant supports the issuer independently of the event's two party assertions.
|
|
239
|
+
expect(view.findings!.authority.status).toBe('supported')
|
|
240
|
+
// A custodian whose party the event does not name as possessing is refused before anything is signed.
|
|
241
|
+
const contradicted = await issue(P.battery, { event: { ...event, ...base(7) }, assertedRole: 'custodian', issuerParty: PARTY.repairer })
|
|
242
|
+
expect([contradicted.status, contradicted.body.error]).toEqual([409, 'claim-refused'])
|
|
243
|
+
expect(contradicted.body.description).toContain('x-party-role-contradicted')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('possession without ownership: receiving by a carrier asserts possession and says nothing of ownership', async () => {
|
|
247
|
+
const view = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(8), epcList: [P.battery], action: 'OBSERVE', bizStep: 'receiving', disposition: 'in_progress', readPoint: { id: PLACE.shop }, sourceList: [{ type: 'possessing_party', source: PARTY.carrier }], destinationList: [{ type: 'possessing_party', destination: PARTY.retailer }] }, assertedRole: 'observer' })
|
|
248
|
+
expect(view.findings!.possession.status).toBe('asserted')
|
|
249
|
+
expect(view.findings!.ownership.status).toBe('not-asserted')
|
|
250
|
+
const rows = findingRows(view.findings!)
|
|
251
|
+
expect(rows.find((r) => r.key === 'ownership')!.sentence).toContain('Nothing about ownership is inferred from possession')
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it('repair without a new product: the same item is observed, no passport is created and the passport is not written', async () => {
|
|
255
|
+
const before = await api.platform.store.listPassports()
|
|
256
|
+
const journal = JSON.stringify(await api.platform.store.getPassport(P.battery))
|
|
257
|
+
const view = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(9), epcList: [P.battery], action: 'OBSERVE', bizStep: 'repairing', disposition: 'active', readPoint: { id: PLACE.workshop } }, assertedRole: 'observer' })
|
|
258
|
+
expect(view.boundPassports).toEqual([P.battery])
|
|
259
|
+
expect((await api.platform.store.listPassports()).length).toBe(before.length)
|
|
260
|
+
// A claim is on its own rail: the passport's journal is as it was.
|
|
261
|
+
expect(JSON.stringify(await api.platform.store.getPassport(P.battery))).toBe(journal)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('a sensor observation keeps its decimal readings byte for byte', async () => {
|
|
265
|
+
const sensorElementList = [{ sensorMetadata: { time: '2026-03-10T04:00:00.000Z' }, sensorReport: [{ type: 'Temperature', value: 21.5, uom: 'CEL' }, { type: 'Temperature', minValue: -3.75, maxValue: 38.125, uom: 'CEL' }] }]
|
|
266
|
+
const view = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(10), epcList: [P.battery], action: 'OBSERVE', bizStep: 'sensor_reporting', readPoint: { id: PLACE.warehouse }, sensorElementList }, assertedRole: 'observer' })
|
|
267
|
+
expect((view.event as Json).sensorElementList).toEqual(sensorElementList)
|
|
268
|
+
expect((await api.get(`/api/lifecycle-claims/${ref(view.attestationId)}`)).text).toContain('"maxValue":38.125')
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
it('a class-level reference binds at class level only, and is never shown as the item taking part', async () => {
|
|
272
|
+
const view = await issued(P.pack, { event: { type: 'ObjectEvent', ...base(11), epcList: [P.pack], quantityList: [{ epcClass: classOf(P.battery), quantity: 2, uom: 'H87' }], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' }, assertedRole: 'observer' })
|
|
273
|
+
// Both batteries share the class, so both are bound at class level; neither is an item participant.
|
|
274
|
+
expect(view.itemParticipants).toEqual([P.pack])
|
|
275
|
+
const onBattery = await findOn(P.battery, view.attestationId)
|
|
276
|
+
expect(onBattery).toMatchObject({ participation: 'class' })
|
|
277
|
+
expect(onBattery!.itemParticipants).not.toContain(P.battery)
|
|
278
|
+
expect(onBattery!.bindingsHere).toEqual([expect.objectContaining({ field: 'quantityList', level: 'class', status: 'pass' })])
|
|
279
|
+
expect(participationLabel(onBattery!).sentence).toContain('does not say this item took part')
|
|
280
|
+
// A class written into a list of individual objects binds nothing, so an event that names only that is refused.
|
|
281
|
+
const classOnly = await issue(P.battery, { event: { type: 'ObjectEvent', ...base(11), epcList: [classOf(P.battery)], action: 'OBSERVE', bizStep: 'inspecting' }, assertedRole: 'observer' })
|
|
282
|
+
expect([classOnly.status, classOnly.body.error]).toEqual([409, 'event-binds-no-passport'])
|
|
283
|
+
expect(classOnly.body.unbound[0].reason).toContain('names a class of products inside a list of individual objects')
|
|
284
|
+
// The comparison itself, as the profiles package's identity rules read it.
|
|
285
|
+
expect(compareLifecycleProduct({ passportId: P.battery, identifier: classOf(P.battery), level: 'instance' }).status).toBe('fail')
|
|
286
|
+
expect(compareLifecycleProduct({ passportId: P.battery, identifier: sgtinOf(P.battery).replace('BAT-0001', 'BAT-9999'), level: 'instance' }).status).toBe('fail')
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('an imported event is signed with a source link back to the import, and never as the observer', async () => {
|
|
290
|
+
const event = { type: 'ObjectEvent', ...base(12), recordTime: '2026-03-12T10:00:00.000Z', epcList: [P.battery2], action: 'OBSERVE', bizStep: 'receiving', disposition: 'in_progress', 'example:dock': 'D4', readPoint: { id: PLACE.shop } }
|
|
291
|
+
const uploaded = await api.upload('/api/epcis/imports?requestId=lifecycle-import-1', utf8(JSON.stringify(epcisDocument([event]))))
|
|
292
|
+
expect(uploaded.status).toBe(201)
|
|
293
|
+
const record = uploaded.body.record as { importId: string; sha256: string; events: Array<{ pointer: string }> }
|
|
294
|
+
const imported = { importId: record.importId, pointer: record.events[0]!.pointer }
|
|
295
|
+
const asObserver = await issue(P.battery2, { imported, assertedRole: 'observer' })
|
|
296
|
+
expect([asObserver.status, asObserver.body.error]).toEqual([409, 'importer-not-observer'])
|
|
297
|
+
const view = await issued(P.battery2, { imported, assertedRole: 'authorised-reporter' })
|
|
298
|
+
expect(view.source).toMatchObject({ relation: 'imported', sourceDigest: record.sha256, eventPointer: imported.pointer })
|
|
299
|
+
expect(view.record?.importedFrom).toEqual(imported)
|
|
300
|
+
// The event is the one received, extension member and all, read under the document's own prefix.
|
|
301
|
+
expect(view.event).toEqual(event)
|
|
302
|
+
expect(view.findings!.eventStructure.status).toBe('pass')
|
|
303
|
+
// Signing it changed nothing in the exchange: the original is returned byte for byte.
|
|
304
|
+
expect((await api.get(`/api/epcis/imports/${ref(record.importId)}/original`)).text).toBe(JSON.stringify(epcisDocument([event])))
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('an error declaration is a new claim; the original is kept unchanged and shows as declared in error', async () => {
|
|
308
|
+
const original = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(13), epcList: [P.battery], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'non_conformant', readPoint: { id: PLACE.workshop } }, assertedRole: 'observer' })
|
|
309
|
+
const bytesBefore = (await api.get(`/api/lifecycle-claims/${ref(original.attestationId)}`)).text
|
|
310
|
+
const declaration = await issued(P.battery, { correctionOf: original.attestationId, reason: 'incorrect_data' })
|
|
311
|
+
expect(declaration.declaresError).toBe(true)
|
|
312
|
+
expect((declaration.event as Json).errorDeclaration).toMatchObject({ reason: 'incorrect_data' })
|
|
313
|
+
expect(correctionLabel(declaration)?.label).toBe('Declares an earlier event in error')
|
|
314
|
+
const reread = await findOn(P.battery, original.attestationId)
|
|
315
|
+
expect(reread!.findings!.correction).toMatchObject({ status: 'declared-in-error', detail: expect.objectContaining({ declaredBy: declaration.attestationId }) })
|
|
316
|
+
expect(correctionLabel(reread!)?.label).toBe('Declared in error')
|
|
317
|
+
expect(findingRows(reread!.findings!).find((r) => r.key === 'correction')!.sentence).toContain('kept exactly as it was signed')
|
|
318
|
+
expect((await api.get(`/api/lifecycle-claims/${ref(original.attestationId)}`)).text).toBe(bytesBefore)
|
|
319
|
+
// A second declaration of the declaration is refused.
|
|
320
|
+
expect((await issue(P.battery, { correctionOf: declaration.attestationId })).body.error).toBe('claim-is-declaration')
|
|
321
|
+
})
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
describe('discovery from verified claims', () => {
|
|
325
|
+
it('an anchor that names a passport the claim does not bind makes it no participant', async () => {
|
|
326
|
+
const view = await issued(P.battery, { event: { type: 'ObjectEvent', ...base(14), epcList: [P.battery], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' }, assertedRole: 'observer', submit: true })
|
|
327
|
+
await registry.anchorUnder(view.attestationId, P.bystander)
|
|
328
|
+
const reading = await claimsOf(P.bystander)
|
|
329
|
+
const found = reading.lifecycle.find((c) => c.attestationId === view.attestationId)
|
|
330
|
+
expect(found).toMatchObject({ foundBy: ['anchor'], held: true, participation: 'not-established', bindingsHere: [] })
|
|
331
|
+
expect(found!.findings!.productBinding).toMatchObject({ status: 'fail', reasonCode: 'subject-mismatch' })
|
|
332
|
+
expect(found!.findings!.anchorCommitment.status).toBe('fail')
|
|
333
|
+
expect(participationLabel(found!).sentence).toContain("An anchor's subject alone never makes a passport part of an event")
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it('finds a correction from registry bytes with a cold or partially populated store and reports incomplete retrieval', async () => {
|
|
337
|
+
const original = await issued(P.pack, { event: { type: 'ObjectEvent', ...base(15), epcList: [P.pack], action: 'OBSERVE', bizStep: 'inspecting' }, assertedRole: 'observer', submit: true })
|
|
338
|
+
const replacement = await issued(P.pack, { event: { type: 'ObjectEvent', ...base(15), epcList: [P.pack], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' }, assertedRole: 'observer', submit: true })
|
|
339
|
+
const correction = await issued(P.pack, { correctionOf: original.attestationId, reason: 'incorrect_data', correctiveEventIDs: [replacement.eventId], submit: true })
|
|
340
|
+
const mongo = await startMongo()
|
|
341
|
+
onTestFinished(() => mongo.stop())
|
|
342
|
+
const store = new MongoStore(mongo.database())
|
|
343
|
+
await store.init()
|
|
344
|
+
const read = async () => (await readPassportClaims(P.pack, { store, index: api.platform.index, registry })).lifecycle
|
|
345
|
+
const checkOriginal = async () => {
|
|
346
|
+
const views = await read()
|
|
347
|
+
const view = views.find((v) => v.attestationId === original.attestationId)
|
|
348
|
+
expect(view?.findings?.correction).toMatchObject({ status: 'declared-in-error', detail: { correctiveClaims: [replacement.attestationId] } })
|
|
349
|
+
expect(view?.relations.filter((r) => r.relation === 'error-declaration')).toHaveLength(1)
|
|
350
|
+
}
|
|
351
|
+
await checkOriginal()
|
|
352
|
+
const local = (await api.platform.store.listClaims({ passportId: P.pack })).find((record) => record.id === original.record!.id)!
|
|
353
|
+
await store.saveClaim(local)
|
|
354
|
+
await checkOriginal()
|
|
355
|
+
// A cached record can refer to the bytes of another valid claim. Recover the exact bytes by identifier.
|
|
356
|
+
const declarationRecord = (await api.platform.store.listClaims({ passportId: P.pack })).find((record) => record.id === correction.record!.id) as EpcisLifecycleClaimRecord
|
|
357
|
+
await store.saveClaim({ ...declarationRecord, bytes: registry.held.get(replacement.attestationId)! })
|
|
358
|
+
await checkOriginal()
|
|
359
|
+
const bytes = registry.held.get(correction.attestationId)!
|
|
360
|
+
try {
|
|
361
|
+
registry.held.delete(correction.attestationId)
|
|
362
|
+
const view = (await read()).find((v) => v.attestationId === original.attestationId)
|
|
363
|
+
expect(view?.findings?.correction).toMatchObject({ status: 'unknown', reasonCode: 'x-related-incomplete' })
|
|
364
|
+
} finally {
|
|
365
|
+
registry.held.set(correction.attestationId, bytes)
|
|
366
|
+
}
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
it('reports a bounded local read as incomplete and keeps one copy of repeated secured bytes', async () => {
|
|
370
|
+
const view = await issued(P.moduleA, { event: { type: 'ObjectEvent', ...base(16), epcList: [P.moduleA], action: 'OBSERVE' }, assertedRole: 'observer' })
|
|
371
|
+
const record = (await api.platform.store.listClaims({ attestationIds: [view.attestationId] }))[0]!
|
|
372
|
+
const store = new MemoryStore()
|
|
373
|
+
for (let i = 0; i < 501; i += 1) await store.saveClaim({ ...record, id: `receipt-${i}` })
|
|
374
|
+
const reading = await readPassportClaims(P.moduleA, { store, index: api.platform.index, registry })
|
|
375
|
+
expect(reading.discovery.relatedClaims).toBe('incomplete')
|
|
376
|
+
const matches = reading.lifecycle.filter((v) => v.attestationId === view.attestationId)
|
|
377
|
+
expect(matches).toHaveLength(1)
|
|
378
|
+
expect(matches[0]?.findings?.correction).toMatchObject({ status: 'unknown', reasonCode: 'x-related-incomplete' })
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
it('reads an exact-size proof response and stops an over-budget response without a content length', async () => {
|
|
382
|
+
const json = JSON.stringify({ securedBytes: 'example' })
|
|
383
|
+
await expect(boundedJson(new Response(json), Buffer.byteLength(json))).resolves.toEqual({ securedBytes: 'example' })
|
|
384
|
+
await expect(boundedJson(new Response(json), Buffer.byteLength(json) - 1)).rejects.toThrow(/reader limit/)
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
it('reads successive anchor pages and keeps the first page when a later lookup is unavailable', async () => {
|
|
388
|
+
const create = async (passportId = P.paged) => await issued(passportId, { event: { type: 'ObjectEvent', ...base(16), epcList: [passportId], action: 'OBSERVE', bizStep: 'inspecting' }, assertedRole: 'observer', submit: true })
|
|
389
|
+
const first = await create()
|
|
390
|
+
const second = await create()
|
|
391
|
+
await create(P.pack)
|
|
392
|
+
const store = new MemoryStore()
|
|
393
|
+
const read = () => readPassportClaims(P.paged, { store, index: api.platform.index, registry })
|
|
394
|
+
const fetchNormally = globalThis.fetch
|
|
395
|
+
let interrupt = false
|
|
396
|
+
let staleSelector = false
|
|
397
|
+
let continuations = 0
|
|
398
|
+
const fetchPage = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
399
|
+
if (String(url) === api.platform.index.url + '/lookup' && typeof init?.body === 'string') {
|
|
400
|
+
const question = JSON.parse(init.body)
|
|
401
|
+
if (interrupt && question.query.attestationId != null) return new Response(null, { status: 503 })
|
|
402
|
+
if (question.query.subject === P.paged) {
|
|
403
|
+
if (staleSelector) question.query.subject = P.pack
|
|
404
|
+
if (question.query.after != null) {
|
|
405
|
+
continuations += 1
|
|
406
|
+
if (interrupt) return new Response(null, { status: 503 })
|
|
407
|
+
}
|
|
408
|
+
question.query.limit = 1
|
|
409
|
+
return fetchNormally(url, { ...init, body: JSON.stringify(question) })
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return fetchNormally(url, init)
|
|
413
|
+
})
|
|
414
|
+
try {
|
|
415
|
+
const all = await read()
|
|
416
|
+
expect(all.discovery.index).toBe('asked')
|
|
417
|
+
expect(all.lifecycle.map((v) => v.attestationId)).toEqual(expect.arrayContaining([first.attestationId, second.attestationId]))
|
|
418
|
+
expect(continuations).toBeGreaterThanOrEqual(2)
|
|
419
|
+
interrupt = true
|
|
420
|
+
const partial = await read()
|
|
421
|
+
expect(partial.discovery).toMatchObject({ index: 'partial', indexDetail: expect.stringContaining('503') })
|
|
422
|
+
expect(partial.lifecycle).toHaveLength(1)
|
|
423
|
+
expect(partial.lifecycle[0]?.findings?.anchorCommitment.status).toBe('pass')
|
|
424
|
+
expect(partial.lifecycle[0]?.findings?.correction).toMatchObject({ status: 'unknown', reasonCode: 'x-related-incomplete' })
|
|
425
|
+
staleSelector = true
|
|
426
|
+
interrupt = false
|
|
427
|
+
const stale = await read()
|
|
428
|
+
expect(stale.discovery).toMatchObject({ relatedClaims: 'incomplete', indexDetail: expect.stringContaining('selector') })
|
|
429
|
+
expect(stale.lifecycle).toHaveLength(0)
|
|
430
|
+
} finally {
|
|
431
|
+
fetchPage.mockRestore()
|
|
432
|
+
}
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
it('a claim held only by the registry is found by its anchor and read from the registry\'s bytes', async () => {
|
|
436
|
+
const view = await issued(P.moduleA, { event: { type: 'ObjectEvent', ...base(15), epcList: [P.moduleA], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' }, assertedRole: 'observer', submit: true })
|
|
437
|
+
// This application forgets it; the registry and the index still hold it.
|
|
438
|
+
const store = api.platform.store as unknown as { claims: Map<string, unknown> }
|
|
439
|
+
store.claims.delete(view.record!.id)
|
|
440
|
+
const found = await findOn(P.moduleA, view.attestationId)
|
|
441
|
+
expect(found).toMatchObject({ foundBy: ['anchor'], held: true, participation: 'item' })
|
|
442
|
+
expect(found!.findings!.anchorCommitment.status).toBe('pass')
|
|
443
|
+
expect(found!.record).toBeUndefined()
|
|
444
|
+
// The bytes came from the member the registry contract gives them, in an answer with every member the contract requires.
|
|
445
|
+
const proof = (await (await fetch(`${registry.url}/attestations/${ref(view.attestationId)}/proof`)).json()) as Json
|
|
446
|
+
expect(Object.keys(proof)).toEqual(expect.arrayContaining(['attestationId', 'attestation', 'claimRelations', 'canonical', 'digest', 'algorithm', 'anchored']))
|
|
447
|
+
expect(`urn:sha256:${Utils.toHex(Hash.sha256(Utils.toArray(proof.securedBytes as string, 'utf8')))}`).toBe(view.attestationId)
|
|
448
|
+
expect(proof).not.toHaveProperty('envelope')
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
it('reports a registry refusal by the outcome and the first issue the registry contract gives it', async () => {
|
|
452
|
+
const view = await issued(P.moduleB, { event: { type: 'ObjectEvent', ...base(15), epcList: [P.moduleB], action: 'OBSERVE', bizStep: 'inspecting', disposition: 'conformant' }, assertedRole: 'observer' })
|
|
453
|
+
const record = (await api.platform.store.listClaims({ passportId: P.moduleB })).find((c) => c.id === view.record!.id) as EpcisLifecycleClaimRecord
|
|
454
|
+
// Sent from a store of its own, so the application's own record stays as it was signed.
|
|
455
|
+
const claims = new claimsModule.Claims({ store: new MemoryStore(), registry: { url: registry.url } })
|
|
456
|
+
// Changed after signing: the registry's own verification refuses the claim.
|
|
457
|
+
const altered = await claims.submit({ ...record, bytes: record.bytes.replace('"inspecting"', '"repairing"') })
|
|
458
|
+
expect(altered.registry).toEqual({ url: registry.url, status: 422, accepted: false, detail: 'invalid: the claim does not verify' })
|
|
459
|
+
// Sent for a passport the claim does not bind.
|
|
460
|
+
const unbound = await claims.submit({ ...record, passportId: P.bystander })
|
|
461
|
+
expect(unbound.registry).toEqual({ url: registry.url, status: 422, accepted: false, detail: `invalid: subject mismatch: the claim does not bind ${P.bystander}` })
|
|
462
|
+
// A refusal that is not a verification outcome keeps its error.
|
|
463
|
+
const gone = await new claimsModule.Claims({ store: new MemoryStore(), registry: { url: `${registry.url}/nowhere` } }).submit({ ...record })
|
|
464
|
+
expect(gone.registry).toEqual({ url: `${registry.url}/nowhere`, status: 404, accepted: false, detail: 'not_found' })
|
|
465
|
+
expect(registry.held.has(view.attestationId)).toBe(false)
|
|
466
|
+
})
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
describe('the cutover from the four categories', () => {
|
|
470
|
+
it('refuses a request for a four-category claim and signs nothing', async () => {
|
|
471
|
+
const count = (await api.platform.store.listClaims()).length
|
|
472
|
+
for (const eventType of ['Origin', 'Transfer', 'Transformation', 'Disposition']) {
|
|
473
|
+
const answer = await issue(P.battery, { eventType })
|
|
474
|
+
expect([answer.status, answer.body.error]).toEqual([400, 'four-category-claims-retired'])
|
|
475
|
+
}
|
|
476
|
+
expect((await api.platform.store.listClaims()).length).toBe(count)
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
it('leaves no path from the claim route to the four-category claim: no event-type list, no native signing', () => {
|
|
480
|
+
expect(Object.keys(claimsModule)).not.toContain('EVENT_TYPES')
|
|
481
|
+
expect(Object.keys(claimsModule)).toEqual(expect.arrayContaining(['Claims', 'ASSERTED_ROLES']))
|
|
482
|
+
const src = (file: string): string => readFileSync(join(import.meta.dirname, '..', 'src', file), 'utf8')
|
|
483
|
+
for (const file of ['claims.ts', 'server.ts', 'lifecycle.ts']) {
|
|
484
|
+
expect(src(file), file).not.toMatch(/\bsignLifecycleClaim\b|\bLifecycleEventType\b|'Origin'|'Disposition'|mapOperation|eventMappings/)
|
|
485
|
+
}
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
it('writes no claim for a passport operation: an update and a hand-on leave the claims as they were', async () => {
|
|
489
|
+
const before = (await api.platform.store.listClaims({ passportId: P.bystander })).length
|
|
490
|
+
expect((await api.post(`/api/passports/${ref(P.bystander)}/update`, { payload: samplePayload('general@2', true) })).status).toBe(200)
|
|
491
|
+
expect((await api.post(`/api/passports/${ref(P.bystander)}/offer`, { terms: { word: 'Sold' } })).status).toBe(200)
|
|
492
|
+
expect((await api.platform.store.listClaims({ passportId: P.bystander })).length).toBe(before)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
it('refuses an event that names none of the passports, and one that does not name the passport it is issued from', async () => {
|
|
496
|
+
const none = await issue(P.battery, { event: { type: 'ObjectEvent', ...base(16), epcList: ['urn:epc:id:sgtin:9521234.012345.NOT-HERE'], action: 'OBSERVE' }, assertedRole: 'observer' })
|
|
497
|
+
expect([none.status, none.body.error]).toEqual([409, 'event-binds-no-passport'])
|
|
498
|
+
const other = await issue(P.battery, { event: { type: 'ObjectEvent', ...base(16), epcList: [P.pack], action: 'OBSERVE' }, assertedRole: 'observer' })
|
|
499
|
+
expect([other.status, other.body.error]).toEqual([409, 'passport-not-bound'])
|
|
500
|
+
const noRole = await issue(P.battery, { event: { type: 'ObjectEvent', ...base(16), epcList: [P.battery], action: 'OBSERVE' } })
|
|
501
|
+
expect([noRole.status, noRole.body.error]).toEqual([400, 'asserted-role-required'])
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
it('still reads a historical native claim under its own rules, labelled as historical', async () => {
|
|
505
|
+
const issuer = api.platform.parties.member('before-the-move')
|
|
506
|
+
const tip = (await api.platform.store.getPassport(P.bystander))!.states[0]!
|
|
507
|
+
const claim: LifecycleClaim = { claimFormat: 'dpp-lifecycle-v1', passportId: P.bystander, recordId: `${tip.txid}:${tip.outputIndex}`, eventType: 'Disposition', timestamp: '2026-03-01T00:00:00Z', issuer: issuer.did, issuerKeyId: 'before-the-move', profile: 'general', profile_version: 2 }
|
|
508
|
+
const signed = await signLifecycleClaim(claim, issuer.wallet)
|
|
509
|
+
// A record as this application wrote it before the move: no claimFormat member of its own.
|
|
510
|
+
await api.platform.store.saveClaim({ id: 'claim-historical-1', passportId: P.bystander, issuer: signed.issuer, issuedBy: issuer.name, claim: signed, createdAt: claim.timestamp })
|
|
511
|
+
const reading = await claimsOf(P.bystander)
|
|
512
|
+
expect(reading.historical).toEqual([expect.objectContaining({ claimFormat: 'dpp-lifecycle-v1', historical: true, id: 'claim-historical-1', signature: 'verified', claim: signed })])
|
|
513
|
+
expect(HISTORICAL_LABEL).toBe('Historical native claim')
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
describe('the words the page uses', () => {
|
|
518
|
+
it('reports unknown as unknown and never words an anchor as proof of the event, of ownership or of compliance', async () => {
|
|
519
|
+
const reading = await claimsOf(P.pack)
|
|
520
|
+
const anchored = reading.lifecycle.find((c) => c.findings?.anchorCommitment.status === 'pass')!
|
|
521
|
+
const rows = findingRows(anchored.findings!)
|
|
522
|
+
expect(rows.map((r) => r.key)).toEqual(['eventStructure', 'eventSemantics', 'productBinding', 'signature', 'authority', 'possession', 'ownership', 'anchorCommitment', 'inclusion', 'correction'])
|
|
523
|
+
expect(rows.find((r) => r.key === 'anchorCommitment')!.sentence).toMatch(/not that the event happened, not who owns the product, and not compliance/)
|
|
524
|
+
expect(rows.find((r) => r.key === 'inclusion')).toMatchObject({ status: 'unknown', tone: 'unknown' })
|
|
525
|
+
expect(rows.find((r) => r.key === 'inclusion')!.sentence).toMatch(/^Unknown/)
|
|
526
|
+
expect(rows.find((r) => r.key === 'authority')).toMatchObject({ status: 'supported', tone: 'pass' })
|
|
527
|
+
expect(LIFECYCLE_NOTICE).toContain('Neither proves the event happened')
|
|
528
|
+
for (const row of rows) expect(row.sentence).not.toMatch(/\bproves? (the event|ownership|compliance)\b/)
|
|
529
|
+
})
|
|
530
|
+
|
|
531
|
+
it('builds the event the form describes, with no action on a transformation and nothing the member did not enter', () => {
|
|
532
|
+
const form = { ...emptyEventForm(P.battery, new Date('2026-03-20T10:00:00.000Z'), 'urn:uuid:6c000000-0000-4000-8000-0000000000ff'), type: 'TransformationEvent' as const, inputEPCList: `${P.moduleA}\n${P.moduleB}`, outputEPCList: P.pack, bizStep: 'commissioning', outputQuantityList: `${classOf(P.pack)} 2 H87` }
|
|
533
|
+
expect(eventFromForm(form)).toEqual({ event: { type: 'TransformationEvent', eventTime: '2026-03-20T10:00:00.000Z', eventTimeZoneOffset: '+00:00', eventID: 'urn:uuid:6c000000-0000-4000-8000-0000000000ff', inputEPCList: [P.moduleA, P.moduleB], outputEPCList: [P.pack], outputQuantityList: [{ epcClass: classOf(P.pack), quantity: 2, uom: 'H87' }], bizStep: 'commissioning' } })
|
|
534
|
+
const shipping = { ...emptyEventForm(P.battery, new Date('2026-03-20T10:00:00.000Z'), 'urn:uuid:6c000000-0000-4000-8000-0000000000fe'), bizStep: 'shipping', sourceList: `owning_party ${PARTY.maker}\npossessing_party ${PARTY.maker}`, destinationList: `possessing_party ${PARTY.carrier}` }
|
|
535
|
+
expect(eventFromForm(shipping)).toMatchObject({ event: { action: 'OBSERVE', epcList: [P.battery], sourceList: [{ type: 'owning_party', source: PARTY.maker }, { type: 'possessing_party', source: PARTY.maker }], destinationList: [{ type: 'possessing_party', destination: PARTY.carrier }] } })
|
|
536
|
+
expect(eventFromForm({ ...shipping, sensorElementList: '{not json' })).toEqual({ problems: ['the sensor elements are not JSON'] })
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
it('issues the event the form builds, through the API', async () => {
|
|
540
|
+
const form = { ...emptyEventForm(P.battery2, new Date('2026-03-21T10:00:00.000Z')), bizStep: 'inspecting', disposition: 'conformant' }
|
|
541
|
+
const built = eventFromForm(form)
|
|
542
|
+
if (!('event' in built)) throw new Error(built.problems.join('; '))
|
|
543
|
+
const view = await issued(P.battery2, { event: built.event, assertedRole: 'observer' })
|
|
544
|
+
expect(view.event).toEqual(built.event)
|
|
545
|
+
})
|
|
546
|
+
})
|