@ethersphere/bee-js 6.9.1 → 7.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 +107 -65
- package/dist/cjs/bee.js +533 -6
- package/dist/cjs/chunk/cac.js +3 -3
- package/dist/cjs/chunk/soc.js +5 -5
- package/dist/cjs/chunk/span.js +2 -6
- package/dist/cjs/feed/identifier.js +2 -2
- package/dist/cjs/feed/index.js +5 -6
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/modules/bytes.js +3 -3
- package/dist/cjs/modules/bzz.js +9 -20
- package/dist/cjs/modules/chunk.js +2 -2
- package/dist/cjs/modules/debug/balance.js +4 -4
- package/dist/cjs/modules/debug/chequebook.js +8 -8
- package/dist/cjs/modules/debug/chunk.js +2 -19
- package/dist/cjs/modules/debug/settlements.js +2 -2
- package/dist/cjs/modules/debug/stake.js +3 -3
- package/dist/cjs/modules/debug/states.js +4 -19
- package/dist/cjs/modules/debug/status.js +15 -32
- package/dist/cjs/modules/debug/tag.js +1 -1
- package/dist/cjs/modules/debug/transactions.js +4 -4
- package/dist/cjs/modules/feed.js +6 -7
- package/dist/cjs/modules/pinning.js +4 -4
- package/dist/cjs/modules/pss.js +1 -1
- package/dist/cjs/modules/soc.js +1 -1
- package/dist/cjs/modules/status.js +1 -1
- package/dist/cjs/modules/stewardship.js +1 -1
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/utils/collection.js +7 -22
- package/dist/cjs/utils/collection.node.js +2 -1
- package/dist/cjs/utils/data.browser.js +1 -49
- package/dist/cjs/utils/error.js +2 -6
- package/dist/cjs/utils/eth.js +1 -1
- package/dist/cjs/utils/expose.js +1 -8
- package/dist/cjs/utils/file.js +2 -2
- package/dist/cjs/utils/http.js +6 -25
- package/dist/cjs/utils/tar-uploader.browser.js +26 -0
- package/dist/cjs/utils/tar-uploader.js +27 -0
- package/dist/cjs/utils/tar-writer.browser.js +17 -0
- package/dist/cjs/utils/tar-writer.js +21 -0
- package/dist/cjs/utils/tar.browser.js +65 -0
- package/dist/cjs/utils/tar.js +47 -21
- package/dist/cjs/utils/type.js +7 -3
- package/dist/cjs/utils/url.js +1 -6
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +0 -42
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +533 -9
- package/dist/mjs/chunk/cac.js +4 -4
- package/dist/mjs/chunk/soc.js +6 -6
- package/dist/mjs/chunk/span.js +2 -6
- package/dist/mjs/feed/identifier.js +2 -2
- package/dist/mjs/feed/index.js +5 -9
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +3 -3
- package/dist/mjs/modules/bzz.js +8 -20
- package/dist/mjs/modules/chunk.js +2 -2
- package/dist/mjs/modules/debug/balance.js +4 -4
- package/dist/mjs/modules/debug/chequebook.js +8 -8
- package/dist/mjs/modules/debug/chunk.js +1 -17
- package/dist/mjs/modules/debug/settlements.js +2 -2
- package/dist/mjs/modules/debug/stake.js +3 -3
- package/dist/mjs/modules/debug/states.js +4 -19
- package/dist/mjs/modules/debug/status.js +15 -34
- package/dist/mjs/modules/debug/tag.js +1 -1
- package/dist/mjs/modules/debug/transactions.js +4 -4
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/pinning.js +4 -4
- package/dist/mjs/modules/pss.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/status.js +1 -1
- package/dist/mjs/modules/stewardship.js +1 -1
- package/dist/mjs/package.json +6 -2
- package/dist/mjs/types/index.js +4 -0
- package/dist/mjs/utils/collection.js +7 -22
- package/dist/mjs/utils/collection.node.js +2 -1
- package/dist/mjs/utils/data.browser.js +0 -57
- package/dist/mjs/utils/error.js +2 -6
- package/dist/mjs/utils/eth.js +1 -1
- package/dist/mjs/utils/expose.js +0 -1
- package/dist/mjs/utils/http.js +5 -2
- package/dist/mjs/utils/tar-uploader.browser.js +22 -0
- package/dist/mjs/utils/tar-uploader.js +23 -0
- package/dist/mjs/utils/tar-writer.browser.js +12 -0
- package/dist/mjs/utils/tar-writer.js +16 -0
- package/dist/mjs/utils/tar.browser.js +61 -0
- package/dist/mjs/utils/tar.js +45 -16
- package/dist/mjs/utils/type.js +4 -1
- package/dist/mjs/utils/url.js +1 -6
- package/dist/types/bee.d.ts +305 -4
- package/dist/types/chunk/soc.d.ts +2 -2
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/modules/bytes.d.ts +3 -3
- package/dist/types/modules/bzz.d.ts +14 -6
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/balance.d.ts +4 -4
- package/dist/types/modules/debug/chequebook.d.ts +8 -8
- package/dist/types/modules/debug/chunk.d.ts +1 -10
- package/dist/types/modules/debug/settlements.d.ts +2 -2
- package/dist/types/modules/debug/stake.d.ts +3 -3
- package/dist/types/modules/debug/states.d.ts +3 -3
- package/dist/types/modules/debug/status.d.ts +10 -20
- package/dist/types/modules/debug/tag.d.ts +1 -1
- package/dist/types/modules/debug/transactions.d.ts +4 -4
- package/dist/types/modules/feed.d.ts +6 -9
- package/dist/types/modules/pinning.d.ts +4 -4
- package/dist/types/modules/pss.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/status.d.ts +1 -1
- package/dist/types/modules/stewardship.d.ts +1 -1
- package/dist/types/types/debug.d.ts +0 -3
- package/dist/types/types/index.d.ts +9 -17
- package/dist/types/utils/collection.browser.d.ts +1 -1
- package/dist/types/utils/collection.d.ts +3 -3
- package/dist/types/utils/collection.node.d.ts +1 -1
- package/dist/types/utils/data.browser.d.ts +0 -7
- package/dist/types/utils/data.d.ts +1 -2
- package/dist/types/utils/error.d.ts +2 -7
- package/dist/types/utils/eth.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +0 -1
- package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
- package/dist/types/utils/tar-uploader.d.ts +4 -0
- package/dist/types/utils/tar-writer.browser.d.ts +3 -0
- package/dist/types/utils/tar-writer.d.ts +3 -0
- package/dist/types/utils/tar.browser.d.ts +9 -0
- package/dist/types/utils/tar.d.ts +10 -2
- package/dist/types/utils/type.d.ts +4 -1
- package/package.json +4 -19
- package/dist/cjs/bee-debug.js +0 -590
- package/dist/cjs/chunk/serialize.js +0 -19
- package/dist/cjs/utils/stream.js +0 -146
- package/dist/cjs/utils/uint64.js +0 -29
- package/dist/mjs/bee-debug.js +0 -560
- package/dist/mjs/chunk/serialize.js +0 -15
- package/dist/mjs/utils/stream.js +0 -129
- package/dist/mjs/utils/uint64.js +0 -22
- package/dist/types/bee-debug.d.ts +0 -323
- package/dist/types/chunk/serialize.d.ts +0 -6
- package/dist/types/utils/stream.d.ts +0 -40
- package/dist/types/utils/uint64.d.ts +0 -4
package/dist/cjs/bee.js
CHANGED
|
@@ -36,6 +36,16 @@ const type_1 = require("./feed/type");
|
|
|
36
36
|
const bytes = __importStar(require("./modules/bytes"));
|
|
37
37
|
const bzz = __importStar(require("./modules/bzz"));
|
|
38
38
|
const chunk = __importStar(require("./modules/chunk"));
|
|
39
|
+
const balance = __importStar(require("./modules/debug/balance"));
|
|
40
|
+
const chequebook = __importStar(require("./modules/debug/chequebook"));
|
|
41
|
+
const connectivity = __importStar(require("./modules/debug/connectivity"));
|
|
42
|
+
const settlements = __importStar(require("./modules/debug/settlements"));
|
|
43
|
+
const stake = __importStar(require("./modules/debug/stake"));
|
|
44
|
+
const stamps = __importStar(require("./modules/debug/stamps"));
|
|
45
|
+
const states = __importStar(require("./modules/debug/states"));
|
|
46
|
+
const debugStatus = __importStar(require("./modules/debug/status"));
|
|
47
|
+
const debugTag = __importStar(require("./modules/debug/tag"));
|
|
48
|
+
const transactions = __importStar(require("./modules/debug/transactions"));
|
|
39
49
|
const feed_2 = require("./modules/feed");
|
|
40
50
|
const pinning = __importStar(require("./modules/pinning"));
|
|
41
51
|
const pss = __importStar(require("./modules/pss"));
|
|
@@ -50,7 +60,6 @@ const data_1 = require("./utils/data");
|
|
|
50
60
|
const error_1 = require("./utils/error");
|
|
51
61
|
const eth_1 = require("./utils/eth");
|
|
52
62
|
const file_1 = require("./utils/file");
|
|
53
|
-
const stream_1 = require("./utils/stream");
|
|
54
63
|
const type_2 = require("./utils/type");
|
|
55
64
|
const url_1 = require("./utils/url");
|
|
56
65
|
/**
|
|
@@ -78,7 +87,6 @@ class Bee {
|
|
|
78
87
|
timeout: options?.timeout ?? false,
|
|
79
88
|
headers: options?.headers,
|
|
80
89
|
onRequest: options?.onRequest,
|
|
81
|
-
adapter: options?.adapter,
|
|
82
90
|
};
|
|
83
91
|
}
|
|
84
92
|
/**
|
|
@@ -201,7 +209,7 @@ class Bee {
|
|
|
201
209
|
const fileOptions = { contentType, ...options };
|
|
202
210
|
return (0, type_2.addCidConversionFunction)(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions), swarm_cid_1.ReferenceType.MANIFEST);
|
|
203
211
|
}
|
|
204
|
-
else if ((0,
|
|
212
|
+
else if ((0, type_2.isReadable)(data) && options?.tag && !options.size) {
|
|
205
213
|
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
206
214
|
const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
207
215
|
await this.updateTag(options.tag, result.reference);
|
|
@@ -673,9 +681,7 @@ class Bee {
|
|
|
673
681
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
674
682
|
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
675
683
|
const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
|
|
676
|
-
const reference = await (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId
|
|
677
|
-
type,
|
|
678
|
-
});
|
|
684
|
+
const reference = await (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId);
|
|
679
685
|
return (0, type_2.addCidConversionFunction)({ reference }, swarm_cid_1.ReferenceType.FEED);
|
|
680
686
|
}
|
|
681
687
|
/**
|
|
@@ -851,6 +857,527 @@ class Bee {
|
|
|
851
857
|
}
|
|
852
858
|
return true;
|
|
853
859
|
}
|
|
860
|
+
// Legacy debug API
|
|
861
|
+
async getNodeAddresses(options) {
|
|
862
|
+
(0, type_2.assertRequestOptions)(options);
|
|
863
|
+
return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
|
|
864
|
+
}
|
|
865
|
+
async getBlocklist(options) {
|
|
866
|
+
(0, type_2.assertRequestOptions)(options);
|
|
867
|
+
return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Retrieve tag extended information from Bee node
|
|
871
|
+
*
|
|
872
|
+
* @param tagUid UID or tag object to be retrieved
|
|
873
|
+
* @throws TypeError if tagUid is in not correct format
|
|
874
|
+
*
|
|
875
|
+
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
876
|
+
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
|
|
877
|
+
*
|
|
878
|
+
*/
|
|
879
|
+
async retrieveExtendedTag(tagUid, options) {
|
|
880
|
+
(0, type_2.assertRequestOptions)(options);
|
|
881
|
+
if ((0, type_2.isTag)(tagUid)) {
|
|
882
|
+
tagUid = tagUid.uid;
|
|
883
|
+
}
|
|
884
|
+
else if (typeof tagUid === 'number') {
|
|
885
|
+
(0, type_2.assertNonNegativeInteger)(tagUid, 'UID');
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
889
|
+
}
|
|
890
|
+
return debugTag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Get list of peers for this node
|
|
894
|
+
*/
|
|
895
|
+
async getPeers(options) {
|
|
896
|
+
(0, type_2.assertRequestOptions)(options);
|
|
897
|
+
return connectivity.getPeers(this.getRequestOptionsForCall(options));
|
|
898
|
+
}
|
|
899
|
+
async removePeer(peer, options) {
|
|
900
|
+
(0, type_2.assertRequestOptions)(options);
|
|
901
|
+
(0, type_2.assertAddress)(peer);
|
|
902
|
+
return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
|
|
903
|
+
}
|
|
904
|
+
async getTopology(options) {
|
|
905
|
+
(0, type_2.assertRequestOptions)(options);
|
|
906
|
+
return connectivity.getTopology(this.getRequestOptionsForCall(options));
|
|
907
|
+
}
|
|
908
|
+
async pingPeer(peer, options) {
|
|
909
|
+
(0, type_2.assertRequestOptions)(options);
|
|
910
|
+
(0, type_2.assertAddress)(peer);
|
|
911
|
+
return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
|
|
912
|
+
}
|
|
913
|
+
/*
|
|
914
|
+
* Balance endpoints
|
|
915
|
+
*/
|
|
916
|
+
/**
|
|
917
|
+
* Get the balances with all known peers including prepaid services
|
|
918
|
+
*/
|
|
919
|
+
async getAllBalances(options) {
|
|
920
|
+
(0, type_2.assertRequestOptions)(options);
|
|
921
|
+
return balance.getAllBalances(this.getRequestOptionsForCall(options));
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Get the balances with a specific peer including prepaid services
|
|
925
|
+
*
|
|
926
|
+
* @param address Swarm address of peer
|
|
927
|
+
*/
|
|
928
|
+
async getPeerBalance(address, options) {
|
|
929
|
+
(0, type_2.assertRequestOptions)(options);
|
|
930
|
+
(0, type_2.assertAddress)(address);
|
|
931
|
+
return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Get the past due consumption balances with all known peers
|
|
935
|
+
*/
|
|
936
|
+
async getPastDueConsumptionBalances(options) {
|
|
937
|
+
(0, type_2.assertRequestOptions)(options);
|
|
938
|
+
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get the past due consumption balance with a specific peer
|
|
942
|
+
*
|
|
943
|
+
* @param address Swarm address of peer
|
|
944
|
+
*/
|
|
945
|
+
async getPastDueConsumptionPeerBalance(address, options) {
|
|
946
|
+
(0, type_2.assertRequestOptions)(options);
|
|
947
|
+
(0, type_2.assertAddress)(address);
|
|
948
|
+
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
949
|
+
}
|
|
950
|
+
/*
|
|
951
|
+
* Chequebook endpoints
|
|
952
|
+
*/
|
|
953
|
+
/**
|
|
954
|
+
* Get the address of the chequebook contract used.
|
|
955
|
+
*
|
|
956
|
+
* **Warning:** The address is returned with 0x prefix unlike all other calls.
|
|
957
|
+
* https://github.com/ethersphere/bee/issues/1443
|
|
958
|
+
*/
|
|
959
|
+
async getChequebookAddress(options) {
|
|
960
|
+
(0, type_2.assertRequestOptions)(options);
|
|
961
|
+
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Get the balance of the chequebook
|
|
965
|
+
*/
|
|
966
|
+
async getChequebookBalance(options) {
|
|
967
|
+
(0, type_2.assertRequestOptions)(options);
|
|
968
|
+
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Get last cheques for all peers
|
|
972
|
+
*/
|
|
973
|
+
async getLastCheques(options) {
|
|
974
|
+
(0, type_2.assertRequestOptions)(options);
|
|
975
|
+
return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Get last cheques for the peer
|
|
979
|
+
*
|
|
980
|
+
* @param address Swarm address of peer
|
|
981
|
+
*/
|
|
982
|
+
async getLastChequesForPeer(address, options) {
|
|
983
|
+
(0, type_2.assertRequestOptions)(options);
|
|
984
|
+
(0, type_2.assertAddress)(address);
|
|
985
|
+
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Get last cashout action for the peer
|
|
989
|
+
*
|
|
990
|
+
* @param address Swarm address of peer
|
|
991
|
+
*/
|
|
992
|
+
async getLastCashoutAction(address, options) {
|
|
993
|
+
(0, type_2.assertRequestOptions)(options);
|
|
994
|
+
(0, type_2.assertAddress)(address);
|
|
995
|
+
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Cashout the last cheque for the peer
|
|
999
|
+
*
|
|
1000
|
+
* @param address Swarm address of peer
|
|
1001
|
+
* @param options
|
|
1002
|
+
* @param options.gasPrice Gas price for the cashout transaction in WEI
|
|
1003
|
+
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
1004
|
+
*/
|
|
1005
|
+
async cashoutLastCheque(address, options, requestOptions) {
|
|
1006
|
+
(0, type_2.assertCashoutOptions)(options);
|
|
1007
|
+
(0, type_2.assertAddress)(address);
|
|
1008
|
+
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Deposit tokens from overlay address into chequebook
|
|
1012
|
+
*
|
|
1013
|
+
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
1014
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1015
|
+
* @return string Hash of the transaction
|
|
1016
|
+
*/
|
|
1017
|
+
async depositTokens(amount, gasPrice, options) {
|
|
1018
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1019
|
+
(0, type_2.assertNonNegativeInteger)(amount);
|
|
1020
|
+
if (gasPrice) {
|
|
1021
|
+
(0, type_2.assertNonNegativeInteger)(gasPrice);
|
|
1022
|
+
}
|
|
1023
|
+
return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Withdraw tokens from the chequebook to the overlay address
|
|
1027
|
+
*
|
|
1028
|
+
* @param amount Amount of tokens to withdraw (must be positive integer)
|
|
1029
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1030
|
+
* @return string Hash of the transaction
|
|
1031
|
+
*/
|
|
1032
|
+
async withdrawTokens(amount, gasPrice, options) {
|
|
1033
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1034
|
+
(0, type_2.assertNonNegativeInteger)(amount);
|
|
1035
|
+
if (gasPrice) {
|
|
1036
|
+
(0, type_2.assertNonNegativeInteger)(gasPrice);
|
|
1037
|
+
}
|
|
1038
|
+
return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
|
|
1039
|
+
}
|
|
1040
|
+
/*
|
|
1041
|
+
* Settlements endpoint
|
|
1042
|
+
*/
|
|
1043
|
+
/**
|
|
1044
|
+
* Get amount of sent and received from settlements with a peer
|
|
1045
|
+
*
|
|
1046
|
+
* @param address Swarm address of peer
|
|
1047
|
+
*/
|
|
1048
|
+
async getSettlements(address, options) {
|
|
1049
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1050
|
+
(0, type_2.assertAddress)(address);
|
|
1051
|
+
return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Get settlements with all known peers and total amount sent or received
|
|
1055
|
+
*/
|
|
1056
|
+
async getAllSettlements(options) {
|
|
1057
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1058
|
+
return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Get status of node
|
|
1062
|
+
*/
|
|
1063
|
+
async getStatus(options) {
|
|
1064
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1065
|
+
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(options));
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Get health of node
|
|
1069
|
+
*/
|
|
1070
|
+
async getHealth(options) {
|
|
1071
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1072
|
+
return debugStatus.getHealth(this.getRequestOptionsForCall(options));
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Get readiness of node
|
|
1076
|
+
*/
|
|
1077
|
+
async getReadiness(options) {
|
|
1078
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1079
|
+
return debugStatus.getReadiness(this.getRequestOptionsForCall(options));
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Get mode information of node
|
|
1083
|
+
*/
|
|
1084
|
+
async getNodeInfo(options) {
|
|
1085
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1086
|
+
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(options));
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
1090
|
+
*
|
|
1091
|
+
* @returns true if the Bee node version is supported
|
|
1092
|
+
* @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
|
|
1093
|
+
*/
|
|
1094
|
+
async isSupportedVersion(options) {
|
|
1095
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1096
|
+
return debugStatus.isSupportedVersion(this.getRequestOptionsForCall(options));
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
1100
|
+
*
|
|
1101
|
+
* Be aware that this is the most strict version check and most probably
|
|
1102
|
+
* you will want to use more relaxed API-versions based checks like
|
|
1103
|
+
* `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
|
|
1104
|
+
* based on your use-case.
|
|
1105
|
+
*
|
|
1106
|
+
* @param options
|
|
1107
|
+
*/
|
|
1108
|
+
async isSupportedExactVersion(options) {
|
|
1109
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1110
|
+
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(options));
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
1114
|
+
*
|
|
1115
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
1116
|
+
* and want to make sure about compatibility.
|
|
1117
|
+
*
|
|
1118
|
+
* @param options
|
|
1119
|
+
*/
|
|
1120
|
+
async isSupportedMainApiVersion(options) {
|
|
1121
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1122
|
+
return debugStatus.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
*
|
|
1126
|
+
* Connects to a node and checks if its Main API version matches with the one that bee-js supports.
|
|
1127
|
+
*
|
|
1128
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
1129
|
+
*
|
|
1130
|
+
* @param options
|
|
1131
|
+
*/
|
|
1132
|
+
async isSupportedApiVersion(options) {
|
|
1133
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1134
|
+
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(options));
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
1138
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
1139
|
+
*
|
|
1140
|
+
* @param options
|
|
1141
|
+
*/
|
|
1142
|
+
async getVersions(options) {
|
|
1143
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1144
|
+
return debugStatus.getVersions(this.getRequestOptionsForCall(options));
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Get reserve state
|
|
1148
|
+
*/
|
|
1149
|
+
async getReserveState(options) {
|
|
1150
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1151
|
+
return states.getReserveState(this.getRequestOptionsForCall(options));
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Get chain state
|
|
1155
|
+
*/
|
|
1156
|
+
async getChainState(options) {
|
|
1157
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1158
|
+
return states.getChainState(this.getRequestOptionsForCall(options));
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Get wallet balances for xDai and BZZ of the Bee node
|
|
1162
|
+
*
|
|
1163
|
+
* @param options
|
|
1164
|
+
*/
|
|
1165
|
+
async getWalletBalance(options) {
|
|
1166
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1167
|
+
return states.getWalletBalance(this.getRequestOptionsForCall(options));
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Creates new postage batch from the funds that the node has available in its Ethereum account.
|
|
1171
|
+
*
|
|
1172
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1173
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1174
|
+
*
|
|
1175
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1176
|
+
*
|
|
1177
|
+
* @param amount Amount that represents the value per chunk, has to be greater or equal zero.
|
|
1178
|
+
* @param depth Logarithm of the number of chunks that can be stamped with the batch.
|
|
1179
|
+
* @param options Options for creation of postage batch
|
|
1180
|
+
* @throws BeeArgumentError when negative amount or depth is specified
|
|
1181
|
+
* @throws TypeError if non-integer value is passed to amount or depth
|
|
1182
|
+
*
|
|
1183
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1184
|
+
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
1185
|
+
*/
|
|
1186
|
+
async createPostageBatch(amount, depth, options, requestOptions) {
|
|
1187
|
+
(0, type_2.assertPostageBatchOptions)(options);
|
|
1188
|
+
(0, type_2.assertPositiveInteger)(amount);
|
|
1189
|
+
(0, type_2.assertNonNegativeInteger)(depth);
|
|
1190
|
+
if (depth < types_1.STAMPS_DEPTH_MIN) {
|
|
1191
|
+
throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
|
|
1192
|
+
}
|
|
1193
|
+
if (depth > types_1.STAMPS_DEPTH_MAX) {
|
|
1194
|
+
throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
|
|
1195
|
+
}
|
|
1196
|
+
if (parseInt(amount, 10) < types_1.STAMPS_AMOUNT_MIN) {
|
|
1197
|
+
throw new error_1.BeeArgumentError(`Amount has to be at least ${types_1.STAMPS_AMOUNT_MIN} (1 day)`, amount);
|
|
1198
|
+
}
|
|
1199
|
+
const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
|
|
1200
|
+
if (options?.waitForUsable !== false) {
|
|
1201
|
+
await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
|
|
1202
|
+
}
|
|
1203
|
+
return stamp;
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Topup a fresh amount of BZZ to given Postage Batch.
|
|
1207
|
+
*
|
|
1208
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1209
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1210
|
+
*
|
|
1211
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1212
|
+
*
|
|
1213
|
+
* @param postageBatchId Batch ID
|
|
1214
|
+
* @param amount Amount to be added to the batch
|
|
1215
|
+
* @param options Request options
|
|
1216
|
+
*
|
|
1217
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1218
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
|
|
1219
|
+
*/
|
|
1220
|
+
async topUpBatch(postageBatchId, amount, options) {
|
|
1221
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1222
|
+
(0, type_2.assertNonNegativeInteger)(amount, 'Amount');
|
|
1223
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
1224
|
+
await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
|
|
1228
|
+
* the Postage Batch to be used for more chunks.
|
|
1229
|
+
*
|
|
1230
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1231
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1232
|
+
*
|
|
1233
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1234
|
+
*
|
|
1235
|
+
* @param postageBatchId Batch ID
|
|
1236
|
+
* @param depth Amount to be added to the batch
|
|
1237
|
+
* @param options Request options
|
|
1238
|
+
*
|
|
1239
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1240
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
|
|
1241
|
+
*/
|
|
1242
|
+
async diluteBatch(postageBatchId, depth, options) {
|
|
1243
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1244
|
+
(0, type_2.assertNonNegativeInteger)(depth, 'Depth');
|
|
1245
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
1246
|
+
await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Return details for specific postage batch.
|
|
1250
|
+
*
|
|
1251
|
+
* @param postageBatchId Batch ID
|
|
1252
|
+
*
|
|
1253
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1254
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
|
|
1255
|
+
*/
|
|
1256
|
+
async getPostageBatch(postageBatchId, options) {
|
|
1257
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1258
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
1259
|
+
return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Return detailed information related to buckets for specific postage batch.
|
|
1263
|
+
*
|
|
1264
|
+
* @param postageBatchId Batch ID
|
|
1265
|
+
*
|
|
1266
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1267
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
|
|
1268
|
+
*/
|
|
1269
|
+
async getPostageBatchBuckets(postageBatchId, options) {
|
|
1270
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1271
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
1272
|
+
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Return all postage batches that has the node available.
|
|
1276
|
+
*
|
|
1277
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1278
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1279
|
+
*/
|
|
1280
|
+
async getAllPostageBatch(options) {
|
|
1281
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1282
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Return all globally available postage batches.
|
|
1286
|
+
*/
|
|
1287
|
+
async getAllGlobalPostageBatch(options) {
|
|
1288
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1289
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Return lists of all current pending transactions that the Bee made
|
|
1293
|
+
*/
|
|
1294
|
+
async getAllPendingTransactions(options) {
|
|
1295
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1296
|
+
return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Return transaction information for specific transaction
|
|
1300
|
+
* @param transactionHash
|
|
1301
|
+
*/
|
|
1302
|
+
async getPendingTransaction(transactionHash, options) {
|
|
1303
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1304
|
+
(0, type_2.assertTransactionHash)(transactionHash);
|
|
1305
|
+
return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Rebroadcast already created transaction.
|
|
1309
|
+
* This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
|
|
1310
|
+
*
|
|
1311
|
+
* @param transactionHash
|
|
1312
|
+
*/
|
|
1313
|
+
async rebroadcastPendingTransaction(transactionHash, options) {
|
|
1314
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1315
|
+
(0, type_2.assertTransactionHash)(transactionHash);
|
|
1316
|
+
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Cancel currently pending transaction
|
|
1320
|
+
* @param transactionHash
|
|
1321
|
+
* @param gasPrice
|
|
1322
|
+
*/
|
|
1323
|
+
async cancelPendingTransaction(transactionHash, gasPrice, options) {
|
|
1324
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1325
|
+
(0, type_2.assertTransactionHash)(transactionHash);
|
|
1326
|
+
if (gasPrice) {
|
|
1327
|
+
(0, type_2.assertNonNegativeInteger)(gasPrice);
|
|
1328
|
+
}
|
|
1329
|
+
return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Gets the staked amount of BZZ (in PLUR unit) as number string.
|
|
1333
|
+
*
|
|
1334
|
+
* @param options
|
|
1335
|
+
*/
|
|
1336
|
+
async getStake(options) {
|
|
1337
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1338
|
+
return stake.getStake(this.getRequestOptionsForCall(options));
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Deposits given amount of BZZ token (in PLUR unit).
|
|
1342
|
+
*
|
|
1343
|
+
* Be aware that staked BZZ tokens can **not** be withdrawn.
|
|
1344
|
+
*
|
|
1345
|
+
* @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
|
|
1346
|
+
* @param options
|
|
1347
|
+
*/
|
|
1348
|
+
async depositStake(amount, options, requestOptions) {
|
|
1349
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1350
|
+
(0, type_2.assertTransactionOptions)(options);
|
|
1351
|
+
await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Get current status of node in redistribution game
|
|
1355
|
+
*
|
|
1356
|
+
* @param options
|
|
1357
|
+
*/
|
|
1358
|
+
async getRedistributionState(options) {
|
|
1359
|
+
(0, type_2.assertRequestOptions)(options);
|
|
1360
|
+
return stake.getRedistributionState(this.getRequestOptionsForCall(options));
|
|
1361
|
+
}
|
|
1362
|
+
async waitForUsablePostageStamp(id, timeout = 240000) {
|
|
1363
|
+
const TIME_STEP = 2000;
|
|
1364
|
+
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
1365
|
+
try {
|
|
1366
|
+
const stamp = await this.getPostageBatch(id);
|
|
1367
|
+
if (stamp.usable) {
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
catch (error) {
|
|
1372
|
+
const message = error?.response?.data?.message || error?.message || '';
|
|
1373
|
+
if (!message.includes('batch not usable')) {
|
|
1374
|
+
throw error;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
await cafe_utility_1.System.sleepMillis(TIME_STEP);
|
|
1378
|
+
}
|
|
1379
|
+
throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
|
|
1380
|
+
}
|
|
854
1381
|
/**
|
|
855
1382
|
* @param signer
|
|
856
1383
|
* @private
|
package/dist/cjs/chunk/cac.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertValidChunkData = exports.isValidChunkData = exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const bytes_1 = require("../utils/bytes");
|
|
4
6
|
const error_1 = require("../utils/error");
|
|
5
7
|
const bmt_1 = require("./bmt");
|
|
6
|
-
const bytes_1 = require("../utils/bytes");
|
|
7
|
-
const serialize_1 = require("./serialize");
|
|
8
8
|
const span_1 = require("./span");
|
|
9
9
|
exports.MIN_PAYLOAD_SIZE = 1;
|
|
10
10
|
exports.MAX_PAYLOAD_SIZE = 4096;
|
|
@@ -18,7 +18,7 @@ const CAC_PAYLOAD_OFFSET = CAC_SPAN_OFFSET + span_1.SPAN_SIZE;
|
|
|
18
18
|
function makeContentAddressedChunk(payloadBytes) {
|
|
19
19
|
const span = (0, span_1.makeSpan)(payloadBytes.length);
|
|
20
20
|
(0, bytes_1.assertFlexBytes)(payloadBytes, exports.MIN_PAYLOAD_SIZE, exports.MAX_PAYLOAD_SIZE);
|
|
21
|
-
const data =
|
|
21
|
+
const data = cafe_utility_1.Binary.concatBytes(span, payloadBytes);
|
|
22
22
|
return {
|
|
23
23
|
data,
|
|
24
24
|
span: () => span,
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
|
|
27
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
27
28
|
const chunkAPI = __importStar(require("../modules/chunk"));
|
|
28
29
|
const socAPI = __importStar(require("../modules/soc"));
|
|
29
30
|
const bytes_1 = require("../utils/bytes");
|
|
@@ -33,7 +34,6 @@ const hex_1 = require("../utils/hex");
|
|
|
33
34
|
const type_1 = require("../utils/type");
|
|
34
35
|
const bmt_1 = require("./bmt");
|
|
35
36
|
const cac_1 = require("./cac");
|
|
36
|
-
const serialize_1 = require("./serialize");
|
|
37
37
|
const signer_1 = require("./signer");
|
|
38
38
|
const span_1 = require("./span");
|
|
39
39
|
const IDENTIFIER_SIZE = 32;
|
|
@@ -96,7 +96,7 @@ async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
|
96
96
|
(0, cac_1.assertValidChunkData)(chunk.data, chunkAddress);
|
|
97
97
|
const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
|
|
98
98
|
const signature = await (0, signer_1.sign)(signer, digest);
|
|
99
|
-
const data =
|
|
99
|
+
const data = cafe_utility_1.Binary.concatBytes(identifier, signature, chunk.span(), chunk.payload());
|
|
100
100
|
const address = makeSOCAddress(identifier, signer.address);
|
|
101
101
|
return {
|
|
102
102
|
data,
|
|
@@ -114,7 +114,7 @@ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
|
|
|
114
114
|
*
|
|
115
115
|
* It uses the Chunk API and calculates the address before uploading.
|
|
116
116
|
*
|
|
117
|
-
* @param
|
|
117
|
+
* @param requestOptions Options for making requests
|
|
118
118
|
* @param chunk A chunk object
|
|
119
119
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
120
120
|
* @param options Upload options
|
|
@@ -123,14 +123,14 @@ async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatchId, opt
|
|
|
123
123
|
const owner = (0, hex_1.bytesToHex)(chunk.owner());
|
|
124
124
|
const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
|
|
125
125
|
const signature = (0, hex_1.bytesToHex)(chunk.signature());
|
|
126
|
-
const data =
|
|
126
|
+
const data = cafe_utility_1.Binary.concatBytes(chunk.span(), chunk.payload());
|
|
127
127
|
return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
|
|
128
128
|
}
|
|
129
129
|
exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
|
|
130
130
|
/**
|
|
131
131
|
* Helper function to create and upload SOC.
|
|
132
132
|
*
|
|
133
|
-
* @param
|
|
133
|
+
* @param requestOptions Options for making requests
|
|
134
134
|
* @param signer The singer interface for signing the chunk
|
|
135
135
|
* @param postageBatchId
|
|
136
136
|
* @param identifier The identifier of the chunk
|
package/dist/cjs/chunk/span.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeSpan = exports.SPAN_SIZE = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
4
5
|
const error_1 = require("../utils/error");
|
|
5
6
|
exports.SPAN_SIZE = 8;
|
|
6
7
|
// we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
|
|
@@ -19,11 +20,6 @@ function makeSpan(length) {
|
|
|
19
20
|
if (length > MAX_SPAN_LENGTH) {
|
|
20
21
|
throw new error_1.BeeArgumentError('invalid length (> MAX_SPAN_LENGTH)', length);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
const dataView = new DataView(span.buffer);
|
|
24
|
-
const littleEndian = true;
|
|
25
|
-
const lengthLower32 = length & 0xffffffff;
|
|
26
|
-
dataView.setUint32(0, lengthLower32, littleEndian);
|
|
27
|
-
return span;
|
|
23
|
+
return cafe_utility_1.Binary.numberToUint64LE(length);
|
|
28
24
|
}
|
|
29
25
|
exports.makeSpan = makeSpan;
|