@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.
Files changed (181) hide show
  1. package/CHANGELOG.md +135 -2
  2. package/README.md +3 -1
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.LICENSE.txt +51 -0
  5. package/dist/index.browser.min.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.LICENSE.txt +42 -0
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/src/bee-debug.d.ts +75 -38
  10. package/dist/src/bee.d.ts +88 -82
  11. package/dist/src/chunk/soc.d.ts +6 -6
  12. package/dist/src/feed/index.d.ts +7 -7
  13. package/dist/src/feed/json.d.ts +2 -2
  14. package/dist/src/modules/bytes.d.ts +8 -11
  15. package/dist/src/modules/bzz.d.ts +9 -14
  16. package/dist/src/modules/chunk.d.ts +7 -11
  17. package/dist/src/modules/debug/balance.d.ts +9 -9
  18. package/dist/src/modules/debug/chequebook.d.ts +17 -18
  19. package/dist/src/modules/debug/chunk.d.ts +5 -5
  20. package/dist/src/modules/debug/connectivity.d.ts +7 -7
  21. package/dist/src/modules/debug/settlements.d.ts +5 -5
  22. package/dist/src/modules/debug/stamps.d.ts +7 -5
  23. package/dist/src/modules/debug/states.d.ts +5 -5
  24. package/dist/src/modules/debug/status.d.ts +5 -4
  25. package/dist/src/modules/debug/tag.d.ts +3 -3
  26. package/dist/src/modules/debug/transactions.d.ts +9 -9
  27. package/dist/src/modules/feed.d.ts +5 -5
  28. package/dist/src/modules/pinning.d.ts +9 -9
  29. package/dist/src/modules/pss.d.ts +4 -3
  30. package/dist/src/modules/soc.d.ts +3 -3
  31. package/dist/src/modules/status.d.ts +3 -2
  32. package/dist/src/modules/stewardship.d.ts +4 -4
  33. package/dist/src/modules/tag.d.ts +6 -6
  34. package/dist/src/types/debug.d.ts +4 -2
  35. package/dist/src/types/index.d.ts +71 -19
  36. package/dist/src/utils/bytes.d.ts +1 -1
  37. package/dist/src/utils/data.browser.d.ts +3 -1
  38. package/dist/src/utils/data.d.ts +7 -4
  39. package/dist/src/utils/expose.d.ts +6 -9
  40. package/dist/src/utils/headers.d.ts +3 -3
  41. package/dist/src/utils/http.d.ts +25 -0
  42. package/dist/src/utils/merge.d.ts +8 -0
  43. package/dist/src/utils/pss.d.ts +9 -0
  44. package/dist/src/utils/stream.d.ts +37 -0
  45. package/dist/src/utils/type.d.ts +19 -9
  46. package/package.json +15 -8
  47. package/.babelrc.js +0 -33
  48. package/.depcheckrc.json +0 -27
  49. package/.editorconfig +0 -6
  50. package/.eslintignore +0 -1
  51. package/.eslintrc.js +0 -108
  52. package/.gitattributes +0 -1
  53. package/.github/config.yaml +0 -23
  54. package/.github/workflows/check.yaml +0 -57
  55. package/.github/workflows/publish_npmjs.yaml +0 -20
  56. package/.github/workflows/release_github.yaml +0 -20
  57. package/.github/workflows/tests.yaml +0 -128
  58. package/.huskyrc +0 -5
  59. package/.prettierrc +0 -13
  60. package/.vscode/launch.json +0 -49
  61. package/.vscode/settings.json +0 -39
  62. package/CODEOWNERS +0 -1
  63. package/CODE_OF_CONDUCT.md +0 -76
  64. package/commitlint.config.js +0 -3
  65. package/dist/src/modules/stamps.d.ts +0 -4
  66. package/dist/src/utils/hooks.d.ts +0 -31
  67. package/dist/src/utils/safe-axios.d.ts +0 -8
  68. package/jest-puppeteer.config.js +0 -5
  69. package/jest.config.ts +0 -170
  70. package/src/bee-debug.ts +0 -440
  71. package/src/bee.ts +0 -941
  72. package/src/chunk/bmt.ts +0 -55
  73. package/src/chunk/cac.ts +0 -79
  74. package/src/chunk/serialize.ts +0 -16
  75. package/src/chunk/signer.ts +0 -141
  76. package/src/chunk/soc.ts +0 -190
  77. package/src/chunk/span.ts +0 -33
  78. package/src/feed/index.ts +0 -221
  79. package/src/feed/json.ts +0 -32
  80. package/src/feed/topic.ts +0 -23
  81. package/src/feed/type.ts +0 -12
  82. package/src/index.ts +0 -24
  83. package/src/modules/bytes.ts +0 -75
  84. package/src/modules/bzz.ts +0 -184
  85. package/src/modules/chunk.ts +0 -75
  86. package/src/modules/debug/balance.ts +0 -63
  87. package/src/modules/debug/chequebook.ts +0 -174
  88. package/src/modules/debug/chunk.ts +0 -39
  89. package/src/modules/debug/connectivity.ts +0 -61
  90. package/src/modules/debug/settlements.ts +0 -33
  91. package/src/modules/debug/stamps.ts +0 -69
  92. package/src/modules/debug/states.ts +0 -35
  93. package/src/modules/debug/status.ts +0 -34
  94. package/src/modules/debug/tag.ts +0 -19
  95. package/src/modules/debug/transactions.ts +0 -79
  96. package/src/modules/feed.ts +0 -92
  97. package/src/modules/pinning.ts +0 -74
  98. package/src/modules/pss.ts +0 -48
  99. package/src/modules/soc.ts +0 -41
  100. package/src/modules/stamps.ts +0 -59
  101. package/src/modules/status.ts +0 -13
  102. package/src/modules/stewardship.ts +0 -21
  103. package/src/modules/tag.ts +0 -83
  104. package/src/types/axios/index.d.ts +0 -18
  105. package/src/types/debug.ts +0 -204
  106. package/src/types/index.ts +0 -497
  107. package/src/types/tar-js.d.ts +0 -1
  108. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  109. package/src/utils/bytes.ts +0 -144
  110. package/src/utils/collection.ts +0 -151
  111. package/src/utils/data.browser.ts +0 -24
  112. package/src/utils/data.ts +0 -35
  113. package/src/utils/error.ts +0 -23
  114. package/src/utils/eth.ts +0 -229
  115. package/src/utils/expose.ts +0 -10
  116. package/src/utils/file.ts +0 -40
  117. package/src/utils/hash.ts +0 -16
  118. package/src/utils/headers.ts +0 -63
  119. package/src/utils/hex.ts +0 -186
  120. package/src/utils/hooks.ts +0 -89
  121. package/src/utils/safe-axios.ts +0 -98
  122. package/src/utils/tar.ts +0 -30
  123. package/src/utils/type.ts +0 -302
  124. package/src/utils/uint64.ts +0 -31
  125. package/src/utils/url.ts +0 -52
  126. package/test/bee.sh +0 -187
  127. package/test/data/1.txt +0 -1
  128. package/test/data/2.txt +0 -0
  129. package/test/data/empty +0 -0
  130. package/test/data/sub/3.txt +0 -1
  131. package/test/data/sub//303/251 +0 -0
  132. package/test/data/sub//360/237/230/216 +0 -0
  133. package/test/integration/bee-class.browser.spec.ts +0 -215
  134. package/test/integration/bee-class.spec.ts +0 -595
  135. package/test/integration/bee-debug-class.spec.ts +0 -85
  136. package/test/integration/chunk/bmt.spec.ts +0 -33
  137. package/test/integration/chunk/cac.spec.ts +0 -27
  138. package/test/integration/chunk/soc.spec.ts +0 -38
  139. package/test/integration/feed/index.spec.ts +0 -84
  140. package/test/integration/modules/bytes.spec.ts +0 -23
  141. package/test/integration/modules/bzz.spec.ts +0 -270
  142. package/test/integration/modules/chunk.spec.ts +0 -29
  143. package/test/integration/modules/debug/balance.spec.ts +0 -70
  144. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  145. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  146. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  147. package/test/integration/modules/debug/states.spec.ts +0 -34
  148. package/test/integration/modules/debug/status.spec.ts +0 -65
  149. package/test/integration/modules/debug/tag.spec.ts +0 -27
  150. package/test/integration/modules/feed.spec.ts +0 -61
  151. package/test/integration/modules/pinning.spec.ts +0 -155
  152. package/test/integration/modules/pss.spec.ts +0 -92
  153. package/test/integration/modules/status.spec.ts +0 -10
  154. package/test/integration/modules/stewardship.spec.ts +0 -32
  155. package/test/integration/modules/tag.spec.ts +0 -51
  156. package/test/test-type-sequencer.js +0 -36
  157. package/test/testpage/testpage.html +0 -20
  158. package/test/unit/assertions.ts +0 -376
  159. package/test/unit/bee-class.spec.ts +0 -685
  160. package/test/unit/bee-debug-class.spec.ts +0 -365
  161. package/test/unit/chunk/bmt.spec.ts +0 -16
  162. package/test/unit/chunk/cac.spec.ts +0 -29
  163. package/test/unit/chunk/serialize.spec.ts +0 -24
  164. package/test/unit/chunk/signer.spec.ts +0 -140
  165. package/test/unit/chunk/soc.spec.ts +0 -25
  166. package/test/unit/chunk/span.spec.ts +0 -38
  167. package/test/unit/feed/json.spec.ts +0 -73
  168. package/test/unit/nock.ts +0 -134
  169. package/test/unit/utils/bytes.spec.ts +0 -32
  170. package/test/unit/utils/collection.spec.ts +0 -22
  171. package/test/unit/utils/eth.spec.ts +0 -224
  172. package/test/unit/utils/hex.spec.ts +0 -115
  173. package/test/unit/utils/hooks.spec.ts +0 -179
  174. package/test/unit/utils/safe-axios.spec.ts +0 -20
  175. package/test/unit/utils/type.spec.ts +0 -32
  176. package/test/unit/utils/uint64.spec.ts +0 -102
  177. package/test/utils.ts +0 -292
  178. package/tsconfig.json +0 -18
  179. package/tsconfig.test.json +0 -11
  180. package/typedoc.json +0 -7
  181. package/webpack.config.ts +0 -141
