@ethersphere/bee-js 2.1.0 → 3.2.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.
Files changed (160) hide show
  1. package/README.md +3 -3
  2. package/dist/index.browser.min.js +1 -1
  3. package/dist/index.browser.min.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/src/bee-debug.d.ts +5 -1
  7. package/dist/src/bee.d.ts +23 -46
  8. package/dist/src/modules/chunk.d.ts +2 -10
  9. package/dist/src/modules/debug/status.d.ts +10 -4
  10. package/dist/src/types/debug.d.ts +19 -0
  11. package/dist/src/types/index.d.ts +31 -2
  12. package/dist/src/utils/bytes.d.ts +1 -1
  13. package/dist/src/utils/error.d.ts +21 -2
  14. package/dist/src/utils/expose.d.ts +1 -0
  15. package/dist/src/utils/http.d.ts +7 -9
  16. package/dist/src/utils/stamps.d.ts +12 -0
  17. package/dist/src/utils/type.d.ts +6 -0
  18. package/package.json +28 -27
  19. package/.babelrc.js +0 -33
  20. package/.depcheckrc.json +0 -27
  21. package/.editorconfig +0 -6
  22. package/.eslintignore +0 -1
  23. package/.eslintrc.js +0 -109
  24. package/.gitattributes +0 -1
  25. package/.github/config.yaml +0 -23
  26. package/.github/workflows/check.yaml +0 -57
  27. package/.github/workflows/publish_npmjs.yaml +0 -20
  28. package/.github/workflows/release_github.yaml +0 -20
  29. package/.github/workflows/tests.yaml +0 -128
  30. package/.huskyrc +0 -5
  31. package/.prettierrc +0 -13
  32. package/.vscode/launch.json +0 -49
  33. package/.vscode/settings.json +0 -39
  34. package/CHANGELOG.md +0 -520
  35. package/CODEOWNERS +0 -1
  36. package/CODE_OF_CONDUCT.md +0 -76
  37. package/commitlint.config.js +0 -3
  38. package/dist/src/modules/stamps.d.ts +0 -4
  39. package/jest-puppeteer.config.js +0 -5
  40. package/jest.config.ts +0 -85
  41. package/src/bee-debug.ts +0 -601
  42. package/src/bee.ts +0 -1087
  43. package/src/chunk/bmt.ts +0 -55
  44. package/src/chunk/cac.ts +0 -79
  45. package/src/chunk/serialize.ts +0 -16
  46. package/src/chunk/signer.ts +0 -141
  47. package/src/chunk/soc.ts +0 -190
  48. package/src/chunk/span.ts +0 -33
  49. package/src/feed/index.ts +0 -217
  50. package/src/feed/json.ts +0 -33
  51. package/src/feed/topic.ts +0 -23
  52. package/src/feed/type.ts +0 -12
  53. package/src/index.ts +0 -24
  54. package/src/modules/bytes.ts +0 -70
  55. package/src/modules/bzz.ts +0 -179
  56. package/src/modules/chunk.ts +0 -69
  57. package/src/modules/debug/balance.ts +0 -63
  58. package/src/modules/debug/chequebook.ts +0 -175
  59. package/src/modules/debug/chunk.ts +0 -39
  60. package/src/modules/debug/connectivity.ts +0 -61
  61. package/src/modules/debug/settlements.ts +0 -33
  62. package/src/modules/debug/stamps.ts +0 -96
  63. package/src/modules/debug/states.ts +0 -35
  64. package/src/modules/debug/status.ts +0 -34
  65. package/src/modules/debug/tag.ts +0 -19
  66. package/src/modules/debug/transactions.ts +0 -79
  67. package/src/modules/feed.ts +0 -105
  68. package/src/modules/pinning.ts +0 -74
  69. package/src/modules/pss.ts +0 -49
  70. package/src/modules/soc.ts +0 -40
  71. package/src/modules/stamps.ts +0 -59
  72. package/src/modules/status.ts +0 -13
  73. package/src/modules/stewardship.ts +0 -32
  74. package/src/modules/tag.ts +0 -83
  75. package/src/types/debug.ts +0 -204
  76. package/src/types/index.ts +0 -561
  77. package/src/types/ky-universal/common.d.ts +0 -17
  78. package/src/types/ky-universal/hooks.d.ts +0 -103
  79. package/src/types/ky-universal/index.d.ts +0 -125
  80. package/src/types/ky-universal/options.d.ts +0 -235
  81. package/src/types/ky-universal/response.d.ts +0 -38
  82. package/src/types/ky-universal/retry.d.ts +0 -39
  83. package/src/types/tar-js.d.ts +0 -1
  84. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  85. package/src/utils/bytes.ts +0 -144
  86. package/src/utils/collection.ts +0 -151
  87. package/src/utils/data.browser.ts +0 -68
  88. package/src/utils/data.ts +0 -48
  89. package/src/utils/error.ts +0 -23
  90. package/src/utils/eth.ts +0 -229
  91. package/src/utils/expose.ts +0 -48
  92. package/src/utils/file.ts +0 -40
  93. package/src/utils/hash.ts +0 -16
  94. package/src/utils/headers.ts +0 -63
  95. package/src/utils/hex.ts +0 -186
  96. package/src/utils/http.ts +0 -141
  97. package/src/utils/merge.ts +0 -34
  98. package/src/utils/pss.ts +0 -16
  99. package/src/utils/stream.ts +0 -146
  100. package/src/utils/tar.ts +0 -30
  101. package/src/utils/type.ts +0 -394
  102. package/src/utils/uint64.ts +0 -31
  103. package/src/utils/url.ts +0 -52
  104. package/test/bee.sh +0 -187
  105. package/test/data/1.txt +0 -1
  106. package/test/data/2.txt +0 -0
  107. package/test/data/empty +0 -0
  108. package/test/data/sub/3.txt +0 -1
  109. package/test/data/sub//303/251 +0 -0
  110. package/test/data/sub//360/237/230/216 +0 -0
  111. package/test/integration/bee-class.browser.spec.ts +0 -272
  112. package/test/integration/bee-class.spec.ts +0 -648
  113. package/test/integration/bee-debug-class.spec.ts +0 -114
  114. package/test/integration/chunk/bmt.spec.ts +0 -33
  115. package/test/integration/chunk/cac.spec.ts +0 -27
  116. package/test/integration/chunk/soc.spec.ts +0 -38
  117. package/test/integration/feed/index.spec.ts +0 -84
  118. package/test/integration/modules/bytes.spec.ts +0 -23
  119. package/test/integration/modules/bzz.spec.ts +0 -265
  120. package/test/integration/modules/chunk.spec.ts +0 -29
  121. package/test/integration/modules/debug/balance.spec.ts +0 -70
  122. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  123. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  124. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  125. package/test/integration/modules/debug/states.spec.ts +0 -34
  126. package/test/integration/modules/debug/status.spec.ts +0 -65
  127. package/test/integration/modules/debug/tag.spec.ts +0 -27
  128. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  129. package/test/integration/modules/feed.spec.ts +0 -61
  130. package/test/integration/modules/pinning.spec.ts +0 -155
  131. package/test/integration/modules/pss.spec.ts +0 -105
  132. package/test/integration/modules/status.spec.ts +0 -10
  133. package/test/integration/modules/stewardship.spec.ts +0 -32
  134. package/test/integration/modules/tag.spec.ts +0 -51
  135. package/test/test-type-sequencer.js +0 -36
  136. package/test/testpage/testpage.html +0 -20
  137. package/test/tests-setup.ts +0 -94
  138. package/test/unit/assertions.ts +0 -460
  139. package/test/unit/bee-class.spec.ts +0 -976
  140. package/test/unit/bee-debug-class.spec.ts +0 -435
  141. package/test/unit/chunk/bmt.spec.ts +0 -16
  142. package/test/unit/chunk/cac.spec.ts +0 -29
  143. package/test/unit/chunk/serialize.spec.ts +0 -24
  144. package/test/unit/chunk/signer.spec.ts +0 -140
  145. package/test/unit/chunk/soc.spec.ts +0 -25
  146. package/test/unit/chunk/span.spec.ts +0 -38
  147. package/test/unit/feed/json.spec.ts +0 -73
  148. package/test/unit/nock.ts +0 -151
  149. package/test/unit/utils/bytes.spec.ts +0 -32
  150. package/test/unit/utils/collection.spec.ts +0 -22
  151. package/test/unit/utils/eth.spec.ts +0 -224
  152. package/test/unit/utils/hex.spec.ts +0 -115
  153. package/test/unit/utils/stream.spec.ts +0 -30
  154. package/test/unit/utils/type.spec.ts +0 -32
  155. package/test/unit/utils/uint64.spec.ts +0 -102
  156. package/test/utils.ts +0 -426
  157. package/tsconfig.json +0 -18
  158. package/tsconfig.test.json +0 -11
  159. package/typedoc.json +0 -7
  160. package/webpack.config.ts +0 -141
