feat(wasm-sdk): auto-generate entropy for document creation when not provided#2988
feat(wasm-sdk): auto-generate entropy for document creation when not provided#2988PastaPastaPasta wants to merge 2 commits intov3.0-devfrom
Conversation
…provided Previously, documentCreate() would throw an error if the Document didn't have entropy set. This was a breaking change for SDKs that create documents via fromObject(), fromJSON(), or fromBytes() which don't auto-generate entropy. Now entropy is auto-generated at the wasm-sdk level when not provided, making it truly optional while maintaining backward compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughDocument creation now treats entropy as optional: if a 32-byte entropy is provided it is used; otherwise entropy is omitted and auto-generated by the downstream rs-sdk/platform call. Erroring on non-32-byte entropy was removed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Instead of generating entropy in wasm-sdk, pass None to rs-sdk when entropy is not set. This lets rs-sdk handle both entropy generation and document ID regeneration correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
I think it's the responsibility of the Document to generate entropy, isn't it? |
Issue being fixed or feature implemented
When creating documents via
sdk.documentCreate(), the SDK threw an error if the Document didn't have entropy set: "Document must have entropy set for creation".While entropy has always been required for document creation, there's an inconsistency in the Document API: the
Documentconstructor auto-generates entropy, butDocument.fromObject(),Document.fromJSON(), andDocument.fromBytes()do not. This creates confusion for SDK consumers who might expect consistent behavior across all document creation methods.What was done?
Modified
document_createinpackages/wasm-sdk/src/state_transitions/document.rsto passNoneto rs-sdk when entropy is not set on the Document, instead of throwing an error.The rs-sdk
PutDocumenttrait already handles optional entropy correctly - whenNoneis passed, it:StdRng::from_entropy()This delegates entropy handling to the lowest level (rs-sdk) where it's already properly implemented, making entropy effectively optional at all higher layers.
Also updated the
DocumentCreateOptionsTypeScript interface comment in the same file to reflect that entropy is now optional.How Has This Been Tested?
cargo check -p wasm-sdkpassescargo fmt -p wasm-sdkappliedBreaking Changes
None. This change makes the API more lenient by accepting documents without entropy set.
Checklist: