Skip to content

Conversation

@PastaPastaPasta
Copy link
Member

@PastaPastaPasta PastaPastaPasta commented Jan 13, 2026

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 Document constructor auto-generates entropy, but Document.fromObject(), Document.fromJSON(), and Document.fromBytes() do not. This creates confusion for SDK consumers who might expect consistent behavior across all document creation methods.

What was done?

Modified document_create in packages/wasm-sdk/src/state_transitions/document.rs to pass None to rs-sdk when entropy is not set on the Document, instead of throwing an error.

The rs-sdk PutDocument trait already handles optional entropy correctly - when None is passed, it:

  1. Generates new entropy using StdRng::from_entropy()
  2. Regenerates the document ID based on that 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 DocumentCreateOptions TypeScript interface comment in the same file to reflect that entropy is now optional.

How Has This Been Tested?

  • cargo check -p wasm-sdk passes
  • cargo fmt -p wasm-sdk applied

Breaking Changes

None. This change makes the API more lenient by accepting documents without entropy set.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

…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>
@github-actions github-actions bot added this to the v3.0.0 milestone Jan 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

Document 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

Cohort / File(s) Summary
Entropy handling and docs
packages/wasm-sdk/src/state_transitions/document.rs
TS documentation updated to mark entropy optional. document_create no longer errors for non-32-byte entropy: it accepts a provided 32-byte array or maps other values to None, passing Option<[u8; 32]> to the platform so entropy is auto-generated when absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nudge the bytes and sigh no more,
If thirty-two don't show, I hop to store —
The rs-sdk spins a secret song,
Creation marches swift and strong,
Optional chaos, neatly core. 🎲

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making entropy auto-generation optional for document creation in the wasm SDK, which directly aligns with the primary objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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>
@shumkov
Copy link
Collaborator

shumkov commented Jan 16, 2026

I think it's the responsibility of the Document to generate entropy, isn't it?
When you use new Document(), it does it for you already.

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