stated-protocol 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 (62) hide show
  1. package/README.md +409 -0
  2. package/dist/constants.d.ts +225 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +227 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/esm/constants.d.ts +225 -0
  7. package/dist/esm/constants.d.ts.map +1 -0
  8. package/dist/esm/hash.d.ts +37 -0
  9. package/dist/esm/hash.d.ts.map +1 -0
  10. package/dist/esm/index.d.ts +6 -0
  11. package/dist/esm/index.d.ts.map +1 -0
  12. package/dist/esm/index.js +2104 -0
  13. package/dist/esm/index.js.map +7 -0
  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 +115 -0
  19. package/dist/esm/types.d.ts.map +1 -0
  20. package/dist/esm/utils.d.ts +14 -0
  21. package/dist/esm/utils.d.ts.map +1 -0
  22. package/dist/hash.d.ts +37 -0
  23. package/dist/hash.d.ts.map +1 -0
  24. package/dist/hash.js +99 -0
  25. package/dist/hash.js.map +1 -0
  26. package/dist/index.d.ts +6 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +22 -0
  29. package/dist/index.js.map +1 -0
  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 +115 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +30 -0
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils.d.ts +14 -0
  43. package/dist/utils.d.ts.map +1 -0
  44. package/dist/utils.js +96 -0
  45. package/dist/utils.js.map +1 -0
  46. package/package.json +66 -0
  47. package/src/constants.ts +245 -0
  48. package/src/fixtures.test.ts +236 -0
  49. package/src/hash.test.ts +219 -0
  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 +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 +185 -0
  61. package/src/utils.test.ts +140 -0
  62. package/src/utils.ts +104 -0
