@ethersphere/bee-js 1.2.1 → 3.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/CHANGELOG.md +135 -2
- package/README.md +3 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +51 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.LICENSE.txt +42 -0
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +75 -38
- package/dist/src/bee.d.ts +88 -82
- package/dist/src/chunk/soc.d.ts +6 -6
- package/dist/src/feed/index.d.ts +7 -7
- package/dist/src/feed/json.d.ts +2 -2
- package/dist/src/modules/bytes.d.ts +8 -11
- package/dist/src/modules/bzz.d.ts +9 -14
- package/dist/src/modules/chunk.d.ts +7 -11
- package/dist/src/modules/debug/balance.d.ts +9 -9
- package/dist/src/modules/debug/chequebook.d.ts +17 -18
- package/dist/src/modules/debug/chunk.d.ts +5 -5
- package/dist/src/modules/debug/connectivity.d.ts +7 -7
- package/dist/src/modules/debug/settlements.d.ts +5 -5
- package/dist/src/modules/debug/stamps.d.ts +7 -5
- package/dist/src/modules/debug/states.d.ts +5 -5
- package/dist/src/modules/debug/status.d.ts +5 -4
- package/dist/src/modules/debug/tag.d.ts +3 -3
- package/dist/src/modules/debug/transactions.d.ts +9 -9
- package/dist/src/modules/feed.d.ts +5 -5
- package/dist/src/modules/pinning.d.ts +9 -9
- package/dist/src/modules/pss.d.ts +4 -3
- package/dist/src/modules/soc.d.ts +3 -3
- package/dist/src/modules/status.d.ts +3 -2
- package/dist/src/modules/stewardship.d.ts +4 -4
- package/dist/src/modules/tag.d.ts +6 -6
- package/dist/src/types/debug.d.ts +4 -2
- package/dist/src/types/index.d.ts +71 -19
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/data.browser.d.ts +3 -1
- package/dist/src/utils/data.d.ts +7 -4
- package/dist/src/utils/expose.d.ts +6 -9
- package/dist/src/utils/headers.d.ts +3 -3
- package/dist/src/utils/http.d.ts +25 -0
- package/dist/src/utils/merge.d.ts +8 -0
- package/dist/src/utils/pss.d.ts +9 -0
- package/dist/src/utils/stream.d.ts +37 -0
- package/dist/src/utils/type.d.ts +19 -9
- package/package.json +15 -8
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -108
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/dist/src/utils/hooks.d.ts +0 -31
- package/dist/src/utils/safe-axios.d.ts +0 -8
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -170
- package/src/bee-debug.ts +0 -440
- package/src/bee.ts +0 -941
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -221
- package/src/feed/json.ts +0 -32
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -75
- package/src/modules/bzz.ts +0 -184
- package/src/modules/chunk.ts +0 -75
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -174
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -69
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -92
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -48
- package/src/modules/soc.ts +0 -41
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -21
- package/src/modules/tag.ts +0 -83
- package/src/types/axios/index.d.ts +0 -18
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -497
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -24
- package/src/utils/data.ts +0 -35
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -10
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/hooks.ts +0 -89
- package/src/utils/safe-axios.ts +0 -98
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -302
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -215
- package/test/integration/bee-class.spec.ts +0 -595
- package/test/integration/bee-debug-class.spec.ts +0 -85
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -270
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -92
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/unit/assertions.ts +0 -376
- package/test/unit/bee-class.spec.ts +0 -685
- package/test/unit/bee-debug-class.spec.ts +0 -365
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -134
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/hooks.spec.ts +0 -179
- package/test/unit/utils/safe-axios.spec.ts +0 -20
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -292
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
package/src/types/index.ts
DELETED
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
import type { AxiosRequestConfig } from 'axios'
|
|
2
|
-
import { Identifier, SingleOwnerChunk } from '../chunk/soc'
|
|
3
|
-
import { ChunkReference, FeedUploadOptions } from '../feed'
|
|
4
|
-
import { FeedType } from '../feed/type'
|
|
5
|
-
import { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed'
|
|
6
|
-
import { Bytes } from '../utils/bytes'
|
|
7
|
-
import { BeeError } from '../utils/error'
|
|
8
|
-
import { EthAddress, HexEthAddress } from '../utils/eth'
|
|
9
|
-
import { HexString } from '../utils/hex'
|
|
10
|
-
export * from './debug'
|
|
11
|
-
|
|
12
|
-
export interface Dictionary<T> {
|
|
13
|
-
[Key: string]: T
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const ADDRESS_HEX_LENGTH = 64
|
|
17
|
-
export const PUBKEY_HEX_LENGTH = 66
|
|
18
|
-
export const BATCH_ID_HEX_LENGTH = 64
|
|
19
|
-
export const REFERENCE_HEX_LENGTH = 64
|
|
20
|
-
export const ENCRYPTED_REFERENCE_HEX_LENGTH = 128
|
|
21
|
-
export const REFERENCE_BYTES_LENGTH = 32
|
|
22
|
-
export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Minimal depth that can be used for creation of postage batch
|
|
26
|
-
*/
|
|
27
|
-
export const STAMPS_DEPTH_MIN = 17
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Maximal depth that can be used for creation of postage batch
|
|
31
|
-
*/
|
|
32
|
-
export const STAMPS_DEPTH_MAX = 255
|
|
33
|
-
|
|
34
|
-
export const TAGS_LIMIT_MIN = 1
|
|
35
|
-
export const TAGS_LIMIT_MAX = 1000
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Generic reference that can be either non-encrypted reference which is a hex string of length 64 or encrypted
|
|
39
|
-
* reference which is a hex string of length 128.
|
|
40
|
-
*
|
|
41
|
-
* Encrypted reference consists of two parts. The reference address itself (like non-encrypted reference) and decryption key.
|
|
42
|
-
*
|
|
43
|
-
* @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
|
|
44
|
-
*/
|
|
45
|
-
export type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>
|
|
46
|
-
export type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>
|
|
47
|
-
|
|
48
|
-
export type Address = HexString<typeof ADDRESS_HEX_LENGTH>
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* BatchId is result of keccak256 hash so 64 hex string without prefix.
|
|
52
|
-
*/
|
|
53
|
-
export type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* AddressPrefix is an HexString of length equal or smaller then ADDRESS_HEX_LENGTH.
|
|
57
|
-
* It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
|
|
58
|
-
*/
|
|
59
|
-
export type AddressPrefix = HexString
|
|
60
|
-
|
|
61
|
-
export interface BeeOptions {
|
|
62
|
-
/**
|
|
63
|
-
* Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
|
|
64
|
-
*/
|
|
65
|
-
signer?: Signer | Uint8Array | string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface UploadOptions {
|
|
69
|
-
/**
|
|
70
|
-
* Will pin the data locally in the Bee node as well.
|
|
71
|
-
*
|
|
72
|
-
* Locally pinned data is possible to reupload to network if it disappear.
|
|
73
|
-
*
|
|
74
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
75
|
-
*
|
|
76
|
-
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
77
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
|
|
78
|
-
*/
|
|
79
|
-
pin?: boolean
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Will encrypt the uploaded data and return longer hash which also includes the decryption key.
|
|
83
|
-
*
|
|
84
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
85
|
-
*
|
|
86
|
-
* @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
|
|
87
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
|
|
88
|
-
* @see Reference
|
|
89
|
-
*/
|
|
90
|
-
encrypt?: boolean
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Tags keep track of syncing the data with network. This option allows attach existing Tag UUID to the uploaded data.
|
|
94
|
-
*
|
|
95
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
|
|
96
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
97
|
-
* @link Tag
|
|
98
|
-
*/
|
|
99
|
-
tag?: number
|
|
100
|
-
|
|
101
|
-
/** Alter default options of axios HTTP client */
|
|
102
|
-
axiosOptions?: AxiosRequestConfig
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface FileUploadOptions extends UploadOptions {
|
|
106
|
-
/**
|
|
107
|
-
* Specifies Content-Length for the given data. It is required when uploading with Readable.
|
|
108
|
-
*
|
|
109
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
|
|
110
|
-
*/
|
|
111
|
-
size?: number
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Specifies given Content-Type so when loaded in browser the file is correctly represented.
|
|
115
|
-
*
|
|
116
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
|
|
117
|
-
*/
|
|
118
|
-
contentType?: string
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface CollectionUploadOptions extends UploadOptions {
|
|
122
|
-
/**
|
|
123
|
-
* Default file to be returned when the root hash of collection is accessed.
|
|
124
|
-
*
|
|
125
|
-
* @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
|
|
126
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
|
|
127
|
-
*/
|
|
128
|
-
indexDocument?: string
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Configure custom error document to be returned when a specified path can not be found in collection.
|
|
132
|
-
*
|
|
133
|
-
* @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
|
|
134
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
|
|
135
|
-
*/
|
|
136
|
-
errorDocument?: string
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface UploadHeaders {
|
|
140
|
-
'swarm-pin'?: string
|
|
141
|
-
'swarm-encrypt'?: string
|
|
142
|
-
'swarm-tag'?: string
|
|
143
|
-
'swarm-postage-batch-id'?: string
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Object that contains infromation about progress of upload of data to network.
|
|
148
|
-
*
|
|
149
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
150
|
-
*/
|
|
151
|
-
export interface Tag {
|
|
152
|
-
/**
|
|
153
|
-
* Number of all chunks that the data will be split into.
|
|
154
|
-
*/
|
|
155
|
-
total: number
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Number of chunks that is locally stored in the Bee node.
|
|
159
|
-
*/
|
|
160
|
-
processed: number
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Number of chunks that arrived to their designated destination in the network
|
|
164
|
-
*/
|
|
165
|
-
synced: number
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Unique identifier
|
|
169
|
-
*/
|
|
170
|
-
uid: number
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* When the upload process started
|
|
174
|
-
*/
|
|
175
|
-
startedAt: string
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export interface AllTagsOptions {
|
|
179
|
-
limit?: number
|
|
180
|
-
offset?: number
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface FileHeaders {
|
|
184
|
-
name?: string
|
|
185
|
-
tagUid?: number
|
|
186
|
-
contentType?: string
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export interface FileData<T> extends FileHeaders {
|
|
190
|
-
data: T
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export interface Pin {
|
|
194
|
-
reference: string
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Helper interface that adds utility functions
|
|
199
|
-
* to work more conveniently with bytes in normal
|
|
200
|
-
* user scenarios.
|
|
201
|
-
*
|
|
202
|
-
* Concretely: text(), hex(), json()
|
|
203
|
-
*/
|
|
204
|
-
export interface Data extends Uint8Array {
|
|
205
|
-
/**
|
|
206
|
-
* Converts the binary data using UTF-8 decoding into string.
|
|
207
|
-
*/
|
|
208
|
-
text(): string
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Converts the binary data into hex-string.
|
|
212
|
-
*/
|
|
213
|
-
hex(): HexString
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Converts the binary data into string which is then parsed into JSON.
|
|
217
|
-
*/
|
|
218
|
-
json(): Record<string, unknown>
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Object represents a file and some of its metadata in [[Directory]] object.
|
|
223
|
-
*/
|
|
224
|
-
export interface CollectionEntry<T> {
|
|
225
|
-
data: T
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
*
|
|
229
|
-
*/
|
|
230
|
-
path: string
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Represents Collections
|
|
235
|
-
*/
|
|
236
|
-
export type Collection<T> = Array<CollectionEntry<T>>
|
|
237
|
-
|
|
238
|
-
export interface PssSubscription {
|
|
239
|
-
readonly topic: string
|
|
240
|
-
cancel: () => void
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface PssMessageHandler {
|
|
244
|
-
onMessage: (message: Data, subscription: PssSubscription) => void
|
|
245
|
-
onError: (error: BeeError, subscription: PssSubscription) => void
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export interface BeeGenericResponse {
|
|
249
|
-
message: string
|
|
250
|
-
code: number
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export interface ReferenceResponse {
|
|
254
|
-
reference: Reference
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export type HttpMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'post' | 'POST' | 'patch' | 'PATCH'
|
|
258
|
-
|
|
259
|
-
export interface BeeRequest {
|
|
260
|
-
url: string
|
|
261
|
-
method: HttpMethod
|
|
262
|
-
headers?: Record<string, string>
|
|
263
|
-
params?: Record<string, unknown>
|
|
264
|
-
data?: unknown
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export interface BeeResponse {
|
|
268
|
-
headers: Record<string, string>
|
|
269
|
-
data: unknown
|
|
270
|
-
status: number
|
|
271
|
-
statusText?: string
|
|
272
|
-
request: BeeRequest
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/*********************************************************
|
|
276
|
-
* Writers and Readers interfaces
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
export const TOPIC_BYTES_LENGTH = 32
|
|
280
|
-
export const TOPIC_HEX_LENGTH = 64
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Hex string of length 64 chars without prefix that specifies topics for feed.
|
|
284
|
-
*/
|
|
285
|
-
export type Topic = HexString<typeof TOPIC_HEX_LENGTH>
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* FeedReader is an interface for downloading feed updates
|
|
289
|
-
*/
|
|
290
|
-
export interface FeedReader {
|
|
291
|
-
readonly type: FeedType
|
|
292
|
-
readonly owner: HexEthAddress
|
|
293
|
-
readonly topic: Topic
|
|
294
|
-
/**
|
|
295
|
-
* Download the latest feed update
|
|
296
|
-
*/
|
|
297
|
-
download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export interface JsonFeedOptions {
|
|
301
|
-
/**
|
|
302
|
-
* Valid only for `get` action, where either this `address` or `signer` has
|
|
303
|
-
* to be specified.
|
|
304
|
-
*/
|
|
305
|
-
address?: EthAddress | Uint8Array | string
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Custom Signer object or private key in either binary or hex form.
|
|
309
|
-
* This required for `set` action, and optional for `get` although
|
|
310
|
-
* if not specified for `get` then `address` option has to be specified.
|
|
311
|
-
*/
|
|
312
|
-
signer?: Signer | Uint8Array | string
|
|
313
|
-
type?: FeedType
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* FeedWriter is an interface for updating feeds
|
|
318
|
-
*/
|
|
319
|
-
export interface FeedWriter extends FeedReader {
|
|
320
|
-
/**
|
|
321
|
-
* Upload a new feed update
|
|
322
|
-
*
|
|
323
|
-
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
324
|
-
* @param reference The reference to be stored in the new update
|
|
325
|
-
* @param options Additional options like `at`
|
|
326
|
-
*
|
|
327
|
-
* @returns Reference that points at Single Owner Chunk that contains the new update and pointer to the updated chunk reference.
|
|
328
|
-
*/
|
|
329
|
-
upload(
|
|
330
|
-
postageBatchId: string | BatchId,
|
|
331
|
-
reference: ChunkReference | Reference,
|
|
332
|
-
options?: FeedUploadOptions,
|
|
333
|
-
): Promise<Reference>
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Interface for downloading single owner chunks
|
|
338
|
-
*/
|
|
339
|
-
export interface SOCReader {
|
|
340
|
-
/**
|
|
341
|
-
* Downloads a single owner chunk
|
|
342
|
-
*
|
|
343
|
-
* @param identifier The identifier of the chunk
|
|
344
|
-
*/
|
|
345
|
-
download: (identifier: Identifier) => Promise<SingleOwnerChunk>
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Interface for downloading and uploading single owner chunks
|
|
350
|
-
*/
|
|
351
|
-
export interface SOCWriter extends SOCReader {
|
|
352
|
-
/**
|
|
353
|
-
* Uploads a single owner chunk
|
|
354
|
-
*
|
|
355
|
-
* @param identifier The identifier of the chunk
|
|
356
|
-
* @param data The chunk payload data
|
|
357
|
-
* @param options Upload options
|
|
358
|
-
*/
|
|
359
|
-
upload: (
|
|
360
|
-
postageBatchId: string | BatchId,
|
|
361
|
-
identifier: Identifier,
|
|
362
|
-
data: Uint8Array,
|
|
363
|
-
options?: UploadOptions,
|
|
364
|
-
) => Promise<Reference>
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Interface representing Postage stamp batch.
|
|
369
|
-
*/
|
|
370
|
-
export interface PostageBatch {
|
|
371
|
-
batchID: BatchId
|
|
372
|
-
utilization: number
|
|
373
|
-
usable: boolean
|
|
374
|
-
label: '' | string
|
|
375
|
-
depth: number
|
|
376
|
-
amount: string
|
|
377
|
-
bucketDepth: number
|
|
378
|
-
blockNumber: number
|
|
379
|
-
immutableFlag: boolean
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export interface DebugPostageBatch extends PostageBatch {
|
|
383
|
-
/**
|
|
384
|
-
* The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
|
|
385
|
-
*/
|
|
386
|
-
batchTTL: number
|
|
387
|
-
|
|
388
|
-
exists: boolean
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
export interface BatchBucket {
|
|
392
|
-
bucketID: number
|
|
393
|
-
collisions: number
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export interface PostageBatchBuckets {
|
|
397
|
-
depth: number
|
|
398
|
-
bucketDepth: number
|
|
399
|
-
bucketUpperBound: number
|
|
400
|
-
buckets?: BatchBucket[]
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export type TransactionHash = BrandedString<'TransactionHash'>
|
|
404
|
-
|
|
405
|
-
export interface TransactionInfo {
|
|
406
|
-
transactionHash: TransactionHash
|
|
407
|
-
to: HexEthAddress
|
|
408
|
-
nonce: number
|
|
409
|
-
gasPrice: NumberString
|
|
410
|
-
gasLimit: number
|
|
411
|
-
data: string
|
|
412
|
-
created: string
|
|
413
|
-
description: string
|
|
414
|
-
value: string
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Options for creation of postage batch
|
|
419
|
-
*/
|
|
420
|
-
export interface PostageBatchOptions {
|
|
421
|
-
/**
|
|
422
|
-
* Sets label for the postage batch
|
|
423
|
-
*/
|
|
424
|
-
label?: string
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Sets gas price in Wei for the transaction that creates the postage batch
|
|
428
|
-
*/
|
|
429
|
-
gasPrice?: NumberString
|
|
430
|
-
immutableFlag?: boolean
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* With this type a number should be represented in a string
|
|
435
|
-
*/
|
|
436
|
-
export type NumberString = FlavoredType<string, 'NumberString'>
|
|
437
|
-
|
|
438
|
-
/*********************************************************
|
|
439
|
-
* Ethereum compatible signing interfaces and definitions
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
export const SIGNATURE_HEX_LENGTH = 130
|
|
443
|
-
export const SIGNATURE_BYTES_LENGTH = 65
|
|
444
|
-
|
|
445
|
-
export type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>
|
|
446
|
-
export type PrivateKeyBytes = Bytes<32>
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Signing function that takes digest in Uint8Array to be signed that has helpers to convert it
|
|
450
|
-
* conveniently into other types like hex-string (non prefix).
|
|
451
|
-
* Result of the signing can be returned either in Uint8Array or hex string form.
|
|
452
|
-
*
|
|
453
|
-
* @see Data
|
|
454
|
-
*/
|
|
455
|
-
type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string
|
|
456
|
-
type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Interface for implementing Ethereum compatible signing.
|
|
460
|
-
*
|
|
461
|
-
* In order to be compatible with Ethereum and its signing method `personal_sign`, the data
|
|
462
|
-
* that are passed to sign() function should be prefixed with: `\x19Ethereum Signed Message:\n${data.length}`, hashed
|
|
463
|
-
* and only then signed.
|
|
464
|
-
* If you are wrapping another signer tool/library (like Metamask or some other Ethereum wallet), you might not have
|
|
465
|
-
* to do this prefixing manually if you use the `personal_sign` method. Check documentation of the tool!
|
|
466
|
-
* If you are writing your own storage for keys, then you have to prefix the data manually otherwise the Bee node
|
|
467
|
-
* will reject the chunks signed by you!
|
|
468
|
-
*
|
|
469
|
-
* For example see the hashWithEthereumPrefix() function.
|
|
470
|
-
*
|
|
471
|
-
* @property sign The sign function that can be sync or async. This function takes non-prefixed data. See above.
|
|
472
|
-
* @property address The ethereum address of the signer in bytes.
|
|
473
|
-
* @see hashWithEthereumPrefix
|
|
474
|
-
*/
|
|
475
|
-
export type Signer = {
|
|
476
|
-
sign: SyncSigner | AsyncSigner
|
|
477
|
-
address: EthAddress
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* These type are used to create new nominal types
|
|
482
|
-
*
|
|
483
|
-
* See https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/
|
|
484
|
-
*/
|
|
485
|
-
export type BrandedType<Type, Name> = Type & { __tag__: Name }
|
|
486
|
-
|
|
487
|
-
export type BrandedString<Name> = BrandedType<string, Name>
|
|
488
|
-
|
|
489
|
-
export type FlavoredType<Type, Name> = Type & { __tag__?: Name }
|
|
490
|
-
|
|
491
|
-
// JSON typings
|
|
492
|
-
// by @indiescripter at https://github.com/microsoft/TypeScript/issues/1897#issuecomment-338650717
|
|
493
|
-
export type AnyJson = boolean | number | string | null | JsonArray | JsonMap
|
|
494
|
-
interface JsonMap {
|
|
495
|
-
[key: string]: AnyJson
|
|
496
|
-
}
|
|
497
|
-
type JsonArray = Array<AnyJson>
|
package/src/types/tar-js.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'tar-js'
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* We declare this module manually instead of using the @types/webpack-bundle-analyzer
|
|
3
|
-
* because it relies on the old @types/webpack for v4 that cause incompatibilities with v5
|
|
4
|
-
* because v5 ships its own definitions.
|
|
5
|
-
*/
|
|
6
|
-
declare module 'webpack-bundle-analyzer' {
|
|
7
|
-
import { Compiler, WebpackPluginInstance } from 'webpack'
|
|
8
|
-
|
|
9
|
-
export class BundleAnalyzerPlugin implements WebpackPluginInstance {
|
|
10
|
-
constructor(options?: unknown)
|
|
11
|
-
apply(compiler: Compiler): void
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/utils/bytes.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper type for dealing with fixed size byte arrays.
|
|
3
|
-
*
|
|
4
|
-
* It changes the type of `length` property of `Uint8Array` to the
|
|
5
|
-
* generic `Length` type parameter which is runtime compatible with
|
|
6
|
-
* the original, because it extends from the `number` type.
|
|
7
|
-
*/
|
|
8
|
-
import { Data } from '../types'
|
|
9
|
-
import { bytesToHex } from './hex'
|
|
10
|
-
|
|
11
|
-
export interface Bytes<Length extends number> extends Uint8Array {
|
|
12
|
-
readonly length: Length
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Helper type for dealing with flexible sized byte arrays.
|
|
17
|
-
*
|
|
18
|
-
* The actual min and and max values are not stored in runtime, they
|
|
19
|
-
* are only there to differentiate the type from the Uint8Array at
|
|
20
|
-
* compile time.
|
|
21
|
-
* @see BrandedType
|
|
22
|
-
*/
|
|
23
|
-
export interface FlexBytes<Min extends number, Max extends number> extends Uint8Array {
|
|
24
|
-
readonly __min__: Min
|
|
25
|
-
readonly __max__: Max
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Type guard for Bytes<T> type
|
|
30
|
-
*
|
|
31
|
-
* @param b The byte array
|
|
32
|
-
* @param length The length of the byte array
|
|
33
|
-
*/
|
|
34
|
-
export function isBytes<Length extends number>(b: unknown, length: Length): b is Bytes<Length> {
|
|
35
|
-
return b instanceof Uint8Array && b.length === length
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Verifies if a byte array has a certain length
|
|
40
|
-
*
|
|
41
|
-
* @param b The byte array
|
|
42
|
-
* @param length The specified length
|
|
43
|
-
*/
|
|
44
|
-
export function assertBytes<Length extends number>(b: unknown, length: Length): asserts b is Bytes<Length> {
|
|
45
|
-
if (!isBytes(b, length)) {
|
|
46
|
-
throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${(b as Uint8Array).length}`)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Type guard for FlexBytes<Min,Max> type
|
|
52
|
-
*
|
|
53
|
-
* @param b The byte array
|
|
54
|
-
* @param min Minimum size of the array
|
|
55
|
-
* @param max Maximum size of the array
|
|
56
|
-
*/
|
|
57
|
-
export function isFlexBytes<Min extends number, Max extends number = Min>(
|
|
58
|
-
b: unknown,
|
|
59
|
-
min: Min,
|
|
60
|
-
max: Max,
|
|
61
|
-
): b is FlexBytes<Min, Max> {
|
|
62
|
-
return b instanceof Uint8Array && b.length >= min && b.length <= max
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Verifies if a byte array has a certain length between min and max
|
|
67
|
-
*
|
|
68
|
-
* @param b The byte array
|
|
69
|
-
* @param min Minimum size of the array
|
|
70
|
-
* @param max Maximum size of the array
|
|
71
|
-
*/
|
|
72
|
-
export function assertFlexBytes<Min extends number, Max extends number = Min>(
|
|
73
|
-
b: unknown,
|
|
74
|
-
min: Min,
|
|
75
|
-
max: Max,
|
|
76
|
-
): asserts b is FlexBytes<Min, Max> {
|
|
77
|
-
if (!isFlexBytes(b, min, max)) {
|
|
78
|
-
throw new TypeError(
|
|
79
|
-
`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${(b as Uint8Array).length}`,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Return `length` bytes starting from `offset`
|
|
86
|
-
*
|
|
87
|
-
* @param data The original data
|
|
88
|
-
* @param offset The offset to start from
|
|
89
|
-
* @param length The length of data to be returned
|
|
90
|
-
*/
|
|
91
|
-
export function bytesAtOffset<Length extends number>(data: Uint8Array, offset: number, length: Length): Bytes<Length> {
|
|
92
|
-
const offsetBytes = data.slice(offset, offset + length) as Bytes<Length>
|
|
93
|
-
|
|
94
|
-
// We are returning strongly typed Bytes so we have to verify that length is really what we claim
|
|
95
|
-
assertBytes<Length>(offsetBytes, length)
|
|
96
|
-
|
|
97
|
-
return offsetBytes
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Return flex bytes starting from `offset`
|
|
102
|
-
*
|
|
103
|
-
* @param data The original data
|
|
104
|
-
* @param offset The offset to start from
|
|
105
|
-
* @param _min The minimum size of the data
|
|
106
|
-
* @param _max The maximum size of the data
|
|
107
|
-
*/
|
|
108
|
-
export function flexBytesAtOffset<Min extends number, Max extends number>(
|
|
109
|
-
data: Uint8Array,
|
|
110
|
-
offset: number,
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
112
|
-
_min: Min,
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
114
|
-
_max: Max,
|
|
115
|
-
): FlexBytes<Min, Max> {
|
|
116
|
-
return data.slice(offset) as FlexBytes<Min, Max>
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Returns true if two byte arrays are equal
|
|
121
|
-
*
|
|
122
|
-
* @param a Byte array to compare
|
|
123
|
-
* @param b Byte array to compare
|
|
124
|
-
*/
|
|
125
|
-
export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
126
|
-
return a.length === b.length && a.every((value, index) => value === b[index])
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Returns a new byte array filled with zeroes with the specified length
|
|
131
|
-
*
|
|
132
|
-
* @param length The length of data to be returned
|
|
133
|
-
*/
|
|
134
|
-
export function makeBytes<Length extends number>(length: Length): Bytes<Length> {
|
|
135
|
-
return new Uint8Array(length) as Bytes<Length>
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function wrapBytesWithHelpers(data: Uint8Array): Data {
|
|
139
|
-
return Object.assign(data, {
|
|
140
|
-
text: () => new TextDecoder('utf-8').decode(data),
|
|
141
|
-
json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
|
|
142
|
-
hex: () => bytesToHex(data),
|
|
143
|
-
})
|
|
144
|
-
}
|