diff --git a/packages/wasm-sdk/src/state_transitions/document.rs b/packages/wasm-sdk/src/state_transitions/document.rs index 44197daf1f9..253520f0aa4 100644 --- a/packages/wasm-sdk/src/state_transitions/document.rs +++ b/packages/wasm-sdk/src/state_transitions/document.rs @@ -51,7 +51,8 @@ export interface DocumentCreateOptions { /** * The document to create. * Use `new Document(...)` or `Document.fromJSON(...)` to construct it. - * Must include dataContractId, documentTypeName, ownerId, and entropy. + * Must include dataContractId, documentTypeName, and ownerId. + * Entropy is optional - if not set, it will be auto-generated. */ document: Document; @@ -108,19 +109,16 @@ impl WasmSdk { let contract_id: Identifier = document_wasm.get_data_contract_id().into(); let document_type_name = document_wasm.get_document_type_name(); - // Get entropy from document - let entropy = document_wasm.get_entropy().ok_or_else(|| { - WasmSdkError::invalid_argument("Document must have entropy set for creation") - })?; - - if entropy.len() != 32 { - return Err(WasmSdkError::invalid_argument( - "Document entropy must be exactly 32 bytes", - )); - } - - let mut entropy_array = [0u8; 32]; - entropy_array.copy_from_slice(&entropy); + // Get entropy from document if set, otherwise let rs-sdk generate it + let entropy = document_wasm.get_entropy().and_then(|e| { + if e.len() == 32 { + let mut arr = [0u8; 32]; + arr.copy_from_slice(&e); + Some(arr) + } else { + None + } + }); // Extract identity key from options let identity_key_wasm = @@ -144,7 +142,7 @@ impl WasmSdk { .put_to_platform_and_wait_for_response( self.inner_sdk(), document_type, - Some(entropy_array), + entropy, identity_key, None, // token_payment_info &signer,