@rakelabs/evidence-publisher 0.1.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 (40) hide show
  1. package/README.md +608 -0
  2. package/dist/src/EvidenceHasher.d.ts +7 -0
  3. package/dist/src/EvidenceHasher.js +32 -0
  4. package/dist/src/EvidenceJsonBuilder.d.ts +6 -0
  5. package/dist/src/EvidenceJsonBuilder.js +50 -0
  6. package/dist/src/EvidencePublisher.d.ts +35 -0
  7. package/dist/src/EvidencePublisher.js +105 -0
  8. package/dist/src/EvidencePublisherFactory.d.ts +83 -0
  9. package/dist/src/EvidencePublisherFactory.js +251 -0
  10. package/dist/src/MetaEvidenceJsonBuilder.d.ts +25 -0
  11. package/dist/src/MetaEvidenceJsonBuilder.js +104 -0
  12. package/dist/src/MetaEvidencePublisher.d.ts +39 -0
  13. package/dist/src/MetaEvidencePublisher.js +104 -0
  14. package/dist/src/advanced.d.ts +15 -0
  15. package/dist/src/advanced.js +7 -0
  16. package/dist/src/config.d.ts +51 -0
  17. package/dist/src/config.js +245 -0
  18. package/dist/src/helia/HeliaAttachmentStore.d.ts +8 -0
  19. package/dist/src/helia/HeliaAttachmentStore.js +20 -0
  20. package/dist/src/helia/HeliaEvidenceStore.d.ts +8 -0
  21. package/dist/src/helia/HeliaEvidenceStore.js +16 -0
  22. package/dist/src/helia/HeliaIpfsClient.d.ts +15 -0
  23. package/dist/src/helia/HeliaIpfsClient.js +63 -0
  24. package/dist/src/http/HttpIpfsAttachmentStore.d.ts +8 -0
  25. package/dist/src/http/HttpIpfsAttachmentStore.js +23 -0
  26. package/dist/src/http/HttpIpfsClient.d.ts +24 -0
  27. package/dist/src/http/HttpIpfsClient.js +126 -0
  28. package/dist/src/http/HttpIpfsEvidenceStore.d.ts +8 -0
  29. package/dist/src/http/HttpIpfsEvidenceStore.js +19 -0
  30. package/dist/src/http/HttpMultipartUploadClient.d.ts +36 -0
  31. package/dist/src/http/HttpMultipartUploadClient.js +183 -0
  32. package/dist/src/http/HttpPinByCidClient.d.ts +23 -0
  33. package/dist/src/http/HttpPinByCidClient.js +137 -0
  34. package/dist/src/index.d.ts +7 -0
  35. package/dist/src/index.js +5 -0
  36. package/dist/src/storage-types.d.ts +21 -0
  37. package/dist/src/storage-types.js +1 -0
  38. package/dist/src/types.d.ts +238 -0
  39. package/dist/src/types.js +1 -0
  40. package/package.json +62 -0
