dash-platform-sdk 1.1.0 → 1.1.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.
Files changed (68) hide show
  1. package/bundle.min.js +1 -1
  2. package/package.json +7 -6
  3. package/proto/generated/platform.d.ts +340 -115
  4. package/proto/generated/platform.js +3732 -2333
  5. package/src/DashPlatformSDK.d.ts +18 -5
  6. package/src/DashPlatformSDK.js +20 -7
  7. package/src/constants.d.ts +4 -0
  8. package/src/constants.js +5 -1
  9. package/src/contestedResources/getContestedResourceVoteState.d.ts +6 -0
  10. package/src/contestedResources/getContestedResourceVoteState.js +124 -0
  11. package/src/contestedResources/index.d.ts +29 -0
  12. package/src/contestedResources/index.js +75 -0
  13. package/src/dataContracts/create.js +1 -1
  14. package/src/dataContracts/createStateTransition.d.ts +1 -1
  15. package/src/dataContracts/createStateTransition.js +5 -6
  16. package/src/dataContracts/getDataContractByIdentifier.js +5 -5
  17. package/src/dataContracts/index.d.ts +2 -3
  18. package/src/dataContracts/index.js +1 -1
  19. package/src/documents/create.d.ts +1 -1
  20. package/src/documents/create.js +1 -41
  21. package/src/documents/createStateTransition.d.ts +2 -2
  22. package/src/documents/createStateTransition.js +9 -10
  23. package/src/documents/index.d.ts +3 -3
  24. package/src/documents/index.js +3 -7
  25. package/src/documents/query.js +3 -5
  26. package/src/grpcConnectionPool.d.ts +3 -2
  27. package/src/grpcConnectionPool.js +52 -48
  28. package/src/identities/getIdentityBalance.js +4 -4
  29. package/src/identities/getIdentityByIdentifier.js +4 -4
  30. package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +3 -0
  31. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +87 -0
  32. package/src/identities/getIdentityByPublicKeyHash.js +4 -4
  33. package/src/identities/getIdentityContractNonce.js +4 -4
  34. package/src/identities/getIdentityNonce.js +4 -4
  35. package/src/identities/getIdentityPublicKeys.js +4 -4
  36. package/src/identities/index.d.ts +9 -1
  37. package/src/identities/index.js +23 -1
  38. package/src/node/epochs.d.ts +10 -0
  39. package/src/node/epochs.js +82 -0
  40. package/src/node/index.d.ts +16 -1
  41. package/src/node/index.js +35 -1
  42. package/src/node/totalCredits.d.ts +2 -0
  43. package/src/node/totalCredits.js +77 -0
  44. package/src/stateTransitions/broadcast.js +3 -0
  45. package/src/tokens/getIdentitiesTokenBalances.d.ts +8 -0
  46. package/src/tokens/getIdentitiesTokenBalances.js +87 -0
  47. package/src/tokens/getIdentityTokensBalances.d.ts +8 -0
  48. package/src/tokens/getIdentityTokensBalances.js +87 -0
  49. package/src/tokens/getTokenContractInfo.d.ts +8 -0
  50. package/src/tokens/getTokenContractInfo.js +87 -0
  51. package/src/tokens/getTokenTotalSupply.d.ts +9 -0
  52. package/src/tokens/getTokenTotalSupply.js +85 -0
  53. package/src/tokens/index.d.ts +50 -0
  54. package/src/tokens/index.js +124 -0
  55. package/src/types.d.ts +30 -0
  56. package/src/types.js +14 -1
  57. package/src/utils/indexBytesToString.d.ts +1 -0
  58. package/src/utils/indexBytesToString.js +7 -0
  59. package/src/utils/stringToIndexValueBytes.d.ts +1 -0
  60. package/src/utils/stringToIndexValueBytes.js +13 -0
  61. package/test/unit/ContestedResources.spec.d.ts +1 -0
  62. package/test/unit/ContestedResources.spec.js +257 -0
  63. package/test/unit/DataContract.spec.js +16 -6
  64. package/test/unit/DocumentsBatch.spec.js +6 -6
  65. package/test/unit/Identity.spec.js +15 -3
  66. package/test/unit/Node.spec.js +40 -0
  67. package/test/unit/Tokens.spec.d.ts +1 -0
  68. package/test/unit/Tokens.spec.js +100 -0
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var getIdentitiesTokenBalances_1 = require("./getIdentitiesTokenBalances");
40
+ var getIdentityTokensBalances_1 = require("./getIdentityTokensBalances");
41
+ var getTokenContractInfo_1 = require("./getTokenContractInfo");
42
+ var getTokenTotalSupply_1 = require("./getTokenTotalSupply");
43
+ /**
44
+ * Tokens controller for requesting information about tokens and tokens holders
45
+ *
46
+ * @hideconstructor
47
+ */
48
+ var TokensController = /** @class */ (function () {
49
+ function TokensController(grpcPool) {
50
+ this.grpcPool = grpcPool;
51
+ }
52
+ /**
53
+ * Retrieves a token balances for identities
54
+ *
55
+ * @param identifiers {IdentifierLike[]} - list of identifiers which balance we need to get
56
+ * @param tokenIdentifier {IdentifierLike} - token identifier
57
+ *
58
+ * @return {Promise<IdentitiesTokenBalances>}
59
+ */
60
+ TokensController.prototype.getIdentitiesTokenBalances = function (identifiers, tokenIdentifier) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0: return [4 /*yield*/, (0, getIdentitiesTokenBalances_1.default)(this.grpcPool, identifiers, tokenIdentifier)];
65
+ case 1: return [2 /*return*/, _a.sent()];
66
+ }
67
+ });
68
+ });
69
+ };
70
+ /**
71
+ * Retrieves a tokens balances for identity
72
+ *
73
+ * @param identifier {IdentifierLike} - identifier which balance we need to get
74
+ * @param tokenIdentifiers {IdentifierLike[]} - list of tokens ids which used in request
75
+ *
76
+ * @return {Promise<IdentityTokenBalances>}
77
+ */
78
+ TokensController.prototype.getIdentityTokensBalances = function (identifier, tokenIdentifiers) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0: return [4 /*yield*/, (0, getIdentityTokensBalances_1.default)(this.grpcPool, identifier, tokenIdentifiers)];
83
+ case 1: return [2 /*return*/, _a.sent()];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ /**
89
+ * Retrieves a tokens contract info by id
90
+ *
91
+ * @param tokenIdentifier {IdentifierLike} - token id which contract info we need
92
+ *
93
+ * @return {Promise<TokenContractInfo>}
94
+ */
95
+ TokensController.prototype.getTokenContractInfo = function (tokenIdentifier) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0: return [4 /*yield*/, (0, getTokenContractInfo_1.default)(this.grpcPool, tokenIdentifier)];
100
+ case 1: return [2 /*return*/, _a.sent()];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ /**
106
+ * Retrieves a token total supply
107
+ *
108
+ * @param tokenIdentifier {IdentifierLike} - token id which total supply we need
109
+ *
110
+ * @return {Promise<TokenTotalSupply>}
111
+ */
112
+ TokensController.prototype.getTokenTotalSupply = function (tokenIdentifier) {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ return __generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0: return [4 /*yield*/, (0, getTokenTotalSupply_1.default)(this.grpcPool, tokenIdentifier)];
117
+ case 1: return [2 /*return*/, _a.sent()];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ return TokensController;
123
+ }());
124
+ exports.default = TokensController;
package/src/types.d.ts CHANGED
@@ -94,6 +94,36 @@ export interface NodeStatus {
94
94
  epoch?: number | undefined;
95
95
  } | undefined;
