@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,64 @@
|
|
|
1
|
+
// The public pages, where the resolver sends a browser that asked for an
|
|
2
|
+
// identifier: /passport/01/<gtin>/21/<serial> for an item's passport, and
|
|
3
|
+
// /passport/01/<gtin> for the product. The identifier is the platform's
|
|
4
|
+
// passport host plus the path after /passport, which is what the brand
|
|
5
|
+
// minted; in development the API's host may differ from the Vite origin, so
|
|
6
|
+
// the host comes from /api/health before the origin is assumed.
|
|
7
|
+
import { Link, useLocation, useParams } from 'react-router'
|
|
8
|
+
import { Button } from '@/components/ui/button'
|
|
9
|
+
import { CopyButton, ErrorNotice, Loading, Mono, PageTitle } from '@/components/bits'
|
|
10
|
+
import { ReadPassport } from '@/components/read-passport'
|
|
11
|
+
import { PAGE_PREFIX } from '@/lib/format'
|
|
12
|
+
import { useHealth } from '@/lib/session'
|
|
13
|
+
|
|
14
|
+
/** The identifier a public page is about: the passport host, or this origin when the API has not said, and the page's path without its prefix. */
|
|
15
|
+
function useIdentifier(): { identifier: string; loading: boolean; error: unknown } {
|
|
16
|
+
const { health, loading, error } = useHealth()
|
|
17
|
+
const location = useLocation()
|
|
18
|
+
const host = health?.identifiers.host
|
|
19
|
+
const path = location.pathname.slice(PAGE_PREFIX.length)
|
|
20
|
+
return { identifier: host == null || host === '' ? `${window.location.origin}${path}` : `https://${host}${path}`, loading, error }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function PublicPassport() {
|
|
24
|
+
const { identifier, loading, error } = useIdentifier()
|
|
25
|
+
|
|
26
|
+
if (loading) return <Loading what="Reading the passport" />
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="mx-auto max-w-2xl space-y-6">
|
|
30
|
+
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
31
|
+
<ReadPassport passportId={identifier} />
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The page a product's identifier leads to. A passport belongs to one item, so this page holds none: it says what the identifier names and where an item's passport is found. */
|
|
37
|
+
export function PublicProduct() {
|
|
38
|
+
const { identifier, loading, error } = useIdentifier()
|
|
39
|
+
const { gtin } = useParams()
|
|
40
|
+
|
|
41
|
+
if (loading) return <Loading />
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="mx-auto max-w-2xl space-y-6">
|
|
45
|
+
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
46
|
+
<PageTitle
|
|
47
|
+
title={`GTIN ${gtin ?? ''}`}
|
|
48
|
+
description={
|
|
49
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
50
|
+
<Mono>{identifier}</Mono>
|
|
51
|
+
<CopyButton text={identifier} label="Copy the identifier" />
|
|
52
|
+
</span>
|
|
53
|
+
}
|
|
54
|
+
/>
|
|
55
|
+
<p className="text-sm leading-relaxed">
|
|
56
|
+
This identifier names a product, not one item of it. A passport belongs to one item and is found under the item's own identifier, which ends with its serial: <Mono>{identifier}/21/<serial></Mono>. Scan the code on the item, or paste its
|
|
57
|
+
identifier to verify it.
|
|
58
|
+
</p>
|
|
59
|
+
<Button asChild variant="outline">
|
|
60
|
+
<Link to="/verify">Verify a passport</Link>
|
|
61
|
+
</Button>
|
|
62
|
+
</div>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useState, type FormEvent } from 'react'
|
|
2
|
+
import { Link, useNavigate } from 'react-router'
|
|
3
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
4
|
+
import { Button } from '@/components/ui/button'
|
|
5
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
|
6
|
+
import { Input } from '@/components/ui/input'
|
|
7
|
+
import { ErrorNotice, Field, Loading } from '@/components/bits'
|
|
8
|
+
import { authClient } from '@/lib/auth'
|
|
9
|
+
import { useHealth } from '@/lib/session'
|
|
10
|
+
|
|
11
|
+
export function SignIn({ mode }: { mode: 'sign-in' | 'sign-up' }) {
|
|
12
|
+
const { health, loading, error: healthError } = useHealth()
|
|
13
|
+
const navigate = useNavigate()
|
|
14
|
+
const [email, setEmail] = useState('')
|
|
15
|
+
const [password, setPassword] = useState('')
|
|
16
|
+
const [name, setName] = useState('')
|
|
17
|
+
const [busy, setBusy] = useState(false)
|
|
18
|
+
const [error, setError] = useState<string>()
|
|
19
|
+
const signingUp = mode === 'sign-up'
|
|
20
|
+
|
|
21
|
+
if (loading) return <Loading />
|
|
22
|
+
if (healthError != null) return <ErrorNotice error={healthError} title="The API is not answering" />
|
|
23
|
+
if (!health?.signIn) {
|
|
24
|
+
return (
|
|
25
|
+
<div className="mx-auto max-w-md">
|
|
26
|
+
<Alert>
|
|
27
|
+
<AlertTitle>Sign-in is off</AlertTitle>
|
|
28
|
+
<AlertDescription>
|
|
29
|
+
<p>
|
|
30
|
+
{health?.devSession == null ? 'This platform has no sign-in configured.' : 'You are the developer, a member of Development brand. Configure MongoDB for sign-in.'}{' '}
|
|
31
|
+
<Link to="/" className="underline underline-offset-4">
|
|
32
|
+
Home
|
|
33
|
+
</Link>
|
|
34
|
+
</p>
|
|
35
|
+
</AlertDescription>
|
|
36
|
+
</Alert>
|
|
37
|
+
</div>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function submit(event: FormEvent) {
|
|
42
|
+
event.preventDefault()
|
|
43
|
+
setBusy(true)
|
|
44
|
+
setError(undefined)
|
|
45
|
+
try {
|
|
46
|
+
const result = signingUp ? await authClient.signUp.email({ email, password, name }) : await authClient.signIn.email({ email, password })
|
|
47
|
+
if (result.error != null) {
|
|
48
|
+
setError(result.error.message ?? (signingUp ? 'Sign-up failed' : 'Sign-in failed'))
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
navigate('/brands')
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
54
|
+
} finally {
|
|
55
|
+
setBusy(false)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="mx-auto max-w-md">
|
|
61
|
+
<Card>
|
|
62
|
+
<CardHeader>
|
|
63
|
+
<CardTitle>{signingUp ? 'Sign up' : 'Sign in'}</CardTitle>
|
|
64
|
+
<CardDescription>{signingUp ? 'An account to create brands and issue passports.' : 'Email and password.'}</CardDescription>
|
|
65
|
+
</CardHeader>
|
|
66
|
+
<CardContent>
|
|
67
|
+
<form onSubmit={submit} className="space-y-4">
|
|
68
|
+
{signingUp ? (
|
|
69
|
+
<Field label="Name" htmlFor="name" required>
|
|
70
|
+
<Input id="name" value={name} onChange={(e) => setName(e.target.value)} required autoComplete="name" />
|
|
71
|
+
</Field>
|
|
72
|
+
) : null}
|
|
73
|
+
<Field label="Email" htmlFor="email" required>
|
|
74
|
+
<Input id="email" type="email" value={email} onChange={(e) => setEmail(e.target.value)} required autoComplete="email" />
|
|
75
|
+
</Field>
|
|
76
|
+
<Field label="Password" htmlFor="password" required help={signingUp ? 'At least eight characters.' : undefined}>
|
|
77
|
+
<Input id="password" type="password" value={password} onChange={(e) => setPassword(e.target.value)} required minLength={signingUp ? 8 : undefined} autoComplete={signingUp ? 'new-password' : 'current-password'} />
|
|
78
|
+
</Field>
|
|
79
|
+
{error == null ? null : <ErrorNotice error={new Error(error)} title={signingUp ? 'Sign-up failed' : 'Sign-in failed'} />}
|
|
80
|
+
<div className="flex items-center justify-between gap-3">
|
|
81
|
+
<Button type="submit" disabled={busy}>
|
|
82
|
+
{busy ? 'Working' : signingUp ? 'Sign up' : 'Sign in'}
|
|
83
|
+
</Button>
|
|
84
|
+
<Link to={signingUp ? '/sign-in' : '/sign-up'} className="text-sm text-muted-foreground underline-offset-4 hover:underline">
|
|
85
|
+
{signingUp ? 'Have an account? Sign in' : 'New here? Sign up'}
|
|
86
|
+
</Link>
|
|
87
|
+
</div>
|
|
88
|
+
</form>
|
|
89
|
+
</CardContent>
|
|
90
|
+
</Card>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, type FormEvent } from 'react'
|
|
2
|
+
import { useSearchParams } from 'react-router'
|
|
3
|
+
import { Button } from '@/components/ui/button'
|
|
4
|
+
import { Input } from '@/components/ui/input'
|
|
5
|
+
import { PageTitle } from '@/components/bits'
|
|
6
|
+
import { ReadPassport } from '@/components/read-passport'
|
|
7
|
+
|
|
8
|
+
export function Verify() {
|
|
9
|
+
const [params, setParams] = useSearchParams()
|
|
10
|
+
const current = params.get('passportId') ?? ''
|
|
11
|
+
const [input, setInput] = useState(current)
|
|
12
|
+
|
|
13
|
+
function submit(event: FormEvent) {
|
|
14
|
+
event.preventDefault()
|
|
15
|
+
const passportId = input.trim()
|
|
16
|
+
if (passportId === '') return
|
|
17
|
+
setParams({ passportId })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="mx-auto max-w-2xl space-y-8">
|
|
22
|
+
<PageTitle title="Verify a passport" description="Paste the identifier printed on the product or read from its QR code. The report is one answer per check; there is no overall score." />
|
|
23
|
+
<form onSubmit={submit} className="flex flex-col gap-2 sm:flex-row">
|
|
24
|
+
<Input value={input} onChange={(e) => setInput(e.target.value)} placeholder="https://host/01/<gtin>/21/<serial>" aria-label="Passport identifier" required spellCheck={false} />
|
|
25
|
+
<Button type="submit">Verify</Button>
|
|
26
|
+
</form>
|
|
27
|
+
{current === '' ? null : <ReadPassport key={current} passportId={current} manageLink publicLink />}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useState, type FormEvent } from 'react'
|
|
2
|
+
import { Button } from '@/components/ui/button'
|
|
3
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
|
4
|
+
import { Input } from '@/components/ui/input'
|
|
5
|
+
import { CopyButton, DefinitionList, ErrorNotice, Field, Loading, Mono, PageTitle, YesNo } from '@/components/bits'
|
|
6
|
+
import { RequireAccount } from '@/components/layout'
|
|
7
|
+
import { api, type FundingAddress } from '@/lib/api'
|
|
8
|
+
import { useLoad } from '@/lib/use-load'
|
|
9
|
+
|
|
10
|
+
export function Wallet() {
|
|
11
|
+
return (
|
|
12
|
+
<RequireAccount>
|
|
13
|
+
<WalletPage />
|
|
14
|
+
</RequireAccount>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function WalletPage() {
|
|
19
|
+
const wallet = useLoad(() => api.wallet(), [])
|
|
20
|
+
const [funding, setFunding] = useState<FundingAddress>()
|
|
21
|
+
const [fundingBusy, setFundingBusy] = useState(false)
|
|
22
|
+
const [fundingError, setFundingError] = useState<unknown>()
|
|
23
|
+
const [txid, setTxid] = useState('')
|
|
24
|
+
const [taking, setTaking] = useState(false)
|
|
25
|
+
const [taken, setTaken] = useState<number>()
|
|
26
|
+
const [takeError, setTakeError] = useState<unknown>()
|
|
27
|
+
|
|
28
|
+
async function newAddress() {
|
|
29
|
+
setFundingBusy(true)
|
|
30
|
+
setFundingError(undefined)
|
|
31
|
+
setTaken(undefined)
|
|
32
|
+
try {
|
|
33
|
+
setFunding(await api.fundingAddress())
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
setFundingError(cause)
|
|
36
|
+
} finally {
|
|
37
|
+
setFundingBusy(false)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function takeIn(event: FormEvent) {
|
|
42
|
+
event.preventDefault()
|
|
43
|
+
if (funding == null) return
|
|
44
|
+
setTaking(true)
|
|
45
|
+
setTakeError(undefined)
|
|
46
|
+
setTaken(undefined)
|
|
47
|
+
try {
|
|
48
|
+
const answer = await api.internalize(txid.trim(), funding)
|
|
49
|
+
setTaken(answer.satoshis)
|
|
50
|
+
setTxid('')
|
|
51
|
+
wallet.reload()
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
setTakeError(cause)
|
|
54
|
+
} finally {
|
|
55
|
+
setTaking(false)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="space-y-10">
|
|
61
|
+
<PageTitle title="Wallet" description="The platform wallet publishes passport states and pays the fees. The current holder’s managed key controls each new passport output." />
|
|
62
|
+
{wallet.loading ? (
|
|
63
|
+
<Loading what="Loading the wallet" />
|
|
64
|
+
) : wallet.error != null || wallet.data == null ? (
|
|
65
|
+
<ErrorNotice error={wallet.error ?? new Error('no answer')} title="Could not load the wallet" />
|
|
66
|
+
) : (
|
|
67
|
+
<DefinitionList
|
|
68
|
+
entries={[
|
|
69
|
+
['Kind', wallet.data.kind === 'toolbox' ? 'toolbox (a wallet with a root key)' : 'test (fixed keys, nothing reaches the chain)'],
|
|
70
|
+
['Network', wallet.data.network],
|
|
71
|
+
[
|
|
72
|
+
'Identity key',
|
|
73
|
+
<span key="k" className="flex items-center gap-2">
|
|
74
|
+
<Mono>{wallet.data.identityKey}</Mono>
|
|
75
|
+
<CopyButton text={wallet.data.identityKey} label="Copy the identity key" />
|
|
76
|
+
</span>,
|
|
77
|
+
],
|
|
78
|
+
['Balance', `${wallet.data.balance.toLocaleString()} satoshis`],
|
|
79
|
+
[
|
|
80
|
+
'Live publishing',
|
|
81
|
+
<span key="l" className="flex flex-col gap-1">
|
|
82
|
+
<YesNo value={wallet.data.livePublishing} />
|
|
83
|
+
{wallet.data.livePublishing ? null : <span className="text-xs text-muted-foreground">LIVE_PUBLISHING is false: states are built, checked and admitted as drafts, then aborted before the send.</span>}
|
|
84
|
+
</span>,
|
|
85
|
+
],
|
|
86
|
+
]}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
|
|
90
|
+
<div className="grid gap-6 lg:grid-cols-2">
|
|
91
|
+
<Card>
|
|
92
|
+
<CardHeader>
|
|
93
|
+
<CardTitle>Fund the wallet</CardTitle>
|
|
94
|
+
<CardDescription>A fresh address to pay. The platform derives the key for the prefix and suffix shown; keep both to take the payment in.</CardDescription>
|
|
95
|
+
</CardHeader>
|
|
96
|
+
<CardContent className="space-y-4">
|
|
97
|
+
<Button onClick={newAddress} disabled={fundingBusy} variant="outline">
|
|
98
|
+
{fundingBusy ? 'Working' : 'New funding address'}
|
|
99
|
+
</Button>
|
|
100
|
+
{fundingError == null ? null : <ErrorNotice error={fundingError} title="No address" />}
|
|
101
|
+
{funding == null ? null : (
|
|
102
|
+
<DefinitionList
|
|
103
|
+
entries={[
|
|
104
|
+
[
|
|
105
|
+
'Address',
|
|
106
|
+
<span key="a" className="flex items-center gap-2">
|
|
107
|
+
<Mono className="text-sm">{funding.address}</Mono>
|
|
108
|
+
<CopyButton text={funding.address} label="Copy the address" />
|
|
109
|
+
</span>,
|
|
110
|
+
],
|
|
111
|
+
['Derivation prefix', <Mono key="p">{funding.derivationPrefix}</Mono>],
|
|
112
|
+
['Derivation suffix', <Mono key="s">{funding.derivationSuffix}</Mono>],
|
|
113
|
+
['Sender identity key', <Mono key="i">{funding.senderIdentityKey}</Mono>],
|
|
114
|
+
]}
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
</CardContent>
|
|
118
|
+
</Card>
|
|
119
|
+
|
|
120
|
+
<Card>
|
|
121
|
+
<CardHeader>
|
|
122
|
+
<CardTitle>Take in a payment</CardTitle>
|
|
123
|
+
<CardDescription>The txid of a payment to the last funding address above.</CardDescription>
|
|
124
|
+
</CardHeader>
|
|
125
|
+
<CardContent>
|
|
126
|
+
<form onSubmit={takeIn} className="space-y-4">
|
|
127
|
+
<Field label="Txid" htmlFor="txid" required help={funding == null ? 'Make a funding address first; the payment must go to it.' : `For the address ${funding.address}.`}>
|
|
128
|
+
<Input id="txid" value={txid} onChange={(e) => setTxid(e.target.value)} required pattern="[0-9a-fA-F]{64}" spellCheck={false} disabled={funding == null} />
|
|
129
|
+
</Field>
|
|
130
|
+
{takeError == null ? null : <ErrorNotice error={takeError} title="Not taken in" />}
|
|
131
|
+
{taken == null ? null : <p className="text-sm">Took in {taken.toLocaleString()} satoshis.</p>}
|
|
132
|
+
<Button type="submit" disabled={taking || funding == null || txid.trim() === ''}>
|
|
133
|
+
{taking ? 'Working' : 'Take in'}
|
|
134
|
+
</Button>
|
|
135
|
+
</form>
|
|
136
|
+
</CardContent>
|
|
137
|
+
</Card>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2022",
|
|
6
|
+
"DOM",
|
|
7
|
+
"DOM.Iterable"
|
|
8
|
+
],
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"paths": {
|
|
18
|
+
"@/*": [
|
|
19
|
+
"./src/*"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"types": [
|
|
23
|
+
"vite/client"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"include": [
|
|
27
|
+
"src"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
4
|
+
import { defineConfig, loadEnv } from 'vite'
|
|
5
|
+
|
|
6
|
+
// In development Vite serves the pages and proxies to the API what the API
|
|
7
|
+
// answers itself: /api, and the identifier host's paths, which are every path
|
|
8
|
+
// under /01, the resolver description and a compressed identifier
|
|
9
|
+
// (apps/api/src/resolver.ts). Vite answers an OPTIONS request itself, before
|
|
10
|
+
// its proxy. In production the API serves the built pages itself
|
|
11
|
+
// (apps/web/dist).
|
|
12
|
+
const projectRoot = fileURLToPath(new URL('../../', import.meta.url))
|
|
13
|
+
const { PORT } = loadEnv('development', projectRoot, 'PORT')
|
|
14
|
+
const api = { target: process.env.API_URL ?? `http://127.0.0.1:${PORT || '3000'}`, changeOrigin: false }
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
plugins: [react(), tailwindcss()],
|
|
18
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
19
|
+
server: {
|
|
20
|
+
port: 5173,
|
|
21
|
+
proxy: { '/api': api, '^/01(/|\\?|$)': api, '^/\\.well-known/gs1resolver/?(\\?|$)': api, '^/e[hx][A-Za-z0-9_-]{16,}/?(\\?|$)': api },
|
|
22
|
+
},
|
|
23
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# MongoDB for the application's records and sign-in. Start it with:
|
|
2
|
+
#
|
|
3
|
+
# docker compose -f deploy/compose.yml --env-file .env up -d
|
|
4
|
+
#
|
|
5
|
+
# Connect the app to an existing index with INDEX_URL and its access tokens,
|
|
6
|
+
# or operate one separately with the DPP repository's operator preset (deploy/).
|
|
7
|
+
# This Compose file does not start an index. See README.md, Connect an index.
|
|
8
|
+
#
|
|
9
|
+
# It does not start a validator service either. By default the application
|
|
10
|
+
# validates in its own process. To use a service instead, set VALIDATOR_URL to
|
|
11
|
+
# one an operator runs, such as the validator of the DPP repository's operator
|
|
12
|
+
# preset, or start one beside the app with `npx dpp-validator`. See README.md,
|
|
13
|
+
# The validation engine.
|
|
14
|
+
#
|
|
15
|
+
# MongoDB is named by tag and digest: the tag says which version the digest
|
|
16
|
+
# was resolved from, and the digest is what is pulled, so two machines run the
|
|
17
|
+
# same image. It is the pin the DPP repository's operator preset uses. MongoDB
|
|
18
|
+
# Community Server is its publisher's program under the Server Side Public
|
|
19
|
+
# License, pulled from its publisher; it is not part of this project.
|
|
20
|
+
name: dpp-platform
|
|
21
|
+
|
|
22
|
+
services:
|
|
23
|
+
mongo:
|
|
24
|
+
image: mongo:7.0.48@sha256:9896df581dfd0718b7abe112f4c37598d0986c54060e4ec1384997e6503c8c71
|
|
25
|
+
restart: unless-stopped
|
|
26
|
+
command: ["mongod", "--bind_ip_all"]
|
|
27
|
+
ports:
|
|
28
|
+
- "${MONGO_PORT:-27017}:27017"
|
|
29
|
+
volumes:
|
|
30
|
+
- mongo-data:/data/db
|
|
31
|
+
healthcheck:
|
|
32
|
+
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 }).ok"]
|
|
33
|
+
interval: 10s
|
|
34
|
+
timeout: 5s
|
|
35
|
+
retries: 12
|
|
36
|
+
|
|
37
|
+
volumes:
|
|
38
|
+
mongo-data:
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-dpp",
|
|
3
|
+
"private": true,
|
|
4
|
+
"description": "A Digital Product Passport application on BSV, scaffolded by @bsv/create-dpp-app",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"workspaces": [
|
|
8
|
+
"apps/*"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "concurrently -n api,web -c blue,green \"npm run dev -w api\" \"npm run dev -w web\"",
|
|
15
|
+
"build": "npm run build -w api && npm run build -w web",
|
|
16
|
+
"typecheck": "npm run typecheck --workspaces --if-present",
|
|
17
|
+
"test": "npm run test --workspaces --if-present",
|
|
18
|
+
"lint": "oxlint apps",
|
|
19
|
+
"format": "prettier --write \"apps/**/*.{ts,tsx,css,json}\"",
|
|
20
|
+
"start": "node apps/api/dist/main.js",
|
|
21
|
+
"wallet": "tsx apps/api/src/cli.ts wallet",
|
|
22
|
+
"operations": "tsx apps/api/src/cli.ts operations",
|
|
23
|
+
"go-live": "tsx apps/api/src/cli.ts go-live",
|
|
24
|
+
"connect-index": "tsx apps/api/src/cli.ts connect-index",
|
|
25
|
+
"export": "tsx apps/api/src/cli.ts export",
|
|
26
|
+
"restore": "tsx apps/api/src/cli.ts restore",
|
|
27
|
+
"epcis-remap": "tsx apps/api/src/cli.ts epcis-remap"
|
|
28
|
+
},
|
|
29
|
+
"dpp": {
|
|
30
|
+
"releaseSet": "dpp-release-2026-11"
|
|
31
|
+
},
|
|
32
|
+
"overrides": {
|
|
33
|
+
"@bsv/overlay": {
|
|
34
|
+
"@bsv/sdk": "2.8.10"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"concurrently": "^9.2.1",
|
|
39
|
+
"oxlint": "^1.87.0",
|
|
40
|
+
"prettier": "^3.9.9",
|
|
41
|
+
"typescript": "^7.0.2"
|
|
42
|
+
},
|
|
43
|
+
"allowScripts": {
|
|
44
|
+
"better-sqlite3@13.0.3": true,
|
|
45
|
+
"esbuild@0.28.2": true,
|
|
46
|
+
"mongodb-memory-server@11.2.0": false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"declaration": false,
|
|
11
|
+
"sourceMap": true
|
|
12
|
+
}
|
|
13
|
+
}
|