stated-protocol-parser 1.0.6 → 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.
Files changed (109) hide show
  1. package/README.md +231 -22
  2. package/dist/constants.d.ts +193 -15
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +197 -20
  5. package/dist/constants.js.map +1 -1
  6. package/dist/esm/constants.d.ts +193 -15
  7. package/dist/esm/constants.d.ts.map +1 -1
  8. package/dist/esm/{hash.browser.d.ts → hash.d.ts} +11 -5
  9. package/dist/esm/hash.d.ts.map +1 -0
  10. package/dist/esm/index.d.ts +4 -42
  11. package/dist/esm/index.d.ts.map +1 -1
  12. package/dist/esm/index.js +2102 -641
  13. package/dist/esm/index.js.map +7 -1
  14. package/dist/esm/protocol.d.ts +30 -0
  15. package/dist/esm/protocol.d.ts.map +1 -0
  16. package/dist/esm/signature.d.ts +49 -0
  17. package/dist/esm/signature.d.ts.map +1 -0
  18. package/dist/esm/types.d.ts +26 -60
  19. package/dist/esm/types.d.ts.map +1 -1
  20. package/dist/esm/utils.d.ts +10 -0
  21. package/dist/esm/utils.d.ts.map +1 -1
  22. package/dist/{hash.browser.d.ts → hash.d.ts} +11 -5
  23. package/dist/hash.d.ts.map +1 -0
  24. package/dist/{hash.browser.js → hash.js} +44 -10
  25. package/dist/hash.js.map +1 -0
  26. package/dist/index.d.ts +4 -42
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -674
  29. package/dist/index.js.map +1 -1
  30. package/dist/protocol.d.ts +30 -0
  31. package/dist/protocol.d.ts.map +1 -0
  32. package/dist/protocol.js +677 -0
  33. package/dist/protocol.js.map +1 -0
  34. package/dist/signature.d.ts +49 -0
  35. package/dist/signature.d.ts.map +1 -0
  36. package/dist/signature.js +169 -0
  37. package/dist/signature.js.map +1 -0
  38. package/dist/types.d.ts +26 -60
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js +27 -0
  41. package/dist/types.js.map +1 -1
  42. package/dist/utils.d.ts +10 -0
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js +79 -11
  45. package/dist/utils.js.map +1 -1
  46. package/package.json +25 -16
  47. package/src/constants.ts +228 -44
  48. package/src/fixtures.test.ts +236 -0
  49. package/src/hash.test.ts +217 -215
  50. package/src/hash.ts +99 -0
  51. package/src/index.ts +5 -678
  52. package/src/organisation-verification.test.ts +50 -0
  53. package/src/person-verification.test.ts +55 -0
  54. package/src/poll.test.ts +28 -0
  55. package/src/protocol.ts +871 -0
  56. package/src/rating.test.ts +25 -0
  57. package/src/signature.test.ts +200 -0
  58. package/src/signature.ts +159 -0
  59. package/src/statement.test.ts +101 -0
  60. package/src/types.ts +155 -156
  61. package/src/utils.test.ts +140 -0
  62. package/src/utils.ts +102 -16
  63. package/dist/esm/constants.js +0 -47
  64. package/dist/esm/constants.js.map +0 -1
  65. package/dist/esm/hash.browser.d.ts.map +0 -1
  66. package/dist/esm/hash.browser.js +0 -58
  67. package/dist/esm/hash.browser.js.map +0 -1
  68. package/dist/esm/hash.node.d.ts +0 -31
  69. package/dist/esm/hash.node.d.ts.map +0 -1
  70. package/dist/esm/hash.node.js +0 -43
  71. package/dist/esm/hash.node.js.map +0 -1
  72. package/dist/esm/hash.test.d.ts +0 -2
  73. package/dist/esm/hash.test.d.ts.map +0 -1
  74. package/dist/esm/hash.test.js +0 -181
  75. package/dist/esm/hash.test.js.map +0 -1
  76. package/dist/esm/index.test.d.ts +0 -2
  77. package/dist/esm/index.test.d.ts.map +0 -1
  78. package/dist/esm/index.test.js +0 -293
  79. package/dist/esm/index.test.js.map +0 -1
  80. package/dist/esm/types.js +0 -2
  81. package/dist/esm/types.js.map +0 -1
  82. package/dist/esm/utils.js +0 -23
  83. package/dist/esm/utils.js.map +0 -1
  84. package/dist/esm/v3.d.ts +0 -5
  85. package/dist/esm/v3.d.ts.map +0 -1
  86. package/dist/esm/v3.js +0 -60
  87. package/dist/esm/v3.js.map +0 -1
  88. package/dist/hash.browser.d.ts.map +0 -1
  89. package/dist/hash.browser.js.map +0 -1
  90. package/dist/hash.node.d.ts +0 -31
  91. package/dist/hash.node.d.ts.map +0 -1
  92. package/dist/hash.node.js +0 -53
  93. package/dist/hash.node.js.map +0 -1
  94. package/dist/hash.test.d.ts +0 -2
  95. package/dist/hash.test.d.ts.map +0 -1
  96. package/dist/hash.test.js +0 -183
  97. package/dist/hash.test.js.map +0 -1
  98. package/dist/index.test.d.ts +0 -2
  99. package/dist/index.test.d.ts.map +0 -1
  100. package/dist/index.test.js +0 -295
  101. package/dist/index.test.js.map +0 -1
  102. package/dist/v3.d.ts +0 -5
  103. package/dist/v3.d.ts.map +0 -1
  104. package/dist/v3.js +0 -64
  105. package/dist/v3.js.map +0 -1
  106. package/src/hash.browser.ts +0 -65
  107. package/src/hash.node.ts +0 -47
  108. package/src/index.test.ts +0 -378
  109. package/src/v3.ts +0 -62
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2CAAgD;AAEzC,MAAM,qBAAqB,GAAG,CAAC,CAAS,EAAsB,EAAE;IACnE,IAAI,CAAC,IAAI,QAAQ;QAAE,OAAO,8BAAkB,CAAC,UAAU,CAAC,CAAA;IACxD,IAAI,CAAC,IAAI,OAAO;QAAE,OAAO,8BAAkB,CAAC,SAAS,CAAC,CAAA;IACtD,IAAI,CAAC,IAAI,MAAM;QAAE,OAAO,8BAAkB,CAAC,QAAQ,CAAC,CAAA;IACpD,IAAI,CAAC,IAAI,KAAK;QAAE,OAAO,8BAAkB,CAAC,OAAO,CAAC,CAAA;IAClD,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,8BAAkB,CAAC,MAAM,CAAC,CAAA;IAChD,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,8BAAkB,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,8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AAE,OAAO,8BAAkB,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,IAAI,OAAO;QAAE,OAAO,8BAAkB,CAAC,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,IAAI,MAAM;QAAE,OAAO,8BAAkB,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,KAAK;QAAE,OAAO,8BAAkB,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,8BAAkB,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,8BAAkB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,8BAAkB,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,8BAAkB,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC;AAEK,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAClD,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAC1F,KAAK,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CACjC,CAAC;AAHS,QAAA,UAAU,cAGnB;AAES,QAAA,eAAe,GAC1B,uFAAuF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stated-protocol-parser",
3
- "version": "1.0.6",
3
+ "version": "5.0.0",
4
4
  "description": "Parser and formatter for the Stated protocol - a decentralized statement verification system",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -8,23 +8,25 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "browser": "./dist/esm/index.js",