96
96
  }
97
+ export declare enum ContestedStateResultType {
98
+ DOCUMENTS = 0,
99
+ VOTE_TALLY = 1,
100
+ DOCUMENTS_AND_VOTE_TALLY = 2
101
+ }
102
+ export declare enum FinishedVoteOutcome {
103
+ TOWARDS_IDENTITY = 0,
104
+ LOCKED = 1,
105
+ NO_PREVIOUS_WINNER = 2,
106
+ UNRECOGNIZED = -1
107
+ }
108
+ export interface Contender {
109
+ identifier: IdentifierWASM;
110
+ voteCount?: number | undefined;
111
+ document?: Uint8Array;
112
+ }
113
+ export interface FinishedVoteInfo {
114
+ type: string;
115
+ wonByIdentityId?: IdentifierWASM | undefined;
116
+ finishedAtBlockHeight: string;
117
+ finishedAtCoreBlockHeight: number;
118
+ finishedAtBlockTimeMs: string;
119
+ finishedAtEpoch: number;
120
+ }
121
+ export interface ContestedResourceVoteState {
122
+ contenders: Contender[];
123
+ abstainVoteTally?: number | undefined;
124
+ lockVoteTally?: number | undefined;
125
+ finishedVoteInfo?: FinishedVoteInfo;
126
+ }
97
127
  export interface DataContractConfig {
98
128
  $format_version: string;
99
129
  canBeDeleted: boolean;
package/src/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DashPlatformSDK = exports.IdentityPublicKeyWASM = exports.StateTransitionWASM = exports.DataContractWASM = exports.DocumentWASM = exports.IdentityWASM = exports.IdentifierWASM = void 0;
3
+ exports.FinishedVoteOutcome = exports.ContestedStateResultType = exports.DashPlatformSDK = exports.IdentityPublicKeyWASM = exports.StateTransitionWASM = exports.DataContractWASM = exports.DocumentWASM = exports.IdentityWASM = exports.IdentifierWASM = void 0;
4
4
  var pshenmic_dpp_1 = require("pshenmic-dpp");
5
5
  Object.defineProperty(exports, "IdentifierWASM", { enumerable: true, get: function () { return pshenmic_dpp_1.IdentifierWASM; } });
6
6
  Object.defineProperty(exports, "IdentityWASM", { enumerable: true, get: function () { return pshenmic_dpp_1.IdentityWASM; } });
@@ -10,3 +10,16 @@ Object.defineProperty(exports, "StateTransitionWASM", { enumerable: true, get: f
10
10
  Object.defineProperty(exports, "IdentityPublicKeyWASM", { enumerable: true, get: function () { return pshenmic_dpp_1.IdentityPublicKeyWASM; } });
11
11
  var DashPlatformSDK_1 = require("./DashPlatformSDK");
12
12
  Object.defineProperty(exports, "DashPlatformSDK", { enumerable: true, get: function () { return DashPlatformSDK_1.DashPlatformSDK; } });
13
+ var ContestedStateResultType;
14
+ (function (ContestedStateResultType) {
15
+ ContestedStateResultType[ContestedStateResultType["DOCUMENTS"] = 0] = "DOCUMENTS";
16
+ ContestedStateResultType[ContestedStateResultType["VOTE_TALLY"] = 1] = "VOTE_TALLY";
17
+ ContestedStateResultType[ContestedStateResultType["DOCUMENTS_AND_VOTE_TALLY"] = 2] = "DOCUMENTS_AND_VOTE_TALLY";
18
+ })(ContestedStateResultType || (exports.ContestedStateResultType = ContestedStateResultType = {}));
19
+ var FinishedVoteOutcome;
20
+ (function (FinishedVoteOutcome) {
21
+ FinishedVoteOutcome[FinishedVoteOutcome["TOWARDS_IDENTITY"] = 0] = "TOWARDS_IDENTITY";
22
+ FinishedVoteOutcome[FinishedVoteOutcome["LOCKED"] = 1] = "LOCKED";
23
+ FinishedVoteOutcome[FinishedVoteOutcome["NO_PREVIOUS_WINNER"] = 2] = "NO_PREVIOUS_WINNER";
24
+ FinishedVoteOutcome[FinishedVoteOutcome["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
25
+ })(FinishedVoteOutcome || (exports.FinishedVoteOutcome = FinishedVoteOutcome = {}));
@@ -0,0 +1 @@
1
+ export default function indexValueBytesToString(value: Uint8Array<ArrayBufferLike>): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = indexValueBytesToString;
4
+ function indexValueBytesToString(value) {
5
+ var decoder = new TextDecoder();
6
+ return decoder.decode(value).slice(2);
7
+ }
@@ -0,0 +1 @@
1
+ export default function stringToIndexValueBytes(name: string): Uint8Array;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = stringToIndexValueBytes;
4
+ function stringToIndexValueBytes(name) {
5
+ var lengthBuffer = new Uint8Array(1);
6
+ lengthBuffer[0] = name.length;
7
+ var nameBuffer = new TextEncoder().encode(name);
8
+ var result = new Uint8Array(1 + 1 + nameBuffer.length);
9
+ result[0] = 0x12;
10
+ result[1] = lengthBuffer[0];
11
+ result.set(nameBuffer, 2);
12
+ return result;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var types_1 = require("../../src/types");
40
+ var pshenmic_dpp_1 = require("pshenmic-dpp");
41
+ var stringToIndexValueBytes_1 = require("../../src/utils/stringToIndexValueBytes");
42
+ var sdk;
43
+ var contract;
44
+ describe('Contested State', function () {
45
+ beforeAll(function () {
46
+ sdk = new types_1.DashPlatformSDK();
47
+ contract = new pshenmic_dpp_1.DataContractWASM('11111111111111111111111111111111', BigInt(1), {
48
+ domain: {
49
+ type: 'object',
50
+ indices: [
51
+ {
52
+ name: 'parentNameAndLabel',
53
+ unique: true,
54
+ contested: {
55
+ resolution: 0,
56
+ 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',
57
+ fieldMatches: [
58
+ {
59
+ field: 'normalizedLabel',
60
+ regexPattern: '^[a-zA-Z01-]{3,19}$'
61
+ }
62
+ ]
63
+ },
64
+ properties: [
65
+ {
66
+ normalizedParentDomainName: 'asc'
67
+ },
68
+ {
69
+ normalizedLabel: 'asc'
70
+ }
71
+ ]
72
+ },
73
+ {
74
+ name: 'identityId',
75
+ properties: [
76
+ {
77
+ 'records.identity': 'asc'
78
+ }
79
+ ],
80
+ nullSearchable: false
81
+ }
82
+ ],
83
+ $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",
84
+ required: [
85
+ '$createdAt',
86
+ '$updatedAt',
87
+ '$transferredAt',
88
+ 'label',
89
+ 'normalizedLabel',
90
+ 'normalizedParentDomainName',
91
+ 'preorderSalt',
92
+ 'records',
93
+ 'subdomainRules'
94
+ ],
95
+ tradeMode: 1,
96
+ transient: [
97
+ 'preorderSalt'
98
+ ],
99
+ properties: {
100
+ label: {
101
+ type: 'string',
102
+ pattern: '^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$',
103
+ position: 0,
104
+ maxLength: 63,
105
+ minLength: 3,
106
+ description: "Domain label. e.g. 'Bob'."
107
+ },
108
+ records: {
109
+ type: 'object',
110
+ position: 5,
111
+ properties: {
112
+ identity: {
113
+ type: 'array',
114
+ maxItems: 32,
115
+ minItems: 32,
116
+ position: 1,
117
+ byteArray: true,
118
+ description: 'Identifier name record that refers to an Identity',
119
+ contentMediaType: 'application/x.dash.dpp.identifier'
120
+ }
121
+ },
122
+ minProperties: 1,
123
+ additionalProperties: false
124
+ },
125
+ preorderSalt: {
126
+ type: 'array',
127
+ maxItems: 32,
128
+ minItems: 32,
129
+ position: 4,
130
+ byteArray: true,
131
+ description: 'Salt used in the preorder document'
132
+ },
133
+ subdomainRules: {
134
+ type: 'object',
135
+ position: 6,
136
+ required: [
137
+ 'allowSubdomains'
138
+ ],
139
+ properties: {
140
+ allowSubdomains: {
141
+ type: 'boolean',
142
+ $comment: 'Only the domain owner is allowed to create subdomains for non top-level domains',
143
+ position: 0,
144
+ description: 'This option defines who can create subdomains: true - anyone; false - only the domain owner'
145
+ }
146
+ },
147
+ description: 'Subdomain rules allow domain owners to define rules for subdomains',
148
+ additionalProperties: false
149
+ },
150
+ normalizedLabel: {
151
+ type: 'string',
152
+ pattern: '^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-]{0,61}[a-hj-km-np-z0-9]$',
153
+ $comment: 'Must be equal to the label in lowercase. "o", "i" and "l" must be replaced with "0" and "1".',
154
+ position: 1,
155
+ maxLength: 63,
156
+ 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'"
157
+ },
158
+ parentDomainName: {
159
+ type: 'string',
160
+ pattern: '^$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$',
161
+ position: 2,
162
+ maxLength: 63,
163
+ minLength: 0,
164
+ description: "A full parent domain name. e.g. 'dash'."
165
+ },
166
+ normalizedParentDomainName: {
167
+ type: 'string',
168
+ pattern: '^$|^[a-hj-km-np-z0-9][a-hj-km-np-z0-9-\\.]{0,61}[a-hj-km-np-z0-9]$',
169
+ $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.',
170
+ position: 3,
171
+ maxLength: 63,
172
+ minLength: 0,
173
+ 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'"
174
+ }
175
+ },
176
+ canBeDeleted: true,
177
+ transferable: 1,
178
+ documentsMutable: false,
179
+ additionalProperties: false
180
+ },
181
+ preorder: {
182
+ type: 'object',
183
+ indices: [
184
+ {
185
+ name: 'saltedHash',
186
+ unique: true,
187
+ properties: [
188
+ {
189
+ saltedDomainHash: 'asc'
190
+ }
191
+ ]
192
+ }
193
+ ],
194
+ $comment: 'Preorder documents are immutable: modification and deletion are restricted',
195
+ required: [
196
+ 'saltedDomainHash'
197
+ ],
198
+ properties: {
199
+ saltedDomainHash: {
200
+ type: 'array',
201
+ maxItems: 32,
202
+ minItems: 32,
203
+ position: 0,
204
+ byteArray: true,
205
+ description: 'Double sha-256 of the concatenation of a 32 byte random salt and a normalized domain name'
206
+ }
207
+ },
208
+ canBeDeleted: true,
209
+ documentsMutable: false,
210
+ additionalProperties: false
211
+ }
212
+ }, undefined, undefined, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9);
213
+ contract.id = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
214
+ });
215
+ test('should be able to get contested resource vote state with finishedVoteInfo', function () { return __awaiter(void 0, void 0, void 0, function () {
216
+ var voteState;
217
+ return __generator(this, function (_a) {
218
+ switch (_a.label) {
219
+ case 0: return [4 /*yield*/, sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
220
+ 'dash',
221
+ 'asdmaye1ght'
222
+ ].map(stringToIndexValueBytes_1.default), types_1.ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, true)];
223
+ case 1:
224
+ voteState = _a.sent();
225
+ expect(voteState.finishedVoteInfo).toBeTruthy();
226
+ expect(voteState.contenders).toBeTruthy();
227
+ expect(voteState.contenders.length).toBeGreaterThan(0);
228
+ expect(voteState.abstainVoteTally).toBeDefined();
229
+ expect(voteState.lockVoteTally).toBeDefined();
230
+ return [2 /*return*/];
231
+ }
232
+ });
233
+ }); });
234
+ test('should be able to get contested resource vote state for incorrect values', function () { return __awaiter(void 0, void 0, void 0, function () {
235
+ var e_1;
236
+ return __generator(this, function (_a) {
237
+ switch (_a.label) {
238
+ case 0:
239
+ _a.trys.push([0, 2, , 3]);
240
+ return [4 /*yield*/, sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
241
+ 'dash',
242
+ 'agreatma1n'
243
+ ].map(stringToIndexValueBytes_1.default), types_1.ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, false)];
244
+ case 1:
245
+ _a.sent();
246
+ return [3 /*break*/, 3];
247
+ case 2:
248
+ e_1 = _a.sent();
249
+ expect(true).toBeTruthy();
250
+ return [2 /*return*/];
251
+ case 3:
252
+ expect(false).toBeTruthy();
253
+ return [2 /*return*/];
254
+ }
255
+ });
256
+ }); });
257
+ });
@@ -38,9 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var pshenmic_dpp_1 = require("pshenmic-dpp");
40
40
  var types_1 = require("../../src/types");
41
- var createStateTransition_1 = require("../../src/dataContracts/createStateTransition");
42
41
  var sdk;
43
- var dataContractIdentifier;
44
42
  var ownerIdentifier;
45
43
  var identityNonce;
46
44
  var config;
@@ -48,7 +46,6 @@ var schema;
48
46
  describe('DataContract', function () {
49
47
  beforeAll(function () {
50
48
  sdk = new types_1.DashPlatformSDK();
51
- dataContractIdentifier = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
52
49
  ownerIdentifier = 'GARSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
53
50
  identityNonce = BigInt(11);
54
51
  config = {
@@ -83,8 +80,21 @@ describe('DataContract', function () {
83
80
  var dataContract;
84
81
  return __generator(this, function (_a) {
85
82
  switch (_a.label) {
86
- case 0: return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier(dataContractIdentifier)];
83
+ case 0: return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec')
84
+ // User Data Contract
85
+ ];
87
86
  case 1:
87
+ // System Data Contract
88
+ dataContract = _a.sent();
89
+ return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('Aukz296s36am6wKStoMbxm4YhC6kTpu3mERVrC7vHokP')
90
+ // User Data Contract with keep history
91
+ ];
92
+ case 2:
93
+ // User Data Contract
94
+ dataContract = _a.sent();
95
+ return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV')];
96
+ case 3:
97
+ // User Data Contract with keep history
88
98
  dataContract = _a.sent();
89
99
  expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
90
100
  return [2 /*return*/];
@@ -112,7 +122,7 @@ describe('DataContract', function () {
112
122
  var dataContract, transition;
113
123
  return __generator(this, function (_a) {
114
124
  dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
115
- transition = sdk.dataContracts.createStateTransition(dataContract, createStateTransition_1.DataContractTransitionType.Create, identityNonce);
125
+ transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
116
126
  expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
117
127
  return [2 /*return*/];
118
128
  });
@@ -121,7 +131,7 @@ describe('DataContract', function () {
121
131
  var dataContract, transition;
122
132
  return __generator(this, function (_a) {
123
133
  dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
124
- transition = sdk.dataContracts.createStateTransition(dataContract, createStateTransition_1.DataContractTransitionType.Update, identityNonce);
134
+ transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
125
135
  expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
126
136
  return [2 /*return*/];
127
137
  });
@@ -69,7 +69,7 @@ describe('DocumentsBatch', function () {
69
69
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
70
70
  case 1:
71
71
  document = _a.sent();
72
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.Create, identityContractNonce)];
72
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'create', identityContractNonce)];
73
73
  case 2:
74
74
  stateTransitions = _a.sent();
75
75
  expect(stateTransitions).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -84,7 +84,7 @@ describe('DocumentsBatch', function () {
84
84
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
85
85
  case 1:
86
86
  document = _a.sent();
87
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.Delete, identityContractNonce)];
87
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'delete', identityContractNonce)];
88
88
  case 2:
89
89
  stateTransitions = _a.sent();
90
90
  expect(stateTransitions).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -99,7 +99,7 @@ describe('DocumentsBatch', function () {
99
99
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
100
100
  case 1:
101
101
  document = _a.sent();
102
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.Purchase, identityContractNonce, { price: price })];
102
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'purchase', identityContractNonce, { price: price })];
103
103
  case 2:
104
104
  stateTransition = _a.sent();
105
105
  expect(stateTransition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -114,7 +114,7 @@ describe('DocumentsBatch', function () {
114
114
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
115
115
  case 1:
116
116
  document = _a.sent();
117
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.Replace, identityContractNonce)];
117
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'replace', identityContractNonce)];
118
118
  case 2:
119
119
  stateTransition = _a.sent();
120
120
  expect(stateTransition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -129,7 +129,7 @@ describe('DocumentsBatch', function () {
129
129
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
130
130
  case 1:
131
131
  document = _a.sent();
132
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.Transfer, identityContractNonce, { recipient: recipient })];
132
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'transfer', identityContractNonce, { recipient: recipient })];
133
133
  case 2:
134
134
  stateTransition = _a.sent();
135
135
  expect(stateTransition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -144,7 +144,7 @@ describe('DocumentsBatch', function () {
144
144
  case 0: return [4 /*yield*/, sdk.documents.create(dataContract, documentType, data, identity, BigInt(1))];
145
145
  case 1:
146
146
  document = _a.sent();
147
- return [4 /*yield*/, sdk.documents.createStateTransition(document, pshenmic_dpp_1.BatchType.UpdatePrice, identityContractNonce, { price: price })];
147
+ return [4 /*yield*/, sdk.documents.createStateTransition(document, 'updatePrice', identityContractNonce, { price: price })];
148
148
  case 2:
149
149
  stateTransition = _a.sent();
150
150
  expect(stateTransition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
@@ -74,7 +74,7 @@ describe('Identity', function () {
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
76
  case 0:
77
- publicKeyHash = 'c5b7fdfa5731e1b31b1b42c13959756e8db22b3b';
77
+ publicKeyHash = 'c1b95d254c405a3d9d82ef88a47f9f792ac8efd7';
78
78
  return [4 /*yield*/, sdk.identities.getIdentityByPublicKeyHash(publicKeyHash)];
79
79
  case 1:
80
80
  identity = _a.sent();
@@ -83,13 +83,25 @@ describe('Identity', function () {
83
83
  }
84
84
  });
85
85
  }); });
86
+ test('should be able to get identity by non unique public key hash', function () { return __awaiter(void 0, void 0, void 0, function () {
87
+ var identity;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0: return [4 /*yield*/, sdk.identities.getIdentityByNonUniquePublicKeyHash('8b30a2cda275d1110874c0380b8447db3a9b04ee')];
91
+ case 1:
92
+ identity = _a.sent();
93
+ expect(identity).toEqual(expect.any(pshenmic_dpp_1.IdentityWASM));
94
+ return [2 /*return*/];
95
+ }
96
+ });
97
+ }); });
86
98
  test('should be able to get identity contract nonce', function () { return __awaiter(void 0, void 0, void 0, function () {
87
99
  var identifier, dataContract, identityContractNonce;
88
100
  return __generator(this, function (_a) {
89
101
  switch (_a.label) {
90
102
  case 0:
91
- identifier = 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH';
92
- dataContract = '6QMfQTdKpC3Y9uWBcTwXeY3KdzRLDqASUsDnQ4MEc9XC';
103
+ identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
104
+ dataContract = 'DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV';
93
105
  return [4 /*yield*/, sdk.identities.getIdentityContractNonce(identifier, dataContract)];
94
106
  case 1:
95
107
  identityContractNonce = _a.sent();