@@ -1,31 +0,0 @@
1
- import { Bytes, makeBytes } from './bytes'
2
-
3
- // TODO handle bigger values than 32 bit
4
- // For now it's good enough because we only use these functions
5
- // sequential feed indexes.
6
- export function writeUint64LittleEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
7
- const dataView = new DataView(bytes.buffer)
8
- const valueLower32 = value & 0xffffffff
9
- const littleEndian = true
10
-
11
- dataView.setUint32(0, valueLower32, littleEndian)
12
- dataView.setUint32(4, 0, littleEndian)
13
-
14
- return bytes
15
- }
16
-
17
- export function writeUint64BigEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
18
- const dataView = new DataView(bytes.buffer)
19
- const valueLower32 = value & 0xffffffff
20
-
21
- dataView.setUint32(0, 0)
22
- dataView.setUint32(4, valueLower32)
23
-
24
- return bytes
25
- }
26
-
27
- export function readUint64BigEndian(bytes: Bytes<8>): number {
28
- const dataView = new DataView(bytes.buffer)
29
-
30
- return dataView.getUint32(4)
31
- }
package/src/utils/url.ts DELETED
@@ -1,52 +0,0 @@
1
- import { BeeArgumentError } from './error'
2
-
3
- /**
4
- * Validates that passed string is valid URL of Bee.
5
- * We support only HTTP and HTTPS protocols.
6
- *
7
- * @param url
8
- */
9
- export function isValidBeeUrl(url: unknown): url is URL {
10
- try {
11
- if (typeof url !== 'string') {
12
- return false
13
- }
14
-
15
- const urlObject = new URL(url)
16
-
17
- // There can be wide range of protocols passed.
18
- return urlObject.protocol === 'http:' || urlObject.protocol === 'https:'
19
- } catch (e) {
20
- // URL constructor throws TypeError if not valid URL
21
- // TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
22
- if (e instanceof TypeError || (e.code && e.code === 'ERR_INVALID_URL')) {
23
- return false
24
- }
25
-
26
- throw e
27
- }
28
- }
29
-
30
- /**
31
- * Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
32
- * We support only HTTP and HTTPS protocols.
33
- * @param url
34
- * @throws BeeArgumentError if non valid URL
35
- */
36
- export function assertBeeUrl(url: unknown): asserts url is URL {
37
- if (!isValidBeeUrl(url)) {
38
- throw new BeeArgumentError('URL is not valid!', url)
39
- }
40
- }
41
-
42
- /**
43
- * Removes trailing slash out of the given string.
44
- * @param url
45
- */
46
- export function stripLastSlash(url: string): string {
47
- if (url.endsWith('/')) {
48
- return url.slice(0, -1)
49
- }
50
-
51
- return url
52
- }
package/test/bee.sh DELETED
@@ -1,187 +0,0 @@
1
- #!/bin/bash
2
-
3
- echoerr() { if [[ $QUIET -ne 1 ]] ; then echo "$@" 1>&2; fi }
4
-
5
- usage() {
6
- cat << USAGE >&2
7
- USAGE:
8
- $ bee.sh [COMMAND] [PARAMETERS]
9
- COMMANDS:
10
- start create Bee cluster with the given parameters
11
- stop stop Bee cluster
12
- PARAMETERS:
13
- --ephemeral create ephemeral container for bee-client. Data won't be persisted.
14
- --workers=number all Bee nodes in the test environment. Default is 4.
15
- --port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
16
- 1. 1633:1635
17
- 2. 11633:11635
18
- 3. 21633:21635 (...)
19
- number represents the nodes number to map from. Default is 4.
20
- --password=string password for Bee client(s).
21
- --version=x.y.z used version of Bee client.
22
- USAGE
23
- exit 1
24
- }
25
-
26
- stop() {
27
- echo "Stop following containers:"
28
- docker container stop $QUEEN_CONTAINER_NAME;
29
- WORKER_NAMES=`docker container ls -f name="$WORKER_CONTAINER_NAME*" --format "{{.Names}}"`
30
- for WORKER_NAME in $WORKER_NAMES; do
31
- docker container stop "$WORKER_NAME"
32
- done
33
-
34
- trap - SIGINT
35
- exit 0;
36
- }
37
-
38
- fetch_queen_underlay_addr() {
39
- if [[ ! -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then return; fi
40
-
41
- while : ; do
42
- QUEEN_UNDERLAY_ADDRESS=$(curl -s localhost:1635/addresses | python -mjson.tool 2>&1 | grep "/ip4/" | awk '!/127.0.0.1/' | xargs)
43
- if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then
44
- echo "Waiting for the Queen initialization..."
45
- sleep 5
46
- else
47
- break;
48
- fi
49
- done
50
- }
51
-
52
- log_queen() {
53
- trap stop SIGINT
54
- docker logs --tail 25 -f $QUEEN_CONTAINER_NAME
55
- }
56
-
57
- # Init variables
58
- EPHEMERAL=false
59
- WORKERS=4
60
- QUEEN_CONTAINER_NAME="bee-queen-test"
61
- WORKER_CONTAINER_NAME="bee-worker-test"
62
- QUEEN_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$QUEEN_CONTAINER_NAME`
63
- BEE_VERSION="latest"
64
- BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
65
- BEE_PASSWORD="password"
66
- QUEEN_BOOTNODE=""
67
- PORT_MAPS=2
68
-
69
- # Decide script action
70
- case "$1" in
71
- start)
72
- shift 1
73
- ;;
74
- stop)
75
- stop
76
- ;;
77
- *)
78
- echoerr "Unknown command: $1"
79
- usage
80
- ;;
81
- esac
82
-
83
- # Alter variables from flags
84
- while [ $# -gt 0 ]
85
- do
86
- case "$1" in
87
- --ephemeral)
88
- EPHEMERAL=true
89
- shift 1
90
- ;;
91
- --workers=*)
92
- WORKERS=${1#*=}
93
- shift 1
94
- ;;
95
- --password=*)
96
- BEE_PASSWORD="${1#*=}"
97
- shift 1
98
- ;;
99
- --version=*)
100
- BEE_VERSION="${1#*=}"
101
- BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
102
- shift 1
103
- ;;
104
- --port-maps=*)
105
- PORT_MAPS="${1#*=}"
106
- shift 1
107
- ;;
108
- --help)
109
- usage
110
- ;;
111
- *)
112
- echoerr "Unknown argument: $1"
113
- usage
114
- ;;
115
- esac
116
- done
117
-
118
- if $EPHEMERAL ; then
119
- EXTRA_DOCKER_PARAMS=" --rm"
120
- fi
121
-
122
- # Start Bee Queen
123
- if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
124
- EXTRA_QUEEN_PARAMS=""
125
- if [ $PORT_MAPS -ge 1 ] ; then
126
- EXTRA_QUEEN_PARAMS=" -p 127.0.0.1:1633-1635:1633-1635"
127
- fi
128
-
129
- echo "start Bee Queen process"
130
- docker run \
131
- -d \
132
- --name $QUEEN_CONTAINER_NAME \
133
- $EXTRA_DOCKER_PARAMS \
134
- $EXTRA_QUEEN_PARAMS \
135
- $BEE_IMAGE \
136
- start \
137
- --password $BEE_PASSWORD \
138
- --bootnode=$QUEEN_BOOTNODE \
139
- --swap-enable=false \
140
- --debug-api-enable \
141
- --verbosity=4 \
142
- --welcome-message="You have found the queen of the beehive..." \
143
- --cors-allowed-origins="*" \
144
- --payment-tolerance=2147483647
145
- else
146
- docker start "$QUEEN_CONTAINER_IN_DOCKER"
147
- fi
148
-
149
- # Start Bee workers
150
- for i in $(seq 1 1 $WORKERS); do
151
- WORKER_NAME="$WORKER_CONTAINER_NAME-$i"
152
- WORKER_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$WORKER_NAME`
153
- if [ -z "$WORKER_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
154
- # fetch queen underlay address
155
- fetch_queen_underlay_addr
156
-
157
- # construct additional params
158
- EXTRA_WORKER_PARAMS=""
159
- if [ $PORT_MAPS -gt $i ] ; then
160
- PORT_START=$((1633+(10000*$i)))
161
- PORT_END=$(($PORT_START + 2))
162
- EXTRA_WORKER_PARAMS=" -p 127.0.0.1:$PORT_START-$PORT_END:1633-1635"
163
- fi
164
-
165
- # run docker container
166
- echo "start Bee worker $i process"
167
- docker run \
168
- -d \
169
- --name $WORKER_NAME \
170
- $EXTRA_DOCKER_PARAMS \
171
- $EXTRA_WORKER_PARAMS \
172
- $BEE_IMAGE \
173
- start \
174
- --password $BEE_PASSWORD \
175
- --bootnode="$QUEEN_UNDERLAY_ADDRESS" \
176
- --swap-enable=false \
177
- --debug-api-enable \
178
- --welcome-message="I'm just Bee worker ${i} in the beehive." \
179
- --cors-allowed-origins="*" \
180
- --payment-tolerance=2147483647
181
- else
182
- docker start "$WORKER_CONTAINER_IN_DOCKER"
183
- fi
184
- done
185
-
186
- # log Bee Queen
187
- log_queen
package/test/data/1.txt DELETED
@@ -1 +0,0 @@
1
- 1
package/test/data/2.txt DELETED
File without changes
package/test/data/empty DELETED
File without changes
@@ -1 +0,0 @@
1
- 3
File without changes
File without changes
@@ -1,215 +0,0 @@
1
- import { join } from 'path'
2
- import {
3
- beeDebugUrl,
4
- beePeerDebugUrl,
5
- beePeerUrl,
6
- beeUrl,
7
- commonMatchers,
8
- getPostageBatch,
9
- PSS_TIMEOUT,
10
- } from '../utils'
11
- import '../../src'
12
- import type { Address } from '../../src/types'
13
-
14
- commonMatchers()
15
-
16
- describe('Bee class - in browser', () => {
17
- const BEE_URL = beeUrl()
18
- const BEE_DEBUG_URL = beeDebugUrl()
19
- const BEE_PEER_URL = beePeerUrl()
20
- let batchId: Address, batchIdPeer: Address
21
-
22
- beforeAll(async () => {
23
- await jestPuppeteer.resetPage()
24
- const testPage = join(__dirname, '..', 'testpage', 'testpage.html')
25
- await page.goto(`file://${testPage}`)
26
-
27
- batchId = await getPostageBatch()
28
- batchIdPeer = await getPostageBatch(beePeerDebugUrl())
29
- })
30
-
31
- it('should create a new Bee instance in browser', async () => {
32
- const testBeeInstance = await page.evaluate(BEE_URL => {
33
- return new window.BeeJs.Bee(BEE_URL)
34
- }, BEE_URL)
35
-
36
- expect(testBeeInstance.url).toBe(BEE_URL)
37
- })
38
-
39
- function testUrl(url: unknown): void {
40
- it(`should not accept invalid url '${url}'`, async () => {
41
- await page.evaluate(url => {
42
- try {
43
- new window.BeeJs.Bee(url as string)
44
- fail('Bee constructor should have thrown error.')
45
- } catch (e) {
46
- if (e instanceof window.BeeJs.BeeArgumentError) {
47
- // We don't have `expect()` available in browser context
48
- if (e.value !== url) {
49
- throw new Error('Error value does not match the URL!')
50
- }
51
-
52
- return
53
- }
54
-
55
- throw e
56
- }
57
- }, url as string)
58
- })
59
- }
60
-
61
- testUrl('')
62
- testUrl(null)
63
- testUrl(undefined)
64
- testUrl(1)
65
- testUrl('some-invalid-url')
66
- testUrl('invalid:protocol')
67
- // eslint-disable-next-line no-script-url
68
- testUrl('javascript:console.log()')
69
- testUrl('ws://localhost:1633')
70
-
71
- it('should pin and unpin collection', async () => {
72
- const fileHash = await page.evaluate(
73
- async (BEE_URL, batchId) => {
74
- const bee = new window.BeeJs.Bee(BEE_URL)
75
- const files: File[] = [new File(['hello'], 'hello')]
76
-
77
- return await bee.uploadFiles(batchId, files)
78
- },
79
- BEE_URL,
80
- batchId,
81
- )
82
- expect(fileHash).toBeHashReference()
83
- //pinning
84
- await page.evaluate(
85
- async (BEE_URL, fileHash) => {
86
- const bee = new window.BeeJs.Bee(BEE_URL)
87
-
88
- return await bee.pin(fileHash)
89
- },
90
- BEE_URL,
91
- fileHash,
92
- )
93
-
94
- //unpinning
95
- await page.evaluate(
96
- async (BEE_URL, fileHash) => {
97
- const bee = new window.BeeJs.Bee(BEE_URL)
98
-
99
- return await bee.unpin(fileHash)
100
- },
101
- BEE_URL,
102
- fileHash,
103
- )
104
- })
105
-
106
- it('should get state of uploading on uploading file', async () => {
107
- const uploadEvent = await page.evaluate(
108
- async (BEE_URL, batchId) => {
109
- const bee = new window.BeeJs.Bee(BEE_URL)
110
- const filename = 'hello.txt'
111
- const data = new Uint8Array([1, 2, 3, 4])
112
-
113
- let uploadEvent: { loaded: number; total: number } = {
114
- loaded: 0,
115
- total: 4,
116
- }
117
-
118
- await bee.uploadFile(batchId, data, filename, {
119
- contentType: 'text/html',
120
- axiosOptions: {
121
- onUploadProgress: ({ loaded, total }) => {
122
- uploadEvent = { loaded, total }
123
- },
124
- },
125
- })
126
-
127
- return uploadEvent
128
- },
129
- BEE_URL,
130
- batchId,
131
- )
132
-
133
- expect(uploadEvent).toEqual({ loaded: 4, total: 4 })
134
- })
135
-
136
- describe('pss', () => {
137
- it(
138
- 'should send and receive pss message',
139
- done => {
140
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
141
- ;(async () => {
142
- const message = '1234'
143
-
144
- const result = await page.evaluate(
145
- async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
146
- const topic = 'browser-bee-class-topic1'
147
-
148
- const bee = new window.BeeJs.Bee(BEE_URL)
149
- const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
150
-
151
- const { overlay } = await beeDebug.getNodeAddresses()
152
- const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
153
-
154
- const receive = bee.pssReceive(topic)
155
- await beePeer.pssSend(batchIdPeer, topic, overlay, message)
156
-
157
- const msg = await receive
158
-
159
- // Need to pass it back as string
160
- return new TextDecoder('utf-8').decode(new Uint8Array(msg))
161
- },
162
- BEE_URL,
163
- BEE_DEBUG_URL,
164
- BEE_PEER_URL,
165
- message,
166
- batchIdPeer,
167
- )
168
-
169
- expect(result).toEqual(message)
170
- done()
171
- })()
172
- },
173
- PSS_TIMEOUT,
174
- )
175
-
176
- it(
177
- 'should send and receive pss message encrypted with PSS key',
178
- done => {
179
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
180
- ;(async () => {
181
- const message = '1234'
182
-
183
- const result = await page.evaluate(
184
- async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
185
- const topic = 'browser-bee-class-topic2'
186
-
187
- const bee = new window.BeeJs.Bee(BEE_URL)
188
- const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
189
-
190
- const { overlay, pssPublicKey } = await beeDebug.getNodeAddresses()
191
- const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
192
-
193
- const receive = bee.pssReceive(topic)
194
- await beePeer.pssSend(batchIdPeer, topic, overlay, message, pssPublicKey)
195
-
196
- const msg = await receive
197
-
198
- // Need to pass it back as string
199
- return new TextDecoder('utf-8').decode(new Uint8Array(msg))
200
- },
201
- BEE_URL,
202
- BEE_DEBUG_URL,
203
- BEE_PEER_URL,
204
- message,
205
- batchIdPeer,
206
- )
207
-
208
- expect(result).toEqual(message)
209
- done()
210
- })()
211
- },
212
- PSS_TIMEOUT,
213
- )
214
- })
215
- })