stated-protocol 5.0.0
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/README.md +409 -0
- package/dist/constants.d.ts +225 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +227 -0
- package/dist/constants.js.map +1 -0
- package/dist/esm/constants.d.ts +225 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/hash.d.ts +37 -0
- package/dist/esm/hash.d.ts.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2104 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/protocol.d.ts +30 -0
- package/dist/esm/protocol.d.ts.map +1 -0
- package/dist/esm/signature.d.ts +49 -0
- package/dist/esm/signature.d.ts.map +1 -0
- package/dist/esm/types.d.ts +115 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/utils.d.ts +14 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/hash.d.ts +37 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +99 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +30 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +677 -0
- package/dist/protocol.js.map +1 -0
- package/dist/signature.d.ts +49 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +169 -0
- package/dist/signature.js.map +1 -0
- package/dist/types.d.ts +115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +96 -0
- package/dist/utils.js.map +1 -0
- package/package.json +66 -0
- package/src/constants.ts +245 -0
- package/src/fixtures.test.ts +236 -0
- package/src/hash.test.ts +219 -0
- package/src/hash.ts +99 -0
- package/src/index.ts +5 -0
- package/src/organisation-verification.test.ts +50 -0
- package/src/person-verification.test.ts +55 -0
- package/src/poll.test.ts +28 -0
- package/src/protocol.ts +871 -0
- package/src/rating.test.ts +25 -0
- package/src/signature.test.ts +200 -0
- package/src/signature.ts +159 -0
- package/src/statement.test.ts +101 -0
- package/src/types.ts +185 -0
- package/src/utils.test.ts +140 -0
- package/src/utils.ts +104 -0
|
@@ -0,0 +1,2104 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/constants.ts
|
|
6
|
+
var legalForms = {
|
|
7
|
+
local_government: "local government",
|
|
8
|
+
state_government: "state government",
|
|
9
|
+
foreign_affairs_ministry: "foreign affairs ministry",
|
|
10
|
+
corporation: "corporation"
|
|
11
|
+
};
|
|
12
|
+
var statementTypes = {
|
|
13
|
+
statement: "statement",
|
|
14
|
+
organisationVerification: "organisation_verification",
|
|
15
|
+
personVerification: "person_verification",
|
|
16
|
+
poll: "poll",
|
|
17
|
+
vote: "vote",
|
|
18
|
+
response: "response",
|
|
19
|
+
disputeContent: "dispute_statement_content",
|
|
20
|
+
disputeAuthenticity: "dispute_statement_authenticity",
|
|
21
|
+
rating: "rating",
|
|
22
|
+
signPdf: "sign_pdf",
|
|
23
|
+
unsupported: "unsupported"
|
|
24
|
+
};
|
|
25
|
+
var peopleCountBuckets = {
|
|
26
|
+
"0": "0-10",
|
|
27
|
+
"10": "10-100",
|
|
28
|
+
"100": "100-1000",
|
|
29
|
+
"1000": "1000-10,000",
|
|
30
|
+
"10000": "10,000-100,000",
|
|
31
|
+
"100000": "100,000+",
|
|
32
|
+
"1000000": "1,000,000+",
|
|
33
|
+
"10000000": "10,000,000+"
|
|
34
|
+
};
|
|
35
|
+
var supportedLanguages = {
|
|
36
|
+
aa: "aa",
|
|
37
|
+
ab: "ab",
|
|
38
|
+
af: "af",
|
|
39
|
+
ak: "ak",
|
|
40
|
+
am: "am",
|
|
41
|
+
ar: "ar",
|
|
42
|
+
an: "an",
|
|
43
|
+
as: "as",
|
|
44
|
+
av: "av",
|
|
45
|
+
ay: "ay",
|
|
46
|
+
az: "az",
|
|
47
|
+
ba: "ba",
|
|
48
|
+
bm: "bm",
|
|
49
|
+
be: "be",
|
|
50
|
+
bn: "bn",
|
|
51
|
+
bi: "bi",
|
|
52
|
+
bo: "bo",
|
|
53
|
+
bs: "bs",
|
|
54
|
+
br: "br",
|
|
55
|
+
bg: "bg",
|
|
56
|
+
ca: "ca",
|
|
57
|
+
cs: "cs",
|
|
58
|
+
ch: "ch",
|
|
59
|
+
ce: "ce",
|
|
60
|
+
cv: "cv",
|
|
61
|
+
kw: "kw",
|
|
62
|
+
co: "co",
|
|
63
|
+
cr: "cr",
|
|
64
|
+
cy: "cy",
|
|
65
|
+
da: "da",
|
|
66
|
+
de: "de",
|
|
67
|
+
dv: "dv",
|
|
68
|
+
dz: "dz",
|
|
69
|
+
el: "el",
|
|
70
|
+
en: "en",
|
|
71
|
+
eo: "eo",
|
|
72
|
+
et: "et",
|
|
73
|
+
eu: "eu",
|
|
74
|
+
ee: "ee",
|
|
75
|
+
fo: "fo",
|
|
76
|
+
fa: "fa",
|
|
77
|
+
fj: "fj",
|
|
78
|
+
fi: "fi",
|
|
79
|
+
fr: "fr",
|
|
80
|
+
fy: "fy",
|
|
81
|
+
ff: "ff",
|
|
82
|
+
gd: "gd",
|
|
83
|
+
ga: "ga",
|
|
84
|
+
gl: "gl",
|
|
85
|
+
gv: "gv",
|
|
86
|
+
gn: "gn",
|
|
87
|
+
gu: "gu",
|
|
88
|
+
ht: "ht",
|
|
89
|
+
ha: "ha",
|
|
90
|
+
sh: "sh",
|
|
91
|
+
he: "he",
|
|
92
|
+
hz: "hz",
|
|
93
|
+
hi: "hi",
|
|
94
|
+
ho: "ho",
|
|
95
|
+
hr: "hr",
|
|
96
|
+
hu: "hu",
|
|
97
|
+
hy: "hy",
|
|
98
|
+
ig: "ig",
|
|
99
|
+
io: "io",
|
|
100
|
+
ii: "ii",
|
|
101
|
+
iu: "iu",
|
|
102
|
+
ie: "ie",
|
|
103
|
+
ia: "ia",
|
|
104
|
+
id: "id",
|
|
105
|
+
ik: "ik",
|
|
106
|
+
is: "is",
|
|
107
|
+
it: "it",
|
|
108
|
+
jv: "jv",
|
|
109
|
+
ja: "ja",
|
|
110
|
+
kl: "kl",
|
|
111
|
+
kn: "kn",
|
|
112
|
+
ks: "ks",
|
|
113
|
+
ka: "ka",
|
|
114
|
+
kr: "kr",
|
|
115
|
+
kk: "kk",
|
|
116
|
+
km: "km",
|
|
117
|
+
ki: "ki",
|
|
118
|
+
rw: "rw",
|
|
119
|
+
ky: "ky",
|
|
120
|
+
kv: "kv",
|
|
121
|
+
kg: "kg",
|
|
122
|
+
ko: "ko",
|
|
123
|
+
kj: "kj",
|
|
124
|
+
ku: "ku",
|
|
125
|
+
lo: "lo",
|
|
126
|
+
la: "la",
|
|
127
|
+
lv: "lv",
|
|
128
|
+
li: "li",
|
|
129
|
+
ln: "ln",
|
|
130
|
+
lt: "lt",
|
|
131
|
+
lb: "lb",
|
|
132
|
+
lu: "lu",
|
|
133
|
+
lg: "lg",
|
|
134
|
+
mh: "mh",
|
|
135
|
+
ml: "ml",
|
|
136
|
+
mr: "mr",
|
|
137
|
+
mk: "mk",
|
|
138
|
+
mg: "mg",
|
|
139
|
+
mt: "mt",
|
|
140
|
+
mn: "mn",
|
|
141
|
+
mi: "mi",
|
|
142
|
+
ms: "ms",
|
|
143
|
+
my: "my",
|
|
144
|
+
na: "na",
|
|
145
|
+
nv: "nv",
|
|
146
|
+
nr: "nr",
|
|
147
|
+
nd: "nd",
|
|
148
|
+
ng: "ng",
|
|
149
|
+
ne: "ne",
|
|
150
|
+
nl: "nl",
|
|
151
|
+
nn: "nn",
|
|
152
|
+
nb: "nb",
|
|
153
|
+
no: "no",
|
|
154
|
+
ny: "ny",
|
|
155
|
+
oc: "oc",
|
|
156
|
+
oj: "oj",
|
|
157
|
+
or: "or",
|
|
158
|
+
om: "om",
|
|
159
|
+
os: "os",
|
|
160
|
+
pa: "pa",
|
|
161
|
+
pi: "pi",
|
|
162
|
+
pl: "pl",
|
|
163
|
+
pt: "pt",
|
|
164
|
+
ps: "ps",
|
|
165
|
+
qu: "qu",
|
|
166
|
+
rm: "rm",
|
|
167
|
+
ro: "ro",
|
|
168
|
+
rn: "rn",
|
|
169
|
+
ru: "ru",
|
|
170
|
+
sg: "sg",
|
|
171
|
+
sa: "sa",
|
|
172
|
+
si: "si",
|
|
173
|
+
sk: "sk",
|
|
174
|
+
sl: "sl",
|
|
175
|
+
se: "se",
|
|
176
|
+
sm: "sm",
|
|
177
|
+
sn: "sn",
|
|
178
|
+
sd: "sd",
|
|
179
|
+
so: "so",
|
|
180
|
+
st: "st",
|
|
181
|
+
es: "es",
|
|
182
|
+
sq: "sq",
|
|
183
|
+
sc: "sc",
|
|
184
|
+
sr: "sr",
|
|
185
|
+
ss: "ss",
|
|
186
|
+
su: "su",
|
|
187
|
+
sw: "sw",
|
|
188
|
+
sv: "sv",
|
|
189
|
+
ty: "ty",
|
|
190
|
+
ta: "ta",
|
|
191
|
+
tt: "tt",
|
|
192
|
+
te: "te",
|
|
193
|
+
tg: "tg",
|
|
194
|
+
tl: "tl",
|
|
195
|
+
th: "th",
|
|
196
|
+
ti: "ti",
|
|
197
|
+
to: "to",
|
|
198
|
+
tn: "tn",
|
|
199
|
+
ts: "ts",
|
|
200
|
+
tk: "tk",
|
|
201
|
+
tr: "tr",
|
|
202
|
+
tw: "tw",
|
|
203
|
+
ug: "ug",
|
|
204
|
+
uk: "uk",
|
|
205
|
+
ur: "ur",
|
|
206
|
+
uz: "uz",
|
|
207
|
+
ve: "ve",
|
|
208
|
+
vi: "vi",
|
|
209
|
+
vo: "vo",
|
|
210
|
+
wa: "wa",
|
|
211
|
+
wo: "wo",
|
|
212
|
+
xh: "xh",
|
|
213
|
+
yi: "yi",
|
|
214
|
+
yo: "yo",
|
|
215
|
+
za: "za",
|
|
216
|
+
zh: "zh",
|
|
217
|
+
zu: "zu"
|
|
218
|
+
};
|
|
219
|
+
var UTCFormat = /(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s\d{2}\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT/;
|
|
220
|
+
var pollKeys = /(Type: |The poll outcome is finalized when the following nodes agree: |Voting deadline: |Poll: |Option 1: |Option 2: |Option 3: |Option 4: |Option 5: |Allow free text votes: |Who can vote: |Description: |Country scope: |City scope: |Legal form scope: |Domain scope: |All entities with the following property: |As observed by: |Link to query defining who can vote: )/g;
|
|
221
|
+
var organisationVerificationKeys = /(Type: |Description: |Name: |English name: |Country: |Legal entity: |Legal form: |Department using the domain: |Owner of the domain: |Foreign domain used for publishing statements: |Province or state: |Business register number: |City: |Longitude: |Latitude: |Population: |Logo: |Employee count: |Reliability policy: |Confidence: |Public key: )/g;
|
|
222
|
+
var personVerificationKeys = /(Type: |Description: |Name: |Date of birth: |City of birth: |Country of birth: |Job title: |Employer: |Owner of the domain: |Foreign domain used for publishing statements: |Picture: |Verification method: |Confidence: |Reliability policy: )/g;
|
|
223
|
+
var voteKeys = /(Type: |Poll id: |Poll: |Option: )/g;
|
|
224
|
+
var disputeAuthenticityKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
|
|
225
|
+
var disputeContentKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
|
|
226
|
+
var responseKeys = /(Type: |Hash of referenced statement: |Response: )/;
|
|
227
|
+
var PDFSigningKeys = /(Type: |Description: |PDF file hash: )/g;
|
|
228
|
+
var ratingKeys = /(Type: |Subject type: |Subject name: |URL that identifies the subject: |Document file hash: |Rated quality: |Our rating: |Comment: )/;
|
|
229
|
+
|
|
230
|
+
// node_modules/@noble/hashes/utils.js
|
|
231
|
+
function isBytes(a) {
|
|
232
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
233
|
+
}
|
|
234
|
+
function abytes(value, length, title = "") {
|
|
235
|
+
const bytes = isBytes(value);
|
|
236
|
+
const len = value?.length;
|
|
237
|
+
const needsLen = length !== void 0;
|
|
238
|
+
if (!bytes || needsLen && len !== length) {
|
|
239
|
+
const prefix = title && `"${title}" `;
|
|
240
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
241
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
242
|
+
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
243
|
+
}
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
function aexists(instance, checkFinished = true) {
|
|
247
|
+
if (instance.destroyed)
|
|
248
|
+
throw new Error("Hash instance has been destroyed");
|
|
249
|
+
if (checkFinished && instance.finished)
|
|
250
|
+
throw new Error("Hash#digest() has already been called");
|
|
251
|
+
}
|
|
252
|
+
function aoutput(out, instance) {
|
|
253
|
+
abytes(out, void 0, "digestInto() output");
|
|
254
|
+
const min = instance.outputLen;
|
|
255
|
+
if (out.length < min) {
|
|
256
|
+
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function clean(...arrays) {
|
|
260
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
261
|
+
arrays[i].fill(0);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function createView(arr) {
|
|
265
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
266
|
+
}
|
|
267
|
+
function rotr(word, shift) {
|
|
268
|
+
return word << 32 - shift | word >>> shift;
|
|
269
|
+
}
|
|
270
|
+
function createHasher(hashCons, info = {}) {
|
|
271
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
272
|
+
const tmp = hashCons(void 0);
|
|
273
|
+
hashC.outputLen = tmp.outputLen;
|
|
274
|
+
hashC.blockLen = tmp.blockLen;
|
|
275
|
+
hashC.create = (opts) => hashCons(opts);
|
|
276
|
+
Object.assign(hashC, info);
|
|
277
|
+
return Object.freeze(hashC);
|
|
278
|
+
}
|
|
279
|
+
var oidNist = (suffix) => ({
|
|
280
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// node_modules/@noble/hashes/_md.js
|
|
284
|
+
function Chi(a, b, c) {
|
|
285
|
+
return a & b ^ ~a & c;
|
|
286
|
+
}
|
|
287
|
+
function Maj(a, b, c) {
|
|
288
|
+
return a & b ^ a & c ^ b & c;
|
|
289
|
+
}
|
|
290
|
+
var HashMD = class {
|
|
291
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
292
|
+
__publicField(this, "blockLen");
|
|
293
|
+
__publicField(this, "outputLen");
|
|
294
|
+
__publicField(this, "padOffset");
|
|
295
|
+
__publicField(this, "isLE");
|
|
296
|
+
// For partial updates less than block size
|
|
297
|
+
__publicField(this, "buffer");
|
|
298
|
+
__publicField(this, "view");
|
|
299
|
+
__publicField(this, "finished", false);
|
|
300
|
+
__publicField(this, "length", 0);
|
|
301
|
+
__publicField(this, "pos", 0);
|
|
302
|
+
__publicField(this, "destroyed", false);
|
|
303
|
+
this.blockLen = blockLen;
|
|
304
|
+
this.outputLen = outputLen;
|
|
305
|
+
this.padOffset = padOffset;
|
|
306
|
+
this.isLE = isLE;
|
|
307
|
+
this.buffer = new Uint8Array(blockLen);
|
|
308
|
+
this.view = createView(this.buffer);
|
|
309
|
+
}
|
|
310
|
+
update(data) {
|
|
311
|
+
aexists(this);
|
|
312
|
+
abytes(data);
|
|
313
|
+
const { view, buffer, blockLen } = this;
|
|
314
|
+
const len = data.length;
|
|
315
|
+
for (let pos = 0; pos < len; ) {
|
|
316
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
317
|
+
if (take === blockLen) {
|
|
318
|
+
const dataView = createView(data);
|
|
319
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
320
|
+
this.process(dataView, pos);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
324
|
+
this.pos += take;
|
|
325
|
+
pos += take;
|
|
326
|
+
if (this.pos === blockLen) {
|
|
327
|
+
this.process(view, 0);
|
|
328
|
+
this.pos = 0;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
this.length += data.length;
|
|
332
|
+
this.roundClean();
|
|
333
|
+
return this;
|
|
334
|
+
}
|
|
335
|
+
digestInto(out) {
|
|
336
|
+
aexists(this);
|
|
337
|
+
aoutput(out, this);
|
|
338
|
+
this.finished = true;
|
|
339
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
340
|
+
let { pos } = this;
|
|
341
|
+
buffer[pos++] = 128;
|
|
342
|
+
clean(this.buffer.subarray(pos));
|
|
343
|
+
if (this.padOffset > blockLen - pos) {
|
|
344
|
+
this.process(view, 0);
|
|
345
|
+
pos = 0;
|
|
346
|
+
}
|
|
347
|
+
for (let i = pos; i < blockLen; i++)
|
|
348
|
+
buffer[i] = 0;
|
|
349
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
350
|
+
this.process(view, 0);
|
|
351
|
+
const oview = createView(out);
|
|
352
|
+
const len = this.outputLen;
|
|
353
|
+
if (len % 4)
|
|
354
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
355
|
+
const outLen = len / 4;
|
|
356
|
+
const state = this.get();
|
|
357
|
+
if (outLen > state.length)
|
|
358
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
359
|
+
for (let i = 0; i < outLen; i++)
|
|
360
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
361
|
+
}
|
|
362
|
+
digest() {
|
|
363
|
+
const { buffer, outputLen } = this;
|
|
364
|
+
this.digestInto(buffer);
|
|
365
|
+
const res = buffer.slice(0, outputLen);
|
|
366
|
+
this.destroy();
|
|
367
|
+
return res;
|
|
368
|
+
}
|
|
369
|
+
_cloneInto(to) {
|
|
370
|
+
to || (to = new this.constructor());
|
|
371
|
+
to.set(...this.get());
|
|
372
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
373
|
+
to.destroyed = destroyed;
|
|
374
|
+
to.finished = finished;
|
|
375
|
+
to.length = length;
|
|
376
|
+
to.pos = pos;
|
|
377
|
+
if (length % blockLen)
|
|
378
|
+
to.buffer.set(buffer);
|
|
379
|
+
return to;
|
|
380
|
+
}
|
|
381
|
+
clone() {
|
|
382
|
+
return this._cloneInto();
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
386
|
+
1779033703,
|
|
387
|
+
3144134277,
|
|
388
|
+
1013904242,
|
|
389
|
+
2773480762,
|
|
390
|
+
1359893119,
|
|
391
|
+
2600822924,
|
|
392
|
+
528734635,
|
|
393
|
+
1541459225
|
|
394
|
+
]);
|
|
395
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
396
|
+
1779033703,
|
|
397
|
+
4089235720,
|
|
398
|
+
3144134277,
|
|
399
|
+
2227873595,
|
|
400
|
+
1013904242,
|
|
401
|
+
4271175723,
|
|
402
|
+
2773480762,
|
|
403
|
+
1595750129,
|
|
404
|
+
1359893119,
|
|
405
|
+
2917565137,
|
|
406
|
+
2600822924,
|
|
407
|
+
725511199,
|
|
408
|
+
528734635,
|
|
409
|
+
4215389547,
|
|
410
|
+
1541459225,
|
|
411
|
+
327033209
|
|
412
|
+
]);
|
|
413
|
+
|
|
414
|
+
// node_modules/@noble/hashes/_u64.js
|
|
415
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
416
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
417
|
+
function fromBig(n, le = false) {
|
|
418
|
+
if (le)
|
|
419
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
420
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
421
|
+
}
|
|
422
|
+
function split(lst, le = false) {
|
|
423
|
+
const len = lst.length;
|
|
424
|
+
let Ah = new Uint32Array(len);
|
|
425
|
+
let Al = new Uint32Array(len);
|
|
426
|
+
for (let i = 0; i < len; i++) {
|
|
427
|
+
const { h: h2, l } = fromBig(lst[i], le);
|
|
428
|
+
[Ah[i], Al[i]] = [h2, l];
|
|
429
|
+
}
|
|
430
|
+
return [Ah, Al];
|
|
431
|
+
}
|
|
432
|
+
var shrSH = (h2, _l, s) => h2 >>> s;
|
|
433
|
+
var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
434
|
+
var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
|
|
435
|
+
var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
436
|
+
var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
|
|
437
|
+
var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
|
|
438
|
+
function add(Ah, Al, Bh, Bl) {
|
|
439
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
440
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
441
|
+
}
|
|
442
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
443
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
444
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
445
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
446
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
447
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
448
|
+
|
|
449
|
+
// node_modules/@noble/hashes/sha2.js
|
|
450
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
451
|
+
1116352408,
|
|
452
|
+
1899447441,
|
|
453
|
+
3049323471,
|
|
454
|
+
3921009573,
|
|
455
|
+
961987163,
|
|
456
|
+
1508970993,
|
|
457
|
+
2453635748,
|
|
458
|
+
2870763221,
|
|
459
|
+
3624381080,
|
|
460
|
+
310598401,
|
|
461
|
+
607225278,
|
|
462
|
+
1426881987,
|
|
463
|
+
1925078388,
|
|
464
|
+
2162078206,
|
|
465
|
+
2614888103,
|
|
466
|
+
3248222580,
|
|
467
|
+
3835390401,
|
|
468
|
+
4022224774,
|
|
469
|
+
264347078,
|
|
470
|
+
604807628,
|
|
471
|
+
770255983,
|
|
472
|
+
1249150122,
|
|
473
|
+
1555081692,
|
|
474
|
+
1996064986,
|
|
475
|
+
2554220882,
|
|
476
|
+
2821834349,
|
|
477
|
+
2952996808,
|
|
478
|
+
3210313671,
|
|
479
|
+
3336571891,
|
|
480
|
+
3584528711,
|
|
481
|
+
113926993,
|
|
482
|
+
338241895,
|
|
483
|
+
666307205,
|
|
484
|
+
773529912,
|
|
485
|
+
1294757372,
|
|
486
|
+
1396182291,
|
|
487
|
+
1695183700,
|
|
488
|
+
1986661051,
|
|
489
|
+
2177026350,
|
|
490
|
+
2456956037,
|
|
491
|
+
2730485921,
|
|
492
|
+
2820302411,
|
|
493
|
+
3259730800,
|
|
494
|
+
3345764771,
|
|
495
|
+
3516065817,
|
|
496
|
+
3600352804,
|
|
497
|
+
4094571909,
|
|
498
|
+
275423344,
|
|
499
|
+
430227734,
|
|
500
|
+
506948616,
|
|
501
|
+
659060556,
|
|
502
|
+
883997877,
|
|
503
|
+
958139571,
|
|
504
|
+
1322822218,
|
|
505
|
+
1537002063,
|
|
506
|
+
1747873779,
|
|
507
|
+
1955562222,
|
|
508
|
+
2024104815,
|
|
509
|
+
2227730452,
|
|
510
|
+
2361852424,
|
|
511
|
+
2428436474,
|
|
512
|
+
2756734187,
|
|
513
|
+
3204031479,
|
|
514
|
+
3329325298
|
|
515
|
+
]);
|
|
516
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
517
|
+
var SHA2_32B = class extends HashMD {
|
|
518
|
+
constructor(outputLen) {
|
|
519
|
+
super(64, outputLen, 8, false);
|
|
520
|
+
}
|
|
521
|
+
get() {
|
|
522
|
+
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
523
|
+
return [A, B, C2, D, E, F, G2, H];
|
|
524
|
+
}
|
|
525
|
+
// prettier-ignore
|
|
526
|
+
set(A, B, C2, D, E, F, G2, H) {
|
|
527
|
+
this.A = A | 0;
|
|
528
|
+
this.B = B | 0;
|
|
529
|
+
this.C = C2 | 0;
|
|
530
|
+
this.D = D | 0;
|
|
531
|
+
this.E = E | 0;
|
|
532
|
+
this.F = F | 0;
|
|
533
|
+
this.G = G2 | 0;
|
|
534
|
+
this.H = H | 0;
|
|
535
|
+
}
|
|
536
|
+
process(view, offset) {
|
|
537
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
538
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
539
|
+
for (let i = 16; i < 64; i++) {
|
|
540
|
+
const W15 = SHA256_W[i - 15];
|
|
541
|
+
const W2 = SHA256_W[i - 2];
|
|
542
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
543
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
544
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
545
|
+
}
|
|
546
|
+
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
547
|
+
for (let i = 0; i < 64; i++) {
|
|
548
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
549
|
+
const T1 = H + sigma1 + Chi(E, F, G2) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
550
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
551
|
+
const T2 = sigma0 + Maj(A, B, C2) | 0;
|
|
552
|
+
H = G2;
|
|
553
|
+
G2 = F;
|
|
554
|
+
F = E;
|
|
555
|
+
E = D + T1 | 0;
|
|
556
|
+
D = C2;
|
|
557
|
+
C2 = B;
|
|
558
|
+
B = A;
|
|
559
|
+
A = T1 + T2 | 0;
|
|
560
|
+
}
|
|
561
|
+
A = A + this.A | 0;
|
|
562
|
+
B = B + this.B | 0;
|
|
563
|
+
C2 = C2 + this.C | 0;
|
|
564
|
+
D = D + this.D | 0;
|
|
565
|
+
E = E + this.E | 0;
|
|
566
|
+
F = F + this.F | 0;
|
|
567
|
+
G2 = G2 + this.G | 0;
|
|
568
|
+
H = H + this.H | 0;
|
|
569
|
+
this.set(A, B, C2, D, E, F, G2, H);
|
|
570
|
+
}
|
|
571
|
+
roundClean() {
|
|
572
|
+
clean(SHA256_W);
|
|
573
|
+
}
|
|
574
|
+
destroy() {
|
|
575
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
576
|
+
clean(this.buffer);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
var _SHA256 = class extends SHA2_32B {
|
|
580
|
+
constructor() {
|
|
581
|
+
super(32);
|
|
582
|
+
// We cannot use array here since array allows indexing by variable
|
|
583
|
+
// which means optimizer/compiler cannot use registers.
|
|
584
|
+
__publicField(this, "A", SHA256_IV[0] | 0);
|
|
585
|
+
__publicField(this, "B", SHA256_IV[1] | 0);
|
|
586
|
+
__publicField(this, "C", SHA256_IV[2] | 0);
|
|
587
|
+
__publicField(this, "D", SHA256_IV[3] | 0);
|
|
588
|
+
__publicField(this, "E", SHA256_IV[4] | 0);
|
|
589
|
+
__publicField(this, "F", SHA256_IV[5] | 0);
|
|
590
|
+
__publicField(this, "G", SHA256_IV[6] | 0);
|
|
591
|
+
__publicField(this, "H", SHA256_IV[7] | 0);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
595
|
+
"0x428a2f98d728ae22",
|
|
596
|
+
"0x7137449123ef65cd",
|
|
597
|
+
"0xb5c0fbcfec4d3b2f",
|
|
598
|
+
"0xe9b5dba58189dbbc",
|
|
599
|
+
"0x3956c25bf348b538",
|
|
600
|
+
"0x59f111f1b605d019",
|
|
601
|
+
"0x923f82a4af194f9b",
|
|
602
|
+
"0xab1c5ed5da6d8118",
|
|
603
|
+
"0xd807aa98a3030242",
|
|
604
|
+
"0x12835b0145706fbe",
|
|
605
|
+
"0x243185be4ee4b28c",
|
|
606
|
+
"0x550c7dc3d5ffb4e2",
|
|
607
|
+
"0x72be5d74f27b896f",
|
|
608
|
+
"0x80deb1fe3b1696b1",
|
|
609
|
+
"0x9bdc06a725c71235",
|
|
610
|
+
"0xc19bf174cf692694",
|
|
611
|
+
"0xe49b69c19ef14ad2",
|
|
612
|
+
"0xefbe4786384f25e3",
|
|
613
|
+
"0x0fc19dc68b8cd5b5",
|
|
614
|
+
"0x240ca1cc77ac9c65",
|
|
615
|
+
"0x2de92c6f592b0275",
|
|
616
|
+
"0x4a7484aa6ea6e483",
|
|
617
|
+
"0x5cb0a9dcbd41fbd4",
|
|
618
|
+
"0x76f988da831153b5",
|
|
619
|
+
"0x983e5152ee66dfab",
|
|
620
|
+
"0xa831c66d2db43210",
|
|
621
|
+
"0xb00327c898fb213f",
|
|
622
|
+
"0xbf597fc7beef0ee4",
|
|
623
|
+
"0xc6e00bf33da88fc2",
|
|
624
|
+
"0xd5a79147930aa725",
|
|
625
|
+
"0x06ca6351e003826f",
|
|
626
|
+
"0x142929670a0e6e70",
|
|
627
|
+
"0x27b70a8546d22ffc",
|
|
628
|
+
"0x2e1b21385c26c926",
|
|
629
|
+
"0x4d2c6dfc5ac42aed",
|
|
630
|
+
"0x53380d139d95b3df",
|
|
631
|
+
"0x650a73548baf63de",
|
|
632
|
+
"0x766a0abb3c77b2a8",
|
|
633
|
+
"0x81c2c92e47edaee6",
|
|
634
|
+
"0x92722c851482353b",
|
|
635
|
+
"0xa2bfe8a14cf10364",
|
|
636
|
+
"0xa81a664bbc423001",
|
|
637
|
+
"0xc24b8b70d0f89791",
|
|
638
|
+
"0xc76c51a30654be30",
|
|
639
|
+
"0xd192e819d6ef5218",
|
|
640
|
+
"0xd69906245565a910",
|
|
641
|
+
"0xf40e35855771202a",
|
|
642
|
+
"0x106aa07032bbd1b8",
|
|
643
|
+
"0x19a4c116b8d2d0c8",
|
|
644
|
+
"0x1e376c085141ab53",
|
|
645
|
+
"0x2748774cdf8eeb99",
|
|
646
|
+
"0x34b0bcb5e19b48a8",
|
|
647
|
+
"0x391c0cb3c5c95a63",
|
|
648
|
+
"0x4ed8aa4ae3418acb",
|
|
649
|
+
"0x5b9cca4f7763e373",
|
|
650
|
+
"0x682e6ff3d6b2b8a3",
|
|
651
|
+
"0x748f82ee5defb2fc",
|
|
652
|
+
"0x78a5636f43172f60",
|
|
653
|
+
"0x84c87814a1f0ab72",
|
|
654
|
+
"0x8cc702081a6439ec",
|
|
655
|
+
"0x90befffa23631e28",
|
|
656
|
+
"0xa4506cebde82bde9",
|
|
657
|
+
"0xbef9a3f7b2c67915",
|
|
658
|
+
"0xc67178f2e372532b",
|
|
659
|
+
"0xca273eceea26619c",
|
|
660
|
+
"0xd186b8c721c0c207",
|
|
661
|
+
"0xeada7dd6cde0eb1e",
|
|
662
|
+
"0xf57d4f7fee6ed178",
|
|
663
|
+
"0x06f067aa72176fba",
|
|
664
|
+
"0x0a637dc5a2c898a6",
|
|
665
|
+
"0x113f9804bef90dae",
|
|
666
|
+
"0x1b710b35131c471b",
|
|
667
|
+
"0x28db77f523047d84",
|
|
668
|
+
"0x32caab7b40c72493",
|
|
669
|
+
"0x3c9ebe0a15c9bebc",
|
|
670
|
+
"0x431d67c49c100d4c",
|
|
671
|
+
"0x4cc5d4becb3e42b6",
|
|
672
|
+
"0x597f299cfc657e2a",
|
|
673
|
+
"0x5fcb6fab3ad6faec",
|
|
674
|
+
"0x6c44198c4a475817"
|
|
675
|
+
].map((n) => BigInt(n))))();
|
|
676
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
677
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
678
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
679
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
680
|
+
var SHA2_64B = class extends HashMD {
|
|
681
|
+
constructor(outputLen) {
|
|
682
|
+
super(128, outputLen, 16, false);
|
|
683
|
+
}
|
|
684
|
+
// prettier-ignore
|
|
685
|
+
get() {
|
|
686
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
687
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
688
|
+
}
|
|
689
|
+
// prettier-ignore
|
|
690
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
691
|
+
this.Ah = Ah | 0;
|
|
692
|
+
this.Al = Al | 0;
|
|
693
|
+
this.Bh = Bh | 0;
|
|
694
|
+
this.Bl = Bl | 0;
|
|
695
|
+
this.Ch = Ch | 0;
|
|
696
|
+
this.Cl = Cl | 0;
|
|
697
|
+
this.Dh = Dh | 0;
|
|
698
|
+
this.Dl = Dl | 0;
|
|
699
|
+
this.Eh = Eh | 0;
|
|
700
|
+
this.El = El | 0;
|
|
701
|
+
this.Fh = Fh | 0;
|
|
702
|
+
this.Fl = Fl | 0;
|
|
703
|
+
this.Gh = Gh | 0;
|
|
704
|
+
this.Gl = Gl | 0;
|
|
705
|
+
this.Hh = Hh | 0;
|
|
706
|
+
this.Hl = Hl | 0;
|
|
707
|
+
}
|
|
708
|
+
process(view, offset) {
|
|
709
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
710
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
711
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
712
|
+
}
|
|
713
|
+
for (let i = 16; i < 80; i++) {
|
|
714
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
715
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
716
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
717
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
718
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
719
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
720
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
721
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
722
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
723
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
724
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
725
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
726
|
+
}
|
|
727
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
728
|
+
for (let i = 0; i < 80; i++) {
|
|
729
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
730
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
731
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
732
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
733
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
734
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
735
|
+
const T1l = T1ll | 0;
|
|
736
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
737
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
738
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
739
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
740
|
+
Hh = Gh | 0;
|
|
741
|
+
Hl = Gl | 0;
|
|
742
|
+
Gh = Fh | 0;
|
|
743
|
+
Gl = Fl | 0;
|
|
744
|
+
Fh = Eh | 0;
|
|
745
|
+
Fl = El | 0;
|
|
746
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
747
|
+
Dh = Ch | 0;
|
|
748
|
+
Dl = Cl | 0;
|
|
749
|
+
Ch = Bh | 0;
|
|
750
|
+
Cl = Bl | 0;
|
|
751
|
+
Bh = Ah | 0;
|
|
752
|
+
Bl = Al | 0;
|
|
753
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
754
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
755
|
+
Al = All | 0;
|
|
756
|
+
}
|
|
757
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
758
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
759
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
760
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
761
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
762
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
763
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
764
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
765
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
766
|
+
}
|
|
767
|
+
roundClean() {
|
|
768
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
769
|
+
}
|
|
770
|
+
destroy() {
|
|
771
|
+
clean(this.buffer);
|
|
772
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
var _SHA512 = class extends SHA2_64B {
|
|
776
|
+
constructor() {
|
|
777
|
+
super(64);
|
|
778
|
+
__publicField(this, "Ah", SHA512_IV[0] | 0);
|
|
779
|
+
__publicField(this, "Al", SHA512_IV[1] | 0);
|
|
780
|
+
__publicField(this, "Bh", SHA512_IV[2] | 0);
|
|
781
|
+
__publicField(this, "Bl", SHA512_IV[3] | 0);
|
|
782
|
+
__publicField(this, "Ch", SHA512_IV[4] | 0);
|
|
783
|
+
__publicField(this, "Cl", SHA512_IV[5] | 0);
|
|
784
|
+
__publicField(this, "Dh", SHA512_IV[6] | 0);
|
|
785
|
+
__publicField(this, "Dl", SHA512_IV[7] | 0);
|
|
786
|
+
__publicField(this, "Eh", SHA512_IV[8] | 0);
|
|
787
|
+
__publicField(this, "El", SHA512_IV[9] | 0);
|
|
788
|
+
__publicField(this, "Fh", SHA512_IV[10] | 0);
|
|
789
|
+
__publicField(this, "Fl", SHA512_IV[11] | 0);
|
|
790
|
+
__publicField(this, "Gh", SHA512_IV[12] | 0);
|
|
791
|
+
__publicField(this, "Gl", SHA512_IV[13] | 0);
|
|
792
|
+
__publicField(this, "Hh", SHA512_IV[14] | 0);
|
|
793
|
+
__publicField(this, "Hl", SHA512_IV[15] | 0);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
var sha256 = /* @__PURE__ */ createHasher(
|
|
797
|
+
() => new _SHA256(),
|
|
798
|
+
/* @__PURE__ */ oidNist(1)
|
|
799
|
+
);
|
|
800
|
+
var sha512 = /* @__PURE__ */ createHasher(
|
|
801
|
+
() => new _SHA512(),
|
|
802
|
+
/* @__PURE__ */ oidNist(3)
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
// src/hash.ts
|
|
806
|
+
var sha2562 = (input) => {
|
|
807
|
+
let data;
|
|
808
|
+
if (typeof input === "string") {
|
|
809
|
+
const encoder = new TextEncoder();
|
|
810
|
+
data = encoder.encode(input);
|
|
811
|
+
} else {
|
|
812
|
+
data = input;
|
|
813
|
+
}
|
|
814
|
+
const hashArray = sha256(data);
|
|
815
|
+
const base64 = bytesToBase64(hashArray);
|
|
816
|
+
const urlSafe = base64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
817
|
+
return urlSafe;
|
|
818
|
+
};
|
|
819
|
+
var verify = (content, hash) => {
|
|
820
|
+
const computed = sha2562(content);
|
|
821
|
+
return computed === hash;
|
|
822
|
+
};
|
|
823
|
+
var fromUrlSafeBase64 = (urlSafe) => {
|
|
824
|
+
const base64 = urlSafe.replace(/-/g, "+").replace(/_/g, "/");
|
|
825
|
+
const padding = "=".repeat((4 - base64.length % 4) % 4);
|
|
826
|
+
return base64 + padding;
|
|
827
|
+
};
|
|
828
|
+
var toUrlSafeBase64 = (base64) => {
|
|
829
|
+
return base64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
830
|
+
};
|
|
831
|
+
function bytesToBase64(bytes) {
|
|
832
|
+
if (typeof btoa !== "undefined") {
|
|
833
|
+
return btoa(String.fromCharCode(...Array.from(bytes)));
|
|
834
|
+
} else {
|
|
835
|
+
return Buffer.from(bytes).toString("base64");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function base64ToBytes(base64) {
|
|
839
|
+
if (typeof atob !== "undefined") {
|
|
840
|
+
const binaryString = atob(base64);
|
|
841
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
842
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
843
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
844
|
+
}
|
|
845
|
+
return bytes;
|
|
846
|
+
} else {
|
|
847
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// src/utils.ts
|
|
852
|
+
var generateFileHash = (fileContent) => {
|
|
853
|
+
return sha2562(fileContent);
|
|
854
|
+
};
|
|
855
|
+
var validateFileHash = (fileContent, expectedHash) => {
|
|
856
|
+
return verify(fileContent, expectedHash);
|
|
857
|
+
};
|
|
858
|
+
var generateStatementContentHash = (statementContent) => {
|
|
859
|
+
return sha2562(statementContent);
|
|
860
|
+
};
|
|
861
|
+
var validateStatementContentHash = (statementContent, expectedHash) => {
|
|
862
|
+
return verify(statementContent, expectedHash);
|
|
863
|
+
};
|
|
864
|
+
var generateStatementHash = (statement) => {
|
|
865
|
+
const signatureRegex = /^([\s\S]+?)---\n[\s\S]+$/;
|
|
866
|
+
const match = statement.match(signatureRegex);
|
|
867
|
+
if (match && match[1]) {
|
|
868
|
+
return sha2562(match[1]);
|
|
869
|
+
}
|
|
870
|
+
return sha2562(statement);
|
|
871
|
+
};
|
|
872
|
+
var validateStatementHash = (statement, expectedHash) => {
|
|
873
|
+
const computedHash = generateStatementHash(statement);
|
|
874
|
+
return computedHash === expectedHash;
|
|
875
|
+
};
|
|
876
|
+
var generateStatementsFile = (statements) => {
|
|
877
|
+
return statements.join("\n\n");
|
|
878
|
+
};
|
|
879
|
+
var parseStatementsFile = (statementsFileContent) => {
|
|
880
|
+
const statementParts = statementsFileContent.split(/\n\nStated protocol version: /);
|
|
881
|
+
const statements = [];
|
|
882
|
+
for (let i = 0; i < statementParts.length; i++) {
|
|
883
|
+
let statement = statementParts[i];
|
|
884
|
+
if (i === 0 && statement.trim().length === 0) continue;
|
|
885
|
+
if (i > 0) {
|
|
886
|
+
statement = "Stated protocol version: " + statement;
|
|
887
|
+
}
|
|
888
|
+
statement = statement.replace(/\n+$/, "\n");
|
|
889
|
+
try {
|
|
890
|
+
parseStatement({ statement });
|
|
891
|
+
statements.push(statement);
|
|
892
|
+
} catch (error) {
|
|
893
|
+
throw new Error(
|
|
894
|
+
`Invalid statement at index ${i}: ${error instanceof Error ? error.message : String(error)}`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return statements;
|
|
899
|
+
};
|
|
900
|
+
var generateStatementFilename = (statement) => {
|
|
901
|
+
const hash = generateStatementHash(statement);
|
|
902
|
+
return `${hash}.txt`;
|
|
903
|
+
};
|
|
904
|
+
var generateAttachmentFilename = (fileContent, extension) => {
|
|
905
|
+
const hash = generateFileHash(fileContent);
|
|
906
|
+
const ext = extension.startsWith(".") ? extension.substring(1) : extension;
|
|
907
|
+
return `${hash}.${ext}`;
|
|
908
|
+
};
|
|
909
|
+
var minPeopleCountToRange = (n) => {
|
|
910
|
+
if (n >= 1e7) return peopleCountBuckets["10000000"];
|
|
911
|
+
if (n >= 1e6) return peopleCountBuckets["1000000"];
|
|
912
|
+
if (n >= 1e5) return peopleCountBuckets["100000"];
|
|
913
|
+
if (n >= 1e4) return peopleCountBuckets["10000"];
|
|
914
|
+
if (n >= 1e3) return peopleCountBuckets["1000"];
|
|
915
|
+
if (n >= 100) return peopleCountBuckets["100"];
|
|
916
|
+
if (n >= 10) return peopleCountBuckets["10"];
|
|
917
|
+
if (n >= 0) return peopleCountBuckets["0"];
|
|
918
|
+
};
|
|
919
|
+
var monthIndex = (month) => ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"].indexOf(
|
|
920
|
+
month.toLowerCase().substr(0, 3)
|
|
921
|
+
);
|
|
922
|
+
var birthDateFormat = /(?<d>\d{1,2})\s(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?<y>\d{4})/;
|
|
923
|
+
|
|
924
|
+
// node_modules/@noble/ed25519/index.js
|
|
925
|
+
var ed25519_CURVE = {
|
|
926
|
+
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
927
|
+
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
928
|
+
h: 8n,
|
|
929
|
+
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
930
|
+
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
931
|
+
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
932
|
+
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
933
|
+
};
|
|
934
|
+
var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
|
|
935
|
+
var L = 32;
|
|
936
|
+
var L2 = 64;
|
|
937
|
+
var captureTrace = (...args) => {
|
|
938
|
+
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
939
|
+
Error.captureStackTrace(...args);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
var err = (message = "") => {
|
|
943
|
+
const e = new Error(message);
|
|
944
|
+
captureTrace(e, err);
|
|
945
|
+
throw e;
|
|
946
|
+
};
|
|
947
|
+
var isBig = (n) => typeof n === "bigint";
|
|
948
|
+
var isStr = (s) => typeof s === "string";
|
|
949
|
+
var isBytes2 = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
950
|
+
var abytes2 = (value, length, title = "") => {
|
|
951
|
+
const bytes = isBytes2(value);
|
|
952
|
+
const len = value?.length;
|
|
953
|
+
const needsLen = length !== void 0;
|
|
954
|
+
if (!bytes || needsLen && len !== length) {
|
|
955
|
+
const prefix = title && `"${title}" `;
|
|
956
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
957
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
958
|
+
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
959
|
+
}
|
|
960
|
+
return value;
|
|
961
|
+
};
|
|
962
|
+
var u8n = (len) => new Uint8Array(len);
|
|
963
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
964
|
+
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
965
|
+
var bytesToHex = (b) => Array.from(abytes2(b)).map((e) => padh(e, 2)).join("");
|
|
966
|
+
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
967
|
+
var _ch = (ch) => {
|
|
968
|
+
if (ch >= C._0 && ch <= C._9)
|
|
969
|
+
return ch - C._0;
|
|
970
|
+
if (ch >= C.A && ch <= C.F)
|
|
971
|
+
return ch - (C.A - 10);
|
|
972
|
+
if (ch >= C.a && ch <= C.f)
|
|
973
|
+
return ch - (C.a - 10);
|
|
974
|
+
return;
|
|
975
|
+
};
|
|
976
|
+
var hexToBytes = (hex) => {
|
|
977
|
+
const e = "hex invalid";
|
|
978
|
+
if (!isStr(hex))
|
|
979
|
+
return err(e);
|
|
980
|
+
const hl = hex.length;
|
|
981
|
+
const al = hl / 2;
|
|
982
|
+
if (hl % 2)
|
|
983
|
+
return err(e);
|
|
984
|
+
const array = u8n(al);
|
|
985
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
986
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
987
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
988
|
+
if (n1 === void 0 || n2 === void 0)
|
|
989
|
+
return err(e);
|
|
990
|
+
array[ai] = n1 * 16 + n2;
|
|
991
|
+
}
|
|
992
|
+
return array;
|
|
993
|
+
};
|
|
994
|
+
var cr = () => globalThis?.crypto;
|
|
995
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
|
|
996
|
+
var concatBytes = (...arrs) => {
|
|
997
|
+
const r = u8n(arrs.reduce((sum, a) => sum + abytes2(a).length, 0));
|
|
998
|
+
let pad = 0;
|
|
999
|
+
arrs.forEach((a) => {
|
|
1000
|
+
r.set(a, pad);
|
|
1001
|
+
pad += a.length;
|
|
1002
|
+
});
|
|
1003
|
+
return r;
|
|
1004
|
+
};
|
|
1005
|
+
var randomBytes = (len = L) => {
|
|
1006
|
+
const c = cr();
|
|
1007
|
+
return c.getRandomValues(u8n(len));
|
|
1008
|
+
};
|
|
1009
|
+
var big = BigInt;
|
|
1010
|
+
var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
1011
|
+
var M = (a, b = P) => {
|
|
1012
|
+
const r = a % b;
|
|
1013
|
+
return r >= 0n ? r : b + r;
|
|
1014
|
+
};
|
|
1015
|
+
var modN = (a) => M(a, N);
|
|
1016
|
+
var invert = (num, md) => {
|
|
1017
|
+
if (num === 0n || md <= 0n)
|
|
1018
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
1019
|
+
let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
1020
|
+
while (a !== 0n) {
|
|
1021
|
+
const q = b / a, r = b % a;
|
|
1022
|
+
const m = x - u * q, n = y - v * q;
|
|
1023
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
1024
|
+
}
|
|
1025
|
+
return b === 1n ? M(x, md) : err("no inverse");
|
|
1026
|
+
};
|
|
1027
|
+
var callHash = (name) => {
|
|
1028
|
+
const fn = hashes[name];
|
|
1029
|
+
if (typeof fn !== "function")
|
|
1030
|
+
err("hashes." + name + " not set");
|
|
1031
|
+
return fn;
|
|
1032
|
+
};
|
|
1033
|
+
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
1034
|
+
var B256 = 2n ** 256n;
|
|
1035
|
+
var _Point = class _Point {
|
|
1036
|
+
constructor(X, Y, Z, T) {
|
|
1037
|
+
__publicField(this, "X");
|
|
1038
|
+
__publicField(this, "Y");
|
|
1039
|
+
__publicField(this, "Z");
|
|
1040
|
+
__publicField(this, "T");
|
|
1041
|
+
const max = B256;
|
|
1042
|
+
this.X = assertRange(X, 0n, max);
|
|
1043
|
+
this.Y = assertRange(Y, 0n, max);
|
|
1044
|
+
this.Z = assertRange(Z, 1n, max);
|
|
1045
|
+
this.T = assertRange(T, 0n, max);
|
|
1046
|
+
Object.freeze(this);
|
|
1047
|
+
}
|
|
1048
|
+
static CURVE() {
|
|
1049
|
+
return ed25519_CURVE;
|
|
1050
|
+
}
|
|
1051
|
+
static fromAffine(p) {
|
|
1052
|
+
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
1053
|
+
}
|
|
1054
|
+
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
1055
|
+
static fromBytes(hex, zip215 = false) {
|
|
1056
|
+
const d = _d;
|
|
1057
|
+
const normed = u8fr(abytes2(hex, L));
|
|
1058
|
+
const lastByte = hex[31];
|
|
1059
|
+
normed[31] = lastByte & ~128;
|
|
1060
|
+
const y = bytesToNumLE(normed);
|
|
1061
|
+
const max = zip215 ? B256 : P;
|
|
1062
|
+
assertRange(y, 0n, max);
|
|
1063
|
+
const y2 = M(y * y);
|
|
1064
|
+
const u = M(y2 - 1n);
|
|
1065
|
+
const v = M(d * y2 + 1n);
|
|
1066
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
1067
|
+
if (!isValid)
|
|
1068
|
+
err("bad point: y not sqrt");
|
|
1069
|
+
const isXOdd = (x & 1n) === 1n;
|
|
1070
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
1071
|
+
if (!zip215 && x === 0n && isLastByteOdd)
|
|
1072
|
+
err("bad point: x==0, isLastByteOdd");
|
|
1073
|
+
if (isLastByteOdd !== isXOdd)
|
|
1074
|
+
x = M(-x);
|
|
1075
|
+
return new _Point(x, y, 1n, M(x * y));
|
|
1076
|
+
}
|
|
1077
|
+
static fromHex(hex, zip215) {
|
|
1078
|
+
return _Point.fromBytes(hexToBytes(hex), zip215);
|
|
1079
|
+
}
|
|
1080
|
+
get x() {
|
|
1081
|
+
return this.toAffine().x;
|
|
1082
|
+
}
|
|
1083
|
+
get y() {
|
|
1084
|
+
return this.toAffine().y;
|
|
1085
|
+
}
|
|
1086
|
+
/** Checks if the point is valid and on-curve. */
|
|
1087
|
+
assertValidity() {
|
|
1088
|
+
const a = _a;
|
|
1089
|
+
const d = _d;
|
|
1090
|
+
const p = this;
|
|
1091
|
+
if (p.is0())
|
|
1092
|
+
return err("bad point: ZERO");
|
|
1093
|
+
const { X, Y, Z, T } = p;
|
|
1094
|
+
const X2 = M(X * X);
|
|
1095
|
+
const Y2 = M(Y * Y);
|
|
1096
|
+
const Z2 = M(Z * Z);
|
|
1097
|
+
const Z4 = M(Z2 * Z2);
|
|
1098
|
+
const aX2 = M(X2 * a);
|
|
1099
|
+
const left = M(Z2 * M(aX2 + Y2));
|
|
1100
|
+
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
1101
|
+
if (left !== right)
|
|
1102
|
+
return err("bad point: equation left != right (1)");
|
|
1103
|
+
const XY = M(X * Y);
|
|
1104
|
+
const ZT = M(Z * T);
|
|
1105
|
+
if (XY !== ZT)
|
|
1106
|
+
return err("bad point: equation left != right (2)");
|
|
1107
|
+
return this;
|
|
1108
|
+
}
|
|
1109
|
+
/** Equality check: compare points P&Q. */
|
|
1110
|
+
equals(other) {
|
|
1111
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
1112
|
+
const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
|
|
1113
|
+
const X1Z2 = M(X1 * Z2);
|
|
1114
|
+
const X2Z1 = M(X2 * Z1);
|
|
1115
|
+
const Y1Z2 = M(Y1 * Z2);
|
|
1116
|
+
const Y2Z1 = M(Y2 * Z1);
|
|
1117
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
1118
|
+
}
|
|
1119
|
+
is0() {
|
|
1120
|
+
return this.equals(I);
|
|
1121
|
+
}
|
|
1122
|
+
/** Flip point over y coordinate. */
|
|
1123
|
+
negate() {
|
|
1124
|
+
return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
|
|
1125
|
+
}
|
|
1126
|
+
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
1127
|
+
double() {
|
|
1128
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
1129
|
+
const a = _a;
|
|
1130
|
+
const A = M(X1 * X1);
|
|
1131
|
+
const B = M(Y1 * Y1);
|
|
1132
|
+
const C2 = M(2n * M(Z1 * Z1));
|
|
1133
|
+
const D = M(a * A);
|
|
1134
|
+
const x1y1 = X1 + Y1;
|
|
1135
|
+
const E = M(M(x1y1 * x1y1) - A - B);
|
|
1136
|
+
const G2 = D + B;
|
|
1137
|
+
const F = G2 - C2;
|
|
1138
|
+
const H = D - B;
|
|
1139
|
+
const X3 = M(E * F);
|
|
1140
|
+
const Y3 = M(G2 * H);
|
|
1141
|
+
const T3 = M(E * H);
|
|
1142
|
+
const Z3 = M(F * G2);
|
|
1143
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
1144
|
+
}
|
|
1145
|
+
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
1146
|
+
add(other) {
|
|
1147
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
1148
|
+
const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
|
|
1149
|
+
const a = _a;
|
|
1150
|
+
const d = _d;
|
|
1151
|
+
const A = M(X1 * X2);
|
|
1152
|
+
const B = M(Y1 * Y2);
|
|
1153
|
+
const C2 = M(T1 * d * T2);
|
|
1154
|
+
const D = M(Z1 * Z2);
|
|
1155
|
+
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
1156
|
+
const F = M(D - C2);
|
|
1157
|
+
const G2 = M(D + C2);
|
|
1158
|
+
const H = M(B - a * A);
|
|
1159
|
+
const X3 = M(E * F);
|
|
1160
|
+
const Y3 = M(G2 * H);
|
|
1161
|
+
const T3 = M(E * H);
|
|
1162
|
+
const Z3 = M(F * G2);
|
|
1163
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
1164
|
+
}
|
|
1165
|
+
subtract(other) {
|
|
1166
|
+
return this.add(apoint(other).negate());
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
1170
|
+
* Uses {@link wNAF} for base point.
|
|
1171
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
1172
|
+
* @param n scalar by which point is multiplied
|
|
1173
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
1174
|
+
*/
|
|
1175
|
+
multiply(n, safe = true) {
|
|
1176
|
+
if (!safe && (n === 0n || this.is0()))
|
|
1177
|
+
return I;
|
|
1178
|
+
assertRange(n, 1n, N);
|
|
1179
|
+
if (n === 1n)
|
|
1180
|
+
return this;
|
|
1181
|
+
if (this.equals(G))
|
|
1182
|
+
return wNAF(n).p;
|
|
1183
|
+
let p = I;
|
|
1184
|
+
let f = G;
|
|
1185
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
1186
|
+
if (n & 1n)
|
|
1187
|
+
p = p.add(d);
|
|
1188
|
+
else if (safe)
|
|
1189
|
+
f = f.add(d);
|
|
1190
|
+
}
|
|
1191
|
+
return p;
|
|
1192
|
+
}
|
|
1193
|
+
multiplyUnsafe(scalar) {
|
|
1194
|
+
return this.multiply(scalar, false);
|
|
1195
|
+
}
|
|
1196
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
1197
|
+
toAffine() {
|
|
1198
|
+
const { X, Y, Z } = this;
|
|
1199
|
+
if (this.equals(I))
|
|
1200
|
+
return { x: 0n, y: 1n };
|
|
1201
|
+
const iz = invert(Z, P);
|
|
1202
|
+
if (M(Z * iz) !== 1n)
|
|
1203
|
+
err("invalid inverse");
|
|
1204
|
+
const x = M(X * iz);
|
|
1205
|
+
const y = M(Y * iz);
|
|
1206
|
+
return { x, y };
|
|
1207
|
+
}
|
|
1208
|
+
toBytes() {
|
|
1209
|
+
const { x, y } = this.assertValidity().toAffine();
|
|
1210
|
+
const b = numTo32bLE(y);
|
|
1211
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
1212
|
+
return b;
|
|
1213
|
+
}
|
|
1214
|
+
toHex() {
|
|
1215
|
+
return bytesToHex(this.toBytes());
|
|
1216
|
+
}
|
|
1217
|
+
clearCofactor() {
|
|
1218
|
+
return this.multiply(big(h), false);
|
|
1219
|
+
}
|
|
1220
|
+
isSmallOrder() {
|
|
1221
|
+
return this.clearCofactor().is0();
|
|
1222
|
+
}
|
|
1223
|
+
isTorsionFree() {
|
|
1224
|
+
let p = this.multiply(N / 2n, false).double();
|
|
1225
|
+
if (N % 2n)
|
|
1226
|
+
p = p.add(this);
|
|
1227
|
+
return p.is0();
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
__publicField(_Point, "BASE");
|
|
1231
|
+
__publicField(_Point, "ZERO");
|
|
1232
|
+
var Point = _Point;
|
|
1233
|
+
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
1234
|
+
var I = new Point(0n, 1n, 1n, 0n);
|
|
1235
|
+
Point.BASE = G;
|
|
1236
|
+
Point.ZERO = I;
|
|
1237
|
+
var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
|
|
1238
|
+
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes2(b)).reverse()));
|
|
1239
|
+
var pow2 = (x, power) => {
|
|
1240
|
+
let r = x;
|
|
1241
|
+
while (power-- > 0n) {
|
|
1242
|
+
r *= r;
|
|
1243
|
+
r %= P;
|
|
1244
|
+
}
|
|
1245
|
+
return r;
|
|
1246
|
+
};
|
|
1247
|
+
var pow_2_252_3 = (x) => {
|
|
1248
|
+
const x2 = x * x % P;
|
|
1249
|
+
const b2 = x2 * x % P;
|
|
1250
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
1251
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
1252
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
1253
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
1254
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
1255
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
1256
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
1257
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
1258
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
1259
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
1260
|
+
return { pow_p_5_8, b2 };
|
|
1261
|
+
};
|
|
1262
|
+
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
1263
|
+
var uvRatio = (u, v) => {
|
|
1264
|
+
const v3 = M(v * v * v);
|
|
1265
|
+
const v7 = M(v3 * v3 * v);
|
|
1266
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
1267
|
+
let x = M(u * v3 * pow);
|
|
1268
|
+
const vx2 = M(v * x * x);
|
|
1269
|
+
const root1 = x;
|
|
1270
|
+
const root2 = M(x * RM1);
|
|
1271
|
+
const useRoot1 = vx2 === u;
|
|
1272
|
+
const useRoot2 = vx2 === M(-u);
|
|
1273
|
+
const noRoot = vx2 === M(-u * RM1);
|
|
1274
|
+
if (useRoot1)
|
|
1275
|
+
x = root1;
|
|
1276
|
+
if (useRoot2 || noRoot)
|
|
1277
|
+
x = root2;
|
|
1278
|
+
if ((M(x) & 1n) === 1n)
|
|
1279
|
+
x = M(-x);
|
|
1280
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
1281
|
+
};
|
|
1282
|
+
var modL_LE = (hash) => modN(bytesToNumLE(hash));
|
|
1283
|
+
var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
|
|
1284
|
+
var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
|
|
1285
|
+
var hash2extK = (hashed) => {
|
|
1286
|
+
const head = hashed.slice(0, L);
|
|
1287
|
+
head[0] &= 248;
|
|
1288
|
+
head[31] &= 127;
|
|
1289
|
+
head[31] |= 64;
|
|
1290
|
+
const prefix = hashed.slice(L, L2);
|
|
1291
|
+
const scalar = modL_LE(head);
|
|
1292
|
+
const point = G.multiply(scalar);
|
|
1293
|
+
const pointBytes = point.toBytes();
|
|
1294
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
1295
|
+
};
|
|
1296
|
+
var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes2(secretKey, L)).then(hash2extK);
|
|
1297
|
+
var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes2(secretKey, L)));
|
|
1298
|
+
var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
|
|
1299
|
+
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
1300
|
+
var _sign = (e, rBytes, msg) => {
|
|
1301
|
+
const { pointBytes: P2, scalar: s } = e;
|
|
1302
|
+
const r = modL_LE(rBytes);
|
|
1303
|
+
const R = G.multiply(r).toBytes();
|
|
1304
|
+
const hashable = concatBytes(R, P2, msg);
|
|
1305
|
+
const finish = (hashed) => {
|
|
1306
|
+
const S = modN(r + modL_LE(hashed) * s);
|
|
1307
|
+
return abytes2(concatBytes(R, numTo32bLE(S)), L2);
|
|
1308
|
+
};
|
|
1309
|
+
return { hashable, finish };
|
|
1310
|
+
};
|
|
1311
|
+
var sign = (message, secretKey) => {
|
|
1312
|
+
const m = abytes2(message);
|
|
1313
|
+
const e = getExtendedPublicKey(secretKey);
|
|
1314
|
+
const rBytes = sha512s(e.prefix, m);
|
|
1315
|
+
return hashFinishS(_sign(e, rBytes, m));
|
|
1316
|
+
};
|
|
1317
|
+
var defaultVerifyOpts = { zip215: true };
|
|
1318
|
+
var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
|
|
1319
|
+
sig = abytes2(sig, L2);
|
|
1320
|
+
msg = abytes2(msg);
|
|
1321
|
+
pub = abytes2(pub, L);
|
|
1322
|
+
const { zip215 } = opts;
|
|
1323
|
+
let A;
|
|
1324
|
+
let R;
|
|
1325
|
+
let s;
|
|
1326
|
+
let SB;
|
|
1327
|
+
let hashable = Uint8Array.of();
|
|
1328
|
+
try {
|
|
1329
|
+
A = Point.fromBytes(pub, zip215);
|
|
1330
|
+
R = Point.fromBytes(sig.slice(0, L), zip215);
|
|
1331
|
+
s = bytesToNumLE(sig.slice(L, L2));
|
|
1332
|
+
SB = G.multiply(s, false);
|
|
1333
|
+
hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
}
|
|
1336
|
+
const finish = (hashed) => {
|
|
1337
|
+
if (SB == null)
|
|
1338
|
+
return false;
|
|
1339
|
+
if (!zip215 && A.isSmallOrder())
|
|
1340
|
+
return false;
|
|
1341
|
+
const k = modL_LE(hashed);
|
|
1342
|
+
const RkA = R.add(A.multiply(k, false));
|
|
1343
|
+
return RkA.add(SB.negate()).clearCofactor().is0();
|
|
1344
|
+
};
|
|
1345
|
+
return { hashable, finish };
|
|
1346
|
+
};
|
|
1347
|
+
var verify2 = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
|
|
1348
|
+
var hashes = {
|
|
1349
|
+
sha512Async: async (message) => {
|
|
1350
|
+
const s = subtle();
|
|
1351
|
+
const m = concatBytes(message);
|
|
1352
|
+
return u8n(await s.digest("SHA-512", m.buffer));
|
|
1353
|
+
},
|
|
1354
|
+
sha512: void 0
|
|
1355
|
+
};
|
|
1356
|
+
var randomSecretKey = (seed = randomBytes(L)) => seed;
|
|
1357
|
+
var utils = {
|
|
1358
|
+
getExtendedPublicKeyAsync,
|
|
1359
|
+
getExtendedPublicKey,
|
|
1360
|
+
randomSecretKey
|
|
1361
|
+
};
|
|
1362
|
+
var W = 8;
|
|
1363
|
+
var scalarBits = 256;
|
|
1364
|
+
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
1365
|
+
var pwindowSize = 2 ** (W - 1);
|
|
1366
|
+
var precompute = () => {
|
|
1367
|
+
const points = [];
|
|
1368
|
+
let p = G;
|
|
1369
|
+
let b = p;
|
|
1370
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1371
|
+
b = p;
|
|
1372
|
+
points.push(b);
|
|
1373
|
+
for (let i = 1; i < pwindowSize; i++) {
|
|
1374
|
+
b = b.add(p);
|
|
1375
|
+
points.push(b);
|
|
1376
|
+
}
|
|
1377
|
+
p = b.double();
|
|
1378
|
+
}
|
|
1379
|
+
return points;
|
|
1380
|
+
};
|
|
1381
|
+
var Gpows = void 0;
|
|
1382
|
+
var ctneg = (cnd, p) => {
|
|
1383
|
+
const n = p.negate();
|
|
1384
|
+
return cnd ? n : p;
|
|
1385
|
+
};
|
|
1386
|
+
var wNAF = (n) => {
|
|
1387
|
+
const comp = Gpows || (Gpows = precompute());
|
|
1388
|
+
let p = I;
|
|
1389
|
+
let f = G;
|
|
1390
|
+
const pow_2_w = 2 ** W;
|
|
1391
|
+
const maxNum = pow_2_w;
|
|
1392
|
+
const mask = big(pow_2_w - 1);
|
|
1393
|
+
const shiftBy = big(W);
|
|
1394
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1395
|
+
let wbits = Number(n & mask);
|
|
1396
|
+
n >>= shiftBy;
|
|
1397
|
+
if (wbits > pwindowSize) {
|
|
1398
|
+
wbits -= maxNum;
|
|
1399
|
+
n += 1n;
|
|
1400
|
+
}
|
|
1401
|
+
const off = w * pwindowSize;
|
|
1402
|
+
const offF = off;
|
|
1403
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
1404
|
+
const isEven = w % 2 !== 0;
|
|
1405
|
+
const isNeg = wbits < 0;
|
|
1406
|
+
if (wbits === 0) {
|
|
1407
|
+
f = f.add(ctneg(isEven, comp[offF]));
|
|
1408
|
+
} else {
|
|
1409
|
+
p = p.add(ctneg(isNeg, comp[offP]));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (n !== 0n)
|
|
1413
|
+
err("invalid wnaf");
|
|
1414
|
+
return { p, f };
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// src/signature.ts
|
|
1418
|
+
hashes.sha512 = (message) => sha512(message);
|
|
1419
|
+
var ALGORITHM = "Ed25519";
|
|
1420
|
+
var generateKeyPair = async () => {
|
|
1421
|
+
const privateKey = utils.randomSecretKey();
|
|
1422
|
+
const publicKey = await getPublicKey(privateKey);
|
|
1423
|
+
return {
|
|
1424
|
+
publicKey: toUrlSafeBase64(bytesToBase642(publicKey)),
|
|
1425
|
+
privateKey: toUrlSafeBase64(bytesToBase642(privateKey))
|
|
1426
|
+
};
|
|
1427
|
+
};
|
|
1428
|
+
var signStatement = async (statement, privateKeyUrlSafe) => {
|
|
1429
|
+
const privateKeyBytes = base64ToBytes(fromUrlSafeBase64(privateKeyUrlSafe));
|
|
1430
|
+
const messageBytes = new TextEncoder().encode(statement);
|
|
1431
|
+
const signature = await sign(messageBytes, privateKeyBytes);
|
|
1432
|
+
return toUrlSafeBase64(bytesToBase642(signature));
|
|
1433
|
+
};
|
|
1434
|
+
var verifySignature = async (statement, signatureUrlSafe, publicKeyUrlSafe) => {
|
|
1435
|
+
try {
|
|
1436
|
+
const publicKeyBytes = base64ToBytes(fromUrlSafeBase64(publicKeyUrlSafe));
|
|
1437
|
+
const signatureBytes = base64ToBytes(fromUrlSafeBase64(signatureUrlSafe));
|
|
1438
|
+
const messageBytes = new TextEncoder().encode(statement);
|
|
1439
|
+
return await verify2(signatureBytes, messageBytes, publicKeyBytes);
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
return false;
|
|
1442
|
+
}
|
|
1443
|
+
};
|
|
1444
|
+
var buildSignedStatement = async (statement, privateKeyUrlSafe, publicKeyUrlSafe) => {
|
|
1445
|
+
const statementHash = sha2562(statement);
|
|
1446
|
+
const signature = await signStatement(statement, privateKeyUrlSafe);
|
|
1447
|
+
return statement + `---
|
|
1448
|
+
Statement hash: ${statementHash}
|
|
1449
|
+
Public key: ${publicKeyUrlSafe}
|
|
1450
|
+
Signature: ${signature}
|
|
1451
|
+
Algorithm: ${ALGORITHM}
|
|
1452
|
+
`;
|
|
1453
|
+
};
|
|
1454
|
+
var parseSignedStatement = (signedStatement) => {
|
|
1455
|
+
const regex = /^([\s\S]+?)---\nStatement hash: ([A-Za-z0-9_-]+)\nPublic key: ([A-Za-z0-9_-]+)\nSignature: ([A-Za-z0-9_-]+)\nAlgorithm: ([^\n]+)\n$/;
|
|
1456
|
+
const match = signedStatement.match(regex);
|
|
1457
|
+
if (!match) return null;
|
|
1458
|
+
const statement = match[1];
|
|
1459
|
+
const statementHash = match[2];
|
|
1460
|
+
const publicKey = match[3];
|
|
1461
|
+
const signature = match[4];
|
|
1462
|
+
const algorithm = match[5];
|
|
1463
|
+
const computedHash = sha2562(statement);
|
|
1464
|
+
if (computedHash !== statementHash) {
|
|
1465
|
+
return null;
|
|
1466
|
+
}
|
|
1467
|
+
if (algorithm !== ALGORITHM) {
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
statement,
|
|
1472
|
+
publicKey,
|
|
1473
|
+
signature,
|
|
1474
|
+
statementHash,
|
|
1475
|
+
algorithm
|
|
1476
|
+
};
|
|
1477
|
+
};
|
|
1478
|
+
var verifySignedStatement = async (signedStatement) => {
|
|
1479
|
+
const parsed = parseSignedStatement(signedStatement);
|
|
1480
|
+
if (!parsed) return false;
|
|
1481
|
+
return await verifySignature(parsed.statement, parsed.signature, parsed.publicKey);
|
|
1482
|
+
};
|
|
1483
|
+
function bytesToBase642(bytes) {
|
|
1484
|
+
if (typeof btoa !== "undefined") {
|
|
1485
|
+
return btoa(String.fromCharCode(...Array.from(bytes)));
|
|
1486
|
+
} else {
|
|
1487
|
+
return Buffer.from(bytes).toString("base64");
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// src/types.ts
|
|
1492
|
+
function isLegalForm(value) {
|
|
1493
|
+
return [
|
|
1494
|
+
"local government",
|
|
1495
|
+
"state government",
|
|
1496
|
+
"foreign affairs ministry",
|
|
1497
|
+
"corporation"
|
|
1498
|
+
].includes(value);
|
|
1499
|
+
}
|
|
1500
|
+
function isPeopleCountBucket(value) {
|
|
1501
|
+
return [
|
|
1502
|
+
"0-10",
|
|
1503
|
+
"10-100",
|
|
1504
|
+
"100-1000",
|
|
1505
|
+
"1000-10,000",
|
|
1506
|
+
"10,000-100,000",
|
|
1507
|
+
"100,000+",
|
|
1508
|
+
"1,000,000+",
|
|
1509
|
+
"10,000,000+"
|
|
1510
|
+
].includes(value);
|
|
1511
|
+
}
|
|
1512
|
+
function isRatingValue(value) {
|
|
1513
|
+
return [1, 2, 3, 4, 5].includes(value);
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// src/protocol.ts
|
|
1517
|
+
var version = 5;
|
|
1518
|
+
var buildStatement = ({
|
|
1519
|
+
domain,
|
|
1520
|
+
author,
|
|
1521
|
+
time,
|
|
1522
|
+
tags,
|
|
1523
|
+
content,
|
|
1524
|
+
representative,
|
|
1525
|
+
supersededStatement,
|
|
1526
|
+
translations,
|
|
1527
|
+
attachments
|
|
1528
|
+
}) => {
|
|
1529
|
+
if (content.match(/\nPublishing domain: /))
|
|
1530
|
+
throw new Error(
|
|
1531
|
+
"Statement must not contain 'Publishing domain: ', as this marks the beginning of a new statement."
|
|
1532
|
+
);
|
|
1533
|
+
if (content.match(/\n\n/))
|
|
1534
|
+
throw new Error(
|
|
1535
|
+
"Statement content must not contain two line breaks in a row, as this is used for separating statements."
|
|
1536
|
+
);
|
|
1537
|
+
if (content.match(/\nTranslation [a-z]{2,3}:\n/))
|
|
1538
|
+
throw new Error(
|
|
1539
|
+
"Statement content must not contain 'Translation XX:\\n' pattern, as this is reserved for translations."
|
|
1540
|
+
);
|
|
1541
|
+
if (content.match(/\nAttachments: /))
|
|
1542
|
+
throw new Error(
|
|
1543
|
+
"Statement content must not contain 'Attachments: ' on a new line, as this is reserved for file attachments."
|
|
1544
|
+
);
|
|
1545
|
+
if (typeof time !== "object" || !time.toUTCString) throw new Error("Time must be a Date object.");
|
|
1546
|
+
if (!domain) throw new Error("Publishing domain missing.");
|
|
1547
|
+
if (attachments && attachments.length > 5) throw new Error("Maximum 5 attachments allowed.");
|
|
1548
|
+
if (attachments) {
|
|
1549
|
+
attachments.forEach((attachment, index) => {
|
|
1550
|
+
if (!attachment.match(/^[A-Za-z0-9_-]+\.[a-zA-Z0-9]+$/)) {
|
|
1551
|
+
throw new Error(
|
|
1552
|
+
`Attachment ${index + 1} must be in format 'base64hash.extension' (URL-safe base64)`
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
if (translations) {
|
|
1558
|
+
for (const [lang, translation] of Object.entries(translations)) {
|
|
1559
|
+
if (translation.match(/\nPublishing domain: /))
|
|
1560
|
+
throw new Error(`Translation for ${lang} must not contain 'Publishing domain: '.`);
|
|
1561
|
+
if (translation.match(/Translation [a-z]{2,3}:\n/))
|
|
1562
|
+
throw new Error(`Translation for ${lang} must not contain 'Translation XX:\\n' pattern.`);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
const translationLines = translations ? Object.entries(translations).map(([lang, translation]) => {
|
|
1566
|
+
const translationWithNewline = translation + (translation.match(/\n$/) ? "" : "\n");
|
|
1567
|
+
const indentedTranslation = translationWithNewline.split("\n").map((line) => line ? " " + line : line).join("\n");
|
|
1568
|
+
return `Translation ${lang}:
|
|
1569
|
+
${indentedTranslation}`;
|
|
1570
|
+
}).join("") : "";
|
|
1571
|
+
const attachmentLines = attachments && attachments.length > 0 ? "Attachments: " + attachments.join(", ") + "\n" : "";
|
|
1572
|
+
const contentWithNewline = content + (content.match(/\n$/) ? "" : "\n");
|
|
1573
|
+
const isTypedContent = contentWithNewline.trim().startsWith("Type:");
|
|
1574
|
+
const finalContent = isTypedContent ? contentWithNewline : contentWithNewline.split("\n").map((line) => line ? " " + line : line).join("\n");
|
|
1575
|
+
const statement = "Stated protocol version: " + version + "\nPublishing domain: " + domain + "\nAuthor: " + (author || "") + "\n" + (representative && representative?.length > 0 ? "Authorized signing representative: " + (representative || "") + "\n" : "") + "Time: " + time.toUTCString() + "\n" + (tags && tags.length > 0 ? "Tags: " + tags.join(", ") + "\n" : "") + (supersededStatement && supersededStatement?.length > 0 ? "Superseded statement: " + (supersededStatement || "") + "\n" : "") + "Statement content:\n" + finalContent + translationLines + attachmentLines;
|
|
1576
|
+
if (statement.length > 3e3)
|
|
1577
|
+
throw new Error("Statement must not be longer than 3,000 characters.");
|
|
1578
|
+
return statement;
|
|
1579
|
+
};
|
|
1580
|
+
var parseStatement = ({
|
|
1581
|
+
statement: input
|
|
1582
|
+
}) => {
|
|
1583
|
+
if (input.length > 3e3) throw new Error("Statement must not be longer than 3,000 characters.");
|
|
1584
|
+
const beforeTranslations = input.split(/\nTranslation [a-z]{2,3}:\n/)[0];
|
|
1585
|
+
if (beforeTranslations.match(/\n\n/))
|
|
1586
|
+
throw new Error(
|
|
1587
|
+
"Statements cannot contain two line breaks in a row before translations, as this is used for separating statements."
|
|
1588
|
+
);
|
|
1589
|
+
const signatureRegex = new RegExp(
|
|
1590
|
+
"" + /^(?<statement>[\s\S]+?)---\n/.source + /Statement hash: (?<statementHash>[A-Za-z0-9_-]+)\n/.source + /Public key: (?<publicKey>[A-Za-z0-9_-]+)\n/.source + /Signature: (?<signature>[A-Za-z0-9_-]+)\n/.source + /Algorithm: (?<algorithm>[^\n]+)\n/.source + /$/.source
|
|
1591
|
+
);
|
|
1592
|
+
const signatureMatch = input.match(signatureRegex);
|
|
1593
|
+
let statementToVerify = input;
|
|
1594
|
+
let publicKey;
|
|
1595
|
+
let signature;
|
|
1596
|
+
if (signatureMatch && signatureMatch.groups) {
|
|
1597
|
+
statementToVerify = signatureMatch.groups.statement;
|
|
1598
|
+
const statementHash = signatureMatch.groups.statementHash;
|
|
1599
|
+
publicKey = signatureMatch.groups.publicKey;
|
|
1600
|
+
signature = signatureMatch.groups.signature;
|
|
1601
|
+
const algorithm = signatureMatch.groups.algorithm;
|
|
1602
|
+
if (algorithm !== "Ed25519") {
|
|
1603
|
+
throw new Error("Unsupported signature algorithm: " + algorithm);
|
|
1604
|
+
}
|
|
1605
|
+
const computedHash = sha2562(statementToVerify);
|
|
1606
|
+
if (computedHash !== statementHash) {
|
|
1607
|
+
throw new Error("Statement hash mismatch");
|
|
1608
|
+
}
|
|
1609
|
+
const isValid = verifySignature(statementToVerify, signature, publicKey);
|
|
1610
|
+
if (!isValid) {
|
|
1611
|
+
throw new Error("Invalid cryptographic signature");
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
const statementRegex = new RegExp(
|
|
1615
|
+
"" + /^Stated protocol version: (?<formatVersion>[^\n]+?)\n/.source + /Publishing domain: (?<domain>[^\n]+?)\n/.source + /Author: (?<author>[^\n]+?)\n/.source + /(?:Authorized signing representative: (?<representative>[^\n]*?)\n)?/.source + /Time: (?<time>[^\n]+?)\n/.source + /(?:Tags: (?<tags>[^\n]*?)\n)?/.source + /(?:Superseded statement: (?<supersededStatement>[^\n]*?)\n)?/.source + /Statement content:\n/.source + /(?:(?<typedContent> Type: (?<type>[^\n]+?)\n[\s\S]+?)(?=\nTranslation [a-z]{2,3}:\n|Attachments: |$)|(?<content>(?: [\s\S]+?)?))/.source + /(?=\nTranslation [a-z]{2,3}:\n|Attachments: |$)/.source + /(?<translations>(?:\nTranslation [a-z]{2,3}:\n[\s\S]+?)*)/.source + /(?:Attachments: (?<attachments>[^\n]+?)\n)?/.source + /$/.source
|
|
1616
|
+
);
|
|
1617
|
+
const match = statementToVerify.match(statementRegex);
|
|
1618
|
+
if (!match || !match.groups) throw new Error("Invalid statement format: " + input);
|
|
1619
|
+
const {
|
|
1620
|
+
domain,
|
|
1621
|
+
author,
|
|
1622
|
+
representative,
|
|
1623
|
+
time: timeStr,
|
|
1624
|
+
tags: tagsStr,
|
|
1625
|
+
supersededStatement,
|
|
1626
|
+
attachments: attachmentsStr,
|
|
1627
|
+
formatVersion,
|
|
1628
|
+
content,
|
|
1629
|
+
typedContent,
|
|
1630
|
+
type,
|
|
1631
|
+
translations: translationsStr
|
|
1632
|
+
} = match.groups;
|
|
1633
|
+
const parsed = {
|
|
1634
|
+
domain,
|
|
1635
|
+
author,
|
|
1636
|
+
representative,
|
|
1637
|
+
timeStr,
|
|
1638
|
+
tagsStr,
|
|
1639
|
+
supersededStatement,
|
|
1640
|
+
formatVersion,
|
|
1641
|
+
content: content ? content.split("\n").map((line) => line.startsWith(" ") ? line.substring(4) : line).join("\n").replace(/\n$/, "") : typedContent,
|
|
1642
|
+
type: type ? type.toLowerCase().replace(" ", "_") : void 0,
|
|
1643
|
+
translationsStr
|
|
1644
|
+
};
|
|
1645
|
+
if (!parsed.timeStr.match(UTCFormat))
|
|
1646
|
+
throw new Error("Invalid statement format: time must be in UTC");
|
|
1647
|
+
if (!parsed.domain) throw new Error("Invalid statement format: domain is required");
|
|
1648
|
+
if (!parsed.author) throw new Error("Invalid statement format: author is required");
|
|
1649
|
+
if (!parsed.content) throw new Error("Invalid statement format: statement content is required");
|
|
1650
|
+
if (!parsed.formatVersion)
|
|
1651
|
+
throw new Error("Invalid statement format: format version is required");
|
|
1652
|
+
if (parsed.formatVersion !== "5")
|
|
1653
|
+
throw new Error(
|
|
1654
|
+
`Invalid statement format: only version 5 is supported, got version ${parsed.formatVersion}`
|
|
1655
|
+
);
|
|
1656
|
+
const tags = parsed.tagsStr?.split(", ");
|
|
1657
|
+
const time = new Date(parsed.timeStr);
|
|
1658
|
+
let attachments = void 0;
|
|
1659
|
+
if (attachmentsStr && attachmentsStr.length > 0) {
|
|
1660
|
+
attachments = attachmentsStr.split(", ").map((a) => a.trim());
|
|
1661
|
+
if (attachments.length > 5) {
|
|
1662
|
+
throw new Error("Maximum 5 attachments allowed");
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
let translations = void 0;
|
|
1666
|
+
if (parsed.translationsStr && parsed.translationsStr.length > 0) {
|
|
1667
|
+
translations = {};
|
|
1668
|
+
const translationParts = parsed.translationsStr.split(/\nTranslation ([a-z]{2,3}):\n/).filter((part) => part.length > 0);
|
|
1669
|
+
for (let i = 0; i < translationParts.length; i += 2) {
|
|
1670
|
+
if (i + 1 < translationParts.length) {
|
|
1671
|
+
const lang = translationParts[i];
|
|
1672
|
+
const rawTranslation = translationParts[i + 1];
|
|
1673
|
+
const translation = rawTranslation.split("\n").map((line) => line.startsWith(" ") ? line.substring(4) : line).join("\n").replace(/\n$/, "");
|
|
1674
|
+
translations[lang] = translation;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return {
|
|
1679
|
+
domain: parsed.domain,
|
|
1680
|
+
author: parsed.author,
|
|
1681
|
+
representative: parsed.representative,
|
|
1682
|
+
time,
|
|
1683
|
+
tags: tags && tags.length > 0 ? tags : void 0,
|
|
1684
|
+
supersededStatement: parsed.supersededStatement,
|
|
1685
|
+
formatVersion: parsed.formatVersion,
|
|
1686
|
+
content: parsed.content,
|
|
1687
|
+
type: parsed.type?.toLowerCase().replace(" ", "_"),
|
|
1688
|
+
translations: translations && Object.keys(translations).length > 0 ? translations : void 0,
|
|
1689
|
+
attachments: attachments && attachments.length > 0 ? attachments : void 0
|
|
1690
|
+
};
|
|
1691
|
+
};
|
|
1692
|
+
var buildPollContent = ({
|
|
1693
|
+
deadline,
|
|
1694
|
+
poll,
|
|
1695
|
+
scopeDescription,
|
|
1696
|
+
options,
|
|
1697
|
+
allowArbitraryVote
|
|
1698
|
+
}) => {
|
|
1699
|
+
if (!poll) throw new Error("Poll must contain a poll question.");
|
|
1700
|
+
if (poll.includes("\n")) throw new Error("Poll question must be single line.");
|
|
1701
|
+
if (scopeDescription && scopeDescription.includes("\n"))
|
|
1702
|
+
throw new Error("Scope description must be single line.");
|
|
1703
|
+
options.forEach((option, index) => {
|
|
1704
|
+
if (option && option.includes("\n"))
|
|
1705
|
+
throw new Error(`Option ${index + 1} must be single line.`);
|
|
1706
|
+
});
|
|
1707
|
+
const content = " Type: Poll\n" + (deadline ? " Voting deadline: " + deadline.toUTCString() + "\n" : "") + " Poll: " + poll + "\n" + (options.length > 0 && options[0] ? " Option 1: " + options[0] + "\n" : "") + (options.length > 1 && options[1] ? " Option 2: " + options[1] + "\n" : "") + (options.length > 2 && options[2] ? " Option 3: " + options[2] + "\n" : "") + (options.length > 3 && options[3] ? " Option 4: " + options[3] + "\n" : "") + (options.length > 4 && options[4] ? " Option 5: " + options[4] + "\n" : "") + (allowArbitraryVote === true || allowArbitraryVote === false ? " Allow free text votes: " + (allowArbitraryVote ? "Yes" : "No") + "\n" : "") + (scopeDescription ? " Who can vote: " + scopeDescription + "\n" : "");
|
|
1708
|
+
return content;
|
|
1709
|
+
};
|
|
1710
|
+
var parsePoll = (content, version2) => {
|
|
1711
|
+
if (version2 !== "5") throw new Error("Invalid version " + version2);
|
|
1712
|
+
const pollRegex = new RegExp(
|
|
1713
|
+
"" + /^ Type: Poll\n/.source + /(?: Voting deadline: (?<deadline>[^\n]+?)\n)?/.source + / Poll: (?<poll>[^\n]+?)\n/.source + /(?: Option 1: (?<option1>[^\n]+?)\n)?/.source + /(?: Option 2: (?<option2>[^\n]+?)\n)?/.source + /(?: Option 3: (?<option3>[^\n]+?)\n)?/.source + /(?: Option 4: (?<option4>[^\n]+?)\n)?/.source + /(?: Option 5: (?<option5>[^\n]+?)\n)?/.source + /(?: Allow free text votes: (?<allowArbitraryVote>Yes|No)\n)?/.source + /(?: Who can vote: (?<scopeDescription>[^\n]+?)\n)?/.source + /$/.source
|
|
1714
|
+
);
|
|
1715
|
+
const match = content.match(pollRegex);
|
|
1716
|
+
if (!match || !match.groups) throw new Error("Invalid poll format: " + content);
|
|
1717
|
+
const {
|
|
1718
|
+
deadline,
|
|
1719
|
+
poll,
|
|
1720
|
+
option1,
|
|
1721
|
+
option2,
|
|
1722
|
+
option3,
|
|
1723
|
+
option4,
|
|
1724
|
+
option5,
|
|
1725
|
+
allowArbitraryVote: allowArbitraryVoteStr,
|
|
1726
|
+
scopeDescription
|
|
1727
|
+
} = match.groups;
|
|
1728
|
+
const options = [option1, option2, option3, option4, option5].filter((o) => o);
|
|
1729
|
+
const allowArbitraryVote = allowArbitraryVoteStr === "Yes" ? true : allowArbitraryVoteStr === "No" ? false : void 0;
|
|
1730
|
+
const deadlineStr = deadline;
|
|
1731
|
+
if (deadlineStr && !deadlineStr.match(UTCFormat))
|
|
1732
|
+
throw new Error("Invalid poll, deadline must be in UTC: " + deadlineStr);
|
|
1733
|
+
return {
|
|
1734
|
+
deadline: deadlineStr ? new Date(deadlineStr) : void 0,
|
|
1735
|
+
poll,
|
|
1736
|
+
options,
|
|
1737
|
+
allowArbitraryVote,
|
|
1738
|
+
scopeDescription
|
|
1739
|
+
};
|
|
1740
|
+
};
|
|
1741
|
+
var buildOrganisationVerificationContent = ({
|
|
1742
|
+
name,
|
|
1743
|
+
englishName,
|
|
1744
|
+
country,
|
|
1745
|
+
city,
|
|
1746
|
+
province,
|
|
1747
|
+
legalForm,
|
|
1748
|
+
department,
|
|
1749
|
+
domain,
|
|
1750
|
+
foreignDomain,
|
|
1751
|
+
serialNumber,
|
|
1752
|
+
confidence,
|
|
1753
|
+
reliabilityPolicy,
|
|
1754
|
+
employeeCount,
|
|
1755
|
+
pictureHash,
|
|
1756
|
+
latitude,
|
|
1757
|
+
longitude,
|
|
1758
|
+
population,
|
|
1759
|
+
publicKey
|
|
1760
|
+
}) => {
|
|
1761
|
+
if (!name || !country || !legalForm || !domain && !foreignDomain)
|
|
1762
|
+
throw new Error("Missing required fields");
|
|
1763
|
+
if (!Object.values(legalForms).includes(legalForm))
|
|
1764
|
+
throw new Error("Invalid legal form " + legalForm);
|
|
1765
|
+
if (employeeCount && !Object.values(peopleCountBuckets).includes(employeeCount))
|
|
1766
|
+
throw new Error("Invalid employee count " + employeeCount);
|
|
1767
|
+
if (population && !Object.values(peopleCountBuckets).includes(population))
|
|
1768
|
+
throw new Error("Invalid population " + population);
|
|
1769
|
+
if (confidence && !("" + confidence)?.match(/^[0-9.]+$/))
|
|
1770
|
+
throw new Error("Invalid confidence " + confidence);
|
|
1771
|
+
if (pictureHash && !pictureHash.match(/^[A-Za-z0-9_-]+\.[a-zA-Z0-9]+$/)) {
|
|
1772
|
+
throw new Error("Logo must be in format 'base64hash.extension' (URL-safe base64)");
|
|
1773
|
+
}
|
|
1774
|
+
if (publicKey && !publicKey.match(/^[A-Za-z0-9_-]+$/)) {
|
|
1775
|
+
throw new Error("Public key must be in URL-safe base64 format (A-Z, a-z, 0-9, _, -)");
|
|
1776
|
+
}
|
|
1777
|
+
return " Type: Organisation verification\n Description: We verified the following information about an organisation.\n Name: " + name + "\n" + (englishName ? " English name: " + englishName + "\n" : "") + " Country: " + country + "\n Legal form: " + legalForm + "\n" + (domain ? " Owner of the domain: " + domain + "\n" : "") + (foreignDomain ? " Foreign domain used for publishing statements: " + foreignDomain + "\n" : "") + (department ? " Department using the domain: " + department + "\n" : "") + (province ? " Province or state: " + province + "\n" : "") + (serialNumber ? " Business register number: " + serialNumber + "\n" : "") + (city ? " City: " + city + "\n" : "") + (latitude ? " Latitude: " + latitude + "\n" : "") + (longitude ? " Longitude: " + longitude + "\n" : "") + (population ? " Population: " + population + "\n" : "") + (pictureHash ? " Logo: " + pictureHash + "\n" : "") + (employeeCount ? " Employee count: " + employeeCount + "\n" : "") + (publicKey ? " Public key: " + publicKey + "\n" : "") + (reliabilityPolicy ? " Reliability policy: " + reliabilityPolicy + "\n" : "") + (confidence ? " Confidence: " + confidence + "\n" : "");
|
|
1778
|
+
};
|
|
1779
|
+
var parseOrganisationVerification = (content) => {
|
|
1780
|
+
const organisationVerificationRegex = new RegExp(
|
|
1781
|
+
"" + /^ Type: Organisation verification\n/.source + / Description: We verified the following information about an organisation.\n/.source + / Name: (?<name>[^\n]+?)\n/.source + /(?: English name: (?<englishName>[^\n]+?)\n)?/.source + / Country: (?<country>[^\n]+?)\n/.source + / Legal (?:form|entity): (?<legalForm>[^\n]+?)\n/.source + /(?: Owner of the domain: (?<domain>[^\n]+?)\n)?/.source + /(?: Foreign domain used for publishing statements: (?<foreignDomain>[^\n]+?)\n)?/.source + /(?: Department using the domain: (?<department>[^\n]+?)\n)?/.source + /(?: Province or state: (?<province>[^\n]+?)\n)?/.source + /(?: Business register number: (?<serialNumber>[^\n]+?)\n)?/.source + /(?: City: (?<city>[^\n]+?)\n)?/.source + /(?: Latitude: (?<latitude>[^\n]+?)\n)?/.source + /(?: Longitude: (?<longitude>[^\n]+?)\n)?/.source + /(?: Population: (?<population>[^\n]+?)\n)?/.source + /(?: Logo: (?<pictureHash>[A-Za-z0-9_-]+\.[a-zA-Z0-9]+)\n)?/.source + /(?: Employee count: (?<employeeCount>[01,+-]+?)\n)?/.source + /(?: Public key: (?<publicKey>[A-Za-z0-9_-]+)\n)?/.source + /(?: Reliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source + /(?: Confidence: (?<confidence>[0-9.]+?))?/.source + /\n?$/.source
|
|
1782
|
+
);
|
|
1783
|
+
const match = content.match(organisationVerificationRegex);
|
|
1784
|
+
if (!match || !match.groups)
|
|
1785
|
+
throw new Error("Invalid organisation verification format: " + content);
|
|
1786
|
+
const {
|
|
1787
|
+
name,
|
|
1788
|
+
englishName,
|
|
1789
|
+
country,
|
|
1790
|
+
legalForm,
|
|
1791
|
+
domain,
|
|
1792
|
+
foreignDomain,
|
|
1793
|
+
department,
|
|
1794
|
+
province,
|
|
1795
|
+
serialNumber,
|
|
1796
|
+
city,
|
|
1797
|
+
latitude,
|
|
1798
|
+
longitude,
|
|
1799
|
+
population,
|
|
1800
|
+
pictureHash,
|
|
1801
|
+
employeeCount,
|
|
1802
|
+
publicKey,
|
|
1803
|
+
reliabilityPolicy,
|
|
1804
|
+
confidence
|
|
1805
|
+
} = match.groups;
|
|
1806
|
+
if (!isLegalForm(legalForm)) {
|
|
1807
|
+
throw new Error("Invalid legal form after validation: " + legalForm);
|
|
1808
|
+
}
|
|
1809
|
+
return {
|
|
1810
|
+
name,
|
|
1811
|
+
englishName,
|
|
1812
|
+
country,
|
|
1813
|
+
legalForm,
|
|
1814
|
+
domain,
|
|
1815
|
+
foreignDomain,
|
|
1816
|
+
department,
|
|
1817
|
+
province,
|
|
1818
|
+
serialNumber,
|
|
1819
|
+
city,
|
|
1820
|
+
latitude: latitude ? parseFloat(latitude) : void 0,
|
|
1821
|
+
longitude: longitude ? parseFloat(longitude) : void 0,
|
|
1822
|
+
population: population && isPeopleCountBucket(population) ? population : void 0,
|
|
1823
|
+
pictureHash,
|
|
1824
|
+
employeeCount: employeeCount && isPeopleCountBucket(employeeCount) ? employeeCount : void 0,
|
|
1825
|
+
publicKey,
|
|
1826
|
+
reliabilityPolicy,
|
|
1827
|
+
confidence: confidence ? parseFloat(confidence) : void 0
|
|
1828
|
+
};
|
|
1829
|
+
};
|
|
1830
|
+
var buildPersonVerificationContent = ({
|
|
1831
|
+
name,
|
|
1832
|
+
countryOfBirth,
|
|
1833
|
+
cityOfBirth,
|
|
1834
|
+
ownDomain,
|
|
1835
|
+
foreignDomain,
|
|
1836
|
+
dateOfBirth,
|
|
1837
|
+
jobTitle,
|
|
1838
|
+
employer,
|
|
1839
|
+
verificationMethod,
|
|
1840
|
+
confidence,
|
|
1841
|
+
picture,
|
|
1842
|
+
reliabilityPolicy,
|
|
1843
|
+
publicKey
|
|
1844
|
+
}) => {
|
|
1845
|
+
if (!name || !countryOfBirth || !cityOfBirth || !dateOfBirth || !ownDomain && !foreignDomain) {
|
|
1846
|
+
throw new Error("Missing required fields for person verification");
|
|
1847
|
+
}
|
|
1848
|
+
if (publicKey && !publicKey.match(/^[A-Za-z0-9_-]+$/)) {
|
|
1849
|
+
throw new Error("Public key must be in URL-safe base64 format (A-Z, a-z, 0-9, _, -)");
|
|
1850
|
+
}
|
|
1851
|
+
const [day, month, year] = dateOfBirth.toUTCString().split(" ").filter((_i, j) => [1, 2, 3].includes(j));
|
|
1852
|
+
const content = " Type: Person verification\n Description: We verified the following information about a person.\n Name: " + name + "\n Date of birth: " + [day.replace(/^0/, ""), month, year].join(" ") + "\n City of birth: " + cityOfBirth + "\n Country of birth: " + countryOfBirth + "\n" + (jobTitle ? " Job title: " + jobTitle + "\n" : "") + (employer ? " Employer: " + employer + "\n" : "") + (ownDomain ? " Owner of the domain: " + ownDomain + "\n" : "") + (foreignDomain ? " Foreign domain used for publishing statements: " + foreignDomain + "\n" : "") + (picture ? " Picture: " + picture + "\n" : "") + (verificationMethod ? " Verification method: " + verificationMethod + "\n" : "") + (publicKey ? " Public key: " + publicKey + "\n" : "") + (confidence ? " Confidence: " + confidence + "\n" : "") + (reliabilityPolicy ? " Reliability policy: " + reliabilityPolicy + "\n" : "");
|
|
1853
|
+
return content;
|
|
1854
|
+
};
|
|
1855
|
+
var parsePersonVerification = (content) => {
|
|
1856
|
+
const domainVerificationRegex = new RegExp(
|
|
1857
|
+
"" + /^ Type: Person verification\n/.source + / Description: We verified the following information about a person.\n/.source + / Name: (?<name>[^\n]+?)\n/.source + / Date of birth: (?<dateOfBirth>[^\n]+?)\n/.source + / City of birth: (?<cityOfBirth>[^\n]+?)\n/.source + / Country of birth: (?<countryOfBirth>[^\n]+?)\n/.source + /(?: Job title: (?<jobTitle>[^\n]+?)\n)?/.source + /(?: Employer: (?<employer>[^\n]+?)\n)?/.source + /(?: Owner of the domain: (?<domain>[^\n]+?)\n)?/.source + /(?: Foreign domain used for publishing statements: (?<foreignDomain>[^\n]+?)\n)?/.source + /(?: Picture: (?<picture>[^\n]+?)\n)?/.source + /(?: Verification method: (?<verificationMethod>[^\n]+?)\n)?/.source + /(?: Public key: (?<publicKey>[A-Za-z0-9_-]+)\n)?/.source + /(?: Confidence: (?<confidence>[^\n]+?)\n)?/.source + /(?: Reliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source + /$/.source
|
|
1858
|
+
);
|
|
1859
|
+
const match = content.match(domainVerificationRegex);
|
|
1860
|
+
if (!match || !match.groups) throw new Error("Invalid person verification format: " + content);
|
|
1861
|
+
const {
|
|
1862
|
+
name,
|
|
1863
|
+
dateOfBirth: dateOfBirthStr,
|
|
1864
|
+
cityOfBirth,
|
|
1865
|
+
countryOfBirth,
|
|
1866
|
+
jobTitle,
|
|
1867
|
+
employer,
|
|
1868
|
+
domain,
|
|
1869
|
+
foreignDomain,
|
|
1870
|
+
picture,
|
|
1871
|
+
verificationMethod,
|
|
1872
|
+
publicKey,
|
|
1873
|
+
confidence,
|
|
1874
|
+
reliabilityPolicy
|
|
1875
|
+
} = match.groups;
|
|
1876
|
+
if (dateOfBirthStr && !dateOfBirthStr.match(birthDateFormat))
|
|
1877
|
+
throw new Error("Invalid birth date format: " + dateOfBirthStr);
|
|
1878
|
+
const { d, month, y } = dateOfBirthStr.match(birthDateFormat)?.groups || {};
|
|
1879
|
+
if (!d || !month || !y) throw new Error("Invalid birth date format: " + dateOfBirthStr);
|
|
1880
|
+
return {
|
|
1881
|
+
name,
|
|
1882
|
+
dateOfBirth: new Date(Date.UTC(parseInt(y), monthIndex(month), parseInt(d))),
|
|
1883
|
+
cityOfBirth,
|
|
1884
|
+
countryOfBirth,
|
|
1885
|
+
jobTitle,
|
|
1886
|
+
employer,
|
|
1887
|
+
ownDomain: domain,
|
|
1888
|
+
foreignDomain,
|
|
1889
|
+
picture,
|
|
1890
|
+
verificationMethod,
|
|
1891
|
+
publicKey,
|
|
1892
|
+
confidence: confidence ? parseFloat(confidence) : void 0,
|
|
1893
|
+
reliabilityPolicy
|
|
1894
|
+
};
|
|
1895
|
+
};
|
|
1896
|
+
var buildVoteContent = ({ pollHash, poll, vote }) => {
|
|
1897
|
+
const content = " Type: Vote\n Poll id: " + pollHash + "\n Poll:\n " + poll + "\n Option:\n " + vote + "\n";
|
|
1898
|
+
return content;
|
|
1899
|
+
};
|
|
1900
|
+
var parseVote = (content) => {
|
|
1901
|
+
const voteRegex = new RegExp(
|
|
1902
|
+
"" + /^ Type: Vote\n/.source + / Poll id: (?<pollHash>[^\n]+?)\n/.source + / Poll:\n (?<poll>[^\n]+?)\n/.source + / Option:\n (?<vote>[^\n]+?)\n/.source + /$/.source
|
|
1903
|
+
);
|
|
1904
|
+
const match = content.match(voteRegex);
|
|
1905
|
+
if (!match || !match.groups) throw new Error("Invalid vote format: " + content);
|
|
1906
|
+
const { pollHash, poll, vote } = match.groups;
|
|
1907
|
+
return { pollHash, poll, vote };
|
|
1908
|
+
};
|
|
1909
|
+
var buildDisputeAuthenticityContent = ({
|
|
1910
|
+
hash,
|
|
1911
|
+
confidence,
|
|
1912
|
+
reliabilityPolicy
|
|
1913
|
+
}) => {
|
|
1914
|
+
const content = " Type: Dispute statement authenticity\n Description: We think that the referenced statement is not authentic.\n Hash of referenced statement: " + hash + "\n" + (confidence ? " Confidence: " + confidence + "\n" : "") + (reliabilityPolicy ? " Reliability policy: " + reliabilityPolicy + "\n" : "");
|
|
1915
|
+
return content;
|
|
1916
|
+
};
|
|
1917
|
+
var parseDisputeAuthenticity = (content) => {
|
|
1918
|
+
const disputeRegex = new RegExp(
|
|
1919
|
+
"" + /^ Type: Dispute statement authenticity\n/.source + / Description: We think that the referenced statement is not authentic.\n/.source + / Hash of referenced statement: (?<hash>[^\n]+?)\n/.source + /(?: Confidence: (?<confidence>[^\n]*?)\n)?/.source + /(?: Reliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source + /$/.source
|
|
1920
|
+
);
|
|
1921
|
+
const match = content.match(disputeRegex);
|
|
1922
|
+
if (!match || !match.groups) throw new Error("Invalid dispute authenticity format: " + content);
|
|
1923
|
+
const { hash, confidence, reliabilityPolicy } = match.groups;
|
|
1924
|
+
return {
|
|
1925
|
+
hash,
|
|
1926
|
+
confidence: confidence ? parseFloat(confidence) : void 0,
|
|
1927
|
+
reliabilityPolicy
|
|
1928
|
+
};
|
|
1929
|
+
};
|
|
1930
|
+
var buildDisputeContentContent = ({
|
|
1931
|
+
hash,
|
|
1932
|
+
confidence,
|
|
1933
|
+
reliabilityPolicy
|
|
1934
|
+
}) => {
|
|
1935
|
+
const content = " Type: Dispute statement content\n Description: We think that the content of the referenced statement is false.\n Hash of referenced statement: " + hash + "\n" + (confidence ? " Confidence: " + confidence + "\n" : "") + (reliabilityPolicy ? " Reliability policy: " + reliabilityPolicy + "\n" : "");
|
|
1936
|
+
return content;
|
|
1937
|
+
};
|
|
1938
|
+
var parseDisputeContent = (content) => {
|
|
1939
|
+
const disputeRegex = new RegExp(
|
|
1940
|
+
"" + /^ Type: Dispute statement content\n/.source + / Description: We think that the content of the referenced statement is false.\n/.source + / Hash of referenced statement: (?<hash>[^\n]+?)\n/.source + /(?: Confidence: (?<confidence>[^\n]*?)\n)?/.source + /(?: Reliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source + /$/.source
|
|
1941
|
+
);
|
|
1942
|
+
const match = content.match(disputeRegex);
|
|
1943
|
+
if (!match || !match.groups) throw new Error("Invalid dispute content format: " + content);
|
|
1944
|
+
const { hash, confidence, reliabilityPolicy } = match.groups;
|
|
1945
|
+
return {
|
|
1946
|
+
hash,
|
|
1947
|
+
confidence: confidence ? parseFloat(confidence) : void 0,
|
|
1948
|
+
reliabilityPolicy
|
|
1949
|
+
};
|
|
1950
|
+
};
|
|
1951
|
+
var buildResponseContent = ({ hash, response }) => {
|
|
1952
|
+
const content = " Type: Response\n Hash of referenced statement: " + hash + "\n Response:\n " + response + "\n";
|
|
1953
|
+
return content;
|
|
1954
|
+
};
|
|
1955
|
+
var parseResponseContent = (content) => {
|
|
1956
|
+
const responseRegex = new RegExp(
|
|
1957
|
+
"" + /^ Type: Response\n/.source + / Hash of referenced statement: (?<hash>[^\n]+?)\n/.source + / Response:\n (?<response>[^\n]*?)\n/.source + /$/.source
|
|
1958
|
+
);
|
|
1959
|
+
const match = content.match(responseRegex);
|
|
1960
|
+
if (!match || !match.groups) throw new Error("Invalid response content format: " + content);
|
|
1961
|
+
const { hash, response } = match.groups;
|
|
1962
|
+
return { hash, response };
|
|
1963
|
+
};
|
|
1964
|
+
var buildPDFSigningContent = ({ hash }) => {
|
|
1965
|
+
if (!hash.match(/^[A-Za-z0-9_-]+$/)) {
|
|
1966
|
+
throw new Error("PDF file hash must be in URL-safe base64 format (A-Z, a-z, 0-9, _, -)");
|
|
1967
|
+
}
|
|
1968
|
+
const content = " Type: Sign PDF\n Description: We hereby digitally sign the referenced PDF file.\n PDF file hash: " + hash + "\n";
|
|
1969
|
+
return content;
|
|
1970
|
+
};
|
|
1971
|
+
var parsePDFSigning = (content) => {
|
|
1972
|
+
const signingRegex = new RegExp(
|
|
1973
|
+
"" + /^ Type: Sign PDF\n/.source + / Description: We hereby digitally sign the referenced PDF file.\n/.source + / PDF file hash: (?<hash>[A-Za-z0-9_-]+)\n/.source + /$/.source
|
|
1974
|
+
);
|
|
1975
|
+
const match = content.match(signingRegex);
|
|
1976
|
+
if (!match || !match.groups) throw new Error("Invalid PDF signing format: " + content);
|
|
1977
|
+
const { hash } = match.groups;
|
|
1978
|
+
return { hash };
|
|
1979
|
+
};
|
|
1980
|
+
var buildRating = ({
|
|
1981
|
+
subjectName,
|
|
1982
|
+
subjectType,
|
|
1983
|
+
subjectReference,
|
|
1984
|
+
documentFileHash,
|
|
1985
|
+
rating,
|
|
1986
|
+
quality,
|
|
1987
|
+
comment
|
|
1988
|
+
}) => {
|
|
1989
|
+
if (![1, 2, 3, 4, 5].includes(rating)) throw new Error("Invalid rating: " + rating);
|
|
1990
|
+
const content = " Type: Rating\n" + (subjectType ? " Subject type: " + subjectType + "\n" : "") + " Subject name: " + subjectName + "\n" + (subjectReference ? " URL that identifies the subject: " + subjectReference + "\n" : "") + (documentFileHash ? " Document file hash: " + documentFileHash + "\n" : "") + (quality ? " Rated quality: " + quality + "\n" : "") + " Our rating: " + rating + "/5 Stars\n" + (comment ? " Comment:\n " + comment + "\n" : "");
|
|
1991
|
+
return content;
|
|
1992
|
+
};
|
|
1993
|
+
var parseRating = (content) => {
|
|
1994
|
+
const ratingRegex = new RegExp(
|
|
1995
|
+
"" + /^ Type: Rating\n/.source + /(?: Subject type: (?<subjectType>[^\n]*?)\n)?/.source + / Subject name: (?<subjectName>[^\n]*?)\n/.source + /(?: URL that identifies the subject: (?<subjectReference>[^\n]*?)\n)?/.source + /(?: Document file hash: (?<documentFileHash>[^\n]*?)\n)?/.source + /(?: Rated quality: (?<quality>[^\n]*?)\n)?/.source + / Our rating: (?<rating>[1-5])\/5 Stars\n/.source + /(?: Comment:\n (?<comment>[\s\S]+?)\n)?/.source + /$/.source
|
|
1996
|
+
);
|
|
1997
|
+
const match = content.match(ratingRegex);
|
|
1998
|
+
if (!match || !match.groups) throw new Error("Invalid rating format: " + content);
|
|
1999
|
+
const {
|
|
2000
|
+
subjectType,
|
|
2001
|
+
subjectName,
|
|
2002
|
+
subjectReference,
|
|
2003
|
+
documentFileHash,
|
|
2004
|
+
quality,
|
|
2005
|
+
rating: ratingStr,
|
|
2006
|
+
comment
|
|
2007
|
+
} = match.groups;
|
|
2008
|
+
const rating = parseInt(ratingStr);
|
|
2009
|
+
if (![1, 2, 3, 4, 5].includes(rating)) throw new Error("Invalid rating: " + ratingStr);
|
|
2010
|
+
if (subjectType && ![
|
|
2011
|
+
"Organisation",
|
|
2012
|
+
"Policy proposal",
|
|
2013
|
+
"Regulation",
|
|
2014
|
+
"Treaty draft",
|
|
2015
|
+
"Product",
|
|
2016
|
+
"Research publication"
|
|
2017
|
+
].includes(subjectType))
|
|
2018
|
+
throw new Error("Invalid subject type: " + subjectType);
|
|
2019
|
+
if (!subjectName) throw new Error("Missing subject name");
|
|
2020
|
+
if (!isRatingValue(rating)) {
|
|
2021
|
+
throw new Error("Invalid rating after validation: " + rating);
|
|
2022
|
+
}
|
|
2023
|
+
return {
|
|
2024
|
+
subjectType,
|
|
2025
|
+
subjectName,
|
|
2026
|
+
subjectReference,
|
|
2027
|
+
documentFileHash,
|
|
2028
|
+
quality,
|
|
2029
|
+
rating,
|
|
2030
|
+
comment
|
|
2031
|
+
};
|
|
2032
|
+
};
|
|
2033
|
+
export {
|
|
2034
|
+
PDFSigningKeys,
|
|
2035
|
+
UTCFormat,
|
|
2036
|
+
base64ToBytes,
|
|
2037
|
+
birthDateFormat,
|
|
2038
|
+
buildDisputeAuthenticityContent,
|
|
2039
|
+
buildDisputeContentContent,
|
|
2040
|
+
buildOrganisationVerificationContent,
|
|
2041
|
+
buildPDFSigningContent,
|
|
2042
|
+
buildPersonVerificationContent,
|
|
2043
|
+
buildPollContent,
|
|
2044
|
+
buildRating,
|
|
2045
|
+
buildResponseContent,
|
|
2046
|
+
buildSignedStatement,
|
|
2047
|
+
buildStatement,
|
|
2048
|
+
buildVoteContent,
|
|
2049
|
+
disputeAuthenticityKeys,
|
|
2050
|
+
disputeContentKeys,
|
|
2051
|
+
fromUrlSafeBase64,
|
|
2052
|
+
generateAttachmentFilename,
|
|
2053
|
+
generateFileHash,
|
|
2054
|
+
generateKeyPair,
|
|
2055
|
+
generateStatementContentHash,
|
|
2056
|
+
generateStatementFilename,
|
|
2057
|
+
generateStatementHash,
|
|
2058
|
+
generateStatementsFile,
|
|
2059
|
+
isLegalForm,
|
|
2060
|
+
isPeopleCountBucket,
|
|
2061
|
+
isRatingValue,
|
|
2062
|
+
legalForms,
|
|
2063
|
+
minPeopleCountToRange,
|
|
2064
|
+
monthIndex,
|
|
2065
|
+
organisationVerificationKeys,
|
|
2066
|
+
parseDisputeAuthenticity,
|
|
2067
|
+
parseDisputeContent,
|
|
2068
|
+
parseOrganisationVerification,
|
|
2069
|
+
parsePDFSigning,
|
|
2070
|
+
parsePersonVerification,
|
|
2071
|
+
parsePoll,
|
|
2072
|
+
parseRating,
|
|
2073
|
+
parseResponseContent,
|
|
2074
|
+
parseSignedStatement,
|
|
2075
|
+
parseStatement,
|
|
2076
|
+
parseStatementsFile,
|
|
2077
|
+
parseVote,
|
|
2078
|
+
peopleCountBuckets,
|
|
2079
|
+
personVerificationKeys,
|
|
2080
|
+
pollKeys,
|
|
2081
|
+
ratingKeys,
|
|
2082
|
+
responseKeys,
|
|
2083
|
+
sha2562 as sha256,
|
|
2084
|
+
signStatement,
|
|
2085
|
+
statementTypes,
|
|
2086
|
+
supportedLanguages,
|
|
2087
|
+
toUrlSafeBase64,
|
|
2088
|
+
validateFileHash,
|
|
2089
|
+
validateStatementContentHash,
|
|
2090
|
+
validateStatementHash,
|
|
2091
|
+
verify,
|
|
2092
|
+
verifySignature,
|
|
2093
|
+
verifySignedStatement,
|
|
2094
|
+
voteKeys
|
|
2095
|
+
};
|
|
2096
|
+
/*! Bundled license information:
|
|
2097
|
+
|
|
2098
|
+
@noble/hashes/utils.js:
|
|
2099
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2100
|
+
|
|
2101
|
+
@noble/ed25519/index.js:
|
|
2102
|
+
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
2103
|
+
*/
|
|
2104
|
+
//# sourceMappingURL=index.js.map
|