12
11
  "import": "./dist/esm/index.js",
13
12
  "require": "./dist/index.js",
14
13
  "default": "./dist/index.js"
15
- },
16
- "./node": {
17
- "types": "./dist/hash.node.d.ts",
18
- "import": "./dist/esm/hash.node.js",
19
- "require": "./dist/hash.node.js"
20
14
  }
21
15
  },
22
16
  "scripts": {
23
- "build": "npm run build:cjs && npm run build:esm",
17
+ "clean": "rm -rf dist",
18
+ "build": "npm run clean && npm run build:cjs && npm run build:esm",
24
19
  "build:cjs": "tsc",
25
- "build:esm": "tsc -p tsconfig.esm.json",
26
- "test": "jest",
27
- "prepublishOnly": "npm run build"
20
+ "build:esm": "node scripts/build-esm.js && tsc -p tsconfig.esm.json --emitDeclarationOnly",
21
+ "test": "tsx --test 'src/**/*.test.ts'",
22
+ "lint": "eslint 'src/**/*.ts' 'scripts/**/*.ts'",
23
+ "lint:fix": "eslint 'src/**/*.ts' 'scripts/**/*.ts' --fix",
24
+ "format": "prettier --write 'src/**/*.ts' 'scripts/**/*.ts'",
25
+ "format:check": "prettier --check 'src/**/*.ts' 'scripts/**/*.ts'",
26
+ "fix": "npm run format && npm run lint:fix",
27
+ "typecheck": "tsc --noEmit",
28
+ "prepublishOnly": "npm run build",
29
+ "update-fixtures": "tsx scripts/updateFixtures.ts"
28
30
  },