@@ -1,32 +0,0 @@
1
- /* eslint @typescript-eslint/no-empty-function: 0 */
2
- import { NumberString } from '../../../src/types'
3
- import { isInteger } from '../../../src/utils/type'
4
-
5
- describe('type', () => {
6
- describe('isInteger', () => {
7
- const wrongValues = [
8
- () => {},
9
- Number.MAX_SAFE_INTEGER + 1,
10
- Number.MIN_SAFE_INTEGER - 1,
11
- 5.000000000000001,
12
- false,
13
- true,
14
- Infinity,
15
- NaN,
16
- [1],
17
- ]
18
- const correctValues = [5, 0, '10', 5.0000000000000001, '-1']
19
-
20
- wrongValues.forEach((v: unknown | NumberString) =>
21
- test(`should return false for value ${v}`, () => {
22
- expect(isInteger(v)).toEqual(false)
23
- }),
24
- )
25
-
26
- correctValues.forEach((v: unknown | NumberString) =>
27
- test(`should return true for value ${v}`, () => {
28
- expect(isInteger(v)).toEqual(true)
29
- }),
30
- )
31
- })
32
- })
@@ -1,102 +0,0 @@
1
- import { Bytes, makeBytes } from '../../../src/utils/bytes'
2
- import { HexString, hexToBytes } from '../../../src/utils/hex'
3
- import { readUint64BigEndian, writeUint64BigEndian, writeUint64LittleEndian } from '../../../src/utils/uint64'
4
-
5
- describe('uint64', () => {
6
- describe('little endian', () => {
7
- test('zero', () => {
8
- const uint64 = writeUint64LittleEndian(0)
9
- const zero = makeBytes(8)
10
-
11
- expect(uint64).toEqual(zero)
12
- })
13
-
14
- test('one', () => {
15
- const uint64 = writeUint64LittleEndian(1)
16
- const one = hexToBytes('0100000000000000' as HexString)
17
-
18
- expect(uint64).toEqual(one)
19
- })
20
-
21
- test('deadbeef', () => {
22
- const uint64 = writeUint64LittleEndian(0xdeadbeef)
23
- const deadbeef = hexToBytes('efbeadde00000000' as HexString)
24
-
25
- expect(uint64).toEqual(deadbeef)
26
- })
27
- })
28
-
29
- describe('big endian', () => {
30
- describe('write', () => {
31
- test('zero', () => {
32
- const uint64 = writeUint64BigEndian(0)
33
- const zero = makeBytes(8)
34
-
35
- expect(uint64).toEqual(zero)
36
- })
37
-
38
- test('one', () => {
39
- const uint64 = writeUint64BigEndian(1)
40
- const one = hexToBytes('0000000000000001' as HexString)
41
-
42
- expect(uint64).toEqual(one)
43
- })
44
-
45
- test('deadbeef', () => {
46
- const uint64 = writeUint64BigEndian(0xdeadbeef)
47
- const deadbeef = hexToBytes('00000000deadbeef' as HexString)
48
-
49
- expect(uint64).toEqual(deadbeef)
50
- })
51
- })
52
-
53
- describe('read', () => {
54
- test('zero', () => {
55
- const zero = makeBytes(8)
56
- const value = readUint64BigEndian(zero)
57
-
58
- expect(value).toEqual(0)
59
- })
60
-
61
- test('one', () => {
62
- const one = hexToBytes('0000000000000001' as HexString) as Bytes<8>
63
- const value = readUint64BigEndian(one)
64
-
65
- expect(value).toEqual(1)
66
- })
67
-
68
- test('deadbeef', () => {
69
- const deadbeef = hexToBytes('00000000deadbeef' as HexString) as Bytes<8>
70
- const value = readUint64BigEndian(deadbeef)
71
-
72
- expect(value).toEqual(0xdeadbeef)
73
- })
74
- })
75
-
76
- describe('read and write', () => {
77
- test('zero', () => {
78
- const zero = makeBytes(8)
79
- const num = readUint64BigEndian(zero)
80
- const value = writeUint64BigEndian(num)
81
-
82
- expect(value).toEqual(zero)
83
- })
84
-
85
- test('one', () => {
86
- const one = hexToBytes('0000000000000001' as HexString) as Bytes<8>
87
- const num = readUint64BigEndian(one)
88
- const value = writeUint64BigEndian(num)
89
-
90
- expect(value).toEqual(one)
91
- })
92
-
93
- test('deadbeef', () => {
94
- const deadbeef = hexToBytes('00000000deadbeef' as HexString) as Bytes<8>
95
- const num = readUint64BigEndian(deadbeef)
96
- const value = writeUint64BigEndian(num)
97
-
98
- expect(value).toEqual(deadbeef)
99
- })
100
- })
101
- })
102
- })
package/test/utils.ts DELETED
@@ -1,426 +0,0 @@
1
- import { Readable } from 'stream'
2
- import ky from 'ky-universal'
3
- import { ReadableStream } from 'web-streams-polyfill/ponyfill'
4
-
5
- import type { Ky, BeeGenericResponse, Reference, Address, BatchId, DebugPostageBatch } from '../src/types'
6
- import { bytesToHex, HexString } from '../src/utils/hex'
7
- import { deleteChunkFromLocalStorage } from '../src/modules/debug/chunk'
8
- import { BeeResponseError } from '../src'
9
- import { ChunkAddress } from '../src/chunk/cac'
10
- import { assertBytes } from '../src/utils/bytes'
11
- import * as stamps from '../src/modules/debug/stamps'
12
-
13
- declare global {
14
- // eslint-disable-next-line @typescript-eslint/no-namespace
15
- namespace jest {
16
- interface Matchers<R> {
17
- toBeHashReference(): R
18
- toBeBeeResponse(expectedStatusCode: number): R
19
- toBeOneOf(el: unknown[]): R
20
- toBeType(type: string): R
21
- toBeNumberString(): R
22
- }
23
- }
24
- }
25
-
26
- /**
27
- * Load common own Jest Matchers which can be used to check particular return values.
28
- */
29
- export function commonMatchers(): void {
30
- expect.extend({
31
- toBeHashReference(received: string) {
32
- const result = {
33
- pass: false,
34
- message: () => 'Given input is not a Swarm hash reference',
35
- }
36
-
37
- if (typeof received === 'string' && /^[0-9a-fA-F]{64}$/.test(received)) {
38
- result.pass = true
39
- result.message = () => 'Given string is semantically valid Swarm hash reference'
40
- }
41
-
42
- return result
43
- },
44
- toBeBeeResponse(received: BeeGenericResponse, expectedStatusCode: number) {
45
- const result = {
46
- pass: false,
47
- message: () =>
48
- `Bee response does not have status code ${expectedStatusCode}. Got: ${received.code}\nResponse message: ${received.message}`,
49
- }
50
-
51
- if (received.code === expectedStatusCode) {
52
- result.pass = true
53
- result.message = () => 'Bee response meets with its requirements'
54
- }
55
-
56
- return result
57
- },
58
- toBeOneOf(received, argument) {
59
- const validValues = Array.isArray(argument) ? argument : [argument]
60
- let containsValidValue = false
61
-
62
- for (const validValue of validValues) {
63
- try {
64
- expect(received).toEqual(validValue)
65
- containsValidValue = true
66
- // eslint-disable-next-line no-empty
67
- } catch (e) {}
68
- }
69
-
70
- if (containsValidValue) {
71
- return {
72
- message: () => `expected ${JSON.stringify(received)} not to be one of [${validValues.join(', ')}]`,
73
- pass: true,
74
- }
75
- }
76
-
77
- return {
78
- message: () => `expected ${JSON.stringify(received)} to be one of [${validValues.join(', ')}]`,
79
- pass: false,
80
- }
81
- },
82
- toBeType(received, argument) {
83
- const initialType = typeof received
84
- const isArray = Array.isArray(received) ? 'array' : initialType
85
- const type = initialType === 'object' ? isArray : initialType
86
-
87
- return type === argument
88
- ? {
89
- message: () => `expected ${received} to be type ${argument}`,
90
- pass: true,
91
- }
92
- : {
93
- message: () => `expected ${received} to be type ${argument}`,
94
- pass: false,
95
- }
96
- },
97
- toBeNumberString(received) {
98
- const message = () => `expected ${received} to be a number in a string type`
99
-
100
- return /^-?(0|[1-9][0-9]*)$/g.test(received)
101
- ? {
102
- message,
103
- pass: true,
104
- }
105
- : {
106
- message,
107
- pass: false,
108
- }
109
- },
110
- })
111
- }
112
-
113
- /**
114
- * Sleep for N miliseconds
115
- *
116
- * @param ms Number of miliseconds to sleep
117
- */
118
- export async function sleep(ms: number): Promise<void> {
119
- return new Promise<void>(resolve => setTimeout(() => resolve(), ms))
120
- }
121
-
122
- export function createRandomNodeReadable(totalSize: number, chunkSize = 1000): Readable {
123
- if (totalSize % chunkSize !== 0) {
124
- throw new Error(`totalSize ${totalSize} is not dividable without remainder by chunkSize ${chunkSize}`)
125
- }
126
-
127
- const stream = new Readable()
128
- // eslint-disable-next-line @typescript-eslint/no-empty-function
129
- stream._read = (): void => {}
130
-
131
- for (let i = 0; i < totalSize / chunkSize; i++) {
132
- stream.push(randomByteArray(chunkSize))
133
- }
134
-
135
- stream.push(null)
136
-
137
- return stream
138
- }
139
-
140
- export function createReadableStream(iterable: Iterable<Uint8Array>): ReadableStream {
141
- const iter = iterable[Symbol.iterator]()
142
-
143
- return new ReadableStream({
144
- async pull(controller) {
145
- const result = iter.next()
146
-
147
- if (result.done) {
148
- controller.close()
149
-
150
- return
151
- }
152
-
153
- controller.enqueue(result.value)
154
- },
155
- })
156
- }
157
-
158
- /**
159
- * Lehmer random number generator with seed (minstd_rand in C++11)
160
- * !!! Very fast but not well distributed pseudo-random function !!!
161
- *
162
- * @param seed Seed for the pseudo-random generator
163
- */
164
- function lrng(seed: number): () => number {
165
- return (): number => ((2 ** 31 - 1) & (seed = Math.imul(48271, seed))) / 2 ** 31
166
- }
167
-
168
- /**
169
- * Utility function for generating random Buffer
170
- * !!! IT IS NOT CRYPTO SAFE !!!
171
- * For that use `crypto.randomBytes()`
172
- *
173
- * @param length Number of bytes to generate
174
- * @param seed Seed for the pseudo-random generator
175
- */
176
- export function randomByteArray(length: number, seed = 500): Uint8Array {
177
- const rand = lrng(seed)
178
- const buf = new Uint8Array(length)
179
-
180
- for (let i = 0; i < length; ++i) {
181
- buf[i] = (rand() * 0xff) << 0
182
- }
183
-
184
- return buf
185
- }
186
-
187
- /**
188
- * Returns a url for testing the Bee public API
189
- */
190
- export function beeUrl(): string {
191
- return process.env.BEE_API_URL || 'http://localhost:1633'
192
- }
193
-
194
- export function beeKy(): Ky {
195
- return ky.create({ prefixUrl: beeUrl(), timeout: false })
196
- }
197
-
198
- /**
199
- * Returns a url of another peer for testing the Bee public API
200
- */
201
- export function beePeerUrl(): string {
202
- return process.env.BEE_PEER_API_URL || 'http://localhost:11633'
203
- }
204
-
205
- export function beePeerKy(): Ky {
206
- return ky.create({ prefixUrl: beePeerUrl(), timeout: false })
207
- }
208
-
209
- /**
210
- * Helper function that create monster batch for all the tests.
211
- * There is semaphore mechanism that allows only creation of one batch across all the
212
- * parallel running tests that have to wait until it is created.
213
- */
214
- export function getPostageBatch(url = beeDebugUrl()): BatchId {
215
- let stamp: BatchId
216
-
217
- switch (url) {
218
- case beeDebugUrl():
219
- stamp = process.env.BEE_POSTAGE as BatchId
220
- break
221
- case beePeerDebugUrl():
222
- stamp = process.env.BEE_PEER_POSTAGE as BatchId
223
- break
224
- default:
225
- throw new Error('Unknown URL ' + url)
226
- }
227
-
228
- if (!stamp) {
229
- throw new Error('There is no postage stamp configured for URL ' + url)
230
- }
231
-
232
- return stamp
233
- }
234
-
235
- /**
236
- * Returns a url for testing the Bee Debug API
237
- */
238
- export function beeDebugUrl(): string {
239
- return process.env.BEE_DEBUG_API_URL || 'http://localhost:1635'
240
- }
241
-
242
- export function beeDebugKy(): Ky {
243
- return ky.create({ prefixUrl: beeDebugUrl(), timeout: false })
244
- }
245
-
246
- /**
247
- * Returns a url for testing the Bee Debug API
248
- */
249
- export function beePeerDebugUrl(): string {
250
- return process.env.BEE_PEER_DEBUG_API_URL || 'http://localhost:11635'
251
- }
252
-
253
- export function beePeerDebugKy(): Ky {
254
- return ky.create({ prefixUrl: beePeerDebugUrl(), timeout: false })
255
- }
256
-
257
- /**
258
- * Try to delete a chunk from local storage, ignoring all errors
259
- *
260
- * @param address Swarm address of chunk
261
- */
262
- export async function tryDeleteChunkFromLocalStorage(address: string | ChunkAddress): Promise<void> {
263
- if (typeof address !== 'string') {
264
- assertBytes(address, 32)
265
- address = bytesToHex(address)
266
- }
267
-
268
- try {
269
- await deleteChunkFromLocalStorage(beeDebugKy(), address)
270
- } catch (e) {
271
- // ignore not found errors
272
- if (e instanceof BeeResponseError && e.status === 404) {
273
- return
274
- }
275
- throw e
276
- }
277
- }
278
-
279
- /**
280
- * Formatting utility for displaying long strings like hexstrings.
281
- *
282
- * @param inputStr
283
- * @param len
284
- */
285
- export function shorten(inputStr: unknown, len = 17): string {
286
- const str = typeof inputStr === 'string' ? inputStr : (inputStr as string).toString()
287
-
288
- if (str.length <= len) {
289
- return str
290
- }
291
-
292
- return `${str.slice(0, 6)}...${str.slice(-6)} (length: ${str.length})`
293
- }
294
-
295
- async function timeout(ms: number, message = 'Execution reached timeout!'): Promise<Error> {
296
- await sleep(ms)
297
- throw new Error(message)
298
- }
299
-
300
- export async function waitForBatchToBeUsable(batchId: string, pollingInterval = 200): Promise<void> {
301
- await Promise.race([
302
- timeout(USABLE_TIMEOUT, 'Awaiting of usable postage batch timed out!'),
303
- async () => {
304
- let stamp
305
-
306
- do {
307
- await sleep(pollingInterval)
308
- stamp = await stamps.getPostageBatch(beeDebugKy(), batchId as BatchId)
309
- } while (!stamp.usable)
310
- },
311
- ])
312
- }
313
-
314
- const DEFAULT_BATCH_AMOUNT = '1'
315
- const DEFAULT_BATCH_DEPTH = 17
316
-
317
- /**
318
- * Returns already existing batch or will create one.
319
- *
320
- * If some specification is passed then it is guaranteed that the batch will have this property(ies)
321
- *
322
- * @param amount
323
- * @param depth
324
- * @param immutable
325
- */
326
- export async function getOrCreatePostageBatch(
327
- amount?: string,
328
- depth?: number,
329
- immutable?: boolean,
330
- ): Promise<DebugPostageBatch> {
331
- // Non-usable stamps are ignored by Bee
332
- const allUsableStamps = (await stamps.getAllPostageBatches(beeDebugKy())).filter(stamp => stamp.usable)
333
-
334
- if (allUsableStamps.length === 0) {
335
- const batchId = await stamps.createPostageBatch(
336
- beeDebugKy(),
337
- amount ?? DEFAULT_BATCH_AMOUNT,
338
- depth ?? DEFAULT_BATCH_DEPTH,
339
- )
340
-
341
- await waitForBatchToBeUsable(batchId)
342
-
343
- return stamps.getPostageBatch(beeDebugKy(), batchId)
344
- }
345
-
346
- // User does not want any specific batch, lets give him the first one
347
- if (amount === undefined && depth === undefined && immutable === undefined) {
348
- return allUsableStamps[0]
349
- }
350
-
351
- // User wants some specific batch
352
- for (const stamp of allUsableStamps) {
353
- let meetingAllCriteria = false
354
-
355
- if (amount !== undefined) {
356
- meetingAllCriteria = amount === stamp.amount
357
- } else {
358
- meetingAllCriteria = true
359
- }
360
-
361
- if (depth !== undefined) {
362
- meetingAllCriteria = meetingAllCriteria && depth === stamp.depth
363
- }
364
-
365
- if (immutable !== undefined) {
366
- meetingAllCriteria = meetingAllCriteria && immutable === stamp.immutableFlag
367
- }
368
-
369
- if (meetingAllCriteria) {
370
- return stamp
371
- }
372
- }
373
-
374
- // No stamp meeting the criteria was found ==> we need to create a new one
375
- const batchId = await stamps.createPostageBatch(
376
- beeDebugKy(),
377
- amount ?? DEFAULT_BATCH_AMOUNT,
378
- depth ?? DEFAULT_BATCH_DEPTH,
379
- )
380
-
381
- await waitForBatchToBeUsable(batchId)
382
-
383
- return stamps.getPostageBatch(beeDebugKy(), batchId)
384
- }
385
-
386
- export function makeTestTarget(target: string): string {
387
- return target.slice(0, 2)
388
- }
389
-
390
- export const invalidReference = '0000000000000000000000000000000000000000000000000000000000000000' as Reference
391
-
392
- export const okResponse: BeeGenericResponse = {
393
- code: 200,
394
- message: 'OK',
395
- }
396
-
397
- export const createdResponse: BeeGenericResponse = {
398
- code: 201,
399
- message: 'Created',
400
- }
401
-
402
- const USABLE_TIMEOUT = 7_000
403
- export const ERR_TIMEOUT = 40_000
404
- export const BIG_FILE_TIMEOUT = 100_000
405
- export const PSS_TIMEOUT = 120_000
406
- export const FEED_TIMEOUT = 120_000
407
- export const BLOCKCHAIN_TRANSACTION_TIMEOUT = 40_000
408
-
409
- export const testChunkPayload = new Uint8Array([1, 2, 3])
410
- // span is the payload length encoded as uint64 little endian
411
- export const testChunkSpan = new Uint8Array([testChunkPayload.length, 0, 0, 0, 0, 0, 0, 0])
412
- export const testChunkData = new Uint8Array([...testChunkSpan, ...testChunkPayload])
413
- // the hash is hardcoded because we would need the bmt hasher otherwise
414
- export const testChunkHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as Reference
415
- export const testAddress = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as Address
416
- export const testBatchId = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as BatchId
417
-
418
- export const testJsonPayload = [{ some: 'object' }]
419
- export const testJsonStringPayload = JSON.stringify(testJsonPayload)
420
- export const testJsonHash = '872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa'
421
-
422
- export const testIdentity = {
423
- privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd' as HexString,
424
- publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4' as HexString,
425
- address: '8d3766440f0d7b949a5e32995d09619a7f86e632' as HexString,
426
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "include": ["src"],
3
- "compilerOptions": {
4
- "alwaysStrict": true,
5
- "target": "ES6",
6
- "esModuleInterop": true,
7
- "allowSyntheticDefaultImports": true,
8
- "moduleResolution": "node",
9
- "module": "commonjs",
10
- "strict": true,
11
- "resolveJsonModule": true,
12
- "experimentalDecorators": true,
13
- "emitDecoratorMetadata": true,
14
- "typeRoots": ["./src/types", "node_modules/@types"],
15
- "rootDirs": ["src"],
16
- "outDir": "dist"
17
- },
18
- }
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": [
4
- "src",
5
- "test",
6
- "jest.config.ts"
7
- ],
8
- "compilerOptions": {
9
- "noEmit": true
10
- }
11
- }
package/typedoc.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "entryPoints": ["./src/index.ts"],
3
- "readme": "none",
4
- "logLevel": "Verbose",
5
- "excludePrivate": true,
6
- "out": "docs"
7
- }