feat(wasm-sdk): auto-generate entropy for document creation when not provided #2988
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.
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: