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.
- package/README.md +231 -22
- package/dist/constants.d.ts +193 -15
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +197 -20
- package/dist/constants.js.map +1 -1
- package/dist/esm/constants.d.ts +193 -15
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/{hash.browser.d.ts → hash.d.ts} +11 -5
- package/dist/esm/hash.d.ts.map +1 -0
- package/dist/esm/index.d.ts +4 -42
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2102 -641
- package/dist/esm/index.js.map +7 -1
- package/dist/esm/protocol.d.ts +30 -0
- package/dist/esm/protocol.d.ts.map +1 -0
- package/dist/esm/signature.d.ts +49 -0
- package/dist/esm/signature.d.ts.map +1 -0
- package/dist/esm/types.d.ts +26 -60
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utils.d.ts +10 -0
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/{hash.browser.d.ts → hash.d.ts} +11 -5
- package/dist/hash.d.ts.map +1 -0
- package/dist/{hash.browser.js → hash.js} +44 -10
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +4 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -674
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +30 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +677 -0
- package/dist/protocol.js.map +1 -0
- package/dist/signature.d.ts +49 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +169 -0
- package/dist/signature.js.map +1 -0
- package/dist/types.d.ts +26 -60
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +27 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +79 -11
- package/dist/utils.js.map +1 -1
- package/package.json +25 -16
- package/src/constants.ts +228 -44
- package/src/fixtures.test.ts +236 -0
- package/src/hash.test.ts +217 -215
- package/src/hash.ts +99 -0
- package/src/index.ts +5 -678
- package/src/organisation-verification.test.ts +50 -0
- package/src/person-verification.test.ts +55 -0
- package/src/poll.test.ts +28 -0
- package/src/protocol.ts +871 -0
- package/src/rating.test.ts +25 -0
- package/src/signature.test.ts +200 -0
- package/src/signature.ts +159 -0
- package/src/statement.test.ts +101 -0
- package/src/types.ts +155 -156
- package/src/utils.test.ts +140 -0
- package/src/utils.ts +102 -16
- package/dist/esm/constants.js +0 -47
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/hash.browser.d.ts.map +0 -1
- package/dist/esm/hash.browser.js +0 -58
- package/dist/esm/hash.browser.js.map +0 -1
- package/dist/esm/hash.node.d.ts +0 -31
- package/dist/esm/hash.node.d.ts.map +0 -1
- package/dist/esm/hash.node.js +0 -43
- package/dist/esm/hash.node.js.map +0 -1
- package/dist/esm/hash.test.d.ts +0 -2
- package/dist/esm/hash.test.d.ts.map +0 -1
- package/dist/esm/hash.test.js +0 -181
- package/dist/esm/hash.test.js.map +0 -1
- package/dist/esm/index.test.d.ts +0 -2
- package/dist/esm/index.test.d.ts.map +0 -1
- package/dist/esm/index.test.js +0 -293
- package/dist/esm/index.test.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils.js +0 -23
- package/dist/esm/utils.js.map +0 -1
- package/dist/esm/v3.d.ts +0 -5
- package/dist/esm/v3.d.ts.map +0 -1
- package/dist/esm/v3.js +0 -60
- package/dist/esm/v3.js.map +0 -1
- package/dist/hash.browser.d.ts.map +0 -1
- package/dist/hash.browser.js.map +0 -1
- package/dist/hash.node.d.ts +0 -31
- package/dist/hash.node.d.ts.map +0 -1
- package/dist/hash.node.js +0 -53
- package/dist/hash.node.js.map +0 -1
- package/dist/hash.test.d.ts +0 -2
- package/dist/hash.test.d.ts.map +0 -1
- package/dist/hash.test.js +0 -183
- package/dist/hash.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -295
- package/dist/index.test.js.map +0 -1
- package/dist/v3.d.ts +0 -5
- package/dist/v3.d.ts.map +0 -1
- package/dist/v3.js +0 -64
- package/dist/v3.js.map +0 -1
- package/src/hash.browser.ts +0 -65
- package/src/hash.node.ts +0 -47
- package/src/index.test.ts +0 -378
- package/src/v3.ts +0 -62
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { parseOrganisationVerification, buildOrganisationVerificationContent } from './protocol';
|
|
4
|
+
|
|
5
|
+
const randomUnicodeString = () =>
|
|
6
|
+
Array.from({ length: 20 }, () => String.fromCharCode(Math.floor(Math.random() * 65536)))
|
|
7
|
+
.join('')
|
|
8
|
+
.replace(/[\n;>=<"''\\]/g, '');
|
|
9
|
+
|
|
10
|
+
describe('Organisation verification building', () => {
|
|
11
|
+
it('build & parse function compatibility: input=parse(build(input))', () => {
|
|
12
|
+
const [name, englishName, city, domain, foreignDomain, serialNumber, reliabilityPolicy] =
|
|
13
|
+
Array.from({ length: 7 }, randomUnicodeString);
|
|
14
|
+
const pictureHash = 'abc123_-XYZ.png';
|
|
15
|
+
const country = 'Germany';
|
|
16
|
+
const province = 'Bayern';
|
|
17
|
+
const legalForm = 'corporation';
|
|
18
|
+
const employeeCount = '100-1000';
|
|
19
|
+
const confidence = 0.8;
|
|
20
|
+
const verificationContent = buildOrganisationVerificationContent({
|
|
21
|
+
name,
|
|
22
|
+
englishName,
|
|
23
|
+
country,
|
|
24
|
+
city,
|
|
25
|
+
province,
|
|
26
|
+
legalForm,
|
|
27
|
+
domain,
|
|
28
|
+
pictureHash,
|
|
29
|
+
foreignDomain,
|
|
30
|
+
serialNumber,
|
|
31
|
+
confidence,
|
|
32
|
+
reliabilityPolicy,
|
|
33
|
+
employeeCount,
|
|
34
|
+
});
|
|
35
|
+
const parsedVerification = parseOrganisationVerification(verificationContent);
|
|
36
|
+
assert.strictEqual(parsedVerification.name, name);
|
|
37
|
+
assert.strictEqual(parsedVerification.englishName, englishName);
|
|
38
|
+
assert.strictEqual(parsedVerification.country, country);
|
|
39
|
+
assert.strictEqual(parsedVerification.city, city);
|
|
40
|
+
assert.strictEqual(parsedVerification.province, province);
|
|
41
|
+
assert.strictEqual(parsedVerification.legalForm, legalForm);
|
|
42
|
+
assert.strictEqual(parsedVerification.domain, domain);
|
|
43
|
+
assert.strictEqual(parsedVerification.foreignDomain, foreignDomain);
|
|
44
|
+
assert.strictEqual(parsedVerification.serialNumber, serialNumber);
|
|
45
|
+
assert.strictEqual(parsedVerification.confidence, confidence);
|
|
46
|
+
assert.strictEqual(parsedVerification.pictureHash, pictureHash);
|
|
47
|
+
assert.strictEqual(parsedVerification.reliabilityPolicy, reliabilityPolicy);
|
|
48
|
+
assert.strictEqual(parsedVerification.employeeCount, employeeCount);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { parsePersonVerification, buildPersonVerificationContent } from './protocol';
|
|
4
|
+
|
|
5
|
+
const randomUnicodeString = () =>
|
|
6
|
+
Array.from({ length: 20 }, () => String.fromCharCode(Math.floor(Math.random() * 65536)))
|
|
7
|
+
.join('')
|
|
8
|
+
.replace(/[\n;>=<"''\\]/g, '');
|
|
9
|
+
|
|
10
|
+
describe('Person verification building', () => {
|
|
11
|
+
it('build & parse function compatibility: input=parse(build(input))', () => {
|
|
12
|
+
const [
|
|
13
|
+
name,
|
|
14
|
+
ownDomain,
|
|
15
|
+
foreignDomain,
|
|
16
|
+
jobTitle,
|
|
17
|
+
employer,
|
|
18
|
+
verificationMethod,
|
|
19
|
+
picture,
|
|
20
|
+
reliabilityPolicy,
|
|
21
|
+
] = Array.from({ length: 12 }, randomUnicodeString);
|
|
22
|
+
const countryOfBirth = 'Germany';
|
|
23
|
+
const cityOfBirth = 'Berlin';
|
|
24
|
+
const confidence = Math.random();
|
|
25
|
+
const dateOfBirth = new Date(0);
|
|
26
|
+
const personVerificationContent = buildPersonVerificationContent({
|
|
27
|
+
name,
|
|
28
|
+
countryOfBirth,
|
|
29
|
+
cityOfBirth,
|
|
30
|
+
ownDomain,
|
|
31
|
+
foreignDomain,
|
|
32
|
+
dateOfBirth,
|
|
33
|
+
jobTitle,
|
|
34
|
+
employer,
|
|
35
|
+
verificationMethod,
|
|
36
|
+
confidence,
|
|
37
|
+
picture,
|
|
38
|
+
reliabilityPolicy,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const parsedVerification = parsePersonVerification(personVerificationContent);
|
|
42
|
+
assert.strictEqual(parsedVerification.name, name);
|
|
43
|
+
assert.strictEqual(parsedVerification.ownDomain, ownDomain);
|
|
44
|
+
assert.strictEqual(parsedVerification.foreignDomain, foreignDomain);
|
|
45
|
+
assert.strictEqual(parsedVerification.dateOfBirth.toUTCString(), dateOfBirth.toUTCString());
|
|
46
|
+
assert.strictEqual(parsedVerification.jobTitle, jobTitle);
|
|
47
|
+
assert.strictEqual(parsedVerification.employer, employer);
|
|
48
|
+
assert.strictEqual(parsedVerification.verificationMethod, verificationMethod);
|
|
49
|
+
assert.strictEqual(parsedVerification.confidence, confidence);
|
|
50
|
+
assert.strictEqual(parsedVerification.picture, picture);
|
|
51
|
+
assert.strictEqual(parsedVerification.reliabilityPolicy, reliabilityPolicy);
|
|
52
|
+
assert.strictEqual(parsedVerification.countryOfBirth, countryOfBirth);
|
|
53
|
+
assert.strictEqual(parsedVerification.cityOfBirth, cityOfBirth);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/src/poll.test.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { parsePoll, buildPollContent } from './protocol';
|
|
4
|
+
|
|
5
|
+
const randomUnicodeString = () =>
|
|
6
|
+
Array.from({ length: 20 }, () => String.fromCharCode(Math.floor(Math.random() * 65536)))
|
|
7
|
+
.join('')
|
|
8
|
+
.replace(/[\n;>=<"''\\]/g, '');
|
|
9
|
+
|
|
10
|
+
describe('Poll building', () => {
|
|
11
|
+
it('build & parse function compatibility: input=parse(build(input))', () => {
|
|
12
|
+
const [poll, scopeDescription] = Array.from({ length: 2 }, randomUnicodeString);
|
|
13
|
+
const options = Array.from({ length: 2 }, randomUnicodeString);
|
|
14
|
+
const deadline = new Date('Thu, 01 Dec 2022 13:38:26 GMT');
|
|
15
|
+
const pollContent = buildPollContent({
|
|
16
|
+
deadline,
|
|
17
|
+
poll,
|
|
18
|
+
options,
|
|
19
|
+
scopeDescription,
|
|
20
|
+
});
|
|
21
|
+
const parsedPoll = parsePoll(pollContent, '5');
|
|
22
|
+
assert.strictEqual(parsedPoll.poll, poll);
|
|
23
|
+
assert.strictEqual(parsedPoll.scopeDescription, scopeDescription);
|
|
24
|
+
assert.strictEqual(parsedPoll.deadline?.toUTCString(), deadline.toUTCString());
|
|
25
|
+
assert.strictEqual(parsedPoll.options[0], options[0]);
|
|
26
|
+
assert.strictEqual(parsedPoll.options[1], options[1]);
|
|
27
|
+
});
|
|
28
|
+
});
|