Bug: Proof.parse() works but client.addSpace() fails with CAR format UCAN #44
+100
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Report: Proof.parse() works but client.addSpace() fails with CAR format UCAN
📋 Summary
The
Proof.parse()function from@storacha/client/proofsuccessfully parses UCANs in CAR (Content Addressable Archive) format, but when the parsed proof is passed toclient.addSpace(proof), an internal error occurs attempting to parse it again as JWT.🔍 Problem Details
Expected Behavior
When a UCAN is generated with
storacha delegation create --base64, it returns a CAR file encoded in base64. TheProof.parse()function should be able to parse this format and return a delegation object that can be used directly withclient.addSpace().Current Behavior
Proof.parse(ucanBase64String)works correctly and returns a delegation objectclient.addSpace(proof)fails with error:"Expected JWT format: 3 dot-separated base64url-encoded values"Stack Trace
Reproduction Code
🔬 Technical Analysis
Relevant Source Code
The
Proof.parse()in@storacha/client/dist/proof.js:The
client.addSpace()internally calls:Problem Hypothesis
The
importSpaceFromDelegationmethod appears to be attempting to parse the proof again as JWT, when it actually already receives a parsed delegation object fromProof.parse(). This causes an error because the delegation object is not a JWT string.🛠️ Current Workaround
Currently, we are using
Proof.parse()correctly, but the error occurs inaddSpace(). There is no known workaround other than waiting for a fix in the Storacha client.📝 Environment Information
1.8.23v20.19.6darwin 25.1.0storacha delegation create <AGENT_DID> --can space/blob/add --can space/index/add --can filecoin/offer --can upload/add --base64🎯 Suggested Fix
The
importSpaceFromDelegationmethod should check if the received parameter is already a parsed delegation object before attempting to parse it again. If it's already an object, it should use it directly. If it's a string, then it should attempt to parse.📚 References
@storacha/[email protected]Reported by: Mellø (neomello)
Date: 2025-01-XX
Project: neo-flowoff-pwa