dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.6

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 (138) hide show
  1. package/bundle.min.js +21 -2
  2. package/index.js +2 -5
  3. package/package.json +30 -31
  4. package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
  5. package/proto/generated/google/protobuf/wrappers.js +562 -345
  6. package/proto/generated/platform.client.d.ts +251 -0
  7. package/proto/generated/platform.client.js +175 -0
  8. package/proto/generated/platform.d.ts +3682 -1939
  9. package/proto/generated/platform.js +8119 -18366
  10. package/src/DashPlatformSDK.d.ts +5 -4
  11. package/src/DashPlatformSDK.js +56 -46
  12. package/src/constants.js +7 -10
  13. package/src/contestedResources/createStateTransition.d.ts +1 -2
  14. package/src/contestedResources/createStateTransition.js +4 -7
  15. package/src/contestedResources/getContestedResourceVoteState.js +67 -118
  16. package/src/contestedResources/index.js +9 -55
  17. package/src/dataContracts/create.js +5 -8
  18. package/src/dataContracts/createStateTransition.js +10 -14
  19. package/src/dataContracts/getDataContractByIdentifier.js +40 -83
  20. package/src/dataContracts/index.js +17 -63
  21. package/src/documents/create.js +3 -6
  22. package/src/documents/createStateTransition.js +19 -31
  23. package/src/documents/index.js +25 -72
  24. package/src/documents/query.js +58 -90
  25. package/src/grpcConnectionPool.d.ts +30 -8
  26. package/src/grpcConnectionPool.js +63 -121
  27. package/src/identities/createStateTransition.js +14 -26
  28. package/src/identities/getIdentityBalance.js +37 -80
  29. package/src/identities/getIdentityByIdentifier.js +37 -80
  30. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
  31. package/src/identities/getIdentityByPublicKeyHash.js +37 -80
  32. package/src/identities/getIdentityContractNonce.js +40 -83
  33. package/src/identities/getIdentityNonce.js +38 -81
  34. package/src/identities/getIdentityPublicKeys.js +43 -81
  35. package/src/identities/index.js +57 -153
  36. package/src/keyPair/deriveChild.d.ts +2 -2
  37. package/src/keyPair/deriveChild.js +2 -49
  38. package/src/keyPair/derivePath.d.ts +2 -2
  39. package/src/keyPair/derivePath.js +2 -49
  40. package/src/keyPair/index.d.ts +39 -114
  41. package/src/keyPair/index.js +62 -296
  42. package/src/keyPair/mnemonicToSeed.d.ts +1 -1
  43. package/src/keyPair/mnemonicToSeed.js +3 -46
  44. package/src/names/index.js +43 -111
  45. package/src/names/registerName.js +60 -127
  46. package/src/names/searchByIdentity.d.ts +1 -1
  47. package/src/names/searchByIdentity.js +4 -50
  48. package/src/names/searchByName.js +15 -63
  49. package/src/names/testNameContested.js +1 -4
  50. package/src/names/validateName.js +3 -6
  51. package/src/node/epochs.js +43 -85
  52. package/src/node/index.d.ts +3 -3
  53. package/src/node/index.js +18 -77
  54. package/src/node/status.js +37 -81
  55. package/src/node/totalCredits.d.ts +2 -1
  56. package/src/node/totalCredits.js +32 -73
  57. package/src/signer/AbstractSigner.js +1 -2
  58. package/src/signer/setSigner.js +1 -4
  59. package/src/stateTransitions/broadcast.js +7 -57
  60. package/src/stateTransitions/index.js +13 -66
  61. package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
  62. package/src/tokens/createStateTransition.js +23 -35
  63. package/src/tokens/getIdentitiesTokenBalances.js +40 -83
  64. package/src/tokens/getIdentityTokensBalances.js +40 -83
  65. package/src/tokens/getTokenContractInfo.js +40 -83
  66. package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
  67. package/src/tokens/getTokenTotalSupply.js +38 -81
  68. package/src/tokens/index.js +39 -124
  69. package/src/types.d.ts +6 -12
  70. package/src/types.js +6 -16
  71. package/src/utils/base58ToBytes.js +3 -6
  72. package/src/utils/bytesToHex.js +2 -5
  73. package/src/utils/bytesToTypedArray.d.ts +1 -0
  74. package/src/utils/bytesToTypedArray.js +3 -0
  75. package/src/utils/calculateMsgHash.d.ts +1 -1
  76. package/src/utils/calculateMsgHash.js +10 -13
  77. package/src/utils/calculateSignHash.d.ts +1 -1
  78. package/src/utils/calculateSignHash.js +7 -10
  79. package/src/utils/calculateStateIdHash.d.ts +1 -1
  80. package/src/utils/calculateStateIdHash.js +8 -10
  81. package/src/utils/convertToHomographSafeChars.js +2 -5
  82. package/src/utils/createVoterIdentityId.d.ts +1 -1
  83. package/src/utils/createVoterIdentityId.js +12 -11
  84. package/src/utils/getEvonodeList.d.ts +2 -2
  85. package/src/utils/getEvonodeList.js +10 -61
  86. package/src/utils/getQuorumPublicKey.js +15 -66
  87. package/src/utils/getRandomArrayItem.js +1 -4
  88. package/src/utils/getRandomBytes.js +2 -5
  89. package/src/utils/hexToBytes.js +2 -6
  90. package/src/utils/index.js +21 -28
  91. package/src/utils/indexBytesToString.js +2 -5
  92. package/src/utils/sha256.d.ts +1 -1
  93. package/src/utils/sha256.js +10 -8
  94. package/src/utils/signHash.d.ts +1 -1
  95. package/src/utils/signHash.js +9 -12
  96. package/src/utils/signRequestId.d.ts +1 -1
  97. package/src/utils/signRequestId.js +9 -12
  98. package/src/utils/sleep.js +2 -50
  99. package/src/utils/stringToIndexValueBytes.js +4 -7
  100. package/src/utils/verifyTenderdashProof.d.ts +1 -1
  101. package/src/utils/verifyTenderdashProof.js +13 -17
  102. package/src/voting/createStateTransition.d.ts +1 -2
  103. package/src/voting/createStateTransition.js +4 -7
  104. package/src/voting/createVote.js +4 -7
  105. package/src/voting/index.d.ts +3 -4
  106. package/src/voting/index.js +19 -26
  107. package/test/unit/ContestedResources.spec.js +92 -177
  108. package/test/unit/DataContract.spec.js +44 -111
  109. package/test/unit/Document.spec.js +93 -183
  110. package/test/unit/Identity.spec.js +221 -346
  111. package/test/unit/KeyPair.spec.js +30 -145
  112. package/test/unit/Names.spec.js +27 -90
  113. package/test/unit/Node.spec.js +55 -126
  114. package/test/unit/SDK.spec.js +7 -9
  115. package/test/unit/Tokens.spec.js +111 -278
  116. package/bundle.min.js.LICENSE.txt +0 -1
  117. package/src/keyPair/keyToPublicKey.d.ts +0 -2
  118. package/src/keyPair/keyToPublicKey.js +0 -47
  119. package/src/keyPair/keyToWalletId.d.ts +0 -2
  120. package/src/keyPair/keyToWalletId.js +0 -50
  121. package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
  122. package/src/keyPair/keyToXPrivateKey.js +0 -50
  123. package/src/keyPair/keyToXPublicKey.d.ts +0 -3
  124. package/src/keyPair/keyToXPublicKey.js +0 -50
  125. package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
  126. package/src/keyPair/mnemonicToIdentityKey.js +0 -57
  127. package/src/keyPair/mnemonicToWallet.d.ts +0 -2
  128. package/src/keyPair/mnemonicToWallet.js +0 -55
  129. package/src/keyPair/privateKeyToWif.d.ts +0 -2
  130. package/src/keyPair/privateKeyToWif.js +0 -50
  131. package/src/keyPair/publicKeyToAddress.d.ts +0 -2
  132. package/src/keyPair/publicKeyToAddress.js +0 -50
  133. package/src/keyPair/seedToWallet.d.ts +0 -2
  134. package/src/keyPair/seedToWallet.js +0 -50
  135. package/src/keyPair/walletToIdentityKey.d.ts +0 -3
  136. package/src/keyPair/walletToIdentityKey.js +0 -56
  137. package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
  138. package/src/keyPair/xkeyToHDXKey.js +0 -50
