@dashevo/dpns-contract 5.0.3 → 5.1.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/schema/v3/dpns-contract-documents.json +273 -0
- package/src/lib.rs +5 -3
- package/src/v1/mod.rs +4 -0
- package/src/v3/mod.rs +40 -0
- package/test/unit/dpnsContract.spec.js +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dpns-contract",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.1.0-dev.1",
|
|
4
4
|
"description": "A contract and helper scripts for DPNS DApp",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint .",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@dashevo/wasm-dpp": "5.0.
|
|
34
|
+
"@dashevo/wasm-dpp": "5.1.0-dev.1",
|
|
35
35
|
"chai": "^4.3.10",
|
|
36
36
|
"dirty-chai": "^2.0.1",
|
|
37
37
|
"eslint": "^9.18.0",
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
{
|
|
2
|
+
"domain": {
|
|
3
|
+
"documentsMutable": false,
|
|
4
|
+
"canBeDeleted": false,
|
|
5
|
+
"transferable": 1,
|
|
6
|
+
"tradeMode": 1,
|
|
7
|
+
"keepsTransferHistory": true,
|
|
8
|
+
"keepsPurchaseHistory": true,
|
|
9
|
+
"keepsPricingHistory": true,
|
|
10
|
+
"type": "object",
|
|
11
|
+
"indices": [
|
|
12
|
+
{
|
|
13
|
+
"name": "parentNameAndLabel",
|
|
14
|
+
"properties": [
|
|
15
|
+
{
|
|
16
|
+
"normalizedParentDomainName": "asc"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"normalizedLabel": "asc"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"unique": true,
|
|
23
|
+
"contested": {
|
|
24
|
+
"fieldMatches": [
|
|
25
|
+
{
|
|
26
|
+
"field": "normalizedLabel",
|
|
27
|
+
"regexPattern": "^[a-zA-Z01-]{3,19}$"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"resolution": 0,
|
|
31
|
+
"description": "Normalized labels of 3 to 19 a-z, 0, 1 or - characters go to a masternode vote"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "identityId",
|
|
36
|
+
"nullSearchable": false,
|
|
37
|
+
"properties": [
|
|
38
|
+
{
|
|
39
|
+
"records.identity": "asc"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"creatorRefersTo": {
|
|
45
|
+
"type": "deletableDocument",
|
|
46
|
+
"documentType": "preorder",
|
|
47
|
+
"findBy": {
|
|
48
|
+
"$ownerId": "$ownerId",
|
|
49
|
+
"nameHash": {
|
|
50
|
+
"function": "sys.hash.sha256d",
|
|
51
|
+
"params": [
|
|
52
|
+
"normalizedLabel",
|
|
53
|
+
{
|
|
54
|
+
"const": "."
|
|
55
|
+
},
|
|
56
|
+
"normalizedParentDomainName"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"where": {
|
|
61
|
+
"$ownerId": "$ownerId"
|
|
62
|
+
},
|
|
63
|
+
"constraints": {
|
|
64
|
+
"minimumAgeBlocks": 1,
|
|
65
|
+
"chooseFirst": {
|
|
66
|
+
"among": "nameHash",
|
|
67
|
+
"validWhen": {
|
|
68
|
+
"ownerNameHash": {
|
|
69
|
+
"function": "sys.hash.sha256d",
|
|
70
|
+
"params": [
|
|
71
|
+
"$ownerId",
|
|
72
|
+
"normalizedLabel",
|
|
73
|
+
{
|
|
74
|
+
"const": "."
|
|
75
|
+
},
|
|
76
|
+
"normalizedParentDomainName"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"by": [
|
|
81
|
+
"$createdAtBlockHeight"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"consume": true
|
|
86
|
+
},
|
|
87
|
+
"properties": {
|
|
88
|
+
"label": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
|
|
91
|
+
"minLength": 3,
|
|
92
|
+
"maxLength": 63,
|
|
93
|
+
"position": 0,
|
|
94
|
+
"description": "Label, e.g. 'Bob'"
|
|
95
|
+
},
|
|
96
|
+
"normalizedLabel": {
|
|
97
|
+
"type": "string",
|
|
98
|
+
"maxLength": 63,
|
|
99
|
+
"generatedFrom": {
|
|
100
|
+
"function": "sys.stringTransformations.homographSafeASCII",
|
|
101
|
+
"params": [
|
|
102
|
+
"label"
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"position": 1,
|
|
106
|
+
"description": "Generated: label lowercased, o to 0, i and l to 1, e.g. 'b0b'"
|
|
107
|
+
},
|
|
108
|
+
"parentDomainName": {
|
|
109
|
+
"type": "string",
|
|
110
|
+
"pattern": "^$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
|
|
111
|
+
"minLength": 0,
|
|
112
|
+
"maxLength": 63,
|
|
113
|
+
"position": 2,
|
|
114
|
+
"description": "Parent domain name, e.g. 'dash'"
|
|
115
|
+
},
|
|
116
|
+
"normalizedParentDomainName": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"maxLength": 63,
|
|
119
|
+
"generatedFrom": {
|
|
120
|
+
"function": "sys.stringTransformations.homographSafeASCII",
|
|
121
|
+
"params": [
|
|
122
|
+
"parentDomainName"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"position": 3,
|
|
126
|
+
"description": "Generated: parentDomainName normalized like normalizedLabel"
|
|
127
|
+
},
|
|
128
|
+
"preorderSalt": {
|
|
129
|
+
"type": "bytes",
|
|
130
|
+
"size": 32,
|
|
131
|
+
"position": 4,
|
|
132
|
+
"description": "Unused from v3; kept so domains written under v1 and v2 decode"
|
|
133
|
+
},
|
|
134
|
+
"records": {
|
|
135
|
+
"type": "object",
|
|
136
|
+
"properties": {
|
|
137
|
+
"identity": {
|
|
138
|
+
"type": "identifier",
|
|
139
|
+
"position": 1,
|
|
140
|
+
"description": "Identity the name resolves to; its owner's at creation"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"minProperties": 1,
|
|
144
|
+
"position": 5,
|
|
145
|
+
"additionalProperties": false
|
|
146
|
+
},
|
|
147
|
+
"subdomainRules": {
|
|
148
|
+
"type": "object",
|
|
149
|
+
"properties": {
|
|
150
|
+
"allowSubdomains": {
|
|
151
|
+
"type": "boolean",
|
|
152
|
+
"description": "Anyone may create subdomains (true) or only the owner (false)",
|
|
153
|
+
"position": 0
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"position": 6,
|
|
157
|
+
"description": "Subdomain rules",
|
|
158
|
+
"additionalProperties": false,
|
|
159
|
+
"required": [
|
|
160
|
+
"allowSubdomains"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"required": [
|
|
165
|
+
"$createdAt",
|
|
166
|
+
"$updatedAt",
|
|
167
|
+
"$transferredAt",
|
|
168
|
+
"label",
|
|
169
|
+
"normalizedLabel",
|
|
170
|
+
"normalizedParentDomainName",
|
|
171
|
+
"records",
|
|
172
|
+
"subdomainRules"
|
|
173
|
+
],
|
|
174
|
+
"transient": [
|
|
175
|
+
"preorderSalt"
|
|
176
|
+
],
|
|
177
|
+
"propertyConstraints": {
|
|
178
|
+
"recordsIdentityIsOwner": {
|
|
179
|
+
"ifThen": [
|
|
180
|
+
{
|
|
181
|
+
"equal": [
|
|
182
|
+
"$transferredAt",
|
|
183
|
+
"$createdAt"
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"equal": [
|
|
188
|
+
"records.identity",
|
|
189
|
+
"$ownerId"
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"additionalProperties": false
|
|
196
|
+
},
|
|
197
|
+
"preorder": {
|
|
198
|
+
"documentsMutable": false,
|
|
199
|
+
"canBeDeleted": true,
|
|
200
|
+
"ttl": 3600,
|
|
201
|
+
"type": "object",
|
|
202
|
+
"indices": [
|
|
203
|
+
{
|
|
204
|
+
"name": "ownerAndNameHash",
|
|
205
|
+
"properties": [
|
|
206
|
+
{
|
|
207
|
+
"$ownerId": "asc"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"nameHash": "asc"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"unique": true
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "nameHashAndHeight",
|
|
217
|
+
"properties": [
|
|
218
|
+
{
|
|
219
|
+
"nameHash": "asc"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"$createdAtBlockHeight": "asc"
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"name": "nameHash",
|
|
228
|
+
"properties": [
|
|
229
|
+
{
|
|
230
|
+
"nameHash": "asc"
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
"countable": "countable"
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"properties": {
|
|
237
|
+
"ownerNameHash": {
|
|
238
|
+
"type": "bytes",
|
|
239
|
+
"size": 32,
|
|
240
|
+
"position": 0,
|
|
241
|
+
"description": "sha256d of owner id, normalized label, '.' and normalized parent domain name"
|
|
242
|
+
},
|
|
243
|
+
"nameHash": {
|
|
244
|
+
"type": "bytes",
|
|
245
|
+
"size": 32,
|
|
246
|
+
"position": 1,
|
|
247
|
+
"description": "sha256d of normalized label, '.' and normalized parent domain name"
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"required": [
|
|
251
|
+
"$createdAt",
|
|
252
|
+
"$createdAtBlockHeight",
|
|
253
|
+
"ownerNameHash",
|
|
254
|
+
"nameHash"
|
|
255
|
+
],
|
|
256
|
+
"propertyConstraints": {
|
|
257
|
+
"atMostAThousandPerName": {
|
|
258
|
+
"lessThanOrEqual": [
|
|
259
|
+
{
|
|
260
|
+
"countOf": [
|
|
261
|
+
"preorder",
|
|
262
|
+
{
|
|
263
|
+
"nameHash": "nameHash"
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
},
|
|
267
|
+
1000
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"additionalProperties": false
|
|
272
|
+
}
|
|
273
|
+
}
|
package/src/lib.rs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
mod error;
|
|
2
2
|
pub mod v1;
|
|
3
3
|
pub mod v2;
|
|
4
|
+
pub mod v3;
|
|
4
5
|
|
|
5
6
|
pub use crate::error::Error;
|
|
6
7
|
use platform_value::{Identifier, IdentifierBytes32};
|
|
@@ -28,10 +29,10 @@ pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
|
|
|
28
29
|
pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
|
|
29
30
|
pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> {
|
|
30
31
|
match platform_version.system_data_contracts.dpns {
|
|
31
|
-
1
|
|
32
|
+
1..=3 => Ok(None),
|
|
32
33
|
version => Err(Error::UnknownVersionMismatch {
|
|
33
34
|
method: "dpns_contract::load_definitions".to_string(),
|
|
34
|
-
known_versions: vec![1, 2],
|
|
35
|
+
known_versions: vec![1, 2, 3],
|
|
35
36
|
received: version,
|
|
36
37
|
}),
|
|
37
38
|
}
|
|
@@ -40,9 +41,10 @@ pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Valu
|
|
|
40
41
|
match platform_version.system_data_contracts.dpns {
|
|
41
42
|
1 => v1::load_documents_schemas(),
|
|
42
43
|
2 => v2::load_documents_schemas(),
|
|
44
|
+
3 => v3::load_documents_schemas(),
|
|
43
45
|
version => Err(Error::UnknownVersionMismatch {
|
|
44
46
|
method: "dpns_contract::load_documents_schemas".to_string(),
|
|
45
|
-
known_versions: vec![1, 2],
|
|
47
|
+
known_versions: vec![1, 2, 3],
|
|
46
48
|
received: version,
|
|
47
49
|
}),
|
|
48
50
|
}
|
package/src/v1/mod.rs
CHANGED
package/src/v3/mod.rs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
use crate::Error;
|
|
2
|
+
use serde_json::Value;
|
|
3
|
+
|
|
4
|
+
/// The names v3 adds; every other name is v1's ([`crate::v1::document_types`]).
|
|
5
|
+
pub mod document_types {
|
|
6
|
+
pub mod preorder {
|
|
7
|
+
pub mod properties {
|
|
8
|
+
/// The double SHA-256 of the owner's id, the normalized label, "." and the
|
|
9
|
+
/// normalized parent domain name: a preorder holding it counts (`validWhen`).
|
|
10
|
+
pub const OWNER_NAME_HASH: &str = "ownerNameHash";
|
|
11
|
+
/// The same hash without the owner's id, shared by every preorder of a name,
|
|
12
|
+
/// which the domain's `creatorRefersTo` finds.
|
|
13
|
+
pub const NAME_HASH: &str = "nameHash";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// The document type names are unchanged from v1 (see [`crate::v1::document_types`]),
|
|
19
|
+
/// and so are every `domain` property's position and the transient list, so domains
|
|
20
|
+
/// written under v1 or v2 decode unchanged: `preorderSalt` stays declared, transient
|
|
21
|
+
/// and no longer required, but nothing reads it. v3 replaces most of the `domain`
|
|
22
|
+
/// create data trigger with schema keywords: `normalizedLabel` and
|
|
23
|
+
/// `normalizedParentDomainName` are generated from their counterparts
|
|
24
|
+
/// (`generatedFrom`), `creatorRefersTo` finds the creator's own preorder of the name
|
|
25
|
+
/// from an earlier block and deletes it (a `findBy` over the creator and the double
|
|
26
|
+
/// SHA-256 of the normalized label, "." and the normalized parent, with
|
|
27
|
+
/// `minimumAgeBlocks` and `consume`, which needs the preorder to record
|
|
28
|
+
/// `$createdAtBlockHeight`), and refuses it while another identity holds a valid
|
|
29
|
+
/// preorder of the name from an earlier block (`chooseFirst` by creation height, a
|
|
30
|
+
/// preorder counting when it holds the same hash with its owner's id first), and the
|
|
31
|
+
/// `recordsIdentityIsOwner` rule holds a new domain's identity record to its owner. A
|
|
32
|
+
/// preorder holds both hashes (`nameHash`, unique per owner and indexed with the
|
|
33
|
+
/// creation height, and `ownerNameHash`) and lives an hour (`ttl`). The protocol
|
|
34
|
+
/// upgrade deletes the v2 preorders and rebuilds the type. Domains can no longer be
|
|
35
|
+
/// deleted (`canBeDeleted: false`).
|
|
36
|
+
/// The parent domain checks stay in the create trigger.
|
|
37
|
+
pub fn load_documents_schemas() -> Result<Value, Error> {
|
|
38
|
+
serde_json::from_str(include_str!("../../schema/v3/dpns-contract-documents.json"))
|
|
39
|
+
.map_err(Error::InvalidSchemaJson)
|
|
40
|
+
}
|
|
@@ -217,11 +217,11 @@ describe('DPNS Contract', () => {
|
|
|
217
217
|
|
|
218
218
|
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
219
219
|
const validationResult = document.validate(dpp.protocolVersion);
|
|
220
|
-
const error = expectJsonSchemaError(validationResult
|
|
220
|
+
const error = expectJsonSchemaError(validationResult);
|
|
221
221
|
|
|
222
222
|
expect(error.keyword)
|
|
223
223
|
.to
|
|
224
|
-
.equal('
|
|
224
|
+
.equal('maxLength');
|
|
225
225
|
expect(error.instancePath)
|
|
226
226
|
.to
|
|
227
227
|
.equal('/label');
|
|
@@ -264,11 +264,11 @@ describe('DPNS Contract', () => {
|
|
|
264
264
|
|
|
265
265
|
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
266
266
|
const validationResult = document.validate(dpp.protocolVersion);
|
|
267
|
-
const error = expectJsonSchemaError(validationResult
|
|
267
|
+
const error = expectJsonSchemaError(validationResult);
|
|
268
268
|
|
|
269
269
|
expect(error.keyword)
|
|
270
270
|
.to
|
|
271
|
-
.equal('
|
|
271
|
+
.equal('maxLength');
|
|
272
272
|
expect(error.instancePath)
|
|
273
273
|
.to
|
|
274
274
|
.equal('/normalizedLabel');
|
|
@@ -291,16 +291,16 @@ describe('DPNS Contract', () => {
|
|
|
291
291
|
.equal('normalizedParentDomainName');
|
|
292
292
|
});
|
|
293
293
|
|
|
294
|
-
it('should be less than
|
|
295
|
-
rawDomainDocument.normalizedParentDomainName = 'a'.repeat(
|
|
294
|
+
it('should be less than 63 chars', async () => {
|
|
295
|
+
rawDomainDocument.normalizedParentDomainName = 'a'.repeat(64);
|
|
296
296
|
|
|
297
297
|
const document = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
298
298
|
const validationResult = document.validate(dpp.protocolVersion);
|
|
299
|
-
const error = expectJsonSchemaError(validationResult
|
|
299
|
+
const error = expectJsonSchemaError(validationResult);
|
|
300
300
|
|
|
301
301
|
expect(error.keyword)
|
|
302
302
|
.to
|
|
303
|
-
.equal('
|
|
303
|
+
.equal('maxLength');
|
|
304
304
|
expect(error.instancePath)
|
|
305
305
|
.to
|
|
306
306
|
.equal('/normalizedParentDomainName');
|