stated-protocol 5.2.1 → 5.3.1
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/dist/fixtures.test.d.ts +2 -0
- package/dist/fixtures.test.d.ts.map +1 -0
- package/dist/fixtures.test.js +207 -0
- package/dist/fixtures.test.js.map +1 -0
- package/dist/hash.js +2 -2
- package/dist/hash.js.map +1 -1
- package/dist/hash.test.d.ts +2 -0
- package/dist/hash.test.d.ts.map +1 -0
- package/dist/hash.test.js +183 -0
- package/dist/hash.test.js.map +1 -0
- package/dist/observation.test.d.ts +2 -0
- package/dist/observation.test.d.ts.map +1 -0
- package/dist/observation.test.js +101 -0
- package/dist/observation.test.js.map +1 -0
- package/dist/organisation-verification.test.d.ts +2 -0
- package/dist/organisation-verification.test.d.ts.map +1 -0
- package/dist/organisation-verification.test.js +44 -0
- package/dist/organisation-verification.test.js.map +1 -0
- package/dist/person-verification.test.d.ts +2 -0
- package/dist/person-verification.test.d.ts.map +1 -0
- package/dist/person-verification.test.js +41 -0
- package/dist/person-verification.test.js.map +1 -0
- package/dist/poll.test.d.ts +2 -0
- package/dist/poll.test.d.ts.map +1 -0
- package/dist/poll.test.js +26 -0
- package/dist/poll.test.js.map +1 -0
- package/dist/protocol.d.ts +3 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +53 -8
- package/dist/protocol.js.map +1 -1
- package/dist/rating.test.d.ts +2 -0
- package/dist/rating.test.d.ts.map +1 -0
- package/dist/rating.test.js +24 -0
- package/dist/rating.test.js.map +1 -0
- package/dist/signature.js +2 -2
- package/dist/signature.js.map +1 -1
- package/dist/signature.test.d.ts +2 -0
- package/dist/signature.test.d.ts.map +1 -0
- package/dist/signature.test.js +165 -0
- package/dist/signature.test.js.map +1 -0
- package/dist/statement.test.d.ts +2 -0
- package/dist/statement.test.d.ts.map +1 -0
- package/dist/statement.test.js +90 -0
- package/dist/statement.test.js.map +1 -0
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +106 -0
- package/dist/utils.test.js.map +1 -0
- package/package.json +1 -1
- package/src/fixtures.test.ts +8 -1
- package/src/hash.ts +2 -2
- package/src/observation.test.ts +128 -0
- package/src/poll.test.ts +1 -1
- package/src/protocol.ts +56 -8
- package/src/rating.test.ts +5 -1
- package/src/signature.ts +2 -2
- package/src/types.ts +9 -2
- package/src/utils.test.ts +5 -10
- package/src/utils.ts +2 -10
package/src/rating.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
3
|
import { parseRating, buildRating } from './protocol';
|
|
4
|
+
import { isRatingValue } from './types';
|
|
4
5
|
|
|
5
6
|
const randomUnicodeString = () =>
|
|
6
7
|
Array.from({ length: 20 }, () => String.fromCharCode(Math.floor(Math.random() * 65536)))
|
|
@@ -13,7 +14,10 @@ describe('Rating building', () => {
|
|
|
13
14
|
{ length: 4 },
|
|
14
15
|
randomUnicodeString
|
|
15
16
|
);
|
|
16
|
-
const rating = Math.
|
|
17
|
+
const rating = Math.floor(Math.random() * 5) + 1;
|
|
18
|
+
if (!isRatingValue(rating)) {
|
|
19
|
+
throw new Error(`Generated invalid rating: ${rating}`);
|
|
20
|
+
}
|
|
17
21
|
const ratingContent = buildRating({ subjectName, subjectReference, rating, comment, quality });
|
|
18
22
|
const parsedRating = parseRating(ratingContent);
|
|
19
23
|
assert.strictEqual(parsedRating.subjectName, subjectName);
|
package/src/signature.ts
CHANGED
|
@@ -150,9 +150,9 @@ export const verifySignedStatement = async (signedStatement: string): Promise<bo
|
|
|
150
150
|
* @returns Base64 string
|
|
151
151
|
*/
|
|
152
152
|
function bytesToBase64(bytes: Uint8Array): string {
|
|
153
|
-
// Use btoa if available (browser), otherwise use Buffer (Node.js)
|
|
154
153
|
if (typeof btoa !== 'undefined') {
|
|
155
|
-
|
|
154
|
+
const binaryString = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
|
|
155
|
+
return btoa(binaryString);
|
|
156
156
|
} else {
|
|
157
157
|
return Buffer.from(bytes).toString('base64');
|
|
158
158
|
}
|
package/src/types.ts
CHANGED
|
@@ -55,7 +55,8 @@ export type StatementTypeValue =
|
|
|
55
55
|
| 'dispute_statement_content'
|
|
56
56
|
| 'dispute_statement_authenticity'
|
|
57
57
|
| 'rating'
|
|
58
|
-
| 'sign_pdf'
|
|
58
|
+
| 'sign_pdf'
|
|
59
|
+
| 'observation';
|
|
59
60
|
|
|
60
61
|
export type Statement = {
|
|
61
62
|
domain: string;
|
|
@@ -152,7 +153,7 @@ export type ResponseContent = {
|
|
|
152
153
|
response: string;
|
|
153
154
|
};
|
|
154
155
|
|
|
155
|
-
export type PDFSigning =
|
|
156
|
+
export type PDFSigning = Record<string, never>;
|
|
156
157
|
|
|
157
158
|
export type RatingSubjectTypeValue =
|
|
158
159
|
| 'Organisation'
|
|
@@ -181,3 +182,9 @@ export type Bounty = {
|
|
|
181
182
|
judge: string;
|
|
182
183
|
judgePay?: string;
|
|
183
184
|
};
|
|
185
|
+
|
|
186
|
+
export type Observation = {
|
|
187
|
+
subject: string;
|
|
188
|
+
property: string;
|
|
189
|
+
value: string;
|
|
190
|
+
};
|
package/src/utils.test.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
generateStatementHash,
|
|
10
10
|
validateStatementHash,
|
|
11
11
|
generateStatementsFile,
|
|
12
|
-
|
|
12
|
+
splitStatements,
|
|
13
13
|
generateStatementFilename,
|
|
14
14
|
generateAttachmentFilename,
|
|
15
15
|
} from './utils';
|
|
@@ -118,22 +118,17 @@ describe('Statement Utils', () => {
|
|
|
118
118
|
assert.ok(statementsFile.includes('\n\n'));
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
it('should
|
|
121
|
+
it('should split statements file', () => {
|
|
122
122
|
const statementsFile = generateStatementsFile([statement1, statement2]);
|
|
123
|
-
const parsed =
|
|
123
|
+
const parsed = splitStatements(statementsFile);
|
|
124
124
|
assert.strictEqual(parsed.length, 2);
|
|
125
125
|
assert.strictEqual(parsed[0], statement1);
|
|
126
126
|
assert.strictEqual(parsed[1], statement2);
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
it('should
|
|
130
|
-
const invalidFile = 'Invalid statement\n\nAnother invalid statement';
|
|
131
|
-
assert.throws(() => parseStatementsFile(invalidFile));
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should filter empty statements', () => {
|
|
129
|
+
it('should filter empty statements when splitting', () => {
|
|
135
130
|
const fileWithEmpty = statement1 + '\n\n\n\n' + statement2;
|
|
136
|
-
const parsed =
|
|
131
|
+
const parsed = splitStatements(fileWithEmpty);
|
|
137
132
|
assert.strictEqual(parsed.length, 2);
|
|
138
133
|
});
|
|
139
134
|
});
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { peopleCountBuckets } from './constants';
|
|
2
2
|
|
|
3
3
|
import { sha256, verify } from './hash';
|
|
4
|
-
import { parseStatement } from './protocol';
|
|
5
4
|
|
|
6
5
|
export const generateFileHash = (fileContent: Buffer | string): string => {
|
|
7
6
|
return sha256(fileContent);
|
|
@@ -42,7 +41,7 @@ export const generateStatementsFile = (statements: string[]): string => {
|
|
|
42
41
|
return statements.join('\n\n');
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
export const
|
|
44
|
+
export const splitStatements = (statementsFileContent: string): string[] => {
|
|
46
45
|
const statementParts = statementsFileContent.split(/\n\nStated protocol version: /);
|
|
47
46
|
const statements: string[] = [];
|
|
48
47
|
|
|
@@ -57,14 +56,7 @@ export const parseStatementsFile = (statementsFileContent: string): string[] =>
|
|
|
57
56
|
|
|
58
57
|
statement = statement.replace(/\n+$/, '\n');
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
parseStatement({ statement });
|
|
62
|
-
statements.push(statement);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Invalid statement at index ${i}: ${error instanceof Error ? error.message : String(error)}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
59
|
+
statements.push(statement);
|
|
68
60
|
}
|
|
69
61
|
|
|
70
62
|
return statements;
|