feat(sdk): typed arrays in the Swift SDK and both mobile example apps (PV14) - #4926
Conversation
The contract parser no longer refuses a typed array (an array property declared by an items schema); it persists it as an ordinary array property. DocumentTypedArray reads the element kind, bounds and enum off the stored schemaJSON, so no SwiftData field or schema version is added, and converts form text into JSON values of the element's own kind. The example app's document form edits a typed array one row per element and refuses an invalid list before broadcast, since a refused transition is still paid for. The state-transition builder now encodes its document fields through the same conversion, which also stops the Objective-C exception it raised on identifier and byte array values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lace forms (PV14) The create and replace forms sent every element of a non-byte array as a string split on commas, which consensus refuses for integer, number and boolean elements and which breaks strings containing a comma. A typed array now gets one row per element with an input suited to its kind, and is sent as a JSON array of that kind; an invalid element, count or repeat is refused on the form. The replace form seeds the rows from the stored document, showing byte array elements as hex because the Rust sanitizer tries hex before base64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 32 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (15)
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. Comment |
|
🕓 Review not started yet because the new head is waiting for the 30-minute push debounce.
Commit 73d3543. Normal review starts when eligible; priority review starts as soon as a slot is available. |
Issue being fixed or feature implemented
Protocol version 14 adds typed scalar arrays to document schemas (#4922, #4923, #4924): an array property declared by an
itemsschema instead ofbyteArray: true. The mobile clients did not support them:No Rust change is needed. The wallet's schema sanitizer (
DocumentType::sanitize_document_properties) already walks into typed array elements: it turns base58 or hex strings into identifiers, hex or base64 strings into bytes, and narrows JSON integers to the element width. It never parses a number or a boolean out of a string, so the clients have to send each element as a JSON value of its own kind.What was done?
The examples use this property:
Swift SDK
DataContractParserpersists a typed array as an ordinaryarrayproperty. TheParseErrorenum fix(dpp)!: typed array review fixes: hyphenated list paths, element constraints, untrusted lists, Swift refusal #4924 added is removed; it was never released.New
DocumentTypedArray(mirrors wasm-dpp2'sDocumentTypedArrayProperty): path, element kind (integer,number,boolean,string,byteArray,identifierwith their bounds andenum),minItems,maxItems,uniqueItems.PersistentDocumentType.typedArraysandtypedArray(named:)derive it from the storedschemaJSON, likeimmutabilitydoes, so no SwiftData field or schema version is added. Nested typed arrays are reported by dotted path (team.leads).DocumentTypedArray.values(fromInputs:)/jsonArray(fromInputs:)convert the form rows. They check the count againstminItems/maxItems, then each row, then repeats whenuniqueItemsis set, and name the first failure (scores[1]: "x" is not a whole number.).Swift example app
The document form edits a typed array one row per element: a picker when the items declare an
enum, a toggle for booleans, number fields for integers and numbers, base58 text for identifiers, hex text for byte arrays.An invalid list is refused before broadcast, because a refused transition is still paid for.
The state-transition builder (
TransitionDetailView) now encodes its document fields through the same conversion. Before, it serialized them withtry? JSONSerialization.data(...), which raises an Objective-C exception (not caught bytry?) on theDatavalue an identifier or byte array field holds. On a conversion failure its submit is disabled and the reason is shown under the fields.propertiesJSONalso refuses a non-finite number (nantyped into a number field) instead of crashing.The type details and storage record views show a typed array's element kind and bounds.
Kotlin example app (the Kotlin SDK keeps no document-type model, so this is app-only, like #4820)
TypedArrays.kt: the same model read off the schema JSON, the per-element conversion, the whole-list check, and replace seeding.The create and replace forms get the row editor; the type details screen shows the element kind and bounds.
The replace form seeds one row per stored element. Byte array elements arrive as base64 and are shown as hex: the sanitizer tries hex before base64, so sending base64 made only of hex digits back would decode to different bytes.
Emptying a seeded optional list removes it; a required list is sent even when empty, so
minItemsis judged on the form.How Has This Been Tested?
xcodebuild test -scheme SwiftDashSDKon an iPhone 17 simulator, run against a freshly built release xcframework, 7 suites: 87 tests, 0 failures. That covers the newDataContractParserTypedArrayTests(12) andDocumentTypedArrayElementInputTests(34), plus the otherDataContractParser*TestsandDocumentTypeImmutabilityTests, which share the parser../gradlew :app:compileDebugKotlin :app:testDebugUnitTest: 31 suites, 219 tests, 0 failures, including the newTypedArraysTest(9).Known limitation, not changed here: the Swift state-transition builder's replace calls
dash_sdk_document_set_properties(rs-sdk-ffi), which does not run the schema sanitizer. That path still cannot send identifier or byte array values, top-level or inside a typed array; it now gets strings instead of crashing. The builder's create path and both apps' main create and replace forms do sanitize.Breaking Changes
None.
DataContractParser.ParseErrorwas added by #4924 on v4.2-dev and never released.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code