dash-platform-sdk 1.2.0 → 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/bundle.min.js.LICENSE.txt +0 -4
- package/package.json +4 -7
- package/src/DashPlatformSDK.d.ts +2 -0
- package/src/DashPlatformSDK.js +2 -4
- 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/getContestedResourceVoteState.js +4 -5
- package/src/contestedResources/index.d.ts +1 -1
- package/src/dataContracts/getDataContractByIdentifier.js +8 -5
- package/src/documents/query.js +8 -9
- package/src/identities/getIdentityBalance.js +1 -2
- package/src/identities/getIdentityByIdentifier.js +2 -3
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +3 -5
- package/src/identities/getIdentityByPublicKeyHash.js +2 -3
- package/src/identities/getIdentityContractNonce.js +4 -5
- package/src/identities/getIdentityNonce.js +1 -2
- package/src/identities/getIdentityPublicKeys.js +5 -5
- 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/node/epochs.js +10 -4
- package/src/node/totalCredits.js +1 -2
- package/src/stateTransitions/waitForStateTransitionResult.js +13 -17
- package/src/tokens/getIdentitiesTokenBalances.js +1 -2
- package/src/tokens/getIdentityTokensBalances.js +1 -2
- package/src/tokens/getTokenContractInfo.js +2 -3
- package/src/tokens/getTokenTotalSupply.d.ts +1 -7
- package/src/tokens/getTokenTotalSupply.js +5 -6
- package/src/tokens/index.d.ts +1 -2
- package/src/types.d.ts +8 -2
- 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/utils/verifyTenderdashProof.js +3 -2
- 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
- package/src/utils/verifyBls.d.ts +0 -1
- package/src/utils/verifyBls.js +0 -15
package/src/names/index.js
CHANGED
|
@@ -37,7 +37,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.NamesController = void 0;
|
|
40
|
-
var
|
|
40
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
+
var searchByName_1 = require("./searchByName");
|
|
42
|
+
var searchByIdentity_1 = require("./searchByIdentity");
|
|
43
|
+
var registerName_1 = require("./registerName");
|
|
44
|
+
var validateName_1 = require("./validateName");
|
|
45
|
+
var getIdentityByIdentifier_1 = require("../identities/getIdentityByIdentifier");
|
|
46
|
+
var convertToHomographSafeChars_1 = require("../utils/convertToHomographSafeChars");
|
|
47
|
+
var testNameContested_1 = require("./testNameContested");
|
|
41
48
|
/**
|
|
42
49
|
* Functions related to DPNS names (usernames)
|
|
43
50
|
*
|
|
@@ -61,30 +68,93 @@ var NamesController = /** @class */ (function () {
|
|
|
61
68
|
*
|
|
62
69
|
* @return Promise<DocumentWASM | null>
|
|
63
70
|
*/
|
|
64
|
-
NamesController.prototype.
|
|
71
|
+
NamesController.prototype.searchByName = function (name) {
|
|
65
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var
|
|
67
|
-
return __generator(this, function (
|
|
68
|
-
switch (
|
|
73
|
+
var validation;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
69
76
|
case 0:
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
validation = (0, validateName_1.default)(name);
|
|
78
|
+
if (validation != null) {
|
|
79
|
+
throw new Error(validation);
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
return [4 /*yield*/, (0, searchByName_1.default)(this.grpcPool, name)];
|
|
82
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Tests a given username against contested names rules.
|
|
89
|
+
* Contested names includes an additional fee of 0.2 Dash
|
|
90
|
+
* as a voting resolution fee
|
|
91
|
+
*
|
|
92
|
+
* This function return boolean whether given username (f.e pshenmic.dash)
|
|
93
|
+
* falls under contested names rules.
|
|
94
|
+
* @param name
|
|
95
|
+
*/
|
|
96
|
+
NamesController.prototype.testNameContested = function (name) {
|
|
97
|
+
var validation = (0, validateName_1.default)(name);
|
|
98
|
+
if (validation != null) {
|
|
99
|
+
throw new Error(validation);
|
|
100
|
+
}
|
|
101
|
+
var label = name.split('.')[0];
|
|
102
|
+
var normalizedLabel = (0, convertToHomographSafeChars_1.default)(label);
|
|
103
|
+
return (0, testNameContested_1.default)(normalizedLabel);
|
|
104
|
+
};
|
|
105
|
+
NamesController.prototype.searchByIdentity = function (identifier) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0: return [4 /*yield*/, (0, searchByIdentity_1.default)(this.grpcPool, new pshenmic_dpp_1.IdentifierWASM(identifier))];
|
|
110
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Performs a DPNS name registration sequence
|
|
117
|
+
* Contested names are include additional fee of 0.2 Dash
|
|
118
|
+
* Check your name is contested with .testNameContested(name) method to check if additional fee will be charged
|
|
119
|
+
*
|
|
120
|
+
* @param name {string} username (ex. pshenmic.dash)
|
|
121
|
+
* @param identityId {IdentifierLike} identity identifier
|
|
122
|
+
* @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
|
|
123
|
+
*/
|
|
124
|
+
NamesController.prototype.registerName = function (name, identityId, privateKey) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
var validation, identity;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
validation = (0, validateName_1.default)(name);
|
|
131
|
+
if (validation != null) {
|
|
132
|
+
throw new Error(validation);
|
|
76
133
|
}
|
|
77
|
-
return [4 /*yield*/, (0,
|
|
134
|
+
return [4 /*yield*/, (0, getIdentityByIdentifier_1.default)(this.grpcPool, identityId)];
|
|
78
135
|
case 1:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return [2 /*return
|
|
136
|
+
identity = _a.sent();
|
|
137
|
+
return [4 /*yield*/, (0, registerName_1.default)(this.grpcPool, name, identity, privateKey)];
|
|
138
|
+
case 2:
|
|
139
|
+
_a.sent();
|
|
140
|
+
return [2 /*return*/];
|
|
84
141
|
}
|
|
85
142
|
});
|
|
86
143
|
});
|
|
87
144
|
};
|
|
145
|
+
/**
|
|
146
|
+
* Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
|
|
147
|
+
*
|
|
148
|
+
* source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
|
|
149
|
+
*
|
|
150
|
+
*
|
|
151
|
+
* @param label {string}
|
|
152
|
+
*
|
|
153
|
+
* @return {string}
|
|
154
|
+
*/
|
|
155
|
+
NamesController.prototype.normalizeLabel = function (label) {
|
|
156
|
+
return (0, convertToHomographSafeChars_1.default)(label);
|
|
157
|
+
};
|
|
88
158
|
return NamesController;
|
|
89
159
|
}());
|
|
90
160
|
exports.NamesController = NamesController;
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.default = registerName;
|
|
49
|
+
var convertToHomographSafeChars_1 = require("../utils/convertToHomographSafeChars");
|
|
50
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
51
|
+
var getRandomBytes_1 = require("../utils/getRandomBytes");
|
|
52
|
+
var sha256_1 = require("../utils/sha256");
|
|
53
|
+
var create_1 = require("../documents/create");
|
|
54
|
+
var createStateTransition_1 = require("../documents/createStateTransition");
|
|
55
|
+
var getIdentityContractNonce_1 = require("../identities/getIdentityContractNonce");
|
|
56
|
+
var broadcast_1 = require("../stateTransitions/broadcast");
|
|
57
|
+
var waitForStateTransitionResult_1 = require("../stateTransitions/waitForStateTransitionResult");
|
|
58
|
+
var testNameContested_1 = require("./testNameContested");
|
|
59
|
+
var constants_1 = require("../constants");
|
|
60
|
+
function registerName(grpcPool, name, identity, privateKey) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var identityPublicKey, _a, label, parentDomainName, salt, normalizedParentDomainName, normalizedLabel, normalizedFullDomainName, saltedDomainHash, document, stateTransition, preorderData, identityContractNonce, domainData;
|
|
63
|
+
return __generator(this, function (_b) {
|
|
64
|
+
switch (_b.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
identityPublicKey = identity.getPublicKeys().filter(function (identityPublicKey) { return identityPublicKey.getPublicKeyHash() === privateKey.getPublicKeyHash(); })[0];
|
|
67
|
+
if (identityPublicKey == null) {
|
|
68
|
+
throw new Error('Private key does not match the identity');
|
|
69
|
+
}
|
|
70
|
+
if (identityPublicKey.securityLevel !== 'HIGH' && identityPublicKey.purpose !== 'AUTHENTICATION') {
|
|
71
|
+
throw new Error('Wrong private key, must be from AUTHENTICATION HIGH identity public key');
|
|
72
|
+
}
|
|
73
|
+
_a = name.split('.'), label = _a[0], parentDomainName = _a[1];
|
|
74
|
+
salt = (0, getRandomBytes_1.default)(32);
|
|
75
|
+
normalizedParentDomainName = (0, convertToHomographSafeChars_1.default)(parentDomainName);
|
|
76
|
+
normalizedLabel = (0, convertToHomographSafeChars_1.default)(label);
|
|
77
|
+
normalizedFullDomainName = "".concat(normalizedLabel, ".").concat(normalizedParentDomainName);
|
|
78
|
+
saltedDomainHash = (0, sha256_1.default)((0, sha256_1.default)(new Uint8Array(__spreadArray(__spreadArray([], salt, true), new TextEncoder().encode(normalizedFullDomainName), true))));
|
|
79
|
+
preorderData = {
|
|
80
|
+
saltedDomainHash: Array.from(saltedDomainHash)
|
|
81
|
+
};
|
|
82
|
+
return [4 /*yield*/, (0, getIdentityContractNonce_1.default)(grpcPool, identity.id, constants_1.DPNS_DATA_CONTRACT_ID)];
|
|
83
|
+
case 1:
|
|
84
|
+
identityContractNonce = _b.sent();
|
|
85
|
+
document = (0, create_1.default)(constants_1.DPNS_DATA_CONTRACT_ID, 'preorder', preorderData, identity.id.base58());
|
|
86
|
+
stateTransition = (0, createStateTransition_1.default)(document, 'create', { identityContractNonce: identityContractNonce + BigInt(1) });
|
|
87
|
+
return [4 /*yield*/, stateTransition.sign(privateKey, identityPublicKey)];
|
|
88
|
+
case 2:
|
|
89
|
+
_b.sent();
|
|
90
|
+
return [4 /*yield*/, (0, broadcast_1.default)(grpcPool, stateTransition)
|
|
91
|
+
// wait for state transition confirmation before next broadcast
|
|
92
|
+
];
|
|
93
|
+
case 3:
|
|
94
|
+
_b.sent();
|
|
95
|
+
// wait for state transition confirmation before next broadcast
|
|
96
|
+
return [4 /*yield*/, (0, waitForStateTransitionResult_1.default)(grpcPool, stateTransition)
|
|
97
|
+
// 2. Create domain document
|
|
98
|
+
];
|
|
99
|
+
case 4:
|
|
100
|
+
// wait for state transition confirmation before next broadcast
|
|
101
|
+
_b.sent();
|
|
102
|
+
domainData = {
|
|
103
|
+
label: label,
|
|
104
|
+
normalizedLabel: normalizedLabel,
|
|
105
|
+
parentDomainName: parentDomainName,
|
|
106
|
+
normalizedParentDomainName: normalizedParentDomainName,
|
|
107
|
+
preorderSalt: Array.from(salt),
|
|
108
|
+
records: {
|
|
109
|
+
identity: Array.from(identity.id.bytes())
|
|
110
|
+
},
|
|
111
|
+
subdomainRules: {
|
|
112
|
+
allowSubdomains: false
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
document = (0, create_1.default)(constants_1.DPNS_DATA_CONTRACT_ID, 'domain', domainData, identity.id.base58());
|
|
116
|
+
stateTransition = (0, createStateTransition_1.default)(document, 'create', {
|
|
117
|
+
identityContractNonce: identityContractNonce + BigInt(2),
|
|
118
|
+
// @ts-expect-error
|
|
119
|
+
prefundedVotingBalance: (0, testNameContested_1.default)(normalizedLabel) ? new pshenmic_dpp_1.PrefundedVotingBalanceWASM('parentNameAndLabel', BigInt(20000000000)) : undefined
|
|
120
|
+
});
|
|
121
|
+
return [4 /*yield*/, stateTransition.sign(privateKey, identityPublicKey)];
|
|
122
|
+
case 5:
|
|
123
|
+
_b.sent();
|
|
124
|
+
return [4 /*yield*/, (0, broadcast_1.default)(grpcPool, stateTransition)];
|
|
125
|
+
case 6:
|
|
126
|
+
_b.sent();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
@@ -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 = search;
|
|
40
|
+
var query_1 = require("../documents/query");
|
|
41
|
+
var DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
42
|
+
function search(grpcPool, identifier) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0: return [4 /*yield*/, (0, query_1.default)(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', [['records.identity', '=', identifier.base58()]], [['records.identity', 'asc']])];
|
|
47
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -40,12 +40,13 @@ exports.default = search;
|
|
|
40
40
|
var convertToHomographSafeChars_1 = require("../utils/convertToHomographSafeChars");
|
|
41
41
|
var query_1 = require("../documents/query");
|
|
42
42
|
var DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
43
|
-
function search(grpcPool,
|
|
43
|
+
function search(grpcPool, name) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
var normalizedParentDomainName, normalizedLabelPrefix, where, orderBy;
|
|
46
|
-
return __generator(this, function (
|
|
47
|
-
switch (
|
|
45
|
+
var _a, label, parentDomainName, normalizedParentDomainName, normalizedLabelPrefix, where, orderBy;
|
|
46
|
+
return __generator(this, function (_b) {
|
|
47
|
+
switch (_b.label) {
|
|
48
48
|
case 0:
|
|
49
|
+
_a = name.split('.'), label = _a[0], parentDomainName = _a[1];
|
|
49
50
|
normalizedParentDomainName = (0, convertToHomographSafeChars_1.default)(parentDomainName);
|
|
50
51
|
normalizedLabelPrefix = (0, convertToHomographSafeChars_1.default)(label);
|
|
51
52
|
where = [
|
|
@@ -56,7 +57,7 @@ function search(grpcPool, label, parentDomainName) {
|
|
|
56
57
|
['normalizedLabel', 'asc']
|
|
57
58
|
];
|
|
58
59
|
return [4 /*yield*/, (0, query_1.default)(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', where, orderBy)];
|
|
59
|
-
case 1: return [2 /*return*/,
|
|
60
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function testNameContested(normalizedLabel: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function validateName(fullName: string): string | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = validateName;
|
|
4
|
+
function validateName(fullName) {
|
|
5
|
+
var chunks = fullName.split('.');
|
|
6
|
+
if (chunks.length !== 2) {
|
|
7
|
+
return 'Name to search should be a full domain name (ex. pshenmic.dash)';
|
|
8
|
+
}
|
|
9
|
+
var parentDomainName = chunks[1];
|
|
10
|
+
if (parentDomainName !== 'dash') {
|
|
11
|
+
return 'Root domain must be .dash';
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
package/src/node/epochs.js
CHANGED
|
@@ -38,14 +38,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = epochs;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
42
41
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
43
42
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
43
|
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
44
|
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
45
|
function epochs(grpcPool, count, ascending, start) {
|
|
47
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var request, v0, _a, proof, metadata, _b, rootHash,
|
|
47
|
+
var request, v0, _a, proof, metadata, _b, rootHash, epochsInfo, quorumPublicKey, verify;
|
|
49
48
|
return __generator(this, function (_c) {
|
|
50
49
|
switch (_c.label) {
|
|
51
50
|
case 0:
|
|
@@ -67,7 +66,7 @@ function epochs(grpcPool, count, ascending, start) {
|
|
|
67
66
|
if (metadata == null) {
|
|
68
67
|
throw new Error('Metadata not found');
|
|
69
68
|
}
|
|
70
|
-
_b = (0,
|
|
69
|
+
_b = (0, pshenmic_dpp_1.verifyEpochsInfoProof)(proof.grovedbProof, metadata.epoch, start, count, ascending, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, epochsInfo = _b.epochsInfo;
|
|
71
70
|
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
71
|
case 2:
|
|
73
72
|
quorumPublicKey = _c.sent();
|
|
@@ -75,7 +74,14 @@ function epochs(grpcPool, count, ascending, start) {
|
|
|
75
74
|
if (!verify) {
|
|
76
75
|
throw new Error('Failed to verify query');
|
|
77
76
|
}
|
|
78
|
-
return [2 /*return*/,
|
|
77
|
+
return [2 /*return*/, epochsInfo.map(function (info) { return ({
|
|
78
|
+
number: info.index,
|
|
79
|
+
firstBlockHeight: info.firstBlockHeight,
|
|
80
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
81
|
+
startTime: info.firstBlockTime,
|
|
82
|
+
feeMultiplier: info.feeMultiplierPermille,
|
|
83
|
+
protocolVersion: info.protocolVersion
|
|
84
|
+
}); })];
|
|
79
85
|
}
|
|
80
86
|
});
|
|
81
87
|
});
|
package/src/node/totalCredits.js
CHANGED
|
@@ -38,7 +38,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = totalCredits;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
42
41
|
var constants_1 = require("../constants");
|
|
43
42
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
44
43
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
@@ -62,7 +61,7 @@ function totalCredits(grpcPool, network) {
|
|
|
62
61
|
throw new Error('Metadata not found');
|
|
63
62
|
}
|
|
64
63
|
activationHeight = network === 'testnet' ? constants_1.TESTNET_ACTIVATION_HEIGHT : constants_1.MAINNET_ACTIVATION_HEIGHT;
|
|
65
|
-
_b = (0,
|
|
64
|
+
_b = (0, pshenmic_dpp_1.verifyTotalCreditsProof)(proof.grovedbProof, constants_1.HALVING_INTERVAL, activationHeight, Number(metadata.height), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, totalCredits = _b.totalCredits;
|
|
66
65
|
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
67
66
|
case 2:
|
|
68
67
|
quorumPublicKey = _c.sent();
|
|
@@ -37,27 +37,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = waitForStateTransitionResult;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
40
|
function waitForStateTransitionResult(grpcPool, stateTransition) {
|
|
42
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var
|
|
44
|
-
return __generator(this, function (
|
|
45
|
-
switch (
|
|
42
|
+
var url, resp, _a, _b;
|
|
43
|
+
return __generator(this, function (_c) {
|
|
44
|
+
switch (_c.label) {
|
|
46
45
|
case 0:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
stateTransitionHash: stateTransition.bytes()
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return [4 /*yield*/, grpcPool.getClient().waitForStateTransitionResult(waitForStateTransitionResultRequest)];
|
|
46
|
+
url = "https://".concat(grpcPool.network === 'mainnet' ? '' : 'testnet.', "platform-explorer.pshenmic.dev/waitForStateTransitionResult/").concat(stateTransition.hash(false));
|
|
47
|
+
return [4 /*yield*/, fetch(url)];
|
|
53
48
|
case 1:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
resp = _c.sent();
|
|
50
|
+
if (!(resp.status !== 200)) return [3 /*break*/, 3];
|
|
51
|
+
_b = (_a = console).log;
|
|
52
|
+
return [4 /*yield*/, resp.json()];
|
|
53
|
+
case 2:
|
|
54
|
+
_b.apply(_a, [_c.sent()]);
|
|
55
|
+
throw new Error('Internal server error while waiting for state transition result');
|
|
56
|
+
case 3: return [2 /*return*/];
|
|
61
57
|
}
|
|
62
58
|
});
|
|
63
59
|
});
|
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = getIdentitiesTokenBalances;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
41
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
43
42
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
43
|
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
44
|
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
@@ -68,7 +67,7 @@ function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
|
68
67
|
if (metadata == null) {
|
|
69
68
|
throw new Error('Metadata not found');
|
|
70
69
|
}
|
|
71
|
-
_b = (0,
|
|
70
|
+
_b = (0, pshenmic_dpp_1.verifyTokenBalancesForIdentitiesProof)(proof.grovedbProof, tokenId, true, ids, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, balances = _b.balances;
|
|
72
71
|
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
72
|
case 2:
|
|
74
73
|
quorumPublicKey = _c.sent();
|
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = getIdentityTokensBalances;
|
|
40
40
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
41
|
var platform_1 = require("../../proto/generated/platform");
|
|
42
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
43
42
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
43
|
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
44
|
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
@@ -68,7 +67,7 @@ function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
|
68
67
|
if (metadata == null) {
|
|
69
68
|
throw new Error('Metadata not found');
|
|
70
69
|
}
|
|
71
|
-
_b = (0,
|
|
70
|
+
_b = (0, pshenmic_dpp_1.verifyTokensBalancesForIdentityProof)(proof.grovedbProof, tokenIds, id, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, balances = _b.balances;
|
|
72
71
|
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
72
|
case 2:
|
|
74
73
|
quorumPublicKey = _c.sent();
|
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = getTokenContractInfo;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
41
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
43
42
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
43
|
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
44
|
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
@@ -66,7 +65,7 @@ function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
|
66
65
|
if (metadata == null) {
|
|
67
66
|
throw new Error('Metadata not found');
|
|
68
67
|
}
|
|
69
|
-
_b = (0,
|
|
68
|
+
_b = (0, pshenmic_dpp_1.verifyTokenContractInfoProof)(proof.grovedbProof, tokenId, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, contractInfo = _b.contractInfo;
|
|
70
69
|
if (contractInfo == null) {
|
|
71
70
|
throw new Error('ContractInfo not found');
|
|
72
71
|
}
|
|
@@ -78,7 +77,7 @@ function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
|
78
77
|
throw new Error('Failed to verify query');
|
|
79
78
|
}
|
|
80
79
|
return [2 /*return*/, {
|
|
81
|
-
dataContractId:
|
|
80
|
+
dataContractId: contractInfo.contractId,
|
|
82
81
|
tokenContractPosition: contractInfo.tokenContractPosition
|
|
83
82
|
}];
|
|
84
83
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
3
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
|
-
export interface TokenTotalSupply {
|
|
5
|
-
tokenId: IdentifierWASM;
|
|
6
|
-
totalSystemAmount: string;
|
|
7
|
-
totalAggregatedAmountInUserAccounts: string;
|
|
8
|
-
}
|
|
2
|
+
import { IdentifierLike, TokenTotalSupply } from '../types';
|
|
9
3
|
export default function getTokenTotalSupply(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
@@ -39,13 +39,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = getTokenTotalSupply;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
41
|
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
43
42
|
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
43
|
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
44
|
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
45
|
function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
47
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var tokenId, request, v0, _a, proof, metadata, _b, rootHash,
|
|
47
|
+
var tokenId, request, v0, _a, proof, metadata, _b, rootHash, totalBalance, quorumPublicKey, verify;
|
|
49
48
|
return __generator(this, function (_c) {
|
|
50
49
|
switch (_c.label) {
|
|
51
50
|
case 0:
|
|
@@ -66,7 +65,7 @@ function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
|
66
65
|
if (metadata == null) {
|
|
67
66
|
throw new Error('Metadata not found');
|
|
68
67
|
}
|
|
69
|
-
_b = (0,
|
|
68
|
+
_b = (0, pshenmic_dpp_1.verifyTokenTotalSupplyProof)(proof.grovedbProof, tokenId, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, totalBalance = _b.totalBalance;
|
|
70
69
|
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
71
70
|
case 2:
|
|
72
71
|
quorumPublicKey = _c.sent();
|
|
@@ -75,9 +74,9 @@ function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
|
75
74
|
throw new Error('Failed to verify query');
|
|
76
75
|
}
|
|
77
76
|
return [2 /*return*/, {
|
|
78
|
-
tokenId:
|
|
79
|
-
totalSystemAmount:
|
|
80
|
-
totalAggregatedAmountInUserAccounts:
|
|
77
|
+
tokenId: tokenId,
|
|
78
|
+
totalSystemAmount: totalBalance.tokenSupply,
|
|
79
|
+
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
81
80
|
}];
|
|
82
81
|
}
|
|
83
82
|
});
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
2
|
+
import { IdentifierLike, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
3
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances';
|
|
4
4
|
import { IdentityTokenBalances } from './getIdentityTokensBalances';
|
|
5
5
|
import { TokenContractInfo } from './getTokenContractInfo';
|
|
6
|
-
import { TokenTotalSupply } from './getTokenTotalSupply';
|
|
7
6
|
import { StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
8
7
|
/**
|
|
9
8
|
* Tokens controller for requesting information about tokens and tokens holders
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
1
|
+
import { DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { Versions } from 'dashhd';
|
|
3
3
|
export { IdentifierWASM, IdentityWASM, DocumentWASM, DataContractWASM, StateTransitionWASM, IdentityPublicKeyWASM } from 'pshenmic-dpp';
|
|
4
4
|
export type IdentifierLike = IdentifierWASM | string | Uint8Array;
|
|
@@ -115,7 +115,7 @@ export declare enum FinishedVoteOutcome {
|
|
|
115
115
|
export interface Contender {
|
|
116
116
|
identifier: IdentifierWASM;
|
|
117
117
|
voteCount?: number | undefined;
|
|
118
|
-
document?: Uint8Array;
|
|
118
|
+
document?: Uint8Array | DocumentWASM;
|
|
119
119
|
}
|
|
120
120
|
export interface FinishedVoteInfo {
|
|
121
121
|
type: string;
|
|
@@ -195,3 +195,9 @@ export interface IdentityTransitionParams {
|
|
|
195
195
|
identityId?: IdentifierLike;
|
|
196
196
|
userFeeIncrease?: number;
|
|
197
197
|
}
|
|
198
|
+
export interface TokenTotalSupply {
|
|
199
|
+
tokenId: IdentifierWASM;
|
|
200
|
+
totalSystemAmount: bigint;
|
|
201
|
+
totalAggregatedAmountInUserAccounts: bigint;
|
|
202
|
+
}
|
|
203
|
+
export type ResourceVoteChoice = IdentifierLike | 'lock' | 'abstain';
|