stated-protocol 5.0.0 → 5.1.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 +10 -10
- package/dist/constants.js +14 -17
- package/dist/constants.js.map +1 -1
- package/dist/hash.js +8 -16
- package/dist/hash.js.map +1 -1
- package/dist/index.js +5 -21
- package/dist/index.js.map +1 -1
- package/dist/protocol.js +42 -79
- package/dist/protocol.js.map +1 -1
- package/dist/signature.js +21 -63
- package/dist/signature.js.map +1 -1
- package/dist/types.js +3 -8
- package/dist/types.js.map +1 -1
- package/dist/utils.js +34 -49
- package/dist/utils.js.map +1 -1
- package/package.json +3 -14
- package/dist/esm/constants.d.ts +0 -225
- package/dist/esm/constants.d.ts.map +0 -1
- package/dist/esm/hash.d.ts +0 -37
- package/dist/esm/hash.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -2104
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/protocol.d.ts +0 -30
- package/dist/esm/protocol.d.ts.map +0 -1
- package/dist/esm/signature.d.ts +0 -49
- package/dist/esm/signature.d.ts.map +0 -1
- package/dist/esm/types.d.ts +0 -115
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/utils.d.ts +0 -14
- package/dist/esm/utils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Stated Protocol Parser
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/stated-protocol)
|
|
4
4
|
|
|
5
5
|
A TypeScript library for parsing and formatting statements in the Stated protocol - a decentralized statement verification system.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install stated-protocol
|
|
10
|
+
npm install stated-protocol
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Features
|
|
@@ -32,7 +32,7 @@ npm install stated-protocol-parser
|
|
|
32
32
|
### Basic Statement
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
|
-
import { buildStatement, parseStatement } from 'stated-protocol
|
|
35
|
+
import { buildStatement, parseStatement } from 'stated-protocol';
|
|
36
36
|
|
|
37
37
|
// Build a statement
|
|
38
38
|
const statement = buildStatement({
|
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
buildSignedStatement,
|
|
63
63
|
verifySignedStatement,
|
|
64
64
|
parseSignedStatement
|
|
65
|
-
} from 'stated-protocol
|
|
65
|
+
} from 'stated-protocol/node';
|
|
66
66
|
|
|
67
67
|
// Generate a key pair
|
|
68
68
|
const { publicKey, privateKey } = generateKeyPair();
|
|
@@ -97,7 +97,7 @@ import {
|
|
|
97
97
|
generateKeyPair,
|
|
98
98
|
buildSignedStatement,
|
|
99
99
|
verifySignedStatement
|
|
100
|
-
} from 'stated-protocol
|
|
100
|
+
} from 'stated-protocol';
|
|
101
101
|
|
|
102
102
|
// Generate a key pair (async in browser)
|
|
103
103
|
const { publicKey, privateKey } = await generateKeyPair();
|
|
@@ -137,7 +137,7 @@ Algorithm: Ed25519
|
|
|
137
137
|
### Poll
|
|
138
138
|
|
|
139
139
|
```typescript
|
|
140
|
-
import { buildPollContent, parsePoll } from 'stated-protocol
|
|
140
|
+
import { buildPollContent, parsePoll } from 'stated-protocol';
|
|
141
141
|
|
|
142
142
|
const pollContent = buildPollContent({
|
|
143
143
|
poll: 'Should we implement feature X?',
|
|
@@ -152,7 +152,7 @@ const parsed = parsePoll(pollContent);
|
|
|
152
152
|
### Organisation Verification
|
|
153
153
|
|
|
154
154
|
```typescript
|
|
155
|
-
import { buildOrganisationVerificationContent, parseOrganisationVerification } from 'stated-protocol
|
|
155
|
+
import { buildOrganisationVerificationContent, parseOrganisationVerification } from 'stated-protocol';
|
|
156
156
|
|
|
157
157
|
const verification = buildOrganisationVerificationContent({
|
|
158
158
|
name: 'Example Corp',
|
|
@@ -167,7 +167,7 @@ const verification = buildOrganisationVerificationContent({
|
|
|
167
167
|
### Person Verification
|
|
168
168
|
|
|
169
169
|
```typescript
|
|
170
|
-
import { buildPersonVerificationContent, parsePersonVerification } from 'stated-protocol
|
|
170
|
+
import { buildPersonVerificationContent, parsePersonVerification } from 'stated-protocol';
|
|
171
171
|
|
|
172
172
|
const verification = buildPersonVerificationContent({
|
|
173
173
|
name: 'John Doe',
|
|
@@ -208,7 +208,7 @@ import {
|
|
|
208
208
|
legalForms,
|
|
209
209
|
peopleCountBuckets,
|
|
210
210
|
UTCFormat
|
|
211
|
-
} from 'stated-protocol
|
|
211
|
+
} from 'stated-protocol';
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
### Types
|
|
@@ -227,7 +227,7 @@ import type {
|
|
|
227
227
|
ResponseContent,
|
|
228
228
|
PDFSigning,
|
|
229
229
|
Rating
|
|
230
|
-
} from 'stated-protocol
|
|
230
|
+
} from 'stated-protocol';
|
|
231
231
|
```
|
|
232
232
|
|
|
233
233
|
## Format Specifications
|
package/dist/constants.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ratingKeys = exports.PDFSigningKeys = exports.responseKeys = exports.disputeContentKeys = exports.disputeAuthenticityKeys = exports.voteKeys = exports.personVerificationKeys = exports.organisationVerificationKeys = exports.pollKeys = exports.UTCFormat = exports.supportedLanguages = exports.peopleCountBuckets = exports.statementTypes = exports.legalForms = void 0;
|
|
4
|
-
exports.legalForms = {
|
|
1
|
+
export const legalForms = {
|
|
5
2
|
local_government: 'local government',
|
|
6
3
|
state_government: 'state government',
|
|
7
4
|
foreign_affairs_ministry: 'foreign affairs ministry',
|
|
8
5
|
corporation: 'corporation',
|
|
9
6
|
};
|
|
10
|
-
|
|
7
|
+
export const statementTypes = {
|
|
11
8
|
statement: 'statement',
|
|
12
9
|
organisationVerification: 'organisation_verification',
|
|
13
10
|
personVerification: 'person_verification',
|
|
@@ -20,7 +17,7 @@ exports.statementTypes = {
|
|
|
20
17
|
signPdf: 'sign_pdf',
|
|
21
18
|
unsupported: 'unsupported',
|
|
22
19
|
};
|
|
23
|
-
|
|
20
|
+
export const peopleCountBuckets = {
|
|
24
21
|
'0': '0-10',
|
|
25
22
|
'10': '10-100',
|
|
26
23
|
'100': '100-1000',
|
|
@@ -30,7 +27,7 @@ exports.peopleCountBuckets = {
|
|
|
30
27
|
'1000000': '1,000,000+',
|
|
31
28
|
'10000000': '10,000,000+',
|
|
32
29
|
};
|
|
33
|
-
|
|
30
|
+
export const supportedLanguages = {
|
|
34
31
|
aa: 'aa',
|
|
35
32
|
ab: 'ab',
|
|
36
33
|
af: 'af',
|
|
@@ -214,14 +211,14 @@ exports.supportedLanguages = {
|
|
|
214
211
|
zh: 'zh',
|
|
215
212
|
zu: 'zu',
|
|
216
213
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
214
|
+
export const 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/;
|
|
215
|
+
export const 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;
|
|
216
|
+
export const 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;
|
|
217
|
+
export const 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;
|
|
218
|
+
export const voteKeys = /(Type: |Poll id: |Poll: |Option: )/g;
|
|
219
|
+
export const disputeAuthenticityKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
|
|
220
|
+
export const disputeContentKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
|
|
221
|
+
export const responseKeys = /(Type: |Hash of referenced statement: |Response: )/;
|
|
222
|
+
export const PDFSigningKeys = /(Type: |Description: |PDF file hash: )/g;
|
|
223
|
+
export const ratingKeys = /(Type: |Subject type: |Subject name: |URL that identifies the subject: |Document file hash: |Rated quality: |Our rating: |Comment: )/;
|
|
227
224
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,wBAAwB,EAAE,0BAA0B;IACpD,WAAW,EAAE,aAAa;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,wBAAwB,EAAE,2BAA2B;IACrD,kBAAkB,EAAE,qBAAqB;IACzC,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,cAAc,EAAE,2BAA2B;IAC3C,mBAAmB,EAAE,gCAAgC;IACrD,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,UAAU;IACnB,WAAW,EAAE,aAAa;CAC3B,CAAC;AAEF,MAAM,CAA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M,CAAC,MAAM,UAAU,GACrB,sIAAsI,CAAC"}
|
package/dist/hash.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Universal hash utilities using @noble/hashes
|
|
4
3
|
* Works in both browser and Node.js environments
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
exports.toUrlSafeBase64 = exports.fromUrlSafeBase64 = exports.verify = exports.sha256 = void 0;
|
|
8
|
-
exports.base64ToBytes = base64ToBytes;
|
|
9
|
-
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
5
|
+
import { sha256 as nobleSha256 } from '@noble/hashes/sha2.js';
|
|
10
6
|
/**
|
|
11
7
|
* Compute SHA-256 hash of a string and return it as URL-safe base64
|
|
12
8
|
* Works in both browser and Node.js environments
|
|
13
9
|
* @param input - The string or buffer to hash
|
|
14
10
|
* @returns URL-safe base64 encoded hash
|
|
15
11
|
*/
|
|
16
|
-
const sha256 = (input) => {
|
|
12
|
+
export const sha256 = (input) => {
|
|
17
13
|
let data;
|
|
18
14
|
if (typeof input === 'string') {
|
|
19
15
|
const encoder = new TextEncoder();
|
|
@@ -23,46 +19,42 @@ const sha256 = (input) => {
|
|
|
23
19
|
data = input;
|
|
24
20
|
}
|
|
25
21
|
// Use @noble/hashes for consistent cross-platform hashing
|
|
26
|
-
const hashArray = (
|
|
22
|
+
const hashArray = nobleSha256(data);
|
|
27
23
|
// Convert to base64
|
|
28
24
|
const base64 = bytesToBase64(hashArray);
|
|
29
25
|
// Make URL-safe: remove padding and replace + with - and / with _
|
|
30
26
|
const urlSafe = base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
31
27
|
return urlSafe;
|
|
32
28
|
};
|
|
33
|
-
exports.sha256 = sha256;
|
|
34
29
|
/**
|
|
35
30
|
* Verify that content matches a given hash
|
|
36
31
|
* @param content - The content to verify
|
|
37
32
|
* @param hash - The expected hash
|
|
38
33
|
* @returns True if the hash matches
|
|
39
34
|
*/
|
|
40
|
-
const verify = (content, hash) => {
|
|
41
|
-
const computed =
|
|
35
|
+
export const verify = (content, hash) => {
|
|
36
|
+
const computed = sha256(content);
|
|
42
37
|
return computed === hash;
|
|
43
38
|
};
|
|
44
|
-
exports.verify = verify;
|
|
45
39
|
/**
|
|
46
40
|
* Convert URL-safe base64 back to standard base64
|
|
47
41
|
* @param urlSafe - URL-safe base64 string
|
|
48
42
|
* @returns Standard base64 string with padding
|
|
49
43
|
*/
|
|
50
|
-
const fromUrlSafeBase64 = (urlSafe) => {
|
|
44
|
+
export const fromUrlSafeBase64 = (urlSafe) => {
|
|
51
45
|
const base64 = urlSafe.replace(/-/g, '+').replace(/_/g, '/');
|
|
52
46
|
// Add padding if needed
|
|
53
47
|
const padding = '='.repeat((4 - (base64.length % 4)) % 4);
|
|
54
48
|
return base64 + padding;
|
|
55
49
|
};
|
|
56
|
-
exports.fromUrlSafeBase64 = fromUrlSafeBase64;
|
|
57
50
|
/**
|
|
58
51
|
* Convert standard base64 to URL-safe base64
|
|
59
52
|
* @param base64 - Standard base64 string
|
|
60
53
|
* @returns URL-safe base64 string without padding
|
|
61
54
|
*/
|
|
62
|
-
const toUrlSafeBase64 = (base64) => {
|
|
55
|
+
export const toUrlSafeBase64 = (base64) => {
|
|
63
56
|
return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
64
57
|
};
|
|
65
|
-
exports.toUrlSafeBase64 = toUrlSafeBase64;
|
|
66
58
|
/**
|
|
67
59
|
* Convert bytes to base64 string
|
|
68
60
|
* @param bytes - Uint8Array to convert
|
|
@@ -82,7 +74,7 @@ function bytesToBase64(bytes) {
|
|
|
82
74
|
* @param base64 - Base64 string to convert
|
|
83
75
|
* @returns Uint8Array
|
|
84
76
|
*/
|
|
85
|
-
function base64ToBytes(base64) {
|
|
77
|
+
export function base64ToBytes(base64) {
|
|
86
78
|
// Use atob if available (browser), otherwise use Buffer (Node.js)
|
|
87
79
|
if (typeof atob !== 'undefined') {
|
|
88
80
|
const binaryString = atob(base64);
|
package/dist/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAA0B,EAAU,EAAE;IAC3D,IAAI,IAAgB,CAAC;IAErB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,KAAK,CAAC;IACf,CAAC;IAED,0DAA0D;IAC1D,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAEpC,oBAAoB;IACpB,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAExC,kEAAkE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEjF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAA4B,EAAE,IAAY,EAAW,EAAE;IAC5E,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,QAAQ,KAAK,IAAI,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAA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AC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./protocol"), exports);
|
|
18
|
-
__exportStar(require("./hash"), exports);
|
|
19
|
-
__exportStar(require("./signature"), exports);
|
|
20
|
-
__exportStar(require("./constants"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './protocol';
|
|
2
|
+
export * from './hash';
|
|
3
|
+
export * from './signature';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './types';
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
package/dist/protocol.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.parseRating = exports.buildRating = exports.parsePDFSigning = exports.buildPDFSigningContent = exports.parseResponseContent = exports.buildResponseContent = exports.parseDisputeContent = exports.buildDisputeContentContent = exports.parseDisputeAuthenticity = exports.buildDisputeAuthenticityContent = exports.parseVote = exports.buildVoteContent = exports.parsePersonVerification = exports.buildPersonVerificationContent = exports.parseOrganisationVerification = exports.buildOrganisationVerificationContent = exports.parsePoll = exports.buildPollContent = exports.parseStatement = exports.buildStatement = void 0;
|
|
18
|
-
const constants_1 = require("./constants");
|
|
19
|
-
const utils_1 = require("./utils");
|
|
20
|
-
const signature_1 = require("./signature");
|
|
21
|
-
const hash_1 = require("./hash");
|
|
22
|
-
const types_1 = require("./types");
|
|
1
|
+
import { legalForms, UTCFormat, peopleCountBuckets } from './constants';
|
|
2
|
+
import { monthIndex, birthDateFormat } from './utils';
|
|
3
|
+
import { verifySignature } from './signature';
|
|
4
|
+
import { sha256 } from './hash';
|
|
5
|
+
import { isLegalForm, isPeopleCountBucket, isRatingValue } from './types';
|
|
23
6
|
const version = 5;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const buildStatement = ({ domain, author, time, tags, content, representative, supersededStatement, translations, attachments, }) => {
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './constants';
|
|
9
|
+
export * from './utils';
|
|
10
|
+
export const buildStatement = ({ domain, author, time, tags, content, representative, supersededStatement, translations, attachments, }) => {
|
|
28
11
|
if (content.match(/\nPublishing domain: /))
|
|
29
12
|
throw new Error("Statement must not contain 'Publishing domain: ', as this marks the beginning of a new statement.");
|
|
30
13
|
if (content.match(/\n\n/))
|
|
@@ -103,8 +86,7 @@ const buildStatement = ({ domain, author, time, tags, content, representative, s
|
|
|
103
86
|
throw new Error('Statement must not be longer than 3,000 characters.');
|
|
104
87
|
return statement;
|
|
105
88
|
};
|
|
106
|
-
|
|
107
|
-
const parseStatement = ({ statement: input, }) => {
|
|
89
|
+
export const parseStatement = ({ statement: input, }) => {
|
|
108
90
|
if (input.length > 3000)
|
|
109
91
|
throw new Error('Statement must not be longer than 3,000 characters.');
|
|
110
92
|
const beforeTranslations = input.split(/\nTranslation [a-z]{2,3}:\n/)[0];
|
|
@@ -130,11 +112,11 @@ const parseStatement = ({ statement: input, }) => {
|
|
|
130
112
|
if (algorithm !== 'Ed25519') {
|
|
131
113
|
throw new Error('Unsupported signature algorithm: ' + algorithm);
|
|
132
114
|
}
|
|
133
|
-
const computedHash =
|
|
115
|
+
const computedHash = sha256(statementToVerify);
|
|
134
116
|
if (computedHash !== statementHash) {
|
|
135
117
|
throw new Error('Statement hash mismatch');
|
|
136
118
|
}
|
|
137
|
-
const isValid =
|
|
119
|
+
const isValid = verifySignature(statementToVerify, signature, publicKey);
|
|
138
120
|
if (!isValid) {
|
|
139
121
|
throw new Error('Invalid cryptographic signature');
|
|
140
122
|
}
|
|
@@ -176,7 +158,7 @@ const parseStatement = ({ statement: input, }) => {
|
|
|
176
158
|
type: type ? type.toLowerCase().replace(' ', '_') : undefined,
|
|
177
159
|
translationsStr,
|
|
178
160
|
};
|
|
179
|
-
if (!parsed.timeStr.match(
|
|
161
|
+
if (!parsed.timeStr.match(UTCFormat))
|
|
180
162
|
throw new Error('Invalid statement format: time must be in UTC');
|
|
181
163
|
if (!parsed.domain)
|
|
182
164
|
throw new Error('Invalid statement format: domain is required');
|
|
@@ -231,8 +213,7 @@ const parseStatement = ({ statement: input, }) => {
|
|
|
231
213
|
attachments: attachments && attachments.length > 0 ? attachments : undefined,
|
|
232
214
|
};
|
|
233
215
|
};
|
|
234
|
-
|
|
235
|
-
const buildPollContent = ({ deadline, poll, scopeDescription, options, allowArbitraryVote, }) => {
|
|
216
|
+
export const buildPollContent = ({ deadline, poll, scopeDescription, options, allowArbitraryVote, }) => {
|
|
236
217
|
if (!poll)
|
|
237
218
|
throw new Error('Poll must contain a poll question.');
|
|
238
219
|
if (poll.includes('\n'))
|
|
@@ -259,8 +240,7 @@ const buildPollContent = ({ deadline, poll, scopeDescription, options, allowArbi
|
|
|
259
240
|
(scopeDescription ? ' Who can vote: ' + scopeDescription + '\n' : '');
|
|
260
241
|
return content;
|
|
261
242
|
};
|
|
262
|
-
|
|
263
|
-
const parsePoll = (content, version) => {
|
|
243
|
+
export const parsePoll = (content, version) => {
|
|
264
244
|
if (version !== '5')
|
|
265
245
|
throw new Error('Invalid version ' + version);
|
|
266
246
|
const pollRegex = new RegExp('' +
|
|
@@ -282,7 +262,7 @@ const parsePoll = (content, version) => {
|
|
|
282
262
|
const options = [option1, option2, option3, option4, option5].filter((o) => o);
|
|
283
263
|
const allowArbitraryVote = allowArbitraryVoteStr === 'Yes' ? true : allowArbitraryVoteStr === 'No' ? false : undefined;
|
|
284
264
|
const deadlineStr = deadline;
|
|
285
|
-
if (deadlineStr && !deadlineStr.match(
|
|
265
|
+
if (deadlineStr && !deadlineStr.match(UTCFormat))
|
|
286
266
|
throw new Error('Invalid poll, deadline must be in UTC: ' + deadlineStr);
|
|
287
267
|
return {
|
|
288
268
|
deadline: deadlineStr ? new Date(deadlineStr) : undefined,
|
|
@@ -292,15 +272,14 @@ const parsePoll = (content, version) => {
|
|
|
292
272
|
scopeDescription,
|
|
293
273
|
};
|
|
294
274
|
};
|
|
295
|
-
|
|
296
|
-
const buildOrganisationVerificationContent = ({ name, englishName, country, city, province, legalForm, department, domain, foreignDomain, serialNumber, confidence, reliabilityPolicy, employeeCount, pictureHash, latitude, longitude, population, publicKey, }) => {
|
|
275
|
+
export const buildOrganisationVerificationContent = ({ name, englishName, country, city, province, legalForm, department, domain, foreignDomain, serialNumber, confidence, reliabilityPolicy, employeeCount, pictureHash, latitude, longitude, population, publicKey, }) => {
|
|
297
276
|
if (!name || !country || !legalForm || (!domain && !foreignDomain))
|
|
298
277
|
throw new Error('Missing required fields');
|
|
299
|
-
if (!Object.values(
|
|
278
|
+
if (!Object.values(legalForms).includes(legalForm))
|
|
300
279
|
throw new Error('Invalid legal form ' + legalForm);
|
|
301
|
-
if (employeeCount && !Object.values(
|
|
280
|
+
if (employeeCount && !Object.values(peopleCountBuckets).includes(employeeCount))
|
|
302
281
|
throw new Error('Invalid employee count ' + employeeCount);
|
|
303
|
-
if (population && !Object.values(
|
|
282
|
+
if (population && !Object.values(peopleCountBuckets).includes(population))
|
|
304
283
|
throw new Error('Invalid population ' + population);
|
|
305
284
|
if (confidence && !('' + confidence)?.match(/^[0-9.]+$/))
|
|
306
285
|
throw new Error('Invalid confidence ' + confidence);
|
|
@@ -339,8 +318,7 @@ const buildOrganisationVerificationContent = ({ name, englishName, country, city
|
|
|
339
318
|
(reliabilityPolicy ? ' Reliability policy: ' + reliabilityPolicy + '\n' : '') +
|
|
340
319
|
(confidence ? ' Confidence: ' + confidence + '\n' : ''));
|
|
341
320
|
};
|
|
342
|
-
|
|
343
|
-
const parseOrganisationVerification = (content) => {
|
|
321
|
+
export const parseOrganisationVerification = (content) => {
|
|
344
322
|
const organisationVerificationRegex = new RegExp('' +
|
|
345
323
|
/^ Type: Organisation verification\n/.source +
|
|
346
324
|
/ Description: We verified the following information about an organisation.\n/.source +
|
|
@@ -367,7 +345,7 @@ const parseOrganisationVerification = (content) => {
|
|
|
367
345
|
if (!match || !match.groups)
|
|
368
346
|
throw new Error('Invalid organisation verification format: ' + content);
|
|
369
347
|
const { name, englishName, country, legalForm, domain, foreignDomain, department, province, serialNumber, city, latitude, longitude, population, pictureHash, employeeCount, publicKey, reliabilityPolicy, confidence, } = match.groups;
|
|
370
|
-
if (!
|
|
348
|
+
if (!isLegalForm(legalForm)) {
|
|
371
349
|
throw new Error('Invalid legal form after validation: ' + legalForm);
|
|
372
350
|
}
|
|
373
351
|
return {
|
|
@@ -383,16 +361,15 @@ const parseOrganisationVerification = (content) => {
|
|
|
383
361
|
city,
|
|
384
362
|
latitude: latitude ? parseFloat(latitude) : undefined,
|
|
385
363
|
longitude: longitude ? parseFloat(longitude) : undefined,
|
|
386
|
-
population: population &&
|
|
364
|
+
population: population && isPeopleCountBucket(population) ? population : undefined,
|
|
387
365
|
pictureHash,
|
|
388
|
-
employeeCount: employeeCount &&
|
|
366
|
+
employeeCount: employeeCount && isPeopleCountBucket(employeeCount) ? employeeCount : undefined,
|
|
389
367
|
publicKey,
|
|
390
368
|
reliabilityPolicy,
|
|
391
369
|
confidence: confidence ? parseFloat(confidence) : undefined,
|
|
392
370
|
};
|
|
393
371
|
};
|
|
394
|
-
|
|
395
|
-
const buildPersonVerificationContent = ({ name, countryOfBirth, cityOfBirth, ownDomain, foreignDomain, dateOfBirth, jobTitle, employer, verificationMethod, confidence, picture, reliabilityPolicy, publicKey, }) => {
|
|
372
|
+
export const buildPersonVerificationContent = ({ name, countryOfBirth, cityOfBirth, ownDomain, foreignDomain, dateOfBirth, jobTitle, employer, verificationMethod, confidence, picture, reliabilityPolicy, publicKey, }) => {
|
|
396
373
|
if (!name || !countryOfBirth || !cityOfBirth || !dateOfBirth || (!ownDomain && !foreignDomain)) {
|
|
397
374
|
throw new Error('Missing required fields for person verification');
|
|
398
375
|
}
|
|
@@ -430,8 +407,7 @@ const buildPersonVerificationContent = ({ name, countryOfBirth, cityOfBirth, own
|
|
|
430
407
|
(reliabilityPolicy ? ' Reliability policy: ' + reliabilityPolicy + '\n' : '');
|
|
431
408
|
return content;
|
|
432
409
|
};
|
|
433
|
-
|
|
434
|
-
const parsePersonVerification = (content) => {
|
|
410
|
+
export const parsePersonVerification = (content) => {
|
|
435
411
|
const domainVerificationRegex = new RegExp('' +
|
|
436
412
|
/^ Type: Person verification\n/.source +
|
|
437
413
|
/ Description: We verified the following information about a person.\n/.source +
|
|
@@ -453,14 +429,14 @@ const parsePersonVerification = (content) => {
|
|
|
453
429
|
if (!match || !match.groups)
|
|
454
430
|
throw new Error('Invalid person verification format: ' + content);
|
|
455
431
|
const { name, dateOfBirth: dateOfBirthStr, cityOfBirth, countryOfBirth, jobTitle, employer, domain, foreignDomain, picture, verificationMethod, publicKey, confidence, reliabilityPolicy, } = match.groups;
|
|
456
|
-
if (dateOfBirthStr && !dateOfBirthStr.match(
|
|
432
|
+
if (dateOfBirthStr && !dateOfBirthStr.match(birthDateFormat))
|
|
457
433
|
throw new Error('Invalid birth date format: ' + dateOfBirthStr);
|
|
458
|
-
const { d, month, y } = dateOfBirthStr.match(
|
|
434
|
+
const { d, month, y } = dateOfBirthStr.match(birthDateFormat)?.groups || {};
|
|
459
435
|
if (!d || !month || !y)
|
|
460
436
|
throw new Error('Invalid birth date format: ' + dateOfBirthStr);
|
|
461
437
|
return {
|
|
462
438
|
name,
|
|
463
|
-
dateOfBirth: new Date(Date.UTC(parseInt(y),
|
|
439
|
+
dateOfBirth: new Date(Date.UTC(parseInt(y), monthIndex(month), parseInt(d))),
|
|
464
440
|
cityOfBirth,
|
|
465
441
|
countryOfBirth,
|
|
466
442
|
jobTitle,
|
|
@@ -474,8 +450,7 @@ const parsePersonVerification = (content) => {
|
|
|
474
450
|
reliabilityPolicy,
|
|
475
451
|
};
|
|
476
452
|
};
|
|
477
|
-
|
|
478
|
-
const buildVoteContent = ({ pollHash, poll, vote }) => {
|
|
453
|
+
export const buildVoteContent = ({ pollHash, poll, vote }) => {
|
|
479
454
|
const content = ' Type: Vote\n' +
|
|
480
455
|
' Poll id: ' +
|
|
481
456
|
pollHash +
|
|
@@ -488,8 +463,7 @@ const buildVoteContent = ({ pollHash, poll, vote }) => {
|
|
|
488
463
|
'\n';
|
|
489
464
|
return content;
|
|
490
465
|
};
|
|
491
|
-
|
|
492
|
-
const parseVote = (content) => {
|
|
466
|
+
export const parseVote = (content) => {
|
|
493
467
|
const voteRegex = new RegExp('' +
|
|
494
468
|
/^ Type: Vote\n/.source +
|
|
495
469
|
/ Poll id: (?<pollHash>[^\n]+?)\n/.source +
|
|
@@ -502,8 +476,7 @@ const parseVote = (content) => {
|
|
|
502
476
|
const { pollHash, poll, vote } = match.groups;
|
|
503
477
|
return { pollHash, poll, vote };
|
|
504
478
|
};
|
|
505
|
-
|
|
506
|
-
const buildDisputeAuthenticityContent = ({ hash, confidence, reliabilityPolicy, }) => {
|
|
479
|
+
export const buildDisputeAuthenticityContent = ({ hash, confidence, reliabilityPolicy, }) => {
|
|
507
480
|
const content = ' Type: Dispute statement authenticity\n' +
|
|
508
481
|
' Description: We think that the referenced statement is not authentic.\n' +
|
|
509
482
|
' Hash of referenced statement: ' +
|
|
@@ -513,8 +486,7 @@ const buildDisputeAuthenticityContent = ({ hash, confidence, reliabilityPolicy,
|
|
|
513
486
|
(reliabilityPolicy ? ' Reliability policy: ' + reliabilityPolicy + '\n' : '');
|
|
514
487
|
return content;
|
|
515
488
|
};
|
|
516
|
-
|
|
517
|
-
const parseDisputeAuthenticity = (content) => {
|
|
489
|
+
export const parseDisputeAuthenticity = (content) => {
|
|
518
490
|
const disputeRegex = new RegExp('' +
|
|
519
491
|
/^ Type: Dispute statement authenticity\n/.source +
|
|
520
492
|
/ Description: We think that the referenced statement is not authentic.\n/.source +
|
|
@@ -532,8 +504,7 @@ const parseDisputeAuthenticity = (content) => {
|
|
|
532
504
|
reliabilityPolicy,
|
|
533
505
|
};
|
|
534
506
|
};
|
|
535
|
-
|
|
536
|
-
const buildDisputeContentContent = ({ hash, confidence, reliabilityPolicy, }) => {
|
|
507
|
+
export const buildDisputeContentContent = ({ hash, confidence, reliabilityPolicy, }) => {
|
|
537
508
|
const content = ' Type: Dispute statement content\n' +
|
|
538
509
|
' Description: We think that the content of the referenced statement is false.\n' +
|
|
539
510
|
' Hash of referenced statement: ' +
|
|
@@ -543,8 +514,7 @@ const buildDisputeContentContent = ({ hash, confidence, reliabilityPolicy, }) =>
|
|
|
543
514
|
(reliabilityPolicy ? ' Reliability policy: ' + reliabilityPolicy + '\n' : '');
|
|
544
515
|
return content;
|
|
545
516
|
};
|
|
546
|
-
|
|
547
|
-
const parseDisputeContent = (content) => {
|
|
517
|
+
export const parseDisputeContent = (content) => {
|
|
548
518
|
const disputeRegex = new RegExp('' +
|
|
549
519
|
/^ Type: Dispute statement content\n/.source +
|
|
550
520
|
/ Description: We think that the content of the referenced statement is false.\n/.source +
|
|
@@ -562,8 +532,7 @@ const parseDisputeContent = (content) => {
|
|
|
562
532
|
reliabilityPolicy,
|
|
563
533
|
};
|
|
564
534
|
};
|
|
565
|
-
|
|
566
|
-
const buildResponseContent = ({ hash, response }) => {
|
|
535
|
+
export const buildResponseContent = ({ hash, response }) => {
|
|
567
536
|
const content = ' Type: Response\n' +
|
|
568
537
|
' Hash of referenced statement: ' +
|
|
569
538
|
hash +
|
|
@@ -573,8 +542,7 @@ const buildResponseContent = ({ hash, response }) => {
|
|
|
573
542
|
'\n';
|
|
574
543
|
return content;
|
|
575
544
|
};
|
|
576
|
-
|
|
577
|
-
const parseResponseContent = (content) => {
|
|
545
|
+
export const parseResponseContent = (content) => {
|
|
578
546
|
const responseRegex = new RegExp('' +
|
|
579
547
|
/^ Type: Response\n/.source +
|
|
580
548
|
/ Hash of referenced statement: (?<hash>[^\n]+?)\n/.source +
|
|
@@ -586,8 +554,7 @@ const parseResponseContent = (content) => {
|
|
|
586
554
|
const { hash, response } = match.groups;
|
|
587
555
|
return { hash, response };
|
|
588
556
|
};
|
|
589
|
-
|
|
590
|
-
const buildPDFSigningContent = ({ hash }) => {
|
|
557
|
+
export const buildPDFSigningContent = ({ hash }) => {
|
|
591
558
|
if (!hash.match(/^[A-Za-z0-9_-]+$/)) {
|
|
592
559
|
throw new Error('PDF file hash must be in URL-safe base64 format (A-Z, a-z, 0-9, _, -)');
|
|
593
560
|
}
|
|
@@ -598,8 +565,7 @@ const buildPDFSigningContent = ({ hash }) => {
|
|
|
598
565
|
'\n';
|
|
599
566
|
return content;
|
|
600
567
|
};
|
|
601
|
-
|
|
602
|
-
const parsePDFSigning = (content) => {
|
|
568
|
+
export const parsePDFSigning = (content) => {
|
|
603
569
|
const signingRegex = new RegExp('' +
|
|
604
570
|
/^ Type: Sign PDF\n/.source +
|
|
605
571
|
/ Description: We hereby digitally sign the referenced PDF file.\n/.source +
|
|
@@ -611,8 +577,7 @@ const parsePDFSigning = (content) => {
|
|
|
611
577
|
const { hash } = match.groups;
|
|
612
578
|
return { hash };
|
|
613
579
|
};
|
|
614
|
-
|
|
615
|
-
const buildRating = ({ subjectName, subjectType, subjectReference, documentFileHash, rating, quality, comment, }) => {
|
|
580
|
+
export const buildRating = ({ subjectName, subjectType, subjectReference, documentFileHash, rating, quality, comment, }) => {
|
|
616
581
|
if (![1, 2, 3, 4, 5].includes(rating))
|
|
617
582
|
throw new Error('Invalid rating: ' + rating);
|
|
618
583
|
const content = ' Type: Rating\n' +
|
|
@@ -629,8 +594,7 @@ const buildRating = ({ subjectName, subjectType, subjectReference, documentFileH
|
|
|
629
594
|
(comment ? ' Comment:\n ' + comment + '\n' : '');
|
|
630
595
|
return content;
|
|
631
596
|
};
|
|
632
|
-
|
|
633
|
-
const parseRating = (content) => {
|
|
597
|
+
export const parseRating = (content) => {
|
|
634
598
|
const ratingRegex = new RegExp('' +
|
|
635
599
|
/^ Type: Rating\n/.source +
|
|
636
600
|
/(?: Subject type: (?<subjectType>[^\n]*?)\n)?/.source +
|
|
@@ -660,7 +624,7 @@ const parseRating = (content) => {
|
|
|
660
624
|
throw new Error('Invalid subject type: ' + subjectType);
|
|
661
625
|
if (!subjectName)
|
|
662
626
|
throw new Error('Missing subject name');
|
|
663
|
-
if (!
|
|
627
|
+
if (!isRatingValue(rating)) {
|
|
664
628
|
throw new Error('Invalid rating after validation: ' + rating);
|
|
665
629
|
}
|
|
666
630
|
return {
|
|
@@ -673,5 +637,4 @@ const parseRating = (content) => {
|
|
|
673
637
|
comment,
|
|
674
638
|
};
|
|
675
639
|
};
|
|
676
|
-
exports.parseRating = parseRating;
|
|
677
640
|
//# sourceMappingURL=protocol.js.map
|