@upcoming/bee-js 0.1.0 → 0.3.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 +8 -2
- package/dist/cjs/bee.js +59 -9
- package/dist/cjs/chunk/soc.js +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/manifest/manifest.js +17 -1
- package/dist/cjs/modules/debug/chequebook.js +6 -5
- package/dist/cjs/modules/debug/connectivity.js +1 -1
- package/dist/cjs/modules/debug/settlements.js +7 -6
- package/dist/cjs/modules/debug/stake.js +5 -4
- package/dist/cjs/modules/debug/states.js +3 -2
- package/dist/cjs/modules/gsoc.js +20 -0
- package/dist/cjs/utils/constants.js +2 -1
- package/dist/cjs/utils/expose.js +2 -3
- package/dist/cjs/utils/http.js +1 -1
- package/dist/cjs/utils/pss.js +3 -3
- package/dist/cjs/utils/stamps.js +8 -21
- package/dist/cjs/utils/tokens.js +48 -0
- package/dist/cjs/utils/type.js +10 -11
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +62 -12
- package/dist/mjs/chunk/soc.js +2 -2
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/manifest/manifest.js +17 -1
- package/dist/mjs/modules/debug/chequebook.js +11 -10
- package/dist/mjs/modules/debug/connectivity.js +3 -3
- package/dist/mjs/modules/debug/settlements.js +13 -12
- package/dist/mjs/modules/debug/stake.js +9 -8
- package/dist/mjs/modules/debug/states.js +5 -4
- package/dist/mjs/modules/gsoc.js +12 -0
- package/dist/mjs/utils/constants.js +2 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/http.js +1 -1
- package/dist/mjs/utils/pss.js +3 -3
- package/dist/mjs/utils/stamps.js +6 -18
- package/dist/mjs/utils/tokens.js +43 -0
- package/dist/mjs/utils/type.js +20 -10
- package/dist/types/bee.d.ts +7 -6
- package/dist/types/chunk/soc.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/manifest/manifest.d.ts +4 -0
- package/dist/types/modules/debug/stake.d.ts +2 -1
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/types/debug.d.ts +17 -16
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/utils/constants.d.ts +1 -0
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +2 -1
- package/dist/types/utils/stamps.d.ts +2 -11
- package/dist/types/utils/tokens.d.ts +21 -0
- package/dist/types/utils/type.d.ts +2 -1
- package/package.json +2 -2
package/dist/mjs/bee.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Objects, System } from 'cafe-utility';
|
|
2
|
-
import {
|
|
1
|
+
import { Binary, Objects, System } from 'cafe-utility';
|
|
2
|
+
import { makeContentAddressedChunk } from "./chunk/cac.js";
|
|
3
|
+
import { downloadSingleOwnerChunk, makeSOCAddress, makeSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
|
|
3
4
|
import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
|
|
4
5
|
import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
|
|
5
6
|
import * as bytes from "./modules/bytes.js";
|
|
@@ -17,6 +18,7 @@ import * as transactions from "./modules/debug/transactions.js";
|
|
|
17
18
|
import { postEnvelope } from "./modules/envelope.js";
|
|
18
19
|
import { createFeedManifest } from "./modules/feed.js";
|
|
19
20
|
import * as grantee from "./modules/grantee.js";
|
|
21
|
+
import * as gsoc from "./modules/gsoc.js";
|
|
20
22
|
import * as pinning from "./modules/pinning.js";
|
|
21
23
|
import * as pss from "./modules/pss.js";
|
|
22
24
|
import * as status from "./modules/status.js";
|
|
@@ -30,8 +32,8 @@ import { makeCollectionFromFS } from "./utils/collection.node.js";
|
|
|
30
32
|
import { prepareWebsocketData } from "./utils/data.js";
|
|
31
33
|
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
32
34
|
import { fileArrayBuffer, isFile } from "./utils/file.js";
|
|
33
|
-
import { asNumberString, assertAllTagsOptions, assertCashoutOptions, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertNonNegativeInteger, assertPostageBatchOptions, assertPssMessageHandler, assertRequestOptions, assertTransactionOptions, assertUploadOptions,
|
|
34
|
-
import { BatchId, EthAddress, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
35
|
+
import { asNumberString, assertAllTagsOptions, assertCashoutOptions, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertGsocMessageHandler, assertNonNegativeInteger, assertPostageBatchOptions, assertPssMessageHandler, assertRequestOptions, assertTransactionOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
|
|
36
|
+
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
35
37
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
36
38
|
/**
|
|
37
39
|
* The main component that abstracts operations available on the main Bee API.
|
|
@@ -212,9 +214,6 @@ export class Bee {
|
|
|
212
214
|
/**
|
|
213
215
|
* Upload single file to a Bee node.
|
|
214
216
|
*
|
|
215
|
-
* **To make sure that you won't lose critical data it is highly recommended to also
|
|
216
|
-
* locally pin the data with `options.pin = true`**
|
|
217
|
-
*
|
|
218
217
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
219
218
|
* @param data Data or file to be uploaded
|
|
220
219
|
* @param name Optional name of the uploaded file
|
|
@@ -244,11 +243,6 @@ export class Bee {
|
|
|
244
243
|
...options
|
|
245
244
|
};
|
|
246
245
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
247
|
-
} else if (isReadable(data) && options?.tag && !options.size) {
|
|
248
|
-
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
249
|
-
const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
250
|
-
await this.updateTag(options.tag, result.reference);
|
|
251
|
-
return result;
|
|
252
246
|
} else {
|
|
253
247
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
254
248
|
}
|
|
@@ -695,6 +689,62 @@ export class Bee {
|
|
|
695
689
|
}
|
|
696
690
|
});
|
|
697
691
|
}
|
|
692
|
+
gsocMine(targetOverlay, identifier, proximity = 16) {
|
|
693
|
+
targetOverlay = new PeerAddress(targetOverlay);
|
|
694
|
+
identifier = new Identifier(identifier);
|
|
695
|
+
const start = 0xb33n;
|
|
696
|
+
for (let i = 0n; i < 0xffffn; i++) {
|
|
697
|
+
const signer = new PrivateKey(Binary.numberToUint256(start + i, 'BE'));
|
|
698
|
+
const socAddress = makeSOCAddress(identifier, signer.publicKey().address());
|
|
699
|
+
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256);
|
|
700
|
+
if (actualProximity <= 256 - proximity) {
|
|
701
|
+
return signer;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
throw Error('Could not mine a valid signer');
|
|
705
|
+
}
|
|
706
|
+
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
707
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
708
|
+
signer = new PrivateKey(signer);
|
|
709
|
+
identifier = new Identifier(identifier);
|
|
710
|
+
const cac = makeContentAddressedChunk(data);
|
|
711
|
+
const soc = makeSingleOwnerChunk(cac, identifier, signer);
|
|
712
|
+
return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
|
|
713
|
+
}
|
|
714
|
+
gsocSubscribe(address, identifier, handler) {
|
|
715
|
+
address = new EthAddress(address);
|
|
716
|
+
identifier = new Identifier(identifier);
|
|
717
|
+
assertGsocMessageHandler(handler);
|
|
718
|
+
const socAddress = makeSOCAddress(identifier, address);
|
|
719
|
+
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
720
|
+
let cancelled = false;
|
|
721
|
+
const cancel = () => {
|
|
722
|
+
if (cancelled === false) {
|
|
723
|
+
cancelled = true;
|
|
724
|
+
if (ws.terminate) {
|
|
725
|
+
ws.terminate();
|
|
726
|
+
} else {
|
|
727
|
+
ws.close();
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
const subscription = {
|
|
732
|
+
address,
|
|
733
|
+
cancel
|
|
734
|
+
};
|
|
735
|
+
ws.onmessage = async event => {
|
|
736
|
+
const data = await prepareWebsocketData(event.data);
|
|
737
|
+
if (data.length) {
|
|
738
|
+
handler.onMessage(new Bytes(data), subscription);
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
ws.onerror = event => {
|
|
742
|
+
if (!cancelled) {
|
|
743
|
+
handler.onError(new BeeError(event.message), subscription);
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
return subscription;
|
|
747
|
+
}
|
|
698
748
|
/**
|
|
699
749
|
* Create feed manifest chunk and return the reference to it.
|
|
700
750
|
*
|
package/dist/mjs/chunk/soc.js
CHANGED
|
@@ -58,7 +58,7 @@ export function makeSOCAddress(identifier, address) {
|
|
|
58
58
|
* @param identifier The identifier of the chunk
|
|
59
59
|
* @param signer The signer interface for signing the chunk
|
|
60
60
|
*/
|
|
61
|
-
export
|
|
61
|
+
export function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
62
62
|
identifier = new Identifier(identifier);
|
|
63
63
|
signer = new PrivateKey(signer);
|
|
64
64
|
const address = makeSOCAddress(identifier, signer.publicKey().address());
|
|
@@ -104,7 +104,7 @@ export async function uploadSingleOwnerChunkData(requestOptions, signer, stamp,
|
|
|
104
104
|
signer = new PrivateKey(signer);
|
|
105
105
|
identifier = new Identifier(identifier);
|
|
106
106
|
const cac = makeContentAddressedChunk(data);
|
|
107
|
-
const soc =
|
|
107
|
+
const soc = makeSingleOwnerChunk(cac, identifier, signer);
|
|
108
108
|
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
109
109
|
}
|
|
110
110
|
/**
|
package/dist/mjs/index.js
CHANGED
|
@@ -28,6 +28,8 @@ export class Fork {
|
|
|
28
28
|
b.prefix = b.prefix.slice(commonPart.length);
|
|
29
29
|
node.forks.set(newAFork.prefix[0], newAFork);
|
|
30
30
|
node.forks.set(newBFork.prefix[0], newBFork);
|
|
31
|
+
newAFork.node.parent = node;
|
|
32
|
+
newBFork.node.parent = node;
|
|
31
33
|
return new Fork(commonPart, node);
|
|
32
34
|
}
|
|
33
35
|
marshal() {
|
|
@@ -76,6 +78,7 @@ export class MantarayNode {
|
|
|
76
78
|
this.metadata = null;
|
|
77
79
|
this.path = new Uint8Array(0);
|
|
78
80
|
this.forks = new Map();
|
|
81
|
+
this.parent = null;
|
|
79
82
|
if (options?.targetAddress) {
|
|
80
83
|
this.targetAddress = options.targetAddress;
|
|
81
84
|
}
|
|
@@ -91,6 +94,15 @@ export class MantarayNode {
|
|
|
91
94
|
if (options?.path) {
|
|
92
95
|
this.path = options.path;
|
|
93
96
|
}
|
|
97
|
+
if (options?.parent) {
|
|
98
|
+
this.parent = options.parent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get fullPath() {
|
|
102
|
+
return Binary.concatBytes(this.parent?.fullPath ?? new Uint8Array(0), this.path);
|
|
103
|
+
}
|
|
104
|
+
get fullPathString() {
|
|
105
|
+
return DECODER.decode(this.fullPath);
|
|
94
106
|
}
|
|
95
107
|
async marshal() {
|
|
96
108
|
for (const fork of this.forks.values()) {
|
|
@@ -132,7 +144,9 @@ export class MantarayNode {
|
|
|
132
144
|
const forkBitmap = reader.read(32);
|
|
133
145
|
for (let i = 0; i < 256; i++) {
|
|
134
146
|
if (Binary.getBit(forkBitmap, i, 'LE')) {
|
|
135
|
-
|
|
147
|
+
const newFork = Fork.unmarshal(reader);
|
|
148
|
+
node.forks.set(i, newFork);
|
|
149
|
+
newFork.node.parent = node;
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
152
|
return node;
|
|
@@ -164,10 +178,12 @@ export class MantarayNode {
|
|
|
164
178
|
if (existing) {
|
|
165
179
|
const fork = Fork.split(newFork, existing);
|
|
166
180
|
tip.forks.set(remainingPath[0], fork);
|
|
181
|
+
fork.node.parent = tip;
|
|
167
182
|
tip.selfAddress = null;
|
|
168
183
|
tip = newFork.node;
|
|
169
184
|
} else {
|
|
170
185
|
tip.forks.set(remainingPath[0], newFork);
|
|
186
|
+
newFork.node.parent = tip;
|
|
171
187
|
tip.selfAddress = null;
|
|
172
188
|
tip = newFork.node;
|
|
173
189
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from 'cafe-utility';
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { BZZ } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
5
|
import { EthAddress, TransactionId } from "../../utils/typed-bytes.js";
|
|
5
6
|
const chequebookEndpoint = 'chequebook';
|
|
@@ -36,12 +37,12 @@ export async function getChequebookBalance(requestOptions) {
|
|
|
36
37
|
name: 'response.data'
|
|
37
38
|
});
|
|
38
39
|
return {
|
|
39
|
-
availableBalance: asNumberString(body.availableBalance, {
|
|
40
|
+
availableBalance: BZZ.fromPLUR(asNumberString(body.availableBalance, {
|
|
40
41
|
name: 'availableBalance'
|
|
41
|
-
}),
|
|
42
|
-
totalBalance: asNumberString(body.totalBalance, {
|
|
42
|
+
})),
|
|
43
|
+
totalBalance: BZZ.fromPLUR(asNumberString(body.totalBalance, {
|
|
43
44
|
name: 'totalBalance'
|
|
44
|
-
})
|
|
45
|
+
}))
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
@@ -62,9 +63,9 @@ export async function getLastCashoutAction(requestOptions, peer) {
|
|
|
62
63
|
peer: Types.asString(body.peer, {
|
|
63
64
|
name: 'peer'
|
|
64
65
|
}),
|
|
65
|
-
uncashedAmount: asNumberString(body.uncashedAmount, {
|
|
66
|
+
uncashedAmount: BZZ.fromPLUR(asNumberString(body.uncashedAmount, {
|
|
66
67
|
name: 'uncashedAmount'
|
|
67
|
-
}),
|
|
68
|
+
})),
|
|
68
69
|
transactionHash: Types.asNullableString(body.transactionHash),
|
|
69
70
|
lastCashedCheque: Types.asNullable(x => asCheque(x), body.lastCashedCheque),
|
|
70
71
|
result: Types.asNullable(x => asCashoutResult(x), body.result)
|
|
@@ -159,9 +160,9 @@ function asCheque(x) {
|
|
|
159
160
|
chequebook: new EthAddress(Types.asString(object.chequebook, {
|
|
160
161
|
name: 'chequebook'
|
|
161
162
|
})),
|
|
162
|
-
payout: asNumberString(object.payout, {
|
|
163
|
+
payout: BZZ.fromPLUR(asNumberString(object.payout, {
|
|
163
164
|
name: 'payout'
|
|
164
|
-
})
|
|
165
|
+
}))
|
|
165
166
|
};
|
|
166
167
|
}
|
|
167
168
|
function asCashoutResult(x) {
|
|
@@ -172,9 +173,9 @@ function asCashoutResult(x) {
|
|
|
172
173
|
recipient: Types.asString(object.recipient, {
|
|
173
174
|
name: 'recipient'
|
|
174
175
|
}),
|
|
175
|
-
lastPayout: asNumberString(object.lastPayout, {
|
|
176
|
+
lastPayout: BZZ.fromPLUR(asNumberString(object.lastPayout, {
|
|
176
177
|
name: 'lastPayout'
|
|
177
|
-
}),
|
|
178
|
+
})),
|
|
178
179
|
bounced: Types.asBoolean(object.bounced, {
|
|
179
180
|
name: 'bounced'
|
|
180
181
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Types } from 'cafe-utility';
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
-
import { EthAddress, PublicKey } from "../../utils/typed-bytes.js";
|
|
3
|
+
import { EthAddress, PeerAddress, PublicKey } from "../../utils/typed-bytes.js";
|
|
4
4
|
export async function getNodeAddresses(requestOptions) {
|
|
5
5
|
const response = await http(requestOptions, {
|
|
6
6
|
url: 'addresses',
|
|
@@ -10,9 +10,9 @@ export async function getNodeAddresses(requestOptions) {
|
|
|
10
10
|
name: 'response.data'
|
|
11
11
|
});
|
|
12
12
|
return {
|
|
13
|
-
overlay: Types.asString(body.overlay, {
|
|
13
|
+
overlay: new PeerAddress(Types.asString(body.overlay, {
|
|
14
14
|
name: 'overlay'
|
|
15
|
-
}),
|
|
15
|
+
})),
|
|
16
16
|
underlay: Types.asArray(body.underlay, {
|
|
17
17
|
name: 'underlay'
|
|
18
18
|
}).map(x => Types.asString(x, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from 'cafe-utility';
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { BZZ } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
5
|
const settlementsEndpoint = 'settlements';
|
|
5
6
|
/**
|
|
@@ -20,12 +21,12 @@ export async function getSettlements(requestOptions, peer) {
|
|
|
20
21
|
peer: Types.asString(body.peer, {
|
|
21
22
|
name: 'peer'
|
|
22
23
|
}),
|
|
23
|
-
sent: asNumberString(body.sent, {
|
|
24
|
+
sent: BZZ.fromPLUR(asNumberString(body.sent, {
|
|
24
25
|
name: 'sent'
|
|
25
|
-
}),
|
|
26
|
-
received: asNumberString(body.received, {
|
|
26
|
+
})),
|
|
27
|
+
received: BZZ.fromPLUR(asNumberString(body.received, {
|
|
27
28
|
name: 'received'
|
|
28
|
-
})
|
|
29
|
+
}))
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -41,12 +42,12 @@ export async function getAllSettlements(requestOptions) {
|
|
|
41
42
|
const body = Types.asObject(response.data, {
|
|
42
43
|
name: 'response.data'
|
|
43
44
|
});
|
|
44
|
-
const totalSent = asNumberString(body.totalSent, {
|
|
45
|
+
const totalSent = BZZ.fromPLUR(asNumberString(body.totalSent, {
|
|
45
46
|
name: 'totalSent'
|
|
46
|
-
});
|
|
47
|
-
const totalReceived = asNumberString(body.totalReceived, {
|
|
47
|
+
}));
|
|
48
|
+
const totalReceived = BZZ.fromPLUR(asNumberString(body.totalReceived, {
|
|
48
49
|
name: 'totalReceived'
|
|
49
|
-
});
|
|
50
|
+
}));
|
|
50
51
|
const settlements = Types.asArray(body.settlements, {
|
|
51
52
|
name: 'settlements'
|
|
52
53
|
}).map(x => Types.asObject(x, {
|
|
@@ -59,12 +60,12 @@ export async function getAllSettlements(requestOptions) {
|
|
|
59
60
|
peer: Types.asString(x.peer, {
|
|
60
61
|
name: 'peer'
|
|
61
62
|
}),
|
|
62
|
-
sent: asNumberString(x.sent, {
|
|
63
|
+
sent: BZZ.fromPLUR(asNumberString(x.sent, {
|
|
63
64
|
name: 'sent'
|
|
64
|
-
}),
|
|
65
|
-
received: asNumberString(x.received, {
|
|
65
|
+
})),
|
|
66
|
+
received: BZZ.fromPLUR(asNumberString(x.received, {
|
|
66
67
|
name: 'received'
|
|
67
|
-
})
|
|
68
|
+
}))
|
|
68
69
|
}))
|
|
69
70
|
};
|
|
70
71
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from 'cafe-utility';
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
5
|
const STAKE_ENDPOINT = 'stake';
|
|
5
6
|
const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
|
|
@@ -17,9 +18,9 @@ export async function getStake(requestOptions) {
|
|
|
17
18
|
const body = Types.asObject(response.data, {
|
|
18
19
|
name: 'response.data'
|
|
19
20
|
});
|
|
20
|
-
return asNumberString(body.stakedAmount, {
|
|
21
|
+
return BZZ.fromPLUR(asNumberString(body.stakedAmount, {
|
|
21
22
|
name: 'stakedAmount'
|
|
22
|
-
});
|
|
23
|
+
}));
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Stake given amount of tokens.
|
|
@@ -58,9 +59,9 @@ export async function getRedistributionState(requestOptions) {
|
|
|
58
59
|
name: 'response.data'
|
|
59
60
|
});
|
|
60
61
|
return {
|
|
61
|
-
minimumGasFunds: asNumberString(body.minimumGasFunds, {
|
|
62
|
+
minimumGasFunds: DAI.fromWei(asNumberString(body.minimumGasFunds, {
|
|
62
63
|
name: 'minimumGasFunds'
|
|
63
|
-
}),
|
|
64
|
+
})),
|
|
64
65
|
hasSufficientFunds: Types.asBoolean(body.hasSufficientFunds, {
|
|
65
66
|
name: 'hasSufficientFunds'
|
|
66
67
|
}),
|
|
@@ -94,12 +95,12 @@ export async function getRedistributionState(requestOptions) {
|
|
|
94
95
|
block: Types.asNumber(body.block, {
|
|
95
96
|
name: 'block'
|
|
96
97
|
}),
|
|
97
|
-
reward: asNumberString(body.reward, {
|
|
98
|
+
reward: BZZ.fromPLUR(asNumberString(body.reward, {
|
|
98
99
|
name: 'reward'
|
|
99
|
-
}),
|
|
100
|
-
fees: asNumberString(body.fees, {
|
|
100
|
+
})),
|
|
101
|
+
fees: DAI.fromWei(asNumberString(body.fees, {
|
|
101
102
|
name: 'fees'
|
|
102
|
-
}),
|
|
103
|
+
})),
|
|
103
104
|
isHealthy: Types.asBoolean(body.isHealthy, {
|
|
104
105
|
name: 'isHealthy'
|
|
105
106
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from 'cafe-utility';
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
5
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
5
6
|
const WALLET_ENDPOINT = 'wallet';
|
|
@@ -74,12 +75,12 @@ export async function getWalletBalance(requestOptions) {
|
|
|
74
75
|
name: 'response.data'
|
|
75
76
|
});
|
|
76
77
|
return {
|
|
77
|
-
bzzBalance: asNumberString(body.bzzBalance, {
|
|
78
|
+
bzzBalance: BZZ.fromPLUR(asNumberString(body.bzzBalance, {
|
|
78
79
|
name: 'bzzBalance'
|
|
79
|
-
}),
|
|
80
|
-
nativeTokenBalance: asNumberString(body.nativeTokenBalance, {
|
|
80
|
+
})),
|
|
81
|
+
nativeTokenBalance: DAI.fromWei(asNumberString(body.nativeTokenBalance, {
|
|
81
82
|
name: 'nativeTokenBalance'
|
|
82
|
-
}),
|
|
83
|
+
})),
|
|
83
84
|
chainID: Types.asNumber(body.chainID, {
|
|
84
85
|
name: 'chainID'
|
|
85
86
|
}),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
import { uploadSingleOwnerChunk } from "../chunk/soc.js";
|
|
3
|
+
const endpoint = 'gsoc';
|
|
4
|
+
export async function send(requestOptions, soc, stamp, options) {
|
|
5
|
+
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
6
|
+
}
|
|
7
|
+
export function subscribe(url, reference, headers) {
|
|
8
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
9
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`, {
|
|
10
|
+
headers
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -2,4 +2,5 @@ import { BatchId, Topic } from "./typed-bytes.js";
|
|
|
2
2
|
export const SWARM_GATEWAY_URL = 'https://api.gateway.ethswarm.org';
|
|
3
3
|
export const NULL_STAMP = new BatchId('0000000000000000000000000000000000000000000000000000000000000000');
|
|
4
4
|
export const NULL_TOPIC = new Topic('0000000000000000000000000000000000000000000000000000000000000000');
|
|
5
|
-
export const NULL_ADDRESS = new Uint8Array(32);
|
|
5
|
+
export const NULL_ADDRESS = new Uint8Array(32);
|
|
6
|
+
export const NULL_IDENTIFIER = new Uint8Array(32);
|
package/dist/mjs/utils/expose.js
CHANGED
|
@@ -2,4 +2,4 @@ export { getCollectionSize } from "./collection.js";
|
|
|
2
2
|
export { getFolderSize } from "./collection.node.js";
|
|
3
3
|
export { makeMaxTarget } from "./pss.js";
|
|
4
4
|
export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
|
|
5
|
-
export { getAmountForTtl, getDepthForCapacity,
|
|
5
|
+
export { getAmountForTtl, getDepthForCapacity, getStampCost, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -18,10 +18,10 @@ export const DEFAULT_HTTP_CONFIG = {
|
|
|
18
18
|
* @param config Internal settings and/or Bee settings
|
|
19
19
|
*/
|
|
20
20
|
export async function http(options, config) {
|
|
21
|
+
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
21
22
|
let failedAttempts = 0;
|
|
22
23
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
23
24
|
try {
|
|
24
|
-
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
25
25
|
maybeRunOnRequestHook(options, requestConfig);
|
|
26
26
|
const response = await axios(requestConfig);
|
|
27
27
|
return response;
|
package/dist/mjs/utils/pss.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Types } from 'cafe-utility';
|
|
2
1
|
import { PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
2
|
+
import { PeerAddress } from "./typed-bytes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Utility function that for given strings/reference takes the most specific
|
|
5
5
|
* target that Bee node will except.
|
|
@@ -8,6 +8,6 @@ import { PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
|
8
8
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
9
9
|
*/
|
|
10
10
|
export function makeMaxTarget(target) {
|
|
11
|
-
|
|
12
|
-
return
|
|
11
|
+
target = new PeerAddress(target);
|
|
12
|
+
return target.toHex().slice(0, PSS_TARGET_HEX_LENGTH_MAX);
|
|
13
13
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Binary } from 'cafe-utility';
|
|
2
2
|
import { Bytes } from "./bytes.js";
|
|
3
|
+
import { BZZ } from "./tokens.js";
|
|
3
4
|
import { asNumberString } from "./type.js";
|
|
4
5
|
/**
|
|
5
6
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
@@ -56,23 +57,10 @@ export function getStampEffectiveBytes(depth) {
|
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
59
|
-
*
|
|
60
|
-
* @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
|
|
61
|
-
*/
|
|
62
|
-
export function getStampCostInPlur(depth, amount) {
|
|
63
|
-
const amountBigint = BigInt(asNumberString(amount));
|
|
64
|
-
return 2n ** BigInt(depth) * amountBigint;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
68
|
-
*
|
|
69
|
-
* The returned number is lossy and should be used for display purposes only.
|
|
70
|
-
*
|
|
71
|
-
* @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
|
|
72
60
|
*/
|
|
73
|
-
export function
|
|
74
|
-
const
|
|
75
|
-
return
|
|
61
|
+
export function getStampCost(depth, amount) {
|
|
62
|
+
const amountBigInt = BigInt(asNumberString(amount));
|
|
63
|
+
return BZZ.fromPLUR(2n ** BigInt(depth) * amountBigInt);
|
|
76
64
|
}
|
|
77
65
|
/**
|
|
78
66
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
@@ -82,8 +70,8 @@ export function getStampCostInBzz(depth, amount) {
|
|
|
82
70
|
* @returns {number} The TTL of the postage batch in seconds.
|
|
83
71
|
*/
|
|
84
72
|
export function getStampTtlSeconds(amount, pricePerBlock = 24000, blockTime = 5) {
|
|
85
|
-
const
|
|
86
|
-
return
|
|
73
|
+
const amountBigInt = BigInt(asNumberString(amount));
|
|
74
|
+
return amountBigInt * BigInt(blockTime) / BigInt(pricePerBlock);
|
|
87
75
|
}
|
|
88
76
|
/**
|
|
89
77
|
* Utility function that calculates the amount of tokens required to maintain a given Time To Live (TTL) for a postage batch.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FixedPointNumber } from 'cafe-utility';
|
|
2
|
+
export class BZZ {
|
|
3
|
+
constructor(state) {
|
|
4
|
+
this.state = state;
|
|
5
|
+
}
|
|
6
|
+
static fromDecimalString(string) {
|
|
7
|
+
return new BZZ(FixedPointNumber.fromDecimalString(string, BZZ.DIGITS));
|
|
8
|
+
}
|
|
9
|
+
static fromPLUR(plur) {
|
|
10
|
+
return new BZZ(new FixedPointNumber(plur, BZZ.DIGITS));
|
|
11
|
+
}
|
|
12
|
+
toPLURString() {
|
|
13
|
+
return this.state.toString();
|
|
14
|
+
}
|
|
15
|
+
toPLURBigInt() {
|
|
16
|
+
return this.state.value;
|
|
17
|
+
}
|
|
18
|
+
toDecimalString() {
|
|
19
|
+
return this.state.toDecimalString();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
BZZ.DIGITS = 16;
|
|
23
|
+
export class DAI {
|
|
24
|
+
constructor(state) {
|
|
25
|
+
this.state = state;
|
|
26
|
+
}
|
|
27
|
+
static fromDecimalString(string) {
|
|
28
|
+
return new DAI(FixedPointNumber.fromDecimalString(string, DAI.DIGITS));
|
|
29
|
+
}
|
|
30
|
+
static fromWei(wei) {
|
|
31
|
+
return new DAI(new FixedPointNumber(wei, DAI.DIGITS));
|
|
32
|
+
}
|
|
33
|
+
toWeiString() {
|
|
34
|
+
return this.state.toString();
|
|
35
|
+
}
|
|
36
|
+
toWeiBigInt() {
|
|
37
|
+
return this.state.value;
|
|
38
|
+
}
|
|
39
|
+
toDecimalString() {
|
|
40
|
+
return this.state.toDecimalString();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
DAI.DIGITS = 18;
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -97,16 +97,26 @@ export function isTag(value) {
|
|
|
97
97
|
return Boolean(value.uid);
|
|
98
98
|
}
|
|
99
99
|
export function assertPssMessageHandler(value) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
const object = Types.asObject(value, {
|
|
101
|
+
name: 'PssMessageHandler'
|
|
102
|
+
});
|
|
103
|
+
Types.asFunction(object.onMessage, {
|
|
104
|
+
name: 'onMessage'
|
|
105
|
+
});
|
|
106
|
+
Types.asFunction(object.onError, {
|
|
107
|
+
name: 'onError'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
export function assertGsocMessageHandler(value) {
|
|
111
|
+
const object = Types.asObject(value, {
|
|
112
|
+
name: 'GsocMessageHandler'
|
|
113
|
+
});
|
|
114
|
+
Types.asFunction(object.onMessage, {
|
|
115
|
+
name: 'onMessage'
|
|
116
|
+
});
|
|
117
|
+
Types.asFunction(object.onError, {
|
|
118
|
+
name: 'onError'
|
|
119
|
+
});
|
|
110
120
|
}
|
|
111
121
|
export function assertPostageBatchOptions(value) {
|
|
112
122
|
if (value === undefined) {
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { Chunk } from './chunk/cac';
|
|
4
|
-
import type { AllSettlements, BalanceResponse, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, DebugStatus, EnvelopeWithBatchId, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GlobalPostageBatch, GranteesResult, Health, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, Readiness, RedistributionState, ReferenceInformation, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Tag, Topology, TransactionInfo, UploadOptions, UploadRedundancyOptions, WalletBalance } from './types';
|
|
4
|
+
import type { AllSettlements, BalanceResponse, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, DebugStatus, EnvelopeWithBatchId, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GlobalPostageBatch, GranteesResult, GsocMessageHandler, GsocSubscription, Health, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, Readiness, RedistributionState, ReferenceInformation, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Tag, Topology, TransactionInfo, UploadOptions, UploadRedundancyOptions, WalletBalance } from './types';
|
|
5
5
|
import { AllTagsOptions, CashoutOptions, Collection, PostageBatchOptions, TransactionOptions, UploadResult } from './types';
|
|
6
6
|
import { Bytes } from './utils/bytes';
|
|
7
|
-
import {
|
|
7
|
+
import { BZZ } from './utils/tokens';
|
|
8
|
+
import { BatchId, EthAddress, FeedIndex, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Topic, TransactionId } from './utils/typed-bytes';
|
|
8
9
|
import { UploadProgress } from './utils/upload-progress';
|
|
9
10
|
/**
|
|
10
11
|
* The main component that abstracts operations available on the main Bee API.
|
|
@@ -130,9 +131,6 @@ export declare class Bee {
|
|
|
130
131
|
/**
|
|
131
132
|
* Upload single file to a Bee node.
|
|
132
133
|
*
|
|
133
|
-
* **To make sure that you won't lose critical data it is highly recommended to also
|
|
134
|
-
* locally pin the data with `options.pin = true`**
|
|
135
|
-
*
|
|
136
134
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
137
135
|
* @param data Data or file to be uploaded
|
|
138
136
|
* @param name Optional name of the uploaded file
|
|
@@ -419,6 +417,9 @@ export declare class Bee {
|
|
|
419
417
|
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
420
418
|
*/
|
|
421
419
|
pssReceive(topic: Topic, timeoutMsec?: number): Promise<Bytes>;
|
|
420
|
+
gsocMine(targetOverlay: PeerAddress | Uint8Array | string, identifier: Identifier | Uint8Array | string, proximity?: number): PrivateKey;
|
|
421
|
+
gsocSend(postageBatchId: BatchId | Uint8Array | string, signer: PrivateKey | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: string | Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
422
|
+
gsocSubscribe(address: EthAddress | Uint8Array | string, identifier: Identifier | Uint8Array | string, handler: GsocMessageHandler): GsocSubscription;
|
|
422
423
|
/**
|
|
423
424
|
* Create feed manifest chunk and return the reference to it.
|
|
424
425
|
*
|
|
@@ -734,7 +735,7 @@ export declare class Bee {
|
|
|
734
735
|
*
|
|
735
736
|
* @param options
|
|
736
737
|
*/
|
|
737
|
-
getStake(options?: BeeRequestOptions): Promise<
|
|
738
|
+
getStake(options?: BeeRequestOptions): Promise<BZZ>;
|
|
738
739
|
/**
|
|
739
740
|
* Deposits given amount of BZZ token (in PLUR unit).
|
|
740
741
|
*
|
|
@@ -32,7 +32,7 @@ export declare function makeSOCAddress(identifier: Identifier, address: EthAddre
|
|
|
32
32
|
* @param identifier The identifier of the chunk
|
|
33
33
|
* @param signer The signer interface for signing the chunk
|
|
34
34
|
*/
|
|
35
|
-
export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string):
|
|
35
|
+
export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
|
|
36
36
|
/**
|
|
37
37
|
* Helper function to upload a chunk.
|
|
38
38
|
*
|
package/dist/types/index.d.ts
CHANGED