@xyo-network/image-thumbnail-plugin 2.70.11 → 2.70.13
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/cjs/Witness/Witness.js +142 -146
- package/dist/cjs/Witness/Witness.js.map +1 -1
- package/dist/docs.json +3820 -2370
- package/dist/esm/Witness/Witness.js +134 -143
- package/dist/esm/Witness/Witness.js.map +1 -1
- package/dist/types/Witness/Witness.d.ts +27 -8
- package/dist/types/Witness/Witness.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/Witness/Witness.ts +151 -154
|
@@ -1,70 +1,18 @@
|
|
|
1
|
+
import { promises as dnsPromises } from 'node:dns';
|
|
1
2
|
import { axios } from '@xyo-network/axios';
|
|
2
3
|
import { PayloadHasher } from '@xyo-network/core';
|
|
3
4
|
import { ImageThumbnailSchema } from '@xyo-network/image-thumbnail-payload-plugin';
|
|
4
|
-
import { isPayload, ModuleErrorSchema } from '@xyo-network/payload-model';
|
|
5
5
|
import { AbstractWitness } from '@xyo-network/witness';
|
|
6
6
|
import { subClass } from 'gm';
|
|
7
7
|
import { sync as hasbin } from 'hasbin';
|
|
8
8
|
import { sha256 } from 'hash-wasm';
|
|
9
9
|
import compact from 'lodash/compact';
|
|
10
|
-
import isBuffer from 'lodash/isBuffer';
|
|
11
10
|
import { LRUCache } from 'lru-cache';
|
|
12
11
|
import shajs from 'sha.js';
|
|
13
12
|
import Url from 'url-parse';
|
|
14
13
|
import { ImageThumbnailWitnessConfigSchema } from './Config';
|
|
15
14
|
//TODO: Break this into two Witnesses?
|
|
16
15
|
const gm = subClass({ imageMagick: '7+' });
|
|
17
|
-
export const binaryToSha256 = async (data) => {
|
|
18
|
-
await PayloadHasher.wasmInitialized;
|
|
19
|
-
if (PayloadHasher.wasmSupport.canUseWasm) {
|
|
20
|
-
try {
|
|
21
|
-
return await sha256(data);
|
|
22
|
-
}
|
|
23
|
-
catch (ex) {
|
|
24
|
-
PayloadHasher.wasmSupport.allowWasm = false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
28
|
-
return shajs('sha256').update(data).digest().toString();
|
|
29
|
-
};
|
|
30
|
-
const checkIpfsUrl = (urlToCheck) => {
|
|
31
|
-
const url = new Url(urlToCheck);
|
|
32
|
-
let protocol = url.protocol;
|
|
33
|
-
let host = url.host;
|
|
34
|
-
let path = url.pathname;
|
|
35
|
-
const query = url.query;
|
|
36
|
-
if (protocol === 'ipfs:') {
|
|
37
|
-
protocol = 'https:';
|
|
38
|
-
host = 'cloudflare-ipfs.com';
|
|
39
|
-
path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`;
|
|
40
|
-
const root = `${protocol}//${host}/${path}`;
|
|
41
|
-
return query?.length > 0 ? `root?${query}` : root;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
return urlToCheck;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const checkDataUrl = (url) => {
|
|
48
|
-
if (url.startsWith('data:image')) {
|
|
49
|
-
const data = url.split(',')[1];
|
|
50
|
-
if (data) {
|
|
51
|
-
const buffer = Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)));
|
|
52
|
-
console.log(`data buffer: ${buffer.length}`);
|
|
53
|
-
return [buffer, undefined];
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const error = {
|
|
57
|
-
message: 'Invalid data Url',
|
|
58
|
-
schema: ModuleErrorSchema,
|
|
59
|
-
url,
|
|
60
|
-
};
|
|
61
|
-
return [undefined, error];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return [undefined, undefined];
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
16
|
export class ImageThumbnailWitness extends AbstractWitness {
|
|
69
17
|
static configSchemas = [ImageThumbnailWitnessConfigSchema];
|
|
70
18
|
_cache;
|
|
@@ -87,119 +35,162 @@ export class ImageThumbnailWitness extends AbstractWitness {
|
|
|
87
35
|
get width() {
|
|
88
36
|
return this.config.width ?? 128;
|
|
89
37
|
}
|
|
38
|
+
static async binaryToSha256(data) {
|
|
39
|
+
await PayloadHasher.wasmInitialized;
|
|
40
|
+
if (PayloadHasher.wasmSupport.canUseWasm) {
|
|
41
|
+
try {
|
|
42
|
+
return await sha256(data);
|
|
43
|
+
}
|
|
44
|
+
catch (ex) {
|
|
45
|
+
PayloadHasher.wasmSupport.allowWasm = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
49
|
+
return shajs('sha256').update(data).digest().toString();
|
|
50
|
+
}
|
|
51
|
+
static bufferFromDataUrl(url) {
|
|
52
|
+
if (url.startsWith('data:image')) {
|
|
53
|
+
const data = url.split(',')[1];
|
|
54
|
+
if (data) {
|
|
55
|
+
const buffer = Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)));
|
|
56
|
+
console.log(`data buffer: ${buffer.length}`);
|
|
57
|
+
return buffer;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const error = {
|
|
61
|
+
message: 'Invalid data Url',
|
|
62
|
+
name: 'ImageThumbnailWitnessError',
|
|
63
|
+
url,
|
|
64
|
+
};
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static checkIpfsUrl(urlToCheck) {
|
|
70
|
+
const url = new Url(urlToCheck);
|
|
71
|
+
let protocol = url.protocol;
|
|
72
|
+
let host = url.host;
|
|
73
|
+
let path = url.pathname;
|
|
74
|
+
const query = url.query;
|
|
75
|
+
if (protocol === 'ipfs:') {
|
|
76
|
+
protocol = 'https:';
|
|
77
|
+
host = 'cloudflare-ipfs.com';
|
|
78
|
+
path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`;
|
|
79
|
+
const root = `${protocol}//${host}/${path}`;
|
|
80
|
+
return query?.length > 0 ? `root?${query}` : root;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return urlToCheck;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
90
86
|
async observeHandler(payloads = []) {
|
|
91
87
|
if (!hasbin('magick')) {
|
|
92
88
|
throw Error('ImageMagick is required for this witness');
|
|
93
89
|
}
|
|
94
|
-
|
|
90
|
+
return compact(await Promise.all(payloads.map(async ({ url }) => {
|
|
95
91
|
const cachedResult = this.cache.get(url);
|
|
96
92
|
if (cachedResult) {
|
|
97
|
-
return
|
|
93
|
+
return cachedResult;
|
|
98
94
|
}
|
|
95
|
+
let result;
|
|
99
96
|
//if it is a data URL, return a Buffer
|
|
100
|
-
const
|
|
97
|
+
const dataBuffer = ImageThumbnailWitness.bufferFromDataUrl(url);
|
|
101
98
|
if (dataBuffer) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
//if it is ipfs, go through cloud flair
|
|
108
|
-
const mutatedUrl = checkIpfsUrl(url);
|
|
109
|
-
try {
|
|
110
|
-
return [
|
|
99
|
+
result = {
|
|
100
|
+
schema: ImageThumbnailSchema,
|
|
101
|
+
sourceHash: await ImageThumbnailWitness.binaryToSha256(dataBuffer),
|
|
102
|
+
sourceUrl: url,
|
|
111
103
|
url,
|
|
112
|
-
|
|
113
|
-
responseType: 'arraybuffer',
|
|
114
|
-
}),
|
|
115
|
-
];
|
|
104
|
+
};
|
|
116
105
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const errorPayload = {
|
|
122
|
-
code: axiosError.code,
|
|
123
|
-
message: axiosError.message,
|
|
124
|
-
schema: ModuleErrorSchema,
|
|
125
|
-
status: axiosError.status,
|
|
126
|
-
url,
|
|
127
|
-
};
|
|
128
|
-
return [url, errorPayload];
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
throw ex;
|
|
132
|
-
}
|
|
106
|
+
else {
|
|
107
|
+
//if it is ipfs, go through cloud flair
|
|
108
|
+
const mutatedUrl = ImageThumbnailWitness.checkIpfsUrl(url);
|
|
109
|
+
result = await this.fromHttp(mutatedUrl);
|
|
133
110
|
}
|
|
111
|
+
this.cache.set(url, result);
|
|
112
|
+
return result;
|
|
134
113
|
})));
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const response = urlResult;
|
|
146
|
-
if (response.status >= 200 && response.status < 300) {
|
|
147
|
-
const contentType = response.headers['content-type']?.toString();
|
|
148
|
-
if (contentType.split('/')[0] !== 'image') {
|
|
149
|
-
const error = {
|
|
150
|
-
message: `Invalid file type: ${contentType}`,
|
|
151
|
-
schema: ModuleErrorSchema,
|
|
152
|
-
url,
|
|
153
|
-
};
|
|
154
|
-
this.cache.set(url, error);
|
|
155
|
-
return error;
|
|
156
|
-
}
|
|
157
|
-
sourceBuffer = Buffer.from(response.data, 'binary');
|
|
114
|
+
}
|
|
115
|
+
async createThumbnail(sourceBuffer) {
|
|
116
|
+
const thumb = await new Promise((resolve, reject) => {
|
|
117
|
+
gm(sourceBuffer)
|
|
118
|
+
.quality(this.quality)
|
|
119
|
+
.resize(this.width, this.height)
|
|
120
|
+
.flatten()
|
|
121
|
+
.toBuffer(this.encoding, (error, buffer) => {
|
|
122
|
+
if (error) {
|
|
123
|
+
reject(error);
|
|
158
124
|
}
|
|
159
125
|
else {
|
|
160
|
-
|
|
161
|
-
schema: ModuleErrorSchema,
|
|
162
|
-
status: response.status,
|
|
163
|
-
url,
|
|
164
|
-
};
|
|
165
|
-
this.cache.set(url, error);
|
|
166
|
-
return error;
|
|
126
|
+
resolve(buffer);
|
|
167
127
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
return `data:image/png;base64,${thumb.toString('base64')}`;
|
|
131
|
+
}
|
|
132
|
+
async fromHttp(url) {
|
|
133
|
+
let response;
|
|
134
|
+
let dnsResult;
|
|
135
|
+
try {
|
|
136
|
+
const urlObj = new Url(url);
|
|
137
|
+
dnsResult = await dnsPromises.resolve(urlObj.host);
|
|
138
|
+
console.log(`dnsResult: ${JSON.stringify(dnsResult, null, 2)}`);
|
|
139
|
+
}
|
|
140
|
+
catch (ex) {
|
|
141
|
+
const error = ex;
|
|
142
|
+
const result = {
|
|
143
|
+
http: {
|
|
144
|
+
dnsError: error.code,
|
|
145
|
+
},
|
|
146
|
+
schema: ImageThumbnailSchema,
|
|
147
|
+
sourceUrl: url,
|
|
148
|
+
};
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
response = await axios.get(url, {
|
|
153
|
+
responseType: 'arraybuffer',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (ex) {
|
|
157
|
+
const axiosError = ex;
|
|
158
|
+
if (axiosError.isAxiosError) {
|
|
159
|
+
//selectively pick fields from AxiosError
|
|
184
160
|
const result = {
|
|
161
|
+
http: {
|
|
162
|
+
ipAddress: dnsResult[0],
|
|
163
|
+
status: axiosError.status,
|
|
164
|
+
},
|
|
185
165
|
schema: ImageThumbnailSchema,
|
|
186
|
-
sourceHash: await binaryToSha256(sourceBuffer),
|
|
187
166
|
sourceUrl: url,
|
|
188
|
-
url: `data:image/png;base64,${thumb.toString('base64')}`,
|
|
189
167
|
};
|
|
190
|
-
this.cache.set(url, result);
|
|
191
168
|
return result;
|
|
192
169
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
message: 'Failed to resize image',
|
|
196
|
-
schema: ModuleErrorSchema,
|
|
197
|
-
url,
|
|
198
|
-
};
|
|
199
|
-
this.cache.set(url, error);
|
|
200
|
-
return error;
|
|
170
|
+
else {
|
|
171
|
+
throw ex;
|
|
201
172
|
}
|
|
202
|
-
}
|
|
173
|
+
}
|
|
174
|
+
const result = {
|
|
175
|
+
http: {
|
|
176
|
+
status: response.status,
|
|
177
|
+
},
|
|
178
|
+
schema: ImageThumbnailSchema,
|
|
179
|
+
sourceUrl: url,
|
|
180
|
+
};
|
|
181
|
+
if (response.status >= 200 && response.status < 300) {
|
|
182
|
+
const contentType = response.headers['content-type']?.toString();
|
|
183
|
+
if (contentType.split('/')[0] !== 'image') {
|
|
184
|
+
result.mime = result.mime ?? {};
|
|
185
|
+
result.mime.invalid = true;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const sourceBuffer = Buffer.from(response.data, 'binary');
|
|
189
|
+
result.sourceHash = await ImageThumbnailWitness.binaryToSha256(sourceBuffer);
|
|
190
|
+
result.url = await this.createThumbnail(sourceBuffer);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
203
194
|
}
|
|
204
195
|
}
|
|
205
196
|
//# sourceMappingURL=Witness.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../../src/Witness/Witness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Witness.js","sourceRoot":"","sources":["../../../src/Witness/Witness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,KAAK,EAA6B,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAkB,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAElG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAC7B,O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AK,OAAO,EAAE;gBACzC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAA;gBAC/B,MAAM,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;aAC3B;iBAAM;gBACL,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;gBACzD,MAAM,CAAC,UAAU,GAAG,MAAM,qBAAqB,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;gBAC5E,MAAM,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;aACtD;SACF;QACD,OAAO,MAAM,CAAA;IACf,CAAC"}
|
|
@@ -1,25 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImageThumbnail } from '@xyo-network/image-thumbnail-payload-plugin';
|
|
2
2
|
import { UrlPayload } from '@xyo-network/url-payload-plugin';
|
|
3
3
|
import { AbstractWitness } from '@xyo-network/witness';
|
|
4
4
|
import { LRUCache } from 'lru-cache';
|
|
5
5
|
import { ImageThumbnailWitnessParams } from './Params';
|
|
6
|
-
export
|
|
6
|
+
export interface ImageThumbnailWitnessError extends Error {
|
|
7
|
+
name: 'ImageThumbnailWitnessError';
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DnsError extends Error {
|
|
11
|
+
code: string;
|
|
12
|
+
}
|
|
7
13
|
export declare class ImageThumbnailWitness<TParams extends ImageThumbnailWitnessParams = ImageThumbnailWitnessParams> extends AbstractWitness<TParams> {
|
|
8
14
|
static configSchemas: "network.xyo.image.thumbnail.witness.config"[];
|
|
9
15
|
private _cache?;
|
|
10
|
-
get cache(): LRUCache<string,
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
get cache(): LRUCache<string, import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
17
|
+
http?: {
|
|
18
|
+
dnsError?: string | undefined;
|
|
19
|
+
ipAddress?: string | undefined;
|
|
20
|
+
status?: number | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
mime?: {
|
|
23
|
+
invalid?: boolean | undefined;
|
|
24
|
+
type?: string | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
sourceHash?: string | undefined;
|
|
13
27
|
sourceUrl: string;
|
|
14
|
-
url
|
|
28
|
+
url?: string | undefined;
|
|
15
29
|
} & {
|
|
16
30
|
schema: "network.xyo.image.thumbnail";
|
|
17
|
-
}
|
|
31
|
+
}, unknown>;
|
|
18
32
|
get encoding(): "PNG";
|
|
19
33
|
get height(): number;
|
|
20
34
|
get maxCacheEntries(): number;
|
|
21
35
|
get quality(): number;
|
|
22
36
|
get width(): number;
|
|
23
|
-
|
|
37
|
+
private static binaryToSha256;
|
|
38
|
+
private static bufferFromDataUrl;
|
|
39
|
+
private static checkIpfsUrl;
|
|
40
|
+
protected observeHandler(payloads?: UrlPayload[]): Promise<ImageThumbnail[]>;
|
|
41
|
+
private createThumbnail;
|
|
42
|
+
private fromHttp;
|
|
24
43
|
}
|
|
25
44
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../../src/Witness/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../../src/Witness/Witness.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAwB,MAAM,6CAA6C,CAAA;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAKtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAKpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AAMtD,MAAM,WAAW,0BAA2B,SAAQ,KAAK;IACvD,IAAI,EAAE,4BAA4B,CAAA;IAClC,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAA;CACb;AAED,qBAAa,qBAAqB,CAAC,OAAO,SAAS,2BAA2B,GAAG,2BAA2B,CAAE,SAAQ,eAAe,CAAC,OAAO,CAAC;IAC5I,OAAgB,aAAa,iDAAsC;IAEnE,OAAO,CAAC,MAAM,CAAC,CAAkC;IAEjD,IAAI,KAAK;;;;;;;;;;;;;;;gBAGR;IAED,IAAI,QAAQ,UAEX;IAED,IAAI,MAAM,WAET;IAED,IAAI,eAAe,WAElB;IAED,IAAI,OAAO,WAEV;IAED,IAAI,KAAK,WAER;mBAEoB,cAAc;IAanC,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkBhC,OAAO,CAAC,MAAM,CAAC,YAAY;cAiBF,cAAc,CAAC,QAAQ,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;YAmCjF,eAAe;YAiBf,QAAQ;CA6DvB"}
|
package/package.json
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xyo-network/axios": "~2.70.
|
|
14
|
-
"@xyo-network/core": "~2.70.
|
|
15
|
-
"@xyo-network/image-thumbnail-payload-plugin": "~2.70.
|
|
16
|
-
"@xyo-network/module": "~2.70.
|
|
17
|
-
"@xyo-network/payload-model": "~2.70.
|
|
18
|
-
"@xyo-network/payloadset-plugin": "~2.70.
|
|
19
|
-
"@xyo-network/url-payload-plugin": "~2.70.
|
|
20
|
-
"@xyo-network/witness": "~2.70.
|
|
13
|
+
"@xyo-network/axios": "~2.70.15",
|
|
14
|
+
"@xyo-network/core": "~2.70.15",
|
|
15
|
+
"@xyo-network/image-thumbnail-payload-plugin": "~2.70.13",
|
|
16
|
+
"@xyo-network/module": "~2.70.15",
|
|
17
|
+
"@xyo-network/payload-model": "~2.70.15",
|
|
18
|
+
"@xyo-network/payloadset-plugin": "~2.70.15",
|
|
19
|
+
"@xyo-network/url-payload-plugin": "~2.70.15",
|
|
20
|
+
"@xyo-network/witness": "~2.70.15",
|
|
21
21
|
"gm": "^1.25.0",
|
|
22
22
|
"hasbin": "^1.2.3",
|
|
23
23
|
"hash-wasm": "^4.9.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
},
|
|
68
68
|
"sideEffects": false,
|
|
69
69
|
"types": "dist/types/index.d.ts",
|
|
70
|
-
"version": "2.70.
|
|
70
|
+
"version": "2.70.13"
|
|
71
71
|
}
|