@ethersphere/bee-js 13.0.0-upcoming.gcfb9756 → 13.0.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/README.md +104 -103
- package/dist/cjs/api/bytes.js +3 -4
- package/dist/cjs/api/bzz.js +5 -6
- package/dist/cjs/api/chunk.js +3 -3
- package/dist/cjs/api/envelope.js +3 -2
- package/dist/cjs/api/feed.js +4 -5
- package/dist/cjs/api/pin.js +2 -2
- package/dist/cjs/api/soc.js +2 -2
- package/dist/cjs/bee.js +18 -19
- package/dist/cjs/chunk/soc.js +21 -63
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +17 -19
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +97 -333
- package/dist/cjs/modules/balance.js +3 -3
- package/dist/cjs/modules/cheque.js +4 -4
- package/dist/cjs/modules/chunk.js +8 -8
- package/dist/cjs/modules/collection.js +6 -6
- package/dist/cjs/modules/connectivity.js +3 -3
- package/dist/cjs/modules/data.js +6 -6
- package/dist/cjs/modules/feed.js +10 -10
- package/dist/cjs/modules/file.js +3 -3
- package/dist/cjs/modules/grantee.js +9 -9
- package/dist/cjs/modules/messaging.js +15 -17
- package/dist/cjs/modules/pin.js +6 -6
- package/dist/cjs/modules/settlement.js +2 -2
- package/dist/cjs/modules/soc.js +3 -3
- package/dist/cjs/modules/stamp.js +7 -7
- package/dist/cjs/modules/tag.js +2 -2
- package/dist/cjs/modules/transaction.js +4 -4
- package/dist/cjs/modules/wallet.js +3 -3
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +3 -1
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/cjs/utils/type.js +2 -2
- package/dist/codemod/index.js +141 -0
- package/dist/codemod/transforms/v13.js +524 -0
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/bytes.js +1 -2
- package/dist/mjs/api/bzz.js +1 -2
- package/dist/mjs/api/chunk.js +1 -1
- package/dist/mjs/api/envelope.js +3 -2
- package/dist/mjs/api/feed.js +1 -2
- package/dist/mjs/api/pin.js +1 -1
- package/dist/mjs/api/soc.js +1 -1
- package/dist/mjs/bee.js +13 -14
- package/dist/mjs/chunk/soc.js +11 -49
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +6 -8
- package/dist/mjs/feed/retrievable.js +1 -1
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +95 -339
- package/dist/mjs/modules/balance.js +1 -1
- package/dist/mjs/modules/cheque.js +1 -1
- package/dist/mjs/modules/chunk.js +1 -1
- package/dist/mjs/modules/collection.js +1 -1
- package/dist/mjs/modules/connectivity.js +1 -1
- package/dist/mjs/modules/data.js +3 -3
- package/dist/mjs/modules/feed.js +1 -1
- package/dist/mjs/modules/file.js +1 -1
- package/dist/mjs/modules/grantee.js +1 -1
- package/dist/mjs/modules/messaging.js +3 -5
- package/dist/mjs/modules/pin.js +1 -1
- package/dist/mjs/modules/settlement.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/stamp.js +1 -1
- package/dist/mjs/modules/tag.js +1 -1
- package/dist/mjs/modules/transaction.js +1 -1
- package/dist/mjs/modules/wallet.js +1 -1
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/http.js +6 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/mjs/utils/type.js +2 -2
- package/dist/types/api/balance.d.ts +1 -1
- package/dist/types/api/batches.d.ts +1 -1
- package/dist/types/api/bytes.d.ts +3 -3
- package/dist/types/api/bzz.d.ts +1 -2
- package/dist/types/api/chequebook.d.ts +1 -1
- package/dist/types/api/chunk.d.ts +1 -1
- package/dist/types/api/connectivity.d.ts +1 -1
- package/dist/types/api/consumed.d.ts +1 -1
- package/dist/types/api/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +1 -2
- package/dist/types/api/grantee.d.ts +1 -1
- package/dist/types/api/pin.d.ts +1 -1
- package/dist/types/api/pss.d.ts +1 -1
- package/dist/types/api/settlement.d.ts +1 -1
- package/dist/types/api/soc.d.ts +1 -1
- package/dist/types/api/stake.d.ts +1 -1
- package/dist/types/api/stamp.d.ts +1 -1
- package/dist/types/api/stewardship.d.ts +1 -1
- package/dist/types/api/tag.d.ts +1 -1
- package/dist/types/api/transaction.d.ts +1 -1
- package/dist/types/api/wallet.d.ts +1 -1
- package/dist/types/bee.d.ts +11 -13
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -3
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +24 -33
- package/dist/types/modules/balance.d.ts +1 -1
- package/dist/types/modules/cheque.d.ts +1 -1
- package/dist/types/modules/chequebook.d.ts +1 -1
- package/dist/types/modules/chunk.d.ts +1 -2
- package/dist/types/modules/collection.d.ts +2 -2
- package/dist/types/modules/connectivity.d.ts +1 -1
- package/dist/types/modules/context.d.ts +1 -1
- package/dist/types/modules/data.d.ts +3 -3
- package/dist/types/modules/feed.d.ts +1 -1
- package/dist/types/modules/file.d.ts +1 -2
- package/dist/types/modules/grantee.d.ts +1 -1
- package/dist/types/modules/messaging.d.ts +1 -2
- package/dist/types/modules/pin.d.ts +1 -1
- package/dist/types/modules/settlement.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/stake.d.ts +1 -1
- package/dist/types/modules/stamp.d.ts +1 -1
- package/dist/types/modules/storage.d.ts +1 -1
- package/dist/types/modules/tag.d.ts +1 -1
- package/dist/types/modules/transaction.d.ts +1 -1
- package/dist/types/modules/wallet.d.ts +1 -1
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +2 -11
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -1
- package/package.json +7 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
|
@@ -1,152 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
static split(a, b) {
|
|
21
|
-
const commonPart = Binary.commonPrefix(a.prefix, b.prefix);
|
|
22
|
-
if (commonPart.length === a.prefix.length) {
|
|
23
|
-
const remainingB = b.prefix.slice(commonPart.length);
|
|
24
|
-
b.node.path = b.prefix.slice(commonPart.length);
|
|
25
|
-
b.prefix = b.prefix.slice(commonPart.length);
|
|
26
|
-
b.node.parent = a.node;
|
|
27
|
-
a.node.forks.set(remainingB[0], b);
|
|
28
|
-
return a;
|
|
29
|
-
}
|
|
30
|
-
if (commonPart.length === b.prefix.length) {
|
|
31
|
-
const remainingA = a.prefix.slice(commonPart.length);
|
|
32
|
-
a.node.path = a.prefix.slice(commonPart.length);
|
|
33
|
-
a.prefix = a.prefix.slice(commonPart.length);
|
|
34
|
-
a.node.parent = b.node;
|
|
35
|
-
b.node.forks.set(remainingA[0], a);
|
|
36
|
-
return b;
|
|
37
|
-
}
|
|
38
|
-
const node = new MantarayNode({
|
|
39
|
-
path: commonPart
|
|
40
|
-
});
|
|
41
|
-
const newAFork = new Fork(a.prefix.slice(commonPart.length), a.node);
|
|
42
|
-
const newBFork = new Fork(b.prefix.slice(commonPart.length), b.node);
|
|
43
|
-
a.node.path = a.prefix.slice(commonPart.length);
|
|
44
|
-
b.node.path = b.prefix.slice(commonPart.length);
|
|
45
|
-
a.prefix = a.prefix.slice(commonPart.length);
|
|
46
|
-
b.prefix = b.prefix.slice(commonPart.length);
|
|
47
|
-
node.forks.set(newAFork.prefix[0], newAFork);
|
|
48
|
-
node.forks.set(newBFork.prefix[0], newBFork);
|
|
49
|
-
newAFork.node.parent = node;
|
|
50
|
-
newBFork.node.parent = node;
|
|
51
|
-
return new Fork(commonPart, node);
|
|
52
|
-
}
|
|
53
|
-
marshal() {
|
|
54
|
-
if (!this.node.selfAddress) {
|
|
55
|
-
throw Error('Fork#marshal node.selfAddress is not set');
|
|
56
|
-
}
|
|
57
|
-
const data = [];
|
|
58
|
-
// Re-emit the type byte read from the chunk when the node is untouched, so an
|
|
59
|
-
// unmarshal → marshal round-trip is byte-identical. determineType() can only
|
|
60
|
-
// recompute it correctly once the node's children are loaded/built in memory.
|
|
61
|
-
data.push(new Uint8Array([this.node.type ?? this.node.determineType()]));
|
|
62
|
-
data.push(Binary.numberToUint8(this.prefix.length));
|
|
63
|
-
data.push(this.prefix);
|
|
64
|
-
if (this.prefix.length < 30) {
|
|
65
|
-
data.push(new Uint8Array(30 - this.prefix.length));
|
|
66
|
-
}
|
|
67
|
-
data.push(this.node.selfAddress);
|
|
68
|
-
debug('marshalling fork', {
|
|
69
|
-
prefixLength: this.prefix.length,
|
|
70
|
-
prefix: DECODER.decode(this.prefix),
|
|
71
|
-
address: Binary.uint8ArrayToHex(this.node.selfAddress)
|
|
72
|
-
});
|
|
73
|
-
if (this.node.metadata) {
|
|
74
|
-
const metadataBytes = Binary.padEndToMultiple(new Uint8Array([0x00, 0x00, ...ENCODER.encode(JSON.stringify(this.node.metadata))]), 32, 0x0a);
|
|
75
|
-
const metadataLengthBytes = Binary.numberToUint16(metadataBytes.length - 2, 'BE');
|
|
76
|
-
metadataBytes.set(metadataLengthBytes, 0);
|
|
77
|
-
data.push(metadataBytes);
|
|
1
|
+
import { Optional } from 'cafe-utility';
|
|
2
|
+
import { Bytes, MantarayNode as CoreMantarayNode, Reference } from '@ethersphere/core-sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Uploads `node` and every node beneath it, updating each `selfAddress` in
|
|
5
|
+
* place. Only the network/ACT-history side is bee-js specific - the trie
|
|
6
|
+
* structure and marshaling live entirely in core-sdk's MantarayNode.
|
|
7
|
+
*/
|
|
8
|
+
async function saveRecursively(node, bee, postageBatchId, options, requestOptions) {
|
|
9
|
+
for (const fork of node.forks.values()) {
|
|
10
|
+
const uploadResult = await saveRecursively(fork.node, bee, postageBatchId, options, requestOptions);
|
|
11
|
+
if (options?.act) {
|
|
12
|
+
let historyAddress;
|
|
13
|
+
uploadResult.historyAddress.ifPresent(ref => historyAddress = ref);
|
|
14
|
+
if (historyAddress) {
|
|
15
|
+
if (!fork.node.metadata) {
|
|
16
|
+
fork.node.metadata = {};
|
|
17
|
+
}
|
|
18
|
+
fork.node.metadata['swarm-act-history-address'] = historyAddress.toHex();
|
|
19
|
+
}
|
|
78
20
|
}
|
|
79
|
-
return Binary.concatBytes(...data);
|
|
80
21
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
22
|
+
const result = await bee.data.upload(postageBatchId, await node.marshal(), options, requestOptions);
|
|
23
|
+
node.selfAddress = result.reference.toUint8Array();
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Downloads and unmarshals every node beneath `node`, following ACT history
|
|
28
|
+
* metadata left by {@link saveRecursively} where present.
|
|
29
|
+
*/
|
|
30
|
+
async function loadRecursively(node, bee, options, requestOptions) {
|
|
31
|
+
for (const fork of node.forks.values()) {
|
|
32
|
+
if (!fork.node.selfAddress) {
|
|
33
|
+
throw Error('MantarayNode#loadRecursively fork.node.selfAddress is not set');
|
|
34
|
+
}
|
|
35
|
+
let downloadOptions = options;
|
|
36
|
+
if (fork.node.metadata && fork.node.metadata['swarm-act-history-address']) {
|
|
37
|
+
downloadOptions = {
|
|
38
|
+
...options,
|
|
39
|
+
actHistoryAddress: fork.node.metadata['swarm-act-history-address']
|
|
40
|
+
};
|
|
100
41
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
42
|
+
const data = (await bee.data.download(fork.node.selfAddress, downloadOptions, requestOptions)).toUint8Array();
|
|
43
|
+
const loaded = CoreMantarayNode.unmarshalFromData(data, fork.node.selfAddress);
|
|
44
|
+
fork.node.targetAddress = loaded.targetAddress;
|
|
45
|
+
fork.node.forks = loaded.forks;
|
|
46
|
+
fork.node.path = fork.prefix;
|
|
47
|
+
fork.node.parent = node;
|
|
48
|
+
await loadRecursively(fork.node, bee, options, requestOptions);
|
|
107
49
|
}
|
|
108
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* bee-js's Bee-client-coupled view of a Mantaray node: the trie structure,
|
|
53
|
+
* marshaling, and byte-level operations all delegate to core-sdk's
|
|
54
|
+
* `MantarayNode`; this class only adds what needs a live `Bee` instance
|
|
55
|
+
* (uploading/downloading, ACT history, feed resolution).
|
|
56
|
+
*/
|
|
109
57
|
export class MantarayNode {
|
|
110
|
-
constructor(
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
this.type = options?.type ?? null;
|
|
58
|
+
constructor(core = new CoreMantarayNode()) {
|
|
59
|
+
this.core = core;
|
|
60
|
+
}
|
|
61
|
+
get obfuscationKey() {
|
|
62
|
+
return this.core.obfuscationKey;
|
|
63
|
+
}
|
|
64
|
+
get selfAddress() {
|
|
65
|
+
return this.core.selfAddress;
|
|
66
|
+
}
|
|
67
|
+
get targetAddress() {
|
|
68
|
+
return this.core.targetAddress;
|
|
69
|
+
}
|
|
70
|
+
get metadata() {
|
|
71
|
+
return this.core.metadata;
|
|
72
|
+
}
|
|
73
|
+
get path() {
|
|
74
|
+
return this.core.path;
|
|
75
|
+
}
|
|
76
|
+
get forks() {
|
|
77
|
+
return this.core.forks;
|
|
78
|
+
}
|
|
79
|
+
get parent() {
|
|
80
|
+
return this.core.parent;
|
|
81
|
+
}
|
|
82
|
+
get type() {
|
|
83
|
+
return this.core.type;
|
|
138
84
|
}
|
|
139
85
|
get fullPath() {
|
|
140
|
-
return
|
|
86
|
+
return this.core.fullPath;
|
|
141
87
|
}
|
|
142
88
|
get fullPathString() {
|
|
143
|
-
return
|
|
89
|
+
return this.core.fullPathString;
|
|
144
90
|
}
|
|
145
91
|
/**
|
|
146
92
|
* Returns the metadata at the `/` path to access idiomatic properties.
|
|
147
93
|
*/
|
|
148
94
|
getRootMetadata() {
|
|
149
|
-
const node = this.find('/');
|
|
95
|
+
const node = this.core.find('/');
|
|
150
96
|
if (node && node.metadata) {
|
|
151
97
|
return Optional.of(node.metadata);
|
|
152
98
|
}
|
|
@@ -156,7 +102,7 @@ export class MantarayNode {
|
|
|
156
102
|
* Returns the `swarm-index-document` and `swarm-error-document` metadata values.
|
|
157
103
|
*/
|
|
158
104
|
getDocsMetadata() {
|
|
159
|
-
const node = this.find('/');
|
|
105
|
+
const node = this.core.find('/');
|
|
160
106
|
if (!node || !node.metadata) {
|
|
161
107
|
return {
|
|
162
108
|
indexDocument: null,
|
|
@@ -172,7 +118,7 @@ export class MantarayNode {
|
|
|
172
118
|
* Attempts to resolve the manifest as a feed, returning the latest update.
|
|
173
119
|
*/
|
|
174
120
|
async resolveFeed(bee, requestOptions) {
|
|
175
|
-
const node = this.find('/');
|
|
121
|
+
const node = this.core.find('/');
|
|
176
122
|
if (!node || !node.metadata) {
|
|
177
123
|
return Optional.empty();
|
|
178
124
|
}
|
|
@@ -187,39 +133,7 @@ export class MantarayNode {
|
|
|
187
133
|
* Gets the binary representation of the node.
|
|
188
134
|
*/
|
|
189
135
|
async marshal() {
|
|
190
|
-
|
|
191
|
-
if (!fork.node.selfAddress) {
|
|
192
|
-
fork.node.selfAddress = (await fork.node.calculateSelfAddress()).toUint8Array();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const hasEntry = !Binary.equals(this.targetAddress, NULL_ADDRESS);
|
|
196
|
-
let refBytesSize = 0;
|
|
197
|
-
if (hasEntry) {
|
|
198
|
-
refBytesSize = this.targetAddress.length;
|
|
199
|
-
} else {
|
|
200
|
-
for (const fork of this.forks.values()) {
|
|
201
|
-
if (fork.node.selfAddress) {
|
|
202
|
-
refBytesSize = fork.node.selfAddress.length;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
const header = new Uint8Array(32);
|
|
208
|
-
header.set(VERSION_02_HASH, 0);
|
|
209
|
-
header.set(Binary.numberToUint8(refBytesSize), 31);
|
|
210
|
-
const entry = hasEntry ? this.targetAddress : new Uint8Array(refBytesSize);
|
|
211
|
-
const forkBitmap = new Uint8Array(32);
|
|
212
|
-
for (const fork of this.forks.keys()) {
|
|
213
|
-
Binary.setBit(forkBitmap, fork, 1, 'LE');
|
|
214
|
-
}
|
|
215
|
-
const forks = [];
|
|
216
|
-
for (let i = 0; i < 256; i++) {
|
|
217
|
-
if (Binary.getBit(forkBitmap, i, 'LE')) {
|
|
218
|
-
forks.push(this.forks.get(i).marshal());
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const data = Binary.xorCypher(Binary.concatBytes(header, entry, forkBitmap, ...forks), this.obfuscationKey);
|
|
222
|
-
return Binary.concatBytes(this.obfuscationKey, data);
|
|
136
|
+
return this.core.marshal();
|
|
223
137
|
}
|
|
224
138
|
/**
|
|
225
139
|
* Downloads and unmarshals a MantarayNode from the given reference.
|
|
@@ -237,173 +151,49 @@ export class MantarayNode {
|
|
|
237
151
|
* Do not forget calling `loadRecursively` on the returned node to load the entire tree.
|
|
238
152
|
*/
|
|
239
153
|
static unmarshalFromData(data, selfAddress) {
|
|
240
|
-
|
|
241
|
-
const decrypted = Binary.xorCypher(data.subarray(32), obfuscationKey);
|
|
242
|
-
const reader = new Uint8ArrayReader(decrypted);
|
|
243
|
-
const versionHash = reader.read(31);
|
|
244
|
-
if (!Binary.equals(versionHash, VERSION_02_HASH.slice(0, 31))) {
|
|
245
|
-
throw new Error('MantarayNode#unmarshal invalid version hash');
|
|
246
|
-
}
|
|
247
|
-
const targetAddressLength = Binary.uint8ToNumber(reader.read(1));
|
|
248
|
-
const targetAddress = targetAddressLength ? reader.read(targetAddressLength) : NULL_ADDRESS;
|
|
249
|
-
const node = new MantarayNode({
|
|
250
|
-
selfAddress,
|
|
251
|
-
targetAddress,
|
|
252
|
-
obfuscationKey
|
|
253
|
-
});
|
|
254
|
-
const forkBitmap = reader.read(32);
|
|
255
|
-
if (targetAddressLength > 0) {
|
|
256
|
-
for (let i = 0; i < 256; i++) {
|
|
257
|
-
if (Binary.getBit(forkBitmap, i, 'LE')) {
|
|
258
|
-
const newFork = Fork.unmarshal(reader, selfAddress.length);
|
|
259
|
-
node.forks.set(i, newFork);
|
|
260
|
-
newFork.node.parent = node;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return node;
|
|
154
|
+
return new MantarayNode(CoreMantarayNode.unmarshalFromData(data, selfAddress));
|
|
265
155
|
}
|
|
266
156
|
/**
|
|
267
157
|
* Adds a fork to the node.
|
|
268
158
|
*/
|
|
269
159
|
addFork(path, reference, metadata) {
|
|
270
|
-
this.
|
|
271
|
-
this.type = null;
|
|
272
|
-
path = path instanceof Uint8Array ? path : ENCODER.encode(path);
|
|
273
|
-
debug('adding fork', {
|
|
274
|
-
path: DECODER.decode(path),
|
|
275
|
-
reference: new Reference(reference).represent()
|
|
276
|
-
});
|
|
277
|
-
// TODO: this should not be ignored
|
|
278
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
279
|
-
let tip = this;
|
|
280
|
-
while (path.length) {
|
|
281
|
-
const prefix = path.slice(0, 30);
|
|
282
|
-
path = path.slice(30);
|
|
283
|
-
const isLast = path.length === 0;
|
|
284
|
-
const [bestMatch, matchedPath] = tip.findClosest(prefix);
|
|
285
|
-
const remainingPath = prefix.slice(matchedPath.length);
|
|
286
|
-
if (matchedPath.length) {
|
|
287
|
-
tip = bestMatch;
|
|
288
|
-
}
|
|
289
|
-
if (!remainingPath.length) {
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
const newFork = new Fork(remainingPath, new MantarayNode({
|
|
293
|
-
targetAddress: isLast ? new Reference(reference).toUint8Array() : undefined,
|
|
294
|
-
metadata: isLast ? metadata : undefined,
|
|
295
|
-
path: remainingPath
|
|
296
|
-
}));
|
|
297
|
-
const existing = bestMatch.forks.get(remainingPath[0]);
|
|
298
|
-
if (existing) {
|
|
299
|
-
const fork = Fork.split(newFork, existing);
|
|
300
|
-
tip.forks.set(remainingPath[0], fork);
|
|
301
|
-
fork.node.parent = tip;
|
|
302
|
-
tip.selfAddress = null;
|
|
303
|
-
tip.type = null;
|
|
304
|
-
tip = newFork.node;
|
|
305
|
-
} else {
|
|
306
|
-
tip.forks.set(remainingPath[0], newFork);
|
|
307
|
-
newFork.node.parent = tip;
|
|
308
|
-
tip.selfAddress = null;
|
|
309
|
-
tip.type = null;
|
|
310
|
-
tip = newFork.node;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
160
|
+
this.core.addFork(path, reference instanceof Bytes ? reference.toUint8Array() : reference, metadata);
|
|
313
161
|
}
|
|
314
162
|
/**
|
|
315
163
|
* Removes a fork from the node.
|
|
316
164
|
*/
|
|
317
165
|
removeFork(path) {
|
|
318
|
-
this.
|
|
319
|
-
this.type = null;
|
|
320
|
-
path = path instanceof Uint8Array ? path : ENCODER.encode(path);
|
|
321
|
-
if (path.length === 0) {
|
|
322
|
-
throw Error('MantarayNode#removeFork [path] parameter cannot be empty');
|
|
323
|
-
}
|
|
324
|
-
const match = this.find(path);
|
|
325
|
-
if (!match) {
|
|
326
|
-
throw Error('MantarayNode#removeFork fork not found');
|
|
327
|
-
}
|
|
328
|
-
const [parent, matchedPath] = this.findClosest(path.slice(0, path.length - 1));
|
|
329
|
-
parent.forks.delete(path.slice(matchedPath.length)[0]);
|
|
330
|
-
for (const fork of match.forks.values()) {
|
|
331
|
-
parent.addFork(Binary.concatBytes(match.path, fork.prefix), fork.node.targetAddress, fork.node.metadata);
|
|
332
|
-
}
|
|
166
|
+
this.core.removeFork(path);
|
|
333
167
|
}
|
|
334
168
|
/**
|
|
335
169
|
* Calculates the self address of the node.
|
|
336
170
|
*/
|
|
337
171
|
async calculateSelfAddress() {
|
|
338
|
-
|
|
339
|
-
return new Reference(this.selfAddress);
|
|
340
|
-
}
|
|
341
|
-
return new Reference((await MerkleTree.root(await this.marshal())).hash());
|
|
172
|
+
return this.core.calculateSelfAddress();
|
|
342
173
|
}
|
|
343
174
|
/**
|
|
344
175
|
* Saves the node and its children recursively.
|
|
345
176
|
*/
|
|
346
177
|
async saveRecursively(bee, postageBatchId, options, requestOptions) {
|
|
347
|
-
|
|
348
|
-
const uploadResult = await fork.node.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
349
|
-
if (options?.act) {
|
|
350
|
-
let historyAddress;
|
|
351
|
-
uploadResult.historyAddress.ifPresent(ref => historyAddress = ref);
|
|
352
|
-
if (historyAddress) {
|
|
353
|
-
if (!fork.node.metadata) {
|
|
354
|
-
fork.node.metadata = {};
|
|
355
|
-
}
|
|
356
|
-
fork.node.metadata['swarm-act-history-address'] = historyAddress.toHex();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const result = await bee.data.upload(postageBatchId, await this.marshal(), options, requestOptions);
|
|
361
|
-
this.selfAddress = result.reference.toUint8Array();
|
|
362
|
-
return result;
|
|
178
|
+
return saveRecursively(this.core, bee, postageBatchId, options, requestOptions);
|
|
363
179
|
}
|
|
364
180
|
/**
|
|
365
181
|
* Loads the node and its children recursively.
|
|
366
182
|
*/
|
|
367
183
|
async loadRecursively(bee, options, requestOptions) {
|
|
368
|
-
|
|
369
|
-
if (!fork.node.selfAddress) {
|
|
370
|
-
throw Error('MantarayNode#loadRecursively fork.node.selfAddress is not set');
|
|
371
|
-
}
|
|
372
|
-
let downloadOptions = options;
|
|
373
|
-
if (fork.node.metadata && fork.node.metadata['swarm-act-history-address']) {
|
|
374
|
-
downloadOptions = {
|
|
375
|
-
...options,
|
|
376
|
-
actHistoryAddress: fork.node.metadata['swarm-act-history-address']
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
const node = await MantarayNode.unmarshal(bee, fork.node.selfAddress, downloadOptions, requestOptions);
|
|
380
|
-
fork.node.targetAddress = node.targetAddress;
|
|
381
|
-
fork.node.forks = node.forks;
|
|
382
|
-
fork.node.path = fork.prefix;
|
|
383
|
-
fork.node.parent = this;
|
|
384
|
-
await fork.node.loadRecursively(bee, options, requestOptions);
|
|
385
|
-
}
|
|
184
|
+
return loadRecursively(this.core, bee, options, requestOptions);
|
|
386
185
|
}
|
|
387
186
|
/**
|
|
388
187
|
* Finds a node in the tree by its path.
|
|
389
188
|
*/
|
|
390
189
|
find(path) {
|
|
391
|
-
|
|
392
|
-
return match.length === path.length ? closest : null;
|
|
190
|
+
return this.core.find(path);
|
|
393
191
|
}
|
|
394
192
|
/**
|
|
395
193
|
* Finds the closest node in the tree to the given path.
|
|
396
194
|
*/
|
|
397
|
-
findClosest(path, current
|
|
398
|
-
|
|
399
|
-
if (path.length === 0) {
|
|
400
|
-
return [this, current];
|
|
401
|
-
}
|
|
402
|
-
const fork = this.forks.get(path[0]);
|
|
403
|
-
if (fork && Binary.commonPrefix(fork.prefix, path).length === fork.prefix.length) {
|
|
404
|
-
return fork.node.findClosest(path.slice(fork.prefix.length), Binary.concatBytes(current, fork.prefix));
|
|
405
|
-
}
|
|
406
|
-
return [this, current];
|
|
195
|
+
findClosest(path, current) {
|
|
196
|
+
return this.core.findClosest(path, current);
|
|
407
197
|
}
|
|
408
198
|
/**
|
|
409
199
|
* Returns an array of all nodes in the tree which have a target address set.
|
|
@@ -411,13 +201,7 @@ export class MantarayNode {
|
|
|
411
201
|
* Must be called after `loadRecursively`.
|
|
412
202
|
*/
|
|
413
203
|
collect(nodes = []) {
|
|
414
|
-
|
|
415
|
-
if (!Binary.equals(fork.node.targetAddress, NULL_ADDRESS)) {
|
|
416
|
-
nodes.push(fork.node);
|
|
417
|
-
}
|
|
418
|
-
fork.node.collect(nodes);
|
|
419
|
-
}
|
|
420
|
-
return nodes;
|
|
204
|
+
return this.core.collect(nodes);
|
|
421
205
|
}
|
|
422
206
|
/**
|
|
423
207
|
* Returns a path:reference map of all nodes in the tree which have a target address set.
|
|
@@ -425,37 +209,9 @@ export class MantarayNode {
|
|
|
425
209
|
* Must be called after `loadRecursively`.
|
|
426
210
|
*/
|
|
427
211
|
collectAndMap() {
|
|
428
|
-
|
|
429
|
-
const result = {};
|
|
430
|
-
for (const node of nodes) {
|
|
431
|
-
result[node.fullPathString] = new Reference(node.targetAddress).toHex();
|
|
432
|
-
}
|
|
433
|
-
return result;
|
|
212
|
+
return this.core.collectAndMap();
|
|
434
213
|
}
|
|
435
214
|
determineType() {
|
|
436
|
-
|
|
437
|
-
// Mirror Bee (pkg/manifest/mantaray/node.go): Add() marks every explicitly
|
|
438
|
-
// added leaf as a value (makeValue), even one with a null entry such as a
|
|
439
|
-
// metadata-only "/" node. In final-state terms a leaf (no forks) is always an
|
|
440
|
-
// added entry, so it is a value; a node with forks is a value only when it also
|
|
441
|
-
// carries an entry. The path-separator flag is set only when a separator occurs
|
|
442
|
-
// past the first byte (IndexRune > 0), so a prefix that merely starts with '/'
|
|
443
|
-
// does not qualify.
|
|
444
|
-
if (!Binary.equals(this.targetAddress, NULL_ADDRESS) || this.forks.size === 0) {
|
|
445
|
-
type |= TYPE_VALUE;
|
|
446
|
-
}
|
|
447
|
-
if (this.forks.size > 0) {
|
|
448
|
-
type |= TYPE_EDGE;
|
|
449
|
-
}
|
|
450
|
-
if (Binary.indexOf(this.path, PATH_SEPARATOR) > 0) {
|
|
451
|
-
type |= TYPE_WITH_PATH_SEPARATOR;
|
|
452
|
-
}
|
|
453
|
-
if (this.metadata) {
|
|
454
|
-
type |= TYPE_WITH_METADATA;
|
|
455
|
-
}
|
|
456
|
-
return type;
|
|
215
|
+
return this.core.determineType();
|
|
457
216
|
}
|
|
458
|
-
}
|
|
459
|
-
function isType(value, type) {
|
|
460
|
-
return (value & type) === type;
|
|
461
217
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { PeerAddress } from '@ethersphere/core-sdk';
|
|
1
2
|
import * as balanceApi from "../api/balance.js";
|
|
2
3
|
import * as consumedApi from "../api/consumed.js";
|
|
3
|
-
import { PeerAddress } from "../utils/typed-bytes.js";
|
|
4
4
|
/**
|
|
5
5
|
* SWAP balance operations. Related to the bandwidth incentives and the chequebook.
|
|
6
6
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { PeerAddress } from '@ethersphere/core-sdk';
|
|
1
2
|
import { TransactionOptionsSchema } from "../utils/schema.js";
|
|
2
|
-
import { PeerAddress } from "../utils/typed-bytes.js";
|
|
3
3
|
import * as api from "../api/chequebook.js";
|
|
4
4
|
/**
|
|
5
5
|
* Cheque operations (last cheques and cashouts).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Identifier, Reference, Signature, Span } from '@ethersphere/core-sdk';
|
|
1
2
|
import { CHUNK_SIZE } from "../types/index.js";
|
|
2
3
|
import { BeeArgumentError } from "../utils/error.js";
|
|
3
4
|
import { DownloadOptionsSchema, UploadOptionsSchema } from "../utils/schema.js";
|
|
4
|
-
import { Identifier, Reference, Signature, Span } from "../utils/typed-bytes.js";
|
|
5
5
|
import * as api from "../api/chunk.js";
|
|
6
6
|
/**
|
|
7
7
|
* Chunk operations backed by the `/chunks` endpoint.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { BatchId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { hashDirectory as hashDirectoryImpl, streamDirectory as streamDirectoryImpl, streamFiles as streamFilesImpl } from "../utils/chunk-stream.js";
|
|
2
3
|
import { assertCollection, makeCollectionFromFileList } from "../utils/collection.js";
|
|
3
4
|
import { makeCollectionFromFS } from "../utils/collection.node.js";
|
|
4
5
|
import { CollectionUploadOptionsSchema } from "../utils/schema.js";
|
|
5
|
-
import { BatchId } from "../utils/typed-bytes.js";
|
|
6
6
|
import * as api from "../api/bzz.js";
|
|
7
7
|
/**
|
|
8
8
|
* Collection (multi-file) operations backed by the `/bzz` endpoint.
|
package/dist/mjs/modules/data.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { BatchId, Reference } from '@ethersphere/core-sdk';
|
|
2
|
+
import * as bytes from "../api/bytes.js";
|
|
3
|
+
import * as stewardship from "../api/stewardship.js";
|
|
1
4
|
import { ResourceLocator } from "../utils/resource-locator.js";
|
|
2
5
|
import { DownloadOptionsSchema, RedundantUploadOptionsSchema } from "../utils/schema.js";
|
|
3
6
|
import { assertData } from "../utils/type.js";
|
|
4
|
-
import { BatchId, Reference } from "../utils/typed-bytes.js";
|
|
5
|
-
import * as bytes from "../api/bytes.js";
|
|
6
|
-
import * as stewardship from "../api/stewardship.js";
|
|
7
7
|
/**
|
|
8
8
|
* Raw data operations backed by the `/bytes` endpoint.
|
|
9
9
|
*
|
package/dist/mjs/modules/feed.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { BatchId, EthAddress, PrivateKey, Topic } from '@ethersphere/core-sdk';
|
|
1
2
|
import { Objects } from 'cafe-utility';
|
|
2
3
|
import { createFeedManifest, fetchLatestFeedUpdate } from "../api/feed.js";
|
|
3
4
|
import { makeFeedReader, makeFeedWriter } from "../feed/index.js";
|
|
4
5
|
import { areAllSequentialFeedsUpdateRetrievable } from "../feed/retrievable.js";
|
|
5
6
|
import { DownloadOptionsSchema, UploadOptionsSchema } from "../utils/schema.js";
|
|
6
|
-
import { BatchId, EthAddress, PrivateKey, Topic } from "../utils/typed-bytes.js";
|
|
7
7
|
/**
|
|
8
8
|
* Feed operations.
|
|
9
9
|
*
|
package/dist/mjs/modules/file.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { BatchId, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import { fileArrayBuffer, isFile } from "../utils/file.js";
|
|
2
3
|
import { ResourceLocator } from "../utils/resource-locator.js";
|
|
3
4
|
import { DownloadOptionsSchema, FileUploadOptionsSchema } from "../utils/schema.js";
|
|
4
5
|
import { assertFileData } from "../utils/type.js";
|
|
5
|
-
import { BatchId, Reference } from "../utils/typed-bytes.js";
|
|
6
6
|
import * as api from "../api/bzz.js";
|
|
7
7
|
/**
|
|
8
8
|
* Single-file operations backed by the `/bzz` endpoint.
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Binary, System } from 'cafe-utility';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
|
-
import { makeContentAddressedChunk } from
|
|
4
|
-
import { makeSOCAddress, uploadSingleOwnerChunk } from "../chunk/soc.js";
|
|
3
|
+
import { BatchId, Bytes, EthAddress, Identifier, makeContentAddressedChunk, numberToUint256, PeerAddress, PrivateKey, PublicKey } from '@ethersphere/core-sdk';
|
|
5
4
|
import * as pssApi from "../api/pss.js";
|
|
6
|
-
import {
|
|
5
|
+
import { makeSOCAddress, uploadSingleOwnerChunk } from "../chunk/soc.js";
|
|
7
6
|
import { prepareWebsocketData } from "../utils/data.js";
|
|
8
7
|
import { BeeError } from "../utils/error.js";
|
|
9
8
|
import { GsocMessageHandlerSchema, PssMessageHandlerSchema } from "../utils/schema.js";
|
|
10
9
|
import { assertData } from "../utils/type.js";
|
|
11
|
-
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey } from "../utils/typed-bytes.js";
|
|
12
10
|
const PSS_ENDPOINT = 'pss';
|
|
13
11
|
const GSOC_ENDPOINT = 'gsoc';
|
|
14
12
|
/**
|
|
@@ -122,7 +120,7 @@ export class Messaging {
|
|
|
122
120
|
const id = new Identifier(identifier);
|
|
123
121
|
const start = 0xb33n;
|
|
124
122
|
for (let i = 0n; i < 0xffffn; i++) {
|
|
125
|
-
const signer = new PrivateKey(
|
|
123
|
+
const signer = new PrivateKey(numberToUint256(start + i, 'BE'));
|
|
126
124
|
const socAddress = makeSOCAddress(id, signer.publicKey().address());
|
|
127
125
|
// TODO: test the significance of the hardcoded 256
|
|
128
126
|
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), overlay.toUint8Array());
|
package/dist/mjs/modules/pin.js
CHANGED