stated-protocol-parser 1.0.7 → 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 (129) 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 +18 -30
  15. package/dist/esm/protocol.d.ts.map +1 -1
  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 +18 -30
  31. package/dist/protocol.d.ts.map +1 -1
  32. package/dist/protocol.js +565 -572
  33. package/dist/protocol.js.map +1 -1
  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 +32 -27
  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 -0
  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 +855 -650
  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.browser.d.ts +0 -3
  77. package/dist/esm/index.browser.d.ts.map +0 -1
  78. package/dist/esm/index.browser.js +0 -5
  79. package/dist/esm/index.browser.js.map +0 -1
  80. package/dist/esm/index.node.d.ts +0 -3
  81. package/dist/esm/index.node.d.ts.map +0 -1
  82. package/dist/esm/index.node.js +0 -5
  83. package/dist/esm/index.node.js.map +0 -1
  84. package/dist/esm/index.test.d.ts +0 -2
  85. package/dist/esm/index.test.d.ts.map +0 -1
  86. package/dist/esm/index.test.js +0 -293
  87. package/dist/esm/index.test.js.map +0 -1
  88. package/dist/esm/protocol.js +0 -639
  89. package/dist/esm/protocol.js.map +0 -1
  90. package/dist/esm/types.js +0 -2
  91. package/dist/esm/types.js.map +0 -1
  92. package/dist/esm/utils.js +0 -23
  93. package/dist/esm/utils.js.map +0 -1
  94. package/dist/esm/v3.d.ts +0 -5
  95. package/dist/esm/v3.d.ts.map +0 -1
  96. package/dist/esm/v3.js +0 -60
  97. package/dist/esm/v3.js.map +0 -1
  98. package/dist/hash.browser.d.ts.map +0 -1
  99. package/dist/hash.browser.js.map +0 -1
  100. package/dist/hash.node.d.ts +0 -31
  101. package/dist/hash.node.d.ts.map +0 -1
  102. package/dist/hash.node.js +0 -53
  103. package/dist/hash.node.js.map +0 -1
  104. package/dist/hash.test.d.ts +0 -2
  105. package/dist/hash.test.d.ts.map +0 -1
  106. package/dist/hash.test.js +0 -183
  107. package/dist/hash.test.js.map +0 -1
  108. package/dist/index.browser.d.ts +0 -3
  109. package/dist/index.browser.d.ts.map +0 -1
  110. package/dist/index.browser.js +0 -21
  111. package/dist/index.browser.js.map +0 -1
  112. package/dist/index.node.d.ts +0 -3
  113. package/dist/index.node.d.ts.map +0 -1
  114. package/dist/index.node.js +0 -21
  115. package/dist/index.node.js.map +0 -1
  116. package/dist/index.test.d.ts +0 -2
  117. package/dist/index.test.d.ts.map +0 -1
  118. package/dist/index.test.js +0 -295
  119. package/dist/index.test.js.map +0 -1
  120. package/dist/v3.d.ts +0 -5
  121. package/dist/v3.d.ts.map +0 -1
  122. package/dist/v3.js +0 -64
  123. package/dist/v3.js.map +0 -1
  124. package/src/hash.browser.ts +0 -65
  125. package/src/hash.node.ts +0 -47
  126. package/src/index.browser.ts +0 -4
  127. package/src/index.node.ts +0 -4
  128. package/src/index.test.ts +0 -378
  129. package/src/v3.ts +0 -62
package/dist/utils.js CHANGED
@@ -1,28 +1,96 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.birthDateFormat = exports.monthIndex = exports.minPeopleCountToRange = void 0;
3
+ exports.birthDateFormat = exports.monthIndex = exports.minPeopleCountToRange = exports.generateAttachmentFilename = exports.generateStatementFilename = exports.parseStatementsFile = exports.generateStatementsFile = exports.validateStatementHash = exports.generateStatementHash = exports.validateStatementContentHash = exports.generateStatementContentHash = exports.validateFileHash = exports.generateFileHash = void 0;
4
4
  const constants_1 = require("./constants");