29
31
  "keywords": [
30
32
  "stated",
@@ -38,10 +40,13 @@
38
40
  "author": "",
39
41
  "license": "MIT",
40
42
  "devDependencies": {
41
- "@types/jest": "^29.5.0",
42
- "@types/node": "^20.0.0",
43
- "jest": "^29.5.0",
44
- "ts-jest": "^29.1.0",
43
+ "@types/node": "^20.19.27",
44
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
45
+ "@typescript-eslint/parser": "^6.21.0",
46
+ "esbuild": "^0.27.2",
47
+ "eslint": "^8.57.0",
48
+ "prettier": "^3.2.5",
49
+ "tsx": "^4.21.0",
45
50
  "typescript": "^5.0.0"
46
51
  },
47
52
  "files": [
@@ -53,5 +58,9 @@
53
58
  "repository": {
54
59
  "type": "git",
55
60
  "url": "https://github.com/c-riq/stated"
61
+ },
62
+ "dependencies": {
63
+ "@noble/ed25519": "^3.0.0",
64
+ "@noble/hashes": "^2.0.1"
56
65
  }
57
- }
66
+ }
package/src/constants.ts CHANGED
@@ -1,61 +1,245 @@
1
1
  export const legalForms = {
2
- local_government: 'local government',
3
- state_government: 'state government',
4
- foreign_affairs_ministry: 'foreign affairs ministry',
5
- corporation: 'corporation',
6
- }
2
+ local_government: 'local government',
3
+ state_government: 'state government',
4
+ foreign_affairs_ministry: 'foreign affairs ministry',
5
+ corporation: 'corporation',
6
+ };
7
7
 
8
8
  export const statementTypes = {
9
- statement: 'statement',
10
- quotation: 'quotation',
11
- organisationVerification: 'organisation_verification',
12
- personVerification: 'person_verification',
13
- poll: 'poll',
14
- vote: 'vote',
15
- response: 'response',
16
- disputeContent: 'dispute_statement_content',
17
- disputeAuthenticity: 'dispute_statement_authenticity',
18
- boycott: 'boycott',
19
- observation: 'observation',
20
- rating: 'rating',
21
- signPdf: "sign_pdf",
22
- bounty: "bounty",
23
- unsupported: "unsupported",
24
- }
9
+ statement: 'statement',
10
+ organisationVerification: 'organisation_verification',
11
+ personVerification: 'person_verification',
12
+ poll: 'poll',
13
+ vote: 'vote',
14
+ response: 'response',
15
+ disputeContent: 'dispute_statement_content',
16
+ disputeAuthenticity: 'dispute_statement_authenticity',
17
+ rating: 'rating',
18
+ signPdf: 'sign_pdf',
19
+ unsupported: 'unsupported',
20
+ };
25
21
 
26
22
  export const peopleCountBuckets = {
27
- "0": "0-10",
28
- "10": "10-100",
29
- "100": "100-1000",
30
- "1000": "1000-10,000",
31
- "10000": "10,000-100,000",
32
- "100000": "100,000+",
33
- "1000000": "1,000,000+",
34
- "10000000": "10,000,000+",
35
- }
23
+ '0': '0-10',
24
+ '10': '10-100',
25
+ '100': '100-1000',
26
+ '1000': '1000-10,000',
27
+ '10000': '10,000-100,000',
28
+ '100000': '100,000+',
29
+ '1000000': '1,000,000+',
30
+ '10000000': '10,000,000+',
31
+ };
36
32
 
