dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.5
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 +21 -2
- package/package.json +29 -30
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/node/index.d.ts +3 -3
- package/src/node/totalCredits.d.ts +2 -1
- package/src/types.d.ts +6 -12
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/index.d.ts +3 -4
- package/bundle.min.js.LICENSE.txt +0 -1
- package/index.js +0 -5
- package/proto/generated/google/protobuf/wrappers.js +0 -398
- package/proto/generated/platform.js +0 -18524
- package/src/DashPlatformSDK.js +0 -91
- package/src/constants.js +0 -13
- package/src/contestedResources/createStateTransition.js +0 -9
- package/src/contestedResources/getContestedResourceVoteState.js +0 -123
- package/src/contestedResources/index.js +0 -76
- package/src/dataContracts/create.js +0 -14
- package/src/dataContracts/createStateTransition.js +0 -23
- package/src/dataContracts/getDataContractByIdentifier.js +0 -87
- package/src/dataContracts/index.js +0 -103
- package/src/documents/create.js +0 -7
- package/src/documents/createStateTransition.js +0 -64
- package/src/documents/index.js +0 -130
- package/src/documents/query.js +0 -94
- package/src/grpcConnectionPool.js +0 -137
- package/src/identities/createStateTransition.js +0 -46
- package/src/identities/getIdentityBalance.js +0 -83
- package/src/identities/getIdentityByIdentifier.js +0 -83
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +0 -85
- package/src/identities/getIdentityByPublicKeyHash.js +0 -83
- package/src/identities/getIdentityContractNonce.js +0 -86
- package/src/identities/getIdentityNonce.js +0 -84
- package/src/identities/getIdentityPublicKeys.js +0 -85
- package/src/identities/index.js +0 -237
- package/src/keyPair/deriveChild.js +0 -50
- package/src/keyPair/derivePath.js +0 -50
- package/src/keyPair/index.js +0 -323
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToSeed.js +0 -47
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
- package/src/names/index.js +0 -170
- package/src/names/registerName.js +0 -131
- package/src/names/searchByIdentity.js +0 -51
- package/src/names/searchByName.js +0 -64
- package/src/names/testNameContested.js +0 -6
- package/src/names/validateName.js +0 -14
- package/src/node/epochs.js +0 -88
- package/src/node/index.js +0 -102
- package/src/node/status.js +0 -85
- package/src/node/totalCredits.js +0 -76
- package/src/signer/AbstractSigner.js +0 -2
- package/src/signer/PrivateKeySigner.d.ts +0 -0
- package/src/signer/PrivateKeySigner.js +0 -64
- package/src/signer/setSigner.js +0 -8
- package/src/stateTransitions/broadcast.js +0 -60
- package/src/stateTransitions/index.js +0 -87
- package/src/stateTransitions/waitForStateTransitionResult.js +0 -60
- package/src/tokens/createStateTransition.js +0 -79
- package/src/tokens/getIdentitiesTokenBalances.js +0 -86
- package/src/tokens/getIdentityTokensBalances.js +0 -86
- package/src/tokens/getTokenContractInfo.js +0 -86
- package/src/tokens/getTokenDirectPurchasePrices.js +0 -83
- package/src/tokens/getTokenTotalSupply.js +0 -84
- package/src/tokens/index.js +0 -193
- package/src/types.js +0 -25
- package/src/utils/base58ToBytes.js +0 -7
- package/src/utils/bytesToHex.js +0 -6
- package/src/utils/calculateMsgHash.js +0 -34
- package/src/utils/calculateSignHash.js +0 -11
- package/src/utils/calculateStateIdHash.js +0 -12
- package/src/utils/convertToHomographSafeChars.js +0 -14
- package/src/utils/createVoterIdentityId.js +0 -12
- package/src/utils/getEvonodeList.js +0 -63
- package/src/utils/getQuorumPublicKey.js +0 -69
- package/src/utils/getRandomArrayItem.js +0 -6
- package/src/utils/getRandomBytes.js +0 -7
- package/src/utils/hexToBytes.js +0 -7
- package/src/utils/index.js +0 -68
- package/src/utils/indexBytesToString.js +0 -7
- package/src/utils/sha256.js +0 -13
- package/src/utils/signHash.js +0 -25
- package/src/utils/signRequestId.js +0 -22
- package/src/utils/sleep.js +0 -51
- package/src/utils/stringToIndexValueBytes.js +0 -13
- package/src/utils/verifyTenderdashProof.js +0 -30
- package/src/voting/createStateTransition.js +0 -9
- package/src/voting/createVote.js +0 -8
- package/src/voting/index.js +0 -62
- package/test/unit/ContestedResources.spec.js +0 -344
- package/test/unit/DataContract.spec.js +0 -142
- package/test/unit/Document.spec.js +0 -199
- package/test/unit/Identity.spec.js +0 -357
- package/test/unit/KeyPair.spec.js +0 -149
- package/test/unit/Names.spec.js +0 -96
- package/test/unit/Node.spec.js +0 -129
- package/test/unit/SDK.spec.js +0 -12
- package/test/unit/Tokens.spec.js +0 -288
package/src/documents/index.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
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.DocumentsController = void 0;
|
|
40
|
-
var create_1 = require("./create");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var createStateTransition_1 = require("./createStateTransition");
|
|
43
|
-
var query_1 = require("./query");
|
|
44
|
-
/**
|
|
45
|
-
* Collection of methods to work with documents like creation, querying or preparing a transition action
|
|
46
|
-
*
|
|
47
|
-
* @hideconstructor
|
|
48
|
-
*/
|
|
49
|
-
var DocumentsController = /** @class */ (function () {
|
|
50
|
-
function DocumentsController(grpcPool) {
|
|
51
|
-
this.grpcPool = grpcPool;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Creates a {DocumentWASM} instance that can be used to submit a document in the network.
|
|
55
|
-
*
|
|
56
|
-
* @param dataContractId {IdentifierLike} Identifier of the Data Contract
|
|
57
|
-
* @param documentType {string} Document type as string
|
|
58
|
-
* @param data {object} Data as JSON object
|
|
59
|
-
* @param owner {IdentifierLike} Identifier of the document's owner
|
|
60
|
-
* @param revision {bigint=} revision (optional)
|
|
61
|
-
*
|
|
62
|
-
* @return {DataContractWASM}
|
|
63
|
-
*/
|
|
64
|
-
DocumentsController.prototype.create = function (dataContractId, documentType, data, owner, revision) {
|
|
65
|
-
return (0, create_1.default)(new pshenmic_dpp_1.IdentifierWASM(dataContractId), documentType, data, new pshenmic_dpp_1.IdentifierWASM(owner), revision);
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Make a query for documents retrieval from the network.
|
|
69
|
-
*
|
|
70
|
-
* @param dataContractId {IdentifierLike} Identifier of the Data Contract where fetch documents from
|
|
71
|
-
* @param documentType {string} Document type of the data contract
|
|
72
|
-
* @param where {object=} Where query clauses according syntax https://docs.dash.org/projects/platform/en/stable/docs/reference/query-syntax.html
|
|
73
|
-
* @param orderBy {object=} Order by clauses according syntax https://docs.dash.org/projects/platform/en/stable/docs/reference/query-syntax.html
|
|
74
|
-
* @param limit {number=} Limit amount of documents per request
|
|
75
|
-
* @param startAt {IdentifierLike=} Optional offset, where startAt is an identifier of the document. Use identifier of last item in previous response
|
|
76
|
-
* @param startAfter {IdentifierLike=} Same as previous, but with exclusion. Cannot be set if startAt already provided
|
|
77
|
-
*/
|
|
78
|
-
DocumentsController.prototype.query = function (dataContractId, documentType, where, orderBy, limit, startAt, startAfter) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
-
return __generator(this, function (_a) {
|
|
81
|
-
switch (_a.label) {
|
|
82
|
-
case 0:
|
|
83
|
-
if (startAfter != null && startAt !== null) {
|
|
84
|
-
throw new Error('You may only set either startAfter or startAt at once');
|
|
85
|
-
}
|
|
86
|
-
return [4 /*yield*/, (0, query_1.default)(this.grpcPool, new pshenmic_dpp_1.IdentifierWASM(dataContractId), documentType, where, orderBy, limit !== null && limit !== void 0 ? limit : 100, startAt, startAfter)];
|
|
87
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Helper function for creating {StateTransitionWASM} from documents. It may be used to create any of 6 Document Transition actions:
|
|
94
|
-
*
|
|
95
|
-
* 1) Create - creates a document
|
|
96
|
-
* 2) Replace - replaces a document
|
|
97
|
-
* 3) Delete - deletes a document
|
|
98
|
-
* 4) Transfer - transfer a document from one identity to another
|
|
99
|
-
* 5) SetPrice - set a price for a document in credits
|
|
100
|
-
* 6) Purchase - purchase a document from identity (if price was set)
|
|
101
|
-
*
|
|
102
|
-
* @param document {DocumentWASM} Instance of the document to make transition with
|
|
103
|
-
* @param type {string} Type of the document transition, must be a one of ('create' | 'replace' | 'delete' | 'updatePrice' |'transfer' | 'purchase')
|
|
104
|
-
* @param params {DocumentTransitionParams} params
|
|
105
|
-
*/
|
|
106
|
-
DocumentsController.prototype.createStateTransition = function (document, type, params) {
|
|
107
|
-
if (type === 'transfer' && params.recipientId == null) {
|
|
108
|
-
throw new Error('Recipient is required for transfer transition');
|
|
109
|
-
}
|
|
110
|
-
if (type === 'updatePrice' && params.price == null) {
|
|
111
|
-
throw new Error('Price is required for updatePrice transition');
|
|
112
|
-
}
|
|
113
|
-
if (type === 'purchase' && params.amount == null) {
|
|
114
|
-
throw new Error('Amount is required for updatePrice transition');
|
|
115
|
-
}
|
|
116
|
-
if (params.prefundedVotingBalance != null) {
|
|
117
|
-
var _a = params.prefundedVotingBalance, indexName = _a.indexName, amount = _a.amount;
|
|
118
|
-
// @ts-expect-error
|
|
119
|
-
params.prefundedVotingBalance = new pshenmic_dpp_1.PrefundedVotingBalanceWASM(indexName, amount);
|
|
120
|
-
}
|
|
121
|
-
if (params.tokenPaymentInfo != null) {
|
|
122
|
-
var _b = params.tokenPaymentInfo, tokenContractId = _b.tokenContractId, tokenContractPosition = _b.tokenContractPosition, minimumTokenCost = _b.minimumTokenCost, maximumTokenCost = _b.maximumTokenCost, gasFeesPaidBy = _b.gasFeesPaidBy;
|
|
123
|
-
// @ts-expect-error
|
|
124
|
-
params.tokenPaymentInfo = new pshenmic_dpp_1.TokenPaymentInfoWASM(new pshenmic_dpp_1.IdentifierWASM(tokenContractId), tokenContractPosition, minimumTokenCost, maximumTokenCost, gasFeesPaidBy);
|
|
125
|
-
}
|
|
126
|
-
return (0, createStateTransition_1.default)(document, type, params);
|
|
127
|
-
};
|
|
128
|
-
return DocumentsController;
|
|
129
|
-
}());
|
|
130
|
-
exports.DocumentsController = DocumentsController;
|
package/src/documents/query.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
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 = query;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var constants_1 = require("../constants");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
|
-
var cbor_x_1 = require("cbor-x");
|
|
47
|
-
var getDataContractByIdentifier_1 = require("../dataContracts/getDataContractByIdentifier");
|
|
48
|
-
function query(grpcPool_1, dataContractId_1, documentTypeName_1, where_1, orderBy_1) {
|
|
49
|
-
return __awaiter(this, arguments, void 0, function (grpcPool, dataContractId, documentTypeName, where, orderBy, limit, startAt, startAfter) {
|
|
50
|
-
var getDocumentsRequest, dataContract, v0, _a, proof, metadata, startAtIncluded, _b, rootHash, documents, quorumPublicKey, verify;
|
|
51
|
-
var _c, _d;
|
|
52
|
-
if (limit === void 0) { limit = 100; }
|
|
53
|
-
return __generator(this, function (_e) {
|
|
54
|
-
switch (_e.label) {
|
|
55
|
-
case 0:
|
|
56
|
-
getDocumentsRequest = platform_1.GetDocumentsRequest.fromPartial({
|
|
57
|
-
v0: {
|
|
58
|
-
dataContractId: (new pshenmic_dpp_1.IdentifierWASM(dataContractId)).bytes(),
|
|
59
|
-
documentType: documentTypeName,
|
|
60
|
-
where: (where != null) ? (0, cbor_x_1.encode)(where) : undefined,
|
|
61
|
-
orderBy: (orderBy != null) ? (0, cbor_x_1.encode)(orderBy) : undefined,
|
|
62
|
-
limit: limit !== null && limit !== void 0 ? limit : constants_1.DAPI_DEFAULT_LIMIT,
|
|
63
|
-
startAt: (startAt != null) ? startAt.bytes() : undefined,
|
|
64
|
-
startAfter: (startAfter != null) ? startAfter.bytes() : undefined,
|
|
65
|
-
prove: true
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return [4 /*yield*/, (0, getDataContractByIdentifier_1.default)(grpcPool, dataContractId)];
|
|
69
|
-
case 1:
|
|
70
|
-
dataContract = _e.sent();
|
|
71
|
-
return [4 /*yield*/, grpcPool.getClient().getDocuments(getDocumentsRequest)];
|
|
72
|
-
case 2:
|
|
73
|
-
v0 = (_e.sent()).v0;
|
|
74
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
75
|
-
if (proof == null) {
|
|
76
|
-
throw new Error('Proof not found');
|
|
77
|
-
}
|
|
78
|
-
if (metadata == null) {
|
|
79
|
-
throw new Error('Metadata not found');
|
|
80
|
-
}
|
|
81
|
-
startAtIncluded = ((_c = getDocumentsRequest.v0) === null || _c === void 0 ? void 0 : _c.startAfter) == null;
|
|
82
|
-
_b = (0, pshenmic_dpp_1.verifyDocumentsProof)(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, (_d = getDocumentsRequest.v0) === null || _d === void 0 ? void 0 : _d.startAt, startAtIncluded, BigInt(metadata === null || metadata === void 0 ? void 0 : metadata.timeMs), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, documents = _b.documents;
|
|
83
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
84
|
-
case 3:
|
|
85
|
-
quorumPublicKey = _e.sent();
|
|
86
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
87
|
-
if (!verify) {
|
|
88
|
-
throw new Error('Failed to verify query');
|
|
89
|
-
}
|
|
90
|
-
return [2 /*return*/, documents !== null && documents !== void 0 ? documents : []];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
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 getRandomArrayItem_1 = require("./utils/getRandomArrayItem");
|
|
40
|
-
var nice_grpc_web_1 = require("nice-grpc-web");
|
|
41
|
-
var platform_1 = require("../proto/generated/platform");
|
|
42
|
-
var getEvonodeList_1 = require("./utils/getEvonodeList");
|
|
43
|
-
var constants_1 = require("./constants");
|
|
44
|
-
var seedNodes = {
|
|
45
|
-
testnet: [
|
|
46
|
-
// seed-1.pshenmic.dev
|
|
47
|
-
'https://158.160.14.115:1443'
|
|
48
|
-
],
|
|
49
|
-
mainnet: [
|
|
50
|
-
// seed-1.pshenmic.dev
|
|
51
|
-
'https://158.160.14.115:443'
|
|
52
|
-
// mainnet dcg seeds
|
|
53
|
-
// 'https://158.160.14.115',
|
|
54
|
-
// 'https://3.0.60.103',
|
|
55
|
-
// 'https://34.211.174.194'
|
|
56
|
-
]
|
|
57
|
-
};
|
|
58
|
-
var GRPCConnectionPool = /** @class */ (function () {
|
|
59
|
-
function GRPCConnectionPool(network, grpcOptions) {
|
|
60
|
-
var _a;
|
|
61
|
-
var grpcPoolLimit = (_a = grpcOptions === null || grpcOptions === void 0 ? void 0 : grpcOptions.poolLimit) !== null && _a !== void 0 ? _a : constants_1.GRPC_DEFAULT_POOL_LIMIT;
|
|
62
|
-
this.network = network;
|
|
63
|
-
this._initialize(network, grpcPoolLimit, grpcOptions === null || grpcOptions === void 0 ? void 0 : grpcOptions.dapiUrl).catch(console.error);
|
|
64
|
-
}
|
|
65
|
-
GRPCConnectionPool.prototype._initialize = function (network, poolLimit, dapiUrl) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var evonodeList, networkDAPIUrls, _i, networkDAPIUrls_1, url, channel, client, response, v0, e_1;
|
|
68
|
-
return __generator(this, function (_a) {
|
|
69
|
-
switch (_a.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
if (typeof dapiUrl === 'string') {
|
|
72
|
-
this.channels = [(0, nice_grpc_web_1.createChannel)(dapiUrl)];
|
|
73
|
-
return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(dapiUrl)) {
|
|
76
|
-
this.channels = dapiUrl.map(function (dapiUrl) { return (0, nice_grpc_web_1.createChannel)(dapiUrl); });
|
|
77
|
-
return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
if (dapiUrl != null) {
|
|
80
|
-
throw new Error('Unrecognized DAPI URL');
|
|
81
|
-
}
|
|
82
|
-
// Add default seed nodes
|
|
83
|
-
this.channels = (seedNodes[network].map(function (dapiUrl) { return (0, nice_grpc_web_1.createChannel)(dapiUrl); }));
|
|
84
|
-
return [4 /*yield*/, (0, getEvonodeList_1.default)(network)
|
|
85
|
-
// map it to array of dapiUrls
|
|
86
|
-
];
|
|
87
|
-
case 1:
|
|
88
|
-
evonodeList = _a.sent();
|
|
89
|
-
networkDAPIUrls = Object.entries(evonodeList)
|
|
90
|
-
.map(function (_a) {
|
|
91
|
-
var info = _a[1];
|
|
92
|
-
return info;
|
|
93
|
-
})
|
|
94
|
-
.filter(function (info) { return info.status === 'ENABLED'; })
|
|
95
|
-
.map(function (info) {
|
|
96
|
-
var host = info.address.split(':')[0];
|
|
97
|
-
return "https://".concat(host, ":").concat(info.platformHTTPPort);
|
|
98
|
-
});
|
|
99
|
-
_i = 0, networkDAPIUrls_1 = networkDAPIUrls;
|
|
100
|
-
_a.label = 2;
|
|
101
|
-
case 2:
|
|
102
|
-
if (!(_i < networkDAPIUrls_1.length)) return [3 /*break*/, 7];
|
|
103
|
-
url = networkDAPIUrls_1[_i];
|
|
104
|
-
if (this.channels.length > poolLimit) {
|
|
105
|
-
return [3 /*break*/, 7];
|
|
106
|
-
}
|
|
107
|
-
_a.label = 3;
|
|
108
|
-
case 3:
|
|
109
|
-
_a.trys.push([3, 5, , 6]);
|
|
110
|
-
channel = (0, nice_grpc_web_1.createChannel)(url);
|
|
111
|
-
client = (0, nice_grpc_web_1.createClient)(platform_1.PlatformDefinition, channel);
|
|
112
|
-
return [4 /*yield*/, client.getStatus(platform_1.GetStatusRequest.fromPartial({ v0: {} }))];
|
|
113
|
-
case 4:
|
|
114
|
-
response = _a.sent();
|
|
115
|
-
v0 = response.v0;
|
|
116
|
-
if ((v0 === null || v0 === void 0 ? void 0 : v0.chain) != null) {
|
|
117
|
-
this.channels.push((0, nice_grpc_web_1.createChannel)(url));
|
|
118
|
-
}
|
|
119
|
-
return [3 /*break*/, 6];
|
|
120
|
-
case 5:
|
|
121
|
-
e_1 = _a.sent();
|
|
122
|
-
return [3 /*break*/, 6];
|
|
123
|
-
case 6:
|
|
124
|
-
_i++;
|
|
125
|
-
return [3 /*break*/, 2];
|
|
126
|
-
case 7: return [2 /*return*/];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
GRPCConnectionPool.prototype.getClient = function () {
|
|
132
|
-
var channel = (0, getRandomArrayItem_1.default)(this.channels);
|
|
133
|
-
return (0, nice_grpc_web_1.createClient)(platform_1.PlatformDefinition, channel);
|
|
134
|
-
};
|
|
135
|
-
return GRPCConnectionPool;
|
|
136
|
-
}());
|
|
137
|
-
exports.default = GRPCConnectionPool;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.default = createStateTransition;
|
|
13
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
14
|
-
var identityTransitionsMap = {
|
|
15
|
-
create: {
|
|
16
|
-
class: pshenmic_dpp_1.IdentityCreateTransitionWASM,
|
|
17
|
-
arguments: ['publicKeys', 'assetLockProof'],
|
|
18
|
-
optionalArguments: ['signature', 'userFeeIncrease']
|
|
19
|
-
},
|
|
20
|
-
topUp: {
|
|
21
|
-
class: pshenmic_dpp_1.IdentityTopUpTransitionWASM,
|
|
22
|
-
arguments: ['assetLockProof', 'identityId'],
|
|
23
|
-
optionalArguments: ['userFeeIncrease']
|
|
24
|
-
},
|
|
25
|
-
update: {
|
|
26
|
-
class: pshenmic_dpp_1.IdentityUpdateTransitionWASM,
|
|
27
|
-
arguments: ['identityId', 'revision', 'identityNonce', 'addPublicKeys', 'disablePublicKeyIds'],
|
|
28
|
-
optionalArguments: ['userFeeIncrease']
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
function createStateTransition(type, params) {
|
|
32
|
-
var _a = identityTransitionsMap[type], TransitionClass = _a.class, classArguments = _a.arguments, optionalArguments = _a.optionalArguments;
|
|
33
|
-
if (TransitionClass == null) {
|
|
34
|
-
throw new Error("Unimplemented transition type: ".concat(type));
|
|
35
|
-
}
|
|
36
|
-
var missingArgument = classArguments
|
|
37
|
-
.filter(function (classArgument) { return params[classArgument] == null &&
|
|
38
|
-
!(optionalArguments).includes(classArgument); })[0];
|
|
39
|
-
if (missingArgument != null) {
|
|
40
|
-
throw new Error("Token transition param \"".concat(missingArgument, "\" is missing"));
|
|
41
|
-
}
|
|
42
|
-
var transitionParams = classArguments.map(function (classArgument) { return params[classArgument]; });
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
var identityTransition = new (TransitionClass.bind.apply(TransitionClass, __spreadArray([void 0], transitionParams, false)))();
|
|
45
|
-
return identityTransition.toStateTransition();
|
|
46
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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 = getIdentityBalance;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
function getIdentityBalance(grpcPool, identifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var id, getIdentityBalanceRequest, v0, _a, proof, metadata, _b, rootHash, balance, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
52
|
-
getIdentityBalanceRequest = platform_1.GetIdentityBalanceRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
id: id.bytes(),
|
|
55
|
-
prove: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityBalance(getIdentityBalanceRequest)];
|
|
59
|
-
case 1:
|
|
60
|
-
v0 = (_c.sent()).v0;
|
|
61
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
62
|
-
if (proof == null) {
|
|
63
|
-
throw new Error('Proof not found');
|
|
64
|
-
}
|
|
65
|
-
if (metadata == null) {
|
|
66
|
-
throw new Error('Metadata not found');
|
|
67
|
-
}
|
|
68
|
-
_b = (0, pshenmic_dpp_1.verifyIdentityBalanceProof)(proof.grovedbProof, id.bytes(), true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, balance = _b.balance;
|
|
69
|
-
if (balance == null) {
|
|
70
|
-
throw new Error("Failed to fetch balance for identifier ".concat(id.base58()));
|
|
71
|
-
}
|
|
72
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
-
case 2:
|
|
74
|
-
quorumPublicKey = _c.sent();
|
|
75
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
76
|
-
if (!verify) {
|
|
77
|
-
throw new Error('Failed to verify query');
|
|
78
|
-
}
|
|
79
|
-
return [2 /*return*/, BigInt(balance)];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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 = getIdentityByIdentifier;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
43
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
44
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
45
|
-
function getIdentityByIdentifier(grpcPool, identifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var id, getIdentityRequest, v0, _a, proof, metadata, _b, rootHash, identity, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
52
|
-
getIdentityRequest = platform_1.GetIdentityRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
id: id.bytes(),
|
|
55
|
-
prove: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentity(getIdentityRequest)];
|
|
59
|
-
case 1:
|
|
60
|
-
v0 = (_c.sent()).v0;
|
|
61
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
62
|
-
if (proof == null) {
|
|
63
|
-
throw new Error('Proof not found');
|
|
64
|
-
}
|
|
65
|
-
if (metadata == null) {
|
|
66
|
-
throw new Error('Metadata not found');
|
|
67
|
-
}
|
|
68
|
-
_b = (0, pshenmic_dpp_1.verifyIdentityByIdentifierProof)(proof.grovedbProof, id, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, identity = _b.identity;
|
|
69
|
-
if (identity == null) {
|
|
70
|
-
throw new Error("Identity with identifier ".concat(id.base58(), " not found"));
|
|
71
|
-
}
|
|
72
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
-
case 2:
|
|
74
|
-
quorumPublicKey = _c.sent();
|
|
75
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
76
|
-
if (!verify) {
|
|
77
|
-
throw new Error('Failed to verify query');
|
|
78
|
-
}
|
|
79
|
-
return [2 /*return*/, identity];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|