@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,198 @@
|
|
|
1
|
+
// Which profile resolver a deployment uses, shown by what it resolves.
|
|
2
|
+
//
|
|
3
|
+
// With PROFILE_BUNDLE_DIR set, the profiles held by a binding are read from
|
|
4
|
+
// the bundle in that folder and from nowhere else. The sector profiles are
|
|
5
|
+
// also in the installed profiles package, byte for byte, so a deployment
|
|
6
|
+
// that quietly read them from the package instead would answer every
|
|
7
|
+
// question about a complete bundle the same way. These tests ask the
|
|
8
|
+
// questions that tell the two apart: a folder with no bundle, a bundle with
|
|
9
|
+
// a file gone, and a bundle that carries one of the two profiles. In each,
|
|
10
|
+
// a profile the folder does not give is not resolved, the deployment says
|
|
11
|
+
// so, nothing can be written under it, and a payload that declares it reads
|
|
12
|
+
// as not checked. A check that did not run is never a pass.
|
|
13
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
14
|
+
import { tmpdir } from 'node:os'
|
|
15
|
+
import { dirname, join } from 'node:path'
|
|
16
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'
|
|
17
|
+
import { EPCIS_GS1_ARTEFACTS } from '@bsv/dpp-credentials'
|
|
18
|
+
import { BUNDLED_BINDINGS, CURRENT_SECTOR_BINDINGS, exportProfileBundle } from '@bsv/dpp-profiles'
|
|
19
|
+
import { startApp, testConfig, type Json, type TestApp } from './epcis-fixtures.js'
|
|
20
|
+
|
|
21
|
+
const SECTOR = ['eu-battery@2', 'eu-textile@2'] as const
|
|
22
|
+
const folders: string[] = []
|
|
23
|
+
const apps: TestApp[] = []
|
|
24
|
+
|
|
25
|
+
/** What the control deployment, which reads the installed package, made for each sector profile: a product, its passport identifier and its signed public payload. */
|
|
26
|
+
const made = new Map<string, { itemReference: string; serial: string; passportId: string; product: Json; payload: { profile: string; profileVersion: number; payloadPublic: string; passportId: string } }>()
|
|
27
|
+
/** The files of a bundle of the profiles named, as an export writes them, under the folder name a restore installs them at. */
|
|
28
|
+
const bundleFiles = new Map<string, Map<string, Uint8Array>>()
|
|
29
|
+
|
|
30
|
+
const folder = (): string => {
|
|
31
|
+
const dir = mkdtempSync(join(tmpdir(), 'dpp-profile-bundle-'))
|
|
32
|
+
folders.push(dir)
|
|
33
|
+
return dir
|
|
34
|
+
}
|
|
35
|
+
const app = async (over: Record<string, string> = {}): Promise<TestApp> => {
|
|
36
|
+
const started = await startApp({ config: testConfig(over) })
|
|
37
|
+
apps.push(started)
|
|
38
|
+
const party = started.platform.parties.brand('dev-brand')
|
|
39
|
+
await started.platform.store.saveBrand({ id: 'dev-brand', name: 'Development brand', identityKey: party.identityKey, did: party.did, createdAt: '2026-03-01T00:00:00.000Z' })
|
|
40
|
+
return started
|
|
41
|
+
}
|
|
42
|
+
const install = (dir: string, files: Map<string, Uint8Array>, without: (path: string) => boolean = () => false): void => {
|
|
43
|
+
for (const [path, bytes] of files) {
|
|
44
|
+
if (without(path)) continue
|
|
45
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true })
|
|
46
|
+
writeFileSync(join(dir, path), bytes)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const everyFile = (dir: string): string[] => readdirSync(dir, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => entry.name)
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
// The control: no bundle folder is configured, so both sector profiles are read from the installed package.
|
|
53
|
+
const packaged = await app()
|
|
54
|
+
expect(packaged.platform.profiles.source).toBe('package')
|
|
55
|
+
expect(packaged.platform.profiles.list().map((profile) => profile.profile).sort()).toEqual(BUNDLED_BINDINGS.map(entry => entry.profile).sort())
|
|
56
|
+
expect(packaged.platform.profiles.refusals).toEqual([])
|
|
57
|
+
for (const profile of SECTOR) {
|
|
58
|
+
const example = (await packaged.get(`/api/profiles/${encodeURIComponent(profile)}`)).body.examples[0] as { itemReference: string; serial: string; passportId: string; product: Json }
|
|
59
|
+
const bound = packaged.platform.profiles.get(profile)!
|
|
60
|
+
const prepared = await packaged.platform.profiles.prepare({ profile: bound, product: example.product, passportId: example.passportId })
|
|
61
|
+
if (!('payloadPublic' in prepared)) throw new Error(`the control deployment could not prepare ${profile}: ${JSON.stringify(prepared)}`)
|
|
62
|
+
const payload = { profile: bound.id, profileVersion: bound.version, payloadPublic: prepared.payloadPublic as string, passportId: example.passportId }
|
|
63
|
+
// Under the package's own binding the payload passes. This is what a deployment that fell back to the package would answer below.
|
|
64
|
+
expect((await packaged.platform.profiles.validatePublic(payload)).status, profile).toBe('pass')
|
|
65
|
+
made.set(profile, { ...example, payload })
|
|
66
|
+
}
|
|
67
|
+
for (const [name, profiles] of [['both', [...SECTOR]], ['textile-only', ['eu-textile@2']]] as const) {
|
|
68
|
+
const bundle = await exportProfileBundle({
|
|
69
|
+
registry: packaged.platform.profiles.registry,
|
|
70
|
+
profiles: [...profiles],
|
|
71
|
+
readNotice: (profile, path) => packaged.platform.profiles.readNotice(profile, path),
|
|
72
|
+
licenceTexts: await packaged.platform.profiles.licenceTexts(),
|
|
73
|
+
provisioned: EPCIS_GS1_ARTEFACTS,
|
|
74
|
+
root: 'profiles',
|
|
75
|
+
})
|
|
76
|
+
if (!bundle.ok) throw new Error(`the control deployment could not export a bundle: ${bundle.code}: ${bundle.detail}`)
|
|
77
|
+
bundleFiles.set(name, bundle.files)
|
|
78
|
+
}
|
|
79
|
+
await packaged.close()
|
|
80
|
+
apps.splice(apps.indexOf(packaged), 1)
|
|
81
|
+
}, 120_000)
|
|
82
|
+
|
|
83
|
+
afterEach(async () => {
|
|
84
|
+
await Promise.all(apps.splice(0).map((started) => started.close()))
|
|
85
|
+
})
|
|
86
|
+
afterAll(() => {
|
|
87
|
+
for (const dir of folders) rmSync(dir, { recursive: true, force: true })
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
/** Everything a deployment answers about a sector profile it does not hold: it is not listed, cannot be written, and a payload that declares it is not checked. */
|
|
91
|
+
async function notResolved(api: TestApp, profile: (typeof SECTOR)[number]): Promise<void> {
|
|
92
|
+
const example = made.get(profile)!
|
|
93
|
+
expect(api.platform.profiles.get(profile), profile).toBeUndefined()
|
|
94
|
+
expect(api.platform.profiles.list().map((held) => held.profile), profile).not.toContain(profile)
|
|
95
|
+
expect(((await api.get('/api/profiles')).body as Json[]).map((listed) => listed.id), profile).not.toContain(profile)
|
|
96
|
+
const described = await api.get(`/api/profiles/${encodeURIComponent(profile)}`)
|
|
97
|
+
expect(described.status, profile).toBe(404)
|
|
98
|
+
expect(described.body, profile).toMatchObject({ error: 'profile-unknown' })
|
|
99
|
+
expect((await api.get(`/api/profiles/${encodeURIComponent(profile)}/codes?class=x`)).status, profile).toBe(404)
|
|
100
|
+
|
|
101
|
+
// Nothing is written under it: the request is refused by name, and no passport is in the journal.
|
|
102
|
+
const issued = await api.post('/api/brands/dev-brand/passports', { profile, itemReference: example.itemReference, serial: example.serial, product: example.product })
|
|
103
|
+
expect(issued.status, profile).toBe(400)
|
|
104
|
+
expect(issued.body, profile).toMatchObject({ error: 'profile-unknown' })
|
|
105
|
+
expect(await api.platform.store.getPassport(example.passportId), profile).toBeUndefined()
|
|
106
|
+
|
|
107
|
+
// A payload that declares it, and that passes under the package's binding, is not checked here. That is an answer of its own, and it is not a pass.
|
|
108
|
+
const validation = await api.platform.profiles.validatePublic(example.payload)
|
|
109
|
+
expect(validation.status, profile).toBe('unknown')
|
|
110
|
+
const view = await api.platform.profiles.viewCheck('public', validation)
|
|
111
|
+
expect(view.status, profile).toBe('not-checked')
|
|
112
|
+
expect(view.status, profile).not.toBe('pass')
|
|
113
|
+
expect(view.summary, profile).toMatch(/A check that could not run is not a pass\./)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe('a deployment told to read its profiles from a bundle folder', () => {
|
|
117
|
+
it('resolves no sector profile from a folder that holds no bundle, says so, and puts nothing into the folder', async () => {
|
|
118
|
+
const dir = folder()
|
|
119
|
+
const lines: string[] = []
|
|
120
|
+
const started = await startApp({ config: testConfig({ PROFILE_BUNDLE_DIR: dir }), lines })
|
|
121
|
+
apps.push(started)
|
|
122
|
+
const party = started.platform.parties.brand('dev-brand')
|
|
123
|
+
await started.platform.store.saveBrand({ id: 'dev-brand', name: 'Development brand', identityKey: party.identityKey, did: party.did, createdAt: '2026-03-01T00:00:00.000Z' })
|
|
124
|
+
|
|
125
|
+
// The resolver is the bundle's, and it gave nothing. Had the package's bindings been read in its place, both profiles would be listed here.
|
|
126
|
+
expect(started.platform.profiles.source).toBe('bundle')
|
|
127
|
+
expect(started.platform.profiles.list()).toEqual([])
|
|
128
|
+
// The deployment says what is missing: one refusal, which names the folder and the setting.
|
|
129
|
+
expect(started.platform.profiles.refusals).toHaveLength(1)
|
|
130
|
+
expect(started.platform.profiles.refusals[0]).toMatchObject({ source: `the profile bundle in ${dir}`, detail: expect.stringContaining('PROFILE_BUNDLE_DIR names the folder a restore installs a bundle into; until it holds one, no profile is registered from it.') })
|
|
131
|
+
expect(lines.filter((line) => line.startsWith(`Profile the profile bundle in ${dir} was not registered`))).toHaveLength(1)
|
|
132
|
+
const operations = (await started.get('/api/operations')).body
|
|
133
|
+
expect(operations.profiles).toMatchObject({ source: 'bundle', refused: [{ source: `the profile bundle in ${dir}`, code: started.platform.profiles.refusals[0]!.code }] })
|
|
134
|
+
// The API runs, and its other profiles are as they were.
|
|
135
|
+
expect((await started.get('/api/health')).status).toBe(200)
|
|
136
|
+
|
|
137
|
+
for (const profile of SECTOR) await notResolved(started, profile)
|
|
138
|
+
// Nothing was copied in to make the folder whole.
|
|
139
|
+
expect(everyFile(dir)).toEqual([])
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('resolves both sector profiles once the folder holds their bundle, under the digests the package publishes', async () => {
|
|
143
|
+
const dir = folder()
|
|
144
|
+
install(dir, bundleFiles.get('both')!)
|
|
145
|
+
const api = await app({ PROFILE_BUNDLE_DIR: dir })
|
|
146
|
+
expect(api.platform.profiles.source).toBe('bundle')
|
|
147
|
+
expect(api.platform.profiles.refusals).toEqual([])
|
|
148
|
+
expect(api.platform.profiles.list().map((profile) => [profile.profile, profile.bindingDigest]).sort()).toEqual(CURRENT_SECTOR_BINDINGS.map((entry) => [entry.profile, entry.bindingDigest]).sort())
|
|
149
|
+
for (const profile of SECTOR) expect((await api.platform.profiles.validatePublic(made.get(profile)!.payload)).status, profile).toBe('pass')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('opens the exact packaged successor carried in a portable bundle under default trust', async () => {
|
|
153
|
+
const { profile } = CURRENT_SECTOR_BINDINGS[0]
|
|
154
|
+
const source = await app()
|
|
155
|
+
const bundle = await exportProfileBundle({
|
|
156
|
+
registry: source.platform.profiles.registry, profiles: [profile],
|
|
157
|
+
readNotice: (entry, path) => source.platform.profiles.readNotice(entry, path),
|
|
158
|
+
licenceTexts: await source.platform.profiles.licenceTexts(), provisioned: EPCIS_GS1_ARTEFACTS, root: 'profiles',
|
|
159
|
+
})
|
|
160
|
+
if (!bundle.ok) throw new Error(bundle.detail)
|
|
161
|
+
const dir = folder()
|
|
162
|
+
install(dir, bundle.files)
|
|
163
|
+
const selected = await app({ PROFILE_BUNDLE_DIR: dir })
|
|
164
|
+
expect(selected.platform.profiles.list().map(entry => entry.profile)).toEqual([profile])
|
|
165
|
+
expect((await selected.get(`/api/profiles/${profile}`)).status).toBe(200)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('resolves only the profile a bundle carries: the other is not taken from the package', async () => {
|
|
169
|
+
const dir = folder()
|
|
170
|
+
install(dir, bundleFiles.get('textile-only')!)
|
|
171
|
+
const api = await app({ PROFILE_BUNDLE_DIR: dir })
|
|
172
|
+
expect(api.platform.profiles.source).toBe('bundle')
|
|
173
|
+
expect(api.platform.profiles.list().map((profile) => profile.profile)).toEqual(['eu-textile@2'])
|
|
174
|
+
expect((await api.platform.profiles.validatePublic(made.get('eu-textile@2')!.payload)).status).toBe('pass')
|
|
175
|
+
await notResolved(api, 'eu-battery@2')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('refuses a bundle with a file gone, by name, and resolves nothing in its place', async () => {
|
|
179
|
+
const dir = folder()
|
|
180
|
+
const files = bundleFiles.get('both')!
|
|
181
|
+
// One file of the battery profile that is not its binding: a rule file or a context the binding names.
|
|
182
|
+
const gone = [...files.keys()].find((path) => path.startsWith('profiles/eu-battery@2/') && !path.endsWith('binding.json'))!
|
|
183
|
+
expect(gone).toBeDefined()
|
|
184
|
+
install(dir, files, (path) => path === gone)
|
|
185
|
+
const lines: string[] = []
|
|
186
|
+
const started = await startApp({ config: testConfig({ PROFILE_BUNDLE_DIR: dir }), lines })
|
|
187
|
+
apps.push(started)
|
|
188
|
+
const party = started.platform.parties.brand('dev-brand')
|
|
189
|
+
await started.platform.store.saveBrand({ id: 'dev-brand', name: 'Development brand', identityKey: party.identityKey, did: party.did, createdAt: '2026-03-01T00:00:00.000Z' })
|
|
190
|
+
|
|
191
|
+
expect(started.platform.profiles.source).toBe('bundle')
|
|
192
|
+
expect(started.platform.profiles.refusals.length).toBeGreaterThan(0)
|
|
193
|
+
expect(lines.some((line) => /was not registered \(/.test(line))).toBe(true)
|
|
194
|
+
// The incomplete profile is not resolved, from the bundle or from anywhere else.
|
|
195
|
+
await notResolved(started, 'eu-battery@2')
|
|
196
|
+
expect((await started.get('/api/operations')).body.profiles.refused.length).toBeGreaterThan(0)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// The earlier sector profiles are retired (RETIRED_PROFILE_IDS in
|
|
2
|
+
// @bsv/dpp-profiles). This application offers none of them, writes nothing
|
|
3
|
+
// under one and reports a record that declares one as not checked, which is
|
|
4
|
+
// neither a pass nor a failure. Retirement removes nothing: a passport
|
|
5
|
+
// already in the journal under a retired profile stays there, readable, and
|
|
6
|
+
// no further state, hand-on or claim is made for it.
|
|
7
|
+
import { once } from 'node:events'
|
|
8
|
+
import type { AddressInfo } from 'node:net'
|
|
9
|
+
import type { Server } from 'node:http'
|
|
10
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
11
|
+
import { ProfileRetiredError, RETIRED_PROFILE_IDS, RETIRED_PROFILE_REPLACEMENTS } from '@bsv/dpp-profiles'
|
|
12
|
+
import { sectorFormFor } from '../../web/src/lib/bound/forms'
|
|
13
|
+
import { loadConfig } from '../src/config.js'
|
|
14
|
+
import { mintPassportId } from '../src/identifiers.js'
|
|
15
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
16
|
+
import { currentProfiles, isProfileId, manifestFor, samplePayload, sampleWithProblems, validatePayload } from '../src/profiles.js'
|
|
17
|
+
import { createServer } from '../src/server.js'
|
|
18
|
+
import type { PassportRecord } from '../src/store.js'
|
|
19
|
+
import { WriteRefused } from '../src/writer.js'
|
|
20
|
+
|
|
21
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
22
|
+
const policy = { host: config.passportHost, prefix: config.gs1Prefix }
|
|
23
|
+
const brandId = 'dev-brand'
|
|
24
|
+
const RETIRED: readonly string[] = RETIRED_PROFILE_IDS
|
|
25
|
+
const parts = (profile: string): { id: string; version: number } => ({ id: profile.split('@')[0]!, version: Number(profile.split('@')[1]) })
|
|
26
|
+
let platform: Platform
|
|
27
|
+
let server: Server
|
|
28
|
+
let base: string
|
|
29
|
+
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
platform = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
32
|
+
const party = platform.parties.brand(brandId)
|
|
33
|
+
await platform.store.saveBrand({ id: brandId, name: 'Development brand', identityKey: party.identityKey, did: party.did, createdAt: new Date().toISOString() })
|
|
34
|
+
const app = createServer({ platform, devSession: { userId: 'developer', email: 'developer@localhost', name: 'Developer', brandIds: [brandId] } })
|
|
35
|
+
server = app.listen(0, '127.0.0.1')
|
|
36
|
+
await once(server, 'listening')
|
|
37
|
+
base = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
afterAll(async () => {
|
|
41
|
+
server.close()
|
|
42
|
+
await platform.close()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const get = async (path: string): Promise<{ status: number; body: any }> => {
|
|
46
|
+
const response = await fetch(`${base}${path}`)
|
|
47
|
+
return { status: response.status, body: await response.json() }
|
|
48
|
+
}
|
|
49
|
+
const post = async (path: string, body: unknown): Promise<{ status: number; body: any }> => {
|
|
50
|
+
const response = await fetch(`${base}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
|
|
51
|
+
return { status: response.status, body: await response.json() }
|
|
52
|
+
}
|
|
53
|
+
const refusal = async (attempt: Promise<unknown>): Promise<WriteRefused> => {
|
|
54
|
+
try {
|
|
55
|
+
await attempt
|
|
56
|
+
} catch (cause) {
|
|
57
|
+
if (cause instanceof WriteRefused) return cause
|
|
58
|
+
throw cause
|
|
59
|
+
}
|
|
60
|
+
throw new Error('the write was not refused')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A passport as an earlier release of this application left it in the journal: one state, under a retired profile. */
|
|
64
|
+
async function storedUnder(profile: string, serial: string): Promise<PassportRecord> {
|
|
65
|
+
const passportId = mintPassportId(policy, '100000042', serial)
|
|
66
|
+
const brand = platform.parties.brand(brandId)
|
|
67
|
+
const { id, version } = parts(profile)
|
|
68
|
+
const record: PassportRecord = {
|
|
69
|
+
passportId,
|
|
70
|
+
brandId,
|
|
71
|
+
profile,
|
|
72
|
+
createdAt: '2026-10-01T00:00:00Z',
|
|
73
|
+
status: 'active',
|
|
74
|
+
holder: { party: brand.name, controllerKey: await brand.controllerKey(passportId) },
|
|
75
|
+
states: [
|
|
76
|
+
{
|
|
77
|
+
op: 'ISSUE',
|
|
78
|
+
txid: 'ab'.repeat(32),
|
|
79
|
+
outputIndex: 0,
|
|
80
|
+
rawTx: '',
|
|
81
|
+
beef: '',
|
|
82
|
+
timestamp: '2026-10-01T00:00:00Z',
|
|
83
|
+
actor: brand.name,
|
|
84
|
+
controllerKey: await brand.controllerKey(passportId),
|
|
85
|
+
payloadPublic: JSON.stringify({ profile: id, profile_version: version, name: 'An earlier demonstration record' }),
|
|
86
|
+
ownerTier: { hash: '00'.repeat(32), ciphertext: '' },
|
|
87
|
+
index: 'admitted',
|
|
88
|
+
network: 'accepted',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
acceptanceRecords: [],
|
|
92
|
+
}
|
|
93
|
+
await platform.store.savePassport(record)
|
|
94
|
+
return record
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe('no retired profile is offered', () => {
|
|
98
|
+
it('lists none: not among the manifest profiles, not over HTTP, and not as a form', async () => {
|
|
99
|
+
expect(currentProfiles().map((p) => p.id)).toEqual(['general@2'])
|
|
100
|
+
const listed = ((await get('/api/profiles')).body as Array<{ id: string; format: string }>).map((p) => p.id)
|
|
101
|
+
expect(listed).toEqual(['general@2', 'eu-battery@1', 'eu-textile@1', 'eu-battery@2', 'eu-textile@2'])
|
|
102
|
+
for (const profile of RETIRED) {
|
|
103
|
+
expect(listed, profile).not.toContain(profile)
|
|
104
|
+
expect(isProfileId(profile), profile).toBe(false)
|
|
105
|
+
expect(sectorFormFor(profile), profile).toBeUndefined()
|
|
106
|
+
expect(platform.profiles.get(profile), profile).toBeUndefined()
|
|
107
|
+
}
|
|
108
|
+
// What replaces them is offered, each with its form.
|
|
109
|
+
for (const replacement of new Set(Object.values(RETIRED_PROFILE_REPLACEMENTS))) {
|
|
110
|
+
expect(listed).toContain(replacement)
|
|
111
|
+
expect(sectorFormFor(replacement)?.profile).toBe(replacement)
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it.each(RETIRED)('%s: the profile route answers 410 with profile-retired and serves no schema, field or sample', async (profile) => {
|
|
116
|
+
const { status, body } = await get(`/api/profiles/${encodeURIComponent(profile)}`)
|
|
117
|
+
expect(status).toBe(410)
|
|
118
|
+
expect(body.error).toBe('profile-retired')
|
|
119
|
+
expect(body.description).toContain(`${RETIRED_PROFILE_REPLACEMENTS[profile as keyof typeof RETIRED_PROFILE_REPLACEMENTS]} replaces it`)
|
|
120
|
+
expect(Object.keys(body).sort()).toEqual(['description', 'error'])
|
|
121
|
+
expect((await get(`/api/profiles/${encodeURIComponent(profile)}/codes?class=x:Y`)).status).toBe(404)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it.each(RETIRED)('%s: no sample is started and no payload is checked', (profile) => {
|
|
125
|
+
const retired = profile as never
|
|
126
|
+
for (const act of [() => samplePayload(retired, true), () => sampleWithProblems(retired, false), () => validatePayload(retired, 'public', {}), () => validatePayload(retired, 'restricted', {}), () => manifestFor(retired)]) {
|
|
127
|
+
expect(act).toThrow(ProfileRetiredError)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('nothing is written under a retired profile', () => {
|
|
133
|
+
it.each(RETIRED)('%s: the writer refuses to issue, with a payload or with a product document, and journals nothing', async (profile) => {
|
|
134
|
+
const brand = platform.parties.brand(brandId)
|
|
135
|
+
const passportId = mintPassportId(policy, '100000041', `NEW-${profile.replace('@', '-')}`)
|
|
136
|
+
for (const data of [{ payload: { profile: parts(profile).id, profile_version: parts(profile).version }, ownerFields: {} }, { product: { id: passportId } }, {}]) {
|
|
137
|
+
const refused = await refusal(platform.writer.issue({ brandId, brand, passportId, profile, ...data }))
|
|
138
|
+
expect(refused.code).toBe('profile-retired')
|
|
139
|
+
expect(refused.message).toContain('Nothing was signed')
|
|
140
|
+
expect(refused.data).toEqual({ replacedBy: profile.startsWith('battery@') ? 'eu-battery@2' : 'eu-textile@2' })
|
|
141
|
+
}
|
|
142
|
+
expect(await platform.store.getPassport(passportId)).toBeUndefined()
|
|
143
|
+
expect(await platform.index.lineage(passportId).catch(() => [])).toEqual([])
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it.each(RETIRED)('%s: the issue route answers 409 with profile-retired', async (profile) => {
|
|
147
|
+
const { status, body } = await post(`/api/brands/${brandId}/passports`, { profile, itemReference: '100000043', serial: `HTTP-${profile.replace('@', '-')}`, payload: {}, ownerFields: {} })
|
|
148
|
+
expect(status).toBe(409)
|
|
149
|
+
expect(body).toMatchObject({ error: 'profile-retired', replacedBy: profile.startsWith('battery@') ? 'eu-battery@2' : 'eu-textile@2' })
|
|
150
|
+
expect((await platform.store.listPassports({ brandId })).every((p) => !p.passportId.includes('/21/HTTP-'))).toBe(true)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it.each(RETIRED)('%s: a passport already journalled gets no further state, hand-on or claim, and stays as it was', async (profile) => {
|
|
154
|
+
const record = await storedUnder(profile, `OLD-${profile.replace('@', '-')}`)
|
|
155
|
+
const before = JSON.stringify(await platform.store.getPassport(record.passportId))
|
|
156
|
+
const brand = platform.parties.brand(brandId)
|
|
157
|
+
const writes = [
|
|
158
|
+
platform.writer.update({ record, actor: brand, payload: { profile: parts(profile).id, profile_version: parts(profile).version } }),
|
|
159
|
+
platform.writer.update({ record, actor: brand, product: { id: record.passportId } }),
|
|
160
|
+
platform.writer.transfer({ record, holder: brand, recipient: platform.parties.recipient('offer-none'), acceptance: {} as never }),
|
|
161
|
+
platform.writer.retire({ record, actor: brand, reason: 'end of the demonstration' }),
|
|
162
|
+
platform.custody.offer({ record, holder: brand, terms: { word: 'Handed on' } }),
|
|
163
|
+
platform.claims.issue({ event: { type: 'ObjectEvent', eventID: 'urn:uuid:6c000000-0000-4000-8000-00000000d001', eventTime: '2026-03-02T08:00:00.000Z', eventTimeZoneOffset: '+00:00', epcList: [record.passportId], action: 'OBSERVE', bizStep: 'inspecting' }, issuer: platform.parties.member('developer'), assertedRole: 'observer', expectedPassport: record.passportId }),
|
|
164
|
+
]
|
|
165
|
+
for (const write of writes) expect((await refusal(write)).code).toBe('profile-retired')
|
|
166
|
+
expect(JSON.stringify(await platform.store.getPassport(record.passportId))).toBe(before)
|
|
167
|
+
expect(await platform.store.listOffers({ passportId: record.passportId })).toEqual([])
|
|
168
|
+
expect(await platform.store.listClaims({ passportId: record.passportId })).toEqual([])
|
|
169
|
+
|
|
170
|
+
// Over HTTP the journal view is still served, and each write route refuses.
|
|
171
|
+
const ref = encodeURIComponent(record.passportId)
|
|
172
|
+
expect((await get(`/api/passports/${ref}`)).body).toMatchObject({ passportId: record.passportId, profile, status: 'active', profileRetired: { replacedBy: RETIRED_PROFILE_REPLACEMENTS[profile as keyof typeof RETIRED_PROFILE_REPLACEMENTS] } })
|
|
173
|
+
for (const [path, body] of [['update', { payload: {} }], ['retire', { reason: 'x' }], ['offer', {}], ['claims', { assertedRole: 'observer', event: { type: 'ObjectEvent', eventID: 'urn:uuid:6c000000-0000-4000-8000-00000000d002', eventTime: '2026-03-02T08:00:00.000Z', eventTimeZoneOffset: '+00:00', epcList: [record.passportId], action: 'OBSERVE', bizStep: 'inspecting' } }]] as const) {
|
|
174
|
+
const answer = await post(`/api/passports/${ref}/${path}`, body)
|
|
175
|
+
expect([answer.status, answer.body.error], path).toEqual([409, 'profile-retired'])
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
describe('a record that declares a retired profile is reported as not checked', () => {
|
|
181
|
+
it.each(RETIRED)('%s: the public view is unknown with profile-retired, whatever the payload holds', async (profile) => {
|
|
182
|
+
const { id, version } = parts(profile)
|
|
183
|
+
const passportId = mintPassportId(policy, '100000044', 'READ-0001')
|
|
184
|
+
for (const payloadPublic of [JSON.stringify({ profile: id, profile_version: version }), '{not json', JSON.stringify({ profile: id, profile_version: version, profile_binding_sha256: '0'.repeat(64), product: { id: passportId } })]) {
|
|
185
|
+
const validation = await platform.profiles.validatePublic({ profile: id, profileVersion: version, payloadPublic, passportId })
|
|
186
|
+
expect(validation).toEqual({ status: 'unknown', reasonCode: 'schema-unavailable', detail: { profile, cause: 'profile-retired', replacedBy: RETIRED_PROFILE_REPLACEMENTS[profile as keyof typeof RETIRED_PROFILE_REPLACEMENTS], steps: [] } })
|
|
187
|
+
const view = await platform.profiles.viewCheck('public', validation)
|
|
188
|
+
expect(view).toMatchObject({ view: 'public', status: 'not-checked', cause: 'profile-retired', steps: [], findings: [], withheld: [] })
|
|
189
|
+
expect(view.summary).toContain('retired profile')
|
|
190
|
+
expect(view.summary).toContain(`${RETIRED_PROFILE_REPLACEMENTS[profile as keyof typeof RETIRED_PROFILE_REPLACEMENTS]} replaces it`)
|
|
191
|
+
expect(view.summary).toContain('not a pass')
|
|
192
|
+
const authorised = await platform.profiles.validateAuthorised({ profile: id, profileVersion: version, payloadPublic, passportId, restrictedProduct: {} })
|
|
193
|
+
expect(authorised).toEqual(validation)
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
describe('what retirement leaves alone', () => {
|
|
199
|
+
it('general@2 is offered, sampled, checked and issued as before', async () => {
|
|
200
|
+
const sample = samplePayload('general@2', true)
|
|
201
|
+
expect(validatePayload('general@2', 'public', sample)).toEqual({ valid: true, problems: [] })
|
|
202
|
+
expect((await get('/api/profiles/general%402')).body).toMatchObject({ id: 'general@2', format: 'manifest' })
|
|
203
|
+
const { status, body } = await post(`/api/brands/${brandId}/passports`, { profile: 'general@2', itemReference: '100000045', serial: 'GEN-0001', payload: sample, ownerFields: {} })
|
|
204
|
+
expect(status).toBe(200)
|
|
205
|
+
expect(body).toMatchObject({ profile: 'general@2', status: 'active' })
|
|
206
|
+
expect(body).not.toHaveProperty('profileRetired')
|
|
207
|
+
const reading = await platform.read(body.passportId)
|
|
208
|
+
expect(reading.payloadChecks.map((c) => [c.profile, c.publicView.status])).toEqual([['general@2', 'pass']])
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('an identifier nobody published is still unknown, with its own code', async () => {
|
|
212
|
+
expect((await get('/api/profiles/toaster%409')).status).toBe(404)
|
|
213
|
+
const { status, body } = await post(`/api/brands/${brandId}/passports`, { profile: 'toaster@9', itemReference: '100000046', serial: 'T-1', payload: {} })
|
|
214
|
+
expect([status, body.error]).toEqual([400, 'profile-unknown'])
|
|
215
|
+
})
|
|
216
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Transaction, Utils } from '@bsv/sdk'
|
|
2
|
+
import { buildLockingScript, completeState, findDppOutputs, ownerBlobHash, ownerKeyFor } from '@bsv/dpp-protocol'
|
|
3
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
4
|
+
import { loadConfig } from '../src/config.js'
|
|
5
|
+
import { DEMONSTRATION_NOTICE } from '../src/profiles.js'
|
|
6
|
+
import { OWNER_DATA_PROTOCOL } from '../src/writer.js'
|
|
7
|
+
import type { PassportRecord } from '../src/store.js'
|
|
8
|
+
import { startApp, type TestApp } from './epcis-fixtures.js'
|
|
9
|
+
|
|
10
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
11
|
+
let app: TestApp
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
app = await startApp({ config })
|
|
15
|
+
const brand = app.platform.parties.brand('dev-brand')
|
|
16
|
+
await app.platform.store.saveBrand({ id: 'dev-brand', name: 'Development brand', identityKey: brand.identityKey, did: brand.did, createdAt: '2026-11-24T00:00:00.000Z' })
|
|
17
|
+
})
|
|
18
|
+
afterAll(async () => { await app?.close() })
|
|
19
|
+
|
|
20
|
+
// An earlier issuer uses the historical binding, the ordinary protocol signatures and a local test wallet.
|
|
21
|
+
async function historicalJournal(profile: string): Promise<PassportRecord> {
|
|
22
|
+
const { platform } = app
|
|
23
|
+
const bound = platform.profiles.get(profile)!
|
|
24
|
+
const { passportId, product } = (await app.get(`/api/profiles/${profile}`)).body.examples[0]
|
|
25
|
+
const prepared = await platform.profiles.prepare({ profile: bound, product, passportId, notice: DEMONSTRATION_NOTICE })
|
|
26
|
+
if (!prepared.ok) throw new Error(prepared.detail)
|
|
27
|
+
const brandId = 'dev-brand'
|
|
28
|
+
const actor = platform.parties.brand(brandId)
|
|
29
|
+
const controllerKey = await actor.controllerKey(passportId)
|
|
30
|
+
const { ciphertext } = await actor.wallet.encrypt({
|
|
31
|
+
plaintext: Utils.toArray(JSON.stringify(prepared.restrictedProduct ?? {}), 'utf8'), protocolID: OWNER_DATA_PROTOCOL, keyID: passportId, counterparty: 'self',
|
|
32
|
+
})
|
|
33
|
+
const hash = ownerBlobHash(ciphertext)
|
|
34
|
+
const timestamp = '2026-10-01T00:00:00Z'
|
|
35
|
+
const state = await completeState({
|
|
36
|
+
version: '2', op: 'ISSUE', passportId, timestamp, ownerIdentityKey: controllerKey, actorIdentityKey: actor.identityKey, actorKeyId: actor.name,
|
|
37
|
+
eventData: '', payloadPublic: prepared.payloadPublic, payloadOwnerHash: hash, previousTxid: '', previousOutputIndex: null, lineageGenesis: null,
|
|
38
|
+
controlLinkage: '', authorisationCommitment: '',
|
|
39
|
+
}, actor.wallet, platform.wallet.publisher)
|
|
40
|
+
const lockingScript = buildLockingScript(state, await ownerKeyFor(passportId, platform.wallet.publisher))
|
|
41
|
+
const built = await platform.wallet.adapter.build({ lockingScript, passportId })
|
|
42
|
+
const [output] = findDppOutputs(built.tx)
|
|
43
|
+
if (output == null) throw new Error('The historical transaction has no passport output.')
|
|
44
|
+
return {
|
|
45
|
+
passportId, brandId, profile, createdAt: timestamp, status: 'active', holder: { party: actor.name, controllerKey }, acceptanceRecords: [],
|
|
46
|
+
states: [{
|
|
47
|
+
op: 'ISSUE', txid: built.txid, outputIndex: output.outputIndex, rawTx: built.tx.toHex(), beef: Utils.toBase64(built.beef),
|
|
48
|
+
timestamp, actor: actor.name, controllerKey, payloadPublic: prepared.payloadPublic,
|
|
49
|
+
ownerTier: { hash, ciphertext: Utils.toBase64(ciphertext) }, index: 'admitted', network: 'dry-run',
|
|
50
|
+
}],
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe.each(['eu-battery@1', 'eu-textile@1'])('the cutover for %s', (profile) => {
|
|
55
|
+
const successor = profile.replace('@1', '@2')
|
|
56
|
+
let journal: PassportRecord
|
|
57
|
+
beforeAll(async () => { journal = await historicalJournal(profile) })
|
|
58
|
+
|
|
59
|
+
it('names the successor and refuses a new historical ISSUE before signing', async () => {
|
|
60
|
+
const catalogue = (await app.get('/api/profiles')).body as Array<{ id: string; issueSuccessor?: string }>
|
|
61
|
+
expect(catalogue.find(entry => entry.id === journal.profile)?.issueSuccessor).toBe(successor)
|
|
62
|
+
expect(catalogue.filter(entry => entry.issueSuccessor == null).map(entry => entry.id)).toContain(successor)
|
|
63
|
+
const response = await app.post('/api/brands/dev-brand/passports', { profile: journal.profile })
|
|
64
|
+
expect(response.status).toBe(409)
|
|
65
|
+
expect(response.body).toMatchObject({ error: 'profile-superseded', replacedBy: successor })
|
|
66
|
+
await expect(app.platform.writer.issue({ brandId: journal.brandId, brand: app.platform.parties.brand(journal.brandId), passportId: journal.passportId, profile: journal.profile })).rejects.toMatchObject({ code: 'profile-superseded', data: { replacedBy: successor } })
|
|
67
|
+
expect(await app.platform.store.getPassport(journal.passportId)).toBeUndefined()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('reads and maintains the original signed ISSUE on its original edition', async () => {
|
|
71
|
+
await app.platform.store.savePassport(journal)
|
|
72
|
+
expect(await app.platform.index.announce(Array.from(Buffer.from(journal.states[0].beef, 'base64')))).toBe('admitted')
|
|
73
|
+
const ref = encodeURIComponent(journal.passportId)
|
|
74
|
+
const reading = await app.get(`/api/verify?passportId=${ref}`)
|
|
75
|
+
expect(reading.status).toBe(200)
|
|
76
|
+
expect(reading.body.product.profile).toBe(journal.profile)
|
|
77
|
+
expect(reading.body.payloadChecks[0].publicView.status).toBe('pass')
|
|
78
|
+
expect((await app.post(`/api/passports/${ref}/authorised-view`, {})).body.authorisedView.status).toBe('pass')
|
|
79
|
+
const example = (await app.get(`/api/profiles/${journal.profile}`)).body.examples[0]
|
|
80
|
+
const response = await app.post(`/api/passports/${ref}/update`, { product: example.product })
|
|
81
|
+
expect(response.status, response.text).toBe(200)
|
|
82
|
+
const updated = (await app.platform.store.getPassport(journal.passportId))!
|
|
83
|
+
expect(updated.states.map(entry => entry.op)).toEqual(['ISSUE', 'UPDATE'])
|
|
84
|
+
expect(updated.profile).toBe(journal.profile)
|
|
85
|
+
expect(updated.states[0].rawTx).toBe(journal.states[0].rawTx)
|
|
86
|
+
const predecessor = findDppOutputs(Transaction.fromHex(updated.states[0].rawTx))[0]!
|
|
87
|
+
expect(predecessor.lockingPublicKey.toString()).toBe(await ownerKeyFor(journal.passportId, app.platform.wallet.publisher))
|
|
88
|
+
expect(predecessor.lockingPublicKey.toString()).not.toBe(predecessor.state.ownerIdentityKey)
|
|
89
|
+
const next = Transaction.fromAtomicBEEF(Utils.toArray(updated.states[1]!.beef, 'base64'))
|
|
90
|
+
const successor = findDppOutputs(next)[0]!
|
|
91
|
+
expect(successor.lockingPublicKey.toString()).toBe(successor.state.ownerIdentityKey)
|
|
92
|
+
expect(await next.verify('scripts only')).toBe(true)
|
|
93
|
+
expect((await app.post(`/api/passports/${ref}/authorised-view`, {})).body.authorisedView.status).toBe('pass')
|
|
94
|
+
})
|
|
95
|
+
})
|