Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions packages/wasm-sdk/src/state_transitions/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 =
Expand All @@ -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,
Expand Down
Loading