@things-factory/survey 0.0.0-stage → 10.1.316
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/dist-client/index.d.ts +1 -0
- package/dist-client/index.js +2 -0
- package/dist-client/pages/my-surveys.d.ts +24 -0
- package/dist-client/pages/my-surveys.js +256 -0
- package/dist-client/pages/survey-editor.d.ts +62 -0
- package/dist-client/pages/survey-editor.js +668 -0
- package/dist-client/pages/survey-list.d.ts +15 -0
- package/dist-client/pages/survey-list.js +150 -0
- package/dist-client/pages/survey-trustee.d.ts +21 -0
- package/dist-client/pages/survey-trustee.js +170 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +17 -0
- package/dist-client/utils/survey-api.d.ts +16 -0
- package/dist-client/utils/survey-api.js +46 -0
- package/dist-client/utils/survey-result.d.ts +4 -0
- package/dist-client/utils/survey-result.js +79 -0
- package/dist-client/utils/survey-secret.d.ts +40 -0
- package/dist-client/utils/survey-secret.js +154 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +27 -0
- package/dist-server/role-tasks.d.ts +2 -0
- package/dist-server/role-tasks.js +16 -0
- package/dist-server/service/index.d.ts +16 -0
- package/dist-server/service/index.js +30 -0
- package/dist-server/service/refusal.d.ts +57 -0
- package/dist-server/service/refusal.js +66 -0
- package/dist-server/service/survey/ballot-route.d.ts +1 -0
- package/dist-server/service/survey/ballot-route.js +30 -0
- package/dist-server/service/survey/ballot-worker.d.ts +1 -0
- package/dist-server/service/survey/ballot-worker.js +19 -0
- package/dist-server/service/survey/index.d.ts +10 -0
- package/dist-server/service/survey/index.js +14 -0
- package/dist-server/service/survey/survey-answer.d.ts +23 -0
- package/dist-server/service/survey/survey-answer.js +99 -0
- package/dist-server/service/survey/survey-attributes.d.ts +16 -0
- package/dist-server/service/survey/survey-attributes.js +39 -0
- package/dist-server/service/survey/survey-ballot.d.ts +14 -0
- package/dist-server/service/survey/survey-ballot.js +61 -0
- package/dist-server/service/survey/survey-class-key.d.ts +20 -0
- package/dist-server/service/survey/survey-class-key.js +92 -0
- package/dist-server/service/survey/survey-question.d.ts +27 -0
- package/dist-server/service/survey/survey-question.js +113 -0
- package/dist-server/service/survey/survey-resolver.d.ts +37 -0
- package/dist-server/service/survey/survey-resolver.js +492 -0
- package/dist-server/service/survey/survey-respondent.d.ts +17 -0
- package/dist-server/service/survey/survey-respondent.js +81 -0
- package/dist-server/service/survey/survey-rules.d.ts +169 -0
- package/dist-server/service/survey/survey-rules.js +299 -0
- package/dist-server/service/survey/survey-secret.d.ts +133 -0
- package/dist-server/service/survey/survey-secret.js +347 -0
- package/dist-server/service/survey/survey-service.d.ts +83 -0
- package/dist-server/service/survey/survey-service.js +384 -0
- package/dist-server/service/survey/survey-trustee.d.ts +25 -0
- package/dist-server/service/survey/survey-trustee.js +119 -0
- package/dist-server/service/survey/survey-types.d.ts +91 -0
- package/dist-server/service/survey/survey-types.js +319 -0
- package/dist-server/service/survey/survey.d.ts +47 -0
- package/dist-server/service/survey/survey.js +214 -0
- package/dist-shared/ballot.d.ts +54 -0
- package/dist-shared/ballot.js +146 -0
- package/dist-shared/blind-rsa.d.ts +18 -0
- package/dist-shared/blind-rsa.js +127 -0
- package/dist-shared/elgamal.d.ts +20 -0
- package/dist-shared/elgamal.js +54 -0
- package/dist-shared/group.d.ts +22 -0
- package/dist-shared/group.js +112 -0
- package/dist-shared/proofs.d.ts +20 -0
- package/dist-shared/proofs.js +94 -0
- package/dist-shared/threshold.d.ts +39 -0
- package/dist-shared/threshold.js +98 -0
- package/dist-shared/verify.d.ts +13 -0
- package/dist-shared/verify.js +73 -0
- package/package.json +63 -4
- package/things-factory.config.js +15 -0
- package/translations/en.json +202 -0
- package/translations/es.json +202 -0
- package/translations/ja.json +202 -0
- package/translations/ko.json +202 -0
- package/translations/ms.json +202 -0
- package/translations/zh.json +202 -0
- package/README.md +0 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PageView } from '@operato/shell';
|
|
2
|
+
import { type Row } from '../utils/survey-api.js';
|
|
3
|
+
declare const SurveyListPage_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
|
|
4
|
+
export declare class SurveyListPage extends SurveyListPage_base {
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
surveys: Row[];
|
|
7
|
+
get context(): {
|
|
8
|
+
title: string;
|
|
9
|
+
};
|
|
10
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
11
|
+
pageUpdated(_changes: any, _lifecycle: any, before: any): Promise<void>;
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
take(survey: Row, step: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import gql from 'graphql-tag';
|
|
3
|
+
import { css, html, nothing } from 'lit';
|
|
4
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
5
|
+
import { client } from '@operato/graphql';
|
|
6
|
+
import { i18next, localize } from '@operato/i18n';
|
|
7
|
+
import { navigate, PageView } from '@operato/shell';
|
|
8
|
+
import { ButtonStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
|
|
9
|
+
import { levelLabel, mutate, statusLabel, sure } from '../utils/survey-api.js';
|
|
10
|
+
/*
|
|
11
|
+
* **설문 관리** - the operator's surveys (operato-survey design §9): each with its level and step, and the step it may
|
|
12
|
+
* take next - open, close, count, publish, cancel. Making and editing is the editor's.
|
|
13
|
+
*/
|
|
14
|
+
const STEPS = {
|
|
15
|
+
DRAFT: ['open', 'delete', 'cancel'],
|
|
16
|
+
OPEN: ['close', 'cancel'],
|
|
17
|
+
CLOSED: ['count', 'cancel'],
|
|
18
|
+
COUNTED: ['publish', 'cancel']
|
|
19
|
+
};
|
|
20
|
+
/* A secret survey makes its key with its key holders before it opens, and they open its sums after it closes (design §3-2). */
|
|
21
|
+
const SECRET_STEPS = {
|
|
22
|
+
DRAFT: ['keying', 'delete', 'cancel'],
|
|
23
|
+
KEYING: ['open', 'cancel'],
|
|
24
|
+
OPEN: ['close', 'cancel'],
|
|
25
|
+
CLOSED: ['count', 'cancel'],
|
|
26
|
+
DECRYPTING: ['cancel'],
|
|
27
|
+
COUNTED: ['publish', 'cancel']
|
|
28
|
+
};
|
|
29
|
+
const DOORS = {
|
|
30
|
+
open: 'openSurvey',
|
|
31
|
+
close: 'closeSurvey',
|
|
32
|
+
count: 'countSurvey',
|
|
33
|
+
publish: 'publishSurvey',
|
|
34
|
+
cancel: 'cancelSurvey',
|
|
35
|
+
delete: 'deleteSurvey',
|
|
36
|
+
keying: 'startSurveyKeying'
|
|
37
|
+
};
|
|
38
|
+
let SurveyListPage = class SurveyListPage extends localize(i18next)(PageView) {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
this.surveys = [];
|
|
42
|
+
}
|
|
43
|
+
static { this.styles = [
|
|
44
|
+
WorkSurfacePageStyles,
|
|
45
|
+
ScrollbarStyles,
|
|
46
|
+
ButtonStyles,
|
|
47
|
+
css `
|
|
48
|
+
main {
|
|
49
|
+
overflow-y: auto;
|
|
50
|
+
padding: 16px;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
gap: 12px;
|
|
54
|
+
}
|
|
55
|
+
table {
|
|
56
|
+
width: 100%;
|
|
57
|
+
border-collapse: collapse;
|
|
58
|
+
font-size: 14px;
|
|
59
|
+
}
|
|
60
|
+
th,
|
|
61
|
+
td {
|
|
62
|
+
text-align: left;
|
|
63
|
+
padding: 8px;
|
|
64
|
+
border-bottom: 1px solid var(--md-sys-color-outline-variant);
|
|
65
|
+
vertical-align: middle;
|
|
66
|
+
}
|
|
67
|
+
td.steps {
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-wrap: wrap;
|
|
70
|
+
gap: 6px;
|
|
71
|
+
}
|
|
72
|
+
a {
|
|
73
|
+
color: var(--md-sys-color-primary);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
}
|
|
76
|
+
.empty {
|
|
77
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
78
|
+
}
|
|
79
|
+
`
|
|
80
|
+
]; }
|
|
81
|
+
get context() {
|
|
82
|
+
return { title: i18next.t('title.survey-list') };
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
return html `
|
|
86
|
+
<main>
|
|
87
|
+
<div>
|
|
88
|
+
<button raised @click=${() => navigate('survey-editor')}>${i18next.t('button.survey-new')}</button>
|
|
89
|
+
</div>
|
|
90
|
+
<table>
|
|
91
|
+
<thead>
|
|
92
|
+
<tr>
|
|
93
|
+
<th>${i18next.t('label.survey-name')}</th>
|
|
94
|
+
<th>${i18next.t('label.survey-level')}</th>
|
|
95
|
+
<th>${i18next.t('label.survey-status')}</th>
|
|
96
|
+
<th>${i18next.t('label.survey-closes-at')}</th>
|
|
97
|
+
<th>${i18next.t('label.survey-asked')}</th>
|
|
98
|
+
<th></th>
|
|
99
|
+
</tr>
|
|
100
|
+
</thead>
|
|
101
|
+
<tbody>
|
|
102
|
+
${this.surveys.map(one => html `<tr>
|
|
103
|
+
<td><a @click=${() => navigate(`survey-editor?id=${one.id}`)}>${one.name}</a></td>
|
|
104
|
+
<td>${levelLabel(one.level)}</td>
|
|
105
|
+
<td>${statusLabel(one.status)}</td>
|
|
106
|
+
<td>${one.closesAt ? new Date(one.closesAt).toLocaleString() : ''}</td>
|
|
107
|
+
<td>${one.askedCount ?? ''}</td>
|
|
108
|
+
<td class="steps">
|
|
109
|
+
${((one.level === 'SECRET' ? SECRET_STEPS : STEPS)[one.status] ?? []).map(step => html `<button small @click=${() => this.take(one, step)}>${i18next.t(`button.survey-${step}`)}</button>`)}
|
|
110
|
+
</td>
|
|
111
|
+
</tr>`)}
|
|
112
|
+
</tbody>
|
|
113
|
+
</table>
|
|
114
|
+
${this.surveys.length ? nothing : html `<p class="empty">${i18next.t('text.survey-none')}</p>`}
|
|
115
|
+
</main>
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
async pageUpdated(_changes, _lifecycle, before) {
|
|
119
|
+
if (this.active && !before?.active)
|
|
120
|
+
await this.load();
|
|
121
|
+
}
|
|
122
|
+
async load() {
|
|
123
|
+
const response = await client.query({
|
|
124
|
+
query: gql `
|
|
125
|
+
query {
|
|
126
|
+
surveys { id name level status closesAt askedCount }
|
|
127
|
+
}
|
|
128
|
+
`,
|
|
129
|
+
fetchPolicy: 'network-only'
|
|
130
|
+
});
|
|
131
|
+
this.surveys = response.data?.surveys ?? [];
|
|
132
|
+
}
|
|
133
|
+
async take(survey, step) {
|
|
134
|
+
if (['cancel', 'delete', 'publish', 'open', 'keying'].includes(step) && !(await sure(i18next.t(`text.survey-confirm-${step}`, { name: survey.name }), i18next.t(`button.survey-${step}`), ['cancel', 'delete'].includes(step))))
|
|
135
|
+
return;
|
|
136
|
+
const door = DOORS[step];
|
|
137
|
+
const done = await mutate(gql `mutation ($id: String!) { ${door}(id: $id) ${step === 'delete' ? '' : '{ id }'} }`, { id: survey.id });
|
|
138
|
+
if (done)
|
|
139
|
+
await this.load();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
__decorate([
|
|
143
|
+
state(),
|
|
144
|
+
__metadata("design:type", Array)
|
|
145
|
+
], SurveyListPage.prototype, "surveys", void 0);
|
|
146
|
+
SurveyListPage = __decorate([
|
|
147
|
+
customElement('survey-list')
|
|
148
|
+
], SurveyListPage);
|
|
149
|
+
export { SurveyListPage };
|
|
150
|
+
//# sourceMappingURL=survey-list.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PageView } from '@operato/shell';
|
|
2
|
+
import { type Row } from '../utils/survey-api.js';
|
|
3
|
+
declare const SurveyTrusteePage_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
|
|
4
|
+
export declare class SurveyTrusteePage extends SurveyTrusteePage_base {
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
surveys: Row[];
|
|
7
|
+
busy: string;
|
|
8
|
+
passphrase: string;
|
|
9
|
+
keyFile?: File;
|
|
10
|
+
get context(): {
|
|
11
|
+
title: string;
|
|
12
|
+
};
|
|
13
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
14
|
+
private renderOne;
|
|
15
|
+
pageUpdated(_changes: any, _lifecycle: any, before: any): Promise<void>;
|
|
16
|
+
load(): Promise<void>;
|
|
17
|
+
private view;
|
|
18
|
+
private secret;
|
|
19
|
+
take(one: Row, step: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import gql from 'graphql-tag';
|
|
3
|
+
import { css, html, nothing } from 'lit';
|
|
4
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
5
|
+
import { client } from '@operato/graphql';
|
|
6
|
+
import { i18next, localize } from '@operato/i18n';
|
|
7
|
+
import { notify } from '@operato/layout';
|
|
8
|
+
import { PageView } from '@operato/shell';
|
|
9
|
+
import { ButtonStyles, FormFieldStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
|
|
10
|
+
import { mutate, statusLabel } from '../utils/survey-api.js';
|
|
11
|
+
import { download, keyFileOf, makeDealing, makePartials, makeTransportKey, myShareOf, readKeyFile } from '../utils/survey-secret.js';
|
|
12
|
+
/*
|
|
13
|
+
* **키 보관** - the secret surveys I hold a key of (operato-survey design §3-2 · §6-3): make my transport key and keep
|
|
14
|
+
* its secret in a key file sealed with my passphrase, deal my shares, check the shares dealt to me, and - when counting -
|
|
15
|
+
* open my part of the sums. My secret never leaves this browser except inside the key file I keep.
|
|
16
|
+
*/
|
|
17
|
+
const NEXT = { INVITED: 'transport', KEYED: 'deal', DEALT: 'confirm', CONFIRMED: 'decrypt' };
|
|
18
|
+
let SurveyTrusteePage = class SurveyTrusteePage extends localize(i18next)(PageView) {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.surveys = [];
|
|
22
|
+
this.busy = '';
|
|
23
|
+
this.passphrase = '';
|
|
24
|
+
}
|
|
25
|
+
static { this.styles = [
|
|
26
|
+
WorkSurfacePageStyles,
|
|
27
|
+
ScrollbarStyles,
|
|
28
|
+
ButtonStyles,
|
|
29
|
+
FormFieldStyles,
|
|
30
|
+
css `
|
|
31
|
+
main {
|
|
32
|
+
overflow-y: auto;
|
|
33
|
+
padding: 16px;
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
gap: 16px;
|
|
37
|
+
max-width: 880px;
|
|
38
|
+
}
|
|
39
|
+
article {
|
|
40
|
+
border: 1px solid var(--md-sys-color-outline-variant);
|
|
41
|
+
border-radius: 10px;
|
|
42
|
+
padding: 16px;
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: 10px;
|
|
46
|
+
}
|
|
47
|
+
article h3 {
|
|
48
|
+
margin: 0;
|
|
49
|
+
}
|
|
50
|
+
.note {
|
|
51
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
52
|
+
font-size: 13px;
|
|
53
|
+
margin: 0;
|
|
54
|
+
}
|
|
55
|
+
.row {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-wrap: wrap;
|
|
58
|
+
gap: 8px;
|
|
59
|
+
align-items: center;
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
]; }
|
|
63
|
+
get context() {
|
|
64
|
+
return { title: i18next.t('title.survey-trustee') };
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
return html `<main>
|
|
68
|
+
<p class="note">${i18next.t('text.survey-trustee-intro')}</p>
|
|
69
|
+
<div class="row">
|
|
70
|
+
<label>${i18next.t('label.survey-passphrase')} <input type="password" autocomplete="new-password" .value=${this.passphrase} @input=${(e) => (this.passphrase = e.target.value)} /></label>
|
|
71
|
+
<label>${i18next.t('label.survey-key-file')} <input type="file" accept="application/json" @change=${(e) => (this.keyFile = e.target.files?.[0])} /></label>
|
|
72
|
+
</div>
|
|
73
|
+
${this.surveys.map(one => this.renderOne(one))}
|
|
74
|
+
${this.surveys.length ? nothing : html `<p class="note">${i18next.t('text.survey-trustee-none')}</p>`}
|
|
75
|
+
</main>`;
|
|
76
|
+
}
|
|
77
|
+
renderOne(one) {
|
|
78
|
+
const step = one.status === 'DECRYPTING' ? (one.myStatus === 'CONFIRMED' ? 'decrypt' : undefined) : one.status === 'KEYING' && one.myStatus !== 'CONFIRMED' ? NEXT[one.myStatus] : undefined;
|
|
79
|
+
return html `<article>
|
|
80
|
+
<h3>${one.name}</h3>
|
|
81
|
+
<p class="note">${statusLabel(one.status)} · ${i18next.t('text.survey-trustee-mine', { seq: one.seq, step: i18next.t(`label.survey-trustee-${String(one.myStatus).toLowerCase()}`) })}</p>
|
|
82
|
+
${step
|
|
83
|
+
? html `<div class="row">
|
|
84
|
+
<button raised ?disabled=${!!this.busy} @click=${() => this.take(one, step)}>${i18next.t(`button.survey-trustee-${step}`)}</button>
|
|
85
|
+
${this.busy === one.surveyId ? html `<span class="note">${i18next.t('text.survey-working')}</span>` : nothing}
|
|
86
|
+
</div>`
|
|
87
|
+
: html `<p class="note">${i18next.t('text.survey-trustee-waiting')}</p>`}
|
|
88
|
+
</article>`;
|
|
89
|
+
}
|
|
90
|
+
async pageUpdated(_changes, _lifecycle, before) {
|
|
91
|
+
if (this.active && !before?.active)
|
|
92
|
+
await this.load();
|
|
93
|
+
}
|
|
94
|
+
async load() {
|
|
95
|
+
const response = await client.query({ query: gql `query { myTrusteeSurveys { surveyId name status myStatus seq } }`, fetchPolicy: 'network-only' });
|
|
96
|
+
this.surveys = response.data?.myTrusteeSurveys ?? [];
|
|
97
|
+
}
|
|
98
|
+
async view(surveyId) {
|
|
99
|
+
const response = await client.query({ query: gql `query ($id: String!) { surveyTrusteeView(id: $id) }`, variables: { id: surveyId }, fetchPolicy: 'network-only' });
|
|
100
|
+
return response.data.surveyTrusteeView;
|
|
101
|
+
}
|
|
102
|
+
async secret(one) {
|
|
103
|
+
if (!this.keyFile || !this.passphrase)
|
|
104
|
+
throw new Error(i18next.t('text.survey-key-file-needed'));
|
|
105
|
+
const content = await readKeyFile(this.keyFile, this.passphrase).catch(() => {
|
|
106
|
+
throw new Error(i18next.t('text.survey-key-file-unreadable'));
|
|
107
|
+
});
|
|
108
|
+
if (content.surveyId !== one.surveyId || content.seq !== one.seq)
|
|
109
|
+
throw new Error(i18next.t('text.survey-key-file-other'));
|
|
110
|
+
return content;
|
|
111
|
+
}
|
|
112
|
+
async take(one, step) {
|
|
113
|
+
this.busy = one.surveyId;
|
|
114
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
115
|
+
try {
|
|
116
|
+
if (step === 'transport') {
|
|
117
|
+
if (this.passphrase.length < 8)
|
|
118
|
+
throw new Error(i18next.t('text.survey-passphrase-short'));
|
|
119
|
+
const made = makeTransportKey(one.surveyId, one.seq);
|
|
120
|
+
download(await keyFileOf({ surveyId: one.surveyId, seq: one.seq, secret: made.secret }, this.passphrase), `survey-key-${one.seq}-${one.surveyId.slice(0, 8)}.json`);
|
|
121
|
+
await mutate(gql `mutation ($id: String!, $key: String!, $proof: Object!) { postSurveyTransportKey(id: $id, key: $key, proof: $proof) }`, { id: one.surveyId, key: made.key, proof: made.proof });
|
|
122
|
+
notify({ level: 'info', message: i18next.t('text.survey-key-file-saved') });
|
|
123
|
+
}
|
|
124
|
+
else if (step === 'deal') {
|
|
125
|
+
const { dealing, sealed } = makeDealing(await this.view(one.surveyId));
|
|
126
|
+
await mutate(gql `mutation ($id: String!, $dealing: Object!, $sealed: Object!) { postSurveyDealing(id: $id, dealing: $dealing, sealed: $sealed) }`, { id: one.surveyId, dealing, sealed });
|
|
127
|
+
}
|
|
128
|
+
else if (step === 'confirm') {
|
|
129
|
+
const content = await this.secret(one);
|
|
130
|
+
myShareOf(await this.view(one.surveyId), content.secret);
|
|
131
|
+
await mutate(gql `mutation ($id: String!) { confirmSurveyShares(id: $id) }`, { id: one.surveyId });
|
|
132
|
+
}
|
|
133
|
+
else if (step === 'decrypt') {
|
|
134
|
+
const content = await this.secret(one);
|
|
135
|
+
const view = await this.view(one.surveyId);
|
|
136
|
+
const partials = makePartials(view, myShareOf(view, content.secret));
|
|
137
|
+
await mutate(gql `mutation ($id: String!, $partials: Object!) { postSurveyPartials(id: $id, partials: $partials) }`, { id: one.surveyId, partials });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const message = String(error?.message ?? '');
|
|
142
|
+
notify({ level: 'error', message: message.startsWith('share-from-') ? i18next.t('text.survey-share-mismatch', { dealer: message.split('-')[2] }) : message });
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
this.busy = '';
|
|
146
|
+
await this.load();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
__decorate([
|
|
151
|
+
state(),
|
|
152
|
+
__metadata("design:type", Array)
|
|
153
|
+
], SurveyTrusteePage.prototype, "surveys", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
state(),
|
|
156
|
+
__metadata("design:type", Object)
|
|
157
|
+
], SurveyTrusteePage.prototype, "busy", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
state(),
|
|
160
|
+
__metadata("design:type", Object)
|
|
161
|
+
], SurveyTrusteePage.prototype, "passphrase", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
state(),
|
|
164
|
+
__metadata("design:type", File)
|
|
165
|
+
], SurveyTrusteePage.prototype, "keyFile", void 0);
|
|
166
|
+
SurveyTrusteePage = __decorate([
|
|
167
|
+
customElement('survey-trustee')
|
|
168
|
+
], SurveyTrusteePage);
|
|
169
|
+
export { SurveyTrusteePage };
|
|
170
|
+
//# sourceMappingURL=survey-trustee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function route(page: string): "survey-list" | "survey-editor" | "survey-trustee" | "my-surveys";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default function route(page) {
|
|
2
|
+
switch (page) {
|
|
3
|
+
case 'survey-list':
|
|
4
|
+
import('./pages/survey-list');
|
|
5
|
+
return page;
|
|
6
|
+
case 'survey-editor':
|
|
7
|
+
import('./pages/survey-editor');
|
|
8
|
+
return page;
|
|
9
|
+
case 'survey-trustee':
|
|
10
|
+
import('./pages/survey-trustee');
|
|
11
|
+
return page;
|
|
12
|
+
case 'my-surveys':
|
|
13
|
+
import('./pages/my-surveys');
|
|
14
|
+
return page;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Row = Record<string, any>;
|
|
2
|
+
/** Run a mutation; say what the server refused and answer nothing. */
|
|
3
|
+
export declare function mutate<T = any>(mutation: any, variables: Record<string, any>): Promise<T | undefined>;
|
|
4
|
+
export declare const SURVEY_STATUS_KEYS: string[];
|
|
5
|
+
export declare const statusLabel: (status: string) => string;
|
|
6
|
+
export declare const levelLabel: (level: string) => string;
|
|
7
|
+
/** One question's published count as rows of a label, a number and its share of the largest. */
|
|
8
|
+
export declare function countRows(question: Row, count: Row | undefined): {
|
|
9
|
+
label: string;
|
|
10
|
+
value: number;
|
|
11
|
+
share: number;
|
|
12
|
+
}[];
|
|
13
|
+
/** A scale's average from its count - the sum over how many answered. */
|
|
14
|
+
export declare function averageOf(count: Row | undefined): string | undefined;
|
|
15
|
+
/** Asks once in the shared popup (ADR-0060 decision 9) - never the browser's confirm. */
|
|
16
|
+
export declare function sure(text: string, confirm: string, destructive?: boolean): Promise<boolean>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { client } from '@operato/graphql';
|
|
2
|
+
import { i18next } from '@operato/i18n';
|
|
3
|
+
import { notify } from '@operato/layout';
|
|
4
|
+
import { OxPrompt } from '@operato/popup';
|
|
5
|
+
/** Run a mutation; say what the server refused and answer nothing. */
|
|
6
|
+
export async function mutate(mutation, variables) {
|
|
7
|
+
try {
|
|
8
|
+
const response = await client.mutate({ mutation, variables });
|
|
9
|
+
if (response.errors?.length)
|
|
10
|
+
throw response.errors[0];
|
|
11
|
+
return response.data;
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
notify({ level: 'error', message: error?.graphQLErrors?.[0]?.message ?? error?.message ?? i18next.t('text.error') });
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const SURVEY_STATUS_KEYS = ['DRAFT', 'KEYING', 'OPEN', 'CLOSED', 'DECRYPTING', 'COUNTED', 'PUBLISHED', 'CANCELLED'];
|
|
19
|
+
export const statusLabel = (status) => i18next.t(`label.survey-status-${String(status).toLowerCase()}`);
|
|
20
|
+
export const levelLabel = (level) => i18next.t(`label.survey-level-${String(level).toLowerCase()}`);
|
|
21
|
+
/** One question's published count as rows of a label, a number and its share of the largest. */
|
|
22
|
+
export function countRows(question, count) {
|
|
23
|
+
if (!count)
|
|
24
|
+
return [];
|
|
25
|
+
const labels = Object.fromEntries((question.options ?? []).map((one) => [one.key, one.label]));
|
|
26
|
+
const entries = Object.entries(count.counts ?? {});
|
|
27
|
+
const most = Math.max(1, ...entries.map(([, value]) => value));
|
|
28
|
+
return entries.map(([key, value]) => ({ label: labels[key] ?? key, value, share: value / most }));
|
|
29
|
+
}
|
|
30
|
+
/** A scale's average from its count - the sum over how many answered. */
|
|
31
|
+
export function averageOf(count) {
|
|
32
|
+
if (!count || count.kind !== 'SCALE')
|
|
33
|
+
return undefined;
|
|
34
|
+
const answered = Object.values(count.counts ?? {}).reduce((total, value) => total + value, 0);
|
|
35
|
+
return answered ? (count.sum / answered).toFixed(2) : undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Asks once in the shared popup (ADR-0060 decision 9) - never the browser's confirm. */
|
|
38
|
+
export async function sure(text, confirm, destructive = false) {
|
|
39
|
+
return !!(await OxPrompt.open({
|
|
40
|
+
type: destructive ? 'warning' : 'info',
|
|
41
|
+
title: text,
|
|
42
|
+
confirmButton: { text: confirm, destructive },
|
|
43
|
+
cancelButton: { text: i18next.t('button.cancel') }
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=survey-api.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { nothing } from 'lit';
|
|
2
|
+
import { type Row } from './survey-api.js';
|
|
3
|
+
export declare const SurveyResultStyles: import("lit").CSSResult;
|
|
4
|
+
export declare function surveyResultView(questions: Row[], figures: Row | undefined | null): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { i18next } from '@operato/i18n';
|
|
3
|
+
import { averageOf, countRows } from './survey-api.js';
|
|
4
|
+
/*
|
|
5
|
+
* A survey's count drawn as bars, question by question (operato-survey design §9) - the published figures for
|
|
6
|
+
* respondents, the operators' count before publishing. A withheld result says only how many answered.
|
|
7
|
+
*/
|
|
8
|
+
export const SurveyResultStyles = css `
|
|
9
|
+
.result {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
gap: 14px;
|
|
13
|
+
}
|
|
14
|
+
.result h4 {
|
|
15
|
+
margin: 0 0 6px;
|
|
16
|
+
font-size: 14px;
|
|
17
|
+
}
|
|
18
|
+
.bar {
|
|
19
|
+
display: grid;
|
|
20
|
+
grid-template-columns: minmax(80px, 30%) 1fr 56px;
|
|
21
|
+
gap: 8px;
|
|
22
|
+
align-items: center;
|
|
23
|
+
font-size: 13px;
|
|
24
|
+
}
|
|
25
|
+
.bar .track {
|
|
26
|
+
height: 10px;
|
|
27
|
+
border-radius: 5px;
|
|
28
|
+
background: var(--md-sys-color-surface-container-high);
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
}
|
|
31
|
+
.bar .fill {
|
|
32
|
+
height: 100%;
|
|
33
|
+
background: var(--md-sys-color-primary);
|
|
34
|
+
}
|
|
35
|
+
.bar .value {
|
|
36
|
+
text-align: right;
|
|
37
|
+
font-variant-numeric: tabular-nums;
|
|
38
|
+
}
|
|
39
|
+
.top {
|
|
40
|
+
margin: 0;
|
|
41
|
+
padding-left: 20px;
|
|
42
|
+
font-size: 14px;
|
|
43
|
+
}
|
|
44
|
+
.muted {
|
|
45
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
46
|
+
font-size: 13px;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
export function surveyResultView(questions, figures) {
|
|
50
|
+
if (!figures)
|
|
51
|
+
return nothing;
|
|
52
|
+
if (figures.withheld)
|
|
53
|
+
return html `<p class="muted">${i18next.t('text.survey-result-withheld', { responded: figures.responded })}</p>`;
|
|
54
|
+
const counts = figures.questions ?? figures.unweighted ?? [];
|
|
55
|
+
return html `<div class="result">
|
|
56
|
+
<p class="muted">${i18next.t('text.survey-result-responded', { responded: figures.responded })}${figures.figure === 'WEIGHTED' ? ` · ${i18next.t('label.survey-figure-weighted')}` : ''}</p>
|
|
57
|
+
${[...questions]
|
|
58
|
+
.sort((a, b) => a.seq - b.seq)
|
|
59
|
+
.map(question => {
|
|
60
|
+
const count = counts.find(one => one.questionId === question.id);
|
|
61
|
+
const average = averageOf(count);
|
|
62
|
+
return html `<section>
|
|
63
|
+
<h4>${question.seq}. ${question.prompt}</h4>
|
|
64
|
+
${count?.top
|
|
65
|
+
? html `<ol class="top">
|
|
66
|
+
${count.top.map((place) => html `<li>${i18next.t('text.survey-top-place', { rank: place.rank, label: (question.options ?? []).find((one) => one.key === place.key)?.label ?? place.key })}${place.value !== undefined ? ` · ${place.value}` : ''}</li>`)}
|
|
67
|
+
</ol>`
|
|
68
|
+
: nothing}
|
|
69
|
+
${countRows(question, count?.top ? undefined : count).map(row => html `<div class="bar">
|
|
70
|
+
<span>${row.label}</span>
|
|
71
|
+
<span class="track"><span class="fill" style="display:block;width:${Math.round(row.share * 100)}%"></span></span>
|
|
72
|
+
<span class="value">${row.value}</span>
|
|
73
|
+
</div>`)}
|
|
74
|
+
${average ? html `<p class="muted">${i18next.t('text.survey-scale-average', { average })}</p>` : nothing}
|
|
75
|
+
</section>`;
|
|
76
|
+
})}
|
|
77
|
+
</div>`;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=survey-result.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type Row = Record<string, any>;
|
|
2
|
+
/** A refusal from the ballot route, carried like a server refusal: its code, said by the screen. */
|
|
3
|
+
export declare class BallotRefusal extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(code: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const pendingBallotOf: (surveyId: string) => Row;
|
|
8
|
+
export declare const receiptOf: (surveyId: string) => string | undefined;
|
|
9
|
+
/** Sends a ballot that was sealed and signed but not yet received - the same ballot, the same token. */
|
|
10
|
+
export declare function resendPending(surveyId: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Seals my answers to the survey's key, takes my one token blind, and sends the ballot without a sign-in. The ballot is
|
|
13
|
+
* sealed before the token is taken, so a failure to seal spends nothing; once signed, it is kept here until received.
|
|
14
|
+
*/
|
|
15
|
+
export declare function castSecretBallot(surveyId: string, questions: Row[], answers: Record<string, Row>): Promise<string>;
|
|
16
|
+
/** The key holder's secret, sealed with their passphrase into a file they keep - the server never sees either. */
|
|
17
|
+
export declare function keyFileOf(content: Row, passphrase: string): Promise<Blob>;
|
|
18
|
+
export declare function readKeyFile(file: File, passphrase: string): Promise<Row>;
|
|
19
|
+
export declare function download(blob: Blob, name: string): void;
|
|
20
|
+
/** Step one: a transport key, its secret into the key file. */
|
|
21
|
+
export declare function makeTransportKey(surveyId: string, seq: number): {
|
|
22
|
+
secret: string;
|
|
23
|
+
key: string;
|
|
24
|
+
proof: import("@things-factory/survey/dist-shared/proofs.js").KnowsLogProof;
|
|
25
|
+
};
|
|
26
|
+
/** Step two: my dealing, and a share sealed to every key holder's transport key. */
|
|
27
|
+
export declare function makeDealing(view: Row): {
|
|
28
|
+
dealing: {
|
|
29
|
+
commitments: string[];
|
|
30
|
+
proof: import("@things-factory/survey/dist-shared/proofs.js").KnowsLogProof;
|
|
31
|
+
};
|
|
32
|
+
sealed: {
|
|
33
|
+
[k: string]: any;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** My share of the survey's key - every share sealed to me, each checked against its dealer's commitments. */
|
|
37
|
+
export declare function myShareOf(view: Row, transportSecret: string): bigint;
|
|
38
|
+
/** Step four: my partial decryption of every sum. */
|
|
39
|
+
export declare function makePartials(view: Row, share: bigint): import("@things-factory/survey/dist-shared/threshold.js").Partial[][];
|
|
40
|
+
export { checkBulletin, type Check } from '@things-factory/survey/dist-shared/verify.js';
|