refactor!: use swarm core - #1236
Conversation
# Conflicts: # src/bee.ts # src/chunk/soc.ts # src/utils/chunk-stream.browser.ts # src/utils/chunk-stream.ts # test/integration/stamper.spec.ts
| address: socAddress, | ||
| owner: ownerAddress, | ||
| try { | ||
| return coreUnmarshalSingleOwnerChunk(data instanceof Bytes ? data.toUint8Array() : data, address) |
There was a problem hiding this comment.
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.
| @@ -1,22 +1,64 @@ | |||
| import { Binary, MerkleTree, Optional, Uint8ArrayReader } from 'cafe-utility' | |||
| import { Optional } from 'cafe-utility' | |||
There was a problem hiding this comment.
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)
| 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), | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| function privateKeyToBigInt(signer: PrivateKey): bigint { | ||
| return uint256ToNumber(signer.toUint8Array(), 'BE') | ||
| } |
There was a problem hiding this comment.
Can be a method on PrivateKey
|
There was a problem hiding this comment.
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-coreexports. - Update upload/chunking paths to use
ChunkSplitter(and adjust browser/node chunk streaming accordingly). - Update unit/integration/regression tests to import primitives from
swarm-coreand 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.
| "debug": "^4.4.3", | ||
| "isomorphic-ws": "^5.0.0", | ||
| "semver": "^7.3.5", | ||
| "swarm-core": "npm:@upcoming/swarm-core@0.0.8", |
| find(path: string | Uint8Array): CoreMantarayNode | null { | ||
| return this.core.find(path) | ||
| } |
| try { | ||
| await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions) | ||
| onUploadProgress?.({ total, processed: ++processed }) | ||
| } catch (err) { | ||
| if (signal?.aborted) { |
| import { Bee } from './bee' | ||
| import { Stamper } from './stamper/stamper' | ||
|
|
||
| export { MerkleTree } from 'cafe-utility' | ||
| export type { Chunk } from './chunk/cac' | ||
| export { |
Before TODO:
@upcoming