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..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 @@ -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..05e1024a526 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_JSON_V0: Value = serde_json::from_str::(include_str!( "../../../schema/meta_schemas/document/v0/document-meta.json" )) .unwrap(); + static ref TOKEN_META_JSON_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) @@ -85,8 +89,7 @@ lazy_static! { .compile(&DRAFT202012) .expect("Invalid data contract schema"); - - // Compiled version of data contract meta schema + // Compiled version of document meta schema pub static ref DOCUMENT_META_SCHEMA_V0: JSONSchema = JSONSchema::options() .with_keyword( "byteArray", @@ -137,6 +140,60 @@ lazy_static! { DRAFT202012.clone(), ) .to_owned() - .compile(&DATA_CONTRACT_V0) + .compile(&DOCUMENT_META_JSON_V0) + .expect("Invalid data contract schema"); + + // Compiled version of token meta schema + pub static ref TOKEN_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(&TOKEN_META_JSON_V0) .expect("Invalid data contract schema"); }