From ba5db6a56a533152aab9149997cc48c2ac05796a Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Thu, 5 Dec 2024 18:29:56 +0700 Subject: [PATCH 1/3] feat(dpp): token meta schema --- .../meta_schemas/token/v0/token-meta.json | 106 ++++++++++++++++++ .../src/validation/meta_validators/mod.rs | 10 +- 2 files changed, 113 insertions(+), 3 deletions(-) diff --git a/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json b/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json index e69de29bb2d..ad038f5d779 100644 --- a/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json +++ b/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json @@ -0,0 +1,106 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json", + "type": "object", + "$defs": { + "localization": { + "type": "string", + "pattern": "^[\\p{L}\\p{N}]*$", + "minLength": 1, + "maxLength": 64, + "$comment": "Allow only alphanumeric characters" + } + }, + "properties": { + "shouldCapitalize": { + "type": "boolean", + "description": "TODO" + }, + "localizations": { + "type": "object", + "description": "TODO", + "additionalProperties": { + "type": "object", + "properties": { + "singular": { + "$ref": "#/$defs/localization" + }, + "plural": { + "$ref": "#/$defs/localization" + } + }, + "required": ["singular", "plural"], + "additionalProperties": false + }, + "maxProperties": 255, + "minProperties": 1 + }, + "maintainer": { + "type": "array", + "contentMediaType": "application/x.dash.dpp.identifier", + "byteArray": true, + "minItems": 32, + "maxItems": 32, + "description": "TODO" + }, + "initialSupply": { + "type": "integer", + "minimum": 0, + "description": "TODO" + }, + "decimals": { + "type": "integer", + "minimum": 0, + "description": "TODO" + }, + "maxSupply": { + "type": "integer", + "minimum": 1, + "description": "TODO" + }, + "permissions": { + "type": "object", + "properties": { + "maintainer": { + "type": "object", + "properties": { + "canMint": { + "type": "boolean" + }, + "canBurn": { + "type": "boolean" + } + }, + "additionalProperties": false, + "required": ["canBurn", "canMint"] + } + }, + "additionalProperties": false, + "minProperties": 1, + "description": "TODO" + }, + "description": { + "type": "string", + "maxLength": 1024, + "description": "Token description" + }, + "metadata": { + "type": "object", + "propertyNames": { + "type": "string", + "maxLength": 255, + }, + "additionalProperties": { + "type": "string", + "maxLength": 1024, + }, + "minProperties": 1, + "maxProperties": 255, + "description": "Token arbitrary metadata", + } + }, + "required": [ + "initialSupply", + "decimals" + ] +} diff --git a/packages/rs-dpp/src/validation/meta_validators/mod.rs b/packages/rs-dpp/src/validation/meta_validators/mod.rs index 8d1ce93b7e3..bdc87b28ed0 100644 --- a/packages/rs-dpp/src/validation/meta_validators/mod.rs +++ b/packages/rs-dpp/src/validation/meta_validators/mod.rs @@ -36,10 +36,14 @@ lazy_static! { "../../../schema/meta_schemas/draft2020-12/meta/content.json" )) .expect("Valid schema!"); - static ref DATA_CONTRACT_V0: Value = serde_json::from_str::(include_str!( + static ref DOCUMENT_META_V0: Value = serde_json::from_str::(include_str!( "../../../schema/meta_schemas/document/v0/document-meta.json" )) .unwrap(); + static ref TOKEN_META_V0: Value = serde_json::from_str::(include_str!( + "../../../schema/meta_schemas/token/v0/token-meta.json" + )) + .unwrap(); pub static ref DRAFT_202012_META_SCHEMA: JSONSchema = JSONSchema::options() .with_draft(Draft::Draft202012) @@ -87,7 +91,7 @@ lazy_static! { // Compiled version of data contract meta schema - pub static ref DOCUMENT_META_SCHEMA_V0: JSONSchema = JSONSchema::options() + pub static ref TOKEN_META_SCHEMA_V0: JSONSchema = JSONSchema::options() .with_keyword( "byteArray", |_, _, _| Ok(Box::new(ByteArrayKeyword)), @@ -137,6 +141,6 @@ lazy_static! { DRAFT202012.clone(), ) .to_owned() - .compile(&DATA_CONTRACT_V0) + .compile(&TOKEN_META_V0) .expect("Invalid data contract schema"); } From d98c15e343414fe837487ef23f0ef57f9242f2f4 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Thu, 5 Dec 2024 18:58:31 +0700 Subject: [PATCH 2/3] revert: document meta schema --- .../src/validation/meta_validators/mod.rs | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/packages/rs-dpp/src/validation/meta_validators/mod.rs b/packages/rs-dpp/src/validation/meta_validators/mod.rs index bdc87b28ed0..05e1024a526 100644 --- a/packages/rs-dpp/src/validation/meta_validators/mod.rs +++ b/packages/rs-dpp/src/validation/meta_validators/mod.rs @@ -36,11 +36,11 @@ lazy_static! { "../../../schema/meta_schemas/draft2020-12/meta/content.json" )) .expect("Valid schema!"); - static ref DOCUMENT_META_V0: Value = serde_json::from_str::(include_str!( + static ref DOCUMENT_META_JSON_V0: Value = serde_json::from_str::(include_str!( "../../../schema/meta_schemas/document/v0/document-meta.json" )) .unwrap(); - static ref TOKEN_META_V0: Value = serde_json::from_str::(include_str!( + static ref TOKEN_META_JSON_V0: Value = serde_json::from_str::(include_str!( "../../../schema/meta_schemas/token/v0/token-meta.json" )) .unwrap(); @@ -89,8 +89,61 @@ lazy_static! { .compile(&DRAFT202012) .expect("Invalid data contract schema"); + // Compiled version of document meta schema + pub static ref DOCUMENT_META_SCHEMA_V0: JSONSchema = JSONSchema::options() + .with_keyword( + "byteArray", + |_, _, _| Ok(Box::new(ByteArrayKeyword)), + ) + .with_patterns_regex_engine(RegexEngine::Regex(RegexOptions { + size_limit: Some(5 * (1 << 20)), + ..Default::default() + })) + .should_ignore_unknown_formats(false) + .should_validate_formats(true) + .with_patterns_regex_engine(RegexEngine::Regex(Default::default())) + .with_draft(Draft::Draft202012) + .with_document( + "https://json-schema.org/draft/2020-12/meta/applicator".to_string(), + DRAFT202012_APPLICATOR.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/core".to_string(), + DRAFT202012_CORE.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/applicator".to_string(), + DRAFT202012_APPLICATOR.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/unevaluated".to_string(), + DRAFT202012_UNEVALUATED.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/validation".to_string(), + DRAFT202012_VALIDATION.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/meta-data".to_string(), + DRAFT202012_META_DATA.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/format-annotation".to_string(), + DRAFT202012_FORMAT_ANNOTATION.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/meta/content".to_string(), + DRAFT202012_CONTENT.clone(), + ) + .with_document( + "https://json-schema.org/draft/2020-12/schema".to_string(), + DRAFT202012.clone(), + ) + .to_owned() + .compile(&DOCUMENT_META_JSON_V0) + .expect("Invalid data contract schema"); - // Compiled version of data contract meta schema + // Compiled version of token meta schema pub static ref TOKEN_META_SCHEMA_V0: JSONSchema = JSONSchema::options() .with_keyword( "byteArray", @@ -141,6 +194,6 @@ lazy_static! { DRAFT202012.clone(), ) .to_owned() - .compile(&TOKEN_META_V0) + .compile(&TOKEN_META_JSON_V0) .expect("Invalid data contract schema"); } From a963d361d6680137fcb4eecf6a1d0267bf11efae Mon Sep 17 00:00:00 2001 From: QuantumExplorer Date: Mon, 9 Dec 2024 13:50:19 +0300 Subject: [PATCH 3/3] Update packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../rs-dpp/schema/meta_schemas/token/v0/token-meta.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json b/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json index ad038f5d779..225e89a5f2b 100644 --- a/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json +++ b/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json @@ -88,15 +88,15 @@ "type": "object", "propertyNames": { "type": "string", - "maxLength": 255, + "maxLength": 255 }, "additionalProperties": { "type": "string", - "maxLength": 1024, + "maxLength": 1024 }, "minProperties": 1, "maxProperties": 255, - "description": "Token arbitrary metadata", + "description": "Token arbitrary metadata" } }, "required": [