@ethernity-cloud/sdk-js 1.5.2 → 1.5.5

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.
@@ -1,275 +1,275 @@
1
- class Order {
2
- constructor(req, order_id) {
3
- this.id = order_id;
4
- this.do_owner = req[0];
5
- this.dproc = req[1];
6
- this.do_req = req[2];
7
- this.dp_req = req[3];
8
- this.status = req[4];
9
- }
10
- }
11
-
12
- class MetadataBase {
13
- constructor(metadata, version) {
14
- this.metadata = metadata;
15
- this._version = version;
16
- }
17
-
18
- get version() {
19
- return this._version;
20
- }
21
-
22
- get ipfs_hash() {
23
- throw new Error("Subclass must implement this method");
24
- }
25
-
26
- checksum() {
27
- throw new Error("Subclass must implement this method");
28
- }
29
-
30
- // True when this metadata carries a real checksum to validate. Empty input
31
- // carries no checksum (checksum is null), so callers can skip validation
32
- // without inspecting raw metadata strings themselves.
33
- get has_checksum() {
34
- return this.checksum != null;
35
- }
36
- }
37
-
38
- class PayloadFactory {
39
- static create_payload_metadata(metadata) {
40
- if (metadata.includes(":")) {
41
- if (metadata.startsWith("v1")) {
42
- return new PayloadMetadataV1(metadata);
43
- }
44
- if (metadata.startsWith("v2")) {
45
- return new PayloadMetadataV2(metadata);
46
- }
47
-
48
- if (metadata.startsWith("v3")) {
49
- return new PayloadMetadataV3(metadata);
50
- }
51
-
52
- throw new Error("Invalid payload metadata type");
53
- } else {
54
- return new PayloadMetadataV0(metadata);
55
- }
56
- }
57
- }
58
-
59
- class InputFactory {
60
- static create_input_metadata(metadata) {
61
- if (metadata.includes(":")) {
62
- if (metadata.startsWith("v1")) {
63
- return new InputMetadataV1(metadata);
64
- }
65
- if (metadata.startsWith("v2")) {
66
- return new InputMetadataV2(metadata);
67
- }
68
- if (metadata.startsWith("v3")) {
69
- return new InputMetadataV3(metadata);
70
- }
71
-
72
- throw new Error("Invalid payload metadata type");
73
- } else {
74
- return new InputMetadataV0(metadata);
75
- }
76
- }
77
- }
78
-
79
- class InputMetadataV0 extends MetadataBase {
80
- constructor(metadata) {
81
- super(metadata, "v0");
82
- this._ipfs_hash = metadata;
83
- }
84
-
85
- get ipfs_hash() {
86
- return this._ipfs_hash;
87
- }
88
-
89
- get checksum() {
90
- return null;
91
- }
92
- }
93
-
94
- class PayloadMetadataV0 extends MetadataBase {
95
- constructor(metadata) {
96
- super(metadata, "v0");
97
- this._ipfs_hash = metadata;
98
- }
99
-
100
- get ipfs_hash() {
101
- return this._ipfs_hash;
102
- }
103
-
104
- get checksum() {
105
- return null;
106
- }
107
- }
108
-
109
- class PayloadMetadataV1 extends MetadataBase {
110
- constructor(metadata) {
111
- super(metadata, "v1");
112
- this._checksum = metadata.split(":")[2];
113
- this._ipfs_hash = metadata.split(":")[1];
114
- }
115
-
116
- get ipfs_hash() {
117
- return this._ipfs_hash;
118
- }
119
-
120
- get checksum() {
121
- return this._checksum;
122
- }
123
- }
124
-
125
- class InputMetadataV1 extends MetadataBase {
126
- constructor(metadata) {
127
- super(metadata, "v1");
128
- this._checksum = metadata.split(":")[2];
129
- this._ipfs_hash = metadata.split(":")[1];
130
- }
131
-
132
- get ipfs_hash() {
133
- return this._ipfs_hash;
134
- }
135
-
136
- get checksum() {
137
- return this._checksum !== "0" ? this._checksum : this._checksum;
138
- }
139
- }
140
-
141
- class PayloadMetadataV2 extends MetadataBase {
142
- constructor(metadata) {
143
- super(metadata, "v2");
144
- this._checksum = metadata.split(":")[2];
145
- this._ipfs_hash = metadata.split(":")[1];
146
- }
147
-
148
- get ipfs_hash() {
149
- return this._ipfs_hash;
150
- }
151
-
152
- get checksum() {
153
- return this._checksum;
154
- }
155
- }
156
-
157
- class PayloadMetadataV3 extends MetadataBase {
158
- constructor(metadata) {
159
- super(metadata, "v3");
160
- // An absent checksum (empty or "0" third field) is normalized to null so
161
- // the rest of the code can rely on `has_checksum` instead of special-
162
- // casing empty strings.
163
- const c = (metadata.split(":")[2] || "").trim();
164
- this._checksum = (c && c !== "0") ? c : null;
165
- this._ipfs_hash = metadata.split(":")[1];
166
- }
167
-
168
- get ipfs_hash() {
169
- return this._ipfs_hash;
170
- }
171
-
172
- get checksum() {
173
- return this._checksum;
174
- }
175
- }
176
-
177
- class InputMetadataV2 extends MetadataBase {
178
- constructor(metadata) {
179
- super(metadata, "v2");
180
- this._checksum = metadata.split(":")[2];
181
- this._ipfs_hash = metadata.split(":")[1];
182
- }
183
-
184
- get ipfs_hash() {
185
- return this._ipfs_hash;
186
- }
187
-
188
- get checksum() {
189
- return this._checksum !== "0" ? this._checksum : this._checksum;
190
- }
191
- }
192
-
193
- class InputMetadataV3 extends MetadataBase {
194
- constructor(metadata) {
195
- super(metadata, "v3");
196
- // Empty input carries an empty (or "0") checksum field; normalize it to
197
- // null so `has_checksum` is false and validation is skipped.
198
- const c = (metadata.split(":")[2] || "").trim();
199
- this._checksum = (c && c !== "0") ? c : null;
200
- this._ipfs_hash = metadata.split(":")[1];
201
- }
202
-
203
- get ipfs_hash() {
204
- return this._ipfs_hash;
205
- }
206
-
207
- get checksum() {
208
- return this._checksum;
209
- }
210
- }
211
-
212
- class DOReqMetadata {
213
- constructor(req, do_req) {
214
- this._do_req_id = do_req;
215
- this._do_owner = req[0];
216
- this._metadata1 = req[1];
217
- this._metadata2 = req[2];
218
- this._metadata3 = req[3];
219
- this._metadata4 = req[4];
220
- this._payload_metadata_obj = PayloadFactory.create_payload_metadata(this.payload_metadata);
221
- this._input_metadata_obj = InputFactory.create_input_metadata(this.input_metadata);
222
- }
223
-
224
- get do_req_id() {
225
- return this._do_req_id;
226
- }
227
-
228
- get do_owner() {
229
- return this._do_owner;
230
- }
231
-
232
- get image_metadata() {
233
- return this._metadata1;
234
- }
235
-
236
- get public_key() {
237
- return this.image_metadata.split(':')[5];
238
- }
239
-
240
- get image_hash() {
241
- return this.image_metadata.split(':')[1];
242
- }
243
-
244
- get payload_metadata() {
245
- return this._metadata2;
246
- }
247
-
248
- get payload_metadata_obj() {
249
- return this._payload_metadata_obj;
250
- }
251
-
252
- get input_metadata_obj() {
253
- return this._input_metadata_obj;
254
- }
255
-
256
- get input_metadata() {
257
- return this._metadata3;
258
- }
259
-
260
- get node_address() {
261
- return this._metadata4;
262
- }
263
- }
264
-
265
- module.exports = {
266
- Order,
267
- MetadataBase,
268
- PayloadFactory,
269
- InputFactory,
270
- InputMetadataV0,
271
- PayloadMetadataV0,
272
- InputMetadataV1,
273
- PayloadMetadataV1,
274
- DOReqMetadata
275
- }
1
+ class Order {
2
+ constructor(req, order_id) {
3
+ this.id = order_id;
4
+ this.do_owner = req[0];
5
+ this.dproc = req[1];
6
+ this.do_req = req[2];
7
+ this.dp_req = req[3];
8
+ this.status = req[4];
9
+ }
10
+ }
11
+
12
+ class MetadataBase {
13
+ constructor(metadata, version) {
14
+ this.metadata = metadata;
15
+ this._version = version;
16
+ }
17
+
18
+ get version() {
19
+ return this._version;
20
+ }
21
+
22
+ get ipfs_hash() {
23
+ throw new Error("Subclass must implement this method");
24
+ }
25
+
26
+ checksum() {
27
+ throw new Error("Subclass must implement this method");
28
+ }
29
+
30
+ // True when this metadata carries a real checksum to validate. Empty input
31
+ // carries no checksum (checksum is null), so callers can skip validation
32
+ // without inspecting raw metadata strings themselves.
33
+ get has_checksum() {
34
+ return this.checksum != null;
35
+ }
36
+ }
37
+
38
+ class PayloadFactory {
39
+ static create_payload_metadata(metadata) {
40
+ if (metadata.includes(":")) {
41
+ if (metadata.startsWith("v1")) {
42
+ return new PayloadMetadataV1(metadata);
43
+ }
44
+ if (metadata.startsWith("v2")) {
45
+ return new PayloadMetadataV2(metadata);
46
+ }
47
+
48
+ if (metadata.startsWith("v3")) {
49
+ return new PayloadMetadataV3(metadata);
50
+ }
51
+
52
+ throw new Error("Invalid payload metadata type");
53
+ } else {
54
+ return new PayloadMetadataV0(metadata);
55
+ }
56
+ }
57
+ }
58
+
59
+ class InputFactory {
60
+ static create_input_metadata(metadata) {
61
+ if (metadata.includes(":")) {
62
+ if (metadata.startsWith("v1")) {
63
+ return new InputMetadataV1(metadata);
64
+ }
65
+ if (metadata.startsWith("v2")) {
66
+ return new InputMetadataV2(metadata);
67
+ }
68
+ if (metadata.startsWith("v3")) {
69
+ return new InputMetadataV3(metadata);
70
+ }
71
+
72
+ throw new Error("Invalid payload metadata type");
73
+ } else {
74
+ return new InputMetadataV0(metadata);
75
+ }
76
+ }
77
+ }
78
+
79
+ class InputMetadataV0 extends MetadataBase {
80
+ constructor(metadata) {
81
+ super(metadata, "v0");
82
+ this._ipfs_hash = metadata;
83
+ }
84
+
85
+ get ipfs_hash() {
86
+ return this._ipfs_hash;
87
+ }
88
+
89
+ get checksum() {
90
+ return null;
91
+ }
92
+ }
93
+
94
+ class PayloadMetadataV0 extends MetadataBase {
95
+ constructor(metadata) {
96
+ super(metadata, "v0");
97
+ this._ipfs_hash = metadata;
98
+ }
99
+
100
+ get ipfs_hash() {
101
+ return this._ipfs_hash;
102
+ }
103
+
104
+ get checksum() {
105
+ return null;
106
+ }
107
+ }
108
+
109
+ class PayloadMetadataV1 extends MetadataBase {
110
+ constructor(metadata) {
111
+ super(metadata, "v1");
112
+ this._checksum = metadata.split(":")[2];
113
+ this._ipfs_hash = metadata.split(":")[1];
114
+ }
115
+
116
+ get ipfs_hash() {
117
+ return this._ipfs_hash;
118
+ }
119
+
120
+ get checksum() {
121
+ return this._checksum;
122
+ }
123
+ }
124
+
125
+ class InputMetadataV1 extends MetadataBase {
126
+ constructor(metadata) {
127
+ super(metadata, "v1");
128
+ this._checksum = metadata.split(":")[2];
129
+ this._ipfs_hash = metadata.split(":")[1];
130
+ }
131
+
132
+ get ipfs_hash() {
133
+ return this._ipfs_hash;
134
+ }
135
+
136
+ get checksum() {
137
+ return this._checksum !== "0" ? this._checksum : this._checksum;
138
+ }
139
+ }
140
+
141
+ class PayloadMetadataV2 extends MetadataBase {
142
+ constructor(metadata) {
143
+ super(metadata, "v2");
144
+ this._checksum = metadata.split(":")[2];
145
+ this._ipfs_hash = metadata.split(":")[1];
146
+ }
147
+
148
+ get ipfs_hash() {
149
+ return this._ipfs_hash;
150
+ }
151
+
152
+ get checksum() {
153
+ return this._checksum;
154
+ }
155
+ }
156
+
157
+ class PayloadMetadataV3 extends MetadataBase {
158
+ constructor(metadata) {
159
+ super(metadata, "v3");
160
+ // An absent checksum (empty or "0" third field) is normalized to null so
161
+ // the rest of the code can rely on `has_checksum` instead of special-
162
+ // casing empty strings.
163
+ const c = (metadata.split(":")[2] || "").trim();
164
+ this._checksum = (c && c !== "0") ? c : null;
165
+ this._ipfs_hash = metadata.split(":")[1];
166
+ }
167
+
168
+ get ipfs_hash() {
169
+ return this._ipfs_hash;
170
+ }
171
+
172
+ get checksum() {
173
+ return this._checksum;
174
+ }
175
+ }
176
+
177
+ class InputMetadataV2 extends MetadataBase {
178
+ constructor(metadata) {
179
+ super(metadata, "v2");
180
+ this._checksum = metadata.split(":")[2];
181
+ this._ipfs_hash = metadata.split(":")[1];
182
+ }
183
+
184
+ get ipfs_hash() {
185
+ return this._ipfs_hash;
186
+ }
187
+
188
+ get checksum() {
189
+ return this._checksum !== "0" ? this._checksum : this._checksum;
190
+ }
191
+ }
192
+
193
+ class InputMetadataV3 extends MetadataBase {
194
+ constructor(metadata) {
195
+ super(metadata, "v3");
196
+ // Empty input carries an empty (or "0") checksum field; normalize it to
197
+ // null so `has_checksum` is false and validation is skipped.
198
+ const c = (metadata.split(":")[2] || "").trim();
199
+ this._checksum = (c && c !== "0") ? c : null;
200
+ this._ipfs_hash = metadata.split(":")[1];
201
+ }
202
+
203
+ get ipfs_hash() {
204
+ return this._ipfs_hash;
205
+ }
206
+
207
+ get checksum() {
208
+ return this._checksum;
209
+ }
210
+ }
211
+
212
+ class DOReqMetadata {
213
+ constructor(req, do_req) {
214
+ this._do_req_id = do_req;
215
+ this._do_owner = req[0];
216
+ this._metadata1 = req[1];
217
+ this._metadata2 = req[2];
218
+ this._metadata3 = req[3];
219
+ this._metadata4 = req[4];
220
+ this._payload_metadata_obj = PayloadFactory.create_payload_metadata(this.payload_metadata);
221
+ this._input_metadata_obj = InputFactory.create_input_metadata(this.input_metadata);
222
+ }
223
+
224
+ get do_req_id() {
225
+ return this._do_req_id;
226
+ }
227
+
228
+ get do_owner() {
229
+ return this._do_owner;
230
+ }
231
+
232
+ get image_metadata() {
233
+ return this._metadata1;
234
+ }
235
+
236
+ get public_key() {
237
+ return this.image_metadata.split(':')[5];
238
+ }
239
+
240
+ get image_hash() {
241
+ return this.image_metadata.split(':')[1];
242
+ }
243
+
244
+ get payload_metadata() {
245
+ return this._metadata2;
246
+ }
247
+
248
+ get payload_metadata_obj() {
249
+ return this._payload_metadata_obj;
250
+ }
251
+
252
+ get input_metadata_obj() {
253
+ return this._input_metadata_obj;
254
+ }
255
+
256
+ get input_metadata() {
257
+ return this._metadata3;
258
+ }
259
+
260
+ get node_address() {
261
+ return this._metadata4;
262
+ }
263
+ }
264
+
265
+ module.exports = {
266
+ Order,
267
+ MetadataBase,
268
+ PayloadFactory,
269
+ InputFactory,
270
+ InputMetadataV0,
271
+ PayloadMetadataV0,
272
+ InputMetadataV1,
273
+ PayloadMetadataV1,
274
+ DOReqMetadata
275
+ }