@@ -0,0 +1,115 @@
1
+ import type { SupportedLanguage } from './constants';
2
+ export type LegalForm = 'local government' | 'state government' | 'foreign affairs ministry' | 'corporation';
3
+ export type PeopleCountBucket = '0-10' | '10-100' | '100-1000' | '1000-10,000' | '10,000-100,000' | '100,000+' | '1,000,000+' | '10,000,000+';
4
+ export declare function isLegalForm(value: string): value is LegalForm;
5
+ export declare function isPeopleCountBucket(value: string): value is PeopleCountBucket;
6
+ export declare function isRatingValue(value: number): value is RatingValue;
7
+ export type StatementTypeValue = 'statement' | 'organisation_verification' | 'person_verification' | 'poll' | 'vote' | 'response' | 'dispute_statement_content' | 'dispute_statement_authenticity' | 'rating' | 'sign_pdf';
8
+ export type Statement = {
9
+ domain: string;
10
+ author: string;
11
+ time: Date;
12
+ tags?: string[];
13
+ content: string;
14
+ representative?: string;
15
+ supersededStatement?: string;
16
+ formatVersion?: string;
17
+ translations?: Partial<Record<SupportedLanguage, string>>;
18
+ attachments?: string[];
19
+ };
20
+ export type CryptographicallySignedStatement = {
21
+ statement: string;
22
+ statementHash: string;
23
+ publicKey: string;
24
+ signature: string;
25
+ algorithm: string;
26
+ };
27
+ export type Poll = {
28
+ deadline: Date | undefined;
29
+ poll: string;
30
+ scopeDescription?: string;
31
+ options: string[];
32
+ allowArbitraryVote?: boolean;
33
+ };
34
+ export type OrganisationVerification = {
35
+ name: string;
36
+ englishName?: string;
37
+ country: string;
38
+ city?: string;
39
+ province?: string;
40
+ legalForm: LegalForm;
41
+ department?: string;
42
+ domain: string;
43
+ foreignDomain?: string;
44
+ serialNumber?: string;
45
+ confidence?: number;
46
+ reliabilityPolicy?: string;
47
+ employeeCount?: PeopleCountBucket;
48
+ pictureHash?: string;
49
+ latitude?: number;
50
+ longitude?: number;
51
+ population?: PeopleCountBucket;
52
+ publicKey?: string;
53
+ };
54
+ export type withOwnDomain = {
55
+ ownDomain: string;
56
+ foreignDomain?: string;
57
+ };
58
+ export type withForeignDomain = {
59
+ foreignDomain: string;
60
+ ownDomain?: string;
61
+ };
62
+ export type PersonVerification = {
63
+ name: string;
64
+ countryOfBirth: string;
65
+ cityOfBirth: string;
66
+ dateOfBirth: Date;
67
+ jobTitle?: string;
68
+ employer?: string;
69
+ verificationMethod?: string;
70
+ confidence?: number;
71
+ picture?: string;
72
+ reliabilityPolicy?: string;
73
+ publicKey?: string;
74
+ } & (withOwnDomain | withForeignDomain);
75
+ export type Vote = {
76
+ pollHash: string;
77
+ poll: string;
78
+ vote: string;
79
+ };
80
+ export type DisputeAuthenticity = {
81
+ hash: string;
82
+ confidence?: number;
83
+ reliabilityPolicy?: string;
84
+ };
85
+ export type DisputeContent = {
86
+ hash: string;
87
+ confidence?: number;
88
+ reliabilityPolicy?: string;
89
+ };
90
+ export type ResponseContent = {
91
+ hash: string;
92
+ response: string;
93
+ };
94
+ export type PDFSigning = {
95
+ hash: string;
96
+ };
97
+ export type RatingSubjectTypeValue = 'Organisation' | 'Policy proposal' | 'Treaty draft' | 'Research publication' | 'Regulation' | 'Product';
98
+ export type RatingValue = 1 | 2 | 3 | 4 | 5;
99
+ export type Rating = {
100
+ subjectType?: RatingSubjectTypeValue;
101
+ subjectName: string;
102
+ subjectReference?: string;
103
+ documentFileHash?: string;
104
+ rating: RatingValue;
105
+ quality?: string;
106
+ comment?: string;
107
+ };
108
+ export type Bounty = {
109
+ motivation?: string;
110
+ bounty: string;
111
+ reward: string;
112
+ judge: string;
113
+ judgePay?: string;
114
+ };
115
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,MAAM,SAAS,GACjB,kBAAkB,GAClB,kBAAkB,GAClB,0BAA0B,GAC1B,aAAa,CAAC;AAElB,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,QAAQ,GACR,UAAU,GACV,aAAa,GACb,gBAAgB,GAChB,UAAU,GACV,YAAY,GACZ,aAAa,CAAC;AAGlB,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAO7D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,iBAAiB,CAW7E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,WAAW,CAEjE;AAED,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,2BAA2B,GAC3B,qBAAqB,GACrB,MAAM,GACN,MAAM,GACN,UAAU,GACV,2BAA2B,GAC3B,gCAAgC,GAChC,QAAQ,GACR,UAAU,CAAC;AAEf,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB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,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B,cAAc,GACd,iBAAiB,GACjB,cAAc,GACd,sBAAsB,GACtB,YAAY,GACZ,SAAS,CAAC;AAEd,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE5C,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,CAAC,EAAE,sBAAsB,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare const generateFileHash: (fileContent: Buffer | string) => string;
2
+ export declare const validateFileHash: (fileContent: Buffer | string, expectedHash: string) => boolean;
3
+ export declare const generateStatementContentHash: (statementContent: string) => string;
4
+ export declare const validateStatementContentHash: (statementContent: string, expectedHash: string) => boolean;
5
+ export declare const generateStatementHash: (statement: string) => string;
6
+ export declare const validateStatementHash: (statement: string, expectedHash: string) => boolean;
7
+ export declare const generateStatementsFile: (statements: string[]) => string;
8
+ export declare const parseStatementsFile: (statementsFileContent: string) => string[];
9
+ export declare const generateStatementFilename: (statement: string) => string;
10
+ export declare const generateAttachmentFilename: (fileContent: Buffer | string, extension: string) => string;
11
+ export declare const minPeopleCountToRange: (n: number) => string | undefined;
12
+ export declare const monthIndex: (month: string) => number;
13
+ export declare const birthDateFormat: RegExp;
14
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,GAAG,MAAM,KAAG,MAE/D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,GAAG,MAAM,EAAE,cAAc,MAAM,KAAG,OAErF,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,kBAAkB,MAAM,KAAG,MAEvE,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,kBAAkB,MAAM,EACxB,cAAc,MAAM,KACnB,OAEF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,WAAW,MAAM,KAAG,MASzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,WAAW,MAAM,EAAE,cAAc,MAAM,KAAG,OAG/E,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,YAAY,MAAM,EAAE,KAAG,MAE7D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,uBAAuB,MAAM,KAAG,MAAM,EA0BzE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,WAAW,MAAM,KAAG,MAG7D,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,aAAa,MAAM,GAAG,MAAM,EAC5B,WAAW,MAAM,KAChB,MAIF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,GAAG,MAAM,KAAG,MAAM,GAAG,SAS1D,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAGxC,CAAC;AAEJ,eAAO,MAAM,eAAe,EAAE,MAC2D,CAAC"}
package/dist/hash.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Universal hash utilities using @noble/hashes
3
+ * Works in both browser and Node.js environments
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 declare const sha256: (input: string | Uint8Array) => string;
12
+ /**
13
+ * Verify that content matches a given hash
14
+ * @param content - The content to verify
15
+ * @param hash - The expected hash
16
+ * @returns True if the hash matches
17
+ */
18
+ export declare const verify: (content: string | Uint8Array, 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
+ /**
32
+ * Convert base64 string to bytes
33
+ * @param base64 - Base64 string to convert
34
+ * @returns Uint8Array
35
+ */
36
+ export declare function base64ToBytes(base64: string): Uint8Array;
37
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,GAAG,UAAU,KAAG,MAoBnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,GAAG,UAAU,EAAE,MAAM,MAAM,KAAG,OAGnE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAKnD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAEhD,CAAC;AAgBF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAYxD"}
package/dist/hash.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Universal hash utilities using @noble/hashes
4
+ * Works in both browser and Node.js environments
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.toUrlSafeBase64 = exports.fromUrlSafeBase64 = exports.verify = exports.sha256 = void 0;
8
+ exports.base64ToBytes = base64ToBytes;
9
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
10
+ /**
11
+ * Compute SHA-256 hash of a string and return it as URL-safe base64
12
+ * Works in both browser and Node.js environments
13
+ * @param input - The string or buffer to hash
14
+ * @returns URL-safe base64 encoded hash
15
+ */
16
+ const sha256 = (input) => {
17
+ let data;
18
+ if (typeof input === 'string') {
19
+ const encoder = new TextEncoder();
20
+ data = encoder.encode(input);
21
+ }
22
+ else {
23
+ data = input;
24
+ }
25
+ // Use @noble/hashes for consistent cross-platform hashing
26
+ const hashArray = (0, sha2_js_1.sha256)(data);
27
+ // Convert to base64
28
+ const base64 = bytesToBase64(hashArray);
29
+ // Make URL-safe: remove padding and replace + with - and / with _
30
+ const urlSafe = base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
31
+ return urlSafe;
32
+ };
33
+ exports.sha256 = sha256;
34
+ /**
35
+ * Verify that content matches a given hash
36
+ * @param content - The content to verify
37
+ * @param hash - The expected hash
38
+ * @returns True if the hash matches
39
+ */
40
+ const verify = (content, hash) => {
41
+ const computed = (0, exports.sha256)(content);
42
+ return computed === hash;
43
+ };
44
+ exports.verify = verify;
45
+ /**
46
+ * Convert URL-safe base64 back to standard base64
47
+ * @param urlSafe - URL-safe base64 string
48
+ * @returns Standard base64 string with padding
49
+ */
50
+ const fromUrlSafeBase64 = (urlSafe) => {
51
+ const base64 = urlSafe.replace(/-/g, '+').replace(/_/g, '/');
52
+ // Add padding if needed
53
+ const padding = '='.repeat((4 - (base64.length % 4)) % 4);
54
+ return base64 + padding;
55
+ };
56
+ exports.fromUrlSafeBase64 = fromUrlSafeBase64;
57
+ /**
58
+ * Convert standard base64 to URL-safe base64
59
+ * @param base64 - Standard base64 string
60
+ * @returns URL-safe base64 string without padding
61
+ */
62
+ const toUrlSafeBase64 = (base64) => {
63
+ return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
64
+ };
65
+ exports.toUrlSafeBase64 = toUrlSafeBase64;
66
+ /**
67
+ * Convert bytes to base64 string
68
+ * @param bytes - Uint8Array to convert
69
+ * @returns Base64 string
70
+ */
71
+ function bytesToBase64(bytes) {
72
+ // Use btoa if available (browser), otherwise use Buffer (Node.js)
73
+ if (typeof btoa !== 'undefined') {
74
+ return btoa(String.fromCharCode(...Array.from(bytes)));
75
+ }
76
+ else {
77
+ return Buffer.from(bytes).toString('base64');
78
+ }
79
+ }
80
+ /**
81
+ * Convert base64 string to bytes
82
+ * @param base64 - Base64 string to convert
83
+ * @returns Uint8Array
84
+ */
85
+ function base64ToBytes(base64) {
86
+ // Use atob if available (browser), otherwise use Buffer (Node.js)
87
+ if (typeof atob !== 'undefined') {
88
+ const binaryString = atob(base64);
89
+ const bytes = new Uint8Array(binaryString.length);
90
+ for (let i = 0; i < binaryString.length; i++) {
91
+ bytes[i] = binaryString.charCodeAt(i);
92
+ }
93
+ return bytes;
94
+ }
95
+ else {
96
+ return new Uint8Array(Buffer.from(base64, 'base64'));
97
+ }
98
+ }
99
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmFH,sCAYC;AA7FD,mDAA8D;AAE9D;;;;;GAKG;AACI,MAAM,MAAM,GAAG,CAAC,KAA0B,EAAU,EAAE;IAC3D,IAAI,IAAgB,CAAC;IAErB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,KAAK,CAAC;I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AAK,EAAE,GAAG,CAAC,CAAC;AAC1E,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEF;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAiB;IACtC,kEAAkE;IAClE,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,MAAc;IAC1C,kEAAkE;IAClE,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './protocol';
2
+ export * from './hash';
3
+ export * from './signature';
4
+ export * from './constants';
5
+ export * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./protocol"), exports);
18
+ __exportStar(require("./hash"), exports);
19
+ __exportStar(require("./signature"), exports);
20
+ __exportStar(require("./constants"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,8CAA4B;AAC5B,0CAAwB"}
@@ -0,0 +1,30 @@
1
+ import type { Statement, Poll, OrganisationVerification, PersonVerification, Vote, DisputeAuthenticity, DisputeContent, ResponseContent, PDFSigning, Rating } from './types';
2
+ export * from './types';
3
+ export * from './constants';
4
+ export * from './utils';
5
+ export declare const buildStatement: ({ domain, author, time, tags, content, representative, supersededStatement, translations, attachments, }: Statement) => string;
6
+ export declare const parseStatement: ({ statement: input, }: {
7
+ statement: string;
8
+ }) => Statement & {
9
+ type?: string;
10
+ formatVersion: string;
11
+ };
12
+ export declare const buildPollContent: ({ deadline, poll, scopeDescription, options, allowArbitraryVote, }: Poll) => string;
13
+ export declare const parsePoll: (content: string, version?: string) => Poll;
14
+ export declare const buildOrganisationVerificationContent: ({ name, englishName, country, city, province, legalForm, department, domain, foreignDomain, serialNumber, confidence, reliabilityPolicy, employeeCount, pictureHash, latitude, longitude, population, publicKey, }: OrganisationVerification) => string;
15
+ export declare const parseOrganisationVerification: (content: string) => OrganisationVerification;
16
+ export declare const buildPersonVerificationContent: ({ name, countryOfBirth, cityOfBirth, ownDomain, foreignDomain, dateOfBirth, jobTitle, employer, verificationMethod, confidence, picture, reliabilityPolicy, publicKey, }: PersonVerification) => string;
17
+ export declare const parsePersonVerification: (content: string) => PersonVerification;
18
+ export declare const buildVoteContent: ({ pollHash, poll, vote }: Vote) => string;
19
+ export declare const parseVote: (content: string) => Vote;
20
+ export declare const buildDisputeAuthenticityContent: ({ hash, confidence, reliabilityPolicy, }: DisputeAuthenticity) => string;
21
+ export declare const parseDisputeAuthenticity: (content: string) => DisputeAuthenticity;
22
+ export declare const buildDisputeContentContent: ({ hash, confidence, reliabilityPolicy, }: DisputeContent) => string;
23
+ export declare const parseDisputeContent: (content: string) => DisputeContent;
24
+ export declare const buildResponseContent: ({ hash, response }: ResponseContent) => string;
25
+ export declare const parseResponseContent: (content: string) => ResponseContent;
26
+ export declare const buildPDFSigningContent: ({ hash }: PDFSigning) => string;
27
+ export declare const parsePDFSigning: (content: string) => PDFSigning;
28
+ export declare const buildRating: ({ subjectName, subjectType, subjectReference, documentFileHash, rating, quality, comment, }: Rating) => string;
29
+ export declare const parseRating: (content: string) => Rating;
30
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,wBAAwB,EACxB,kBAAkB,EAClB,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