Skip to content

Commit

Permalink
fix: address dpns contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia committed Aug 24, 2024
1 parent 78044d7 commit b293048
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 40 deletions.
8 changes: 4 additions & 4 deletions DashSync/shared/Models/DAPI/DSPlatformDocumentsRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ + (instancetype)dpnsRequestForUsername:(NSString *)username inDomain:(NSString *

+ (instancetype)dpnsRequestForUserId:(NSData *)userId {
DSPlatformDocumentsRequest *platformDocumentsRequest = [[DSPlatformDocumentsRequest alloc] init];
platformDocumentsRequest.pathPredicate = [NSPredicate predicateWithFormat:@"records.dashUniqueIdentityId == %@", userId];
platformDocumentsRequest.pathPredicate = [NSPredicate predicateWithFormat:@"records.identity == %@", userId]; // why not path predicate and then predicate?
platformDocumentsRequest.startAt = nil;
platformDocumentsRequest.limit = 100;
platformDocumentsRequest.queryType = DSPlatformQueryType_RangeOverIndex;
Expand Down Expand Up @@ -115,7 +115,7 @@ + (instancetype)dashpayRequestForContactRequestsForSendingUserId:(NSData *)userI
platformDocumentsRequest.startAtIncluded = false;
platformDocumentsRequest.limit = 100;
platformDocumentsRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"$createdAt" ascending:YES]];
platformDocumentsRequest.queryType = DSPlatformQueryType_RangeOverValue;
platformDocumentsRequest.queryType = DSPlatformQueryType_RangeOverValue; // why not over index?
platformDocumentsRequest.type = DSPlatformDocumentType_Document;
platformDocumentsRequest.tableName = @"contactRequest";
platformDocumentsRequest.prove = DSPROVE_PLATFORM_SINDEXES;
Expand All @@ -131,7 +131,7 @@ + (instancetype)dashpayRequestForContactRequestsForRecipientUserId:(NSData *)use
platformDocumentsRequest.startAtIncluded = false;
platformDocumentsRequest.limit = 100;
platformDocumentsRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"$createdAt" ascending:YES]];
platformDocumentsRequest.queryType = DSPlatformQueryType_RangeOverValue;
platformDocumentsRequest.queryType = DSPlatformQueryType_RangeOverValue; // why not over index?
platformDocumentsRequest.type = DSPlatformDocumentType_Document;
platformDocumentsRequest.tableName = @"contactRequest";
platformDocumentsRequest.prove = DSPROVE_PLATFORM_SINDEXES;
Expand All @@ -140,7 +140,7 @@ + (instancetype)dashpayRequestForContactRequestsForRecipientUserId:(NSData *)use