37
- export const UTCFormat: RegExp = /(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/
33
+ export const supportedLanguages = {
34
+ aa: 'aa',
35
+ ab: 'ab',
36
+ af: 'af',
37
+ ak: 'ak',
38
+ am: 'am',
39
+ ar: 'ar',
40
+ an: 'an',
41
+ as: 'as',
42
+ av: 'av',
43
+ ay: 'ay',
44
+ az: 'az',
45
+ ba: 'ba',
46
+ bm: 'bm',
47
+ be: 'be',
48
+ bn: 'bn',
49
+ bi: 'bi',
50
+ bo: 'bo',
51
+ bs: 'bs',
52
+ br: 'br',
53
+ bg: 'bg',
54
+ ca: 'ca',
55
+ cs: 'cs',
56
+ ch: 'ch',
57
+ ce: 'ce',
58
+ cv: 'cv',
59
+ kw: 'kw',
60
+ co: 'co',
61
+ cr: 'cr',
62
+ cy: 'cy',
63
+ da: 'da',
64
+ de: 'de',
65
+ dv: 'dv',
66
+ dz: 'dz',
67
+ el: 'el',
68
+ en: 'en',
69
+ eo: 'eo',
70
+ et: 'et',
71
+ eu: 'eu',
72
+ ee: 'ee',
73
+ fo: 'fo',
74
+ fa: 'fa',
75
+ fj: 'fj',
76
+ fi: 'fi',
77
+ fr: 'fr',
78
+ fy: 'fy',
79
+ ff: 'ff',
80
+ gd: 'gd',
81
+ ga: 'ga',
82
+ gl: 'gl',
83
+ gv: 'gv',
84
+ gn: 'gn',
85
+ gu: 'gu',
86
+ ht: 'ht',
87
+ ha: 'ha',
88
+ sh: 'sh',
89
+ he: 'he',
90
+ hz: 'hz',
91
+ hi: 'hi',
92
+ ho: 'ho',
93
+ hr: 'hr',
94
+ hu: 'hu',
95
+ hy: 'hy',
96
+ ig: 'ig',
97
+ io: 'io',
98
+ ii: 'ii',
99
+ iu: 'iu',
100
+ ie: 'ie',
101
+ ia: 'ia',
102
+ id: 'id',
103
+ ik: 'ik',
104
+ is: 'is',
105
+ it: 'it',
106
+ jv: 'jv',
107
+ ja: 'ja',
108
+ kl: 'kl',
109
+ kn: 'kn',
110
+ ks: 'ks',
111
+ ka: 'ka',
112
+ kr: 'kr',
113
+ kk: 'kk',
114
+ km: 'km',
115
+ ki: 'ki',
116
+ rw: 'rw',
117
+ ky: 'ky',
118
+ kv: 'kv',
119
+ kg: 'kg',
120
+ ko: 'ko',
121
+ kj: 'kj',
122
+ ku: 'ku',
123
+ lo: 'lo',
124
+ la: 'la',
125
+ lv: 'lv',
126
+ li: 'li',
127
+ ln: 'ln',
128
+ lt: 'lt',
129
+ lb: 'lb',
130
+ lu: 'lu',
131
+ lg: 'lg',
132
+ mh: 'mh',
133
+ ml: 'ml',
134
+ mr: 'mr',
135
+ mk: 'mk',
136
+ mg: 'mg',
137
+ mt: 'mt',
138
+ mn: 'mn',
139
+ mi: 'mi',
140
+ ms: 'ms',
141
+ my: 'my',
142
+ na: 'na',
143
+ nv: 'nv',
144
+ nr: 'nr',
145
+ nd: 'nd',
146
+ ng: 'ng',
147
+ ne: 'ne',
148
+ nl: 'nl',
149
+ nn: 'nn',
150
+ nb: 'nb',
151
+ no: 'no',
152
+ ny: 'ny',
153
+ oc: 'oc',
154
+ oj: 'oj',
155
+ or: 'or',
156
+ om: 'om',
157
+ os: 'os',
158
+ pa: 'pa',
159
+ pi: 'pi',
160
+ pl: 'pl',
161
+ pt: 'pt',
162
+ ps: 'ps',
163
+ qu: 'qu',
164
+ rm: 'rm',
165
+ ro: 'ro',
166
+ rn: 'rn',
167
+ ru: 'ru',
168
+ sg: 'sg',
169
+ sa: 'sa',
170
+ si: 'si',
171
+ sk: 'sk',
172
+ sl: 'sl',
173
+ se: 'se',
174
+ sm: 'sm',
175
+ sn: 'sn',
176
+ sd: 'sd',
177
+ so: 'so',
178
+ st: 'st',
179
+ es: 'es',
180
+ sq: 'sq',
181
+ sc: 'sc',
182
+ sr: 'sr',
183
+ ss: 'ss',
184
+ su: 'su',
185
+ sw: 'sw',
186
+ sv: 'sv',
187
+ ty: 'ty',
188
+ ta: 'ta',
189
+ tt: 'tt',
190
+ te: 'te',
191
+ tg: 'tg',
192
+ tl: 'tl',
193
+ th: 'th',
194
+ ti: 'ti',
195
+ to: 'to',
196
+ tn: 'tn',
197
+ ts: 'ts',
198
+ tk: 'tk',
199
+ tr: 'tr',
200
+ tw: 'tw',
201
+ ug: 'ug',
202
+ uk: 'uk',
203
+ ur: 'ur',
204
+ uz: 'uz',
205
+ ve: 've',
206
+ vi: 'vi',
207
+ vo: 'vo',
208
+ wa: 'wa',
209
+ wo: 'wo',
210
+ xh: 'xh',
211
+ yi: 'yi',
212
+ yo: 'yo',
213
+ za: 'za',
214
+ zh: 'zh',
215
+ zu: 'zu',
216
+ } as const;
38
217
 
39
- 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
218
+ export type SupportedLanguage = (typeof supportedLanguages)[keyof typeof supportedLanguages];
40
219
 
41
- 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: )/g
220
+ export const UTCFormat: RegExp =
221
+ /(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/;
42
222
 
43
- 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
223
+ export const pollKeys =
224
+ /(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;
44
225
 
45
- export const voteKeys = /(Type: |Poll id: |Poll: |Option: )/g
226
+ export const organisationVerificationKeys =
227
+ /(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;
46
228
 
47
- export const disputeAuthenticityKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g
229
+ export const personVerificationKeys =
230
+ /(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;
48
231
 
49
- export const disputeContentKeys = /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g
232
+ export const voteKeys = /(Type: |Poll id: |Poll: |Option: )/g;
50
233
 
51
- export const responseKeys = /(Type: |Hash of referenced statement: |Response: )/
234
+ export const disputeAuthenticityKeys =
235
+ /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
52
236
 
53
- export const PDFSigningKeys = /(Type: |Description: |PDF file hash: )/
237
+ export const disputeContentKeys =
238
+ /(Type: |Description: |Hash of referenced statement: |Confidence: |Reliability policy: )/g;
54
239
 
55
- export const ratingKeys = /(Type: |Subject type: |Subject name: |URL that identifies the subject: |Document file hash: |Rated quality: |Our rating: |Comment: )/
240
+ export const responseKeys = /(Type: |Hash of referenced statement: |Response: )/;
56
241
 
57
- export const BountyKeys = /(Type: |In order to: |We will reward any entity that: |The reward is: |In case of dispute, bounty claims are judged by: |The judge will be paid per investigated case with a maxium of: )/
242
+ export const PDFSigningKeys = /(Type: |Description: |PDF file hash: )/g;
58
243
 
59
- export const ObservationKeys = /(Type: |Approach: |Confidence: |Reliability policy: |Subject: |Subject identity reference: |Observation reference: |Observed property: |Observed value: )/
60
-
61
- export const BoycottKeys = /(Type: |Description: |Subject: |Subject identity reference: )/
244
+ export const ratingKeys =
245
+ /(Type: |Subject type: |Subject name: |URL that identifies the subject: |Document file hash: |Rated quality: |Our rating: |Comment: )/;
@@ -0,0 +1,236 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert';
6
+ import {
7
+ buildStatement,
8
+ parseStatement,
9
+ buildPollContent,
10
+ buildVoteContent,
11
+ buildOrganisationVerificationContent,
12
+ buildPersonVerificationContent,
13
+ buildDisputeAuthenticityContent,
14
+ buildDisputeContentContent,
15
+ buildResponseContent,
16
+ buildPDFSigningContent,
17
+ buildRating,
18
+ } from './protocol';
19
+ import { verifySignedStatement } from './signature';
20
+
21
+ // ESM-compatible __dirname
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = path.dirname(__filename);
24
+
25
+ const fixturesDir = path.join(__dirname, '../fixtures');
26
+
27
+ function getFixtureDirs(): string[] {
28
+ if (!fs.existsSync(fixturesDir)) {
29
+ return [];
30
+ }
31
+ return fs
32
+ .readdirSync(fixturesDir, { withFileTypes: true })
33
+ .filter((dirent) => dirent.isDirectory())
34
+ .map((dirent) => dirent.name);
35
+ }
36
+
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ function buildContentFromInput(contentObj: any): string {
39
+ if (!contentObj || typeof contentObj !== 'object') {
40
+ throw new Error('Content must be an object with a type field');
41
+ }
42
+
43
+ switch (contentObj.type) {
44
+ case 'poll':
45
+ return buildPollContent({
46
+ poll: contentObj.poll,
47
+ options: contentObj.options || [],
48
+ deadline: contentObj.deadline ? new Date(contentObj.deadline) : undefined,
49
+ scopeDescription: contentObj.scopeDescription,
50
+ allowArbitraryVote: contentObj.allowArbitraryVote,
51
+ });
52
+ case 'vote':
53
+ return buildVoteContent({
54
+ pollHash: contentObj.pollHash,
55
+ poll: contentObj.poll,
56
+ vote: contentObj.vote,
57
+ });
58
+ case 'organisation_verification':
59
+ return buildOrganisationVerificationContent({
60
+ name: contentObj.name,
61
+ englishName: contentObj.englishName,
62
+ country: contentObj.country,
63
+ city: contentObj.city,
64
+ province: contentObj.province,
65
+ legalForm: contentObj.legalForm,
66
+ department: contentObj.department,
67
+ domain: contentObj.domain,
68
+ foreignDomain: contentObj.foreignDomain,
69
+ serialNumber: contentObj.serialNumber,
70
+ confidence: contentObj.confidence,
71
+ reliabilityPolicy: contentObj.reliabilityPolicy,
72
+ employeeCount: contentObj.employeeCount,
73
+ pictureHash: contentObj.pictureHash,
74
+ latitude: contentObj.latitude,
75
+ longitude: contentObj.longitude,
76
+ population: contentObj.population,
77
+ publicKey: contentObj.publicKey,
78
+ });
79
+ case 'person_verification':
80
+ return buildPersonVerificationContent({
81
+ name: contentObj.name,
82
+ countryOfBirth: contentObj.countryOfBirth,
83
+ cityOfBirth: contentObj.cityOfBirth,
84
+ ownDomain: contentObj.ownDomain,
85
+ foreignDomain: contentObj.foreignDomain,
86
+ dateOfBirth: new Date(contentObj.dateOfBirth),
87
+ jobTitle: contentObj.jobTitle,
88
+ employer: contentObj.employer,
89
+ verificationMethod: contentObj.verificationMethod,
90
+ confidence: contentObj.confidence,
91
+ picture: contentObj.picture,
92
+ reliabilityPolicy: contentObj.reliabilityPolicy,
93
+ publicKey: contentObj.publicKey,
94
+ });
95
+ case 'dispute_authenticity':
96
+ return buildDisputeAuthenticityContent({
97
+ hash: contentObj.hash,
98
+ confidence: contentObj.confidence,
99
+ reliabilityPolicy: contentObj.reliabilityPolicy,
100
+ });
101
+ case 'dispute_content':
102
+ return buildDisputeContentContent({
103
+ hash: contentObj.hash,
104
+ confidence: contentObj.confidence,
105
+ reliabilityPolicy: contentObj.reliabilityPolicy,
106
+ });
107
+ case 'response':
108
+ return buildResponseContent({
109
+ hash: contentObj.hash,
110
+ response: contentObj.response,
111
+ });
112
+ case 'pdf_signing':
113
+ return buildPDFSigningContent({
114
+ hash: contentObj.hash,
115
+ });
116
+ case 'rating':
117
+ return buildRating({
118
+ subjectName: contentObj.subjectName,
119
+ subjectType: contentObj.subjectType,
120
+ subjectReference: contentObj.subjectReference,
121
+ documentFileHash: contentObj.documentFileHash,
122
+ rating: contentObj.rating,
123
+ quality: contentObj.quality,
124
+ comment: contentObj.comment,
125
+ });
126
+ default:
127
+ throw new Error(`Unknown content type: ${contentObj.type}`);
128
+ }
129
+ }
130
+
131
+ describe('Fixture Validation', () => {
132
+ const fixtureDirs = getFixtureDirs();
133
+
134
+ if (fixtureDirs.length === 0) {
135
+ it('no fixtures found', () => {
136
+ // No fixture directories found
137
+ assert.ok(true);
138
+ });
139
+ return;
140
+ }
141
+
142
+ for (const dir of fixtureDirs) {
143
+ describe(`Fixture: ${dir}`, () => {
144
+ const inputPath = path.join(fixturesDir, dir, 'input.json');
145
+ const outputPath = path.join(fixturesDir, dir, 'output.txt');
146
+
147
+ if (!fs.existsSync(inputPath)) {
148
+ it('should have input.json', () => {
149
+ assert.fail(`Missing input.json in ${dir}`);
150
+ });
151
+ return;
152
+ }
153
+
154
+ if (!fs.existsSync(outputPath)) {
155
+ it('should have output.txt', () => {
156
+ assert.fail(`Missing output.txt in ${dir}`);
157
+ });
158
+ return;
159
+ }
160
+
161
+ it('output.txt should match built statement from input.json', async () => {
162
+ const input = JSON.parse(fs.readFileSync(inputPath, 'utf-8'));
163
+ const expectedOutput = fs.readFileSync(outputPath, 'utf-8');
164
+
165
+ if (input.signature) {
166
+ const isValid = await verifySignedStatement(expectedOutput);
167
+ assert.strictEqual(isValid, true);
168
+ return;
169
+ }
170
+
171
+ let content: string;
172
+ if (typeof input.content === 'string') {
173
+ content = input.content;
174
+ } else {
175
+ content = buildContentFromInput(input.content);
176
+ }
177
+
178
+ // Build statement
179
+ const builtStatement = buildStatement({
180
+ domain: input.domain,
181
+ author: input.author,
182
+ time: new Date(input.time),
183
+ tags: input.tags,
184
+ content,
185
+ representative: input.representative,
186
+ supersededStatement: input.supersededStatement,
187
+ translations: input.translations,
188
+ attachments: input.attachments,
189
+ });
190
+
191
+ assert.strictEqual(builtStatement, expectedOutput);
192
+ });
193
+
194
+ it('output.txt should not contain double newlines', () => {
195
+ const output = fs.readFileSync(outputPath, 'utf-8');
196
+ assert.ok(!/\n\n/.test(output));
197
+ });
198
+
199
+ it('output.txt should be parseable', () => {
200
+ const output = fs.readFileSync(outputPath, 'utf-8');
201
+ const parsed = parseStatement({ statement: output });
202
+
203
+ assert.ok(parsed.domain);
204
+ assert.ok(parsed.author);
205
+ assert.ok(parsed.content);
206
+ assert.strictEqual(parsed.formatVersion, '5');
207
+ });
208
+
209
+ it('round-trip: parse(output.txt) should match input.json structure', () => {
210
+ const input = JSON.parse(fs.readFileSync(inputPath, 'utf-8'));
211
+ const output = fs.readFileSync(outputPath, 'utf-8');
212
+ const parsed = parseStatement({ statement: output });
213
+
214
+ assert.strictEqual(parsed.domain, input.domain);
215
+ assert.strictEqual(parsed.author, input.author);
216
+ assert.strictEqual(new Date(parsed.time).toISOString(), new Date(input.time).toISOString());
217
+
218
+ if (input.tags) {
219
+ assert.deepStrictEqual(parsed.tags, input.tags);
220
+ }
221
+ if (input.representative) {
222
+ assert.strictEqual(parsed.representative, input.representative);
223
+ }
224
+ if (input.supersededStatement) {
225
+ assert.strictEqual(parsed.supersededStatement, input.supersededStatement);
226
+ }
227
+ if (input.attachments) {
228
+ assert.deepStrictEqual(parsed.attachments, input.attachments);
229
+ }
230
+ if (input.translations) {
231
+ assert.deepStrictEqual(parsed.translations, input.translations);
232
+ }
233
+ });
234
+ });
235
+ }
236
+ });