@@ -1,28 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VotingController = void 0;
4
- var createVote_1 = require("./createVote");
5
- var pshenmic_dpp_1 = require("pshenmic-dpp");
6
- var createVoterIdentityId_1 = require("../utils/createVoterIdentityId");
1
+ import createVote from './createVote';
2
+ import { IdentifierWASM, MasternodeVoteTransitionWASM, ResourceVoteChoiceWASM } from 'pshenmic-dpp';
3
+ import { createVoterIdentityId } from '../utils/createVoterIdentityId';
7
4
  /**
8
5
  * Voting controller for performing masternode votes
9
6
  *
10
7
  * @hideconstructor
11
8
  */
12
- var VotingController = /** @class */ (function () {
13
- function VotingController() {
14
- }
9
+ export class VotingController {
15
10
  /**
16
11
  * Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
17
12
  *
18
13
  * @param proTxHash {string} voter's masternode pro tx hash
19
14
  * @param publicKeyHash {string} voter address's public key hash
20
15
  *
21
- * @return {IdentifierWASM}
16
+ * @return {Promise<IdentifierWASM>}
22
17
  */
23
- VotingController.prototype.createVoterIdentityId = function (proTxHash, publicKeyHash) {
24
- return (0, createVoterIdentityId_1.createVoterIdentityId)(proTxHash, publicKeyHash);
25
- };
18
+ async createVoterIdentityId(proTxHash, publicKeyHash) {
19
+ return await createVoterIdentityId(proTxHash, publicKeyHash);
20
+ }
26
21
  /**
27
22
  * Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
28
23
  *
@@ -32,19 +27,19 @@ var VotingController = /** @class */ (function () {
32
27
  * @param indexValues {string[]}
33
28
  * @param choice {ResourceVoteChoice}
34
29
  */
35
- VotingController.prototype.createVote = function (dataContractId, documentTypeName, indexName, indexValues, choice) {
36
- var resourceVoteChoice;
30
+ createVote(dataContractId, documentTypeName, indexName, indexValues, choice) {
31
+ let resourceVoteChoice;
37
32
  if (choice === 'lock') {
38
- resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.Lock();
33
+ resourceVoteChoice = ResourceVoteChoiceWASM.Lock();
39
34
  }
40
35
  else if (choice === 'abstain') {
41
- resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.Abstain();
36
+ resourceVoteChoice = ResourceVoteChoiceWASM.Abstain();
42
37
  }
43
38
  else {
44
- resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.TowardsIdentity(new pshenmic_dpp_1.IdentifierWASM(choice));
39
+ resourceVoteChoice = ResourceVoteChoiceWASM.TowardsIdentity(new IdentifierWASM(choice));
45
40
  }
46
- return (0, createVote_1.default)(new pshenmic_dpp_1.IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
47
- };
41
+ return createVote(new IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
42
+ }
48
43
  /**
49
44
  * Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
50
45
  *
@@ -53,10 +48,8 @@ var VotingController = /** @class */ (function () {
53
48
  * @param voterIdentity {IdentifierWASM} voter identity identifier
54
49
  * @param identityNonce {BigInt} identity nonce
55
50
  */
56
- VotingController.prototype.createStateTransition = function (voteWASM, proTxHash, voterIdentity, identityNonce) {
57
- var transition = new pshenmic_dpp_1.MasternodeVoteTransitionWASM(pshenmic_dpp_1.IdentifierWASM.fromHex(proTxHash), new pshenmic_dpp_1.IdentifierWASM(voterIdentity), voteWASM, identityNonce);
51
+ createStateTransition(voteWASM, proTxHash, voterIdentity, identityNonce) {
52
+ const transition = new MasternodeVoteTransitionWASM(IdentifierWASM.fromHex(proTxHash), new IdentifierWASM(voterIdentity), voteWASM, identityNonce);
58
53
  return transition.toStateTransition();
59
- };
60
- return VotingController;
61
- }());
62
- exports.VotingController = VotingController;
54
+ }
55
+ }
@@ -1,50 +1,13 @@
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 pshenmic_dpp_1 = require("pshenmic-dpp");
40
- var types_1 = require("../../src/types");
41
- var stringToIndexValueBytes_1 = require("../../src/utils/stringToIndexValueBytes");
42
- var sdk;
43
- var contract;
44
- describe('Contested Resources', function () {
45
- beforeAll(function () {
46
- sdk = new types_1.DashPlatformSDK({ network: 'testnet' });
47
- contract = new pshenmic_dpp_1.DataContractWASM('11111111111111111111111111111111', BigInt(1), {
1
+ import { DataContractWASM, PlatformVersionWASM, PrivateKeyWASM } from 'pshenmic-dpp';
2
+ import stringToIndexValueBytes from '../../src/utils/stringToIndexValueBytes';
3
+ import { DashPlatformSDK } from '../../src/DashPlatformSDK';
4
+ import { ContestedStateResultType } from '../../src/types';
5
+ let sdk;
6
+ let contract;
7
+ describe('Contested Resources', () => {
8
+ beforeAll(() => {
9
+ sdk = new DashPlatformSDK({ network: 'testnet' });
10
+ contract = new DataContractWASM('11111111111111111111111111111111', BigInt(1), {
48
11
  domain: {
49
12
  type: 'object',
50
13
  indices: [
@@ -209,136 +172,88 @@ describe('Contested Resources', function () {
209
172
  documentsMutable: false,
210
173
  additionalProperties: false
211
174
  }
212
- }, undefined, undefined, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9);
175
+ }, undefined, undefined, true, PlatformVersionWASM.PLATFORM_V9);
213
176
  contract.id = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
214
177
  });
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
- test('should be able to create TowardsIdentity vote', function () { return __awaiter(void 0, void 0, void 0, function () {
258
- var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
259
- return __generator(this, function (_a) {
260
- switch (_a.label) {
261
- case 0:
262
- dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
263
- documentTypeName = 'domain';
264
- indexName = 'parentNameAndLabel';
265
- indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
266
- proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
267
- choice = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
268
- privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
269
- voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
270
- return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
271
- case 1:
272
- voterIdentity = _a.sent();
273
- identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
274
- return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
275
- case 2:
276
- identityNonce = _a.sent();
277
- vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
278
- stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
279
- // test key disabled
280
- identityPublicKey.removeDisabledAt();
281
- stateTransition.sign(privateKey, identityPublicKey);
282
- return [2 /*return*/];
283
- }
284
- });
285
- }); });
286
- test('should be able to create Abstain vote', function () { return __awaiter(void 0, void 0, void 0, function () {
287
- var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0:
291
- dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
292
- documentTypeName = 'domain';
293
- indexName = 'parentNameAndLabel';
294
- indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
295
- proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
296
- choice = 'abstain';
297
- privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
298
- voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
299
- return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
300
- case 1:
301
- voterIdentity = _a.sent();
302
- identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
303
- return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
304
- case 2:
305
- identityNonce = _a.sent();
306
- vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
307
- stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
308
- // test key disabled
309
- identityPublicKey.removeDisabledAt();
310
- stateTransition.sign(privateKey, identityPublicKey);
311
- return [2 /*return*/];
312
- }
313
- });
314
- }); });
315
- test('should be able to create Lock vote', function () { return __awaiter(void 0, void 0, void 0, function () {
316
- var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
319
- case 0:
320
- dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
321
- documentTypeName = 'domain';
322
- indexName = 'parentNameAndLabel';
323
- indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
324
- proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
325
- choice = 'lock';
326
- privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
327
- voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
328
- return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
329
- case 1:
330
- voterIdentity = _a.sent();
331
- identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
332
- return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
333
- case 2:
334
- identityNonce = _a.sent();
335
- vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
336
- stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
337
- // test key disabled
338
- identityPublicKey.removeDisabledAt();
339
- stateTransition.sign(privateKey, identityPublicKey);
340
- return [2 /*return*/];
341
- }
342
- });
343
- }); });
178
+ test('should be able to get contested resource vote state with finishedVoteInfo', async () => {
179
+ const voteState = await sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
180
+ 'dash',
181
+ 'asdmaye1ght'
182
+ ].map(stringToIndexValueBytes), ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, true);
183
+ expect(voteState.finishedVoteInfo).toBeTruthy();
184
+ expect(voteState.contenders).toBeTruthy();
185
+ expect(voteState.contenders.length).toBeGreaterThan(0);
186
+ expect(voteState.abstainVoteTally).toBeDefined();
187
+ expect(voteState.lockVoteTally).toBeDefined();
188
+ });
189
+ test('should be able to get contested resource vote state for incorrect values', async () => {
190
+ try {
191
+ await sdk.contestedResources.getContestedResourceVoteState(contract, 'domain', 'parentNameAndLabel', [
192
+ 'dash',
193
+ 'agreatma1n'
194
+ ].map(stringToIndexValueBytes), ContestedStateResultType.DOCUMENTS_AND_VOTE_TALLY, false);
195
+ }
196
+ catch (e) {
197
+ expect(true).toBeTruthy();
198
+ return;
199
+ }
200
+ expect(false).toBeTruthy();
201
+ });
202
+ test('should be able to create TowardsIdentity vote', async () => {
203
+ const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
204
+ const documentTypeName = 'domain';
205
+ const indexName = 'parentNameAndLabel';
206
+ const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
207
+ const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
208
+ const choice = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
209
+ const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
210
+ const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
211
+ expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
212
+ const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
213
+ const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
214
+ const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
215
+ const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
216
+ const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
217
+ // test key disabled
218
+ identityPublicKey.removeDisabledAt();
219
+ stateTransition.sign(privateKey, identityPublicKey);
220
+ });
221
+ test('should be able to create Abstain vote', async () => {
222
+ const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
223
+ const documentTypeName = 'domain';
224
+ const indexName = 'parentNameAndLabel';
225
+ const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
226
+ const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
227
+ const choice = 'abstain';
228
+ const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
229
+ const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
230
+ expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
231
+ const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
232
+ const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
233
+ const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
234
+ const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
235
+ const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
236
+ // test key disabled
237
+ identityPublicKey.removeDisabledAt();
238
+ stateTransition.sign(privateKey, identityPublicKey);
239
+ });
240
+ test('should be able to create Lock vote', async () => {
241
+ const dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
242
+ const documentTypeName = 'domain';
243
+ const indexName = 'parentNameAndLabel';
244
+ const indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
245
+ const proTxHash = 'd9b090cfc19caf2e27d512e69c43812a274bdf29c081d0ade4fd272ad56a5f89';
246
+ const choice = 'lock';
247
+ const privateKey = PrivateKeyWASM.fromWIF('cPGCETHtoevguQoyTSdsowCEF91yqhrcikcvBNK2CuTwpSLV7m9Z');
248
+ const voterIdentifier = await sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
249
+ expect(voterIdentifier.base58()).toEqual('HqfLeB9PLg3t9CL25tRNkEDPjAnDaHAMmthRNe8ucn8q');
250
+ const voterIdentity = await sdk.identities.getIdentityByIdentifier(voterIdentifier);
251
+ const [identityPublicKey] = voterIdentity.getPublicKeys().filter(identityPublicKey => privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash());
252
+ const identityNonce = await sdk.identities.getIdentityNonce(voterIdentity.id);
253
+ const vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
254
+ const stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
255
+ // test key disabled
256
+ identityPublicKey.removeDisabledAt();
257
+ stateTransition.sign(privateKey, identityPublicKey);
258
+ });
344
259
  });
@@ -1,51 +1,13 @@
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 pshenmic_dpp_1 = require("pshenmic-dpp");
40
- var types_1 = require("../../src/types");
41
- var sdk;
42
- var ownerIdentifier;
43
- var identityNonce;
44
- var config;
45
- var schema;
46
- describe('DataContract', function () {
47
- beforeAll(function () {
48
- sdk = new types_1.DashPlatformSDK();
1
+ import { DataContractWASM, StateTransitionWASM } from 'pshenmic-dpp';
2
+ import { DashPlatformSDK } from '../../src/types';
3
+ let sdk;
4
+ let ownerIdentifier;
5
+ let identityNonce;
6
+ let config;
7
+ let schema;
8
+ describe('DataContract', () => {
9
+ beforeAll(() => {
10
+ sdk = new DashPlatformSDK({ network: 'testnet' });
49
11
  ownerIdentifier = 'GARSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
50
12
  identityNonce = BigInt(11);
51
13
  config = {
@@ -76,67 +38,38 @@ describe('DataContract', function () {
76
38
  }
77
39
  };
78
40
  });
79
- test('should be able to get data contract', function () { return __awaiter(void 0, void 0, void 0, function () {
80
- var dataContract;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0: return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec')];
84
- case 1:
85
- // System Data Contract
86
- dataContract = _a.sent();
87
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
88
- return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('Aukz296s36am6wKStoMbxm4YhC6kTpu3mERVrC7vHokP')];
89
- case 2:
90
- // User Data Contract
91
- dataContract = _a.sent();
92
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
93
- return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV')];
94
- case 3:
95
- // User Data Contract with keep history
96
- dataContract = _a.sent();
97
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
98
- return [4 /*yield*/, sdk.dataContracts.getDataContractByIdentifier('3XtMFe9UPf75DAcLmLsX9CLTrLPNysNPMcnWCE1C39vm')];
99
- case 4:
100
- // Token Data Contract
101
- dataContract = _a.sent();
102
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
103
- return [2 /*return*/];
104
- }
105
- });
106
- }); });
107
- test('should be able to create data contract', function () { return __awaiter(void 0, void 0, void 0, function () {
108
- var dataContract;
109
- return __generator(this, function (_a) {
110
- dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
111
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
112
- return [2 /*return*/];
113
- });
114
- }); });
115
- test('should be able to create data contract with optional params', function () { return __awaiter(void 0, void 0, void 0, function () {
116
- var dataContract;
117
- return __generator(this, function (_a) {
118
- dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema, true, undefined, config);
119
- expect(dataContract).toEqual(expect.any(pshenmic_dpp_1.DataContractWASM));
120
- expect(dataContract.getConfig()).toEqual(config);
121
- return [2 /*return*/];
122
- });
123
- }); });
124
- test('should be able to create data contract create transition', function () { return __awaiter(void 0, void 0, void 0, function () {
125
- var dataContract, transition;
126
- return __generator(this, function (_a) {
127
- dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
128
- transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
129
- expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
130
- return [2 /*return*/];
131
- });
132
- }); });
133
- test('should be able to create data contract update transition', function () { return __awaiter(void 0, void 0, void 0, function () {
134
- var dataContract, transition;
135
- return __generator(this, function (_a) {
136
- dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
137
- transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
138
- expect(transition).toEqual(expect.any(pshenmic_dpp_1.StateTransitionWASM));
139
- return [2 /*return*/];
140
- });
141
- }); });
41
+ test('should be able to get data contract', async () => {
42
+ let dataContract;
43
+ // System Data Contract
44
+ dataContract = await sdk.dataContracts.getDataContractByIdentifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec');
45
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
46
+ // User Data Contract
47
+ dataContract = await sdk.dataContracts.getDataContractByIdentifier('Aukz296s36am6wKStoMbxm4YhC6kTpu3mERVrC7vHokP');
48
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
49
+ // User Data Contract with keep history
50
+ dataContract = await sdk.dataContracts.getDataContractByIdentifier('DrEhmVJz56ukHbaFt8xLVRasnNWsrx3x8dGtcu9xg6rV');
51
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
52
+ // Token Data Contract
53
+ dataContract = await sdk.dataContracts.getDataContractByIdentifier('3XtMFe9UPf75DAcLmLsX9CLTrLPNysNPMcnWCE1C39vm');
54
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
55
+ });
56
+ test('should be able to create data contract', async () => {
57
+ const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
58
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
59
+ });
60
+ test('should be able to create data contract with optional params', async () => {
61
+ const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema, true, undefined, config);
62
+ expect(dataContract).toEqual(expect.any(DataContractWASM));
63
+ expect(dataContract.getConfig()).toEqual(config);
64
+ });
65
+ test('should be able to create data contract create transition', async () => {
66
+ const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
67
+ const transition = sdk.dataContracts.createStateTransition(dataContract, 'create', identityNonce);
68
+ expect(transition).toEqual(expect.any(StateTransitionWASM));
69
+ });
70
+ test('should be able to create data contract update transition', async () => {
71
+ const dataContract = sdk.dataContracts.create(ownerIdentifier, identityNonce, schema);
72
+ const transition = sdk.dataContracts.createStateTransition(dataContract, 'update', identityNonce);
73
+ expect(transition).toEqual(expect.any(StateTransitionWASM));
74
+ });
142
75
  });