@ethersphere/bee-js 6.9.0 → 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 +7 -8
- 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 +7 -11
- 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/feed/index.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/mjs/bee.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReferenceType } from '@ethersphere/swarm-cid';
|
|
2
|
-
import { Objects } from 'cafe-utility';
|
|
2
|
+
import { Objects, System } from 'cafe-utility';
|
|
3
3
|
import { makeSigner } from "./chunk/signer.js";
|
|
4
4
|
import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
|
|
5
5
|
import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
|
|
@@ -10,13 +10,23 @@ import { DEFAULT_FEED_TYPE, assertFeedType } from "./feed/type.js";
|
|
|
10
10
|
import * as bytes from "./modules/bytes.js";
|
|
11
11
|
import * as bzz from "./modules/bzz.js";
|
|
12
12
|
import * as chunk from "./modules/chunk.js";
|
|
13
|
+
import * as balance from "./modules/debug/balance.js";
|
|
14
|
+
import * as chequebook from "./modules/debug/chequebook.js";
|
|
15
|
+
import * as connectivity from "./modules/debug/connectivity.js";
|
|
16
|
+
import * as settlements from "./modules/debug/settlements.js";
|
|
17
|
+
import * as stake from "./modules/debug/stake.js";
|
|
18
|
+
import * as stamps from "./modules/debug/stamps.js";
|
|
19
|
+
import * as states from "./modules/debug/states.js";
|
|
20
|
+
import * as debugStatus from "./modules/debug/status.js";
|
|
21
|
+
import * as debugTag from "./modules/debug/tag.js";
|
|
22
|
+
import * as transactions from "./modules/debug/transactions.js";
|
|
13
23
|
import { createFeedManifest } from "./modules/feed.js";
|
|
14
24
|
import * as pinning from "./modules/pinning.js";
|
|
15
25
|
import * as pss from "./modules/pss.js";
|
|
16
26
|
import * as status from "./modules/status.js";
|
|
17
27
|
import * as stewardship from "./modules/stewardship.js";
|
|
18
28
|
import * as tag from "./modules/tag.js";
|
|
19
|
-
import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
|
|
29
|
+
import { CHUNK_SIZE, SPAN_SIZE, STAMPS_AMOUNT_MIN, STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
|
|
20
30
|
import { wrapBytesWithHelpers } from "./utils/bytes.js";
|
|
21
31
|
import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
|
|
22
32
|
import { makeCollectionFromFS } from "./utils/collection.node.js";
|
|
@@ -24,8 +34,7 @@ import { prepareWebsocketData } from "./utils/data.js";
|
|
|
24
34
|
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
25
35
|
import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
|
|
26
36
|
import { fileArrayBuffer, isFile } from "./utils/file.js";
|
|
27
|
-
import { isReadable } from "./utils/
|
|
28
|
-
import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
|
|
37
|
+
import { addCidConversionFunction, assertAddress, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCashoutOptions, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertTransactionHash, assertTransactionOptions, assertUploadOptions, isReadable, isTag, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
|
|
29
38
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
30
39
|
/**
|
|
31
40
|
* The main component that abstracts operations available on the main Bee API.
|
|
@@ -51,8 +60,7 @@ export class Bee {
|
|
|
51
60
|
baseURL: this.url,
|
|
52
61
|
timeout: options?.timeout ?? false,
|
|
53
62
|
headers: options?.headers,
|
|
54
|
-
onRequest: options?.onRequest
|
|
55
|
-
adapter: options?.adapter
|
|
63
|
+
onRequest: options?.onRequest
|
|
56
64
|
};
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
@@ -638,9 +646,7 @@ export class Bee {
|
|
|
638
646
|
assertBatchId(postageBatchId);
|
|
639
647
|
const canonicalTopic = makeTopic(topic);
|
|
640
648
|
const canonicalOwner = makeHexEthAddress(owner);
|
|
641
|
-
const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId
|
|
642
|
-
type
|
|
643
|
-
});
|
|
649
|
+
const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId);
|
|
644
650
|
return addCidConversionFunction({
|
|
645
651
|
reference
|
|
646
652
|
}, ReferenceType.FEED);
|
|
@@ -814,6 +820,524 @@ export class Bee {
|
|
|
814
820
|
}
|
|
815
821
|
return true;
|
|
816
822
|
}
|
|
823
|
+
// Legacy debug API
|
|
824
|
+
async getNodeAddresses(options) {
|
|
825
|
+
assertRequestOptions(options);
|
|
826
|
+
return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
|
|
827
|
+
}
|
|
828
|
+
async getBlocklist(options) {
|
|
829
|
+
assertRequestOptions(options);
|
|
830
|
+
return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Retrieve tag extended information from Bee node
|
|
834
|
+
*
|
|
835
|
+
* @param tagUid UID or tag object to be retrieved
|
|
836
|
+
* @throws TypeError if tagUid is in not correct format
|
|
837
|
+
*
|
|
838
|
+
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
839
|
+
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
|
|
840
|
+
*
|
|
841
|
+
*/
|
|
842
|
+
async retrieveExtendedTag(tagUid, options) {
|
|
843
|
+
assertRequestOptions(options);
|
|
844
|
+
if (isTag(tagUid)) {
|
|
845
|
+
tagUid = tagUid.uid;
|
|
846
|
+
} else if (typeof tagUid === 'number') {
|
|
847
|
+
assertNonNegativeInteger(tagUid, 'UID');
|
|
848
|
+
} else {
|
|
849
|
+
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
850
|
+
}
|
|
851
|
+
return debugTag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Get list of peers for this node
|
|
855
|
+
*/
|
|
856
|
+
async getPeers(options) {
|
|
857
|
+
assertRequestOptions(options);
|
|
858
|
+
return connectivity.getPeers(this.getRequestOptionsForCall(options));
|
|
859
|
+
}
|
|
860
|
+
async removePeer(peer, options) {
|
|
861
|
+
assertRequestOptions(options);
|
|
862
|
+
assertAddress(peer);
|
|
863
|
+
return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
|
|
864
|
+
}
|
|
865
|
+
async getTopology(options) {
|
|
866
|
+
assertRequestOptions(options);
|
|
867
|
+
return connectivity.getTopology(this.getRequestOptionsForCall(options));
|
|
868
|
+
}
|
|
869
|
+
async pingPeer(peer, options) {
|
|
870
|
+
assertRequestOptions(options);
|
|
871
|
+
assertAddress(peer);
|
|
872
|
+
return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
|
|
873
|
+
}
|
|
874
|
+
/*
|
|
875
|
+
* Balance endpoints
|
|
876
|
+
*/
|
|
877
|
+
/**
|
|
878
|
+
* Get the balances with all known peers including prepaid services
|
|
879
|
+
*/
|
|
880
|
+
async getAllBalances(options) {
|
|
881
|
+
assertRequestOptions(options);
|
|
882
|
+
return balance.getAllBalances(this.getRequestOptionsForCall(options));
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Get the balances with a specific peer including prepaid services
|
|
886
|
+
*
|
|
887
|
+
* @param address Swarm address of peer
|
|
888
|
+
*/
|
|
889
|
+
async getPeerBalance(address, options) {
|
|
890
|
+
assertRequestOptions(options);
|
|
891
|
+
assertAddress(address);
|
|
892
|
+
return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Get the past due consumption balances with all known peers
|
|
896
|
+
*/
|
|
897
|
+
async getPastDueConsumptionBalances(options) {
|
|
898
|
+
assertRequestOptions(options);
|
|
899
|
+
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Get the past due consumption balance with a specific peer
|
|
903
|
+
*
|
|
904
|
+
* @param address Swarm address of peer
|
|
905
|
+
*/
|
|
906
|
+
async getPastDueConsumptionPeerBalance(address, options) {
|
|
907
|
+
assertRequestOptions(options);
|
|
908
|
+
assertAddress(address);
|
|
909
|
+
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
910
|
+
}
|
|
911
|
+
/*
|
|
912
|
+
* Chequebook endpoints
|
|
913
|
+
*/
|
|
914
|
+
/**
|
|
915
|
+
* Get the address of the chequebook contract used.
|
|
916
|
+
*
|
|
917
|
+
* **Warning:** The address is returned with 0x prefix unlike all other calls.
|
|
918
|
+
* https://github.com/ethersphere/bee/issues/1443
|
|
919
|
+
*/
|
|
920
|
+
async getChequebookAddress(options) {
|
|
921
|
+
assertRequestOptions(options);
|
|
922
|
+
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Get the balance of the chequebook
|
|
926
|
+
*/
|
|
927
|
+
async getChequebookBalance(options) {
|
|
928
|
+
assertRequestOptions(options);
|
|
929
|
+
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Get last cheques for all peers
|
|
933
|
+
*/
|
|
934
|
+
async getLastCheques(options) {
|
|
935
|
+
assertRequestOptions(options);
|
|
936
|
+
return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Get last cheques for the peer
|
|
940
|
+
*
|
|
941
|
+
* @param address Swarm address of peer
|
|
942
|
+
*/
|
|
943
|
+
async getLastChequesForPeer(address, options) {
|
|
944
|
+
assertRequestOptions(options);
|
|
945
|
+
assertAddress(address);
|
|
946
|
+
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Get last cashout action for the peer
|
|
950
|
+
*
|
|
951
|
+
* @param address Swarm address of peer
|
|
952
|
+
*/
|
|
953
|
+
async getLastCashoutAction(address, options) {
|
|
954
|
+
assertRequestOptions(options);
|
|
955
|
+
assertAddress(address);
|
|
956
|
+
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Cashout the last cheque for the peer
|
|
960
|
+
*
|
|
961
|
+
* @param address Swarm address of peer
|
|
962
|
+
* @param options
|
|
963
|
+
* @param options.gasPrice Gas price for the cashout transaction in WEI
|
|
964
|
+
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
965
|
+
*/
|
|
966
|
+
async cashoutLastCheque(address, options, requestOptions) {
|
|
967
|
+
assertCashoutOptions(options);
|
|
968
|
+
assertAddress(address);
|
|
969
|
+
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Deposit tokens from overlay address into chequebook
|
|
973
|
+
*
|
|
974
|
+
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
975
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
976
|
+
* @return string Hash of the transaction
|
|
977
|
+
*/
|
|
978
|
+
async depositTokens(amount, gasPrice, options) {
|
|
979
|
+
assertRequestOptions(options);
|
|
980
|
+
assertNonNegativeInteger(amount);
|
|
981
|
+
if (gasPrice) {
|
|
982
|
+
assertNonNegativeInteger(gasPrice);
|
|
983
|
+
}
|
|
984
|
+
return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Withdraw tokens from the chequebook to the overlay address
|
|
988
|
+
*
|
|
989
|
+
* @param amount Amount of tokens to withdraw (must be positive integer)
|
|
990
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
991
|
+
* @return string Hash of the transaction
|
|
992
|
+
*/
|
|
993
|
+
async withdrawTokens(amount, gasPrice, options) {
|
|
994
|
+
assertRequestOptions(options);
|
|
995
|
+
assertNonNegativeInteger(amount);
|
|
996
|
+
if (gasPrice) {
|
|
997
|
+
assertNonNegativeInteger(gasPrice);
|
|
998
|
+
}
|
|
999
|
+
return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
|
|
1000
|
+
}
|
|
1001
|
+
/*
|
|
1002
|
+
* Settlements endpoint
|
|
1003
|
+
*/
|
|
1004
|
+
/**
|
|
1005
|
+
* Get amount of sent and received from settlements with a peer
|
|
1006
|
+
*
|
|
1007
|
+
* @param address Swarm address of peer
|
|
1008
|
+
*/
|
|
1009
|
+
async getSettlements(address, options) {
|
|
1010
|
+
assertRequestOptions(options);
|
|
1011
|
+
assertAddress(address);
|
|
1012
|
+
return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Get settlements with all known peers and total amount sent or received
|
|
1016
|
+
*/
|
|
1017
|
+
async getAllSettlements(options) {
|
|
1018
|
+
assertRequestOptions(options);
|
|
1019
|
+
return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Get status of node
|
|
1023
|
+
*/
|
|
1024
|
+
async getStatus(options) {
|
|
1025
|
+
assertRequestOptions(options);
|
|
1026
|
+
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(options));
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Get health of node
|
|
1030
|
+
*/
|
|
1031
|
+
async getHealth(options) {
|
|
1032
|
+
assertRequestOptions(options);
|
|
1033
|
+
return debugStatus.getHealth(this.getRequestOptionsForCall(options));
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Get readiness of node
|
|
1037
|
+
*/
|
|
1038
|
+
async getReadiness(options) {
|
|
1039
|
+
assertRequestOptions(options);
|
|
1040
|
+
return debugStatus.getReadiness(this.getRequestOptionsForCall(options));
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Get mode information of node
|
|
1044
|
+
*/
|
|
1045
|
+
async getNodeInfo(options) {
|
|
1046
|
+
assertRequestOptions(options);
|
|
1047
|
+
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(options));
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
1051
|
+
*
|
|
1052
|
+
* @returns true if the Bee node version is supported
|
|
1053
|
+
* @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
|
|
1054
|
+
*/
|
|
1055
|
+
async isSupportedVersion(options) {
|
|
1056
|
+
assertRequestOptions(options);
|
|
1057
|
+
return debugStatus.isSupportedVersion(this.getRequestOptionsForCall(options));
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
1061
|
+
*
|
|
1062
|
+
* Be aware that this is the most strict version check and most probably
|
|
1063
|
+
* you will want to use more relaxed API-versions based checks like
|
|
1064
|
+
* `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
|
|
1065
|
+
* based on your use-case.
|
|
1066
|
+
*
|
|
1067
|
+
* @param options
|
|
1068
|
+
*/
|
|
1069
|
+
async isSupportedExactVersion(options) {
|
|
1070
|
+
assertRequestOptions(options);
|
|
1071
|
+
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(options));
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
1075
|
+
*
|
|
1076
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
1077
|
+
* and want to make sure about compatibility.
|
|
1078
|
+
*
|
|
1079
|
+
* @param options
|
|
1080
|
+
*/
|
|
1081
|
+
async isSupportedMainApiVersion(options) {
|
|
1082
|
+
assertRequestOptions(options);
|
|
1083
|
+
return debugStatus.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
*
|
|
1087
|
+
* Connects to a node and checks if its Main API version matches with the one that bee-js supports.
|
|
1088
|
+
*
|
|
1089
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
1090
|
+
*
|
|
1091
|
+
* @param options
|
|
1092
|
+
*/
|
|
1093
|
+
async isSupportedApiVersion(options) {
|
|
1094
|
+
assertRequestOptions(options);
|
|
1095
|
+
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(options));
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
1099
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
1100
|
+
*
|
|
1101
|
+
* @param options
|
|
1102
|
+
*/
|
|
1103
|
+
async getVersions(options) {
|
|
1104
|
+
assertRequestOptions(options);
|
|
1105
|
+
return debugStatus.getVersions(this.getRequestOptionsForCall(options));
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Get reserve state
|
|
1109
|
+
*/
|
|
1110
|
+
async getReserveState(options) {
|
|
1111
|
+
assertRequestOptions(options);
|
|
1112
|
+
return states.getReserveState(this.getRequestOptionsForCall(options));
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Get chain state
|
|
1116
|
+
*/
|
|
1117
|
+
async getChainState(options) {
|
|
1118
|
+
assertRequestOptions(options);
|
|
1119
|
+
return states.getChainState(this.getRequestOptionsForCall(options));
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Get wallet balances for xDai and BZZ of the Bee node
|
|
1123
|
+
*
|
|
1124
|
+
* @param options
|
|
1125
|
+
*/
|
|
1126
|
+
async getWalletBalance(options) {
|
|
1127
|
+
assertRequestOptions(options);
|
|
1128
|
+
return states.getWalletBalance(this.getRequestOptionsForCall(options));
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Creates new postage batch from the funds that the node has available in its Ethereum account.
|
|
1132
|
+
*
|
|
1133
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1134
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1135
|
+
*
|
|
1136
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1137
|
+
*
|
|
1138
|
+
* @param amount Amount that represents the value per chunk, has to be greater or equal zero.
|
|
1139
|
+
* @param depth Logarithm of the number of chunks that can be stamped with the batch.
|
|
1140
|
+
* @param options Options for creation of postage batch
|
|
1141
|
+
* @throws BeeArgumentError when negative amount or depth is specified
|
|
1142
|
+
* @throws TypeError if non-integer value is passed to amount or depth
|
|
1143
|
+
*
|
|
1144
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1145
|
+
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
1146
|
+
*/
|
|
1147
|
+
async createPostageBatch(amount, depth, options, requestOptions) {
|
|
1148
|
+
assertPostageBatchOptions(options);
|
|
1149
|
+
assertPositiveInteger(amount);
|
|
1150
|
+
assertNonNegativeInteger(depth);
|
|
1151
|
+
if (depth < STAMPS_DEPTH_MIN) {
|
|
1152
|
+
throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth);
|
|
1153
|
+
}
|
|
1154
|
+
if (depth > STAMPS_DEPTH_MAX) {
|
|
1155
|
+
throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
|
|
1156
|
+
}
|
|
1157
|
+
if (parseInt(amount, 10) < STAMPS_AMOUNT_MIN) {
|
|
1158
|
+
throw new BeeArgumentError(`Amount has to be at least ${STAMPS_AMOUNT_MIN} (1 day)`, amount);
|
|
1159
|
+
}
|
|
1160
|
+
const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
|
|
1161
|
+
if (options?.waitForUsable !== false) {
|
|
1162
|
+
await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
|
|
1163
|
+
}
|
|
1164
|
+
return stamp;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Topup a fresh amount of BZZ to given Postage Batch.
|
|
1168
|
+
*
|
|
1169
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1170
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1171
|
+
*
|
|
1172
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1173
|
+
*
|
|
1174
|
+
* @param postageBatchId Batch ID
|
|
1175
|
+
* @param amount Amount to be added to the batch
|
|
1176
|
+
* @param options Request options
|
|
1177
|
+
*
|
|
1178
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1179
|
+
* @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)
|
|
1180
|
+
*/
|
|
1181
|
+
async topUpBatch(postageBatchId, amount, options) {
|
|
1182
|
+
assertRequestOptions(options);
|
|
1183
|
+
assertNonNegativeInteger(amount, 'Amount');
|
|
1184
|
+
assertBatchId(postageBatchId);
|
|
1185
|
+
await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
|
|
1189
|
+
* the Postage Batch to be used for more chunks.
|
|
1190
|
+
*
|
|
1191
|
+
* For better understanding what each parameter means and what are the optimal values please see
|
|
1192
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
1193
|
+
*
|
|
1194
|
+
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1195
|
+
*
|
|
1196
|
+
* @param postageBatchId Batch ID
|
|
1197
|
+
* @param depth Amount to be added to the batch
|
|
1198
|
+
* @param options Request options
|
|
1199
|
+
*
|
|
1200
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1201
|
+
* @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)
|
|
1202
|
+
*/
|
|
1203
|
+
async diluteBatch(postageBatchId, depth, options) {
|
|
1204
|
+
assertRequestOptions(options);
|
|
1205
|
+
assertNonNegativeInteger(depth, 'Depth');
|
|
1206
|
+
assertBatchId(postageBatchId);
|
|
1207
|
+
await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Return details for specific postage batch.
|
|
1211
|
+
*
|
|
1212
|
+
* @param postageBatchId Batch ID
|
|
1213
|
+
*
|
|
1214
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1215
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
|
|
1216
|
+
*/
|
|
1217
|
+
async getPostageBatch(postageBatchId, options) {
|
|
1218
|
+
assertRequestOptions(options);
|
|
1219
|
+
assertBatchId(postageBatchId);
|
|
1220
|
+
return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Return detailed information related to buckets for specific postage batch.
|
|
1224
|
+
*
|
|
1225
|
+
* @param postageBatchId Batch ID
|
|
1226
|
+
*
|
|
1227
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1228
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
|
|
1229
|
+
*/
|
|
1230
|
+
async getPostageBatchBuckets(postageBatchId, options) {
|
|
1231
|
+
assertRequestOptions(options);
|
|
1232
|
+
assertBatchId(postageBatchId);
|
|
1233
|
+
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Return all postage batches that has the node available.
|
|
1237
|
+
*
|
|
1238
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
1239
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1240
|
+
*/
|
|
1241
|
+
async getAllPostageBatch(options) {
|
|
1242
|
+
assertRequestOptions(options);
|
|
1243
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Return all globally available postage batches.
|
|
1247
|
+
*/
|
|
1248
|
+
async getAllGlobalPostageBatch(options) {
|
|
1249
|
+
assertRequestOptions(options);
|
|
1250
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Return lists of all current pending transactions that the Bee made
|
|
1254
|
+
*/
|
|
1255
|
+
async getAllPendingTransactions(options) {
|
|
1256
|
+
assertRequestOptions(options);
|
|
1257
|
+
return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Return transaction information for specific transaction
|
|
1261
|
+
* @param transactionHash
|
|
1262
|
+
*/
|
|
1263
|
+
async getPendingTransaction(transactionHash, options) {
|
|
1264
|
+
assertRequestOptions(options);
|
|
1265
|
+
assertTransactionHash(transactionHash);
|
|
1266
|
+
return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Rebroadcast already created transaction.
|
|
1270
|
+
* This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
|
|
1271
|
+
*
|
|
1272
|
+
* @param transactionHash
|
|
1273
|
+
*/
|
|
1274
|
+
async rebroadcastPendingTransaction(transactionHash, options) {
|
|
1275
|
+
assertRequestOptions(options);
|
|
1276
|
+
assertTransactionHash(transactionHash);
|
|
1277
|
+
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Cancel currently pending transaction
|
|
1281
|
+
* @param transactionHash
|
|
1282
|
+
* @param gasPrice
|
|
1283
|
+
*/
|
|
1284
|
+
async cancelPendingTransaction(transactionHash, gasPrice, options) {
|
|
1285
|
+
assertRequestOptions(options);
|
|
1286
|
+
assertTransactionHash(transactionHash);
|
|
1287
|
+
if (gasPrice) {
|
|
1288
|
+
assertNonNegativeInteger(gasPrice);
|
|
1289
|
+
}
|
|
1290
|
+
return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Gets the staked amount of BZZ (in PLUR unit) as number string.
|
|
1294
|
+
*
|
|
1295
|
+
* @param options
|
|
1296
|
+
*/
|
|
1297
|
+
async getStake(options) {
|
|
1298
|
+
assertRequestOptions(options);
|
|
1299
|
+
return stake.getStake(this.getRequestOptionsForCall(options));
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Deposits given amount of BZZ token (in PLUR unit).
|
|
1303
|
+
*
|
|
1304
|
+
* Be aware that staked BZZ tokens can **not** be withdrawn.
|
|
1305
|
+
*
|
|
1306
|
+
* @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
|
|
1307
|
+
* @param options
|
|
1308
|
+
*/
|
|
1309
|
+
async depositStake(amount, options, requestOptions) {
|
|
1310
|
+
assertRequestOptions(options);
|
|
1311
|
+
assertTransactionOptions(options);
|
|
1312
|
+
await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Get current status of node in redistribution game
|
|
1316
|
+
*
|
|
1317
|
+
* @param options
|
|
1318
|
+
*/
|
|
1319
|
+
async getRedistributionState(options) {
|
|
1320
|
+
assertRequestOptions(options);
|
|
1321
|
+
return stake.getRedistributionState(this.getRequestOptionsForCall(options));
|
|
1322
|
+
}
|
|
1323
|
+
async waitForUsablePostageStamp(id, timeout = 240000) {
|
|
1324
|
+
const TIME_STEP = 2000;
|
|
1325
|
+
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
1326
|
+
try {
|
|
1327
|
+
const stamp = await this.getPostageBatch(id);
|
|
1328
|
+
if (stamp.usable) {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
} catch (error) {
|
|
1332
|
+
const message = error?.response?.data?.message || error?.message || '';
|
|
1333
|
+
if (!message.includes('batch not usable')) {
|
|
1334
|
+
throw error;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
await System.sleepMillis(TIME_STEP);
|
|
1338
|
+
}
|
|
1339
|
+
throw new BeeError('Timeout on waiting for postage stamp to become usable');
|
|
1340
|
+
}
|
|
817
1341
|
/**
|
|
818
1342
|
* @param signer
|
|
819
1343
|
* @private
|
package/dist/mjs/chunk/cac.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
2
|
+
import { assertFlexBytes, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
|
|
1
3
|
import { BeeError } from "../utils/error.js";
|
|
2
4
|
import { bmtHash } from "./bmt.js";
|
|
3
|
-
import {
|
|
4
|
-
import { serializeBytes } from "./serialize.js";
|
|
5
|
-
import { makeSpan, SPAN_SIZE } from "./span.js";
|
|
5
|
+
import { SPAN_SIZE, makeSpan } from "./span.js";
|
|
6
6
|
export const MIN_PAYLOAD_SIZE = 1;
|
|
7
7
|
export const MAX_PAYLOAD_SIZE = 4096;
|
|
8
8
|
const CAC_SPAN_OFFSET = 0;
|
|
@@ -15,7 +15,7 @@ const CAC_PAYLOAD_OFFSET = CAC_SPAN_OFFSET + SPAN_SIZE;
|
|
|
15
15
|
export function makeContentAddressedChunk(payloadBytes) {
|
|
16
16
|
const span = makeSpan(payloadBytes.length);
|
|
17
17
|
assertFlexBytes(payloadBytes, MIN_PAYLOAD_SIZE, MAX_PAYLOAD_SIZE);
|
|
18
|
-
const data =
|
|
18
|
+
const data = Binary.concatBytes(span, payloadBytes);
|
|
19
19
|
return {
|
|
20
20
|
data,
|
|
21
21
|
span: () => span,
|
package/dist/mjs/chunk/soc.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
1
2
|
import * as chunkAPI from "../modules/chunk.js";
|
|
2
3
|
import * as socAPI from "../modules/soc.js";
|
|
3
4
|
import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
|
|
@@ -6,8 +7,7 @@ import { keccak256Hash } from "../utils/hash.js";
|
|
|
6
7
|
import { bytesToHex } from "../utils/hex.js";
|
|
7
8
|
import { assertAddress } from "../utils/type.js";
|
|
8
9
|
import { bmtHash } from "./bmt.js";
|
|
9
|
-
import {
|
|
10
|
-
import { serializeBytes } from "./serialize.js";
|
|
10
|
+
import { MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE, assertValidChunkData, makeContentAddressedChunk } from "./cac.js";
|
|
11
11
|
import { recoverAddress, sign } from "./signer.js";
|
|
12
12
|
import { SPAN_SIZE } from "./span.js";
|
|
13
13
|
const IDENTIFIER_SIZE = 32;
|
|
@@ -68,7 +68,7 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
|
68
68
|
assertValidChunkData(chunk.data, chunkAddress);
|
|
69
69
|
const digest = keccak256Hash(identifier, chunkAddress);
|
|
70
70
|
const signature = await sign(signer, digest);
|
|
71
|
-
const data =
|
|
71
|
+
const data = Binary.concatBytes(identifier, signature, chunk.span(), chunk.payload());
|
|
72
72
|
const address = makeSOCAddress(identifier, signer.address);
|
|
73
73
|
return {
|
|
74
74
|
data,
|
|
@@ -85,7 +85,7 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
|
85
85
|
*
|
|
86
86
|
* It uses the Chunk API and calculates the address before uploading.
|
|
87
87
|
*
|
|
88
|
-
* @param
|
|
88
|
+
* @param requestOptions Options for making requests
|
|
89
89
|
* @param chunk A chunk object
|
|
90
90
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
91
91
|
* @param options Upload options
|
|
@@ -94,13 +94,13 @@ export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatch
|
|
|
94
94
|
const owner = bytesToHex(chunk.owner());
|
|
95
95
|
const identifier = bytesToHex(chunk.identifier());
|
|
96
96
|
const signature = bytesToHex(chunk.signature());
|
|
97
|
-
const data =
|
|
97
|
+
const data = Binary.concatBytes(chunk.span(), chunk.payload());
|
|
98
98
|
return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to create and upload SOC.
|
|
102
102
|
*
|
|
103
|
-
* @param
|
|
103
|
+
* @param requestOptions Options for making requests
|
|
104
104
|
* @param signer The singer interface for signing the chunk
|
|
105
105
|
* @param postageBatchId
|
|
106
106
|
* @param identifier The identifier of the chunk
|
package/dist/mjs/chunk/span.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
1
2
|
import { BeeArgumentError } from "../utils/error.js";
|
|
2
3
|
export const SPAN_SIZE = 8;
|
|
3
4
|
// we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
|
|
@@ -16,10 +17,5 @@ export function makeSpan(length) {
|
|
|
16
17
|
if (length > MAX_SPAN_LENGTH) {
|
|
17
18
|
throw new BeeArgumentError('invalid length (> MAX_SPAN_LENGTH)', length);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
const dataView = new DataView(span.buffer);
|
|
21
|
-
const littleEndian = true;
|
|
22
|
-
const lengthLower32 = length & 0xffffffff;
|
|
23
|
-
dataView.setUint32(0, lengthLower32, littleEndian);
|
|
24
|
-
return span;
|
|
20
|
+
return Binary.numberToUint64LE(length);
|
|
25
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
1
2
|
import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
|
|
2
3
|
import { keccak256Hash } from "../utils/hash.js";
|
|
3
4
|
import { hexToBytes, makeHexString } from "../utils/hex.js";
|
|
4
|
-
import { writeUint64BigEndian } from "../utils/uint64.js";
|
|
5
5
|
function isEpoch(epoch) {
|
|
6
6
|
return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ function hashFeedIdentifier(topic, index) {
|
|
|
9
9
|
return keccak256Hash(hexToBytes(topic), index);
|
|
10
10
|
}
|
|
11
11
|
function makeSequentialFeedIdentifier(topic, index) {
|
|
12
|
-
const indexBytes =
|
|
12
|
+
const indexBytes = Binary.numberToUint64BE(index);
|
|
13
13
|
return hashFeedIdentifier(topic, indexBytes);
|
|
14
14
|
}
|
|
15
15
|
function makeFeedIndexBytes(s) {
|