@dashevo/dpns-contract 5.0.3 → 5.1.0-dev.2

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/README.md CHANGED
@@ -9,6 +9,7 @@ JSON Contracts for Dash Platform Name Service
9
9
 
10
10
  - [Install](#install)
11
11
  - [Usage](#usage)
12
+ - [Giving up a name](#giving-up-a-name)
12
13
  - [Contributing](#contributing)
13
14
  - [License](#license)
14
15
 
@@ -24,6 +25,15 @@ npm install @dashevo/dpns-contract
24
25
  # TODO ...
25
26
  ```
26
27
 
28
+ ## Giving up a name
29
+
30
+ From contract v3 (protocol version 15) the identity holding a name can throw it away, in one of two ways:
31
+
32
+ - **Delete** the `domain` document. The name is free again and anybody may register it. A contested name (a normalized label of 3 to 19 `a-z`, `0`, `1` or `-` characters, awarded by a masternode vote) can not be deleted.
33
+ - **Tombstone** it: create a `tombstone` document holding the name's `normalizedLabel` and `normalizedParentDomainName`. The create deletes the creator's own `domain` of that name, and nobody can register the name while the tombstone exists. Any name can be tombstoned, a contested one included.
34
+
35
+ Nobody can replace, delete or transfer a tombstone, the identity that created it included. A tombstoned name may later be brought back and redistributed through a direct or indirect will of the DAO.
36
+
27
37
  ## Contributing
28
38
 
29
39
  Feel free to dive in! [Open an issue](https://github.com/dashpay/platform/issues/new/choose) or submit PRs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dpns-contract",
3
- "version": "5.0.3",
3
+ "version": "5.1.0-dev.2",
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.3",
34
+ "@dashevo/wasm-dpp": "5.1.0-dev.2",
35
35
  "chai": "^4.3.10",
36
36
  "dirty-chai": "^2.0.1",
37
37
  "eslint": "^9.18.0",
@@ -0,0 +1,341 @@
1
+ {
2
+ "domain": {
3
+ "documentsMutable": false,
4
+ "canBeDeleted": true,
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
+ "nameIsNotTombstoned": {
179
+ "equal": [
180
+ {
181
+ "countOf": [
182
+ "tombstone",
183
+ {
184
+ "normalizedParentDomainName": "normalizedParentDomainName",
185
+ "normalizedLabel": "normalizedLabel"
186
+ }
187
+ ]
188
+ },
189
+ 0
190
+ ]
191
+ },
192
+ "recordsIdentityIsOwner": {
193
+ "ifThen": [
194
+ {
195
+ "equal": [
196
+ "$transferredAt",
197
+ "$createdAt"
198
+ ]
199
+ },
200
+ {
201
+ "equal": [
202
+ "records.identity",
203
+ "$ownerId"
204
+ ]
205
+ }
206
+ ]
207
+ }
208
+ },
209
+ "additionalProperties": false
210
+ },
211
+ "preorder": {
212
+ "documentsMutable": false,
213
+ "canBeDeleted": true,
214
+ "ttl": 3600,
215
+ "type": "object",
216
+ "indices": [
217
+ {
218
+ "name": "ownerAndNameHash",
219
+ "properties": [
220
+ {
221
+ "$ownerId": "asc"
222
+ },
223
+ {
224
+ "nameHash": "asc"
225
+ }
226
+ ],
227
+ "unique": true
228
+ },
229
+ {
230
+ "name": "nameHashAndHeight",
231
+ "properties": [
232
+ {
233
+ "nameHash": "asc"
234
+ },
235
+ {
236
+ "$createdAtBlockHeight": "asc"
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ "name": "nameHash",
242
+ "properties": [
243
+ {
244
+ "nameHash": "asc"
245
+ }
246
+ ],
247
+ "countable": "countable"
248
+ }
249
+ ],
250
+ "properties": {
251
+ "ownerNameHash": {
252
+ "type": "bytes",
253
+ "size": 32,
254
+ "position": 0,
255
+ "description": "sha256d of owner id, normalized label, '.' and normalized parent domain name"
256
+ },
257
+ "nameHash": {
258
+ "type": "bytes",
259
+ "size": 32,
260
+ "position": 1,
261
+ "description": "sha256d of normalized label, '.' and normalized parent domain name"
262
+ }
263
+ },
264
+ "required": [
265
+ "$createdAt",
266
+ "$createdAtBlockHeight",
267
+ "ownerNameHash",
268
+ "nameHash"
269
+ ],
270
+ "propertyConstraints": {
271
+ "atMostAThousandPerName": {
272
+ "lessThanOrEqual": [
273
+ {
274
+ "countOf": [
275
+ "preorder",
276
+ {
277
+ "nameHash": "nameHash"
278
+ }
279
+ ]
280
+ },
281
+ 1000
282
+ ]
283
+ }
284
+ },
285
+ "additionalProperties": false
286
+ },
287
+ "tombstone": {
288
+ "description": "A name its owner gave up for good: creating one deletes the owner's domain of that name, and nobody can register the name while the tombstone exists. Nobody can delete or change a tombstone. A tombstoned name may later be brought back and redistributed through a direct or indirect will of the DAO",
289
+ "documentsMutable": false,
290
+ "canBeDeleted": false,
291
+ "transferable": 0,
292
+ "tradeMode": 0,
293
+ "type": "object",
294
+ "indices": [
295
+ {
296
+ "name": "parentNameAndLabel",
297
+ "properties": [
298
+ {
299
+ "normalizedParentDomainName": "asc"
300
+ },
301
+ {
302
+ "normalizedLabel": "asc"
303
+ }
304
+ ],
305
+ "countable": "countable"
306
+ }
307
+ ],
308
+ "properties": {
309
+ "normalizedLabel": {
310
+ "type": "string",
311
+ "maxLength": 63,
312
+ "refersTo": {
313
+ "type": "deletableDocument",
314
+ "documentType": "domain",
315
+ "findBy": {
316
+ "normalizedParentDomainName": "normalizedParentDomainName",
317
+ "normalizedLabel": "."
318
+ },
319
+ "where": {
320
+ "$ownerId": "$ownerId"
321
+ },
322
+ "consume": true
323
+ },
324
+ "position": 0,
325
+ "description": "Normalized label of the tombstoned name, e.g. 'b0b': the creator's own domain of that name, which the create deletes"
326
+ },
327
+ "normalizedParentDomainName": {
328
+ "type": "string",
329
+ "maxLength": 63,
330
+ "position": 1,
331
+ "description": "Normalized parent domain name of the tombstoned name, e.g. 'dash'"
332
+ }
333
+ },
334
+ "required": [
335
+ "$createdAt",
336
+ "normalizedLabel",
337
+ "normalizedParentDomainName"
338
+ ],
339
+ "additionalProperties": false
340
+ }
341
+ }
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 | 2 => Ok(None),
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
@@ -18,6 +18,10 @@ pub mod document_types {
18
18
  pub const DASH_ALIAS_IDENTITY_ID: &str = "dashAliasIdentityId";
19
19
  }
20
20
  }
21
+
22
+ pub mod preorder {
23
+ pub const NAME: &str = "preorder";
24
+ }
21
25
  }
22
26
 
23
27
  pub fn load_documents_schemas() -> Result<Value, Error> {
package/src/v3/mod.rs ADDED
@@ -0,0 +1,69 @@
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 tombstone {
7
+ /// A name its owner gave up for good.
8
+ pub const NAME: &str = "tombstone";
9
+
10
+ pub mod properties {
11
+ /// The normalized label of the tombstoned name, which finds the creator's own
12
+ /// `domain` of that name: the create deletes it.
13
+ pub const NORMALIZED_LABEL: &str = "normalizedLabel";
14
+ /// The normalized parent domain name of the tombstoned name.
15
+ pub const NORMALIZED_PARENT_DOMAIN_NAME: &str = "normalizedParentDomainName";
16
+ }
17
+ }
18
+
19
+ pub mod preorder {
20
+ pub mod properties {
21
+ /// The double SHA-256 of the owner's id, the normalized label, "." and the
22
+ /// normalized parent domain name: a preorder holding it counts (`validWhen`).
23
+ pub const OWNER_NAME_HASH: &str = "ownerNameHash";
24
+ /// The same hash without the owner's id, shared by every preorder of a name,
25
+ /// which the domain's `creatorRefersTo` finds.
26
+ pub const NAME_HASH: &str = "nameHash";
27
+ }
28
+ }
29
+ }
30
+
31
+ /// The document type names are unchanged from v1 (see [`crate::v1::document_types`]),
32
+ /// and so are every `domain` property's position and the transient list, so domains
33
+ /// written under v1 or v2 decode unchanged: `preorderSalt` stays declared, transient
34
+ /// and no longer required, but nothing reads it. v3 replaces most of the `domain`
35
+ /// create data trigger with schema keywords: `normalizedLabel` and
36
+ /// `normalizedParentDomainName` are generated from their counterparts
37
+ /// (`generatedFrom`), `creatorRefersTo` finds the creator's own preorder of the name
38
+ /// from an earlier block and deletes it (a `findBy` over the creator and the double
39
+ /// SHA-256 of the normalized label, "." and the normalized parent, with
40
+ /// `minimumAgeBlocks` and `consume`, which needs the preorder to record
41
+ /// `$createdAtBlockHeight`), and refuses it while another identity holds a valid
42
+ /// preorder of the name from an earlier block (`chooseFirst` by creation height, a
43
+ /// preorder counting when it holds the same hash with its owner's id first), unless the
44
+ /// create opens or joins the name's contest, which the masternode vote decides (held to the
45
+ /// order, an identity holding preorders of a name easy to guess older than a rival's could
46
+ /// delay the rival's reveal; each contender still reveals its own preorder, a block old at
47
+ /// least), and the
48
+ /// `recordsIdentityIsOwner` rule holds a new domain's identity record to its owner. A
49
+ /// preorder holds both hashes (`nameHash`, unique per owner and indexed with the
50
+ /// creation height, and `ownerNameHash`) and lives an hour (`ttl`). The protocol
51
+ /// upgrade deletes the v2 preorders and rebuilds the type.
52
+ /// The parent domain checks stay in the create trigger.
53
+ ///
54
+ /// A name's owner can give the name up, two ways. A delete of the `domain` frees the
55
+ /// name: anybody may register it again (`canBeDeleted: true`; the delete trigger refuses
56
+ /// a contested name, which a masternode vote awarded and which is never contested
57
+ /// again). A `tombstone` create deletes the creator's own `domain` of that name with it
58
+ /// (its `normalizedLabel` carries a `refersTo` with `consume`, found through the domain's
59
+ /// unique index and held to the creator's own by the `where` entry) and keeps the name
60
+ /// from being registered while the tombstone exists: the `domain` rule
61
+ /// `nameIsNotTombstoned` counts the tombstones of the name through the tombstone's
62
+ /// countable index and refuses a create, one opening a contest included, unless there is
63
+ /// none. Any name can be tombstoned, a contested one too. A tombstone can not be
64
+ /// replaced, deleted or transferred; the type's description says a tombstoned name may
65
+ /// later be brought back and redistributed through a direct or indirect will of the DAO.
66
+ pub fn load_documents_schemas() -> Result<Value, Error> {
67
+ serde_json::from_str(include_str!("../../schema/v3/dpns-contract-documents.json"))
68
+ .map_err(Error::InvalidSchemaJson)
69
+ }
@@ -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, 2);
220
+ const error = expectJsonSchemaError(validationResult);
221
221
 
222
222
  expect(error.keyword)
223
223
  .to
224
- .equal('pattern');
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, 2);
267
+ const error = expectJsonSchemaError(validationResult);
268
268
 
269
269
  expect(error.keyword)
270
270
  .to
271
- .equal('pattern');
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 190 chars', async () => {
295
- rawDomainDocument.normalizedParentDomainName = 'a'.repeat(191);
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, 2);
299
+ const error = expectJsonSchemaError(validationResult);
300
300
 
301
301
  expect(error.keyword)
302
302
  .to
303
- .equal('pattern');
303
+ .equal('maxLength');
304
304
  expect(error.instancePath)
305
305
  .to
306
306
  .equal('/normalizedParentDomainName');