dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.min.js +21 -2
- package/index.js +2 -5
- package/package.json +30 -31
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/google/protobuf/wrappers.js +562 -345
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/proto/generated/platform.js +8119 -18366
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/DashPlatformSDK.js +56 -46
- package/src/constants.js +7 -10
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/contestedResources/createStateTransition.js +4 -7
- package/src/contestedResources/getContestedResourceVoteState.js +67 -118
- package/src/contestedResources/index.js +9 -55
- package/src/dataContracts/create.js +5 -8
- package/src/dataContracts/createStateTransition.js +10 -14
- package/src/dataContracts/getDataContractByIdentifier.js +40 -83
- package/src/dataContracts/index.js +17 -63
- package/src/documents/create.js +3 -6
- package/src/documents/createStateTransition.js +19 -31
- package/src/documents/index.js +25 -72
- package/src/documents/query.js +58 -90
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/grpcConnectionPool.js +63 -121
- package/src/identities/createStateTransition.js +14 -26
- package/src/identities/getIdentityBalance.js +37 -80
- package/src/identities/getIdentityByIdentifier.js +37 -80
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
- package/src/identities/getIdentityByPublicKeyHash.js +37 -80
- package/src/identities/getIdentityContractNonce.js +40 -83
- package/src/identities/getIdentityNonce.js +38 -81
- package/src/identities/getIdentityPublicKeys.js +43 -81
- package/src/identities/index.js +57 -153
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/deriveChild.js +2 -49
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/derivePath.js +2 -49
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/index.js +62 -296
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/keyPair/mnemonicToSeed.js +3 -46
- package/src/names/index.js +43 -111
- package/src/names/registerName.js +60 -127
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/names/searchByIdentity.js +4 -50
- package/src/names/searchByName.js +15 -63
- package/src/names/testNameContested.js +1 -4
- package/src/names/validateName.js +3 -6
- package/src/node/epochs.js +43 -85
- package/src/node/index.d.ts +3 -3
- package/src/node/index.js +18 -77
- package/src/node/status.js +37 -81
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +32 -73
- package/src/signer/AbstractSigner.js +1 -2
- package/src/signer/setSigner.js +1 -4
- package/src/stateTransitions/broadcast.js +7 -57
- package/src/stateTransitions/index.js +13 -66
- package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
- package/src/tokens/createStateTransition.js +23 -35
- package/src/tokens/getIdentitiesTokenBalances.js +40 -83
- package/src/tokens/getIdentityTokensBalances.js +40 -83
- package/src/tokens/getTokenContractInfo.js +40 -83
- package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
- package/src/tokens/getTokenTotalSupply.js +38 -81
- package/src/tokens/index.js +39 -124
- package/src/types.d.ts +6 -12
- package/src/types.js +6 -16
- package/src/utils/base58ToBytes.js +3 -6
- package/src/utils/bytesToHex.js +2 -5
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateMsgHash.js +10 -13
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateSignHash.js +7 -10
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.js +8 -10
- package/src/utils/convertToHomographSafeChars.js +2 -5
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/createVoterIdentityId.js +12 -11
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/getEvonodeList.js +10 -61
- package/src/utils/getQuorumPublicKey.js +15 -66
- package/src/utils/getRandomArrayItem.js +1 -4
- package/src/utils/getRandomBytes.js +2 -5
- package/src/utils/hexToBytes.js +2 -6
- package/src/utils/index.js +21 -28
- package/src/utils/indexBytesToString.js +2 -5
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/sha256.js +10 -8
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signHash.js +9 -12
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/signRequestId.js +9 -12
- package/src/utils/sleep.js +2 -50
- package/src/utils/stringToIndexValueBytes.js +4 -7
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.js +13 -17
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/createStateTransition.js +4 -7
- package/src/voting/createVote.js +4 -7
- package/src/voting/index.d.ts +3 -4
- package/src/voting/index.js +19 -26
- package/test/unit/ContestedResources.spec.js +92 -177
- package/test/unit/DataContract.spec.js +44 -111
- package/test/unit/Document.spec.js +93 -183
- package/test/unit/Identity.spec.js +221 -346
- package/test/unit/KeyPair.spec.js +30 -145
- package/test/unit/Names.spec.js +27 -90
- package/test/unit/Node.spec.js +55 -126
- package/test/unit/SDK.spec.js +7 -9
- package/test/unit/Tokens.spec.js +111 -278
- package/bundle.min.js.LICENSE.txt +0 -1
- 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/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
|
@@ -1,85 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 = getIdentityByNonUniquePublicKeyHash;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var hexToBytes_1 = require("../utils/hexToBytes");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
|
-
var getIdentityByIdentifier_1 = require("./getIdentityByIdentifier");
|
|
47
|
-
function getIdentityByNonUniquePublicKeyHash(grpcPool, hex) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
-
var getIdentityByNonUniquePublicKeyHashRequest, v0, _a, proof, metadata, _b, rootHash, identifier, quorumPublicKey, verify;
|
|
50
|
-
return __generator(this, function (_c) {
|
|
51
|
-
switch (_c.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
getIdentityByNonUniquePublicKeyHashRequest = platform_1.GetIdentityByNonUniquePublicKeyHashRequest.fromPartial({
|
|
54
|
-
v0: {
|
|
55
|
-
publicKeyHash: (0, hexToBytes_1.default)(hex),
|
|
56
|
-
prove: true
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityByNonUniquePublicKeyHash(getIdentityByNonUniquePublicKeyHashRequest)];
|
|
60
|
-
case 1:
|
|
61
|
-
v0 = (_c.sent()).v0;
|
|
62
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
63
|
-
if ((proof === null || proof === void 0 ? void 0 : proof.grovedbIdentityPublicKeyHashProof) == null) {
|
|
64
|
-
throw new Error('Proof not found');
|
|
65
|
-
}
|
|
66
|
-
if (metadata == null) {
|
|
67
|
-
throw new Error('Metadata not found');
|
|
68
|
-
}
|
|
69
|
-
_b = (0, pshenmic_dpp_1.verifyIdentifierByNonUniquePublicKeyHashProof)(proof.grovedbIdentityPublicKeyHashProof.grovedbProof, false, (0, hexToBytes_1.default)(hex), undefined, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, identifier = _b.identifier;
|
|
70
|
-
if (identifier == null) {
|
|
71
|
-
throw new Error("Identity with non unique public key hash ".concat(hex, " not found"));
|
|
72
|
-
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.grovedbIdentityPublicKeyHashProof.quorumType, (0, bytesToHex_1.default)(proof.grovedbIdentityPublicKeyHashProof.quorumHash))];
|
|
74
|
-
case 2:
|
|
75
|
-
quorumPublicKey = _c.sent();
|
|
76
|
-
verify = (0, verifyTenderdashProof_1.default)(proof.grovedbIdentityPublicKeyHashProof, metadata, rootHash, quorumPublicKey);
|
|
77
|
-
if (!verify) {
|
|
78
|
-
throw new Error('Failed to verify query');
|
|
79
|
-
}
|
|
80
|
-
return [4 /*yield*/, (0, getIdentityByIdentifier_1.default)(grpcPool, identifier)];
|
|
81
|
-
case 3: return [2 /*return*/, _c.sent()];
|
|
1
|
+
import { GetIdentityByNonUniquePublicKeyHashRequest } from '../../proto/generated/platform';
|
|
2
|
+
import { PlatformVersionWASM, verifyIdentifierByNonUniquePublicKeyHashProof } from 'pshenmic-dpp';
|
|
3
|
+
import hexToBytes from '../utils/hexToBytes';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof';
|
|
7
|
+
import getIdentityByIdentifier from './getIdentityByIdentifier';
|
|
8
|
+
export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, hex) {
|
|
9
|
+
const getIdentityByNonUniquePublicKeyHashRequest = GetIdentityByNonUniquePublicKeyHashRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
publicKeyHash: hexToBytes(hex),
|
|
14
|
+
prove: true
|
|
82
15
|
}
|
|
83
|
-
}
|
|
16
|
+
}
|
|
84
17
|
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getIdentityByNonUniquePublicKeyHash(getIdentityByNonUniquePublicKeyHashRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
if (proof.grovedbIdentityPublicKeyHashProof == null) {
|
|
32
|
+
throw new Error('GroveDB proof not found for identity by non unique public key request');
|
|
33
|
+
}
|
|
34
|
+
const { rootHash, identifier } = verifyIdentifierByNonUniquePublicKeyHashProof(proof.grovedbIdentityPublicKeyHashProof.grovedbProof, false, hexToBytes(hex), undefined, PlatformVersionWASM.PLATFORM_V9);
|
|
35
|
+
if (identifier == null) {
|
|
36
|
+
throw new Error(`Identity with non unique public key hash ${hex} not found`);
|
|
37
|
+
}
|
|
38
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.grovedbIdentityPublicKeyHashProof.quorumType, bytesToHex(proof.grovedbIdentityPublicKeyHashProof.quorumHash));
|
|
39
|
+
const verify = await verifyTenderdashProof(proof.grovedbIdentityPublicKeyHashProof, metadata, rootHash, quorumPublicKey);
|
|
40
|
+
if (!verify) {
|
|
41
|
+
throw new Error('Failed to verify query');
|
|
42
|
+
}
|
|
43
|
+
return await getIdentityByIdentifier(grpcPool, identifier);
|
|
85
44
|
}
|
|
@@ -1,83 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 = getIdentityByPublicKeyHash;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
42
|
-
var hexToBytes_1 = require("../utils/hexToBytes");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
|
-
function getIdentityByPublicKeyHash(grpcPool, hex) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var getIdentityByPublicKeyHashRequest, v0, _a, proof, metadata, _b, rootHash, identity, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
getIdentityByPublicKeyHashRequest = platform_1.GetIdentityByPublicKeyHashRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
publicKeyHash: (0, hexToBytes_1.default)(hex),
|
|
55
|
-
prove: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityByPublicKeyHash(getIdentityByPublicKeyHashRequest)];
|
|
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.verifyIdentityByUniqueKeyHashProof)(proof.grovedbProof, (0, hexToBytes_1.default)(hex), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, identity = _b.identity;
|
|
69
|
-
if (identity == null) {
|
|
70
|
-
throw new Error("Identity with public key hash ".concat(hex, " 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];
|
|
1
|
+
import { GetIdentityByPublicKeyHashRequest } from '../../proto/generated/platform';
|
|
2
|
+
import { PlatformVersionWASM, verifyIdentityByUniqueKeyHashProof } from 'pshenmic-dpp';
|
|
3
|
+
import hexToBytes from '../utils/hexToBytes';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof';
|
|
7
|
+
export default async function getIdentityByPublicKeyHash(grpcPool, hex) {
|
|
8
|
+
const getIdentityByPublicKeyHashRequest = GetIdentityByPublicKeyHashRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
publicKeyHash: hexToBytes(hex),
|
|
13
|
+
prove: true
|
|
80
14
|
}
|
|
81
|
-
}
|
|
15
|
+
}
|
|
82
16
|
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getIdentityByPublicKeyHash(getIdentityByPublicKeyHashRequest);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, identity } = verifyIdentityByUniqueKeyHashProof(proof.grovedbProof, hexToBytes(hex), PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (identity == null) {
|
|
32
|
+
throw new Error(`Identity with public key hash ${hex} not found`);
|
|
33
|
+
}
|
|
34
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
35
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
+
if (!verify) {
|
|
37
|
+
throw new Error('Failed to verify query');
|
|
38
|
+
}
|
|
39
|
+
return identity;
|
|
83
40
|
}
|
|
@@ -1,86 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 = getIdentityContractNonce;
|
|
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
|
-
var IDENTITY_CONTRACT_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
|
|
46
|
-
function getIdentityContractNonce(grpcPool, identity, dataContract) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var identityIdentifier, dataContractIdentifier, getIdentityContractNonceRequest, v0, _a, proof, metadata, _b, rootHash, contractNonce, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
identityIdentifier = new pshenmic_dpp_1.IdentifierWASM(identity);
|
|
53
|
-
dataContractIdentifier = new pshenmic_dpp_1.IdentifierWASM(dataContract);
|
|
54
|
-
getIdentityContractNonceRequest = platform_1.GetIdentityContractNonceRequest.fromPartial({
|
|
55
|
-
v0: {
|
|
56
|
-
identityId: identityIdentifier.bytes(),
|
|
57
|
-
contractId: dataContractIdentifier.bytes(),
|
|
58
|
-
prove: true
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityContractNonce(getIdentityContractNonceRequest)];
|
|
62
|
-
case 1:
|
|
63
|
-
v0 = (_c.sent()).v0;
|
|
64
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
65
|
-
if (proof == null) {
|
|
66
|
-
throw new Error('Proof not found');
|
|
67
|
-
}
|
|
68
|
-
if (metadata == null) {
|
|
69
|
-
throw new Error('Metadata not found');
|
|
70
|
-
}
|
|
71
|
-
_b = (0, pshenmic_dpp_1.verifyIdentityContractNonceProof)(proof.grovedbProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, contractNonce = _b.contractNonce;
|
|
72
|
-
if (contractNonce == null) {
|
|
73
|
-
return [2 /*return*/, BigInt(0)];
|
|
74
|
-
}
|
|
75
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
76
|
-
case 2:
|
|
77
|
-
quorumPublicKey = _c.sent();
|
|
78
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
79
|
-
if (!verify) {
|
|
80
|
-
throw new Error('Failed to verify query');
|
|
81
|
-
}
|
|
82
|
-
return [2 /*return*/, BigInt(contractNonce) & IDENTITY_CONTRACT_NONCE_VALUE_FILTER];
|
|
1
|
+
import { GetIdentityContractNonceRequest } from '../../proto/generated/platform';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyIdentityContractNonceProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof';
|
|
6
|
+
const IDENTITY_CONTRACT_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
|
|
7
|
+
export default async function getIdentityContractNonce(grpcPool, identity, dataContract) {
|
|
8
|
+
const identityIdentifier = new IdentifierWASM(identity);
|
|
9
|
+
const dataContractIdentifier = new IdentifierWASM(dataContract);
|
|
10
|
+
const getIdentityContractNonceRequest = GetIdentityContractNonceRequest.create({
|
|
11
|
+
version: {
|
|
12
|
+
oneofKind: 'v0',
|
|
13
|
+
v0: {
|
|
14
|
+
identityId: identityIdentifier.bytes(),
|
|
15
|
+
contractId: dataContractIdentifier.bytes(),
|
|
16
|
+
prove: true
|
|
83
17
|
}
|
|
84
|
-
}
|
|
18
|
+
}
|
|
85
19
|
});
|
|
20
|
+
const { response } = await grpcPool.getClient().getIdentityContractNonce(getIdentityContractNonceRequest);
|
|
21
|
+
const { version } = response;
|
|
22
|
+
if (version.oneofKind !== 'v0') {
|
|
23
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
24
|
+
}
|
|
25
|
+
const { v0 } = version;
|
|
26
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
27
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
28
|
+
}
|
|
29
|
+
const { result: { proof }, metadata } = v0;
|
|
30
|
+
if (metadata == null) {
|
|
31
|
+
throw new Error('Metadata not found');
|
|
32
|
+
}
|
|
33
|
+
const { rootHash, contractNonce } = verifyIdentityContractNonceProof(proof.grovedbProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
|
|
34
|
+
if (contractNonce == null) {
|
|
35
|
+
return BigInt(0);
|
|
36
|
+
}
|
|
37
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
38
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
39
|
+
if (!verify) {
|
|
40
|
+
throw new Error('Failed to verify query');
|
|
41
|
+
}
|
|
42
|
+
return BigInt(contractNonce) & IDENTITY_CONTRACT_NONCE_VALUE_FILTER;
|
|
86
43
|
}
|
|
@@ -1,84 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 = getIdentityNonce;
|
|
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
|
-
var IDENTITY_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
|
|
46
|
-
function getIdentityNonce(grpcPool, identifier) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var id, getIdentityNonceRequest, v0, _a, proof, metadata, _b, rootHash, nonce, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
53
|
-
getIdentityNonceRequest = platform_1.GetIdentityNonceRequest.fromPartial({
|
|
54
|
-
v0: {
|
|
55
|
-
identityId: id.bytes(),
|
|
56
|
-
prove: true
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityNonce(getIdentityNonceRequest)];
|
|
60
|
-
case 1:
|
|
61
|
-
v0 = (_c.sent()).v0;
|
|
62
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
63
|
-
if (proof == null) {
|
|
64
|
-
throw new Error('Proof not found');
|
|
65
|
-
}
|
|
66
|
-
if (metadata == null) {
|
|
67
|
-
throw new Error('Metadata not found');
|
|
68
|
-
}
|
|
69
|
-
_b = (0, pshenmic_dpp_1.verifyIdentityNonceProof)(proof.grovedbProof, id.bytes(), true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, nonce = _b.nonce;
|
|
70
|
-
if (nonce == null) {
|
|
71
|
-
return [2 /*return*/, BigInt(0)];
|
|
72
|
-
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
|
-
case 2:
|
|
75
|
-
quorumPublicKey = _c.sent();
|
|
76
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
77
|
-
if (!verify) {
|
|
78
|
-
throw new Error('Failed to verify query');
|
|
79
|
-
}
|
|
80
|
-
return [2 /*return*/, BigInt(nonce) & IDENTITY_NONCE_VALUE_FILTER];
|
|
1
|
+
import { GetIdentityNonceRequest } from '../../proto/generated/platform';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyIdentityNonceProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof';
|
|
6
|
+
const IDENTITY_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
|
|
7
|
+
export default async function getIdentityNonce(grpcPool, identifier) {
|
|
8
|
+
const id = new IdentifierWASM(identifier);
|
|
9
|
+
const getIdentityNonceRequest = GetIdentityNonceRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
identityId: id.bytes(),
|
|
14
|
+
prove: true
|
|
81
15
|
}
|
|
82
|
-
}
|
|
16
|
+
}
|
|
83
17
|
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getIdentityNonce(getIdentityNonceRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
const { rootHash, nonce } = verifyIdentityNonceProof(proof.grovedbProof, id.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
|
|
32
|
+
if (nonce == null) {
|
|
33
|
+
return BigInt(0);
|
|
34
|
+
}
|
|
35
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
36
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
37
|
+
if (!verify) {
|
|
38
|
+
throw new Error('Failed to verify query');
|
|
39
|
+
}
|
|
40
|
+
return BigInt(nonce) & IDENTITY_NONCE_VALUE_FILTER;
|
|
84
41
|
}
|
|
@@ -1,85 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 = getIdentityPublicKeys;
|
|
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 getIdentityPublicKeys(grpcPool, identifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var id, getIdentityKeysRequest, v0, _a, proof, metadata, _b, rootHash, identity, quorumPublicKey, verify, loadedKeysIds;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
52
|
-
getIdentityKeysRequest = platform_1.GetIdentityKeysRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
identityId: id.bytes(),
|
|
55
|
-
requestType: platform_1.KeyRequestType.fromPartial({ allKeys: {} }),
|
|
56
|
-
prove: true
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityKeys(getIdentityKeysRequest)];
|
|
60
|
-
case 1:
|
|
61
|
-
v0 = (_c.sent()).v0;
|
|
62
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
63
|
-
if (proof == null) {
|
|
64
|
-
throw new Error('Proof not found');
|
|
65
|
-
}
|
|
66
|
-
if (metadata == null) {
|
|
67
|
-
throw new Error('Metadata not found');
|
|
68
|
-
}
|
|
69
|
-
_b = (0, pshenmic_dpp_1.verifyIdentityKeysByIdentifierProof)(proof.grovedbProof, id.bytes(), null, false, false, true, null, null, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, identity = _b.identity;
|
|
70
|
-
if (identity == null) {
|
|
71
|
-
throw new Error("Identity with identifier ".concat(id.base58(), " not found"));
|
|
72
|
-
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
|
-
case 2:
|
|
75
|
-
quorumPublicKey = _c.sent();
|
|
76
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
77
|
-
if (!verify) {
|
|
78
|
-
throw new Error('Failed to verify query');
|
|
1
|
+
import { GetIdentityKeysRequest, KeyRequestType } from '../../proto/generated/platform';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyIdentityKeysByIdentifierProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof';
|
|
6
|
+
export default async function getIdentityPublicKeys(grpcPool, identifier) {
|
|
7
|
+
const id = new IdentifierWASM(identifier);
|
|
8
|
+
const getIdentityKeysRequest = GetIdentityKeysRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
identityId: id.bytes(),
|
|
13
|
+
requestType: KeyRequestType.create({
|
|
14
|
+
request: {
|
|
15
|
+
oneofKind: 'allKeys',
|
|
16
|
+
allKeys: {}
|
|
79
17
|
}
|
|
80
|
-
|
|
81
|
-
|
|
18
|
+
}),
|
|
19
|
+
prove: true
|
|
82
20
|
}
|
|
83
|
-
}
|
|
21
|
+
}
|
|
84
22
|
});
|
|
23
|
+
const { response } = await grpcPool.getClient().getIdentityKeys(getIdentityKeysRequest);
|
|
24
|
+
const { version } = response;
|
|
25
|
+
if (version.oneofKind !== 'v0') {
|
|
26
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
27
|
+
}
|
|
28
|
+
const { v0 } = version;
|
|
29
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
30
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
31
|
+
}
|
|
32
|
+
const { result: { proof }, metadata } = v0;
|
|
33
|
+
if (metadata == null) {
|
|
34
|
+
throw new Error('Metadata not found');
|
|
35
|
+
}
|
|
36
|
+
const { rootHash, identity } = verifyIdentityKeysByIdentifierProof(proof.grovedbProof, id.bytes(), null, false, false, true, null, null, PlatformVersionWASM.PLATFORM_V9);
|
|
37
|
+
if (identity == null) {
|
|
38
|
+
throw new Error(`Identity with identifier ${id.base58()} not found`);
|
|
39
|
+
}
|
|
40
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
41
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
42
|
+
if (!verify) {
|
|
43
|
+
throw new Error('Failed to verify query');
|
|
44
|
+
}
|
|
45
|
+
const loadedKeysIds = Object.keys(identity.loadedPublicKeys);
|
|
46
|
+
return loadedKeysIds.map((id) => identity.loadedPublicKeys[id]);
|
|
85
47
|
}
|