@xyo-network/file-browser-plugin 2.99.4 → 2.99.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.
- package/dist/browser/BrowserFileWitness.d.cts +3 -3
- package/dist/browser/BrowserFileWitness.d.mts +3 -3
- package/dist/browser/BrowserFileWitness.d.ts +3 -3
- package/dist/browser/Payload.d.cts +1 -1
- package/dist/browser/Payload.d.mts +1 -1
- package/dist/browser/Payload.d.ts +1 -1
- package/dist/browser/PluginBrowser.d.cts +1 -1
- package/dist/browser/PluginBrowser.d.mts +1 -1
- package/dist/browser/PluginBrowser.d.ts +1 -1
- package/dist/browser/Witness.d.cts +1 -1
- package/dist/browser/Witness.d.mts +1 -1
- package/dist/browser/Witness.d.ts +1 -1
- package/dist/browser/index.cjs +37 -15
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +7 -7
- package/dist/browser/index.d.mts +7 -7
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/{index.js → index.mjs} +40 -16
- package/dist/{node/index.js.map → browser/index.mjs.map} +1 -1
- package/dist/browser/util/index.d.cts +1 -1
- package/dist/browser/util/index.d.mts +1 -1
- package/dist/browser/util/index.d.ts +1 -1
- package/dist/neutral/BrowserFileWitness.d.cts +3 -3
- package/dist/neutral/BrowserFileWitness.d.mts +3 -3
- package/dist/neutral/BrowserFileWitness.d.ts +3 -3
- package/dist/neutral/Payload.d.cts +1 -1
- package/dist/neutral/Payload.d.mts +1 -1
- package/dist/neutral/Payload.d.ts +1 -1
- package/dist/neutral/PluginBrowser.d.cts +1 -1
- package/dist/neutral/PluginBrowser.d.mts +1 -1
- package/dist/neutral/PluginBrowser.d.ts +1 -1
- package/dist/neutral/Witness.d.cts +1 -1
- package/dist/neutral/Witness.d.mts +1 -1
- package/dist/neutral/Witness.d.ts +1 -1
- package/dist/neutral/index.cjs +37 -15
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +7 -7
- package/dist/neutral/index.d.mts +7 -7
- package/dist/neutral/index.d.ts +7 -7
- package/dist/neutral/{index.js → index.mjs} +40 -16
- package/dist/{browser/index.js.map → neutral/index.mjs.map} +1 -1
- package/dist/neutral/util/index.d.cts +1 -1
- package/dist/neutral/util/index.d.mts +1 -1
- package/dist/neutral/util/index.d.ts +1 -1
- package/dist/node/BrowserFileWitness.d.cts +3 -3
- package/dist/node/BrowserFileWitness.d.mts +3 -3
- package/dist/node/BrowserFileWitness.d.ts +3 -3
- package/dist/node/Payload.d.cts +1 -1
- package/dist/node/Payload.d.mts +1 -1
- package/dist/node/Payload.d.ts +1 -1
- package/dist/node/PluginBrowser.d.cts +1 -1
- package/dist/node/PluginBrowser.d.mts +1 -1
- package/dist/node/PluginBrowser.d.ts +1 -1
- package/dist/node/Witness.d.cts +1 -1
- package/dist/node/Witness.d.mts +1 -1
- package/dist/node/Witness.d.ts +1 -1
- package/dist/node/index.cjs +43 -19
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +7 -7
- package/dist/node/index.d.mts +7 -7
- package/dist/node/index.d.ts +7 -7
- package/dist/node/{index.js → index.mjs} +47 -20
- package/dist/{neutral/index.js.map → node/index.mjs.map} +1 -1
- package/dist/node/util/index.d.cts +1 -1
- package/dist/node/util/index.d.mts +1 -1
- package/dist/node/util/index.d.ts +1 -1
- package/package.json +15 -15
- package/src/BrowserFileWitness.ts +6 -6
- package/src/Payload.ts +1 -1
- package/src/PluginBrowser.ts +2 -2
- package/src/Witness.ts +2 -2
- package/src/index.ts +7 -7
- package/src/util/index.ts +1 -1
|
@@ -3,7 +3,7 @@ import { AbstractWitness } from '@xyo-network/abstract-witness';
|
|
|
3
3
|
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
4
4
|
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
import { WitnessModule, WitnessParams } from '@xyo-network/witness-model';
|
|
6
|
-
import { FileWitnessConfig } from './Config.
|
|
6
|
+
import { FileWitnessConfig } from './Config.ts';
|
|
7
7
|
export type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>;
|
|
8
8
|
export declare abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {
|
|
9
9
|
static readonly configSchemas: Schema[];
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name in all)
|
|
10
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -53,30 +54,49 @@ var FileSchema = "network.xyo.file";
|
|
|
53
54
|
|
|
54
55
|
// src/util/GenerateDataUri.ts
|
|
55
56
|
var import_base = require("@scure/base");
|
|
56
|
-
var generateDataUri = (data) => {
|
|
57
|
+
var generateDataUri = /* @__PURE__ */ __name((data) => {
|
|
57
58
|
return `data:application/octet-stream;base64,${import_base.base64.encode(data)}`;
|
|
58
|
-
};
|
|
59
|
+
}, "generateDataUri");
|
|
59
60
|
|
|
60
61
|
// src/Witness.ts
|
|
61
62
|
var import_abstract_witness = require("@xyo-network/abstract-witness");
|
|
62
63
|
var FileWitness = class extends import_abstract_witness.AbstractWitness {
|
|
63
|
-
static
|
|
64
|
+
static {
|
|
65
|
+
__name(this, "FileWitness");
|
|
66
|
+
}
|
|
67
|
+
static configSchemas = [
|
|
68
|
+
...super.configSchemas,
|
|
69
|
+
FileWitnessConfigSchema
|
|
70
|
+
];
|
|
64
71
|
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
65
72
|
observeHandler(payloads) {
|
|
66
|
-
return [
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
...payloads?.[0],
|
|
76
|
+
schema: FileSchema
|
|
77
|
+
}
|
|
78
|
+
];
|
|
67
79
|
}
|
|
68
80
|
};
|
|
69
81
|
|
|
70
82
|
// src/BrowserFileWitness.ts
|
|
71
83
|
var BrowserFileWitness = class extends FileWitness {
|
|
72
|
-
static
|
|
84
|
+
static {
|
|
85
|
+
__name(this, "BrowserFileWitness");
|
|
86
|
+
}
|
|
87
|
+
static configSchemas = [
|
|
88
|
+
...super.configSchemas,
|
|
89
|
+
FileWitnessConfigSchema
|
|
90
|
+
];
|
|
73
91
|
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
74
92
|
async observeHandler() {
|
|
75
93
|
try {
|
|
76
94
|
const [payload] = await this.witnessBrowserFile();
|
|
77
95
|
const { logger } = this.params;
|
|
78
96
|
logger?.log(`BrowserFileWitness: ${await import_payload_builder.PayloadBuilder.dataHash(payload)}`);
|
|
79
|
-
return [
|
|
97
|
+
return [
|
|
98
|
+
payload
|
|
99
|
+
];
|
|
80
100
|
} catch (e) {
|
|
81
101
|
throw new Error(`Error reading file: ${e}`);
|
|
82
102
|
}
|
|
@@ -121,13 +141,15 @@ var isFilePayload = (0, import_payload_model.isPayloadOfSchemaType)(FileSchema);
|
|
|
121
141
|
// src/PluginBrowser.ts
|
|
122
142
|
var import_payload_model2 = require("@xyo-network/payload-model");
|
|
123
143
|
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
124
|
-
var BrowserFilePlugin = () => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
144
|
+
var BrowserFilePlugin = /* @__PURE__ */ __name(() => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)({
|
|
145
|
+
required: {
|
|
146
|
+
[FileSchema]: 1
|
|
147
|
+
},
|
|
148
|
+
schema: import_payload_model2.PayloadSetSchema
|
|
149
|
+
}, {
|
|
150
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
151
|
+
const result = await BrowserFileWitness.create(params);
|
|
152
|
+
return result;
|
|
153
|
+
}, "witness")
|
|
154
|
+
}), "BrowserFilePlugin");
|
|
133
155
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/BrowserFileWitness.ts","../../src/Config.ts","../../src/Schema.ts","../../src/util/GenerateDataUri.ts","../../src/Witness.ts","../../src/Payload.ts","../../src/PluginBrowser.ts"],"sourcesContent":["export * from './BrowserFileWitness.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/BrowserFileWitness.ts","../../src/Config.ts","../../src/Schema.ts","../../src/util/GenerateDataUri.ts","../../src/Witness.ts","../../src/Payload.ts","../../src/PluginBrowser.ts"],"sourcesContent":["export * from './BrowserFileWitness.ts'\nexport * from './Config.ts'\nexport * from './Params.ts'\nexport * from './Payload.ts'\n// eslint-disable-next-line import/no-default-export\nexport { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.ts'\nexport * from './Schema.ts'\nexport * from './Witness.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport shajs from 'sha.js'\n\nimport { FileWitnessConfigSchema } from './Config.ts'\nimport { BrowserFileWitnessAdditionalParams } from './Params.ts'\nimport { FilePayload } from './Payload.ts'\nimport { FileSchema } from './Schema.ts'\nimport { generateDataUri } from './util/index.ts'\nimport { FileWitness, FileWitnessParams } from './Witness.ts'\n\ntype BrowserFileWitnessParams = FileWitnessParams & BrowserFileWitnessAdditionalParams\n\nexport class BrowserFileWitness extends FileWitness<BrowserFileWitnessParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, FileWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = FileWitnessConfigSchema\n\n protected override async observeHandler() {\n try {\n const [payload] = await this.witnessBrowserFile()\n const { logger } = this.params\n logger?.log(`BrowserFileWitness: ${await PayloadBuilder.dataHash(payload)}`)\n return [payload]\n } catch (e) {\n throw new Error(`Error reading file: ${e}`)\n }\n }\n\n private readBinaryFile(file: File): Promise<Uint8Array> {\n return new Promise((resolve, reject) => {\n const fileReader = new FileReader()\n fileReader.addEventListener('load', (event) => {\n const arrayBuffer = event.target?.result as ArrayBuffer\n resolve(new Uint8Array(arrayBuffer))\n })\n // eslint-disable-next-line unicorn/prefer-add-event-listener\n fileReader.onerror = () => reject(fileReader.error)\n // eslint-disable-next-line unicorn/prefer-blob-reading-methods\n fileReader.readAsArrayBuffer(file)\n })\n }\n\n private async witnessBrowserFile(): Promise<[FilePayload, Uint8Array]> {\n const file = assertEx(this.params.file, () => 'File is missing from params')\n const fileBinary = await this.readBinaryFile(file)\n const result = new Uint8Array(fileBinary)\n const hash = shajs('sha256').update(result).digest('hex').padStart(64, '0')\n\n return [\n {\n hash,\n length: fileBinary.byteLength,\n meta: {\n name: file.name,\n type: file.type,\n },\n modified: file.lastModified,\n schema: FileSchema,\n uri: this.config.storage === 'data-uri' ? generateDataUri(fileBinary) : file.name,\n },\n fileBinary,\n ]\n }\n}\n","import { WitnessConfig } from '@xyo-network/witness-model'\n\nexport type FileWitnessConfigSchema = 'network.xyo.file.witness.config'\nexport const FileWitnessConfigSchema: FileWitnessConfigSchema = 'network.xyo.file.witness.config'\n\nexport type FileWitnessConfig = WitnessConfig<{\n schema: FileWitnessConfigSchema\n storage?: 'data-uri'\n}>\n","export type FileSchema = 'network.xyo.file'\nexport const FileSchema: FileSchema = 'network.xyo.file'\n","import { base64 } from '@scure/base'\n\nexport const generateDataUri = (data: Uint8Array): string => {\n return `data:application/octet-stream;base64,${base64.encode(data)}`\n}\n","import { Promisable } from '@xylabs/promise'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessModule, WitnessParams } from '@xyo-network/witness-model'\n\nimport { FileWitnessConfig, FileWitnessConfigSchema } from './Config.ts'\nimport { FileSchema } from './Schema.ts'\n\nexport type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>\n\n// Abstract so that derived classes provide a type for the file param and methods to parse it\nexport abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, FileWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = FileWitnessConfigSchema\n\n protected override observeHandler(payloads?: Payload[]): Promisable<Payload[]> {\n return [{ ...payloads?.[0], schema: FileSchema }]\n }\n}\n","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nimport { FileSchema } from './Schema.ts'\n\nexport type BinaryDataHash = string\n\n/** @description File location and optional data */\nexport type FilePayload = Payload<\n {\n created?: number\n hash: BinaryDataHash\n length: number\n /** @field Storage specific meta data */\n meta?: Record<string, string | number>\n modified?: number\n uri: string\n },\n FileSchema\n>\n\nexport const isFilePayload = isPayloadOfSchemaType<FilePayload>(FileSchema)\n","import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { BrowserFileWitness } from './BrowserFileWitness.ts'\nimport { FileSchema } from './Schema.ts'\n\nexport const BrowserFilePlugin = () =>\n createPayloadSetWitnessPlugin<BrowserFileWitness>(\n { required: { [FileSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await BrowserFileWitness.create(params)\n return result\n },\n },\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;ACAA,oBAAyB;AACzB,6BAA+B;AAE/B,iBAAkB;;;ACAX,IAAMA,0BAAmD;;;ACFzD,IAAMC,aAAyB;;;ACDtC,kBAAuB;AAEhB,IAAMC,kBAAkB,wBAACC,SAAAA;AAC9B,SAAO,wCAAwCC,mBAAOC,OAAOF,IAAAA,CAAAA;AAC/D,GAF+B;;;ACD/B,8BAAgC;AAWzB,IAAeG,cAAf,cAA0FC,wCAAAA;EAXjG,OAWiGA;;;EAC/F,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEpCE,eAAeC,UAA6C;AAC7E,WAAO;MAAC;QAAE,GAAGA,WAAW,CAAA;QAAIC,QAAQC;MAAW;;EACjD;AACF;;;AJLO,IAAMC,qBAAN,cAAiCC,YAAAA;EAdxC,OAcwCA;;;EACtC,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,iBAAiB;AACxC,QAAI;AACF,YAAM,CAACC,OAAAA,IAAW,MAAM,KAAKC,mBAAkB;AAC/C,YAAM,EAAEC,OAAM,IAAK,KAAKC;AACxBD,cAAQE,IAAI,uBAAuB,MAAMC,sCAAeC,SAASN,OAAAA,CAAAA,EAAU;AAC3E,aAAO;QAACA;;IACV,SAASO,GAAG;AACV,YAAM,IAAIC,MAAM,uBAAuBD,CAAAA,EAAG;IAC5C;EACF;EAEQE,eAAeC,MAAiC;AACtD,WAAO,IAAIC,QAAQ,CAACC,SAASC,WAAAA;AAC3B,YAAMC,aAAa,IAAIC,WAAAA;AACvBD,iBAAWE,iBAAiB,QAAQ,CAACC,UAAAA;AACnC,cAAMC,cAAcD,MAAME,QAAQC;AAClCR,gBAAQ,IAAIS,WAAWH,WAAAA,CAAAA;MACzB,CAAA;AAEAJ,iBAAWQ,UAAU,MAAMT,OAAOC,WAAWS,KAAK;AAElDT,iBAAWU,kBAAkBd,IAAAA;IAC/B,CAAA;EACF;EAEA,MAAcT,qBAAyD;AACrE,UAAMS,WAAOe,wBAAS,KAAKtB,OAAOO,MAAM,MAAM,6BAAA;AAC9C,UAAMgB,aAAa,MAAM,KAAKjB,eAAeC,IAAAA;AAC7C,UAAMU,SAAS,IAAIC,WAAWK,UAAAA;AAC9B,UAAMC,WAAOC,WAAAA,SAAM,QAAA,EAAUC,OAAOT,MAAAA,EAAQU,OAAO,KAAA,EAAOC,SAAS,IAAI,GAAA;AAEvE,WAAO;MACL;QACEJ;QACAK,QAAQN,WAAWO;QACnBC,MAAM;UACJC,MAAMzB,KAAKyB;UACXC,MAAM1B,KAAK0B;QACb;QACAC,UAAU3B,KAAK4B;QACfC,QAAQC;QACRC,KAAK,KAAKC,OAAOC,YAAY,aAAaC,gBAAgBlB,UAAAA,IAAchB,KAAKyB;MAC/E;MACAT;;EAEJ;AACF;;;AKhEA,2BAA+C;AAoBxC,IAAMmB,oBAAgBC,4CAAmCC,UAAAA;;;ACpBhE,IAAAC,wBAAiC;AACjC,+BAA8C;AAKvC,IAAMC,oBAAoB,iCAC/BC,wDACE;EAAEC,UAAU;IAAE,CAACC,UAAAA,GAAa;EAAE;EAAGC,QAAQC;AAAiB,GAC1D;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,mBAAmBC,OAAOH,MAAAA;AAC/C,WAAOC;EACT,GAHS;AAIX,CAAA,GAR6B;","names":["FileWitnessConfigSchema","FileSchema","generateDataUri","data","base64","encode","FileWitness","AbstractWitness","configSchemas","FileWitnessConfigSchema","defaultConfigSchema","observeHandler","payloads","schema","FileSchema","BrowserFileWitness","FileWitness","configSchemas","FileWitnessConfigSchema","defaultConfigSchema","observeHandler","payload","witnessBrowserFile","logger","params","log","PayloadBuilder","dataHash","e","Error","readBinaryFile","file","Promise","resolve","reject","fileReader","FileReader","addEventListener","event","arrayBuffer","target","result","Uint8Array","onerror","error","readAsArrayBuffer","assertEx","fileBinary","hash","shajs","update","digest","padStart","length","byteLength","meta","name","type","modified","lastModified","schema","FileSchema","uri","config","storage","generateDataUri","isFilePayload","isPayloadOfSchemaType","FileSchema","import_payload_model","BrowserFilePlugin","createPayloadSetWitnessPlugin","required","FileSchema","schema","PayloadSetSchema","witness","params","result","BrowserFileWitness","create"]}
|
package/dist/neutral/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './BrowserFileWitness.
|
|
2
|
-
export * from './Config.
|
|
3
|
-
export * from './Params.
|
|
4
|
-
export * from './Payload.
|
|
5
|
-
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.
|
|
6
|
-
export * from './Schema.
|
|
7
|
-
export * from './Witness.
|
|
1
|
+
export * from './BrowserFileWitness.ts';
|
|
2
|
+
export * from './Config.ts';
|
|
3
|
+
export * from './Params.ts';
|
|
4
|
+
export * from './Payload.ts';
|
|
5
|
+
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.ts';
|
|
6
|
+
export * from './Schema.ts';
|
|
7
|
+
export * from './Witness.ts';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './BrowserFileWitness.
|
|
2
|
-
export * from './Config.
|
|
3
|
-
export * from './Params.
|
|
4
|
-
export * from './Payload.
|
|
5
|
-
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.
|
|
6
|
-
export * from './Schema.
|
|
7
|
-
export * from './Witness.
|
|
1
|
+
export * from './BrowserFileWitness.ts';
|
|
2
|
+
export * from './Config.ts';
|
|
3
|
+
export * from './Params.ts';
|
|
4
|
+
export * from './Payload.ts';
|
|
5
|
+
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.ts';
|
|
6
|
+
export * from './Schema.ts';
|
|
7
|
+
export * from './Witness.ts';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './BrowserFileWitness.
|
|
2
|
-
export * from './Config.
|
|
3
|
-
export * from './Params.
|
|
4
|
-
export * from './Payload.
|
|
5
|
-
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.
|
|
6
|
-
export * from './Schema.
|
|
7
|
-
export * from './Witness.
|
|
1
|
+
export * from './BrowserFileWitness.ts';
|
|
2
|
+
export * from './Config.ts';
|
|
3
|
+
export * from './Params.ts';
|
|
4
|
+
export * from './Payload.ts';
|
|
5
|
+
export { BrowserFilePlugin, BrowserFilePlugin as default } from './PluginBrowser.ts';
|
|
6
|
+
export * from './Schema.ts';
|
|
7
|
+
export * from './Witness.ts';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/BrowserFileWitness.ts
|
|
2
5
|
import { assertEx } from "@xylabs/assert";
|
|
3
6
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
@@ -11,30 +14,49 @@ var FileSchema = "network.xyo.file";
|
|
|
11
14
|
|
|
12
15
|
// src/util/GenerateDataUri.ts
|
|
13
16
|
import { base64 } from "@scure/base";
|
|
14
|
-
var generateDataUri = (data) => {
|
|
17
|
+
var generateDataUri = /* @__PURE__ */ __name((data) => {
|
|
15
18
|
return `data:application/octet-stream;base64,${base64.encode(data)}`;
|
|
16
|
-
};
|
|
19
|
+
}, "generateDataUri");
|
|
17
20
|
|
|
18
21
|
// src/Witness.ts
|
|
19
22
|
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
20
23
|
var FileWitness = class extends AbstractWitness {
|
|
21
|
-
static
|
|
24
|
+
static {
|
|
25
|
+
__name(this, "FileWitness");
|
|
26
|
+
}
|
|
27
|
+
static configSchemas = [
|
|
28
|
+
...super.configSchemas,
|
|
29
|
+
FileWitnessConfigSchema
|
|
30
|
+
];
|
|
22
31
|
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
23
32
|
observeHandler(payloads) {
|
|
24
|
-
return [
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
...payloads?.[0],
|
|
36
|
+
schema: FileSchema
|
|
37
|
+
}
|
|
38
|
+
];
|
|
25
39
|
}
|
|
26
40
|
};
|
|
27
41
|
|
|
28
42
|
// src/BrowserFileWitness.ts
|
|
29
43
|
var BrowserFileWitness = class extends FileWitness {
|
|
30
|
-
static
|
|
44
|
+
static {
|
|
45
|
+
__name(this, "BrowserFileWitness");
|
|
46
|
+
}
|
|
47
|
+
static configSchemas = [
|
|
48
|
+
...super.configSchemas,
|
|
49
|
+
FileWitnessConfigSchema
|
|
50
|
+
];
|
|
31
51
|
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
32
52
|
async observeHandler() {
|
|
33
53
|
try {
|
|
34
54
|
const [payload] = await this.witnessBrowserFile();
|
|
35
55
|
const { logger } = this.params;
|
|
36
56
|
logger?.log(`BrowserFileWitness: ${await PayloadBuilder.dataHash(payload)}`);
|
|
37
|
-
return [
|
|
57
|
+
return [
|
|
58
|
+
payload
|
|
59
|
+
];
|
|
38
60
|
} catch (e) {
|
|
39
61
|
throw new Error(`Error reading file: ${e}`);
|
|
40
62
|
}
|
|
@@ -79,15 +101,17 @@ var isFilePayload = isPayloadOfSchemaType(FileSchema);
|
|
|
79
101
|
// src/PluginBrowser.ts
|
|
80
102
|
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
81
103
|
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
82
|
-
var BrowserFilePlugin = () => createPayloadSetWitnessPlugin(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
var BrowserFilePlugin = /* @__PURE__ */ __name(() => createPayloadSetWitnessPlugin({
|
|
105
|
+
required: {
|
|
106
|
+
[FileSchema]: 1
|
|
107
|
+
},
|
|
108
|
+
schema: PayloadSetSchema
|
|
109
|
+
}, {
|
|
110
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
111
|
+
const result = await BrowserFileWitness.create(params);
|
|
112
|
+
return result;
|
|
113
|
+
}, "witness")
|
|
114
|
+
}), "BrowserFilePlugin");
|
|
91
115
|
export {
|
|
92
116
|
BrowserFilePlugin,
|
|
93
117
|
BrowserFileWitness,
|
|
@@ -97,4 +121,4 @@ export {
|
|
|
97
121
|
BrowserFilePlugin as default,
|
|
98
122
|
isFilePayload
|
|
99
123
|
};
|
|
100
|
-
//# sourceMappingURL=index.
|
|
124
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/BrowserFileWitness.ts","../../src/Config.ts","../../src/Schema.ts","../../src/util/GenerateDataUri.ts","../../src/Witness.ts","../../src/Payload.ts","../../src/PluginBrowser.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport shajs from 'sha.js'\n\nimport { FileWitnessConfigSchema } from './Config.
|
|
1
|
+
{"version":3,"sources":["../../src/BrowserFileWitness.ts","../../src/Config.ts","../../src/Schema.ts","../../src/util/GenerateDataUri.ts","../../src/Witness.ts","../../src/Payload.ts","../../src/PluginBrowser.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Schema } from '@xyo-network/payload-model'\nimport shajs from 'sha.js'\n\nimport { FileWitnessConfigSchema } from './Config.ts'\nimport { BrowserFileWitnessAdditionalParams } from './Params.ts'\nimport { FilePayload } from './Payload.ts'\nimport { FileSchema } from './Schema.ts'\nimport { generateDataUri } from './util/index.ts'\nimport { FileWitness, FileWitnessParams } from './Witness.ts'\n\ntype BrowserFileWitnessParams = FileWitnessParams & BrowserFileWitnessAdditionalParams\n\nexport class BrowserFileWitness extends FileWitness<BrowserFileWitnessParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, FileWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = FileWitnessConfigSchema\n\n protected override async observeHandler() {\n try {\n const [payload] = await this.witnessBrowserFile()\n const { logger } = this.params\n logger?.log(`BrowserFileWitness: ${await PayloadBuilder.dataHash(payload)}`)\n return [payload]\n } catch (e) {\n throw new Error(`Error reading file: ${e}`)\n }\n }\n\n private readBinaryFile(file: File): Promise<Uint8Array> {\n return new Promise((resolve, reject) => {\n const fileReader = new FileReader()\n fileReader.addEventListener('load', (event) => {\n const arrayBuffer = event.target?.result as ArrayBuffer\n resolve(new Uint8Array(arrayBuffer))\n })\n // eslint-disable-next-line unicorn/prefer-add-event-listener\n fileReader.onerror = () => reject(fileReader.error)\n // eslint-disable-next-line unicorn/prefer-blob-reading-methods\n fileReader.readAsArrayBuffer(file)\n })\n }\n\n private async witnessBrowserFile(): Promise<[FilePayload, Uint8Array]> {\n const file = assertEx(this.params.file, () => 'File is missing from params')\n const fileBinary = await this.readBinaryFile(file)\n const result = new Uint8Array(fileBinary)\n const hash = shajs('sha256').update(result).digest('hex').padStart(64, '0')\n\n return [\n {\n hash,\n length: fileBinary.byteLength,\n meta: {\n name: file.name,\n type: file.type,\n },\n modified: file.lastModified,\n schema: FileSchema,\n uri: this.config.storage === 'data-uri' ? generateDataUri(fileBinary) : file.name,\n },\n fileBinary,\n ]\n }\n}\n","import { WitnessConfig } from '@xyo-network/witness-model'\n\nexport type FileWitnessConfigSchema = 'network.xyo.file.witness.config'\nexport const FileWitnessConfigSchema: FileWitnessConfigSchema = 'network.xyo.file.witness.config'\n\nexport type FileWitnessConfig = WitnessConfig<{\n schema: FileWitnessConfigSchema\n storage?: 'data-uri'\n}>\n","export type FileSchema = 'network.xyo.file'\nexport const FileSchema: FileSchema = 'network.xyo.file'\n","import { base64 } from '@scure/base'\n\nexport const generateDataUri = (data: Uint8Array): string => {\n return `data:application/octet-stream;base64,${base64.encode(data)}`\n}\n","import { Promisable } from '@xylabs/promise'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessModule, WitnessParams } from '@xyo-network/witness-model'\n\nimport { FileWitnessConfig, FileWitnessConfigSchema } from './Config.ts'\nimport { FileSchema } from './Schema.ts'\n\nexport type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>\n\n// Abstract so that derived classes provide a type for the file param and methods to parse it\nexport abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, FileWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = FileWitnessConfigSchema\n\n protected override observeHandler(payloads?: Payload[]): Promisable<Payload[]> {\n return [{ ...payloads?.[0], schema: FileSchema }]\n }\n}\n","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nimport { FileSchema } from './Schema.ts'\n\nexport type BinaryDataHash = string\n\n/** @description File location and optional data */\nexport type FilePayload = Payload<\n {\n created?: number\n hash: BinaryDataHash\n length: number\n /** @field Storage specific meta data */\n meta?: Record<string, string | number>\n modified?: number\n uri: string\n },\n FileSchema\n>\n\nexport const isFilePayload = isPayloadOfSchemaType<FilePayload>(FileSchema)\n","import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { BrowserFileWitness } from './BrowserFileWitness.ts'\nimport { FileSchema } from './Schema.ts'\n\nexport const BrowserFilePlugin = () =>\n createPayloadSetWitnessPlugin<BrowserFileWitness>(\n { required: { [FileSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await BrowserFileWitness.create(params)\n return result\n },\n },\n )\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,sBAAsB;AAE/B,OAAOC,WAAW;;;ACAX,IAAMC,0BAAmD;;;ACFzD,IAAMC,aAAyB;;;ACDtC,SAASC,cAAc;AAEhB,IAAMC,kBAAkB,wBAACC,SAAAA;AAC9B,SAAO,wCAAwCC,OAAOC,OAAOF,IAAAA,CAAAA;AAC/D,GAF+B;;;ACD/B,SAASG,uBAAuB;AAWzB,IAAeC,cAAf,cAA0FC,gBAAAA;EAXjG,OAWiGA;;;EAC/F,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEpCE,eAAeC,UAA6C;AAC7E,WAAO;MAAC;QAAE,GAAGA,WAAW,CAAA;QAAIC,QAAQC;MAAW;;EACjD;AACF;;;AJLO,IAAMC,qBAAN,cAAiCC,YAAAA;EAdxC,OAcwCA;;;EACtC,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,MAAyBE,iBAAiB;AACxC,QAAI;AACF,YAAM,CAACC,OAAAA,IAAW,MAAM,KAAKC,mBAAkB;AAC/C,YAAM,EAAEC,OAAM,IAAK,KAAKC;AACxBD,cAAQE,IAAI,uBAAuB,MAAMC,eAAeC,SAASN,OAAAA,CAAAA,EAAU;AAC3E,aAAO;QAACA;;IACV,SAASO,GAAG;AACV,YAAM,IAAIC,MAAM,uBAAuBD,CAAAA,EAAG;IAC5C;EACF;EAEQE,eAAeC,MAAiC;AACtD,WAAO,IAAIC,QAAQ,CAACC,SAASC,WAAAA;AAC3B,YAAMC,aAAa,IAAIC,WAAAA;AACvBD,iBAAWE,iBAAiB,QAAQ,CAACC,UAAAA;AACnC,cAAMC,cAAcD,MAAME,QAAQC;AAClCR,gBAAQ,IAAIS,WAAWH,WAAAA,CAAAA;MACzB,CAAA;AAEAJ,iBAAWQ,UAAU,MAAMT,OAAOC,WAAWS,KAAK;AAElDT,iBAAWU,kBAAkBd,IAAAA;IAC/B,CAAA;EACF;EAEA,MAAcT,qBAAyD;AACrE,UAAMS,OAAOe,SAAS,KAAKtB,OAAOO,MAAM,MAAM,6BAAA;AAC9C,UAAMgB,aAAa,MAAM,KAAKjB,eAAeC,IAAAA;AAC7C,UAAMU,SAAS,IAAIC,WAAWK,UAAAA;AAC9B,UAAMC,OAAOC,MAAM,QAAA,EAAUC,OAAOT,MAAAA,EAAQU,OAAO,KAAA,EAAOC,SAAS,IAAI,GAAA;AAEvE,WAAO;MACL;QACEJ;QACAK,QAAQN,WAAWO;QACnBC,MAAM;UACJC,MAAMzB,KAAKyB;UACXC,MAAM1B,KAAK0B;QACb;QACAC,UAAU3B,KAAK4B;QACfC,QAAQC;QACRC,KAAK,KAAKC,OAAOC,YAAY,aAAaC,gBAAgBlB,UAAAA,IAAchB,KAAKyB;MAC/E;MACAT;;EAEJ;AACF;;;AKhEA,SAASmB,6BAAsC;AAoBxC,IAAMC,gBAAgBC,sBAAmCC,UAAAA;;;ACpBhE,SAASC,wBAAwB;AACjC,SAASC,qCAAqC;AAKvC,IAAMC,oBAAoB,6BAC/BC,8BACE;EAAEC,UAAU;IAAE,CAACC,UAAAA,GAAa;EAAE;EAAGC,QAAQC;AAAiB,GAC1D;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,mBAAmBC,OAAOH,MAAAA;AAC/C,WAAOC;EACT,GAHS;AAIX,CAAA,GAR6B;","names":["assertEx","PayloadBuilder","shajs","FileWitnessConfigSchema","FileSchema","base64","generateDataUri","data","base64","encode","AbstractWitness","FileWitness","AbstractWitness","configSchemas","FileWitnessConfigSchema","defaultConfigSchema","observeHandler","payloads","schema","FileSchema","BrowserFileWitness","FileWitness","configSchemas","FileWitnessConfigSchema","defaultConfigSchema","observeHandler","payload","witnessBrowserFile","logger","params","log","PayloadBuilder","dataHash","e","Error","readBinaryFile","file","Promise","resolve","reject","fileReader","FileReader","addEventListener","event","arrayBuffer","target","result","Uint8Array","onerror","error","readAsArrayBuffer","assertEx","fileBinary","hash","shajs","update","digest","padStart","length","byteLength","meta","name","type","modified","lastModified","schema","FileSchema","uri","config","storage","generateDataUri","isPayloadOfSchemaType","isFilePayload","isPayloadOfSchemaType","FileSchema","PayloadSetSchema","createPayloadSetWitnessPlugin","BrowserFilePlugin","createPayloadSetWitnessPlugin","required","FileSchema","schema","PayloadSetSchema","witness","params","result","BrowserFileWitness","create"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './GenerateDataUri.
|
|
1
|
+
export * from './GenerateDataUri.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './GenerateDataUri.
|
|
1
|
+
export * from './GenerateDataUri.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './GenerateDataUri.
|
|
1
|
+
export * from './GenerateDataUri.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Schema } from '@xyo-network/payload-model';
|
|
2
|
-
import { BrowserFileWitnessAdditionalParams } from './Params.
|
|
3
|
-
import { FileWitness, FileWitnessParams } from './Witness.
|
|
2
|
+
import { BrowserFileWitnessAdditionalParams } from './Params.ts';
|
|
3
|
+
import { FileWitness, FileWitnessParams } from './Witness.ts';
|
|
4
4
|
type BrowserFileWitnessParams = FileWitnessParams & BrowserFileWitnessAdditionalParams;
|
|
5
5
|
export declare class BrowserFileWitness extends FileWitness<BrowserFileWitnessParams> {
|
|
6
6
|
static readonly configSchemas: Schema[];
|
|
7
7
|
static readonly defaultConfigSchema: Schema;
|
|
8
8
|
protected observeHandler(): Promise<(import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
9
9
|
created?: number;
|
|
10
|
-
hash: import("./Payload.
|
|
10
|
+
hash: import("./Payload.ts").BinaryDataHash;
|
|
11
11
|
length: number;
|
|
12
12
|
meta?: Record<string, string | number>;
|
|
13
13
|
modified?: number;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Schema } from '@xyo-network/payload-model';
|
|
2
|
-
import { BrowserFileWitnessAdditionalParams } from './Params.
|
|
3
|
-
import { FileWitness, FileWitnessParams } from './Witness.
|
|
2
|
+
import { BrowserFileWitnessAdditionalParams } from './Params.ts';
|
|
3
|
+
import { FileWitness, FileWitnessParams } from './Witness.ts';
|
|
4
4
|
type BrowserFileWitnessParams = FileWitnessParams & BrowserFileWitnessAdditionalParams;
|
|
5
5
|
export declare class BrowserFileWitness extends FileWitness<BrowserFileWitnessParams> {
|
|
6
6
|
static readonly configSchemas: Schema[];
|
|
7
7
|
static readonly defaultConfigSchema: Schema;
|
|
8
8
|
protected observeHandler(): Promise<(import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
9
9
|
created?: number;
|
|
10
|
-
hash: import("./Payload.
|
|
10
|
+
hash: import("./Payload.ts").BinaryDataHash;
|
|
11
11
|
length: number;
|
|
12
12
|
meta?: Record<string, string | number>;
|
|
13
13
|
modified?: number;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Schema } from '@xyo-network/payload-model';
|
|
2
|
-
import { BrowserFileWitnessAdditionalParams } from './Params.
|
|
3
|
-
import { FileWitness, FileWitnessParams } from './Witness.
|
|
2
|
+
import { BrowserFileWitnessAdditionalParams } from './Params.ts';
|
|
3
|
+
import { FileWitness, FileWitnessParams } from './Witness.ts';
|
|
4
4
|
type BrowserFileWitnessParams = FileWitnessParams & BrowserFileWitnessAdditionalParams;
|
|
5
5
|
export declare class BrowserFileWitness extends FileWitness<BrowserFileWitnessParams> {
|
|
6
6
|
static readonly configSchemas: Schema[];
|
|
7
7
|
static readonly defaultConfigSchema: Schema;
|
|
8
8
|
protected observeHandler(): Promise<(import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
9
9
|
created?: number;
|
|
10
|
-
hash: import("./Payload.
|
|
10
|
+
hash: import("./Payload.ts").BinaryDataHash;
|
|
11
11
|
length: number;
|
|
12
12
|
meta?: Record<string, string | number>;
|
|
13
13
|
modified?: number;
|
package/dist/node/Payload.d.cts
CHANGED
package/dist/node/Payload.d.mts
CHANGED
package/dist/node/Payload.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BrowserFileWitness } from './BrowserFileWitness.
|
|
1
|
+
import { BrowserFileWitness } from './BrowserFileWitness.ts';
|
|
2
2
|
export declare const BrowserFilePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<BrowserFileWitness>;
|
|
3
3
|
//# sourceMappingURL=PluginBrowser.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BrowserFileWitness } from './BrowserFileWitness.
|
|
1
|
+
import { BrowserFileWitness } from './BrowserFileWitness.ts';
|
|
2
2
|
export declare const BrowserFilePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<BrowserFileWitness>;
|
|
3
3
|
//# sourceMappingURL=PluginBrowser.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BrowserFileWitness } from './BrowserFileWitness.
|
|
1
|
+
import { BrowserFileWitness } from './BrowserFileWitness.ts';
|
|
2
2
|
export declare const BrowserFilePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<BrowserFileWitness>;
|
|
3
3
|
//# sourceMappingURL=PluginBrowser.d.ts.map
|
package/dist/node/Witness.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { AbstractWitness } from '@xyo-network/abstract-witness';
|
|
|
3
3
|
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
4
4
|
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
import { WitnessModule, WitnessParams } from '@xyo-network/witness-model';
|
|
6
|
-
import { FileWitnessConfig } from './Config.
|
|
6
|
+
import { FileWitnessConfig } from './Config.ts';
|
|
7
7
|
export type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>;
|
|
8
8
|
export declare abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {
|
|
9
9
|
static readonly configSchemas: Schema[];
|
package/dist/node/Witness.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { AbstractWitness } from '@xyo-network/abstract-witness';
|
|
|
3
3
|
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
4
4
|
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
import { WitnessModule, WitnessParams } from '@xyo-network/witness-model';
|
|
6
|
-
import { FileWitnessConfig } from './Config.
|
|
6
|
+
import { FileWitnessConfig } from './Config.ts';
|
|
7
7
|
export type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>;
|
|
8
8
|
export declare abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {
|
|
9
9
|
static readonly configSchemas: Schema[];
|
package/dist/node/Witness.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AbstractWitness } from '@xyo-network/abstract-witness';
|
|
|
3
3
|
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
4
4
|
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
import { WitnessModule, WitnessParams } from '@xyo-network/witness-model';
|
|
6
|
-
import { FileWitnessConfig } from './Config.
|
|
6
|
+
import { FileWitnessConfig } from './Config.ts';
|
|
7
7
|
export type FileWitnessParams = WitnessParams<AnyConfigSchema<FileWitnessConfig>>;
|
|
8
8
|
export declare abstract class FileWitness<TParams extends FileWitnessParams = FileWitnessParams> extends AbstractWitness<TParams> implements WitnessModule {
|
|
9
9
|
static readonly configSchemas: Schema[];
|
package/dist/node/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __reflectGet = Reflect.get;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,6 +29,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
29
|
mod
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
33
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
29
34
|
|
|
30
35
|
// src/index.ts
|
|
31
36
|
var src_exports = {};
|
|
@@ -53,30 +58,40 @@ var FileSchema = "network.xyo.file";
|
|
|
53
58
|
|
|
54
59
|
// src/util/GenerateDataUri.ts
|
|
55
60
|
var import_base = require("@scure/base");
|
|
56
|
-
var generateDataUri = (data) => {
|
|
61
|
+
var generateDataUri = /* @__PURE__ */ __name((data) => {
|
|
57
62
|
return `data:application/octet-stream;base64,${import_base.base64.encode(data)}`;
|
|
58
|
-
};
|
|
63
|
+
}, "generateDataUri");
|
|
59
64
|
|
|
60
65
|
// src/Witness.ts
|
|
61
66
|
var import_abstract_witness = require("@xyo-network/abstract-witness");
|
|
62
|
-
var
|
|
63
|
-
static configSchemas = [...super.configSchemas, FileWitnessConfigSchema];
|
|
64
|
-
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
67
|
+
var _FileWitness = class _FileWitness extends import_abstract_witness.AbstractWitness {
|
|
65
68
|
observeHandler(payloads) {
|
|
66
|
-
return [
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
...payloads == null ? void 0 : payloads[0],
|
|
72
|
+
schema: FileSchema
|
|
73
|
+
}
|
|
74
|
+
];
|
|
67
75
|
}
|
|
68
76
|
};
|
|
77
|
+
__name(_FileWitness, "FileWitness");
|
|
78
|
+
__publicField(_FileWitness, "configSchemas", [
|
|
79
|
+
...__superGet(_FileWitness, _FileWitness, "configSchemas"),
|
|
80
|
+
FileWitnessConfigSchema
|
|
81
|
+
]);
|
|
82
|
+
__publicField(_FileWitness, "defaultConfigSchema", FileWitnessConfigSchema);
|
|
83
|
+
var FileWitness = _FileWitness;
|
|
69
84
|
|
|
70
85
|
// src/BrowserFileWitness.ts
|
|
71
|
-
var
|
|
72
|
-
static configSchemas = [...super.configSchemas, FileWitnessConfigSchema];
|
|
73
|
-
static defaultConfigSchema = FileWitnessConfigSchema;
|
|
86
|
+
var _BrowserFileWitness = class _BrowserFileWitness extends FileWitness {
|
|
74
87
|
async observeHandler() {
|
|
75
88
|
try {
|
|
76
89
|
const [payload] = await this.witnessBrowserFile();
|
|
77
90
|
const { logger } = this.params;
|
|
78
91
|
logger == null ? void 0 : logger.log(`BrowserFileWitness: ${await import_payload_builder.PayloadBuilder.dataHash(payload)}`);
|
|
79
|
-
return [
|
|
92
|
+
return [
|
|
93
|
+
payload
|
|
94
|
+
];
|
|
80
95
|
} catch (e) {
|
|
81
96
|
throw new Error(`Error reading file: ${e}`);
|
|
82
97
|
}
|
|
@@ -114,6 +129,13 @@ var BrowserFileWitness = class extends FileWitness {
|
|
|
114
129
|
];
|
|
115
130
|
}
|
|
116
131
|
};
|
|
132
|
+
__name(_BrowserFileWitness, "BrowserFileWitness");
|
|
133
|
+
__publicField(_BrowserFileWitness, "configSchemas", [
|
|
134
|
+
...__superGet(_BrowserFileWitness, _BrowserFileWitness, "configSchemas"),
|
|
135
|
+
FileWitnessConfigSchema
|
|
136
|
+
]);
|
|
137
|
+
__publicField(_BrowserFileWitness, "defaultConfigSchema", FileWitnessConfigSchema);
|
|
138
|
+
var BrowserFileWitness = _BrowserFileWitness;
|
|
117
139
|
|
|
118
140
|
// src/Payload.ts
|
|
119
141
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
@@ -122,15 +144,17 @@ var isFilePayload = (0, import_payload_model.isPayloadOfSchemaType)(FileSchema);
|
|
|
122
144
|
// src/PluginBrowser.ts
|
|
123
145
|
var import_payload_model2 = require("@xyo-network/payload-model");
|
|
124
146
|
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
125
|
-
var BrowserFilePlugin = () => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
var BrowserFilePlugin = /* @__PURE__ */ __name(() => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)({
|
|
148
|
+
required: {
|
|
149
|
+
[FileSchema]: 1
|
|
150
|
+
},
|
|
151
|
+
schema: import_payload_model2.PayloadSetSchema
|
|
152
|
+
}, {
|
|
153
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
154
|
+
const result = await BrowserFileWitness.create(params);
|
|
155
|
+
return result;
|
|
156
|
+
}, "witness")
|
|
157
|
+
}), "BrowserFilePlugin");
|
|
134
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
135
159
|
0 && (module.exports = {
|
|
136
160
|
BrowserFilePlugin,
|