@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,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "A valid document checked without saying which passport carries it.",
|
|
3
|
+
"kind": "payload",
|
|
4
|
+
"payload": {
|
|
5
|
+
"notice": "Demonstration record: this passport describes no real product.",
|
|
6
|
+
"profile": "example-notebook",
|
|
7
|
+
"profile_version": 1,
|
|
8
|
+
"profile_binding_sha256": "5261083e202d8a1acc6f4d45ba13fcbaa0e268511410fafde2e48251c9f4e7b4",
|
|
9
|
+
"product": {
|
|
10
|
+
"id": "https://id.example/01/09529876000101/21/NB-0001",
|
|
11
|
+
"title": "Field notebook A5",
|
|
12
|
+
"gtin": "09529876000101",
|
|
13
|
+
"serialNumber": "NB-0001",
|
|
14
|
+
"pages": 96,
|
|
15
|
+
"ruling": "dotted",
|
|
16
|
+
"paper": {
|
|
17
|
+
"recycledPercent": 100,
|
|
18
|
+
"gramsPerSquareMetre": 90
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"expected": {
|
|
23
|
+
"status": "unknown",
|
|
24
|
+
"cause": "product-identity-unavailable",
|
|
25
|
+
"step": "passport-identity"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Another notebook's valid document inside this passport.",
|
|
3
|
+
"kind": "payload",
|
|
4
|
+
"passportId": "https://passports.example/01/09529876000101/21/NB-0001",
|
|
5
|
+
"payload": {
|
|
6
|
+
"notice": "Demonstration record: this passport describes no real product.",
|
|
7
|
+
"profile": "example-notebook",
|
|
8
|
+
"profile_version": 1,
|
|
9
|
+
"profile_binding_sha256": "5261083e202d8a1acc6f4d45ba13fcbaa0e268511410fafde2e48251c9f4e7b4",
|
|
10
|
+
"product": {
|
|
11
|
+
"id": "https://id.example/01/09529876000101/21/NB-0002",
|
|
12
|
+
"title": "Field notebook A5",
|
|
13
|
+
"gtin": "09529876000101",
|
|
14
|
+
"serialNumber": "NB-0002",
|
|
15
|
+
"pages": 96,
|
|
16
|
+
"ruling": "dotted",
|
|
17
|
+
"paper": {
|
|
18
|
+
"recycledPercent": 100,
|
|
19
|
+
"gramsPerSquareMetre": 90
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"expected": {
|
|
24
|
+
"status": "fail",
|
|
25
|
+
"cause": "product-identity-mismatch",
|
|
26
|
+
"step": "passport-identity"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
+
import { PrivateKey } from '@bsv/sdk'
|
|
6
|
+
import { readEnvFile } from '../src/env-file.js'
|
|
7
|
+
import { startDevIndex, type DevIndex } from '../src/dev-index.js'
|
|
8
|
+
import { goLive, type GoLiveOptions } from '../src/go-live.js'
|
|
9
|
+
import { openPlatform } from '../src/platform.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* npm run go-live against an in-process index with registration open: the
|
|
13
|
+
* first run makes the root key, registers the publisher key, stores the two
|
|
14
|
+
* tokens and flips LIVE_PUBLISHING; a second run changes nothing; every
|
|
15
|
+
* failure names its fix. The test wallet stands in (DPP_TEST_WALLET=1), as
|
|
16
|
+
* it does in the scaffold check.
|
|
17
|
+
*/
|
|
18
|
+
const temps: string[] = []
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
for (const dir of temps) rmSync(dir, { recursive: true, force: true })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const secrets = { AUTH_SECRET: 'a'.repeat(64), BRAND_ROOT_SECRET: 'b'.repeat(64), MANAGED_IDENTITY_SECRET: 'c'.repeat(64) }
|
|
24
|
+
|
|
25
|
+
function project(env: Record<string, string>): { envFile: string; env: Record<string, string> } {
|
|
26
|
+
const dir = mkdtempSync(join(tmpdir(), 'dpp-go-live-'))
|
|
27
|
+
temps.push(dir)
|
|
28
|
+
const envFile = join(dir, '.env')
|
|
29
|
+
writeFileSync(envFile, Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n') + '\n')
|
|
30
|
+
return { envFile, env }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function run(index: DevIndex | { url: string }, overrides: Record<string, string> = {}, options: Partial<GoLiveOptions> = {}) {
|
|
34
|
+
const { envFile, env } = project({ NETWORK: 'test', INDEX_URL: index.url, DPP_TEST_WALLET: '1', PASSPORT_HOST: 'localhost:3000', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false', ...secrets, ...overrides })
|
|
35
|
+
const lines: string[] = []
|
|
36
|
+
const result = await goLive({ env: { ...env }, envFile, projectName: 'my-test-app', out: (line) => lines.push(line), ...options })
|
|
37
|
+
return { result, lines, envFile, file: readEnvFile(envFile) }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const failure = (result: { failures: Array<{ check: string }> }, check: string) => result.failures.find((f) => f.check === check)
|
|
41
|
+
|
|
42
|
+
describe('go-live', () => {
|
|
43
|
+
it('registers on the first run, stores the tokens and goes live; a second run keeps everything', async () => {
|
|
44
|
+
const index = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'open' })
|
|
45
|
+
try {
|
|
46
|
+
const first = await run(index)
|
|
47
|
+
expect(first.result.failures).toEqual([])
|
|
48
|
+
expect(first.result.ok).toBe(true)
|
|
49
|
+
expect(first.file.WALLET_ROOT_KEY).toMatch(/^[0-9a-f]{64}$/)
|
|
50
|
+
expect(first.file.INDEX_SUBMIT_TOKEN).toMatch(/^[0-9a-f]{64}$/)
|
|
51
|
+
expect(first.file.INDEX_CALLBACK_TOKEN).toMatch(/^[0-9a-f]{64}$/)
|
|
52
|
+
expect(first.file.LIVE_PUBLISHING).toBe('true')
|
|
53
|
+
const key = PrivateKey.fromHex(first.file.WALLET_ROOT_KEY).toPublicKey().toString()
|
|
54
|
+
const policy = (await (await fetch(`${index.url}/publisher-policy`)).json()) as Array<{ publishers: Array<{ key: string }> }>
|
|
55
|
+
expect(policy[policy.length - 1].publishers.map((p) => p.key)).toContain(key)
|
|
56
|
+
const output = first.lines.join('\n')
|
|
57
|
+
expect(output).toContain('DPP_TEST_WALLET')
|
|
58
|
+
expect(output).not.toContain(first.file.WALLET_ROOT_KEY)
|
|
59
|
+
expect(output).not.toContain(first.file.INDEX_SUBMIT_TOKEN)
|
|
60
|
+
expect(output).toContain(key)
|
|
61
|
+
expect(output).toMatch(/real satoshis/)
|
|
62
|
+
|
|
63
|
+
// The same file again: nothing re-registers, the tokens and the key stay.
|
|
64
|
+
const again = await goLive({ env: { ...first.file }, envFile: first.envFile, projectName: 'my-test-app', out: () => {} })
|
|
65
|
+
expect(again.failures).toEqual([])
|
|
66
|
+
const file = readEnvFile(first.envFile)
|
|
67
|
+
expect(file.INDEX_SUBMIT_TOKEN).toBe(first.file.INDEX_SUBMIT_TOKEN)
|
|
68
|
+
expect(file.WALLET_ROOT_KEY).toBe(first.file.WALLET_ROOT_KEY)
|
|
69
|
+
expect((await (await fetch(`${index.url}/publisher-policy`)).json()).length).toBe(policy.length)
|
|
70
|
+
} finally {
|
|
71
|
+
await index.close()
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('under approval, reports the wait and collects the tokens once the operator approved', async () => {
|
|
76
|
+
const index = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'approval' })
|
|
77
|
+
try {
|
|
78
|
+
const first = await run(index)
|
|
79
|
+
const pending = failure(first.result, 'registration')
|
|
80
|
+
expect(pending?.problem).toMatch(/approv/)
|
|
81
|
+
expect(pending?.fix).toContain('go-live')
|
|
82
|
+
expect(first.file.LIVE_PUBLISHING).toBe('false')
|
|
83
|
+
expect(first.file.INDEX_SUBMIT_TOKEN).toBeUndefined()
|
|
84
|
+
await index.approve!(PrivateKey.fromHex(first.file.WALLET_ROOT_KEY).toPublicKey().toString())
|
|
85
|
+
const second = await goLive({ env: { ...first.file }, envFile: first.envFile, projectName: 'my-test-app', out: () => {} })
|
|
86
|
+
expect(second.failures).toEqual([])
|
|
87
|
+
expect(readEnvFile(first.envFile).LIVE_PUBLISHING).toBe('true')
|
|
88
|
+
} finally {
|
|
89
|
+
await index.close()
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('decides LIVE_PUBLISHING itself: a file already saying true without tokens is not a dead end', async () => {
|
|
94
|
+
const index = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'open' })
|
|
95
|
+
try {
|
|
96
|
+
const result = await run(index, { LIVE_PUBLISHING: 'true' })
|
|
97
|
+
expect(result.result.failures).toEqual([])
|
|
98
|
+
expect(result.file.INDEX_SUBMIT_TOKEN).toMatch(/^[0-9a-f]{64}$/)
|
|
99
|
+
expect(result.file.LIVE_PUBLISHING).toBe('true')
|
|
100
|
+
} finally {
|
|
101
|
+
await index.close()
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('names the reason an index could not be reached, and a request the protocol refuses to sign, without a stack trace', async () => {
|
|
106
|
+
const unreachable = await run({ url: 'http://127.0.0.1:1' })
|
|
107
|
+
expect(failure(unreachable.result, 'index')?.problem).toMatch(/could not be reached: fetch failed \(.+\)/)
|
|
108
|
+
const index = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'open' })
|
|
109
|
+
try {
|
|
110
|
+
const bad = await run(index, {}, { projectName: 'my\u0007app' })
|
|
111
|
+
expect(failure(bad.result, 'registration')?.problem).toMatch(/label/)
|
|
112
|
+
expect(failure(bad.result, 'registration')?.fix).toContain('package.json')
|
|
113
|
+
} finally {
|
|
114
|
+
await index.close()
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('refuses a known host on the wrong network and a placeholder secret at configuration, before touching the wallet or the index', async () => {
|
|
119
|
+
const wrong = await run({ url: 'https://dpp-overlay.bsvb.net' })
|
|
120
|
+
expect(failure(wrong.result, 'configuration')?.problem).toMatch(/dpp-overlay\.bsvb\.net.*main/)
|
|
121
|
+
expect(wrong.file.WALLET_ROOT_KEY).toBeUndefined()
|
|
122
|
+
const wrongTestnet = await run({ url: 'https://dpp-overlay-testnet.bsvb.net' }, { NETWORK: 'main' })
|
|
123
|
+
expect(failure(wrongTestnet.result, 'configuration')?.fix).toContain('https://dpp-overlay-mainnet.bsvb.net')
|
|
124
|
+
expect(wrongTestnet.file.WALLET_ROOT_KEY).toBeUndefined()
|
|
125
|
+
const placeholder = await run({ url: 'https://dpp-overlay-testnet.bsvb.net' }, { AUTH_SECRET: 'change-me-to-32-random-bytes-hex' })
|
|
126
|
+
expect(failure(placeholder.result, 'configuration')?.problem).toContain('AUTH_SECRET')
|
|
127
|
+
expect(placeholder.lines.join('\n')).not.toContain('change-me-to-32-random-bytes-hex')
|
|
128
|
+
const mainnet = await run({ url: 'https://dpp-overlay.bsvb.net' }, { NETWORK: 'main' })
|
|
129
|
+
expect(mainnet.result.failures.filter((f) => f.check === 'configuration').map((f) => `${f.problem} ${f.fix}`).join(' ')).toMatch(/952.*licensed/)
|
|
130
|
+
expect(mainnet.result.failures.map((f) => f.problem).join(' ')).toContain('PASSPORT_HOST')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('names an unreachable index, a network mismatch and a custody profile mismatch at the index check', async () => {
|
|
134
|
+
const unreachable = await run({ url: 'http://127.0.0.1:1' })
|
|
135
|
+
expect(failure(unreachable.result, 'index')?.problem).toMatch(/reach/)
|
|
136
|
+
expect(failure(unreachable.result, 'index')?.fix).toContain('connect-index')
|
|
137
|
+
const mainnetIndex = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'main', registration: 'open' })
|
|
138
|
+
try {
|
|
139
|
+
const mismatch = await run(mainnetIndex)
|
|
140
|
+
expect(failure(mismatch.result, 'index')?.problem).toMatch(/main.*test|test.*main/)
|
|
141
|
+
} finally {
|
|
142
|
+
await mainnetIndex.close()
|
|
143
|
+
}
|
|
144
|
+
const baseline = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'open', custody: 'record-model-baseline@2' })
|
|
145
|
+
try {
|
|
146
|
+
const custody = await run(baseline)
|
|
147
|
+
expect(failure(custody.result, 'index')?.problem).toContain('record-model-baseline@2')
|
|
148
|
+
} finally {
|
|
149
|
+
await baseline.close()
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('reports an index that does not register, and empty funds with the funding address', async () => {
|
|
154
|
+
const closed = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test' })
|
|
155
|
+
try {
|
|
156
|
+
const refused = await run(closed)
|
|
157
|
+
expect(failure(refused.result, 'registration')?.problem).toMatch(/does not register/)
|
|
158
|
+
expect(failure(refused.result, 'registration')?.fix).toContain('connect-index')
|
|
159
|
+
} finally {
|
|
160
|
+
await closed.close()
|
|
161
|
+
}
|
|
162
|
+
const index = await startDevIndex({ publisherKey: PrivateKey.fromHex('79'.repeat(32)).toPublicKey().toString(), network: 'test', registration: 'open' })
|
|
163
|
+
try {
|
|
164
|
+
const broke = await run(index, {}, {
|
|
165
|
+
openPlatform: async (options) => {
|
|
166
|
+
const platform = await openPlatform(options)
|
|
167
|
+
platform.wallet.balance = async () => 0
|
|
168
|
+
return platform
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
expect(failure(broke.result, 'funds')?.problem).toMatch(/0 satoshis/)
|
|
172
|
+
expect(failure(broke.result, 'funds')?.fix).toMatch(/wallet fund/)
|
|
173
|
+
expect(broke.file.INDEX_SUBMIT_TOKEN).toMatch(/^[0-9a-f]{64}$/)
|
|
174
|
+
expect(broke.file.LIVE_PUBLISHING).toBe('false')
|
|
175
|
+
} finally {
|
|
176
|
+
await index.close()
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The EPCIS tests validate against the EPCIS files GS1 publishes, and this
|
|
2
|
+
// project does not contain them: GS1 publishes them under its own terms. This
|
|
3
|
+
// set-up obtains the three pinned files once, into a cache folder, and checks
|
|
4
|
+
// every byte against its pinned digest. The tests then read them offline.
|
|
5
|
+
//
|
|
6
|
+
// A run that cannot obtain a file fails here, before any test, and says which
|
|
7
|
+
// file and why. It never skips: a skipped validation test would read as a
|
|
8
|
+
// pass.
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
import { GS1_ARTEFACTS_DIR_ENV, provisionGs1Artefacts } from '@bsv/dpp-credentials'
|
|
11
|
+
|
|
12
|
+
/** The folder the tests read the GS1 files from: the one DPP_GS1_ARTEFACTS_DIR names, or a cache folder under this project's node_modules. */
|
|
13
|
+
export function gs1TestDir(): string {
|
|
14
|
+
const named = process.env[GS1_ARTEFACTS_DIR_ENV]
|
|
15
|
+
return named != null && named !== '' ? named : join(import.meta.dirname, '..', '..', '..', 'node_modules', '.cache', 'dpp-gs1')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default async function setup(): Promise<void> {
|
|
19
|
+
const dir = gs1TestDir()
|
|
20
|
+
const report = await provisionGs1Artefacts({ dir })
|
|
21
|
+
if (report.ok) return
|
|
22
|
+
const failed = report.files.filter((file) => file.outcome === 'failed').map((file) => ` ${file.fileName}: ${file.reason}: ${file.detail}`)
|
|
23
|
+
const error = new Error(
|
|
24
|
+
[
|
|
25
|
+
`The EPCIS tests need the pinned GS1 files in ${dir} and ${failed.length} could not be provisioned:`,
|
|
26
|
+
...failed,
|
|
27
|
+
`Run the tests with network access to https://ref.gs1.org/, or place the files GS1 publishes in that folder under these names, or point ${GS1_ARTEFACTS_DIR_ENV} at a folder that holds them. No test is skipped for want of them.`,
|
|
28
|
+
].join('\n')
|
|
29
|
+
)
|
|
30
|
+
// The message is the whole report. A stack through the test runner adds nothing and can hide it.
|
|
31
|
+
error.stack = `${error.name}: ${error.message}`
|
|
32
|
+
throw error
|
|
33
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Each test worker reads the folder the global set-up provisioned, the same way a deployment names its own.
|
|
2
|
+
import { GS1_ARTEFACTS_DIR_ENV } from '@bsv/dpp-credentials'
|
|
3
|
+
import { gs1TestDir } from './gs1-global-setup.js'
|
|
4
|
+
|
|
5
|
+
process.env[GS1_ARTEFACTS_DIR_ENV] = gs1TestDir()
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// The identifier host, over HTTP. A passport identifier is a GS1 Digital
|
|
2
|
+
// Link under PASSPORT_HOST, and the standard asks the host an identifier is
|
|
3
|
+
// minted under to be a GS1-Conformant Resolver for primary key 01
|
|
4
|
+
// (spec/gs1-discovery.md §1, rule 6). These tests issue one passport with the
|
|
5
|
+
// writer and then ask the server what a scanner, a discovery client and a
|
|
6
|
+
// browser would ask: the resolver description, the identifier with each
|
|
7
|
+
// Accept, a malformed and an unknown identifier, each method, and the walk
|
|
8
|
+
// from the identifier to the passport's verification.
|
|
9
|
+
//
|
|
10
|
+
// The item's GTIN and serial are the ones GS1's compression standard uses in
|
|
11
|
+
// its worked example, which is under the demonstration prefix, so the two
|
|
12
|
+
// compressed forms that standard publishes spell this passport's identifier.
|
|
13
|
+
import { once } from 'node:events'
|
|
14
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import type { Server } from 'node:http'
|
|
16
|
+
import type { AddressInfo } from 'node:net'
|
|
17
|
+
import { tmpdir } from 'node:os'
|
|
18
|
+
import { join } from 'node:path'
|
|
19
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
20
|
+
import { DPP_EVIDENCE_PACKAGE_LINK_TYPE, GS1_LINK_TYPES, JSON_LD_CONTEXT_RELATION, LINKSET_CONTEXT_URI, describeResolver, selectLink, type LinksetDocument } from '@bsv/dpp-profiles'
|
|
21
|
+
import { holderLabel, offerIdFromPath, publicPathOf } from '../../web/src/lib/format'
|
|
22
|
+
import { loadConfig } from '../src/config.js'
|
|
23
|
+
import { mintGtin, mintPassportId } from '../src/identifiers.js'
|
|
24
|
+
import { openPlatform, type Platform } from '../src/platform.js'
|
|
25
|
+
import { samplePayload } from '../src/profiles.js'
|
|
26
|
+
import type { PassportReading } from '../src/reader.js'
|
|
27
|
+
import { createServer } from '../src/server.js'
|
|
28
|
+
|
|
29
|
+
const config = loadConfig({ NETWORK: 'main', PASSPORT_HOST: 'passports.example.com', GS1_PREFIX: '952', LIVE_PUBLISHING: 'false' })
|
|
30
|
+
const policy = { host: config.passportHost, prefix: config.gs1Prefix }
|
|
31
|
+
const ROOT = `https://${policy.host}`
|
|
32
|
+
const GTIN = '09528765123457'
|
|
33
|
+
const SERIAL = '123456789123'
|
|
34
|
+
const ITEM = `/01/${GTIN}/21/${SERIAL}`
|
|
35
|
+
const PRODUCT = `/01/${GTIN}`
|
|
36
|
+
/** A GTIN under the same prefix that no passport was issued under. */
|
|
37
|
+
const OTHER_GTIN = mintGtin(policy.prefix, '876512346')
|
|
38
|
+
const SHELL = '<!doctype html><title>The web app</title>'
|
|
39
|
+
const BROWSER = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
|
40
|
+
const LINKSET = 'application/linkset+json'
|
|
41
|
+
|
|
42
|
+
const webDist = mkdtempSync(join(tmpdir(), 'dpp-identifier-host-'))
|
|
43
|
+
let platform: Platform
|
|
44
|
+
let server: Server
|
|
45
|
+
let base: string
|
|
46
|
+
let passportId: string
|
|
47
|
+
|
|
48
|
+
// Issuing a passport signs and announces a state, so the set-up has a time limit of its own.
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
platform = await openPlatform({ config, mode: 'test', log: () => {} })
|
|
51
|
+
passportId = mintPassportId(policy, '876512345', SERIAL)
|
|
52
|
+
await platform.writer.issue({ brandId: 'dev-brand', brand: platform.parties.brand('dev-brand'), passportId, profile: 'general@2', payload: samplePayload('general@2', true), ownerFields: {} })
|
|
53
|
+
// The built web app is one page whatever the path. A stand-in for it shows that a redirect's target answers.
|
|
54
|
+
writeFileSync(join(webDist, 'index.html'), SHELL)
|
|
55
|
+
server = createServer({ platform, webDist }).listen(0, '127.0.0.1')
|
|
56
|
+
await once(server, 'listening')
|
|
57
|
+
base = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
|
|
58
|
+
}, 30_000)
|
|
59
|
+
|
|
60
|
+
afterAll(async () => {
|
|
61
|
+
server.close()
|
|
62
|
+
await platform.close()
|
|
63
|
+
rmSync(webDist, { recursive: true, force: true })
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/** One request that follows no redirect, so a redirect is seen as the answer it is. */
|
|
67
|
+
const ask = (path: string, accept?: string, method = 'GET'): Promise<Response> => fetch(`${base}${path}`, { method, redirect: 'manual', headers: accept == null ? {} : { accept } })
|
|
68
|
+
const linksetOf = async (response: Response): Promise<LinksetDocument> => (await response.json()) as LinksetDocument
|
|
69
|
+
|
|
70
|
+
describe('the identifier host', () => {
|
|
71
|
+
it('mints the identifier the tests ask for', () => {
|
|
72
|
+
expect(passportId).toBe(`${ROOT}${ITEM}`)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('publishes the resolver description for primary key 01', async () => {
|
|
76
|
+
const response = await ask('/.well-known/gs1resolver')
|
|
77
|
+
expect(response.status).toBe(200)
|
|
78
|
+
expect(response.headers.get('content-type')).toContain('application/json')
|
|
79
|
+
const body = await response.json()
|
|
80
|
+
expect(body).toEqual(describeResolver({ resolverRoot: ROOT }))
|
|
81
|
+
expect(body).toMatchObject({ resolverRoot: ROOT, supportedPrimaryKeys: ['01'], linkTypeDefaultCanBeLinkset: false, jsonLdContextLocation: LINKSET_CONTEXT_URI })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('redirects a browser from the identifier to the passport page with 307, and the page answers', async () => {
|
|
85
|
+
const response = await ask(ITEM, BROWSER)
|
|
86
|
+
expect(response.status).toBe(307)
|
|
87
|
+
const location = response.headers.get('location')
|
|
88
|
+
expect(location).toBe(`/passport${ITEM}`)
|
|
89
|
+
// The web app links to the same page the resolver redirects to.
|
|
90
|
+
expect(location).toBe(publicPathOf(passportId))
|
|
91
|
+
const page = await ask(location!, BROWSER)
|
|
92
|
+
expect(page.status).toBe(200)
|
|
93
|
+
expect(page.headers.get('content-type')).toContain('text/html')
|
|
94
|
+
expect(await page.text()).toBe(SHELL)
|
|
95
|
+
// A client that states no preference is redirected too, and the whole query string is passed on.
|
|
96
|
+
expect((await ask(ITEM)).status).toBe(307)
|
|
97
|
+
expect((await ask(`${ITEM}?lang=en&17=261231`)).headers.get('location')).toBe(`/passport${ITEM}?lang=en&17=261231`)
|
|
98
|
+
// One trailing slash is tolerated, and the item is found under a lot it was not registered with.
|
|
99
|
+
expect((await ask(`${ITEM}/`)).headers.get('location')).toBe(`/passport${ITEM}`)
|
|
100
|
+
expect((await ask(`/01/${GTIN}/10/LOT-1/21/${SERIAL}`)).headers.get('location')).toBe(`/passport${ITEM}`)
|
|
101
|
+
// The passport page is asked for by its link type as well.
|
|
102
|
+
expect((await ask(`${ITEM}?linkType=gs1:dpp`)).headers.get('location')).toBe(`/passport${ITEM}?linkType=gs1:dpp`)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('gives the linkset to a client that asks for it, and never redirects that request', async () => {
|
|
106
|
+
const response = await ask(ITEM, LINKSET)
|
|
107
|
+
expect(response.status).toBe(200)
|
|
108
|
+
expect(response.headers.get('content-type')).toContain(LINKSET)
|
|
109
|
+
expect(response.headers.get('link')).toBe(`<${LINKSET_CONTEXT_URI}>; rel="${JSON_LD_CONTEXT_RELATION}"; type="application/ld+json"`)
|
|
110
|
+
const linkset = await linksetOf(response)
|
|
111
|
+
const passportPage = { href: `${ROOT}/passport${ITEM}`, title: 'Digital product passport' }
|
|
112
|
+
const productPage = { href: `${ROOT}/passport${PRODUCT}`, title: 'Product information' }
|
|
113
|
+
// The item first, then its GTIN, each anchored at its own identifier, and only the links this application serves.
|
|
114
|
+
expect(linkset).toEqual({
|
|
115
|
+
linkset: [
|
|
116
|
+
{ anchor: `${ROOT}${ITEM}`, [GS1_LINK_TYPES.dpp]: [passportPage], [GS1_LINK_TYPES.defaultLink]: [passportPage] },
|
|
117
|
+
{ anchor: `${ROOT}${PRODUCT}`, [GS1_LINK_TYPES.pip]: [productPage], [GS1_LINK_TYPES.defaultLink]: [productPage] },
|
|
118
|
+
],
|
|
119
|
+
})
|
|
120
|
+
expect(selectLink(linkset, { rel: 'gs1:dpp' })).toMatchObject({ outcome: 'selected', link: passportPage, scope: { granularity: 'item' } })
|
|
121
|
+
expect(selectLink(linkset, { rel: DPP_EVIDENCE_PACKAGE_LINK_TYPE }).outcome).toBe('not-found')
|
|
122
|
+
// The same answer for linkType=linkset from a browser, for a request for JSON, and beside a named link type.
|
|
123
|
+
for (const [path, accept] of [
|
|
124
|
+
[`${ITEM}?linkType=linkset`, BROWSER],
|
|
125
|
+
[ITEM, 'application/json'],
|
|
126
|
+
[`${ITEM}?linkType=gs1:dpp`, LINKSET],
|
|
127
|
+
] as const) {
|
|
128
|
+
const again = await ask(path, accept)
|
|
129
|
+
expect(again.status, path).toBe(200)
|
|
130
|
+
expect(await linksetOf(again), path).toEqual(linkset)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('answers the GTIN alone, and a serial nobody issued under it, with the product page and never with a passport', async () => {
|
|
135
|
+
const product = await ask(PRODUCT, BROWSER)
|
|
136
|
+
expect(product.status).toBe(307)
|
|
137
|
+
expect(product.headers.get('location')).toBe(`/passport${PRODUCT}`)
|
|
138
|
+
expect((await ask(`/passport${PRODUCT}`, BROWSER)).status).toBe(200)
|
|
139
|
+
// The resolver standard walks a request up to the GTIN's default (section 2.5.9). The answer is about the product, and the linkset says so by its anchor.
|
|
140
|
+
const stranger = `/01/${GTIN}/21/NOBODY-ISSUED-THIS`
|
|
141
|
+
expect((await ask(stranger, BROWSER)).headers.get('location')).toBe(`/passport${PRODUCT}`)
|
|
142
|
+
const linkset = await linksetOf(await ask(stranger, LINKSET))
|
|
143
|
+
expect(linkset.linkset.map((entry) => entry.anchor)).toEqual([`${ROOT}${PRODUCT}`])
|
|
144
|
+
expect(selectLink(linkset, { rel: 'gs1:dpp' }).outcome).toBe('not-found')
|
|
145
|
+
// No passport link exists for it, so asking for one by type is refused.
|
|
146
|
+
const refused = await ask(`${stranger}?linkType=gs1:dpp`)
|
|
147
|
+
expect(refused.status).toBe(404)
|
|
148
|
+
expect(await refused.json()).toMatchObject({ error: 'link-type-unknown' })
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('refuses a malformed identifier with 400 and one this application did not issue with 404', async () => {
|
|
152
|
+
for (const [path, reason] of [
|
|
153
|
+
['/01', 'primary-key-not-a-gtin'],
|
|
154
|
+
['/01/123', 'primary-key-not-a-gtin'],
|
|
155
|
+
[`/01/${GTIN}/21`, 'trailing-segment'],
|
|
156
|
+
[`/01/${GTIN}/21/A/10/B`, 'qualifier-order'],
|
|
157
|
+
[`/01/${GTIN}/21/${'A'.repeat(21)}`, 'qualifier-value'],
|
|
158
|
+
[`/01/${GTIN}/99/A`, 'qualifier-unsupported'],
|
|
159
|
+
[`/01/${GTIN}?21=${SERIAL}`, 'key-in-query'],
|
|
160
|
+
[`/01/${GTIN.slice(0, 13)}0/21/${SERIAL}`, 'check-digit'],
|
|
161
|
+
] as const) {
|
|
162
|
+
for (const accept of [BROWSER, LINKSET]) {
|
|
163
|
+
const response = await ask(path, accept)
|
|
164
|
+
expect(response.status, path).toBe(400)
|
|
165
|
+
expect(await response.json(), path).toMatchObject({ error: 'identifier-malformed', reason })
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const path of [`/01/${OTHER_GTIN}`, `/01/${OTHER_GTIN}/21/${SERIAL}`, `/01/${OTHER_GTIN}?linkType=linkset`]) {
|
|
169
|
+
for (const accept of [BROWSER, LINKSET]) {
|
|
170
|
+
const response = await ask(path, accept)
|
|
171
|
+
expect(response.status, path).toBe(404)
|
|
172
|
+
expect(await response.json(), path).toMatchObject({ error: 'identifier-unknown' })
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('answers GET, HEAD and OPTIONS from any origin, and no other method', async () => {
|
|
178
|
+
const cors = (response: Response, what: string): void => {
|
|
179
|
+
expect(response.headers.get('access-control-allow-origin'), what).toBe('*')
|
|
180
|
+
expect(response.headers.get('access-control-allow-methods'), what).toBe('GET, HEAD, OPTIONS')
|
|
181
|
+
expect(response.headers.get('vary'), what).toContain('Accept')
|
|
182
|
+
}
|
|
183
|
+
for (const [path, accept, status] of [
|
|
184
|
+
['/.well-known/gs1resolver', undefined, 200],
|
|
185
|
+
[ITEM, LINKSET, 200],
|
|
186
|
+
[ITEM, BROWSER, 307],
|
|
187
|
+
['/01/123', BROWSER, 400],
|
|
188
|
+
[`/01/${OTHER_GTIN}`, BROWSER, 404],
|
|
189
|
+
] as const) {
|
|
190
|
+
const got = await ask(path, accept)
|
|
191
|
+
expect(got.status, path).toBe(status)
|
|
192
|
+
cors(got, `GET ${path}`)
|
|
193
|
+
const head = await ask(path, accept, 'HEAD')
|
|
194
|
+
expect(head.status, path).toBe(status)
|
|
195
|
+
expect(await head.text(), path).toBe('')
|
|
196
|
+
cors(head, `HEAD ${path}`)
|
|
197
|
+
const options = await ask(path, accept, 'OPTIONS')
|
|
198
|
+
expect(options.status, path).toBe(204)
|
|
199
|
+
cors(options, `OPTIONS ${path}`)
|
|
200
|
+
}
|
|
201
|
+
const post = await ask(ITEM, undefined, 'POST')
|
|
202
|
+
expect(post.status).toBe(405)
|
|
203
|
+
expect(post.headers.get('allow')).toBe('GET, HEAD, OPTIONS')
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('decompresses an EPC binary string and answers it as the identifier it spells', async () => {
|
|
207
|
+
// The two worked examples of the compression standard: one SGTIN-96, in hexadecimal and in URI-safe base 64.
|
|
208
|
+
for (const compressed of ['/eh30164596f40c0e5cbe991a83', '/exMBZFlvQMDly-mRqD']) {
|
|
209
|
+
const response = await ask(compressed, BROWSER)
|
|
210
|
+
expect(response.status, compressed).toBe(307)
|
|
211
|
+
expect(response.headers.get('location'), compressed).toBe(`/passport${ITEM}`)
|
|
212
|
+
// A linkset is anchored at the decompressed form.
|
|
213
|
+
const linkset = await linksetOf(await ask(compressed, LINKSET))
|
|
214
|
+
expect(linkset.linkset[0]!.anchor, compressed).toBe(`${ROOT}${ITEM}`)
|
|
215
|
+
}
|
|
216
|
+
// A string of the same form that is no SGTIN is refused, not passed to the web app.
|
|
217
|
+
const refused = await ask('/eh310000000000000000000000')
|
|
218
|
+
expect(refused.status).toBe(400)
|
|
219
|
+
expect(await refused.json()).toMatchObject({ error: 'identifier-malformed', reason: 'unsupported-epc-scheme' })
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it(
|
|
223
|
+
'walks from the identifier to the verification of its passport',
|
|
224
|
+
async () => {
|
|
225
|
+
// A scanner asks for the identifier and is sent to the page.
|
|
226
|
+
const redirect = await ask(ITEM, BROWSER)
|
|
227
|
+
const pagePath = redirect.headers.get('location')!
|
|
228
|
+
// A discovery client asks for the links, selects the passport and reaches the same page.
|
|
229
|
+
const selected = selectLink(await linksetOf(await ask(ITEM, LINKSET)), { rel: GS1_LINK_TYPES.dpp })
|
|
230
|
+
expect(selected.outcome === 'selected' && new URL(selected.link.href).pathname).toBe(pagePath)
|
|
231
|
+
// The page reads the passport whose identifier is the passport host and its own path without the page prefix: the identifier that was scanned.
|
|
232
|
+
const identifier = `${ROOT}${pagePath.slice('/passport'.length)}`
|
|
233
|
+
expect(identifier).toBe(passportId)
|
|
234
|
+
const reading = (await (await fetch(`${base}/api/verify?passportId=${encodeURIComponent(identifier)}`)).json()) as PassportReading
|
|
235
|
+
expect(reading.passportId).toBe(passportId)
|
|
236
|
+
expect(reading.lineage.map((state) => state.op)).toEqual(['ISSUE'])
|
|
237
|
+
const status = (name: string): string | undefined => reading.checks.find((check) => check.name === name)?.status
|
|
238
|
+
expect(status('recordEncoding')).toBe('pass')
|
|
239
|
+
expect(status('actorSignatures')).toBe('pass')
|
|
240
|
+
expect(status('publisherSignatures')).toBe('pass')
|
|
241
|
+
},
|
|
242
|
+
20_000
|
|
243
|
+
)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
describe('custody offer links', () => {
|
|
247
|
+
it.each(['supplier/id', 'supplier%2Fid', 'offer:part:two', 'offer-previous-1'])('preserves the exact request ID %s', (id) => {
|
|
248
|
+
const link = new URL(`/accept/${encodeURIComponent(id)}`, 'https://issuer.example')
|
|
249
|
+
expect(offerIdFromPath(link.pathname)).toBe(id)
|
|
250
|
+
expect(holderLabel(`recipient:${id}`)).toBe(`Recipient of offer ${id}`)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('refuses a link with an invalid escape', () => {
|
|
254
|
+
expect(offerIdFromPath('/accept/bad%')).toBeUndefined()
|
|
255
|
+
})
|
|
256
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
5
|
+
import { readEnvFile } from '../src/env-file.js'
|
|
6
|
+
import { connectIndex } from '../src/index-projects.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* connect-index writes a provider's address and tokens and runs the checks.
|
|
10
|
+
* --from takes them from the connection file an index operator writes with
|
|
11
|
+
* dpp-index connection, in the form that command prints.
|
|
12
|
+
*/
|
|
13
|
+
const temps: string[] = []
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
for (const dir of temps) rmSync(dir, { recursive: true, force: true })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const secrets = { AUTH_SECRET: 'a'.repeat(64), BRAND_ROOT_SECRET: 'b'.repeat(64), MANAGED_IDENTITY_SECRET: 'c'.repeat(64) }
|
|
19
|
+
|
|
20
|
+
function app(): { root: string; envFile: string } {
|
|
21
|
+
const parent = mkdtempSync(join(tmpdir(), 'dpp-index-projects-'))
|
|
22
|
+
temps.push(parent)
|
|
23
|
+
const root = join(parent, 'my-app')
|
|
24
|
+
mkdirSync(root)
|
|
25
|
+
const envFile = join(root, '.env')
|
|
26
|
+
writeFileSync(envFile, `NETWORK=test\nINDEX_URL=\nINDEX_SUBMIT_TOKEN=\nINDEX_CALLBACK_TOKEN=\nLIVE_PUBLISHING=false\nDPP_TEST_WALLET=1\nWALLET_ROOT_KEY=${'77'.repeat(32)}\n`)
|
|
27
|
+
return { root, envFile }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('connect-index', () => {
|
|
31
|
+
it('writes the address and the tokens given, then runs the checks against the file', async () => {
|
|
32
|
+
const { root, envFile } = app()
|
|
33
|
+
const lines: string[] = []
|
|
34
|
+
const result = await connectIndex({ env: { ...secrets, ...readEnvFile(envFile) }, envFile, projectName: 'my-app', out: (line) => lines.push(line), url: 'http://127.0.0.1:1/', submitToken: 'd'.repeat(64), callbackToken: 'e'.repeat(64) })
|
|
35
|
+
const file = readEnvFile(envFile)
|
|
36
|
+
expect(file.INDEX_URL).toBe('http://127.0.0.1:1')
|
|
37
|
+
expect(file.INDEX_SUBMIT_TOKEN).toBe('d'.repeat(64))
|
|
38
|
+
expect(file.INDEX_CALLBACK_TOKEN).toBe('e'.repeat(64))
|
|
39
|
+
// The checks ran: the index at port 1 is unreachable.
|
|
40
|
+
expect(result.ok).toBe(false)
|
|
41
|
+
expect(result.failures.map((f) => f.check)).toEqual(['index'])
|
|
42
|
+
expect(existsSync(join(root, '.env'))).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('needs an address', async () => {
|
|
46
|
+
const { envFile } = app()
|
|
47
|
+
const result = await connectIndex({ env: { ...secrets }, envFile, projectName: 'my-app', out: () => {}, url: '' })
|
|
48
|
+
expect(result.failures[0]?.fix).toContain('--url')
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('connect-index --from', () => {
|
|
53
|
+
function connection(dir: string, network: string): string {
|
|
54
|
+
const path = join(dir, 'app.env')
|
|
55
|
+
writeFileSync(path, `# The index connection for an application server.\nNETWORK=${network}\nINDEX_URL=http://127.0.0.1:1/\nINDEX_SUBMIT_TOKEN=${'f'.repeat(64)}\nINDEX_CALLBACK_TOKEN=${'9'.repeat(64)}\n`)
|
|
56
|
+
return path
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
it('takes the address and both tokens from the operator\'s connection file, never printing a token, then runs the checks', async () => {
|
|
60
|
+
const { root, envFile } = app()
|
|
61
|
+
const lines: string[] = []
|
|
62
|
+
const result = await connectIndex({ env: { ...secrets, ...readEnvFile(envFile) }, envFile, projectName: 'my-app', out: (line) => lines.push(line), from: connection(root, 'test') })
|
|
63
|
+
const file = readEnvFile(envFile)
|
|
64
|
+
expect(file.INDEX_URL).toBe('http://127.0.0.1:1')
|
|
65
|
+
expect(file.INDEX_SUBMIT_TOKEN).toBe('f'.repeat(64))
|
|
66
|
+
expect(file.INDEX_CALLBACK_TOKEN).toBe('9'.repeat(64))
|
|
67
|
+
expect(file.LIVE_PUBLISHING).toBe('false')
|
|
68
|
+
expect(result.failures.map((f) => f.check)).toEqual(['index'])
|
|
69
|
+
expect(lines.join('\n')).not.toContain('f'.repeat(64))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('refuses a file for the other network and a missing file, before writing anything', async () => {
|
|
73
|
+
const { root, envFile } = app()
|
|
74
|
+
const env = { ...secrets, ...readEnvFile(envFile) }
|
|
75
|
+
const other = await connectIndex({ env, envFile, projectName: 'my-app', out: () => {}, from: connection(root, 'main') })
|
|
76
|
+
expect(other.failures[0]?.problem).toContain('main index')
|
|
77
|
+
const missing = await connectIndex({ env, envFile, projectName: 'my-app', out: () => {}, from: join(root, 'absent.env') })
|
|
78
|
+
expect(missing.failures[0]?.problem).toContain('does not exist')
|
|
79
|
+
expect(readEnvFile(envFile).INDEX_URL).toBe('')
|
|
80
|
+
})
|
|
81
|
+
})
|