5
+ const hash_1 = require("./hash");
6
+ const protocol_1 = require("./protocol");
7
+ const generateFileHash = (fileContent) => {
8
+ return (0, hash_1.sha256)(fileContent);
9
+ };
10
+ exports.generateFileHash = generateFileHash;
11
+ const validateFileHash = (fileContent, expectedHash) => {
12
+ return (0, hash_1.verify)(fileContent, expectedHash);
13
+ };
14
+ exports.validateFileHash = validateFileHash;
15
+ const generateStatementContentHash = (statementContent) => {
16
+ return (0, hash_1.sha256)(statementContent);
17
+ };
18
+ exports.generateStatementContentHash = generateStatementContentHash;
19
+ const validateStatementContentHash = (statementContent, expectedHash) => {
20
+ return (0, hash_1.verify)(statementContent, expectedHash);
21
+ };
22
+ exports.validateStatementContentHash = validateStatementContentHash;
23
+ const generateStatementHash = (statement) => {
24
+ const signatureRegex = /^([\s\S]+?)---\n[\s\S]+$/;
25
+ const match = statement.match(signatureRegex);
26
+ if (match && match[1]) {
27
+ return (0, hash_1.sha256)(match[1]);
28
+ }
29
+ return (0, hash_1.sha256)(statement);
30
+ };
31
+ exports.generateStatementHash = generateStatementHash;
32
+ const validateStatementHash = (statement, expectedHash) => {
33
+ const computedHash = (0, exports.generateStatementHash)(statement);
34
+ return computedHash === expectedHash;
35
+ };
36
+ exports.validateStatementHash = validateStatementHash;
37
+ const generateStatementsFile = (statements) => {
38
+ return statements.join('\n\n');
39
+ };
40
+ exports.generateStatementsFile = generateStatementsFile;
41
+ const parseStatementsFile = (statementsFileContent) => {
42
+ const statementParts = statementsFileContent.split(/\n\nStated protocol version: /);
43
+ const statements = [];
44
+ for (let i = 0; i < statementParts.length; i++) {
45
+ let statement = statementParts[i];
46
+ if (i === 0 && statement.trim().length === 0)
47
+ continue;
48
+ if (i > 0) {
49
+ statement = 'Stated protocol version: ' + statement;
50
+ }
51
+ statement = statement.replace(/\n+$/, '\n');
52
+ try {
53
+ (0, protocol_1.parseStatement)({ statement });
54
+ statements.push(statement);
55
+ }
56
+ catch (error) {
57
+ throw new Error(`Invalid statement at index ${i}: ${error instanceof Error ? error.message : String(error)}`);
58
+ }
59
+ }
60
+ return statements;
61
+ };
62
+ exports.parseStatementsFile = parseStatementsFile;
63
+ const generateStatementFilename = (statement) => {
64
+ const hash = (0, exports.generateStatementHash)(statement);
65
+ return `${hash}.txt`;
66
+ };
67
+ exports.generateStatementFilename = generateStatementFilename;
68
+ const generateAttachmentFilename = (fileContent, extension) => {
69
+ const hash = (0, exports.generateFileHash)(fileContent);
70
+ const ext = extension.startsWith('.') ? extension.substring(1) : extension;
71
+ return `${hash}.${ext}`;
72
+ };
73
+ exports.generateAttachmentFilename = generateAttachmentFilename;
5
74
  const minPeopleCountToRange = (n) => {
6
75
  if (n >= 10000000)
7
- return constants_1.peopleCountBuckets["10000000"];
76
+ return constants_1.peopleCountBuckets['10000000'];
8
77
  if (n >= 1000000)
9
- return constants_1.peopleCountBuckets["1000000"];
78
+ return constants_1.peopleCountBuckets['1000000'];
10
79
  if (n >= 100000)
11
- return constants_1.peopleCountBuckets["100000"];
80
+ return constants_1.peopleCountBuckets['100000'];
12
81
  if (n >= 10000)
13
- return constants_1.peopleCountBuckets["10000"];
82
+ return constants_1.peopleCountBuckets['10000'];
14
83
  if (n >= 1000)
15
- return constants_1.peopleCountBuckets["1000"];
84
+ return constants_1.peopleCountBuckets['1000'];
16
85
  if (n >= 100)
17
- return constants_1.peopleCountBuckets["100"];
86
+ return constants_1.peopleCountBuckets['100'];
18
87
  if (n >= 10)
19
- return constants_1.peopleCountBuckets["10"];
88
+ return constants_1.peopleCountBuckets['10'];
20
89
  if (n >= 0)
21
- return constants_1.peopleCountBuckets["0"];
90
+ return constants_1.peopleCountBuckets['0'];
22
91
  };
23
92
  exports.minPeopleCountToRange = minPeopleCountToRange;
24
- const monthIndex = (month) => ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
25
- .indexOf(month.toLowerCase().substr(0, 3));
93
+ const monthIndex = (month) => ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'].indexOf(month.toLowerCase().substr(0, 3));
26
94
  exports.monthIndex = monthIndex;
27
95
  exports.birthDateFormat = /(?<d>\d{1,2})\s(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?<y>\d{4})/;
28
96
  //# sourceMappingURL=utils.js.map
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,8BAAkB,CAAC,IAAI,CAAC,CAAA;IAC5C,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,8BAAkB,CAAC,GAAG,CAAC,CAAA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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,34 +1,32 @@
1
1
  {
2
2
  "name": "stated-protocol-parser",
3
- "version": "1.0.7",
3
+ "version": "5.0.0",
4
4
  "description": "Parser and formatter for the Stated protocol - a decentralized statement verification system",
5
- "main": "dist/index.node.js",
6
- "module": "dist/esm/index.browser.js",
7
- "types": "dist/index.browser.d.ts",
5
+ "main": "dist/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.browser.d.ts",
11
- "browser": "./dist/esm/index.browser.js",
12
- "import": "./dist/esm/index.browser.js",
13
- "require": "./dist/index.browser.js",
14
- "default": "./dist/index.browser.js"
15
- },
16
- "./node": {
17
- "types": "./dist/index.node.d.ts",
18
- "import": "./dist/esm/index.node.js",
19
- "require": "./dist/index.node.js"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/esm/index.js",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
20
14
  }
21
15
  },
22
- "browser": {
23
- "./dist/esm/index.node.js": "./dist/esm/index.browser.js",
24
- "./dist/index.node.js": "./dist/index.browser.js"
25
- },
26
16
  "scripts": {
27
- "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",
28
19
  "build:cjs": "tsc",
29
- "build:esm": "tsc -p tsconfig.esm.json",
30
- "test": "jest",
31
- "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"
32
30
  },
33
31
  "keywords": [
34
32
  "stated",
@@ -42,10 +40,13 @@
42
40
  "author": "",
43
41
  "license": "MIT",
44
42
  "devDependencies": {
45
- "@types/jest": "^29.5.0",
46
- "@types/node": "^20.0.0",
47
- "jest": "^29.5.0",
48
- "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",
49
50
  "typescript": "^5.0.0"
50
51
  },
51
52
  "files": [
@@ -57,5 +58,9 @@
57
58
  "repository": {
58
59
  "type": "git",
59
60
  "url": "https://github.com/c-riq/stated"
61
+ },
62
+ "dependencies": {
63
+ "@noble/ed25519": "^3.0.0",
64
+ "@noble/hashes": "^2.0.1"
60
65
  }
61
- }
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: )/;