@@ -0,0 +1,238 @@
1
+ export type RequestAuth = {
2
+ type: 'none';
3
+ } | {
4
+ type: 'basic';
5
+ username: string;
6
+ password: string;
7
+ } | {
8
+ type: 'bearer';
9
+ token: string;
10
+ } | {
11
+ type: 'header';
12
+ name: string;
13
+ value: string;
14
+ };
15
+ /** Court-compatible ruling option types supported by Kleros Court. */
16
+ export type RulingOptionType = 'single-select' | 'multiple-select' | 'uint' | 'int' | 'string' | 'datetime' | 'hash';
17
+ /** Modern iframe encoding mode used by Kleros Court. */
18
+ export type CourtEncodingVersion = '0' | '1';
19
+ /** Court-facing nested ruling options. */
20
+ export interface RulingOptions {
21
+ type: RulingOptionType;
22
+ precision: number;
23
+ titles: string[];
24
+ descriptions: string[];
25
+ reserved: Record<string, string>;
26
+ }
27
+ /** Court-facing MetaEvidence document (ERC-1497). */
28
+ export interface MetaEvidence {
29
+ category: string;
30
+ title: string;
31
+ description: string;
32
+ question: string;
33
+ rulingOptions: RulingOptions;
34
+ fileURI?: string;
35
+ fileHash?: string;
36
+ fileTypeExtension?: string;
37
+ aliases?: Record<string, string>;
38
+ evidenceDisplayInterfaceURI?: string;
39
+ evidenceDisplayInterfaceHash?: string;
40
+ dynamicScriptURI?: string;
41
+ dynamicScriptHash?: string;
42
+ arbitrableInterfaceURI?: string;
43
+ arbitrableChainID?: number;
44
+ arbitratorChainID?: number;
45
+ arbitrableJsonRpcUrl?: string;
46
+ arbitratorJsonRpcUrl?: string;
47
+ /** Court encoding version. Defaults to '1' when omitted. */
48
+ _v?: CourtEncodingVersion;
49
+ }
50
+ /**
51
+ * Caller-supplied draft for building a MetaEvidence document.
52
+ * Required fields match the ERC-1497 minimum; all other fields are optional.
53
+ * File-related fields are supplied by the caller (manual path) or derived from
54
+ * an uploaded attachment (assisted path).
55
+ */
56
+ export interface MetaEvidenceDraft {
57
+ category: string;
58
+ title: string;
59
+ description: string;
60
+ question: string;
61
+ rulingOptions: RulingOptions;
62
+ aliases?: Record<string, string>;
63
+ fileURI?: string;
64
+ fileHash?: string;
65
+ fileTypeExtension?: string;
66
+ evidenceDisplayInterfaceURI?: string;
67
+ evidenceDisplayInterfaceHash?: string;
68
+ dynamicScriptURI?: string;
69
+ dynamicScriptHash?: string;
70
+ arbitrableInterfaceURI?: string;
71
+ arbitrableChainID?: number;
72
+ arbitratorChainID?: number;
73
+ arbitrableJsonRpcUrl?: string;
74
+ arbitratorJsonRpcUrl?: string;
75
+ _v?: CourtEncodingVersion;
76
+ }
77
+ /**
78
+ * Manual MetaEvidence publish — the caller provides all document fields,
79
+ * including any file-related metadata. No attachment upload is performed.
80
+ */
81
+ export type ManualMetaEvidencePublishRequest = MetaEvidenceDraft;
82
+ /**
83
+ * Assisted MetaEvidence publish — the caller provides the core draft plus a
84
+ * binary attachment. The SDK uploads the attachment first and fills
85
+ * `fileURI`, `fileHash`, and `fileTypeExtension` from the upload result.
86
+ * Attachment-derived values take precedence over any file fields on the draft.
87
+ */
88
+ export interface AssistedMetaEvidencePublishRequest extends MetaEvidenceDraft {
89
+ attachment: Attachment;
90
+ }
91
+ /** Union of both MetaEvidence publish paths. */
92
+ export type MetaEvidencePublishRequest = ManualMetaEvidencePublishRequest | AssistedMetaEvidencePublishRequest;
93
+ /** Result returned by {@link MetaEvidencePublisher.publish}. */
94
+ export interface MetaEvidencePublishResult {
95
+ /** The canonical MetaEvidence JSON that was published. */
96
+ documentJson: MetaEvidence;
97
+ /** The published IPFS document location. */
98
+ document: PublishedEvidenceDocument;
99
+ /** Published attachment, present only when the assisted path was used. */
100
+ attachment?: PublishedAttachment;
101
+ /**
102
+ * Remote pinning outcome. Present only when `remotePinning` is configured
103
+ * on the publisher. Check `remotePinning.error` to detect persistence
104
+ * failures without losing the publish result.
105
+ */
106
+ remotePinning?: RemotePinOutcome;
107
+ }
108
+ /**
109
+ * Optional post-publish durability step.
110
+ *
111
+ * After any backend produces a CID, the SDK optionally forwards that CID to a
112
+ * remote pinning service. This is backend-agnostic: it works after Helia,
113
+ * Kubo, Pinata upload, or any future backend that returns a CID.
114
+ *
115
+ * Remote pinning is distinct from local pinning (which is an internal Helia
116
+ * implementation detail).
117
+ */
118
+ export interface RemotePinningConfig {
119
+ /** Base URL of the remote pinning service (e.g. https://api.pinata.cloud/v3). */
120
+ endpoint: string;
121
+ /** Authentication for the remote pinning service. */
122
+ auth: RequestAuth;
123
+ /** Path for the pin-by-CID endpoint relative to endpoint. Defaults to /files/public/pin_by_cid. */
124
+ requestPath?: string;
125
+ /** Additional headers for every remote pin request. */
126
+ headers?: Record<string, string>;
127
+ /**
128
+ * Whether remote pinning is active.
129
+ * Omit or set to true to enable; false to disable without removing the config block.
130
+ */
131
+ enabled?: boolean;
132
+ }
133
+ /**
134
+ * Outcome of the remote pinning step embedded in {@link EvidencePublishResult}.
135
+ * Present only when `remotePinning` is configured.
136
+ */
137
+ export interface RemotePinOutcome {
138
+ /** CID pin result for the evidence document. Present when pinning succeeded. */
139
+ documentPin?: PinResult;
140
+ /** CID pin result for the attachment. Present when an attachment was published and pinning succeeded. */
141
+ attachmentPin?: PinResult;
142
+ /**
143
+ * Set when remote pinning failed. The publish result is still returned — the
144
+ * caller can inspect this field to distinguish publish success from persistence failure.
145
+ */
146
+ error?: Error;
147
+ }
148
+ export type RequestFieldValue = string | number | boolean | null | undefined | Record<string, string> | string[];
149
+ export type RequestFields = Record<string, RequestFieldValue>;
150
+ /** Minimal shared transport context: how to authenticate and any extra headers.
151
+ * `auth` is optional — when omitted, the client falls back to its own configured auth. */
152
+ export interface RequestContext {
153
+ auth?: RequestAuth;
154
+ headers?: Record<string, string>;
155
+ }
156
+ export interface UploadRequest extends RequestContext {
157
+ file: Uint8Array;
158
+ fileName?: string;
159
+ mediaType?: string;
160
+ /** Provider-specific extra form or body fields. */
161
+ fields?: RequestFields;
162
+ }
163
+ export interface PinByCidRequest extends RequestContext {
164
+ cid: string;
165
+ /** Provider-specific extra JSON body fields included in the pin request. */
166
+ fields?: RequestFields;
167
+ }
168
+ export type PinningRequest = UploadRequest | PinByCidRequest;
169
+ /** ERC-1497 Evidence JSON document. */
170
+ export interface EvidenceJson {
171
+ title: string;
172
+ name: string;
173
+ description: string;
174
+ fileURI?: string;
175
+ fileHash?: string;
176
+ fileTypeExtension?: string;
177
+ selfHash?: string;
178
+ }
179
+ export type EvidenceJsonDocument = EvidenceJson;
180
+ export interface EvidenceDraft {
181
+ title: string;
182
+ description: string;
183
+ fileUri?: string;
184
+ fileHash?: string;
185
+ fileTypeExtension?: string;
186
+ }
187
+ export interface Attachment {
188
+ bytes: Uint8Array;
189
+ fileName?: string;
190
+ mediaType?: string;
191
+ fileTypeExtension?: string;
192
+ }
193
+ export interface PublishedAttachment {
194
+ cid: string;
195
+ uri: string;
196
+ fileHash?: string;
197
+ fileTypeExtension?: string;
198
+ mediaType?: string;
199
+ sizeBytes?: number;
200
+ gatewayUrls?: string[];
201
+ metadata?: Record<string, string>;
202
+ }
203
+ export interface PublishedEvidenceDocument {
204
+ cid: string;
205
+ uri: string;
206
+ gatewayUrls?: string[];
207
+ metadata?: Record<string, string>;
208
+ }
209
+ export interface EvidencePublishRequest {
210
+ title: string;
211
+ description: string;
212
+ attachment?: Attachment;
213
+ fileUri?: string;
214
+ fileHash?: string;
215
+ fileTypeExtension?: string;
216
+ }
217
+ export interface EvidencePublishResult {
218
+ selfHash: string;
219
+ documentJson: EvidenceJsonDocument;
220
+ attachment?: PublishedAttachment;
221
+ document: PublishedEvidenceDocument;
222
+ /**
223
+ * Remote pinning outcome. Present only when `remotePinning` is configured
224
+ * on the publisher. Check `remotePinning.error` to detect persistence
225
+ * failures without losing the publish result.
226
+ */
227
+ remotePinning?: RemotePinOutcome;
228
+ }
229
+ /** CID input wrapper — kept as a type to allow validation in future. */
230
+ export interface CidInput {
231
+ cid: string;
232
+ }
233
+ export interface PinResult {
234
+ cid: string;
235
+ uri?: string;
236
+ gatewayUrls?: string[];
237
+ metadata?: Record<string, string>;
238
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@rakelabs/evidence-publisher",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "Standalone npm SDK for ERC-1497 / Kleros evidence document construction and IPFS publication",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/programmaman/evidence-publisher.git"
11
+ },
12
+ "homepage": "https://github.com/programmaman/evidence-publisher#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/programmaman/evidence-publisher/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "dist/src/index.js",
18
+ "types": "dist/src/index.d.ts",
19
+ "keywords": [
20
+ "erc-1497",
21
+ "kleros",
22
+ "evidence",
23
+ "metaevidence",
24
+ "ipfs"
25
+ ],
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/src/index.d.ts",
32
+ "default": "./dist/src/index.js"
33
+ },
34
+ "./advanced": {
35
+ "types": "./dist/src/advanced.d.ts",
36
+ "default": "./dist/src/advanced.js"
37
+ }
38
+ },
39
+ "scripts": {
40
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
41
+ "build": "npm run clean && tsc -p tsconfig.json",
42
+ "prepack": "npm run build",
43
+ "test": "npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@helia/unixfs": "^7.2.1",
47
+ "dotenv": "^16.4.5",
48
+ "ethers": "^6.10.0",
49
+ "helia": "^6.1.4",
50
+ "yaml": "^2.5.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^20.0.0",
54
+ "typescript": "^5.0.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "files": [
60
+ "dist/src"
61
+ ]
62
+ }