forked from veridatum-labs/earnproof-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverification-panel.tsx
More file actions
143 lines (135 loc) · 4.34 KB
/
Copy pathverification-panel.tsx
File metadata and controls
143 lines (135 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { ArtifactExport } from "@/components/proofs/artifact-export";
import { appConfig } from "@/config/app";
import { buildCredentialExport, buildVerificationLinkExport } from "@/lib/credentials/export";
export type VerificationResult =
| "VALID"
| "EXPIRED"
| "REVOKED"
| "INVALID_SIGNATURE"
| "UNKNOWN_PROOF"
| "UNVERIFIED_ISSUER";
export type VerifyProofResponse = {
result: VerificationResult;
status: "valid" | "expired" | "revoked" | "unknown" | "invalid";
credential?: {
id: string;
schemaVersion: string;
subject: {
walletHash: string;
};
claim: {
operator: "gte";
thresholdAmount: string;
assetCode: string;
assetIssuer: string | null;
periodStart: string;
periodEnd: string;
qualifyingPaymentCount: number;
};
privacy: {
exactIncomeHidden: boolean;
sourceTransactionsHidden: boolean;
};
issuedAt: string;
expiresAt: string;
proof: {
type: string;
credentialHash: string;
signature: string;
};
};
proof?: {
id: string;
type: string;
schemaVersion: string;
network: string;
issuedAt: string;
expiresAt: string;
revokedAt: string | null;
};
};
export const statusStyles: Record<VerifyProofResponse["status"], string> = {
valid: "border-emerald-300/30 bg-emerald-300/10 text-emerald-100",
expired: "border-amber-300/30 bg-amber-300/10 text-amber-100",
revoked: "border-rose-300/30 bg-rose-300/10 text-rose-100",
unknown: "border-slate-300/20 bg-slate-300/10 text-slate-100",
invalid: "border-rose-300/30 bg-rose-300/10 text-rose-100",
};
export function formatDate(value: string) {
return new Intl.DateTimeFormat("en", {
dateStyle: "medium",
timeStyle: "short",
}).format(new Date(value));
}
export function ResultItem({ label, value }: { label: string; value: string }) {
return (
<div className="min-w-0">
<dt className="text-xs font-semibold uppercase text-slate-400">{label}</dt>
<dd className="mt-1 break-words text-slate-100">{value}</dd>
</div>
);
}
export function VerificationPanel({ result }: { result: VerifyProofResponse | null }) {
if (!result) {
return null;
}
return (
<div className="rounded-lg border border-white/10 bg-white/[0.04] p-5">
<div
className={`inline-flex rounded-md border px-3 py-1 text-sm font-semibold uppercase ${statusStyles[result.status]}`}
>
{result.status}
</div>
{result.credential && result.proof ? (
<>
<dl className="mt-5 grid gap-4 text-sm text-slate-300 sm:grid-cols-2">
<ResultItem label="Proof ID" value={result.proof.id} />
<ResultItem label="Network" value={result.proof.network} />
<ResultItem
label="Claim"
value={`Income ${result.credential.claim.operator} ${result.credential.claim.thresholdAmount} ${result.credential.claim.assetCode}`}
/>
<ResultItem
label="Qualifying payments"
value={String(result.credential.claim.qualifyingPaymentCount)}
/>
<ResultItem
label="Period"
value={`${formatDate(result.credential.claim.periodStart)} to ${formatDate(
result.credential.claim.periodEnd,
)}`}
/>
<ResultItem label="Expires" value={formatDate(result.proof.expiresAt)} />
<ResultItem
label="Wallet hash"
value={result.credential.subject.walletHash}
/>
<ResultItem
label="Credential hash"
value={result.credential.proof.credentialHash}
/>
</dl>
<div className="mt-5 grid gap-3 sm:grid-cols-2">
<ArtifactExport
plan={buildCredentialExport({
credential: result.credential,
proof: result.proof,
})}
title="Export credential JSON"
/>
<ArtifactExport
plan={buildVerificationLinkExport(
`${appConfig.appUrl}/verify?proof=${encodeURIComponent(result.proof.id)}`,
)}
title="Export verification link"
/>
</div>
</>
) : (
<p className="mt-5 text-sm leading-6 text-slate-300">
No matching EarnProof credential was found for this identifier.
</p>
)}
</div>
);
}