dash-platform-sdk 1.3.0-dev.1 → 1.3.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/bundle.min.js +1 -1
- package/package.json +1 -1
- package/src/DashPlatformSDK.d.ts +2 -0
- package/src/DashPlatformSDK.js +2 -0
- package/src/constants.d.ts +2 -0
- package/src/constants.js +3 -1
- package/src/contestedResources/createStateTransition.d.ts +3 -0
- package/src/contestedResources/createStateTransition.js +9 -0
- package/src/contestedResources/index.d.ts +1 -1
- package/src/dataContracts/getDataContractByIdentifier.js +4 -0
- package/src/names/index.d.ts +35 -2
- package/src/names/index.js +86 -16
- package/src/names/registerName.d.ts +3 -0
- package/src/names/registerName.js +131 -0
- package/src/names/searchByIdentity.d.ts +3 -0
- package/src/names/searchByIdentity.js +51 -0
- package/src/names/searchByName.d.ts +3 -0
- package/src/names/{search.js → searchByName.js} +6 -5
- package/src/names/testNameContested.d.ts +1 -0
- package/src/names/testNameContested.js +6 -0
- package/src/names/validateName.d.ts +1 -0
- package/src/names/validateName.js +14 -0
- package/src/stateTransitions/waitForStateTransitionResult.js +13 -17
- package/src/types.d.ts +1 -0
- package/src/utils/convertToHomographSafeChars.d.ts +0 -4
- package/src/utils/convertToHomographSafeChars.js +0 -4
- package/src/utils/createVoterIdentityId.d.ts +2 -0
- package/src/utils/createVoterIdentityId.js +12 -0
- package/src/utils/getRandomBytes.d.ts +1 -0
- package/src/utils/getRandomBytes.js +7 -0
- package/src/utils/index.d.ts +1 -3
- package/src/utils/index.js +1 -3
- package/src/utils/sleep.d.ts +1 -0
- package/src/utils/sleep.js +51 -0
- package/src/voting/createStateTransition.d.ts +3 -0
- package/src/voting/createStateTransition.js +9 -0
- package/src/voting/createVote.d.ts +2 -0
- package/src/voting/createVote.js +8 -0
- package/src/voting/index.d.ts +38 -0
- package/src/voting/index.js +62 -0
- package/test/unit/ContestedResources.spec.js +84 -3
- package/test/unit/Identity.spec.js +0 -12
- package/test/unit/Names.spec.d.ts +1 -0
- package/test/unit/Names.spec.js +96 -0
- package/src/names/search.d.ts +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVoterIdentityId = createVoterIdentityId;
|
|
4
|
+
var hash_js_1 = require("hash.js");
|
|
5
|
+
var hexToBytes_1 = require("./hexToBytes");
|
|
6
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
7
|
+
function createVoterIdentityId(proTxHash, publicKeyHash) {
|
|
8
|
+
var hash = (0, hash_js_1.sha256)().update((0, hexToBytes_1.default)(proTxHash));
|
|
9
|
+
hash.update((0, hexToBytes_1.default)(publicKeyHash));
|
|
10
|
+
var voterHex = hash.digest('hex');
|
|
11
|
+
return pshenmic_dpp_1.IdentifierWASM.fromHex(voterHex);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getRandomBytes(length: number): Uint8Array;
|
package/src/utils/index.d.ts
CHANGED
|
@@ -37,9 +37,7 @@ export declare class UtilsController {
|
|
|
37
37
|
*/
|
|
38
38
|
hexToBytes(hex: string): Uint8Array;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
|
|
40
|
+
* @deprecated use sdk.names.normalizeLabel()
|
|
43
41
|
*
|
|
44
42
|
* @param str {string}
|
|
45
43
|
*
|
package/src/utils/index.js
CHANGED
|
@@ -54,9 +54,7 @@ var UtilsController = /** @class */ (function () {
|
|
|
54
54
|
return (0, hexToBytes_1.default)(hex);
|
|
55
55
|
};
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
|
|
57
|
+
* @deprecated use sdk.names.normalizeLabel()
|
|
60
58
|
*
|
|
61
59
|
* @param str {string}
|
|
62
60
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function sleep(ms: number): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
exports.default = sleep;
|
|
40
|
+
function sleep(ms) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
|
45
|
+
case 1:
|
|
46
|
+
_a.sent();
|
|
47
|
+
return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createStateTransition;
|
|
4
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
5
|
+
function createStateTransition(voteWASM, proTxHash, identityNonce) {
|
|
6
|
+
var voterIdentity = pshenmic_dpp_1.IdentifierWASM.fromHex(proTxHash);
|
|
7
|
+
var masternodeVoteTransition = new pshenmic_dpp_1.MasternodeVoteTransitionWASM(proTxHash, voterIdentity, voteWASM, identityNonce);
|
|
8
|
+
return masternodeVoteTransition.toStateTransition();
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createVote;
|
|
4
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
5
|
+
function createVote(dataContractId, documentTypeName, indexName, indexValues, choice) {
|
|
6
|
+
var votePoll = new pshenmic_dpp_1.VotePollWASM(dataContractId, documentTypeName, indexName, indexValues);
|
|
7
|
+
return new pshenmic_dpp_1.VoteWASM(votePoll, choice);
|
|
8
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IdentifierLike, ResourceVoteChoice } from '../types';
|
|
2
|
+
import { IdentifierWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { VoteWASM } from 'pshenmic-dpp/dist/wasm/pshenmic_dpp';
|
|
4
|
+
/**
|
|
5
|
+
* Voting controller for performing masternode votes
|
|
6
|
+
*
|
|
7
|
+
* @hideconstructor
|
|
8
|
+
*/
|
|
9
|
+
export declare class VotingController {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
|
|
12
|
+
*
|
|
13
|
+
* @param proTxHash {string} voter's masternode pro tx hash
|
|
14
|
+
* @param publicKeyHash {string} voter address's public key hash
|
|
15
|
+
*
|
|
16
|
+
* @return {IdentifierWASM}
|
|
17
|
+
*/
|
|
18
|
+
createVoterIdentityId(proTxHash: string, publicKeyHash: string): IdentifierWASM;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
|
|
21
|
+
*
|
|
22
|
+
* @param dataContractId {DataContractWASM}
|
|
23
|
+
* @param documentTypeName {string}
|
|
24
|
+
* @param indexName {string}
|
|
25
|
+
* @param indexValues {string[]}
|
|
26
|
+
* @param choice {ResourceVoteChoice}
|
|
27
|
+
*/
|
|
28
|
+
createVote(dataContractId: IdentifierLike, documentTypeName: string, indexName: string, indexValues: string[], choice: ResourceVoteChoice): VoteWASM;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
|
|
31
|
+
*
|
|
32
|
+
* @param voteWASM {VoteWASM} vote instance from .createMsternodeVote() method
|
|
33
|
+
* @param proTxHash {string} pro tx hash of the masternode as hex
|
|
34
|
+
* @param voterIdentity {IdentifierWASM} voter identity identifier
|
|
35
|
+
* @param identityNonce {BigInt} identity nonce
|
|
36
|
+
*/
|
|
37
|
+
createStateTransition(voteWASM: VoteWASM, proTxHash: string, voterIdentity: IdentifierWASM, identityNonce: bigint): StateTransitionWASM;
|
|
38
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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");
|
|
7
|
+
/**
|
|
8
|
+
* Voting controller for performing masternode votes
|
|
9
|
+
*
|
|
10
|
+
* @hideconstructor
|
|
11
|
+
*/
|
|
12
|
+
var VotingController = /** @class */ (function () {
|
|
13
|
+
function VotingController() {
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
|
|
17
|
+
*
|
|
18
|
+
* @param proTxHash {string} voter's masternode pro tx hash
|
|
19
|
+
* @param publicKeyHash {string} voter address's public key hash
|
|
20
|
+
*
|
|
21
|
+
* @return {IdentifierWASM}
|
|
22
|
+
*/
|
|
23
|
+
VotingController.prototype.createVoterIdentityId = function (proTxHash, publicKeyHash) {
|
|
24
|
+
return (0, createVoterIdentityId_1.createVoterIdentityId)(proTxHash, publicKeyHash);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
|
|
28
|
+
*
|
|
29
|
+
* @param dataContractId {DataContractWASM}
|
|
30
|
+
* @param documentTypeName {string}
|
|
31
|
+
* @param indexName {string}
|
|
32
|
+
* @param indexValues {string[]}
|
|
33
|
+
* @param choice {ResourceVoteChoice}
|
|
34
|
+
*/
|
|
35
|
+
VotingController.prototype.createVote = function (dataContractId, documentTypeName, indexName, indexValues, choice) {
|
|
36
|
+
var resourceVoteChoice;
|
|
37
|
+
if (choice === 'lock') {
|
|
38
|
+
resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.Lock();
|
|
39
|
+
}
|
|
40
|
+
else if (choice === 'abstain') {
|
|
41
|
+
resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.Abstain();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
resourceVoteChoice = pshenmic_dpp_1.ResourceVoteChoiceWASM.TowardsIdentity(new pshenmic_dpp_1.IdentifierWASM(choice));
|
|
45
|
+
}
|
|
46
|
+
return (0, createVote_1.default)(new pshenmic_dpp_1.IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
|
|
50
|
+
*
|
|
51
|
+
* @param voteWASM {VoteWASM} vote instance from .createMsternodeVote() method
|
|
52
|
+
* @param proTxHash {string} pro tx hash of the masternode as hex
|
|
53
|
+
* @param voterIdentity {IdentifierWASM} voter identity identifier
|
|
54
|
+
* @param identityNonce {BigInt} identity nonce
|
|
55
|
+
*/
|
|
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);
|
|
58
|
+
return transition.toStateTransition();
|
|
59
|
+
};
|
|
60
|
+
return VotingController;
|
|
61
|
+
}());
|
|
62
|
+
exports.VotingController = VotingController;
|
|
@@ -36,14 +36,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var types_1 = require("../../src/types");
|
|
40
39
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
|
+
var types_1 = require("../../src/types");
|
|
41
41
|
var stringToIndexValueBytes_1 = require("../../src/utils/stringToIndexValueBytes");
|
|
42
42
|
var sdk;
|
|
43
43
|
var contract;
|
|
44
|
-
describe('Contested
|
|
44
|
+
describe('Contested Resources', function () {
|
|
45
45
|
beforeAll(function () {
|
|
46
|
-
sdk = new types_1.DashPlatformSDK();
|
|
46
|
+
sdk = new types_1.DashPlatformSDK({ network: 'testnet' });
|
|
47
47
|
contract = new pshenmic_dpp_1.DataContractWASM('11111111111111111111111111111111', BigInt(1), {
|
|
48
48
|
domain: {
|
|
49
49
|
type: 'object',
|
|
@@ -254,4 +254,85 @@ describe('Contested State', function () {
|
|
|
254
254
|
}
|
|
255
255
|
});
|
|
256
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
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
280
|
+
return [2 /*return*/];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}); });
|
|
284
|
+
test('should be able to create Abstain vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
285
|
+
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
switch (_a.label) {
|
|
288
|
+
case 0:
|
|
289
|
+
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
290
|
+
documentTypeName = 'domain';
|
|
291
|
+
indexName = 'parentNameAndLabel';
|
|
292
|
+
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
293
|
+
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
294
|
+
choice = 'abstain';
|
|
295
|
+
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
296
|
+
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
297
|
+
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
298
|
+
case 1:
|
|
299
|
+
voterIdentity = _a.sent();
|
|
300
|
+
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
301
|
+
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
302
|
+
case 2:
|
|
303
|
+
identityNonce = _a.sent();
|
|
304
|
+
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
305
|
+
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
306
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
307
|
+
return [2 /*return*/];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}); });
|
|
311
|
+
test('should be able to create Lock vote', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
312
|
+
var dataContactId, documentTypeName, indexName, indexValues, proTxHash, choice, privateKey, voterIdentifier, voterIdentity, identityPublicKey, identityNonce, vote, stateTransition;
|
|
313
|
+
return __generator(this, function (_a) {
|
|
314
|
+
switch (_a.label) {
|
|
315
|
+
case 0:
|
|
316
|
+
dataContactId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
317
|
+
documentTypeName = 'domain';
|
|
318
|
+
indexName = 'parentNameAndLabel';
|
|
319
|
+
indexValues = ['dash', sdk.names.normalizeLabel('testidentity')];
|
|
320
|
+
proTxHash = '559db949f305ae7ca1f2c3fafbde707a5adcb9ef7d53f99df4600d72b6bab965';
|
|
321
|
+
choice = 'lock';
|
|
322
|
+
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromHex('bf175afa03d3b3647e3480bb1feffb9d4a76c1e40eb2c2b0f8b5884b42dbe955', 'testnet');
|
|
323
|
+
voterIdentifier = sdk.voting.createVoterIdentityId(proTxHash, privateKey.getPublicKeyHash());
|
|
324
|
+
return [4 /*yield*/, sdk.identities.getIdentityByIdentifier(voterIdentifier)];
|
|
325
|
+
case 1:
|
|
326
|
+
voterIdentity = _a.sent();
|
|
327
|
+
identityPublicKey = voterIdentity.getPublicKeys().filter(function (identityPublicKey) { return privateKey.getPublicKeyHash() === identityPublicKey.getPublicKeyHash(); })[0];
|
|
328
|
+
return [4 /*yield*/, sdk.identities.getIdentityNonce(voterIdentity.id)];
|
|
329
|
+
case 2:
|
|
330
|
+
identityNonce = _a.sent();
|
|
331
|
+
vote = sdk.voting.createVote(dataContactId, documentTypeName, indexName, indexValues, choice);
|
|
332
|
+
stateTransition = sdk.voting.createStateTransition(vote, proTxHash, voterIdentity.id, identityNonce + BigInt(1));
|
|
333
|
+
stateTransition.sign(privateKey, identityPublicKey);
|
|
334
|
+
return [2 /*return*/];
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}); });
|
|
257
338
|
});
|
|
@@ -43,18 +43,6 @@ describe('Identity', function () {
|
|
|
43
43
|
beforeAll(function () {
|
|
44
44
|
sdk = new DashPlatformSDK_1.DashPlatformSDK();
|
|
45
45
|
});
|
|
46
|
-
test('should be able to search names by DPNS name', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
var document;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0: return [4 /*yield*/, sdk.names.search('xyz.dash')];
|
|
51
|
-
case 1:
|
|
52
|
-
document = _a.sent();
|
|
53
|
-
expect(document).toEqual(expect.any(pshenmic_dpp_1.DocumentWASM));
|
|
54
|
-
return [2 /*return*/];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}); });
|
|
58
46
|
test('should be able to get identity by identifier', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
47
|
var identifier, identity;
|
|
60
48
|
return __generator(this, function (_a) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
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 broadcast_1 = require("../../src/stateTransitions/broadcast");
|
|
40
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
+
var DashPlatformSDK_1 = require("../../src/DashPlatformSDK");
|
|
42
|
+
var sleep_1 = require("../../src/utils/sleep");
|
|
43
|
+
jest.mock('../../src/stateTransitions/broadcast');
|
|
44
|
+
jest.mock('../../src/utils/sleep');
|
|
45
|
+
var sdk;
|
|
46
|
+
describe('DPNS names', function () {
|
|
47
|
+
beforeAll(function () {
|
|
48
|
+
sdk = new DashPlatformSDK_1.DashPlatformSDK({ network: 'testnet' });
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
sleep_1.default.mockReturnValue(Promise.resolve());
|
|
51
|
+
sdk.stateTransitions.broadcast = jest.fn();
|
|
52
|
+
});
|
|
53
|
+
test('should be able to search names by identity identifier', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
var documents;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, sdk.names.searchByName('xyz.dash')];
|
|
58
|
+
case 1:
|
|
59
|
+
documents = _a.sent();
|
|
60
|
+
expect(documents === null || documents === void 0 ? void 0 : documents.length).toEqual(1);
|
|
61
|
+
expect(documents[0]).toEqual(expect.any(pshenmic_dpp_1.DocumentWASM));
|
|
62
|
+
return [2 /*return*/];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}); });
|
|
66
|
+
test('should be able to search names by DPNS name', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var documents, xyzDocument;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, sdk.names.searchByIdentity('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm')];
|
|
71
|
+
case 1:
|
|
72
|
+
documents = _a.sent();
|
|
73
|
+
expect(documents === null || documents === void 0 ? void 0 : documents.length).toEqual(3);
|
|
74
|
+
xyzDocument = documents[0];
|
|
75
|
+
expect(xyzDocument.ownerId.base58()).toEqual('36LGwPSXef8q8wpdnx4EdDeVNuqCYNAE9boDu5bxytsm');
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}); });
|
|
80
|
+
test('should be able to register a name', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var fullName, identityId, privateKey;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
fullName = 'test-identity-050.dash';
|
|
86
|
+
identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
87
|
+
privateKey = pshenmic_dpp_1.PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
88
|
+
return [4 /*yield*/, sdk.names.registerName(fullName, identityId, privateKey)];
|
|
89
|
+
case 1:
|
|
90
|
+
_a.sent();
|
|
91
|
+
expect(broadcast_1.default).toHaveBeenCalledTimes(2);
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}); });
|
|
96
|
+
});
|
package/src/names/search.d.ts
DELETED