Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ jobs:
- packages/js-dash-sdk/**
- packages/wallet-lib/**
- packages/wasm-sdk/**
- packages/wasm-dpp2/**
- packages/js-evo-sdk/**
- packages/dapi/.env.example
- packages/rs-drive-abci/.env.local
- .github/actions/aws_ecr_login/**
Expand Down
7 changes: 6 additions & 1 deletion packages/wasm-dpp2/src/data_contract/document/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ impl DocumentWasm {
.map(|(k, v)| (Value::Text(k.clone()), v.clone()))
.collect(),
);
let js_value = serialization::platform_value_to_object(&properties_value)?;
// Identifier-typed properties surface as base58 strings — the
// form where-clauses accept back, so a proven join value can be
// used as a pagination cursor directly. Other binary properties
// stay Uint8Array.
let js_value =
serialization::platform_value_to_object_with_base58_identifiers(&properties_value)?;
Ok(js_value.into())
}

Expand Down
35 changes: 35 additions & 0 deletions packages/wasm-dpp2/src/serialization/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,41 @@ fn stringify_key(key: &platform_value::Value) -> platform_value::Value {
}
}

/// Serialize platform_value::Value to JsValue as a JS object like
/// [`platform_value_to_object`], but with `Value::Identifier` VALUES as
/// base58 strings (matching the `Identifier` JSON convention and the
/// base58 form query where-clauses accept). `Value::Bytes*` still become
/// Uint8Array. This is the document `properties` surface: every typed
/// decode path (binary document deserialization, index-key synthesis)
/// produces `Value::Identifier` for identifier-typed properties, so the
/// variant alone marks them — no document-type schema is needed here.
pub fn platform_value_to_object_with_base58_identifiers(
value: &platform_value::Value,
) -> WasmDppResult<JsValue> {
platform_value_to_object(&identifier_values_to_base58(value))
}

/// Recursively convert `Value::Identifier` values to base58 `Value::Text`.
/// Map keys are left alone — [`stringify_map_keys_for_object`] already
/// renders identifier keys as base58.
fn identifier_values_to_base58(value: &platform_value::Value) -> platform_value::Value {
use dpp::platform_value::Value;
use dpp::platform_value::string_encoding::{Encoding, encode};
match value {
Value::Identifier(bytes) => Value::Text(encode(bytes, Encoding::Base58)),
Value::Map(entries) => Value::Map(
entries
.iter()
.map(|(k, v)| (k.clone(), identifier_values_to_base58(v)))
.collect(),
),
Value::Array(items) => {
Value::Array(items.iter().map(identifier_values_to_base58).collect())
}
other => other.clone(),
}
}

/// Serialize platform_value::Value to JsValue as JSON-compatible (human-readable).
///
/// Converts Value::Identifier and Value::Bytes to base58/base64 strings for JSON compatibility.
Expand Down
38 changes: 38 additions & 0 deletions packages/wasm-dpp2/tests/unit/Document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,44 @@ describe('Document', () => {

expect(documentInstance.properties).to.deep.equal(document2);
});

it('should surface identifier-typed properties as base58 strings', () => {
const contractWithIdentifier = {
...dataContractValue,
documentSchemas: {
note: {
type: 'object',
properties: {
message: { type: 'string', position: 0 },
authorId: {
type: 'array',
byteArray: true,
contentMediaType: 'application/x.dash.dpp.identifier',
minItems: 32,
maxItems: 32,
position: 1,
},
},
additionalProperties: false,
},
},
};
const dataContract = wasm.DataContract.fromJSON(contractWithIdentifier, false);
const documentInstance = createDocument({
id,
properties: { message: 'hi', authorId: id },
dataContractId: dataContract.id.toBase58(),
});

const bytes = documentInstance.toBytes(dataContract, new PlatformVersion(1));
const restored = wasm.Document.fromBytes(bytes, dataContract, 'note', new PlatformVersion(1));

// The schema-typed decode yields Value::Identifier for authorId,
// and the properties getter surfaces it as base58 — the form
// where-clauses accept back as a cursor.
expect(restored.properties.authorId).to.equal(id);
expect(restored.properties.message).to.equal('hi');
});
});

describe('revision', () => {
Expand Down
Loading