+ (instancetype)dashpayRequestForContactRequestForSendingUserId:(NSData *)userId toRecipientUserId:(NSData *)toUserId {
DSPlatformDocumentsRequest *platformDocumentsRequest = [[DSPlatformDocumentsRequest alloc] init];
platformDocumentsRequest.pathPredicate = [NSPredicate predicateWithFormat:@"%K == %@ && toUserId == %@", @"$ownerId", userId, toUserId];
platformDocumentsRequest.pathPredicate = [NSPredicate predicateWithFormat:@"%K == %@ && toUserId == %@", @"$ownerId", userId, toUserId]; // why not path predicate and predicate?
platformDocumentsRequest.startAt = nil;
platformDocumentsRequest.limit = 100;
platformDocumentsRequest.type = DSPlatformDocumentType_Document;
Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/Models/Identity/DSBlockchainIdentity.m
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ - (NSString *)dashpayDomainName {
@"normalizedLabel": [username lowercaseString],
@"normalizedParentDomainName": domain,
@"preorderSalt": [self.usernameSalts objectForKey:usernameFullPath],
@"records": @{@"dashUniqueIdentityId": uint256_data(self.uniqueID)},
@"records": @{@"identity": uint256_data(self.uniqueID)},
@"subdomainRules": @{@"allowSubdomains": @NO}
};
DPDocument *document = [self.dpnsDocumentFactory documentOnTable:@"domain" withDataDictionary:dataDictionary usingEntropy:entropyData error:error];
Expand Down
97 changes: 62 additions & 35 deletions DashSync/shared/dpns-contract.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"documents": {
"domain": {
"documentsMutable": false,
"canBeDeleted": true,
"transferable": 1,
"tradeMode": 1,
"type": "object",
"indices": [
{
"name": "parentNameAndLabel",
"properties": [
{
"normalizedParentDomainName": "asc"
Expand All @@ -11,79 +17,85 @@
"normalizedLabel": "asc"
}
],
"unique": true
"unique": true,
"contested": {
"fieldMatches": [
{
"field": "normalizedLabel",
"regexPattern": "^[a-zA-Z01-]{3,19}$"
}
],
"resolution": 0,
"description": "If the normalized label part of this index is less than 20 characters (all alphabet a-z, A-Z, 0, 1, and -) then a masternode vote contest takes place to give out the name"
}
},
{
"name": "identityId",
"nullSearchable": false,
"properties": [
{
"records.dashUniqueIdentityId": "asc"
}
],
"unique": true
},
{
"properties": [
{
"records.dashAliasIdentityId": "asc"
"records.identity": "asc"
}
]
}
],
"properties": {
"label": {
"type": "string",
"pattern": "^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])$",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
"minLength": 3,
"maxLength": 63,
"position": 0,
"description": "Domain label. e.g. 'Bob'."
},
"normalizedLabel": {
"type": "string",
"pattern": "^((?!-)[a-z0-9-]{0,62}[a-z0-9])$",
"pattern": "^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-]{0,61}[a-hj-km-np-z0-9]$",
"maxLength": 63,
"description": "Domain label in lowercase for case-insensitive uniqueness validation. e.g. 'bob'",
"$comment": "Must be equal to the label in lowercase. This property will be deprecated due to case insensitive indices"
"position": 1,
"description": "Domain label converted to lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'b0b'",
"$comment": "Must be equal to the label in lowercase. \"o\", \"i\" and \"l\" must be replaced with \"0\" and \"1\"."
},
"parentDomainName": {
"type": "string",
"pattern": "^$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
"minLength": 0,
"maxLength": 63,
"position": 2,
"description": "A full parent domain name. e.g. 'dash'."
},
"normalizedParentDomainName": {
"type": "string",
"pattern": "^$|^((?!-)[a-z0-9-\\.]{0,189}[a-z0-9])$",
"pattern": "^$|^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-\\.]{0,61}[a-hj-km-np-z0-9]$",
"minLength": 0,
"maxLength": 190,
"description": "A full parent domain name in lowercase for case-insensitive uniqueness validation. e.g. 'dash'",
"$comment": "Must either be equal to an existing domain or empty to create a top level domain. Only the data contract owner can create top level domains."
"maxLength": 63,
"position": 3,
"description": "A parent domain name in lowercase for case-insensitive uniqueness validation. \"o\", \"i\" and \"l\" replaced with \"0\" and \"1\" to mitigate homograph attack. e.g. 'dash'",
"$comment": "Must either be equal to an existing domain or empty to create a top level domain. \"o\", \"i\" and \"l\" must be replaced with \"0\" and \"1\". Only the data contract owner can create top level domains."
},
"preorderSalt": {
"type": "array",
"byteArray": true,
"minItems": 32,
"maxItems": 32,
"position": 4,
"description": "Salt used in the preorder document"
},
"records": {
"type": "object",
"properties": {
"dashUniqueIdentityId": {
"type": "array",
"byteArray": true,
"minItems": 32,
"maxItems": 32,
"contentMediaType": "application/x.dash.dpp.identifier",
"description": "Identity ID to be used to create the primary name the Identity",
"$comment": "Must be equal to the document owner"
},
"dashAliasIdentityId": {
"identity": {
"type": "array",
"byteArray": true,
"minItems": 32,
"maxItems": 32,
"position": 1,
"contentMediaType": "application/x.dash.dpp.identifier",
"description": "Identity ID to be used to create alias names for the Identity",
"$comment": "Must be equal to the document owner"
"description": "Identifier name record that refers to an Identity"
}
},
"$comment": "Constraint with max and min properties ensure that only one identity record is used - either a `dashUniqueIdentityId` or a `dashAliasIdentityId`",
"minProperties": 1,
"maxProperties": 1,
"position": 5,
"additionalProperties": false
},
"subdomainRules": {
Expand All @@ -92,28 +104,42 @@
"allowSubdomains": {
"type": "boolean",
"description": "This option defines who can create subdomains: true - anyone; false - only the domain owner",
"$comment": "Only the domain owner is allowed to create subdomains for non top-level domains"
"$comment": "Only the domain owner is allowed to create subdomains for non top-level domains",
"position": 0
}
},
"position": 6,
"description": "Subdomain rules allow domain owners to define rules for subdomains",
"additionalProperties": false,
"required": ["allowSubdomains"]
"required": [
"allowSubdomains"
]
}
},
"required": [
"$createdAt",
"$updatedAt",
"$transferredAt",
"label",
"normalizedLabel",
"normalizedParentDomainName",
"preorderSalt",
"records",
"subdomainRules"
],
"transient": [
"preorderSalt"
],
"additionalProperties": false,
"$comment": "In order to register a domain you need to create a preorder. The preorder step is needed to prevent man-in-the-middle attacks. normalizedLabel + '.' + normalizedParentDomain must not be longer than 253 chars length as defined by RFC 1035. Domain documents are immutable: modification and deletion are restricted"
},
"preorder": {
"documentsMutable": false,
"canBeDeleted": true,
"type": "object",
"indices": [
{
"name": "saltedHash",
"properties": [
{
"saltedDomainHash": "asc"
Expand All @@ -128,6 +154,7 @@
"byteArray": true,
"minItems": 32,
"maxItems": 32,
"position": 0,
"description": "Double sha-256 of the concatenation of a 32 byte random salt and a normalized domain name"
}
},
Expand All @@ -138,4 +165,4 @@
"$comment": "Preorder documents are immutable: modification and deletion are restricted"
}
}
}
}

0 comments on commit b293048

Please sign in to comment.