@terminal3/seal-web 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +111 -2
- package/dist/codec.d.ts +19 -0
- package/dist/codec.js +65 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +147 -0
- package/dist/delivery.d.ts +63 -0
- package/dist/delivery.js +135 -0
- package/dist/elements.d.ts +2 -0
- package/dist/elements.js +353 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +16 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/jwe.d.ts +69 -0
- package/dist/jwe.js +213 -0
- package/dist/passkey.d.ts +38 -0
- package/dist/passkey.js +142 -0
- package/dist/session.d.ts +26 -0
- package/dist/session.js +90 -0
- package/package.json +41 -4
package/dist/elements.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// <t3-safebox ref="sealed:…" label="…" source="…" auto-open>: a sealed item,
|
|
2
|
+
// opened only in this browser and dropped from the page a minute later, or
|
|
3
|
+
// as soon as the element leaves the page.
|
|
4
|
+
// <t3-safebox-form ref="request:…">: a sealed request, drawn from its signed
|
|
5
|
+
// description. Both wait in `data-state="waiting"` until `configure` has run,
|
|
6
|
+
// then render into a shadow root of the configured mode, attached once, and
|
|
7
|
+
// render again on each later `configure`. Both take their accent from
|
|
8
|
+
// `--seal-accent` and `--seal-accent-soft`.
|
|
9
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
11
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
12
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
|
+
};
|
|
14
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
15
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
16
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
18
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
19
|
+
};
|
|
20
|
+
import { toB64 } from "./codec.js";
|
|
21
|
+
import { configured, onConfigure } from "./config.js";
|
|
22
|
+
import { confirmItem, describe, openItem, submit } from "./delivery.js";
|
|
23
|
+
import { SealError } from "./errors.js";
|
|
24
|
+
const SHOWN_MS = 60000;
|
|
25
|
+
const LOCK = `<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><rect x="4.5" y="10.5" width="15" height="10" rx="2.5" stroke="currentColor" stroke-width="1.8"/><path d="M8 10.5V7.8a4 4 0 0 1 8 0v2.7" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><circle cx="12" cy="15.5" r="1.4" fill="currentColor"/></svg>`;
|
|
26
|
+
const OPEN = `<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><rect x="4.5" y="10.5" width="15" height="10" rx="2.5" stroke="currentColor" stroke-width="1.8"/><path d="M8 10.5V7.8a4 4 0 0 1 7.7-1.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>`;
|
|
27
|
+
const FORM = `<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><rect x="5" y="3.5" width="14" height="17" rx="2.5" stroke="currentColor" stroke-width="1.8"/><path d="M8.5 8h7M8.5 12h7M8.5 16h4" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>`;
|
|
28
|
+
const STYLE = `
|
|
29
|
+
:host{display:block;max-width:360px;font:14px/1.45 -apple-system,BlinkMacSystemFont,"Helvetica Neue",Arial,sans-serif;color:#1d1d1f}
|
|
30
|
+
.box{background:#fff;border:1px solid #ebe6e1;border-left:4px solid var(--seal-accent,#c8102e);border-radius:14px;padding:14px 16px;box-shadow:0 1px 2px rgba(30,20,10,.05),0 6px 22px rgba(30,20,10,.06)}
|
|
31
|
+
.head{display:flex;align-items:center;gap:10px}
|
|
32
|
+
.ic{width:34px;height:34px;border-radius:10px;background:var(--seal-accent-soft,#fdf1f3);color:var(--seal-accent,#c8102e);display:grid;place-items:center;flex:none}
|
|
33
|
+
.t{font-weight:650;font-size:14.5px}
|
|
34
|
+
.s{font-size:12px;color:#7a7a82}
|
|
35
|
+
.sum{margin-top:10px;font-weight:600}
|
|
36
|
+
.fields{margin-top:12px;border-top:1px solid #f0ece8}
|
|
37
|
+
.f{display:flex;justify-content:space-between;gap:12px;padding:8px 0;border-bottom:1px solid #f0ece8}
|
|
38
|
+
.f span{color:#7a7a82;font-size:12.5px}
|
|
39
|
+
.f b{font-weight:600;text-align:right}
|
|
40
|
+
.mono{font-family:ui-monospace,"SF Mono",Menlo,monospace;letter-spacing:.02em}
|
|
41
|
+
.row{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:12px}
|
|
42
|
+
button{font:inherit;font-weight:600;border-radius:10px;padding:8px 14px;cursor:pointer;border:0;background:var(--seal-accent,#c8102e);color:#fff}
|
|
43
|
+
button.ghost{background:#fff;color:#1d1d1f;border:1px solid #d9d3cd}
|
|
44
|
+
button:disabled{opacity:.55;cursor:default}
|
|
45
|
+
.err{color:#b3261e;font-size:12.5px;margin-top:10px}
|
|
46
|
+
.ok{color:#1c7c3c;font-weight:600;font-size:13px;margin-top:10px}
|
|
47
|
+
.note{font-size:11.5px;color:#7a7a82}
|
|
48
|
+
.who{margin-top:10px;background:#faf8f6;border:1px solid #f0ece8;border-radius:10px;padding:8px 10px;font-size:12.5px}
|
|
49
|
+
.who div{margin:2px 0}
|
|
50
|
+
.who b{font-weight:600}
|
|
51
|
+
.desc{margin-top:8px;font-size:12.5px;color:#5c5c66}
|
|
52
|
+
label{display:block;margin-top:10px;font-size:12.5px;color:#5c5c66}
|
|
53
|
+
input,select{display:block;width:100%;box-sizing:border-box;margin-top:4px;font:inherit;padding:8px 10px;border:1px solid #d9d3cd;border-radius:9px;background:#fff}
|
|
54
|
+
input[type=file]{padding:6px}
|
|
55
|
+
.or{margin-top:10px;font-size:11.5px;color:#7a7a82;text-transform:uppercase;letter-spacing:.04em}
|
|
56
|
+
.thumb{margin-top:8px;max-width:100%;max-height:150px;border-radius:8px;border:1px solid #ebe6e1}
|
|
57
|
+
:host([data-kind=table]){max-width:640px}
|
|
58
|
+
.tw{margin-top:8px;max-height:330px;overflow:auto;border:1px solid #f0ece8;border-radius:10px}
|
|
59
|
+
table{border-collapse:collapse;width:100%;font-size:12px}
|
|
60
|
+
th{position:sticky;top:0;background:#faf8f6;color:#7a7a82;font-weight:600;text-align:left;padding:6px 7px;border-bottom:1px solid #ebe6e1;white-space:nowrap}
|
|
61
|
+
td{padding:5px 7px;border-bottom:1px solid #f4f1ee;vertical-align:top}
|
|
62
|
+
`;
|
|
63
|
+
const esc = (s) => String(s ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
64
|
+
const messageOf = (e) => (e instanceof Error ? e.message : String(e));
|
|
65
|
+
const rpName = () => configured()?.rpName ?? "";
|
|
66
|
+
const shadowMode = () => configured()?.shadow ?? "closed";
|
|
67
|
+
/** Defines both elements once; a no-op where they are already defined. */
|
|
68
|
+
export function defineElements() {
|
|
69
|
+
var _T3Safebox_root, _T3Safebox_unlisten, _T3Safebox_data, _T3Safebox_label, _T3Safebox_confirmed, _T3Safebox_error, _T3Safebox_hideTimer, _T3SafeboxForm_root, _T3SafeboxForm_unlisten, _T3SafeboxForm_desc, _T3SafeboxForm_files, _T3SafeboxForm_error;
|
|
70
|
+
class T3Safebox extends HTMLElement {
|
|
71
|
+
constructor() {
|
|
72
|
+
super(...arguments);
|
|
73
|
+
_T3Safebox_root.set(this, null);
|
|
74
|
+
_T3Safebox_unlisten.set(this, null);
|
|
75
|
+
_T3Safebox_data.set(this, null);
|
|
76
|
+
_T3Safebox_label.set(this, null);
|
|
77
|
+
_T3Safebox_confirmed.set(this, false);
|
|
78
|
+
_T3Safebox_error.set(this, null);
|
|
79
|
+
_T3Safebox_hideTimer.set(this, void 0);
|
|
80
|
+
}
|
|
81
|
+
connectedCallback() {
|
|
82
|
+
__classPrivateFieldSet(this, _T3Safebox_unlisten, __classPrivateFieldGet(this, _T3Safebox_unlisten, "f") ?? onConfigure(() => (__classPrivateFieldGet(this, _T3Safebox_root, "f") ? this.render() : this.start())), "f");
|
|
83
|
+
if (configured())
|
|
84
|
+
this.start();
|
|
85
|
+
else
|
|
86
|
+
this.setAttribute("data-state", "waiting");
|
|
87
|
+
}
|
|
88
|
+
disconnectedCallback() {
|
|
89
|
+
clearTimeout(__classPrivateFieldGet(this, _T3Safebox_hideTimer, "f"));
|
|
90
|
+
// A detached element keeps no opened content, in memory or in its shadow root.
|
|
91
|
+
if (__classPrivateFieldGet(this, _T3Safebox_root, "f"))
|
|
92
|
+
this.hide();
|
|
93
|
+
__classPrivateFieldGet(this, _T3Safebox_unlisten, "f")?.call(this);
|
|
94
|
+
__classPrivateFieldSet(this, _T3Safebox_unlisten, null, "f");
|
|
95
|
+
}
|
|
96
|
+
start() {
|
|
97
|
+
__classPrivateFieldSet(this, _T3Safebox_root, __classPrivateFieldGet(this, _T3Safebox_root, "f") ?? this.attachShadow({ mode: shadowMode() }), "f");
|
|
98
|
+
this.setAttribute("data-state", "sealed");
|
|
99
|
+
this.render();
|
|
100
|
+
if (this.hasAttribute("auto-open"))
|
|
101
|
+
void this.reveal();
|
|
102
|
+
}
|
|
103
|
+
async reveal() {
|
|
104
|
+
const btn = __classPrivateFieldGet(this, _T3Safebox_root, "f")?.querySelector("#reveal");
|
|
105
|
+
if (btn)
|
|
106
|
+
btn.disabled = true;
|
|
107
|
+
__classPrivateFieldSet(this, _T3Safebox_error, null, "f");
|
|
108
|
+
try {
|
|
109
|
+
const source = this.getAttribute("source") ?? undefined;
|
|
110
|
+
const { content, meta } = await openItem(this.getAttribute("ref") ?? "", source);
|
|
111
|
+
__classPrivateFieldSet(this, _T3Safebox_data, (content ?? {}), "f");
|
|
112
|
+
__classPrivateFieldSet(this, _T3Safebox_label, typeof meta.label === "string" ? meta.label : null, "f");
|
|
113
|
+
this.setAttribute("data-state", "revealed");
|
|
114
|
+
this.render();
|
|
115
|
+
clearTimeout(__classPrivateFieldGet(this, _T3Safebox_hideTimer, "f"));
|
|
116
|
+
__classPrivateFieldSet(this, _T3Safebox_hideTimer, setTimeout(() => this.hide(), SHOWN_MS), "f");
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
__classPrivateFieldSet(this, _T3Safebox_error, messageOf(e), "f");
|
|
120
|
+
this.setAttribute("data-state", "error");
|
|
121
|
+
this.render();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async confirm() {
|
|
125
|
+
const btn = __classPrivateFieldGet(this, _T3Safebox_root, "f")?.querySelector("#confirm");
|
|
126
|
+
if (btn)
|
|
127
|
+
btn.disabled = true;
|
|
128
|
+
const c = __classPrivateFieldGet(this, _T3Safebox_data, "f")?.confirm ?? {};
|
|
129
|
+
const ref = this.getAttribute("ref");
|
|
130
|
+
try {
|
|
131
|
+
if (c.kind === "run") {
|
|
132
|
+
// Confirmed through the integrator's own flow, which listens for this event.
|
|
133
|
+
this.dispatchEvent(new CustomEvent("seal-confirm", { bubbles: true, composed: true, detail: { run_id: c.run_id, ref } }));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
await confirmItem(ref ?? "");
|
|
137
|
+
this.dispatchEvent(new CustomEvent("seal-confirmed", { bubbles: true, composed: true, detail: { ref } }));
|
|
138
|
+
}
|
|
139
|
+
__classPrivateFieldSet(this, _T3Safebox_confirmed, true, "f");
|
|
140
|
+
this.setAttribute("data-confirmed", "true");
|
|
141
|
+
this.render();
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
__classPrivateFieldSet(this, _T3Safebox_error, messageOf(e), "f");
|
|
145
|
+
this.render();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
hide() {
|
|
149
|
+
__classPrivateFieldSet(this, _T3Safebox_data, null, "f");
|
|
150
|
+
__classPrivateFieldSet(this, _T3Safebox_error, null, "f");
|
|
151
|
+
this.setAttribute("data-state", "sealed");
|
|
152
|
+
this.render();
|
|
153
|
+
}
|
|
154
|
+
render() {
|
|
155
|
+
const root = __classPrivateFieldGet(this, _T3Safebox_root, "f");
|
|
156
|
+
if (!root)
|
|
157
|
+
return;
|
|
158
|
+
const state = this.getAttribute("data-state");
|
|
159
|
+
const label = this.getAttribute("label") || __classPrivateFieldGet(this, _T3Safebox_label, "f") || "Sealed details";
|
|
160
|
+
const d = state === "revealed" ? __classPrivateFieldGet(this, _T3Safebox_data, "f") : null;
|
|
161
|
+
const table = d?.kind === "table";
|
|
162
|
+
if (table)
|
|
163
|
+
this.setAttribute("data-kind", "table");
|
|
164
|
+
else
|
|
165
|
+
this.removeAttribute("data-kind");
|
|
166
|
+
let body;
|
|
167
|
+
if (d && table) {
|
|
168
|
+
const cols = d.columns ?? [];
|
|
169
|
+
const rows = d.rows ?? [];
|
|
170
|
+
body = `<div class="tw"><table><thead><tr>${cols.map((c) => `<th>${esc(c)}</th>`).join("")}</tr></thead><tbody>${rows
|
|
171
|
+
.map((r) => `<tr>${r.map((v) => `<td>${esc(v)}</td>`).join("")}</tr>`)
|
|
172
|
+
.join("")}</tbody></table></div><div class="row"><span class="note">Decrypted in this browser only.</span><button class="ghost" id="hide">Hide</button></div>`;
|
|
173
|
+
}
|
|
174
|
+
else if (d) {
|
|
175
|
+
const fields = Array.isArray(d.fields) ? d.fields : [];
|
|
176
|
+
const c = d.confirm;
|
|
177
|
+
body = `${d.summary ? `<div class="sum">${esc(d.summary)}</div>` : ""}<div class="fields">${fields
|
|
178
|
+
.map((f) => `<div class="f" data-field="${esc(f.label)}"><span>${esc(f.label)}</span><b class="${f.mono ? "mono" : ""}">${esc(f.value)}</b></div>`)
|
|
179
|
+
.join("")}</div>
|
|
180
|
+
${__classPrivateFieldGet(this, _T3Safebox_confirmed, "f") ? `<div class="ok">Confirmed</div>` : ""}
|
|
181
|
+
<div class="row"><span class="note">Decrypted in this browser only.</span>
|
|
182
|
+
${c && !__classPrivateFieldGet(this, _T3Safebox_confirmed, "f") ? `<button id="confirm">${esc(c.label ?? "Confirm")}</button>` : `<button class="ghost" id="hide">Hide</button>`}</div>`;
|
|
183
|
+
}
|
|
184
|
+
else if (state === "error") {
|
|
185
|
+
body = `<div class="err">${esc(__classPrivateFieldGet(this, _T3Safebox_error, "f"))}</div><div class="row"><span class="note">Only this browser can open it.</span><button id="reveal">Open</button></div>`;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
body = `<div class="row"><span class="note">Only this browser can open it.</span><button id="reveal">Open</button></div>`;
|
|
189
|
+
}
|
|
190
|
+
const title = esc(d?.title || label);
|
|
191
|
+
const by = rpName() ? `Sealed to this device by ${esc(rpName())}` : "Sealed to this device";
|
|
192
|
+
root.innerHTML = `<style>${STYLE}</style><div class="box">
|
|
193
|
+
<div class="head"><div class="ic">${d ? OPEN : LOCK}</div>
|
|
194
|
+
<div><div class="t">${title}</div><div class="s">${by}</div></div></div>
|
|
195
|
+
${body}${__classPrivateFieldGet(this, _T3Safebox_error, "f") && state !== "error" ? `<div class="err">${esc(__classPrivateFieldGet(this, _T3Safebox_error, "f"))}</div>` : ""}</div>`;
|
|
196
|
+
root.querySelector("#reveal")?.addEventListener("click", () => void this.reveal());
|
|
197
|
+
root.querySelector("#hide")?.addEventListener("click", () => this.hide());
|
|
198
|
+
root.querySelector("#confirm")?.addEventListener("click", () => void this.confirm());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_T3Safebox_root = new WeakMap(), _T3Safebox_unlisten = new WeakMap(), _T3Safebox_data = new WeakMap(), _T3Safebox_label = new WeakMap(), _T3Safebox_confirmed = new WeakMap(), _T3Safebox_error = new WeakMap(), _T3Safebox_hideTimer = new WeakMap();
|
|
202
|
+
class T3SafeboxForm extends HTMLElement {
|
|
203
|
+
constructor() {
|
|
204
|
+
super(...arguments);
|
|
205
|
+
_T3SafeboxForm_root.set(this, null);
|
|
206
|
+
_T3SafeboxForm_unlisten.set(this, null);
|
|
207
|
+
_T3SafeboxForm_desc.set(this, null);
|
|
208
|
+
_T3SafeboxForm_files.set(this, {});
|
|
209
|
+
_T3SafeboxForm_error.set(this, null);
|
|
210
|
+
}
|
|
211
|
+
connectedCallback() {
|
|
212
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_unlisten, __classPrivateFieldGet(this, _T3SafeboxForm_unlisten, "f") ?? onConfigure(() => (__classPrivateFieldGet(this, _T3SafeboxForm_root, "f") ? this.render(true) : void this.start())), "f");
|
|
213
|
+
if (configured())
|
|
214
|
+
void this.start();
|
|
215
|
+
else
|
|
216
|
+
this.setAttribute("data-state", "waiting");
|
|
217
|
+
}
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
__classPrivateFieldGet(this, _T3SafeboxForm_unlisten, "f")?.call(this);
|
|
220
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_unlisten, null, "f");
|
|
221
|
+
}
|
|
222
|
+
async start() {
|
|
223
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_root, __classPrivateFieldGet(this, _T3SafeboxForm_root, "f") ?? this.attachShadow({ mode: shadowMode() }), "f");
|
|
224
|
+
this.setAttribute("data-state", "loading");
|
|
225
|
+
this.render();
|
|
226
|
+
try {
|
|
227
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_desc, await describe(this.getAttribute("ref") ?? ""), "f");
|
|
228
|
+
this.setAttribute("data-state", "form");
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_error, messageOf(e), "f");
|
|
232
|
+
this.setAttribute("data-state", e instanceof SealError && e.code === "already_submitted" ? "sent" : "error");
|
|
233
|
+
}
|
|
234
|
+
this.render();
|
|
235
|
+
}
|
|
236
|
+
async send() {
|
|
237
|
+
const btn = __classPrivateFieldGet(this, _T3SafeboxForm_root, "f")?.querySelector("#send");
|
|
238
|
+
if (btn)
|
|
239
|
+
btn.disabled = true;
|
|
240
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_error, null, "f");
|
|
241
|
+
const desc = __classPrivateFieldGet(this, _T3SafeboxForm_desc, "f");
|
|
242
|
+
if (!desc)
|
|
243
|
+
return;
|
|
244
|
+
try {
|
|
245
|
+
const answers = {};
|
|
246
|
+
for (const f of desc.payload.form.fields) {
|
|
247
|
+
if (f.type === "file") {
|
|
248
|
+
if (__classPrivateFieldGet(this, _T3SafeboxForm_files, "f")[f.id])
|
|
249
|
+
answers[f.id] = __classPrivateFieldGet(this, _T3SafeboxForm_files, "f")[f.id];
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const input = __classPrivateFieldGet(this, _T3SafeboxForm_root, "f")?.querySelector(`[name="${CSS.escape(f.id)}"]`);
|
|
253
|
+
const v = input?.value?.trim();
|
|
254
|
+
if (v)
|
|
255
|
+
answers[f.id] = f.type === "digits" ? v.replace(/\D/g, "") : v;
|
|
256
|
+
}
|
|
257
|
+
await submit(this.getAttribute("ref") ?? "", desc, answers);
|
|
258
|
+
for (const k of Object.keys(answers))
|
|
259
|
+
delete answers[k];
|
|
260
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_files, {}, "f");
|
|
261
|
+
this.setAttribute("data-state", "sent");
|
|
262
|
+
this.render();
|
|
263
|
+
this.dispatchEvent(new CustomEvent("seal-submitted", { bubbles: true, composed: true, detail: { ref: this.getAttribute("ref") } }));
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_error, messageOf(e), "f");
|
|
267
|
+
if (btn)
|
|
268
|
+
btn.disabled = false;
|
|
269
|
+
this.render(true);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
render(keep = false) {
|
|
273
|
+
const root = __classPrivateFieldGet(this, _T3SafeboxForm_root, "f");
|
|
274
|
+
if (!root)
|
|
275
|
+
return;
|
|
276
|
+
const state = this.getAttribute("data-state");
|
|
277
|
+
const p = __classPrivateFieldGet(this, _T3SafeboxForm_desc, "f")?.payload;
|
|
278
|
+
const name = esc(rpName());
|
|
279
|
+
let body = "";
|
|
280
|
+
if (state === "loading")
|
|
281
|
+
body = `<div class="note" style="margin-top:10px">Checking the signature…</div>`;
|
|
282
|
+
else if (state === "error")
|
|
283
|
+
body = `<div class="err">${esc(__classPrivateFieldGet(this, _T3SafeboxForm_error, "f"))}</div>`;
|
|
284
|
+
else if (state === "sent") {
|
|
285
|
+
const readers = (p?.recipients ?? []).map((r) => r.name).join(" and ");
|
|
286
|
+
body = `<div class="ok">Sent securely.</div><div class="desc">${readers ? `Only ${esc(readers)} can read it.` : "Only the named recipients can read it."} The assistant never sees it.</div>`;
|
|
287
|
+
}
|
|
288
|
+
else if (state === "form" && p) {
|
|
289
|
+
const registered = name ? `, registered by ${name}` : "";
|
|
290
|
+
const recip = (p.recipients ?? []).map((r) => `<div>· <b>${esc(r.name)}</b>${r.role ? ` <span class="note">(${esc(r.role)}${registered})</span>` : ""}</div>`).join("");
|
|
291
|
+
const dest = (p.destinations ?? []).map((d) => `<div>· <b>${esc(d.purpose)}</b> <span class="note">${esc(d.host)}</span></div>`).join("");
|
|
292
|
+
const groups = p.form.one_of ?? [];
|
|
293
|
+
const inAlt = (id) => groups.findIndex((g) => g.includes(id));
|
|
294
|
+
let fields = "";
|
|
295
|
+
let lastGroup = -1;
|
|
296
|
+
for (const f of p.form.fields) {
|
|
297
|
+
const g = inAlt(f.id);
|
|
298
|
+
if (g > 0 && g !== lastGroup)
|
|
299
|
+
fields += `<div class="or">or type them</div>`;
|
|
300
|
+
lastGroup = g;
|
|
301
|
+
if (f.type === "select") {
|
|
302
|
+
fields += `<label>${esc(f.label)}<select name="${esc(f.id)}">${(f.options ?? []).map((o) => `<option value="${esc(o.value)}">${esc(o.label)}</option>`).join("")}</select></label>`;
|
|
303
|
+
}
|
|
304
|
+
else if (f.type === "file") {
|
|
305
|
+
const chosen = __classPrivateFieldGet(this, _T3SafeboxForm_files, "f")[f.id];
|
|
306
|
+
fields += `<label>${esc(f.label)}<input type="file" name="${esc(f.id)}" accept="${esc((f.accept ?? []).join(","))}"></label>${chosen ? `<img class="thumb" src="data:${esc(chosen.type)};base64,${chosen.data}">` : ""}`;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
fields += `<label>${esc(f.label)}<input name="${esc(f.id)}" ${f.type === "digits" ? 'inputmode="numeric" autocomplete="off"' : ""}></label>`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
body = `${p.form.description ? `<div class="desc">${esc(p.form.description)}</div>` : ""}
|
|
313
|
+
<div class="who"><div class="note">Who can read it</div>${recip}<div class="note" style="margin-top:6px">Where it goes</div>${dest}</div>
|
|
314
|
+
${fields}
|
|
315
|
+
${__classPrivateFieldGet(this, _T3SafeboxForm_error, "f") ? `<div class="err">${esc(__classPrivateFieldGet(this, _T3SafeboxForm_error, "f"))}</div>` : ""}
|
|
316
|
+
<div class="row"><span class="note">Encrypted on this device.</span><button id="send">${esc(p.form.submit_label ?? "Send")}</button></div>`;
|
|
317
|
+
}
|
|
318
|
+
const kept = keep
|
|
319
|
+
? Object.fromEntries([...root.querySelectorAll("input:not([type=file]),select")].map((i) => [i.name, i.value]))
|
|
320
|
+
: {};
|
|
321
|
+
const signed = name ? `Signed by ${name} in T3N · not readable by the assistant` : "Signed in T3N · not readable by the assistant";
|
|
322
|
+
root.innerHTML = `<style>${STYLE}</style><div class="box">
|
|
323
|
+
<div class="head"><div class="ic">${FORM}</div>
|
|
324
|
+
<div><div class="t">${esc(p?.form?.title ?? "Secure form")}</div><div class="s">${signed}</div></div></div>
|
|
325
|
+
${body}</div>`;
|
|
326
|
+
for (const [k, v] of Object.entries(kept)) {
|
|
327
|
+
const el = root.querySelector(`[name="${CSS.escape(k)}"]`);
|
|
328
|
+
if (el)
|
|
329
|
+
el.value = v;
|
|
330
|
+
}
|
|
331
|
+
root.querySelector("#send")?.addEventListener("click", () => void this.send());
|
|
332
|
+
for (const input of root.querySelectorAll("input[type=file]")) {
|
|
333
|
+
input.addEventListener("change", async () => {
|
|
334
|
+
const file = input.files?.[0];
|
|
335
|
+
if (!file)
|
|
336
|
+
return;
|
|
337
|
+
try {
|
|
338
|
+
__classPrivateFieldGet(this, _T3SafeboxForm_files, "f")[input.name] = { type: file.type, name: file.name, data: toB64(new Uint8Array(await file.arrayBuffer())) };
|
|
339
|
+
}
|
|
340
|
+
catch (e) {
|
|
341
|
+
__classPrivateFieldSet(this, _T3SafeboxForm_error, messageOf(e), "f");
|
|
342
|
+
}
|
|
343
|
+
this.render(true);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
_T3SafeboxForm_root = new WeakMap(), _T3SafeboxForm_unlisten = new WeakMap(), _T3SafeboxForm_desc = new WeakMap(), _T3SafeboxForm_files = new WeakMap(), _T3SafeboxForm_error = new WeakMap();
|
|
349
|
+
if (!customElements.get("t3-safebox"))
|
|
350
|
+
customElements.define("t3-safebox", T3Safebox);
|
|
351
|
+
if (!customElements.get("t3-safebox-form"))
|
|
352
|
+
customElements.define("t3-safebox-form", T3SafeboxForm);
|
|
353
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A refusal or a failure. `code` is stable and meant for branching; `message`
|
|
3
|
+
* is fit to show the customer.
|
|
4
|
+
*
|
|
5
|
+
* The format codes match the sealing service's: `invalid_key`,
|
|
6
|
+
* `jwe_malformed`, `header_mismatch`, `jwe_not_authentic` and `expired`.
|
|
7
|
+
* An error answer from the integrator's app keeps its own `error` as the code,
|
|
8
|
+
* or `http_<status>` when it has none.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SealError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
constructor(code: string, message: string);
|
|
13
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A refusal or a failure. `code` is stable and meant for branching; `message`
|
|
3
|
+
* is fit to show the customer.
|
|
4
|
+
*
|
|
5
|
+
* The format codes match the sealing service's: `invalid_key`,
|
|
6
|
+
* `jwe_malformed`, `header_mismatch`, `jwe_not_authentic` and `expired`.
|
|
7
|
+
* An error answer from the integrator's app keeps its own `error` as the code,
|
|
8
|
+
* or `http_<status>` when it has none.
|
|
9
|
+
*/
|
|
10
|
+
export class SealError extends Error {
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "SealError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { configure, type SealApi, type SealConfig, type ShadowMode } from "./config.js";
|
|
2
|
+
export { confirmItem, describe, open, openItem, submit, type FormDescription, type FormField, type FormPayload, type OpenedItem, } from "./delivery.js";
|
|
3
|
+
export { defineElements } from "./elements.js";
|
|
4
|
+
export { SealError } from "./errors.js";
|
|
5
|
+
export { thumbprint, type PublicJwk } from "./jwe.js";
|
|
6
|
+
export { registerPasskey } from "./passkey.js";
|
|
7
|
+
export { ensureSession, hasSession, reset, startSession } from "./session.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Importing this module defines <t3-safebox> and <t3-safebox-form> wherever
|
|
2
|
+
// `customElements` exists; elsewhere only the functions load.
|
|
3
|
+
import { defineElements } from "./elements.js";
|
|
4
|
+
export { configure } from "./config.js";
|
|
5
|
+
export { confirmItem, describe, open, openItem, submit, } from "./delivery.js";
|
|
6
|
+
export { defineElements } from "./elements.js";
|
|
7
|
+
export { SealError } from "./errors.js";
|
|
8
|
+
export { thumbprint } from "./jwe.js";
|
|
9
|
+
export { registerPasskey } from "./passkey.js";
|
|
10
|
+
export { ensureSession, hasSession, reset, startSession } from "./session.js";
|
|
11
|
+
if (typeof customElements !== "undefined")
|
|
12
|
+
defineElements();
|
package/dist/jwe.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Bytes } from "./codec.js";
|
|
2
|
+
export declare const ALG = "ECDH-ES";
|
|
3
|
+
export declare const ENC = "A256GCM";
|
|
4
|
+
export declare const FORM_JWS_TYPE = "t3n-seal-form+jws";
|
|
5
|
+
export declare const ECDH: {
|
|
6
|
+
readonly name: "ECDH";
|
|
7
|
+
readonly namedCurve: "P-256";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A P-256 public JWK whose point is on the curve. Its `kid` is its thumbprint,
|
|
11
|
+
* except on the sealing service's signing key, whose `kid` the service names.
|
|
12
|
+
*/
|
|
13
|
+
export interface PublicJwk {
|
|
14
|
+
kty: "EC";
|
|
15
|
+
crv: "P-256";
|
|
16
|
+
x: string;
|
|
17
|
+
y: string;
|
|
18
|
+
kid: string;
|
|
19
|
+
}
|
|
20
|
+
/** RFC 7638 thumbprint of a P-256 public JWK. */
|
|
21
|
+
export declare function thumbprint(jwk: {
|
|
22
|
+
x: string;
|
|
23
|
+
y: string;
|
|
24
|
+
}): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Accepts `jwk` only as an EC P-256 public key whose point is on the curve and
|
|
27
|
+
* whose `kid`, when it names one, is its own thumbprint.
|
|
28
|
+
*/
|
|
29
|
+
export declare function publicJwk(jwk: unknown): Promise<PublicJwk>;
|
|
30
|
+
/**
|
|
31
|
+
* Accepts `jwk` as the key the sealing service signs a tenant's form
|
|
32
|
+
* descriptions with: an EC P-256 public key whose point is on the curve, with
|
|
33
|
+
* the `kid` the service names, `<tid>.<generation>`. A description's header
|
|
34
|
+
* must carry that same `kid`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function signingJwk(jwk: unknown): PublicJwk;
|
|
37
|
+
export declare function importEcdhPublic(jwk: PublicJwk): Promise<CryptoKey>;
|
|
38
|
+
/** RFC 7518 §4.6.2 Concat KDF, one SHA-256 round: at most 256 key bits. */
|
|
39
|
+
export declare function concatKdf(z: Bytes, algId: string, apu: Bytes, apv: Bytes, keyBits: number): Promise<Bytes>;
|
|
40
|
+
export interface SealOptions {
|
|
41
|
+
/** The ephemeral key pair; a fresh one by default. Its public key must be extractable. */
|
|
42
|
+
ephemeral?: CryptoKeyPair;
|
|
43
|
+
/** The 12-byte IV; random by default. */
|
|
44
|
+
iv?: Bytes;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Seals `plaintext` to `to` as a compact JWE. `claims` join `alg`, `enc`,
|
|
48
|
+
* `epk` and `kid` in the protected header, which is serialised with its
|
|
49
|
+
* members sorted.
|
|
50
|
+
*/
|
|
51
|
+
export declare function seal(to: PublicJwk, claims: Record<string, unknown>, plaintext: Bytes, opts?: SealOptions): Promise<string>;
|
|
52
|
+
/** The protected header of a compact JWE, without opening it. */
|
|
53
|
+
export declare function jweHeader(jwe: string): Record<string, unknown>;
|
|
54
|
+
/** Refuses a header whose `exp` (Unix seconds) is before `nowSecs`; one without `exp` passes. */
|
|
55
|
+
export declare function checkExpiry(header: Record<string, unknown>, nowSecs: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Opens a compact ECDH-ES/A256GCM JWE with `privateKey`, whose thumbprint is
|
|
58
|
+
* `kid`. The header must name that `kid` and an on-curve `epk`. Does not read
|
|
59
|
+
* `exp`: run {@link checkExpiry} on the {@link jweHeader} first.
|
|
60
|
+
*/
|
|
61
|
+
export declare function openJwe(jwe: string, privateKey: CryptoKey, kid: string): Promise<{
|
|
62
|
+
header: Record<string, unknown>;
|
|
63
|
+
plaintext: Bytes;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Verifies a compact ES256 JWS against `key` over the exact bytes received and
|
|
67
|
+
* answers its payload; `null` if it is malformed or does not verify.
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifyJws(jws: string, key: PublicJwk): Promise<Bytes | null>;
|