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
@@ -1,58 +0,0 @@
1
- /**
2
- * Browser-compatible hash utilities using Web Crypto API
3
- * Async operations for client-side use
4
- */
5
- /**
6
- * Compute SHA-256 hash of a string and return it as URL-safe base64
7
- * Works in both browser and Node.js environments
8
- * @param input - The string or buffer to hash
9
- * @returns URL-safe base64 encoded hash
10
- */
11
- export const sha256 = async (input) => {
12
- let data;
13
- if (typeof input === 'string') {
14
- const encoder = new TextEncoder();
15
- data = encoder.encode(input);
16
- }
17
- else {
18
- data = input;
19
- }
20
- // Use Web Crypto API (available in both modern browsers and Node.js 15+)
21
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
22
- const hashArray = Array.from(new Uint8Array(hashBuffer));
23
- // Convert to base64
24
- const base64 = btoa(String.fromCharCode(...hashArray));
25
- // Make URL-safe: remove padding and replace + with - and / with _
26
- const urlSafe = base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
27
- return urlSafe;
28
- };
29
- /**
30
- * Verify that content matches a given hash
31
- * @param content - The content to verify
32
- * @param hash - The expected hash
33
- * @returns True if the hash matches
34
- */
35
- export const verify = async (content, hash) => {
36
- const computed = await sha256(content);
37
- return computed === hash;
38
- };
39
- /**
40
- * Convert URL-safe base64 back to standard base64
41
- * @param urlSafe - URL-safe base64 string
42
- * @returns Standard base64 string with padding
43
- */
44
- export const fromUrlSafeBase64 = (urlSafe) => {
45
- const base64 = urlSafe.replace(/-/g, '+').replace(/_/g, '/');
46
- // Add padding if needed
47
- const padding = '='.repeat((4 - (base64.length % 4)) % 4);
48
- return base64 + padding;
49
- };
50
- /**
51
- * Convert standard base64 to URL-safe base64
52
- * @param base64 - Standard base64 string
53
- * @returns URL-safe base64 string without padding
54
- */
55
- export const toUrlSafeBase64 = (base64) => {
56
- return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
57
- };
58
- //# sourceMappingURL=hash.browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.browser.js","sourceRoot":"","sources":["../../src/hash.browser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAA0B,EAAmB,EAAE;IACxE,IAAI,IAAgB,CAAC;IAErB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACJ,IAAI,GAAG,KAAK,CAAC;IACjB,CAAC;IAED,yEAAyE;IACzE,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IAEzD,oBAAoB;IACpB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAEvD,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;AACnB,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,OAA4B,EAAE,IAAY,EAAoB,EAAE;IACzF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,QAAQ,KAAK,IAAI,CAAC;AAC7B,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IACzD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7D,wBAAwB;IACxB,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,MAAM,GAAG,OAAO,CAAC;AAC5B,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IACtD,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5E,CAAC,CAAA"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Node.js-specific hash utilities using native crypto module
3
- * Synchronous operations for server-side use
4
- */
5
- import crypto from 'crypto';
6
- /**
7
- * Compute SHA-256 hash and return as URL-safe base64 (Node.js)
8
- * @param input - String or buffer to hash
9
- * @returns URL-safe base64 encoded hash
10
- */
11
- export declare const sha256: (input: crypto.BinaryLike) => string;
12
- /**
13
- * Verify that content matches a given hash
14
- * @param content - Content to verify
15
- * @param hash - Expected hash
16
- * @returns True if hash matches
17
- */
18
- export declare const verify: (content: crypto.BinaryLike, hash: string) => boolean;
19
- /**
20
- * Convert URL-safe base64 back to standard base64
21
- * @param urlSafe - URL-safe base64 string
22
- * @returns Standard base64 string with padding
23
- */
24
- export declare const fromUrlSafeBase64: (urlSafe: string) => string;
25
- /**
26
- * Convert standard base64 to URL-safe base64
27
- * @param base64 - Standard base64 string
28
- * @returns URL-safe base64 string without padding
29
- */
30
- export declare const toUrlSafeBase64: (base64: string) => string;
31
- //# sourceMappingURL=hash.node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.node.d.ts","sourceRoot":"","sources":["../../src/hash.node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,CAAC,UAAU,KAAG,MAIjD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,CAAC,UAAU,EAAE,MAAM,MAAM,KAAG,OAEjE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAInD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAEhD,CAAA"}
@@ -1,43 +0,0 @@
1
- /**
2
- * Node.js-specific hash utilities using native crypto module
3
- * Synchronous operations for server-side use
4
- */
5
- import crypto from 'crypto';
6
- /**
7
- * Compute SHA-256 hash and return as URL-safe base64 (Node.js)
8
- * @param input - String or buffer to hash
9
- * @returns URL-safe base64 encoded hash
10
- */
11
- export const sha256 = (input) => {
12
- const base64 = crypto.createHash('sha256').update(input).digest('base64');
13
- const urlSafe = base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
14
- return urlSafe;
15
- };
16
- /**
17
- * Verify that content matches a given hash
18
- * @param content - Content to verify
19
- * @param hash - Expected hash
20
- * @returns True if hash matches
21
- */
22
- export const verify = (content, hash) => {
23
- return hash === sha256(content);
24
- };
25
- /**
26
- * Convert URL-safe base64 back to standard base64
27
- * @param urlSafe - URL-safe base64 string
28
- * @returns Standard base64 string with padding
29
- */
30
- export const fromUrlSafeBase64 = (urlSafe) => {
31
- const base64 = urlSafe.replace(/-/g, '+').replace(/_/g, '/');
32
- const padding = '='.repeat((4 - (base64.length % 4)) % 4);
33
- return base64 + padding;
34
- };
35
- /**
36
- * Convert standard base64 to URL-safe base64
37
- * @param base64 - Standard base64 string
38
- * @returns URL-safe base64 string without padding
39
- */
40
- export const toUrlSafeBase64 = (base64) => {
41
- return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
42
- };
43
- //# sourceMappingURL=hash.node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.node.js","sourceRoot":"","sources":["../../src/hash.node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAwB,EAAU,EAAE;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACzE,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,CAAA;IAChF,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAA0B,EAAE,IAAY,EAAW,EAAE;IACxE,OAAO,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IACzD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,MAAM,GAAG,OAAO,CAAC;AAC5B,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IACtD,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5E,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=hash.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.test.d.ts","sourceRoot":"","sources":["../../src/hash.test.ts"],"names":[],"mappings":""}
@@ -1,181 +0,0 @@
1
- import { sha256, verify, fromUrlSafeBase64, toUrlSafeBase64 } from './hash.node';
2
- describe('Hash utilities', () => {
3
- describe('sha256', () => {
4
- it('should hash a simple string', () => {
5
- const input = 'hello world';
6
- const hash = sha256(input);
7
- // Verify it's URL-safe (no +, /, or =)
8
- expect(hash).not.toContain('+');
9
- expect(hash).not.toContain('/');
10
- expect(hash).not.toContain('=');
11
- // Verify consistent output
12
- const hash2 = sha256(input);
13
- expect(hash).toBe(hash2);
14
- });
15
- it('should produce correct hash for known input', () => {
16
- const input = 'hello world';
17
- const expectedHash = 'uU0nuZNNPgilLlLX2n2r-sSE7-N6U4DukIj3rOLvzek';
18
- const hash = sha256(input);
19
- expect(hash).toBe(expectedHash);
20
- });
21
- it('should handle empty string', () => {
22
- const hash = sha256('');
23
- expect(hash).toBeTruthy();
24
- expect(typeof hash).toBe('string');
25
- });
26
- it('should handle unicode characters', () => {
27
- const input = '你好世界 🌍';
28
- const hash = sha256(input);
29
- expect(hash).toBeTruthy();
30
- expect(typeof hash).toBe('string');
31
- // Verify consistency
32
- const hash2 = sha256(input);
33
- expect(hash).toBe(hash2);
34
- });
35
- it('should handle Buffer input', () => {
36
- const data = Buffer.from('hello world');
37
- const hash = sha256(data);
38
- // Should produce same hash as string input
39
- const stringHash = sha256('hello world');
40
- expect(hash).toBe(stringHash);
41
- });
42
- it('should produce different hashes for different inputs', () => {
43
- const hash1 = sha256('hello');
44
- const hash2 = sha256('world');
45
- expect(hash1).not.toBe(hash2);
46
- });
47
- it('should produce 43-character URL-safe base64 string', () => {
48
- const hash = sha256('test');
49
- // SHA-256 produces 256 bits = 32 bytes
50
- // Base64 encoding: 32 bytes * 4/3 = 42.67, rounded up = 43 chars (without padding)
51
- expect(hash.length).toBe(43);
52
- });
53
- });
54
- describe('verify', () => {
55
- it('should verify correct hash', () => {
56
- const content = 'hello world';
57
- const hash = sha256(content);
58
- const isValid = verify(content, hash);
59
- expect(isValid).toBe(true);
60
- });
61
- it('should reject incorrect hash', () => {
62
- const content = 'hello world';
63
- const wrongHash = 'incorrect_hash_value_here_1234567890';
64
- const isValid = verify(content, wrongHash);
65
- expect(isValid).toBe(false);
66
- });
67
- it('should reject hash for different content', () => {
68
- const content1 = 'hello world';
69
- const content2 = 'goodbye world';
70
- const hash1 = sha256(content1);
71
- const isValid = verify(content2, hash1);
72
- expect(isValid).toBe(false);
73
- });
74
- it('should work with Buffer', () => {
75
- const data = Buffer.from('test data');
76
- const hash = sha256(data);
77
- const isValid = verify(data, hash);
78
- expect(isValid).toBe(true);
79
- });
80
- });
81
- describe('fromUrlSafeBase64', () => {
82
- it('should convert URL-safe base64 to standard base64', () => {
83
- // Use a URL-safe string that contains both - and _ characters
84
- const urlSafe = 'abc-def_ghi';
85
- const standard = fromUrlSafeBase64(urlSafe);
86
- // Should replace - with + and _ with /
87
- expect(standard).toContain('+');
88
- expect(standard).toContain('/');
89
- // Should add padding
90
- expect(standard.endsWith('=')).toBe(true);
91
- });
92
- it('should add correct padding', () => {
93
- // Test different padding scenarios
94
- const testCases = [
95
- { input: 'abc', expectedPadding: 1 },
96
- { input: 'abcd', expectedPadding: 0 },
97
- { input: 'abcde', expectedPadding: 3 },
98
- { input: 'abcdef', expectedPadding: 2 },
99
- ];
100
- testCases.forEach(({ input, expectedPadding }) => {
101
- const result = fromUrlSafeBase64(input);
102
- const paddingCount = (result.match(/=/g) || []).length;
103
- expect(paddingCount).toBe(expectedPadding);
104
- });
105
- });
106
- it('should handle strings without special characters', () => {
107
- const input = 'abcdefghijklmnop';
108
- const result = fromUrlSafeBase64(input);
109
- expect(result).toBeTruthy();
110
- });
111
- });
112
- describe('toUrlSafeBase64', () => {
113
- it('should convert standard base64 to URL-safe', () => {
114
- const standard = 'uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=';
115
- const urlSafe = toUrlSafeBase64(standard);
116
- // Should not contain standard base64 special characters
117
- expect(urlSafe).not.toContain('+');
118
- expect(urlSafe).not.toContain('/');
119
- expect(urlSafe).not.toContain('=');
120
- // Should contain URL-safe replacements
121
- expect(urlSafe).toContain('-');
122
- });
123
- it('should remove padding', () => {
124
- const withPadding = 'abc=';
125
- const result = toUrlSafeBase64(withPadding);
126
- expect(result).not.toContain('=');
127
- expect(result).toBe('abc');
128
- });
129
- it('should be reversible with fromUrlSafeBase64', () => {
130
- // Start with a standard base64 string with special chars
131
- const original = 'test+data/with==';
132
- const urlSafe = toUrlSafeBase64(original);
133
- const restored = fromUrlSafeBase64(urlSafe);
134
- // Should restore to equivalent base64 (padding might differ slightly)
135
- expect(restored.replace(/=+$/, '')).toBe(original.replace(/=+$/, ''));
136
- });
137
- });
138
- describe('Round-trip conversions', () => {
139
- it('should maintain hash integrity through URL-safe conversion', () => {
140
- const content = 'test content for hashing';
141
- const hash = sha256(content);
142
- // Convert to standard base64 and back
143
- const standard = fromUrlSafeBase64(hash);
144
- const backToUrlSafe = toUrlSafeBase64(standard);
145
- expect(backToUrlSafe).toBe(hash);
146
- });
147
- it('should verify hash after conversion', () => {
148
- const content = 'verification test';
149
- const hash = sha256(content);
150
- // Convert and back
151
- const standard = fromUrlSafeBase64(hash);
152
- const urlSafe = toUrlSafeBase64(standard);
153
- // Should still verify
154
- const isValid = verify(content, urlSafe);
155
- expect(isValid).toBe(true);
156
- });
157
- });
158
- describe('Edge cases', () => {
159
- it('should handle very long strings', () => {
160
- const longString = 'a'.repeat(10000);
161
- const hash = sha256(longString);
162
- expect(hash).toBeTruthy();
163
- expect(hash.length).toBe(43);
164
- });
165
- it('should handle special characters', () => {
166
- const special = '!@#$%^&*()_+-=[]{}|;:,.<>?';
167
- const hash = sha256(special);
168
- expect(hash).toBeTruthy();
169
- const isValid = verify(special, hash);
170
- expect(isValid).toBe(true);
171
- });
172
- it('should handle newlines and whitespace', () => {
173
- const withNewlines = 'line1\nline2\r\nline3\ttab';
174
- const hash = sha256(withNewlines);
175
- expect(hash).toBeTruthy();
176
- const isValid = verify(withNewlines, hash);
177
- expect(isValid).toBe(true);
178
- });
179
- });
180
- });
181
- //# sourceMappingURL=hash.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.test.js","sourceRoot":"","sources":["../../src/hash.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACpB,EAAE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AU,CAAC,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;YACxC,MAAM,OAAO,GAAG,4BAA4B,CAAC;YAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;YAE1B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACtC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC7C,MAAM,YAAY,GAAG,4BAA4B,CAAC;YAClD,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;YAE1B,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAC3C,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/index.test.ts"],"names":[],"mappings":""}
@@ -1,293 +0,0 @@
1
- import { parseRating, parseStatement, parseOrganisationVerification, parsePersonVerification, parsePoll, parseQuotation, buildRating, buildStatement, buildPersonVerificationContent, buildPollContent, buildQuotationContent, buildOrganisationVerificationContent, } from './index';
2
- const randomUnicodeString = () => Array.from({ length: 20 }, () => String.fromCharCode(Math.floor(Math.random() * 65536)))
3
- .join('')
4
- .replace(/[\n;>=<"''\\]/g, '');
5
- test('parse statement', () => {
6
- const statement = `Publishing domain: localhost
7
- Author: chris
8
- Time: Tue, 18 Apr 2023 18:20:26 GMT
9
- Tags: hashtag1, hashtag2
10
- Format version: 4
11
- Statement content: hi
12
- `;
13
- const parsedStatement = parseStatement({ statement });
14
- expect(parsedStatement.content).toBe(`hi
15
- `);
16
- });
17
- test('statement build & parse function compatibility: input=parse(build(input))', () => {
18
- const [domain, author, representative, content, supersededStatement] = Array.from({ length: 5 }, randomUnicodeString);
19
- const tags = Array.from({ length: 4 }, randomUnicodeString);
20
- const contentWithTrailingNewline = content + (content.match(/\n$/) ? '' : '\n');
21
- const time = new Date('Sun, 04 Sep 2022 14:48:50 GMT');
22
- const statementContent = buildStatement({
23
- domain,
24
- author,
25
- time,
26
- content: contentWithTrailingNewline,
27
- representative,
28
- supersededStatement,
29
- tags,
30
- });
31
- const parsedStatement = parseStatement({ statement: statementContent });
32
- expect(parsedStatement.domain).toBe(domain);
33
- expect(parsedStatement.author).toBe(author);
34
- expect(parsedStatement.time?.toUTCString()).toBe(time.toUTCString());
35
- expect(parsedStatement.content).toBe(contentWithTrailingNewline);
36
- expect(parsedStatement.representative).toBe(representative);
37
- expect(parsedStatement.supersededStatement).toBe(supersededStatement);
38
- expect(parsedStatement.tags?.sort()).toStrictEqual(tags.sort());
39
- });
40
- test('parse quotation', () => {
41
- let quotation = `Publishing domain: rixdata.net
42
- Author: Example Inc.
43
- Time: Sun, 04 Sep 2022 14:48:50 GMT
44
- Format version: 4
45
- Statement content:
46
- Type: Quotation
47
- Original author: XYZ Company Inc.
48
- Author verification: eXoVsm2CdF5Ri-SEAr33RNkG3DBuehvFoDBQ_pO9CXE
49
- Original publication time: Sun, 04 Sep 2022 14:48:50 GMT
50
- Source: https://www.facebook.com/companyxzy/posts/XXXX
51
- Picture proof: 5HKiyQXGV4xavq-Nn9RXi_ndUH-2BEux3ccFIjaSk_8
52
- Confidence: 0.9
53
- Quotation: we give example.com a 2/5 star rating
54
- Paraphrased statement:
55
- Type: Rating
56
- Organisation name: example
57
- Organisation domain: example.com
58
- Our rating: 2/5 Stars
59
- `;
60
- const parsedStatement = parseStatement({ statement: quotation });
61
- const parsedQuotation = parseQuotation(parsedStatement.content);
62
- const type = parsedQuotation.type;
63
- expect(type).toBe('rating');
64
- });
65
- test('quotation build & parse function compatibility: input=parse(build(input))', () => {
66
- const [originalAuthor, source, picture, quotation, paraphrasedStatement] = Array.from({ length: 6 }, randomUnicodeString);
67
- const authorVerification = 'yXoVsm2CdF5Ri-SEAr33RNkG3DBuehvFoDBQ_pO9CXE';
68
- const originalTime = 'Sun, 04 Sep 2022 14:48:50 GMT';
69
- const confidence = '' + Math.random();
70
- const quotationContent = buildQuotationContent({
71
- originalAuthor,
72
- authorVerification,
73
- originalTime,
74
- source,
75
- picture,
76
- confidence,
77
- quotation,
78
- paraphrasedStatement,
79
- });
80
- const parsedQuotation = parseQuotation(quotationContent);
81
- expect(parsedQuotation.originalAuthor).toBe(originalAuthor);
82
- expect(parsedQuotation.originalTime).toBe(originalTime);
83
- expect(parsedQuotation.source).toBe(source);
84
- expect(parsedQuotation.picture).toBe(picture);
85
- expect(parsedQuotation.confidence).toBe(confidence);
86
- expect(parsedQuotation.quotation).toBe(quotation);
87
- expect(parsedQuotation.paraphrasedStatement?.replace(/\n$/, '')).toBe(paraphrasedStatement);
88
- expect(parsedQuotation.authorVerification).toBe(authorVerification);
89
- });
90
- test('parse organisation verification', () => {
91
- let organisationVerification = `Publishing domain: rixdata.net
92
- Author: Example Inc.
93
- Time: Sun, 04 Sep 2022 14:48:50 GMT
94
- Format version: 4
95
- Statement content:
96
- Type: Organisation verification
97
- Description: We verified the following information about an organisation.
98
- Name: Walmart Inc.
99
- Country: United States of America
100
- Legal entity: corporation
101
- Owner of the domain: walmart.com
102
- Province or state: Arkansas
103
- City: Bentonville
104
- `;
105
- const parsedStatement = parseStatement({
106
- statement: organisationVerification,
107
- });
108
- const parsedOVerification = parseOrganisationVerification(parsedStatement.content);
109
- const name = parsedOVerification.name;
110
- expect(name).toBe('Walmart Inc.');
111
- });
112
- test('organisation verification build & parse function compatibility: input=parse(build(input))', () => {
113
- const [name, englishName, city, domain, foreignDomain, serialNumber, reliabilityPolicy, pictureHash,] = Array.from({ length: 8 }, randomUnicodeString);
114
- const country = 'Germany';
115
- const province = 'Bayern';
116
- const legalForm = 'corporation';
117
- const employeeCount = '100-1000';
118
- const confidence = 0.8;
119
- const verificationContent = buildOrganisationVerificationContent({
120
- name,
121
- englishName,
122
- country,
123
- city,
124
- province,
125
- legalForm,
126
- domain,
127
- pictureHash,
128
- foreignDomain,
129
- serialNumber,
130
- confidence,
131
- reliabilityPolicy,
132
- employeeCount,
133
- });
134
- const parsedVerification = parseOrganisationVerification(verificationContent);
135
- expect(parsedVerification.name).toBe(name);
136
- expect(parsedVerification.englishName).toBe(englishName);
137
- expect(parsedVerification.country).toBe(country);
138
- expect(parsedVerification.city).toBe(city);
139
- expect(parsedVerification.province).toBe(province);
140
- expect(parsedVerification.legalForm).toBe(legalForm);
141
- expect(parsedVerification.domain).toBe(domain);
142
- expect(parsedVerification.foreignDomain).toBe(foreignDomain);
143
- expect(parsedVerification.serialNumber).toBe(serialNumber);
144
- expect(parsedVerification.confidence).toBe(confidence);
145
- expect(parsedVerification.pictureHash).toBe(pictureHash);
146
- expect(parsedVerification.reliabilityPolicy).toBe(reliabilityPolicy);
147
- expect(parsedVerification.employeeCount).toBe(employeeCount);
148
- });
149
- test('parse person verification', () => {
150
- let personVerification = `Publishing domain: rixdata.net
151
- Author: Example Inc.
152
- Time: Sun, 04 Sep 2022 14:48:50 GMT
153
- Format version: 4
154
- Statement content:
155
- Type: Person verification
156
- Description: We verified the following information about a person.
157
- Name: Barack Hossein Obama II
158
- Date of birth: 4 Aug 1961
159
- City of birth: Honolulu
160
- Country of birth: United States of America
161
- Owner of the domain: barackobama.com
162
- `;
163
- const parsedStatement = parseStatement({ statement: personVerification });
164
- const parsedPVerification = parsePersonVerification(parsedStatement.content);
165
- const name = parsedPVerification.name;
166
- expect(name).toBe('Barack Hossein Obama II');
167
- });
168
- test('person verification build & parse function compatibility: input=parse(build(input))', () => {
169
- const [name, ownDomain, foreignDomain, jobTitle, employer, verificationMethod, picture, reliabilityPolicy,] = Array.from({ length: 12 }, randomUnicodeString);
170
- const countryOfBirth = 'Germany';
171
- const cityOfBirth = 'Berlin';
172
- const confidence = Math.random();
173
- const dateOfBirth = new Date(0);
174
- const personVerificationContent = buildPersonVerificationContent({
175
- name,
176
- countryOfBirth,
177
- cityOfBirth,
178
- ownDomain,
179
- foreignDomain,
180
- dateOfBirth,
181
- jobTitle,
182
- employer,
183
- verificationMethod,
184
- confidence,
185
- picture,
186
- reliabilityPolicy,
187
- });
188
- const parsedVerification = parsePersonVerification(personVerificationContent);
189
- expect(parsedVerification.name).toBe(name);
190
- expect(parsedVerification.ownDomain).toBe(ownDomain);
191
- expect(parsedVerification.foreignDomain).toBe(foreignDomain);
192
- expect(parsedVerification.dateOfBirth.toUTCString()).toBe(dateOfBirth.toUTCString());
193
- expect(parsedVerification.jobTitle).toBe(jobTitle);
194
- expect(parsedVerification.employer).toBe(employer);
195
- expect(parsedVerification.verificationMethod).toBe(verificationMethod);
196
- expect(parsedVerification.confidence).toBe(confidence);
197
- expect(parsedVerification.picture).toBe(picture);
198
- expect(parsedVerification.reliabilityPolicy).toBe(reliabilityPolicy);
199
- expect(parsedVerification.countryOfBirth).toBe(countryOfBirth);
200
- expect(parsedVerification.cityOfBirth).toBe(cityOfBirth);
201
- });
202
- test('parse rating', () => {
203
- let rating = `Publishing domain: localhost
204
- Author: chris
205
- Time: Tue, 18 Apr 2023 18:20:26 GMT
206
- Format version: 4
207
- Statement content:
208
- Type: Rating
209
- Subject name: AMBOSS GmbH
210
- URL that identifies the subject: amboss.com
211
- Rated quality: AI safety
212
- Our rating: 5/5 Stars
213
- `;
214
- const parsedStatement = parseStatement({ statement: rating });
215
- const parsedRating = parseRating(parsedStatement.content);
216
- const ratingNumber = parsedRating.rating;
217
- expect(ratingNumber).toBe(5);
218
- const subjectName = parsedRating.subjectName;
219
- expect(subjectName).toBe('AMBOSS GmbH');
220
- const subjectReference = parsedRating.subjectReference;
221
- expect(subjectReference).toBe('amboss.com');
222
- const quality = parsedRating.quality;
223
- expect(quality).toBe('AI safety');
224
- });
225
- test('rating build & parse function compatibility: input=parse(build(input))', () => {
226
- const [subjectName, subjectReference, comment, quality] = Array.from({ length: 4 }, randomUnicodeString);
227
- const rating = Math.ceil(Math.random() * 5);
228
- const ratingContent = buildRating({ subjectName, subjectReference, rating, comment, quality });
229
- const parsedRating = parseRating(ratingContent);
230
- expect(parsedRating.subjectName).toBe(subjectName);
231
- expect(parsedRating.subjectReference).toBe(subjectReference);
232
- expect(parsedRating.quality).toBe(quality);
233
- expect(parsedRating.rating).toBe(rating);
234
- expect(parsedRating.comment).toBe(comment);
235
- });
236
- test('parse poll v4', () => {
237
- let poll = `Publishing domain: rixdata.net
238
- Author: Example Inc.
239
- Time: Thu, 17 Nov 2022 13:38:20 GMT
240
- Format version: 4
241
- Statement content:
242
- Type: Poll
243
- The poll outcome is finalized when the following nodes agree: rixdata.net
244
- Voting deadline: Thu, 01 Dec 2022 13:38:26 GMT
245
- Poll: Should the UK join the EU
246
- Option 1: Yes
247
- Option 2: No
248
- Who can vote:
249
- Description: All universities with a ROR ID
250
- Legal form scope: corporation
251
- All entities with the following property: ROR ID
252
- As observed by: Rix Data NL B.V.@rixdata.net
253
- Link to query defining who can vote: https://stated.rixdata.net/?search_query=%09Observed%20property:%20ROR%20ID%0A%09&domain=rixdata.net&author=Rix%20Data%20NL%20B.V.
254
- `;
255
- const parsedStatement = parseStatement({ statement: poll });
256
- const parsedPoll = parsePoll(parsedStatement.content);
257
- const pollTitle = parsedPoll.poll;
258
- expect(pollTitle).toBe('Should the UK join the EU');
259
- expect(parsedPoll.options[0]).toBe('Yes');
260
- expect(parsedPoll.options[1]).toBe('No');
261
- expect(parsedPoll.deadline?.toUTCString()).toBe('Thu, 01 Dec 2022 13:38:26 GMT');
262
- expect(parsedPoll.scopeDescription).toBe('All universities with a ROR ID');
263
- expect(parsedPoll.legalEntity).toBe('corporation');
264
- expect(parsedPoll.requiredProperty).toBe('ROR ID');
265
- expect(parsedPoll.requiredPropertyObserver).toBe('Rix Data NL B.V.@rixdata.net');
266
- expect(parsedPoll.scopeQueryLink).toBe('https://stated.rixdata.net/?search_query=%09Observed%20property:%20ROR%20ID%0A%09&domain=rixdata.net&author=Rix%20Data%20NL%20B.V.');
267
- });
268
- test('poll build & parse function compatibility: input=parse(build(input))', () => {
269
- const [country, city, legalEntity, judges, poll, scopeDescription] = Array.from({ length: 6 }, randomUnicodeString);
270
- const options = Array.from({ length: 2 }, randomUnicodeString);
271
- const domainScope = ['rixdata.net'];
272
- const deadline = new Date('Thu, 01 Dec 2022 13:38:26 GMT');
273
- const pollContent = buildPollContent({
274
- country,
275
- city,
276
- legalEntity,
277
- domainScope,
278
- judges,
279
- deadline,
280
- poll,
281
- options,
282
- scopeDescription,
283
- });
284
- const parsedPoll = parsePoll(pollContent);
285
- expect(parsedPoll.poll).toBe(poll);
286
- expect(parsedPoll.country).toBe(country);
287
- expect(parsedPoll.legalEntity).toBe(legalEntity);
288
- expect(parsedPoll.judges).toBe(judges);
289
- expect(parsedPoll.deadline?.toUTCString()).toBe(deadline.toUTCString());
290
- expect(parsedPoll.options[0]).toEqual(options[0]);
291
- expect(parsedPoll.options[1]).toEqual(options[1]);
292
- });
293
- //# sourceMappingURL=index.test.js.map