Skip to content

refactor!: use swarm core - #1236

Open
slapec93 wants to merge 21 commits into
upcomingfrom
chore/use-swarm-core
Open

refactor!: use swarm core#1236
slapec93 wants to merge 21 commits into
upcomingfrom
chore/use-swarm-core

Conversation

@slapec93

@slapec93 slapec93 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Before TODO:

  • Publish swarm-core as @ethersphere/swarm-core in npm.js and use that instead of @upcoming

Gergely Békési added 8 commits July 21, 2026 14:11
@slapec93
slapec93 marked this pull request as ready for review July 22, 2026 10:14
Comment thread src/chunk/soc.ts Outdated
address: socAddress,
owner: ownerAddress,
try {
return coreUnmarshalSingleOwnerChunk(data instanceof Bytes ? data.toUint8Array() : data, address)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bytes comes from core, and coreUnmarshalSingleOwnerChunk is a core function too, so this logic should be in the core, being able to juggle with its own types.

Comment thread src/manifest/manifest.ts
@@ -1,22 +1,64 @@
import { Binary, MerkleTree, Optional, Uint8ArrayReader } from 'cafe-utility'
import { Optional } from 'cafe-utility'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manifest should also be in core. Bee-JS should only provide a thin layer on how to serialize, deserialize it recursively (so a Bee class, and the HTTP options params)

Comment thread src/chunk/cac.ts Outdated
Comment on lines +43 to +52
function withToSingleOwnerChunk(core: { data: Uint8Array; span: Span; payload: Bytes; address: Reference }): Chunk {
return {
data: core.data,
span: core.span,
payload: core.payload,
address: core.address,
toSingleOwnerChunk: (identifier, signer) =>
makeSingleOwnerChunk(core.address, core.span, core.payload, identifier, signer),
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add this method to CAC in the core, too? Then this function, and some others can be removed from Bee-JS and stay fully supplied from core.

Comment thread src/chunk/soc.ts Outdated
Comment on lines 20 to 22
function privateKeyToBigInt(signer: PrivateKey): bigint {
return uint256ToNumber(signer.toUint8Array(), 'BE')
}

@Cafe137 Cafe137 Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a method on PrivateKey

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
File Coverage Now Coverage Before Delta% Rating
Total 1847 / 2247 2320 / 2760 -1.86 🔴
bee.ts 68 / 70 69 / 71 -0.04 🔴
index.ts 28 / 28 15 / 15 0.00
version.ts 3 / 3 3 / 3 0.00
api/balance.ts 9 / 9 9 / 9 0.00
api/batches.ts 9 / 9 9 / 9 0.00
api/bytes.ts 22 / 25 23 / 26 -0.46 🔴
api/bzz.ts 30 / 31 31 / 32 -0.10 🔴
api/chequebook.ts 32 / 34 32 / 34 0.00
api/chunk.ts 15 / 15 15 / 15 0.00
api/connectivity.ts 24 / 32 24 / 32 0.00
api/consumed.ts 9 / 9 9 / 9 0.00
api/envelope.ts 8 / 8 7 / 7 0.00
api/feed.ts 20 / 22 21 / 23 -0.40 🔴
api/grantee.ts 18 / 18 18 / 18 0.00
api/pin.ts 16 / 16 16 / 16 0.00
api/pss.ts 5 / 5 5 / 5 0.00
api/rchash.ts 6 / 6 6 / 6 0.00
api/redistributionstate.ts 6 / 6 6 / 6 0.00
api/settlement.ts 9 / 9 9 / 9 0.00
api/soc.ts 11 / 11 11 / 11 0.00
api/stake.ts 13 / 19 13 / 19 0.00
api/stamp.ts 27 / 29 27 / 29 0.00
api/status.ts 27 / 27 27 / 27 0.00
api/stewardship.ts 8 / 8 8 / 8 0.00
api/tag.ts 15 / 16 15 / 16 0.00
api/transaction.ts 11 / 18 11 / 18 0.00
api/wallet.ts 12 / 12 12 / 12 0.00
chunk/soc.ts 33 / 34 58 / 59 -1.25 🔴
feed/identifier.ts 4 / 4 5 / 5 0.00
feed/index.ts 83 / 85 85 / 87 -0.05 🔴
feed/retrievable.ts 18 / 19 18 / 19 0.00
manifest/manifest.ts 54 / 69 238 / 253 -15.81 🔴
modules/balance.ts 11 / 11 11 / 11 0.00
modules/cheque.ts 13 / 14 13 / 14 0.00
modules/chequebook.ts 13 / 13 13 / 13 0.00
modules/chunk.ts 18 / 22 18 / 22 0.00
modules/collection.ts 25 / 28 25 / 28 0.00
modules/connectivity.ts 11 / 20 11 / 20 0.00
modules/data.ts 20 / 23 20 / 23 0.00
modules/feed.ts 26 / 33 26 / 33 0.00
modules/file.ts 26 / 28 26 / 28 0.00
modules/grantee.ts 16 / 16 16 / 16 0.00
modules/messaging.ts 78 / 92 80 / 94 -0.32 🔴
modules/pin.ts 15 / 15 15 / 15 0.00
modules/settlement.ts 7 / 7 7 / 7 0.00
modules/soc.ts 9 / 10 9 / 10 0.00
modules/stake.ts 12 / 16 12 / 16 0.00
modules/stamp.ts 48 / 54 48 / 54 0.00
modules/status.ts 11 / 17 11 / 17 0.00
modules/storage.ts 67 / 68 67 / 68 0.00
modules/tag.ts 14 / 17 14 / 17 0.00
modules/transaction.ts 8 / 13 8 / 13 0.00
modules/wallet.ts 12 / 12 12 / 12 0.00
types/debug.ts 8 / 12 8 / 12 0.00
types/index.ts 21 / 21 21 / 21 0.00
types/schema/balance.ts 7 / 7 7 / 7 0.00
types/schema/chequebook.ts 28 / 28 28 / 28 0.00
types/schema/connectivity.ts 15 / 15 15 / 15 0.00
types/schema/envelope.ts 7 / 7 7 / 7 0.00
types/schema/grantee.ts 6 / 6 6 / 6 0.00
types/schema/pinning.ts 2 / 2 2 / 2 0.00
types/schema/rchash.ts 2 / 2 2 / 2 0.00
types/schema/settlements.ts 10 / 10 10 / 10 0.00
types/schema/stake.ts 13 / 14 13 / 14 0.00
types/schema/stamps.ts 14 / 14 14 / 14 0.00
types/schema/states.ts 14 / 14 14 / 14 0.00
types/schema/status.ts 7 / 7 7 / 7 0.00
types/schema/stewardship.ts 2 / 2 2 / 2 0.00
types/schema/tag.ts 4 / 4 4 / 4 0.00
types/schema/transactions.ts 10 / 11 10 / 11 0.00
types/schema/upload.ts 4 / 4 4 / 4 0.00
utils/bad-ports.ts 1 / 1 1 / 1 0.00
utils/chunk-size.ts 9 / 9 9 / 9 0.00
utils/chunk-stream.browser.ts 0 / 74 0 / 71 0.00
utils/chunk-stream.ts 60 / 66 57 / 63 0.43 🟢
utils/collection.browser.ts 0 / 4 0 / 4 0.00
utils/collection.node.ts 29 / 33 29 / 33 0.00
utils/collection.ts 14 / 18 14 / 18 0.00
utils/constants.ts 7 / 7 7 / 7 0.00
utils/data.browser.ts 0 / 8 0 / 8 0.00
utils/data.ts 4 / 11 4 / 11 0.00
utils/duration.ts 20 / 22 20 / 22 0.00
utils/error.ts 13 / 13 13 / 13 0.00
utils/expose.ts 16 / 16 16 / 16 0.00
utils/file.ts 8 / 12 8 / 12 0.00
utils/headers.ts 68 / 77 68 / 77 0.00
utils/hex-schema.ts 2 / 3 3 / 3 -33.33 🔴
utils/http.ts 66 / 74 66 / 74 0.00
utils/mime.ts 1 / 1 1 / 1 0.00
utils/pss.ts 5 / 5 5 / 5 0.00
utils/resource-locator.ts 7 / 8 7 / 8 0.00
utils/schema.ts 23 / 27 23 / 27 0.00
utils/size.ts 12 / 14 12 / 14 0.00
utils/stamps.ts 26 / 32 55 / 78 10.74 🟢
utils/tar-uploader.browser.ts 0 / 11 0 / 11 0.00
utils/tar-uploader.ts 12 / 12 12 / 12 0.00
utils/tar-writer.browser.ts 0 / 8 0 / 8 0.00
utils/tar-writer.ts 13 / 14 13 / 14 0.00
utils/tar.browser.ts 0 / 73 0 / 73 0.00
utils/tar.ts 65 / 67 65 / 67 0.00
utils/tokens.ts 26 / 41 26 / 41 0.00
utils/type.ts 23 / 31 23 / 31 0.00
utils/url.ts 21 / 26 21 / 26 0.00
utils/workaround.ts 9 / 14 9 / 14 0.00

@slapec93
slapec93 requested review from Cafe137 and a lite review from Copilot August 7, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates bee-js to use swarm-core as the canonical implementation for core Swarm primitives (typed bytes, chunking, stamps, redundancy, and Mantaray/manifest internals), removing duplicated logic from bee-js and updating tests and imports accordingly.

Changes:

  • Replace many bee-js internal implementations (typed-bytes, CAC/BMT, redundancy tables, Stamper, parts of Mantaray) with swarm-core exports.
  • Update upload/chunking paths to use ChunkSplitter (and adjust browser/node chunk streaming accordingly).
  • Update unit/integration/regression tests to import primitives from swarm-core and to match updated canonical values/behaviors.

Reviewed changes

Copilot reviewed 102 out of 103 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/unit/utils.spec.ts Update redundancy overhead expectations to match swarm-core parity tables.
test/unit/topic-identifier.spec.ts Switch Identifier/Topic + hex conversion import to swarm-core.
test/unit/signature.spec.ts Switch PrivateKey import to swarm-core.
test/unit/reference.spec.ts Switch Reference import to swarm-core.
test/unit/manifest.spec.ts Switch hex conversion helper to swarm-core.
test/unit/feed-index.spec.ts Switch FeedIndex import to swarm-core.
test/unit/cid.spec.ts Switch Reference import to swarm-core.
test/unit/chunk-stream.browser.spec.ts Switch BatchId import to swarm-core.
test/unit/bytes.spec.ts Switch Bytes import to swarm-core.
test/regression/bytes-ctor.spec.ts Switch Bytes import to swarm-core.
test/regression/bee-2317.spec.ts Switch uint64 conversion to swarm-core.
test/integration/upload.spec.ts Use swarm-core chunking/crypto helpers instead of local implementations.
test/integration/stamper.spec.ts Use swarm-core Stamper + ChunkSplitter and updated error message.
test/integration/stamp.spec.ts Switch CAC creation to swarm-core.
test/integration/pss.spec.ts Switch Topic to swarm-core.
test/integration/manifest.spec.ts Switch PrivateKey/Topic to swarm-core.
test/integration/gsoc.spec.ts Switch Bytes to swarm-core.
test/integration/feed.ux.spec.ts Switch FeedIndex/PrivateKey to swarm-core.
test/integration/feed.spec.ts Switch FeedIndex/PrivateKey/Reference to swarm-core.
test/integration/download-ens.spec.ts Switch concatBytes to swarm-core.
test/integration/chunk.spec.ts Switch CAC creation to swarm-core.
test/integration/act.spec.ts Switch PublicKey to swarm-core.
src/utils/typed-bytes.ts Removed (replaced by swarm-core typed bytes).
src/utils/tar-uploader.ts Switch BatchId to swarm-core.
src/utils/tar-uploader.browser.ts Switch BatchId to swarm-core.
src/utils/stamps.ts Delegate stamp math/marshaling to swarm-core and re-export helpers.
src/utils/schema.ts Switch PublicKey/Reference schemas to swarm-core.
src/utils/resource-locator.ts Switch Reference to swarm-core.
src/utils/redundancy.ts Removed (replaced by swarm-core redundancy helpers).
src/utils/pss.ts Switch PeerAddress to swarm-core.
src/utils/headers.ts Switch typed primitives to swarm-core.
src/utils/expose.ts Re-export redundancy helpers from swarm-core.
src/utils/constants.ts Switch BatchId/Topic to swarm-core.
src/utils/cid.ts Removed (CID conversion moved to swarm-core).
src/utils/chunk-stream.ts Replace MerkleTree flow with swarm-core ChunkSplitter in node streaming.
src/utils/chunk-stream.browser.ts Replace MerkleTree flow with swarm-core ChunkSplitter in browser streaming.
src/utils/bytes.ts Removed (replaced by swarm-core Bytes).
src/types/schema/upload.ts Switch Reference to swarm-core.
src/types/schema/transactions.ts Switch TransactionId to swarm-core.
src/types/schema/states.ts Switch TransactionId to swarm-core.
src/types/schema/stamps.ts Switch BatchId/EthAddress to swarm-core.
src/types/schema/stake.ts Switch TransactionId to swarm-core.
src/types/schema/grantee.ts Switch PublicKey/Reference to swarm-core.
src/types/schema/envelope.ts Switch hex parsing helper to swarm-core.
src/types/schema/connectivity.ts Switch EthAddress/PeerAddress/PublicKey to swarm-core.
src/types/schema/chequebook.ts Switch EthAddress/TransactionId to swarm-core.
src/types/index.ts Source typed primitives + Envelope types from swarm-core.
src/types/debug.ts Switch debug typed primitives to swarm-core.
src/stamper/stamper.ts Removed (replaced by swarm-core Stamper).
src/modules/wallet.ts Switch typed primitives to swarm-core.
src/modules/transaction.ts Switch TransactionId to swarm-core.
src/modules/tag.ts Switch Reference to swarm-core.
src/modules/storage.ts Switch BatchId/TransactionId imports to swarm-core.
src/modules/stamp.ts Switch BatchId to swarm-core.
src/modules/stake.ts Switch TransactionId to swarm-core.
src/modules/soc.ts Switch EthAddress/PrivateKey to swarm-core.
src/modules/settlement.ts Switch PeerAddress to swarm-core.
src/modules/pin.ts Switch BatchId/Reference to swarm-core.
src/modules/messaging.ts Switch chunk/crypto/typed primitives to swarm-core.
src/modules/grantee.ts Switch typed primitives to swarm-core.
src/modules/file.ts Switch BatchId/Bytes/Reference to swarm-core.
src/modules/feed.ts Switch feed typed primitives to swarm-core.
src/modules/data.ts Switch BatchId/Bytes/Reference to swarm-core.
src/modules/context.ts Switch PrivateKey type to swarm-core.
src/modules/connectivity.ts Switch PeerAddress to swarm-core.
src/modules/collection.ts Switch BatchId to swarm-core.
src/modules/chunk.ts Switch chunk primitives (BatchId/Identifier/etc.) to swarm-core.
src/modules/chequebook.ts Switch TransactionId to swarm-core.
src/modules/cheque.ts Switch PeerAddress/TransactionId to swarm-core.
src/modules/balance.ts Switch PeerAddress to swarm-core.
src/manifest/manifest.ts Wrap swarm-core MantarayNode; keep bee-js networking/ACT logic.
src/index.ts Re-export core primitives from swarm-core; adjust global BeeJs typings.
src/feed/retrievable.ts Switch feed typed primitives to swarm-core.
src/feed/index.ts Switch chunk/feed primitives + byte ops to swarm-core.
src/feed/identifier.ts Switch hash/concat + typed primitives to swarm-core.
src/chunk/soc.ts Delegate SOC logic to swarm-core + wrap errors as BeeError.
src/chunk/cac.ts Removed (CAC implementation moved to swarm-core).
src/chunk/bmt.ts Removed (BMT implementation moved to swarm-core).
src/bee.ts Switch core chunk/bytes primitives used by Bee to swarm-core.
src/api/wallet.ts Switch typed primitives to swarm-core.
src/api/transaction.ts Switch TransactionId to swarm-core.
src/api/tag.ts Switch Reference to swarm-core.
src/api/stewardship.ts Switch BatchId/Reference to swarm-core.
src/api/stamp.ts Switch BatchId to swarm-core.
src/api/stake.ts Switch TransactionId to swarm-core.
src/api/soc.ts Switch SOC typed primitives to swarm-core.
src/api/settlement.ts Switch PeerAddress to swarm-core.
src/api/pss.ts Switch PSS typed primitives to swarm-core.
src/api/pin.ts Switch Reference to swarm-core.
src/api/grantee.ts Switch typed primitives to swarm-core.
src/api/feed.ts Switch feed typed primitives + Bytes to swarm-core.
src/api/envelope.ts Switch typed primitives to swarm-core and adjust envelope mapping.
src/api/consumed.ts Switch PeerAddress to swarm-core.
src/api/connectivity.ts Switch PeerAddress to swarm-core.
src/api/chunk.ts Switch BatchId/Reference to swarm-core.
src/api/chequebook.ts Switch PeerAddress/TransactionId to swarm-core.
src/api/bzz.ts Switch BatchId/Bytes/Reference to swarm-core.
src/api/bytes.ts Switch BatchId/Bytes/Reference to swarm-core.
src/api/batches.ts Switch BatchId to swarm-core.
src/api/balance.ts Switch PeerAddress to swarm-core.
package.json Add dependency alias swarm-core to npm:@upcoming/swarm-core@0.0.8.
package-lock.json Lock new dependency subtree for swarm-core (+ noble deps).
cheatsheet.ts Update examples to use swarm-core primitives + new module APIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
"debug": "^4.4.3",
"isomorphic-ws": "^5.0.0",
"semver": "^7.3.5",
"swarm-core": "npm:@upcoming/swarm-core@0.0.8",
Comment thread src/manifest/manifest.ts
Comment on lines +258 to 260
find(path: string | Uint8Array): CoreMantarayNode | null {
return this.core.find(path)
}
Comment on lines +51 to 55
try {
await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions)
onUploadProgress?.({ total, processed: ++processed })
} catch (err) {
if (signal?.aborted) {
Comment thread src/index.ts
Comment on lines 1 to +3
import { Bee } from './bee'
import { Stamper } from './stamper/stamper'

export { MerkleTree } from 'cafe-utility'
export type { Chunk } from './chunk/cac'
export {
@slapec93 slapec93 changed the title chore: use swarm core refactor!: use swarm core Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants