@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,547 @@
|
|
|
1
|
+
// Passports under the two sector profiles the profiles package ships,
|
|
2
|
+
// eu-battery@2 and eu-textile@2, end to end with no wallet, funds or
|
|
3
|
+
// network: a complete product document goes in, the writer validates it,
|
|
4
|
+
// splits it and signs only the public part, the restricted part is sealed
|
|
5
|
+
// as every owner tier is, and the reader checks what it reads against the
|
|
6
|
+
// passport that carries it. The documents are the starter's own examples,
|
|
7
|
+
// all invented and under the GS1 demonstration prefix.
|
|
8
|
+
import http from 'node:http'
|
|
9
|
+
import https from 'node:https'
|
|
10
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
11
|
+
import { Utils } from '@bsv/sdk'
|
|
12
|
+
import { findDppOutputs, verifyOwnerBlob } from '@bsv/dpp-protocol'
|
|
13
|
+
import { BUNDLED_BINDINGS, PUBLIC_PAYLOAD_MAX_BYTES, type BindingProfile } from '@bsv/dpp-profiles'
|
|
14
|
+
import type { BoundProfiles, ViewCheck } from '../src/bound-profiles.js'
|
|
15
|
+
import { loadConfig } from '../src/config.js'
|
|
16
|
+
import { mintGtin, mintPassportId } from '../src/identifiers.js'
|
|
17
|
+
import type { IndexClient } from '../src/index-client.js'
|
|
18
|
+
import type { Party } from '../src/parties.js'
|
|
19
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
20
|
+
import { readPassport } from '../src/reader.js'
|
|
21
|
+
import { DEMONSTRATION_NOTICE, samplePayload } from '../src/profiles.js'
|
|
22
|
+
import { sectorExamples } from '../src/sector-examples.js'
|
|
23
|
+
import { OWNER_DATA_PROTOCOL, WriteRefused, Writer } from '../src/writer.js'
|
|
24
|
+
|
|
25
|
+
type Json = Record<string, unknown>
|
|
26
|
+
|
|
27
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
28
|
+
const policy = { host: config.passportHost, prefix: config.gs1Prefix }
|
|
29
|
+
const brandId = 'brand-sector-1'
|
|
30
|
+
let platform: Platform
|
|
31
|
+
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
platform = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
afterAll(async () => {
|
|
37
|
+
await platform.close()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const bindingOf = (profile: string): BindingProfile => {
|
|
41
|
+
const bound = platform.profiles.get(profile)
|
|
42
|
+
if (bound == null) throw new Error(`${profile} is not registered`)
|
|
43
|
+
return bound
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The starter's example for a sector, as a complete document, under a serial of the test's own so every test writes a fresh passport. */
|
|
47
|
+
function exampleFor(profile: string, serial: string): { passportId: string; itemReference: string; product: Json } {
|
|
48
|
+
const example = sectorExamples(bindingOf(profile), policy)[0]
|
|
49
|
+
const passportId = mintPassportId(policy, example.itemReference, serial)
|
|
50
|
+
const product = JSON.parse(JSON.stringify(example.product).replaceAll(example.serial, serial)) as Json
|
|
51
|
+
return { passportId, itemReference: example.itemReference, product }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A brand party whose wallet counts the signatures it makes, so a test can show a refusal came before any. */
|
|
55
|
+
function countingBrand(): { brand: Party; signatures: () => number } {
|
|
56
|
+
const brand = platform.parties.brand(brandId)
|
|
57
|
+
let count = 0
|
|
58
|
+
const sign = brand.wallet.createSignature.bind(brand.wallet)
|
|
59
|
+
brand.wallet.createSignature = (async (...args: Parameters<typeof sign>) => {
|
|
60
|
+
count++
|
|
61
|
+
return await sign(...args)
|
|
62
|
+
}) as typeof brand.wallet.createSignature
|
|
63
|
+
return { brand, signatures: () => count }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const refusal = async (work: Promise<unknown>): Promise<WriteRefused> => {
|
|
67
|
+
try {
|
|
68
|
+
await work
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
if (cause instanceof WriteRefused) return cause
|
|
71
|
+
throw cause
|
|
72
|
+
}
|
|
73
|
+
throw new Error('the write was not refused')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const nothingWritten = async (passportId: string): Promise<void> => {
|
|
77
|
+
expect(await platform.store.getPassport(passportId)).toBeUndefined()
|
|
78
|
+
expect(await platform.index.lineage(passportId)).toEqual([])
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe('managed transfers of a restricted product', () => {
|
|
82
|
+
it('delivers the same product under each successive recipient key and preserves the final ciphertext on retirement', async () => {
|
|
83
|
+
const profile = 'eu-battery@2'
|
|
84
|
+
const { passportId, product } = exampleFor(profile, 'BAT-HANDOVER')
|
|
85
|
+
const brand = platform.parties.brand(brandId)
|
|
86
|
+
const issued = await platform.writer.issue({ brandId, brand, passportId, profile, product })
|
|
87
|
+
let record = issued.record
|
|
88
|
+
let holder = brand
|
|
89
|
+
const hashes = new Set([issued.state.payloadOwnerHash])
|
|
90
|
+
for (let i = 0; i < 2; i++) {
|
|
91
|
+
const { offer, claimCode } = await platform.custody.offer({ record, holder, terms: { word: 'Passed on' } })
|
|
92
|
+
const accepted = await platform.custody.accept({ requestId: offer.requestId, claimCode })
|
|
93
|
+
record = (await platform.store.getPassport(passportId))!
|
|
94
|
+
holder = platform.parties.recipient(offer.requestId)
|
|
95
|
+
const read = await platform.readAuthorised(record, holder)
|
|
96
|
+
expect(read.authorisedView.status).toBe('pass')
|
|
97
|
+
expect(read.ownerTier.status).toBe('pass')
|
|
98
|
+
expect(read.product).toEqual(product)
|
|
99
|
+
const tip = (await platform.index.lineage(passportId)).at(-1)!
|
|
100
|
+
expect(tip.id('hex')).toBe(accepted.transferTxid)
|
|
101
|
+
const state = findDppOutputs(tip)[0].state
|
|
102
|
+
expect(hashes.has(state.payloadOwnerHash)).toBe(false)
|
|
103
|
+
hashes.add(state.payloadOwnerHash)
|
|
104
|
+
expect(state.payloadPublic).toBe(issued.state.payloadPublic)
|
|
105
|
+
}
|
|
106
|
+
const beforeRetirement = record.states.at(-1)!.ownerTier
|
|
107
|
+
const retired = await platform.writer.retire({ record, actor: holder, reason: 'End of the demonstration' })
|
|
108
|
+
expect(retired.entry.ownerTier).toEqual(beforeRetirement)
|
|
109
|
+
expect((await platform.readAuthorised(retired.record, holder)).product).toEqual(product)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
describe('start-up', () => {
|
|
114
|
+
it('registers the two bundled sector bindings under the shipped trust list, with the engine built once', () => {
|
|
115
|
+
expect(platform.profiles.engineProblem).toBeUndefined()
|
|
116
|
+
expect(platform.profiles.refusals).toEqual([])
|
|
117
|
+
expect(platform.profiles.list().map((p) => [p.profile, p.bindingDigest])).toEqual(BUNDLED_BINDINGS.map((b) => [b.profile, b.bindingDigest]))
|
|
118
|
+
expect(platform.profiles.engines.jsonLd).toBeDefined()
|
|
119
|
+
expect(platform.profiles.engines.shacl?.capabilities).toContain('shacl-sparql-constraints')
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it.each([
|
|
123
|
+
['eu-battery@2', 'eubat:hasBatteryState'],
|
|
124
|
+
['eu-textile@2', 'eutex:hasWaterUsage'],
|
|
125
|
+
])('uses the current %s by default and separates public and authorised readings', async (profile, restricted) => {
|
|
126
|
+
const selected = await openPlatform({
|
|
127
|
+
config: loadConfig({ LIVE_PUBLISHING: 'false', GS1_PREFIX: '952', PASSPORT_HOST: policy.host }),
|
|
128
|
+
mode: 'test', log: () => {},
|
|
129
|
+
})
|
|
130
|
+
try {
|
|
131
|
+
expect(selected.profiles.list().map(entry => entry.profile).sort()).toEqual(BUNDLED_BINDINGS.map(entry => entry.profile).sort())
|
|
132
|
+
const bound = selected.profiles.get(profile)!
|
|
133
|
+
const example = sectorExamples(bound, policy)[0]!
|
|
134
|
+
expect(example.product).toHaveProperty(restricted)
|
|
135
|
+
const brand = selected.parties.brand(brandId)
|
|
136
|
+
await selected.writer.issue({ brandId, brand, passportId: example.passportId, profile, product: example.product })
|
|
137
|
+
const record = (await selected.store.getPassport(example.passportId))!
|
|
138
|
+
const reading = await selected.read(example.passportId)
|
|
139
|
+
expect(reading.product?.profile).toBe(profile)
|
|
140
|
+
expect(reading.payloadChecks[0].publicView.status).toBe('pass')
|
|
141
|
+
expect(JSON.stringify(reading)).not.toContain(restricted)
|
|
142
|
+
const ownerReading = await selected.readAuthorised(record, brand)
|
|
143
|
+
expect(ownerReading.authorisedView.status).toBe('pass')
|
|
144
|
+
expect(ownerReading.restrictedProduct?.[restricted]).toEqual(example.product[restricted])
|
|
145
|
+
} finally {
|
|
146
|
+
await selected.close()
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('validates without touching the network', async () => {
|
|
151
|
+
const spies = [vi.spyOn(globalThis, 'fetch'), vi.spyOn(http, 'request'), vi.spyOn(http, 'get'), vi.spyOn(https, 'request'), vi.spyOn(https, 'get')]
|
|
152
|
+
try {
|
|
153
|
+
for (const profile of ['eu-battery@2', 'eu-textile@2']) {
|
|
154
|
+
const { passportId, product } = exampleFor(profile, 'NO-NETWORK-1')
|
|
155
|
+
const bound = bindingOf(profile)
|
|
156
|
+
const prepared = await platform.profiles.prepare({ profile: bound, product, passportId })
|
|
157
|
+
if (!prepared.ok) throw new Error(prepared.detail)
|
|
158
|
+
expect((await platform.profiles.validatePublic({ profile: bound.id, profileVersion: bound.version, payloadPublic: prepared.payloadPublic, passportId })).status).toBe('pass')
|
|
159
|
+
expect((await platform.profiles.validateAuthorised({ profile: bound.id, profileVersion: bound.version, payloadPublic: prepared.payloadPublic, passportId, restrictedProduct: prepared.restrictedProduct })).status).toBe('pass')
|
|
160
|
+
}
|
|
161
|
+
for (const spy of spies) expect(spy).not.toHaveBeenCalled()
|
|
162
|
+
} finally {
|
|
163
|
+
for (const spy of spies) spy.mockRestore()
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
describe.each([
|
|
169
|
+
{ profile: 'eu-battery@2', serial: 'BAT-RT-0001', restricted: 'eubat:hasBatteryState', open: 'eubat:batteryModelIdentifier', nested: (product: Json) => ((product['eubat:hasBatteryState'] as Json)['oea:hasResult'] as Json[])[0]['oea:hasMeasuredValue'], expected: { type: 'gs1:QuantitativeValue', 'gs1:value': '98.50', 'gs1:unitCode': 'P1' } },
|
|
170
|
+
{ profile: 'eu-textile@2', serial: 'TEX-RT-0001', restricted: 'eutex:hasWaterUsage', open: 'gs1:textileMaterial', nested: (product: Json) => (product['gs1:textileMaterial'] as Json[])[0]['gs1:textileMaterialPercentage'], expected: { '@value': '88', '@type': 'xsd:decimal' } },
|
|
171
|
+
])('a $profile passport, written and read back', ({ profile, serial, restricted, open, nested, expected }) => {
|
|
172
|
+
let passportId: string
|
|
173
|
+
let product: Json
|
|
174
|
+
|
|
175
|
+
it('signs exactly the public payload prepareBoundPayload returned, and seals the restricted part as an owner tier', async () => {
|
|
176
|
+
;({ passportId, product } = exampleFor(profile, serial))
|
|
177
|
+
const bound = bindingOf(profile)
|
|
178
|
+
const brand = platform.parties.brand(brandId)
|
|
179
|
+
const outcome = await platform.writer.issue({ brandId, brand, passportId, profile, product })
|
|
180
|
+
expect(outcome.entry.index).toBe('admitted')
|
|
181
|
+
expect(outcome.record.profile).toBe(profile)
|
|
182
|
+
|
|
183
|
+
// The same document prepared again gives the same text: that text, byte for byte, is what was signed and journalled.
|
|
184
|
+
const prepared = await platform.profiles.prepare({ profile: bound, product, passportId, notice: DEMONSTRATION_NOTICE })
|
|
185
|
+
if (!prepared.ok) throw new Error(prepared.detail)
|
|
186
|
+
expect(outcome.state.payloadPublic).toBe(prepared.payloadPublic)
|
|
187
|
+
expect(outcome.entry.payloadPublic).toBe(prepared.payloadPublic)
|
|
188
|
+
const onChain = findDppOutputs((await platform.index.lineage(passportId)).at(-1)!)[0].state
|
|
189
|
+
expect(onChain.payloadPublic).toBe(prepared.payloadPublic)
|
|
190
|
+
expect(onChain.passportId).toBe(passportId)
|
|
191
|
+
|
|
192
|
+
// The public payload carries the envelope and public properties only.
|
|
193
|
+
const envelope = JSON.parse(onChain.payloadPublic) as { notice: string; profile: string; profile_version: number; profile_binding_sha256: string; product: Json }
|
|
194
|
+
expect(Object.keys(envelope)).toEqual(['notice', 'profile', 'profile_version', 'profile_binding_sha256', 'product'])
|
|
195
|
+
expect(envelope.profile_binding_sha256).toBe(bound.bindingDigest)
|
|
196
|
+
expect(Object.hasOwn(envelope.product, open)).toBe(true)
|
|
197
|
+
expect(Object.hasOwn(envelope.product, restricted)).toBe(false)
|
|
198
|
+
for (const name of Object.keys(envelope.product)) expect(bound.binding.access?.public).toContain(name)
|
|
199
|
+
|
|
200
|
+
// The restricted part went through the owner-tier seal: field 11 is the hash of the stored ciphertext, and the brand's own key opens it.
|
|
201
|
+
const tier = outcome.entry.ownerTier!
|
|
202
|
+
const ciphertext = Utils.toArray(tier.ciphertext, 'base64') as number[]
|
|
203
|
+
expect(tier.hash).toBe(onChain.payloadOwnerHash)
|
|
204
|
+
expect(verifyOwnerBlob(ciphertext, onChain.payloadOwnerHash)).toBe(true)
|
|
205
|
+
const { plaintext } = await brand.wallet.decrypt({ ciphertext, protocolID: OWNER_DATA_PROTOCOL, keyID: passportId, counterparty: 'self' })
|
|
206
|
+
const sealed = JSON.parse(Utils.toUTF8(plaintext)) as Json
|
|
207
|
+
expect(sealed).toEqual(prepared.restrictedProduct)
|
|
208
|
+
expect(Object.hasOwn(sealed, restricted)).toBe(true)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('reads back with the public view checked for the state, inside the report', async () => {
|
|
212
|
+
const reading = await platform.read(passportId)
|
|
213
|
+
expect(reading.checks.find((c) => c.name === 'schema')?.status).toBe('pass')
|
|
214
|
+
expect(reading.payloadChecks).toHaveLength(1)
|
|
215
|
+
const view = reading.payloadChecks[0].publicView
|
|
216
|
+
expect(view).toMatchObject({ view: 'public', status: 'pass' })
|
|
217
|
+
expect(view.steps.map((s) => [s.step, s.status])).toEqual([
|
|
218
|
+
['envelope', 'pass'],
|
|
219
|
+
['binding', 'pass'],
|
|
220
|
+
['access', 'pass'],
|
|
221
|
+
['json-ld-expand', 'pass'],
|
|
222
|
+
['shacl', 'pass'],
|
|
223
|
+
['passport-identity', 'pass'],
|
|
224
|
+
])
|
|
225
|
+
// A public pass is worded as one, and never as a statement about the restricted part.
|
|
226
|
+
expect(view.summary).toMatch(/says nothing about restricted data/)
|
|
227
|
+
expect(reading.product?.profile).toBe(profile)
|
|
228
|
+
expect(Object.hasOwn(reading.product!.publicProduct, restricted)).toBe(false)
|
|
229
|
+
expect(reading.product?.access?.public).toContain(open)
|
|
230
|
+
expect(JSON.stringify(reading)).not.toContain(restricted)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('gives the holder the authorised view, after the protocol\'s owner-tier check, with every nested value exactly as written', async () => {
|
|
234
|
+
const record = (await platform.store.getPassport(passportId))!
|
|
235
|
+
const authorised = await platform.readAuthorised(record, platform.parties.brand(brandId))
|
|
236
|
+
expect(authorised.ownerTier.status).toBe('pass')
|
|
237
|
+
expect(authorised.ownerTier.detail).toMatch(/payload_owner_hash/)
|
|
238
|
+
expect(authorised.authorisedView).toMatchObject({ view: 'authorised', status: 'pass' })
|
|
239
|
+
expect(authorised.authorisedView.steps.map((s) => s.step)).toContain('assembly')
|
|
240
|
+
expect(authorised.authorisedView.summary).toMatch(/not a statement about the on-chain commitment/)
|
|
241
|
+
// The round trip: the two parts rejoined are the document that went in, value for value.
|
|
242
|
+
expect(authorised.product).toEqual(product)
|
|
243
|
+
expect(nested(authorised.product!)).toEqual(expected)
|
|
244
|
+
expect(JSON.stringify(nested(authorised.product!))).toBe(JSON.stringify(expected))
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('does not open a restricted part that is not the one the state commits to', async () => {
|
|
248
|
+
const record = (await platform.store.getPassport(passportId))!
|
|
249
|
+
const swapped = structuredClone(record)
|
|
250
|
+
const bytes = Utils.toArray(swapped.states[0].ownerTier!.ciphertext, 'base64') as number[]
|
|
251
|
+
bytes[bytes.length - 1] ^= 1
|
|
252
|
+
swapped.states[0].ownerTier!.ciphertext = Utils.toBase64(bytes)
|
|
253
|
+
const authorised = await platform.readAuthorised(swapped, platform.parties.brand(brandId))
|
|
254
|
+
expect(authorised.ownerTier.status).toBe('fail')
|
|
255
|
+
expect(authorised.authorisedView.status).toBe('not-checked')
|
|
256
|
+
expect(authorised.restrictedProduct).toBeUndefined()
|
|
257
|
+
expect(authorised.product).toBeUndefined()
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it('never reports a valid, identity-matching part as matching payload_owner_hash when the journal holds no restricted part for the newest state', async () => {
|
|
261
|
+
const record = (await platform.store.getPassport(passportId))!
|
|
262
|
+
const newest = record.states.at(-1)!
|
|
263
|
+
// What any reader holds is a valid document about this item: the public view passes, the identity rule included.
|
|
264
|
+
const view = (await platform.read(passportId)).payloadChecks.at(-1)!.publicView
|
|
265
|
+
expect(view.status).toBe('pass')
|
|
266
|
+
expect(view.steps.find((s) => s.step === 'passport-identity')?.status).toBe('pass')
|
|
267
|
+
// The same journal entry without its sealed restricted part: nothing to compare with the state's payload_owner_hash.
|
|
268
|
+
const withoutEvidence = structuredClone(record)
|
|
269
|
+
delete withoutEvidence.states.at(-1)!.ownerTier
|
|
270
|
+
const authorised = await platform.readAuthorised(withoutEvidence, platform.parties.brand(brandId))
|
|
271
|
+
expect(authorised.ownerTier).toEqual({ status: 'not-checked', txid: newest.txid, detail: "This platform's journal holds no restricted part for the newest state the index returned." })
|
|
272
|
+
expect(authorised.authorisedView).toMatchObject({ view: 'authorised', status: 'not-checked', steps: [], findings: [] })
|
|
273
|
+
expect(authorised.authorisedView.summary).toMatch(/A check that could not run is not a pass\.$/)
|
|
274
|
+
expect(authorised.restrictedProduct).toBeUndefined()
|
|
275
|
+
expect(authorised.product).toBeUndefined()
|
|
276
|
+
// No sentence of the answer says a stored part hashes to the commitment, and the passing public view is not carried into it.
|
|
277
|
+
expect(JSON.stringify(authorised)).not.toMatch(/hashes to the payload_owner_hash/)
|
|
278
|
+
expect(JSON.stringify(authorised)).not.toMatch(/"status":"pass"/)
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it('updates with a new complete document, and both states are checked', async () => {
|
|
282
|
+
const revised = { ...product, 'oec:lastUpdated': '2026-11-03T10:00:00Z' }
|
|
283
|
+
const outcome = await platform.writer.update({ record: (await platform.store.getPassport(passportId))!, actor: platform.parties.brand(brandId), product: revised })
|
|
284
|
+
expect(outcome.entry.op).toBe('UPDATE')
|
|
285
|
+
const reading = await platform.read(passportId)
|
|
286
|
+
expect(reading.payloadChecks.map((c) => c.publicView.status)).toEqual(['pass', 'pass'])
|
|
287
|
+
expect((reading.product!.publicProduct as Json)['oec:lastUpdated']).toBe('2026-11-03T10:00:00Z')
|
|
288
|
+
const authorised = await platform.readAuthorised((await platform.store.getPassport(passportId))!, platform.parties.brand(brandId))
|
|
289
|
+
expect(authorised.product).toEqual(revised)
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
describe('what the writer refuses before anything is signed', () => {
|
|
294
|
+
it('another product\'s valid document under this passport, and this passport\'s document under another identifier', async () => {
|
|
295
|
+
const a = exampleFor('eu-battery@2', 'BAT-A-0001')
|
|
296
|
+
const b = exampleFor('eu-battery@2', 'BAT-B-0001')
|
|
297
|
+
for (const [passportId, product] of [
|
|
298
|
+
[a.passportId, b.product],
|
|
299
|
+
[b.passportId, a.product],
|
|
300
|
+
] as const) {
|
|
301
|
+
const { brand, signatures } = countingBrand()
|
|
302
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@2', product }))
|
|
303
|
+
expect(refused.code).toBe('product-invalid')
|
|
304
|
+
expect(refused.data?.cause).toBe('product-identity-mismatch')
|
|
305
|
+
expect(refused.message).toMatch(/different product/)
|
|
306
|
+
expect(refused.message).toMatch(/Nothing was signed/)
|
|
307
|
+
expect(signatures()).toBe(0)
|
|
308
|
+
await nothingWritten(passportId)
|
|
309
|
+
}
|
|
310
|
+
// Each document under its own identifier is written.
|
|
311
|
+
expect((await platform.writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId: a.passportId, profile: 'eu-battery@2', product: a.product })).entry.index).toBe('admitted')
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('a GTIN or a serial member that disagrees with the document\'s own identifier', async () => {
|
|
315
|
+
for (const [member, value] of [
|
|
316
|
+
['gs1:gtin', mintGtin('952', '999999999')],
|
|
317
|
+
['gs1:hasSerialNumber', 'SOME-OTHER-SERIAL'],
|
|
318
|
+
] as const) {
|
|
319
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-C-0001')
|
|
320
|
+
const { brand, signatures } = countingBrand()
|
|
321
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@2', product: { ...product, [member]: value } }))
|
|
322
|
+
expect(refused.code).toBe('product-invalid')
|
|
323
|
+
expect(refused.data?.cause).toBe('product-identity-mismatch')
|
|
324
|
+
expect(signatures()).toBe(0)
|
|
325
|
+
await nothingWritten(passportId)
|
|
326
|
+
}
|
|
327
|
+
const { passportId, product } = exampleFor('eu-textile@2', 'TEX-C-0001')
|
|
328
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId, profile: 'eu-textile@2', product: { ...product, 'schema:serialNumber': 'SOME-OTHER-SERIAL' } }))
|
|
329
|
+
expect(refused.data?.cause).toBe('product-identity-mismatch')
|
|
330
|
+
await nothingWritten(passportId)
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('a document about a model, not an item', async () => {
|
|
334
|
+
for (const profile of ['eu-battery@2', 'eu-textile@2']) {
|
|
335
|
+
const { passportId, product } = exampleFor(profile, 'MODEL-0001')
|
|
336
|
+
const model = { ...product, id: passportId.replace(/\/21\/.*$/, ''), 'oec:granularityLevel': 'model' }
|
|
337
|
+
const { brand, signatures } = countingBrand()
|
|
338
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile, product: model }))
|
|
339
|
+
expect(refused.code).toBe('product-invalid')
|
|
340
|
+
expect(signatures()).toBe(0)
|
|
341
|
+
await nothingWritten(passportId)
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('a public payload over the size a state holds, naming the size and the limit', async () => {
|
|
346
|
+
const { passportId, product } = exampleFor('eu-textile@2', 'TEX-BIG-0001')
|
|
347
|
+
const { brand, signatures } = countingBrand()
|
|
348
|
+
const large = { ...product, 'gs1:productDescription': [{ '@value': 'x'.repeat(PUBLIC_PAYLOAD_MAX_BYTES), '@language': 'en' }] }
|
|
349
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-textile@2', product: large }))
|
|
350
|
+
expect(refused.code).toBe('public-payload-too-large')
|
|
351
|
+
expect(refused.data?.limit).toBe(PUBLIC_PAYLOAD_MAX_BYTES)
|
|
352
|
+
expect(refused.data?.byteLength as number).toBeGreaterThan(PUBLIC_PAYLOAD_MAX_BYTES)
|
|
353
|
+
expect(refused.message).toMatch(/65535/)
|
|
354
|
+
expect(refused.message).toMatch(/restricted part does not count/)
|
|
355
|
+
expect(signatures()).toBe(0)
|
|
356
|
+
await nothingWritten(passportId)
|
|
357
|
+
// The same text in a restricted property is not counted, and the document is written.
|
|
358
|
+
const elsewhere = { ...product, 'eutex:hasSubstancesOfConcern': [{ ...(product['eutex:hasSubstancesOfConcern'] as Json[])[0], 'eutex:safeUseInstructions': 'x'.repeat(PUBLIC_PAYLOAD_MAX_BYTES) }] }
|
|
359
|
+
expect((await platform.writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId, profile: 'eu-textile@2', product: elsewhere })).entry.index).toBe('admitted')
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it('a document that breaks a rule, with each finding placed at the property it concerns', async () => {
|
|
363
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-D-0001')
|
|
364
|
+
const broken = structuredClone(product)
|
|
365
|
+
delete (broken['gs1:netWeight'] as Json)['gs1:unitCode']
|
|
366
|
+
delete broken['oec:passportStatus']
|
|
367
|
+
;((broken['eubat:hasMaterialComposition'] as Json[])[1] as Json)['schema:name'] = undefined
|
|
368
|
+
const { brand, signatures } = countingBrand()
|
|
369
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@2', product: JSON.parse(JSON.stringify(broken)) as Json }))
|
|
370
|
+
expect(refused.code).toBe('product-invalid')
|
|
371
|
+
expect(refused.data?.cause).toBe('profile-rule-violation')
|
|
372
|
+
const validation = refused.data?.validation as ViewCheck
|
|
373
|
+
expect(validation).toMatchObject({ view: 'whole', status: 'fail' })
|
|
374
|
+
const pointers = validation.findings.map((f) => f.pointer)
|
|
375
|
+
expect(pointers).toContain('/gs1:netWeight/gs1:unitCode')
|
|
376
|
+
expect(pointers).toContain('/oec:passportStatus')
|
|
377
|
+
expect(pointers).toContain('/eubat:hasMaterialComposition/1/schema:name')
|
|
378
|
+
expect(signatures()).toBe(0)
|
|
379
|
+
await nothingWritten(passportId)
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
it('a payload and owner fields for a bound profile, and a product document for a manifest profile', async () => {
|
|
383
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-E-0001')
|
|
384
|
+
const brand = platform.parties.brand(brandId)
|
|
385
|
+
expect((await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@2', payload: product, ownerFields: {} }))).code).toBe('product-required')
|
|
386
|
+
expect((await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'general@2', product }))).code).toBe('payload-required')
|
|
387
|
+
expect((await refusal(platform.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@7', product }))).code).toBe('profile-unknown')
|
|
388
|
+
await nothingWritten(passportId)
|
|
389
|
+
})
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
describe('the identifier that is validated is the identifier that is signed', () => {
|
|
393
|
+
/** A writer whose preparation was tampered with: it validates the document against another identifier than the state's. */
|
|
394
|
+
const tampered = (overrides: Partial<BoundProfiles>): Writer =>
|
|
395
|
+
new Writer({ store: platform.store, wallet: platform.wallet, index: platform.index, identifiers: policy, bound: { ...platform.profiles, ...overrides }, livePublishing: false, spendCapSatoshis: 20_000 })
|
|
396
|
+
|
|
397
|
+
it('refuses a state whose public payload was validated for another passport, on the bytes about to be sent', async () => {
|
|
398
|
+
const mine = exampleFor('eu-battery@2', 'BAT-F-0001')
|
|
399
|
+
const other = exampleFor('eu-battery@2', 'BAT-G-0001')
|
|
400
|
+
// The document is the other item's, and so is the identifier the tampered preparation validates it against. Only the state's own identifier is this passport's.
|
|
401
|
+
const writer = tampered({ prepare: (input) => platform.profiles.prepare({ ...input, passportId: other.passportId }) })
|
|
402
|
+
const refused = await refusal(writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId: mine.passportId, profile: 'eu-battery@2', product: other.product }))
|
|
403
|
+
expect(refused.code).toBe('own-check-refused')
|
|
404
|
+
expect(refused.message).toMatch(/product-identity-mismatch/)
|
|
405
|
+
await nothingWritten(mine.passportId)
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('fails at read when such a state reaches an index all the same', async () => {
|
|
409
|
+
const mine = exampleFor('eu-textile@2', 'TEX-F-0001')
|
|
410
|
+
const other = exampleFor('eu-textile@2', 'TEX-G-0001')
|
|
411
|
+
// A writer with both of its checks removed, standing in for someone else's faulty writer.
|
|
412
|
+
const writer = tampered({ prepare: (input) => platform.profiles.prepare({ ...input, passportId: other.passportId }), validatePublic: async () => ({ status: 'pass' }) })
|
|
413
|
+
await writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId: mine.passportId, profile: 'eu-textile@2', product: other.product })
|
|
414
|
+
const reading = await platform.read(mine.passportId)
|
|
415
|
+
expect(reading.checks.find((c) => c.name === 'schema')).toMatchObject({ status: 'fail', reasonCode: 'schema-invalid' })
|
|
416
|
+
expect(reading.payloadChecks[0].publicView).toMatchObject({ status: 'fail', cause: 'product-identity-mismatch' })
|
|
417
|
+
expect(reading.payloadChecks[0].publicView.steps.at(-1)).toMatchObject({ step: 'passport-identity', status: 'fail' })
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
it('checks a state against the identifier that state carries, not the one the reader was asked about', async () => {
|
|
421
|
+
const asked = exampleFor('eu-battery@2', 'BAT-ASKED-0001')
|
|
422
|
+
const carried = exampleFor('eu-battery@2', 'BAT-CARRIED-0001')
|
|
423
|
+
await platform.writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId: carried.passportId, profile: 'eu-battery@2', product: carried.product })
|
|
424
|
+
// An index that answers a question about one passport with the lineage of another, as a faulty or hostile one might.
|
|
425
|
+
const index = { publisherKeys: () => platform.index.publisherKeys(), lineage: (id: string) => platform.index.lineage(id === asked.passportId ? carried.passportId : id) } as unknown as IndexClient
|
|
426
|
+
const reading = await readPassport(asked.passportId, { index, chainTracker: 'scripts only', profiles: platform.profiles })
|
|
427
|
+
// The document is the carried passport's, and so is the identifier its state carries: checked against that, it matches.
|
|
428
|
+
const view = reading.payloadChecks[0].publicView
|
|
429
|
+
expect(view.steps.find((s) => s.step === 'passport-identity')).toMatchObject({ status: 'pass' })
|
|
430
|
+
expect(view.status).toBe('pass')
|
|
431
|
+
// Checked against the identifier asked about, the same payload fails the identity rule. So the pass above came from the state's identifier.
|
|
432
|
+
const bound = bindingOf('eu-battery@2')
|
|
433
|
+
const state = findDppOutputs((await platform.index.lineage(carried.passportId))[0])[0].state
|
|
434
|
+
expect(state.passportId).toBe(carried.passportId)
|
|
435
|
+
expect(await platform.profiles.validatePublic({ profile: bound.id, profileVersion: bound.version, payloadPublic: state.payloadPublic, passportId: asked.passportId })).toMatchObject({ status: 'fail', detail: { cause: 'product-identity-mismatch' } })
|
|
436
|
+
// That the lineage is about another passport is the report's own finding, on a check of its own, and not the profile's.
|
|
437
|
+
expect(reading.checks.find((c) => c.name === 'subjectBinding')?.status).toBe('fail')
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
it('fails at read when the payload declares another binding digest', async () => {
|
|
441
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-H-0001')
|
|
442
|
+
const substituted = 'ab'.repeat(32)
|
|
443
|
+
const writer = tampered({
|
|
444
|
+
prepare: async (input) => {
|
|
445
|
+
const prepared = await platform.profiles.prepare(input)
|
|
446
|
+
return prepared.ok ? { ...prepared, payloadPublic: prepared.payloadPublic.replace(bindingOf('eu-battery@2').bindingDigest, substituted) } : prepared
|
|
447
|
+
},
|
|
448
|
+
validatePublic: async () => ({ status: 'pass' }),
|
|
449
|
+
})
|
|
450
|
+
await writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId, profile: 'eu-battery@2', product })
|
|
451
|
+
const reading = await platform.read(passportId)
|
|
452
|
+
expect(reading.checks.find((c) => c.name === 'schema')?.status).toBe('fail')
|
|
453
|
+
expect(reading.payloadChecks[0].publicView).toMatchObject({ status: 'fail', cause: 'profile-binding-mismatch' })
|
|
454
|
+
// Nothing after the binding step ran: the payload was written to other rules.
|
|
455
|
+
expect(reading.payloadChecks[0].publicView.steps.map((s) => s.step)).toEqual(['envelope', 'binding'])
|
|
456
|
+
})
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
describe('after a hand-on', () => {
|
|
460
|
+
it('opens the transferred textile tier for the recipient and reports an unavailable view under an unrelated key', async () => {
|
|
461
|
+
const { passportId, product } = exampleFor('eu-textile@2', 'TEX-H-0001')
|
|
462
|
+
const brand = platform.parties.brand(brandId)
|
|
463
|
+
await platform.writer.issue({ brandId, brand, passportId, profile: 'eu-textile@2', product })
|
|
464
|
+
const { offer, claimCode } = await platform.custody.offer({ record: (await platform.store.getPassport(passportId))!, holder: brand, terms: { word: 'Sold' } })
|
|
465
|
+
await platform.custody.accept({ requestId: offer.requestId, claimCode })
|
|
466
|
+
const record = (await platform.store.getPassport(passportId))!
|
|
467
|
+
const recipient = platform.custody.holderOf(record)
|
|
468
|
+
const authorised = await platform.readAuthorised(record, recipient)
|
|
469
|
+
expect(authorised.authorisedView.status).toBe('pass')
|
|
470
|
+
expect(authorised.product).toEqual(product)
|
|
471
|
+
const other = await platform.readAuthorised(record, platform.parties.member('other-reader'))
|
|
472
|
+
expect(other.ownerTier.status).toBe('pass')
|
|
473
|
+
expect(other.authorisedView.status).toBe('not-checked')
|
|
474
|
+
expect(other.product).toBeUndefined()
|
|
475
|
+
expect(other.restrictedProduct).toBeUndefined()
|
|
476
|
+
// The public view is unchanged by the hand-on.
|
|
477
|
+
const reading = await platform.read(passportId)
|
|
478
|
+
expect(reading.payloadChecks.map((c) => c.publicView.status)).toEqual(['pass', 'pass'])
|
|
479
|
+
// A later update seals the new version to the current holder.
|
|
480
|
+
await platform.writer.update({ record, actor: recipient, product })
|
|
481
|
+
const again = await platform.readAuthorised((await platform.store.getPassport(passportId))!, recipient)
|
|
482
|
+
expect(again.authorisedView.status).toBe('pass')
|
|
483
|
+
expect(again.product).toEqual(product)
|
|
484
|
+
})
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
describe('without the validation engine', () => {
|
|
488
|
+
let bare: Platform
|
|
489
|
+
|
|
490
|
+
beforeAll(async () => {
|
|
491
|
+
// What a project sees when jsonld, n3 and shacl-engine are not installed.
|
|
492
|
+
bare = await openPlatform({
|
|
493
|
+
config,
|
|
494
|
+
mode: 'test',
|
|
495
|
+
log: () => {},
|
|
496
|
+
loadEngineLibrary: async (name) => {
|
|
497
|
+
throw new Error(`Cannot find package '${name}'`)
|
|
498
|
+
},
|
|
499
|
+
})
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
afterAll(async () => {
|
|
503
|
+
await bare.close()
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
it('still starts, says what to install, and keeps the manifest profiles working', async () => {
|
|
507
|
+
expect(bare.profiles.engineProblem).toMatch(/jsonld@9\.0\.0 n3@2\.13\.12 shacl-engine@1\.1\.3/)
|
|
508
|
+
expect(bare.profiles.list().map((p) => p.profile).sort()).toEqual(BUNDLED_BINDINGS.map(entry => entry.profile).sort())
|
|
509
|
+
const passportId = mintPassportId(policy, '100000077', 'GEN-NOENGINE-1')
|
|
510
|
+
const outcome = await bare.writer.issue({ brandId, brand: bare.parties.brand(brandId), passportId, profile: 'general@2', payload: samplePayload('general@2', true), ownerFields: {} })
|
|
511
|
+
expect(outcome.entry.index).toBe('admitted')
|
|
512
|
+
// A manifest profile's payload is checked against its schema, and its answer says that and no more.
|
|
513
|
+
const view = (await bare.read(passportId)).payloadChecks[0].publicView
|
|
514
|
+
expect(view.status).toBe('pass')
|
|
515
|
+
expect(view.summary).toMatch(/fits the public schema/)
|
|
516
|
+
expect(view.summary).not.toMatch(/passport's item/)
|
|
517
|
+
})
|
|
518
|
+
|
|
519
|
+
it('refuses to write a bound profile, before anything is signed', async () => {
|
|
520
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-NOENGINE-1')
|
|
521
|
+
const brand = bare.parties.brand(brandId)
|
|
522
|
+
let signatures = 0
|
|
523
|
+
const sign = brand.wallet.createSignature.bind(brand.wallet)
|
|
524
|
+
brand.wallet.createSignature = (async (...args: Parameters<typeof sign>) => {
|
|
525
|
+
signatures++
|
|
526
|
+
return await sign(...args)
|
|
527
|
+
}) as typeof brand.wallet.createSignature
|
|
528
|
+
const refused = await refusal(bare.writer.issue({ brandId, brand, passportId, profile: 'eu-battery@2', product }))
|
|
529
|
+
expect(refused.code).toBe('product-not-validated')
|
|
530
|
+
expect(refused.message).toMatch(/Install jsonld@9\.0\.0 n3@2\.13\.12 shacl-engine@1\.1\.3/)
|
|
531
|
+
expect(signatures).toBe(0)
|
|
532
|
+
expect(await bare.store.getPassport(passportId)).toBeUndefined()
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
it('reads a bound passport as not checked, never as passed', async () => {
|
|
536
|
+
const { passportId, product } = exampleFor('eu-battery@2', 'BAT-NOENGINE-2')
|
|
537
|
+
await platform.writer.issue({ brandId, brand: platform.parties.brand(brandId), passportId, profile: 'eu-battery@2', product })
|
|
538
|
+
const reading = await readPassport(passportId, { index: platform.index, chainTracker: 'scripts only', profiles: bare.profiles })
|
|
539
|
+
expect(reading.checks.find((c) => c.name === 'schema')).toMatchObject({ status: 'unknown', reasonCode: 'schema-unavailable' })
|
|
540
|
+
const view = reading.payloadChecks[0].publicView
|
|
541
|
+
expect(view).toMatchObject({ status: 'not-checked', cause: 'validator-unavailable' })
|
|
542
|
+
expect(view.summary).toMatch(/not a pass/)
|
|
543
|
+
expect(view.steps.find((s) => s.step === 'shacl')?.status).toBe('not-checked')
|
|
544
|
+
// Reading every semantic identity assertion requires the selected contexts to be expanded.
|
|
545
|
+
expect(view.steps.find((s) => s.step === 'passport-identity')?.status).toBe('not-checked')
|
|
546
|
+
})
|
|
547
|
+
})
|