core-3nweb-client-lib 0.21.0 → 0.22.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.
- package/build/api-defs/files.d.ts +8 -7
- package/build/core/asmail/inbox/attachments/fs.d.ts +2 -2
- package/build/core/asmail/inbox/attachments/fs.js +3 -2
- package/build/core/asmail/msg/common.d.ts +2 -2
- package/build/core/asmail/msg/common.js +3 -2
- package/build/core/asmail/msg/opener.d.ts +2 -2
- package/build/core/asmail/msg/opener.js +3 -2
- package/build/core/asmail/msg/packer.d.ts +2 -2
- package/build/core/asmail/msg/packer.js +7 -6
- package/build/core/storage/index.js +2 -2
- package/build/core/storage/local/obj-files.js +8 -5
- package/build/core/storage/local/obj-status.js +4 -3
- package/build/core/storage/synced/obj-status.js +4 -3
- package/build/ipc-via-protobuf/bytes.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.d.ts +28 -0
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +337 -0
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/common.js +3 -2
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +31 -18
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +130 -118
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +0 -1
- package/build/lib-client/3nstorage/xsp-fs/file.js +14 -49
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +95 -91
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +19 -24
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +133 -190
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +3 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -21
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +13 -8
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +46 -38
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +17 -35
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +34 -127
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +57 -0
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +182 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.d.ts +3 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +87 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.d.ts +6 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +1022 -0
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/local-files/device-fs.js +7 -3
- package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -7
- package/build/lib-common/big-endian.d.ts +0 -24
- package/build/lib-common/big-endian.js +16 -78
- package/build/lib-common/exceptions/file.js +5 -1
- package/build/lib-common/obj-streaming/sink-utils.d.ts +0 -4
- package/build/lib-common/obj-streaming/sink-utils.js +4 -70
- package/build/lib-common/objs-on-disk/file-layout.js +2 -1
- package/build/lib-common/objs-on-disk/obj-file.js +2 -2
- package/build/lib-common/objs-on-disk/utils.js +2 -1
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +2 -1
- package/package.json +2 -2
- package/build/lib-client/files/file-attrs.d.ts +0 -76
- package/build/lib-client/files/file-attrs.js +0 -549
- package/build/lib-client/files/file-layout.d.ts +0 -56
- package/build/lib-client/files/file-layout.js +0 -456
- package/build/lib-client/files/file-sink.d.ts +0 -33
- package/build/lib-client/files/file-sink.js +0 -173
- package/build/lib-client/files/file-source.d.ts +0 -19
- package/build/lib-client/files/file-source.js +0 -115
|
@@ -2,25 +2,30 @@
|
|
|
2
2
|
* Everything in this module is assumed to be inside of a file system
|
|
3
3
|
* reliance set.
|
|
4
4
|
*/
|
|
5
|
-
import { NodeInFS
|
|
5
|
+
import { NodeInFS } from './node-in-fs';
|
|
6
6
|
import { LinkParameters } from '../../files';
|
|
7
7
|
import { Storage, AsyncSBoxCryptor } from './common';
|
|
8
|
-
import { ObjSource } from 'xsp-files';
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
import { ObjSource, Subscribe } from 'xsp-files';
|
|
9
|
+
import { CommonAttrs, XAttrs } from './attrs';
|
|
10
|
+
import { NodePersistance } from './node-persistence';
|
|
11
|
+
declare class LinkPersistance extends NodePersistance {
|
|
11
12
|
constructor(zNonce: Uint8Array, key: Uint8Array, cryptor: AsyncSBoxCryptor);
|
|
12
|
-
|
|
13
|
+
read(src: ObjSource): Promise<{
|
|
13
14
|
params: LinkParameters<any>;
|
|
14
|
-
attrs
|
|
15
|
+
attrs: CommonAttrs;
|
|
16
|
+
xattrs?: XAttrs;
|
|
15
17
|
}>;
|
|
18
|
+
write(params: LinkParameters<any>, version: number, attrs: CommonAttrs, xattrs: XAttrs | undefined): Promise<Subscribe>;
|
|
16
19
|
}
|
|
17
20
|
declare type SymLink = web3n.files.SymLink;
|
|
18
|
-
|
|
21
|
+
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
22
|
+
export declare class LinkNode extends NodeInFS<LinkPersistance> {
|
|
19
23
|
private linkParams;
|
|
20
24
|
constructor(storage: Storage, name: string, objId: string, version: number, parentId: string | undefined, key: Uint8Array);
|
|
21
25
|
static makeForNew(storage: Storage, parentId: string, name: string, key: Uint8Array): Promise<LinkNode>;
|
|
22
26
|
static makeForExisting(storage: Storage, parentId: string, name: string, objId: string, key: Uint8Array): Promise<LinkNode>;
|
|
23
|
-
|
|
27
|
+
private setUpdatedState;
|
|
28
|
+
save(params: LinkParameters<any>, changes?: XAttrsChanges): Promise<void>;
|
|
24
29
|
private getLinkParams;
|
|
25
30
|
read(): Promise<SymLink>;
|
|
26
31
|
private makeLinkToSharedStorage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2018, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016 - 2018, 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.LinkNode = void 0;
|
|
19
20
|
/**
|
|
@@ -22,38 +23,31 @@ exports.LinkNode = void 0;
|
|
|
22
23
|
*/
|
|
23
24
|
const node_in_fs_1 = require("./node-in-fs");
|
|
24
25
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
25
|
-
const error_1 = require("../../../lib-common/exceptions/error");
|
|
26
26
|
const device_fs_1 = require("../../local-files/device-fs");
|
|
27
27
|
const file_1 = require("./file");
|
|
28
28
|
const fs_1 = require("./fs");
|
|
29
29
|
const xsp_files_1 = require("xsp-files");
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const attrs_1 = require("./attrs");
|
|
31
|
+
const node_persistence_1 = require("./node-persistence");
|
|
32
|
+
class LinkPersistance extends node_persistence_1.NodePersistance {
|
|
32
33
|
constructor(zNonce, key, cryptor) {
|
|
33
34
|
super(zNonce, key, cryptor);
|
|
34
35
|
Object.seal(this);
|
|
35
36
|
}
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (attrs) {
|
|
41
|
-
return {
|
|
42
|
-
params,
|
|
43
|
-
attrs: file_attrs_1.AttrsHolder.fromBytesReadonly(attrs)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return { params };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (exc) {
|
|
51
|
-
throw error_1.errWithCause(exc, `Cannot open link object`);
|
|
37
|
+
async read(src) {
|
|
38
|
+
const { content, attrs, xattrs } = await super.readAll(src);
|
|
39
|
+
if (!content) {
|
|
40
|
+
throw `Cannot open link object`;
|
|
52
41
|
}
|
|
42
|
+
const params = formatV1.parse(content);
|
|
43
|
+
return { params, xattrs, attrs: attrs_1.CommonAttrs.fromAttrs(attrs) };
|
|
44
|
+
}
|
|
45
|
+
async write(params, version, attrs, xattrs) {
|
|
46
|
+
return super.writeWhole(formatV1.pack(params), version, attrs, xattrs);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
Object.freeze(
|
|
56
|
-
Object.freeze(
|
|
49
|
+
Object.freeze(LinkPersistance.prototype);
|
|
50
|
+
Object.freeze(LinkPersistance);
|
|
57
51
|
function makeFileSymLink(storage, params) {
|
|
58
52
|
const sl = {
|
|
59
53
|
isFile: true,
|
|
@@ -88,38 +82,38 @@ class LinkNode extends node_in_fs_1.NodeInFS {
|
|
|
88
82
|
if (!name || !objId || !parentId) {
|
|
89
83
|
throw new Error("Bad link parameter(s) given");
|
|
90
84
|
}
|
|
91
|
-
this.crypto = new
|
|
92
|
-
this.attrs = file_attrs_1.AttrsHolder.makeReadonlyForLink(Date.now());
|
|
85
|
+
this.crypto = new LinkPersistance(xsp_files_1.idToHeaderNonce(this.objId), key, this.storage.cryptor);
|
|
93
86
|
Object.seal(this);
|
|
94
87
|
}
|
|
95
88
|
static async makeForNew(storage, parentId, name, key) {
|
|
96
89
|
const objId = await storage.generateNewObjId();
|
|
97
90
|
const link = new LinkNode(storage, name, objId, 0, parentId, key);
|
|
98
|
-
link.attrs =
|
|
91
|
+
link.attrs = attrs_1.CommonAttrs.makeForTimeNow();
|
|
99
92
|
return link;
|
|
100
93
|
}
|
|
101
94
|
static async makeForExisting(storage, parentId, name, objId, key) {
|
|
102
95
|
const src = await storage.getObj(objId);
|
|
103
96
|
const link = new LinkNode(storage, name, objId, src.version, parentId, key);
|
|
104
|
-
const { params, attrs } = await link.crypto.
|
|
105
|
-
link.
|
|
106
|
-
link.attrs = (attrs ? attrs : file_attrs_1.AttrsHolder.makeReadonlyForLink(0));
|
|
97
|
+
const { params, attrs, xattrs } = await link.crypto.read(src);
|
|
98
|
+
link.setUpdatedState(params, src.version, attrs, xattrs);
|
|
107
99
|
return link;
|
|
108
100
|
}
|
|
109
|
-
|
|
101
|
+
setUpdatedState(params, version, attrs, xattrs) {
|
|
102
|
+
this.linkParams = params;
|
|
103
|
+
super.setUpdatedParams(version, attrs, xattrs);
|
|
104
|
+
}
|
|
105
|
+
async save(params, changes) {
|
|
110
106
|
if (this.linkParams) {
|
|
111
107
|
throw new Error('Cannot set link parameters second time');
|
|
112
108
|
}
|
|
113
109
|
return this.doChange(false, async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
const sinkSub = await this.crypto.saveBytes(bytes, newVersion, attrs);
|
|
110
|
+
// prepare data for recording
|
|
111
|
+
const { attrs, xattrs, newVersion } = this.getParamsForUpdate(changes);
|
|
112
|
+
// save/record
|
|
113
|
+
const sinkSub = await this.crypto.write(params, newVersion, attrs, xattrs);
|
|
119
114
|
await this.storage.saveObj(this.objId, newVersion, sinkSub);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.attrs = attrs;
|
|
115
|
+
// set updated data in the node
|
|
116
|
+
this.setUpdatedState(params, newVersion, attrs, xattrs);
|
|
123
117
|
});
|
|
124
118
|
}
|
|
125
119
|
async getLinkParams() {
|
|
@@ -205,4 +199,18 @@ class LinkNode extends node_in_fs_1.NodeInFS {
|
|
|
205
199
|
exports.LinkNode = LinkNode;
|
|
206
200
|
Object.freeze(LinkNode.prototype);
|
|
207
201
|
Object.freeze(LinkNode);
|
|
202
|
+
var formatV1;
|
|
203
|
+
(function (formatV1) {
|
|
204
|
+
// XXX make proper type version check
|
|
205
|
+
function pack(params) {
|
|
206
|
+
return buffer_utils_1.utf8.pack(JSON.stringify(params));
|
|
207
|
+
}
|
|
208
|
+
formatV1.pack = pack;
|
|
209
|
+
function parse(bytes) {
|
|
210
|
+
const params = JSON.parse(buffer_utils_1.utf8.open(bytes));
|
|
211
|
+
return params;
|
|
212
|
+
}
|
|
213
|
+
formatV1.parse = parse;
|
|
214
|
+
})(formatV1 || (formatV1 = {}));
|
|
215
|
+
Object.freeze(formatV1);
|
|
208
216
|
Object.freeze(exports);
|
|
@@ -1,53 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Everything in this module is assumed to be inside of a file system
|
|
3
|
-
* reliance set.
|
|
4
|
-
*/
|
|
5
|
-
import { AsyncSBoxCryptor, SegmentsWriter, SegmentsReader, Subscribe, ObjSource, ByteSource } from 'xsp-files';
|
|
6
1
|
import { Node, NodeType, Storage, RemoteEvent } from './common';
|
|
7
2
|
import { Observable } from 'rxjs';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
private zerothHeaderNonce;
|
|
11
|
-
private key;
|
|
12
|
-
private cryptor;
|
|
13
|
-
protected constructor(zerothHeaderNonce: Uint8Array, key: Uint8Array, cryptor: AsyncSBoxCryptor);
|
|
14
|
-
wipe(): void;
|
|
15
|
-
compareKey(keyB64: string): boolean;
|
|
16
|
-
fileKeyInBase64(): string;
|
|
17
|
-
protected segWriter(version: number): Promise<SegmentsWriter>;
|
|
18
|
-
protected segWriterWithBase(newVersion: number, base: ObjSource): Promise<SegmentsWriter>;
|
|
19
|
-
protected segReader(src: ObjSource): Promise<SegmentsReader>;
|
|
20
|
-
saveBytes(bytes: Uint8Array | Uint8Array[], version: number, attrs: AttrsHolder<any>): Promise<Subscribe>;
|
|
21
|
-
saveAttrs<T extends EntityAttrs>(attrs: AttrsHolder<T>, version: number, base: ObjSource | undefined): Promise<Subscribe>;
|
|
22
|
-
getAttrsAndByteSrc(src: ObjSource): Promise<{
|
|
23
|
-
attrsBytes?: Uint8Array;
|
|
24
|
-
byteSrc: ByteSource;
|
|
25
|
-
}>;
|
|
26
|
-
readBytes(src: ObjSource): Promise<{
|
|
27
|
-
content: Uint8Array;
|
|
28
|
-
attrs?: Uint8Array;
|
|
29
|
-
}>;
|
|
30
|
-
reencryptHeader: (initHeader: Uint8Array, newVersion: number) => Promise<Uint8Array>;
|
|
31
|
-
}
|
|
3
|
+
import { CommonAttrs, XAttrs } from './attrs';
|
|
4
|
+
import { NodePersistance } from './node-persistence';
|
|
32
5
|
export declare type FSEvent = web3n.files.FolderEvent | web3n.files.FileEvent;
|
|
33
6
|
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
34
|
-
export declare abstract class NodeInFS<
|
|
35
|
-
protected storage: Storage;
|
|
36
|
-
type: NodeType;
|
|
7
|
+
export declare abstract class NodeInFS<P extends NodePersistance> implements Node {
|
|
8
|
+
protected readonly storage: Storage;
|
|
9
|
+
readonly type: NodeType;
|
|
37
10
|
name: string;
|
|
38
|
-
objId: string;
|
|
11
|
+
readonly objId: string;
|
|
39
12
|
private currentVersion;
|
|
40
13
|
parentId: string | undefined;
|
|
41
|
-
protected crypto:
|
|
42
|
-
protected attrs:
|
|
14
|
+
protected crypto: P;
|
|
15
|
+
protected attrs: CommonAttrs;
|
|
16
|
+
protected xattrs: XAttrs | undefined;
|
|
43
17
|
private writeProc;
|
|
44
18
|
get version(): number;
|
|
45
19
|
protected setCurrentVersion(newVersion: number): void;
|
|
46
20
|
private remoteEvents;
|
|
47
21
|
protected constructor(storage: Storage, type: NodeType, name: string, objId: string, currentVersion: number, parentId: string | undefined);
|
|
22
|
+
private updatedXAttrs;
|
|
23
|
+
protected setUpdatedParams(version: number, attrs: CommonAttrs | undefined, xattrs: XAttrs | undefined): void;
|
|
24
|
+
protected getParamsForUpdate(changes: XAttrsChanges | undefined): {
|
|
25
|
+
newVersion: number;
|
|
26
|
+
attrs: CommonAttrs;
|
|
27
|
+
xattrs?: XAttrs;
|
|
28
|
+
};
|
|
48
29
|
updateXAttrs(changes: XAttrsChanges): Promise<number>;
|
|
49
30
|
getXAttr(xaName: string): any;
|
|
50
31
|
listXAttrs(): string[];
|
|
32
|
+
getAttrs(): CommonAttrs;
|
|
51
33
|
processRemoteEvent(event: RemoteEvent): Promise<void>;
|
|
52
34
|
private bufferRemoteEvent;
|
|
53
35
|
private getBufferedEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -13,130 +13,20 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.NodeInFS =
|
|
19
|
+
exports.NodeInFS = void 0;
|
|
19
20
|
/**
|
|
20
21
|
* Everything in this module is assumed to be inside of a file system
|
|
21
22
|
* reliance set.
|
|
22
23
|
*/
|
|
23
|
-
const xsp_files_1 = require("xsp-files");
|
|
24
|
-
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
25
24
|
const processes_1 = require("../../../lib-common/processes");
|
|
26
|
-
const random = require("../../../lib-common/random-node");
|
|
27
25
|
const file_1 = require("../../../lib-common/exceptions/file");
|
|
28
26
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
29
27
|
const rxjs_1 = require("rxjs");
|
|
30
|
-
const sink_utils_1 = require("../../../lib-common/obj-streaming/sink-utils");
|
|
31
28
|
const operators_1 = require("rxjs/operators");
|
|
32
|
-
const
|
|
33
|
-
const EMPTY_BYTE_ARR = new Uint8Array(0);
|
|
34
|
-
class NodeCrypto {
|
|
35
|
-
constructor(zerothHeaderNonce, key, cryptor) {
|
|
36
|
-
this.zerothHeaderNonce = zerothHeaderNonce;
|
|
37
|
-
this.key = key;
|
|
38
|
-
this.cryptor = cryptor;
|
|
39
|
-
this.reencryptHeader = async (initHeader, newVersion) => {
|
|
40
|
-
if (!this.key) {
|
|
41
|
-
throw new Error("Cannot use wiped object.");
|
|
42
|
-
}
|
|
43
|
-
const headerContent = await this.cryptor.formatWN.open(initHeader, this.key);
|
|
44
|
-
const n = xsp_files_1.calculateNonce(this.zerothHeaderNonce, newVersion);
|
|
45
|
-
return this.cryptor.formatWN.pack(headerContent, n, this.key);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
wipe() {
|
|
49
|
-
if (this.key) {
|
|
50
|
-
this.key.fill(0);
|
|
51
|
-
this.key = undefined;
|
|
52
|
-
this.zerothHeaderNonce.fill(0);
|
|
53
|
-
this.zerothHeaderNonce = undefined;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
compareKey(keyB64) {
|
|
57
|
-
const k = buffer_utils_1.base64.open(keyB64);
|
|
58
|
-
return xsp_files_1.compareVectors(k, this.key);
|
|
59
|
-
}
|
|
60
|
-
fileKeyInBase64() {
|
|
61
|
-
if (!this.key) {
|
|
62
|
-
throw new Error("Cannot use wiped object.");
|
|
63
|
-
}
|
|
64
|
-
return buffer_utils_1.base64.pack(this.key);
|
|
65
|
-
}
|
|
66
|
-
segWriter(version) {
|
|
67
|
-
if (!this.key) {
|
|
68
|
-
throw new Error("Cannot use wiped object.");
|
|
69
|
-
}
|
|
70
|
-
return xsp_files_1.makeSegmentsWriter(this.key, this.zerothHeaderNonce, version, { type: 'new', segSize: SEG_SIZE, formatWithSections: true }, random.bytes, this.cryptor);
|
|
71
|
-
}
|
|
72
|
-
async segWriterWithBase(newVersion, base) {
|
|
73
|
-
if (!this.key) {
|
|
74
|
-
throw new Error("Cannot use wiped object.");
|
|
75
|
-
}
|
|
76
|
-
return xsp_files_1.makeSegmentsWriter(this.key, this.zerothHeaderNonce, newVersion, { type: 'update', base, formatWithSections: true }, random.bytes, this.cryptor);
|
|
77
|
-
}
|
|
78
|
-
async segReader(src) {
|
|
79
|
-
if (!this.key) {
|
|
80
|
-
throw new Error("Cannot use wiped object.");
|
|
81
|
-
}
|
|
82
|
-
const version = src.version;
|
|
83
|
-
const header = await src.readHeader();
|
|
84
|
-
return xsp_files_1.makeSegmentsReader(this.key, this.zerothHeaderNonce, version, header, this.cryptor);
|
|
85
|
-
}
|
|
86
|
-
async saveBytes(bytes, version, attrs) {
|
|
87
|
-
attrs.mtime = Date.now();
|
|
88
|
-
const segWriter = await this.segWriter(version);
|
|
89
|
-
const sub = sink_utils_1.encryptBytesToSinkProc(bytes, attrs.toBytes(), segWriter);
|
|
90
|
-
return sub;
|
|
91
|
-
}
|
|
92
|
-
async saveAttrs(attrs, version, base) {
|
|
93
|
-
if (base) {
|
|
94
|
-
const writer = await this.segWriterWithBase(version, base);
|
|
95
|
-
const { attrsBytes } = await this.getAttrsAndByteSrc(base);
|
|
96
|
-
const baseAttrsSize = (attrsBytes ? attrsBytes.length : 0);
|
|
97
|
-
return sink_utils_1.encryptAttrsToSinkProc(attrs.toBytes(), writer, baseAttrsSize);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const writer = await this.segWriter(version);
|
|
101
|
-
return sink_utils_1.encryptAttrsToSinkProc(attrs.toBytes(), writer, undefined);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async getAttrsAndByteSrc(src) {
|
|
105
|
-
const segReader = await this.segReader(src);
|
|
106
|
-
if (segReader.formatVersion === 2) {
|
|
107
|
-
const byteSrc = await xsp_files_1.makeDecryptedByteSourceWithAttrs(src.segSrc, segReader);
|
|
108
|
-
const attrsBytes = await byteSrc.readAttrs();
|
|
109
|
-
return { byteSrc, attrsBytes };
|
|
110
|
-
}
|
|
111
|
-
else if (segReader.formatVersion === 1) {
|
|
112
|
-
const byteSrc = xsp_files_1.makeDecryptedByteSource(src.segSrc, segReader);
|
|
113
|
-
return { byteSrc };
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
throw new Error(`XSP segments format ${segReader.formatVersion} is unknown`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async readBytes(src) {
|
|
120
|
-
const segReader = await this.segReader(src);
|
|
121
|
-
if (segReader.formatVersion === 2) {
|
|
122
|
-
const decSrc = await xsp_files_1.makeDecryptedByteSourceWithAttrs(src.segSrc, segReader);
|
|
123
|
-
const attrs = await decSrc.readAttrs();
|
|
124
|
-
const bytes = await decSrc.read(undefined);
|
|
125
|
-
return { attrs, content: (bytes ? bytes : EMPTY_BYTE_ARR) };
|
|
126
|
-
}
|
|
127
|
-
else if (segReader.formatVersion === 1) {
|
|
128
|
-
const decSrc = xsp_files_1.makeDecryptedByteSource(src.segSrc, segReader);
|
|
129
|
-
const bytes = await decSrc.read(undefined);
|
|
130
|
-
return { content: (bytes ? bytes : EMPTY_BYTE_ARR) };
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
throw new Error(`XSP segments format ${segReader.formatVersion} is unknown`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.NodeCrypto = NodeCrypto;
|
|
138
|
-
Object.freeze(NodeCrypto.prototype);
|
|
139
|
-
Object.freeze(NodeCrypto);
|
|
29
|
+
const attrs_1 = require("./attrs");
|
|
140
30
|
class NodeInFS {
|
|
141
31
|
constructor(storage, type, name, objId, currentVersion, parentId) {
|
|
142
32
|
this.storage = storage;
|
|
@@ -147,6 +37,7 @@ class NodeInFS {
|
|
|
147
37
|
this.parentId = parentId;
|
|
148
38
|
this.crypto = undefined;
|
|
149
39
|
this.attrs = undefined;
|
|
40
|
+
this.xattrs = undefined;
|
|
150
41
|
this.writeProc = undefined;
|
|
151
42
|
this.remoteEvents = undefined;
|
|
152
43
|
/**
|
|
@@ -164,30 +55,46 @@ class NodeInFS {
|
|
|
164
55
|
}
|
|
165
56
|
this.currentVersion = newVersion;
|
|
166
57
|
}
|
|
58
|
+
updatedXAttrs(changes) {
|
|
59
|
+
return (this.xattrs ?
|
|
60
|
+
(changes ? this.xattrs.makeUpdated(changes) : this.xattrs) :
|
|
61
|
+
(changes ? attrs_1.XAttrs.makeEmpty().makeUpdated(changes) : undefined));
|
|
62
|
+
}
|
|
63
|
+
setUpdatedParams(version, attrs, xattrs) {
|
|
64
|
+
if (attrs) {
|
|
65
|
+
this.attrs = attrs;
|
|
66
|
+
}
|
|
67
|
+
this.xattrs = xattrs;
|
|
68
|
+
this.setCurrentVersion(version);
|
|
69
|
+
}
|
|
70
|
+
getParamsForUpdate(changes) {
|
|
71
|
+
return {
|
|
72
|
+
newVersion: this.version + 1,
|
|
73
|
+
attrs: this.attrs.copy(),
|
|
74
|
+
xattrs: this.updatedXAttrs(changes)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
167
77
|
async updateXAttrs(changes) {
|
|
168
78
|
if (Object.keys(changes).length === 0) {
|
|
169
79
|
return this.version;
|
|
170
80
|
}
|
|
171
81
|
return this.doChange(true, async () => {
|
|
172
|
-
const newVersion = this.
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
const base = ((this.version === 0) ?
|
|
176
|
-
undefined :
|
|
177
|
-
await this.storage.getObj(this.objId));
|
|
178
|
-
const sub = await this.crypto.saveAttrs(attrs, newVersion, base);
|
|
82
|
+
const { xattrs, newVersion } = this.getParamsForUpdate(changes);
|
|
83
|
+
const base = await this.storage.getObj(this.objId);
|
|
84
|
+
const sub = await this.crypto.writeXAttrs(xattrs, newVersion, base);
|
|
179
85
|
await this.storage.saveObj(this.objId, newVersion, sub);
|
|
180
|
-
this.
|
|
181
|
-
attrs.setReadonly();
|
|
182
|
-
this.attrs = attrs;
|
|
86
|
+
this.setUpdatedParams(newVersion, undefined, xattrs);
|
|
183
87
|
return this.version;
|
|
184
88
|
});
|
|
185
89
|
}
|
|
186
90
|
getXAttr(xaName) {
|
|
187
|
-
return this.
|
|
91
|
+
return (this.xattrs ? this.xattrs.get(xaName) : undefined);
|
|
188
92
|
}
|
|
189
93
|
listXAttrs() {
|
|
190
|
-
return this.
|
|
94
|
+
return (this.xattrs ? this.xattrs.list() : []);
|
|
95
|
+
}
|
|
96
|
+
getAttrs() {
|
|
97
|
+
return this.attrs;
|
|
191
98
|
}
|
|
192
99
|
processRemoteEvent(event) {
|
|
193
100
|
this.bufferRemoteEvent(event);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything in this module is assumed to be inside of a file system
|
|
3
|
+
* reliance set.
|
|
4
|
+
*/
|
|
5
|
+
import { AsyncSBoxCryptor, Subscribe, ObjSource } from 'xsp-files';
|
|
6
|
+
import { CommonAttrs, XAttrs } from './attrs';
|
|
7
|
+
/**
|
|
8
|
+
* This does reading and writing, keeping keys. This and extending objects are
|
|
9
|
+
* used in file system nodes as thematic place with persistence functionality.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class NodePersistance {
|
|
12
|
+
private zerothHeaderNonce;
|
|
13
|
+
private key;
|
|
14
|
+
private cryptor;
|
|
15
|
+
protected constructor(zerothHeaderNonce: Uint8Array, key: Uint8Array, cryptor: AsyncSBoxCryptor);
|
|
16
|
+
wipe(): void;
|
|
17
|
+
compareKey(keyB64: string): boolean;
|
|
18
|
+
fileKeyInBase64(): string;
|
|
19
|
+
private segWriter;
|
|
20
|
+
private segWriterWithBase;
|
|
21
|
+
private decryptedByteSrc;
|
|
22
|
+
readonlyPayload(src: ObjSource): Promise<ReadonlyPayload>;
|
|
23
|
+
protected readAll(src: ObjSource): Promise<{
|
|
24
|
+
content: Uint8Array | undefined;
|
|
25
|
+
attrs: Attrs;
|
|
26
|
+
xattrs?: XAttrs;
|
|
27
|
+
}>;
|
|
28
|
+
private writablePayload;
|
|
29
|
+
protected writeWhole(content: Uint8Array | Uint8Array[], newVersion: number, attrs?: CommonAttrs, xattrs?: XAttrs): Promise<Subscribe>;
|
|
30
|
+
writeXAttrs(xattrs: XAttrs, newVersion: number, base: ObjSource): Promise<Subscribe>;
|
|
31
|
+
protected writableSink(newVersion: number, attrs?: CommonAttrs, xattrs?: XAttrs, base?: ObjSource): Promise<{
|
|
32
|
+
sinkPromise: Promise<FileByteSink>;
|
|
33
|
+
sub: Subscribe;
|
|
34
|
+
}>;
|
|
35
|
+
reencryptHeader: (initHeader: Uint8Array, newVersion: number) => Promise<Uint8Array>;
|
|
36
|
+
}
|
|
37
|
+
declare type FileByteSource = web3n.files.FileByteSource;
|
|
38
|
+
declare type FileByteSink = web3n.files.FileByteSink;
|
|
39
|
+
export interface ReadonlyPayload {
|
|
40
|
+
getAttrs(): Attrs;
|
|
41
|
+
getXAttrs(): Promise<XAttrs>;
|
|
42
|
+
readAllContent(): Promise<Uint8Array | undefined>;
|
|
43
|
+
readSomeContentBytes(start: number, end: number): Promise<Uint8Array | undefined>;
|
|
44
|
+
makeFileByteSource(): FileByteSource;
|
|
45
|
+
}
|
|
46
|
+
export interface Attrs {
|
|
47
|
+
ctime: number;
|
|
48
|
+
mtime: number;
|
|
49
|
+
size: number;
|
|
50
|
+
isEndless?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface WritablePayload {
|
|
53
|
+
setXAttrs(xattrs: XAttrs): Promise<void>;
|
|
54
|
+
writeAllContent(bytes: Uint8Array[], xattrs?: XAttrs): Promise<void>;
|
|
55
|
+
makeFileByteSink(xattrs?: XAttrs): Promise<FileByteSink>;
|
|
56
|
+
}
|
|
57
|
+
export {};
|