dash-platform-sdk 1.3.0-dev.1 → 1.3.0-dev.10
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.d.ts +1 -1
- package/index.js +2 -5
- package/package.json +32 -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 +18 -19
- package/src/DashPlatformSDK.js +52 -45
- package/src/constants.d.ts +2 -0
- package/src/constants.js +7 -8
- package/src/contestedResources/createStateTransition.d.ts +2 -0
- package/src/contestedResources/createStateTransition.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +3 -3
- package/src/contestedResources/getContestedResourceVoteState.js +67 -118
- package/src/contestedResources/index.d.ts +3 -3
- package/src/contestedResources/index.js +9 -55
- package/src/dataContracts/create.d.ts +1 -1
- package/src/dataContracts/create.js +5 -8
- package/src/dataContracts/createStateTransition.js +10 -14
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -2
- package/src/dataContracts/getDataContractByIdentifier.js +40 -79
- package/src/dataContracts/index.d.ts +2 -2
- package/src/dataContracts/index.js +17 -63
- package/src/documents/create.d.ts +1 -1
- package/src/documents/create.js +3 -6
- package/src/documents/createStateTransition.d.ts +1 -1
- package/src/documents/createStateTransition.js +19 -31
- package/src/documents/index.d.ts +2 -2
- package/src/documents/index.js +25 -72
- package/src/documents/query.d.ts +2 -2
- package/src/documents/query.js +58 -90
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/grpcConnectionPool.js +63 -121
- package/src/identities/createStateTransition.d.ts +2 -2
- package/src/identities/createStateTransition.js +24 -26
- package/src/identities/getIdentityBalance.d.ts +2 -2
- package/src/identities/getIdentityBalance.js +37 -80
- package/src/identities/getIdentityByIdentifier.d.ts +2 -2
- package/src/identities/getIdentityByIdentifier.js +37 -80
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
- package/src/identities/getIdentityByPublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByPublicKeyHash.js +37 -80
- package/src/identities/getIdentityContractNonce.d.ts +2 -2
- package/src/identities/getIdentityContractNonce.js +40 -83
- package/src/identities/getIdentityNonce.d.ts +2 -2
- package/src/identities/getIdentityNonce.js +38 -81
- package/src/identities/getIdentityPublicKeys.d.ts +2 -2
- package/src/identities/getIdentityPublicKeys.js +43 -81
- package/src/identities/index.d.ts +6 -4
- package/src/identities/index.js +70 -154
- 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.d.ts +44 -3
- package/src/names/index.js +81 -69
- package/src/names/registerName.d.ts +3 -0
- package/src/names/registerName.js +64 -0
- package/src/names/searchByIdentity.d.ts +3 -0
- package/src/names/searchByIdentity.js +5 -0
- package/src/names/searchByName.d.ts +3 -0
- package/src/names/searchByName.js +16 -0
- package/src/names/testNameContested.d.ts +1 -0
- package/src/names/testNameContested.js +3 -0
- package/src/names/validateName.d.ts +1 -0
- package/src/names/validateName.js +11 -0
- package/src/node/epochs.d.ts +1 -1
- package/src/node/epochs.js +43 -85
- package/src/node/index.d.ts +5 -5
- package/src/node/index.js +18 -77
- package/src/node/status.d.ts +2 -2
- package/src/node/status.js +37 -81
- package/src/node/totalCredits.d.ts +3 -2
- package/src/node/totalCredits.js +32 -73
- package/src/stateTransitions/broadcast.d.ts +1 -1
- package/src/stateTransitions/broadcast.js +7 -57
- package/src/stateTransitions/index.d.ts +1 -1
- package/src/stateTransitions/index.js +13 -66
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +1 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +6 -62
- package/src/tokens/createStateTransition.d.ts +1 -1
- package/src/tokens/createStateTransition.js +23 -35
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -2
- package/src/tokens/getIdentitiesTokenBalances.js +40 -83
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
- package/src/tokens/getIdentityTokensBalances.js +40 -83
- package/src/tokens/getTokenContractInfo.d.ts +2 -2
- package/src/tokens/getTokenContractInfo.js +40 -83
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
- package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
- package/src/tokens/getTokenTotalSupply.d.ts +2 -2
- package/src/tokens/getTokenTotalSupply.js +38 -81
- package/src/tokens/index.d.ts +13 -5
- package/src/tokens/index.js +46 -113
- package/src/types.d.ts +20 -16
- 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 +2 -2
- package/src/utils/calculateSignHash.js +7 -10
- package/src/utils/calculateStateIdHash.d.ts +2 -2
- package/src/utils/calculateStateIdHash.js +8 -10
- package/src/utils/convertToHomographSafeChars.d.ts +0 -4
- package/src/utils/convertToHomographSafeChars.js +2 -9
- package/src/utils/createMasternodeIdentityId.d.ts +2 -0
- package/src/utils/createMasternodeIdentityId.js +4 -0
- package/src/utils/createVoterIdentityId.d.ts +2 -0
- package/src/utils/createVoterIdentityId.js +13 -0
- 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.d.ts +1 -0
- package/src/utils/getRandomBytes.js +4 -0
- package/src/utils/hexToBytes.js +2 -6
- package/src/utils/index.d.ts +19 -3
- package/src/utils/index.js +45 -31
- 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.d.ts +1 -0
- package/src/utils/sleep.js +3 -0
- package/src/utils/stringToIndexValueBytes.js +4 -7
- package/src/utils/verifyTenderdashProof.d.ts +2 -2
- package/src/utils/verifyTenderdashProof.js +13 -17
- package/src/voting/createStateTransition.d.ts +2 -0
- package/src/voting/createStateTransition.js +6 -0
- package/src/voting/createVote.d.ts +2 -0
- package/src/voting/createVote.js +5 -0
- package/src/voting/index.d.ts +37 -0
- package/src/voting/index.js +55 -0
- package/test/unit/ContestedResources.spec.js +91 -90
- package/test/unit/DataContract.spec.js +44 -111
- package/test/unit/Document.spec.js +93 -183
- package/test/unit/Identity.spec.js +254 -357
- package/test/unit/KeyPair.spec.js +30 -145
- package/test/unit/Names.spec.d.ts +1 -0
- package/test/unit/Names.spec.js +33 -0
- package/test/unit/Node.spec.js +55 -126
- package/test/unit/SDK.spec.js +7 -9
- package/test/unit/Tokens.spec.js +112 -262
- 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
- package/src/names/search.d.ts +0 -3
- package/src/names/search.js +0 -63
- package/src/signer/AbstractSigner.d.ts +0 -12
- 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.d.ts +0 -2
- package/src/signer/setSigner.js +0 -8
|
@@ -1,86 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 = getIdentitiesTokenBalances;
|
|
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 getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var ids, tokenId, request, v0, _a, proof, metadata, _b, rootHash, balances, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
ids = identifiers.map(function (identifier) { return new pshenmic_dpp_1.IdentifierWASM(identifier); });
|
|
52
|
-
tokenId = new pshenmic_dpp_1.IdentifierWASM(tokenIdentifier);
|
|
53
|
-
request = platform_1.GetIdentitiesTokenBalancesRequest.fromPartial({
|
|
54
|
-
v0: {
|
|
55
|
-
tokenId: tokenId.bytes(),
|
|
56
|
-
identityIds: ids.map(function (id) { return id.bytes(); }),
|
|
57
|
-
prove: true
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentitiesTokenBalances(request)];
|
|
61
|
-
case 1:
|
|
62
|
-
v0 = (_c.sent()).v0;
|
|
63
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
64
|
-
if (proof == null) {
|
|
65
|
-
throw new Error('Proof not found');
|
|
66
|
-
}
|
|
67
|
-
if (metadata == null) {
|
|
68
|
-
throw new Error('Metadata not found');
|
|
69
|
-
}
|
|
70
|
-
_b = (0, pshenmic_dpp_1.verifyTokenBalancesForIdentitiesProof)(proof.grovedbProof, tokenId, true, ids, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, balances = _b.balances;
|
|
71
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
|
-
case 2:
|
|
73
|
-
quorumPublicKey = _c.sent();
|
|
74
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
75
|
-
if (!verify) {
|
|
76
|
-
throw new Error('Failed to verify query');
|
|
77
|
-
}
|
|
78
|
-
return [2 /*return*/, balances
|
|
79
|
-
.map(function (identityTokenBalance) { return ({
|
|
80
|
-
identityId: new pshenmic_dpp_1.IdentifierWASM(identityTokenBalance.identityId),
|
|
81
|
-
balance: identityTokenBalance.balance
|
|
82
|
-
}); })];
|
|
1
|
+
import { GetIdentitiesTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
7
|
+
const ids = identifiers.map(identifier => new IdentifierWASM(identifier));
|
|
8
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
9
|
+
const getIdentitiesTokenBalancesRequest = GetIdentitiesTokenBalancesRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
tokenId: tokenId.bytes(),
|
|
14
|
+
identityIds: ids.map(id => id.bytes()),
|
|
15
|
+
prove: true
|
|
83
16
|
}
|
|
84
|
-
}
|
|
17
|
+
}
|
|
85
18
|
});
|
|
19
|
+
const { response } = await grpcPool.getClient().getIdentitiesTokenBalances(getIdentitiesTokenBalancesRequest);
|
|
20
|
+
const { version } = response;
|
|
21
|
+
if (version.oneofKind !== 'v0') {
|
|
22
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
23
|
+
}
|
|
24
|
+
const { v0 } = version;
|
|
25
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
26
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
27
|
+
}
|
|
28
|
+
const { result: { proof }, metadata } = v0;
|
|
29
|
+
if (metadata == null) {
|
|
30
|
+
throw new Error('Metadata not found');
|
|
31
|
+
}
|
|
32
|
+
const { rootHash, balances } = verifyTokenBalancesForIdentitiesProof(proof.grovedbProof, tokenId, true, ids, PlatformVersionWASM.PLATFORM_V9);
|
|
33
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
34
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
35
|
+
if (!verify) {
|
|
36
|
+
throw new Error('Failed to verify query');
|
|
37
|
+
}
|
|
38
|
+
return balances
|
|
39
|
+
.map((identityTokenBalance) => ({
|
|
40
|
+
identityId: new IdentifierWASM(identityTokenBalance.identityId),
|
|
41
|
+
balance: identityTokenBalance.balance
|
|
42
|
+
}));
|
|
86
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface IdentityTokenBalances {
|
|
5
5
|
tokenId: IdentifierWASM;
|
|
@@ -1,86 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 = getIdentityTokensBalances;
|
|
40
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
42
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
43
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
44
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
45
|
-
function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var id, tokenIds, request, v0, _a, proof, metadata, _b, rootHash, balances, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
52
|
-
tokenIds = tokenIdentifiers.map(function (tokenIdentifier) { return new pshenmic_dpp_1.IdentifierWASM(tokenIdentifier); });
|
|
53
|
-
request = platform_1.GetIdentityTokenBalancesRequest.fromPartial({
|
|
54
|
-
v0: {
|
|
55
|
-
tokenIds: tokenIds.map(function (identifier) { return identifier.bytes(); }),
|
|
56
|
-
identityId: id.bytes(),
|
|
57
|
-
prove: true
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return [4 /*yield*/, grpcPool.getClient().getIdentityTokenBalances(request)];
|
|
61
|
-
case 1:
|
|
62
|
-
v0 = (_c.sent()).v0;
|
|
63
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
64
|
-
if (proof == null) {
|
|
65
|
-
throw new Error('Proof not found');
|
|
66
|
-
}
|
|
67
|
-
if (metadata == null) {
|
|
68
|
-
throw new Error('Metadata not found');
|
|
69
|
-
}
|
|
70
|
-
_b = (0, pshenmic_dpp_1.verifyTokensBalancesForIdentityProof)(proof.grovedbProof, tokenIds, id, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, balances = _b.balances;
|
|
71
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
|
-
case 2:
|
|
73
|
-
quorumPublicKey = _c.sent();
|
|
74
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
75
|
-
if (!verify) {
|
|
76
|
-
throw new Error('Failed to verify query');
|
|
77
|
-
}
|
|
78
|
-
return [2 /*return*/, balances
|
|
79
|
-
.map(function (tokenBalance) { return ({
|
|
80
|
-
tokenId: new pshenmic_dpp_1.IdentifierWASM(tokenBalance.tokenId),
|
|
81
|
-
balance: tokenBalance.balance
|
|
82
|
-
}); })];
|
|
1
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokensBalancesForIdentityProof } from 'pshenmic-dpp';
|
|
2
|
+
import { GetIdentityTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
7
|
+
const id = new IdentifierWASM(identifier);
|
|
8
|
+
const tokenIds = tokenIdentifiers.map(tokenIdentifier => new IdentifierWASM(tokenIdentifier));
|
|
9
|
+
const getIdentityTokenBalancesRequest = GetIdentityTokenBalancesRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
tokenIds: tokenIds.map((identifier) => identifier.bytes()),
|
|
14
|
+
identityId: id.bytes(),
|
|
15
|
+
prove: true
|
|
83
16
|
}
|
|
84
|
-
}
|
|
17
|
+
}
|
|
85
18
|
});
|
|
19
|
+
const { response } = await grpcPool.getClient().getIdentityTokenBalances(getIdentityTokenBalancesRequest);
|
|
20
|
+
const { version } = response;
|
|
21
|
+
if (version.oneofKind !== 'v0') {
|
|
22
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
23
|
+
}
|
|
24
|
+
const { v0 } = version;
|
|
25
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
26
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
27
|
+
}
|
|
28
|
+
const { result: { proof }, metadata } = v0;
|
|
29
|
+
if (metadata == null) {
|
|
30
|
+
throw new Error('Metadata not found');
|
|
31
|
+
}
|
|
32
|
+
const { rootHash, balances } = verifyTokensBalancesForIdentityProof(proof.grovedbProof, tokenIds, id, true, PlatformVersionWASM.PLATFORM_V9);
|
|
33
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
34
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
35
|
+
if (!verify) {
|
|
36
|
+
throw new Error('Failed to verify query');
|
|
37
|
+
}
|
|
38
|
+
return balances
|
|
39
|
+
.map((tokenBalance) => ({
|
|
40
|
+
tokenId: new IdentifierWASM(tokenBalance.tokenId),
|
|
41
|
+
balance: tokenBalance.balance
|
|
42
|
+
}));
|
|
86
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface TokenContractInfo {
|
|
5
5
|
dataContractId: IdentifierWASM;
|
|
@@ -1,86 +1,43 @@
|
|
|
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 = getTokenContractInfo;
|
|
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 getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var tokenId, request, v0, _a, proof, metadata, _b, rootHash, contractInfo, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
tokenId = new pshenmic_dpp_1.IdentifierWASM(tokenIdentifier);
|
|
52
|
-
request = platform_1.GetTokenContractInfoRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
tokenId: (tokenId).bytes(),
|
|
55
|
-
prove: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return [4 /*yield*/, grpcPool.getClient().getTokenContractInfo(request)];
|
|
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.verifyTokenContractInfoProof)(proof.grovedbProof, tokenId, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, contractInfo = _b.contractInfo;
|
|
69
|
-
if (contractInfo == null) {
|
|
70
|
-
throw new Error('ContractInfo 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*/, {
|
|
80
|
-
dataContractId: contractInfo.contractId,
|
|
81
|
-
tokenContractPosition: contractInfo.tokenContractPosition
|
|
82
|
-
}];
|
|
1
|
+
import { GetTokenContractInfoRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenContractInfoProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
7
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
8
|
+
const getTokenContractInfoRequest = GetTokenContractInfoRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenId: (tokenId).bytes(),
|
|
13
|
+
prove: true
|
|
83
14
|
}
|
|
84
|
-
}
|
|
15
|
+
}
|
|
85
16
|
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenContractInfo(getTokenContractInfoRequest);
|
|
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, contractInfo } = verifyTokenContractInfoProof(proof.grovedbProof, tokenId, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (contractInfo == null) {
|
|
32
|
+
throw new Error('ContractInfo 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 {
|
|
40
|
+
dataContractId: contractInfo.contractId,
|
|
41
|
+
tokenContractPosition: contractInfo.tokenContractPosition
|
|
42
|
+
};
|
|
86
43
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices } from '../types.js';
|
|
3
|
+
export default function getTokenDirectPurchasePrices(grpcPool: GRPCConnectionPool, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenDirectPurchasePrices } from 'pshenmic-dpp';
|
|
2
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
3
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import { GetTokenDirectPurchasePricesRequest } from '../../proto/generated/platform.js';
|
|
6
|
+
export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdentifiers) {
|
|
7
|
+
const tokenIds = tokenIdentifiers.map(tokenId => new IdentifierWASM(tokenId).bytes());
|
|
8
|
+
const request = GetTokenDirectPurchasePricesRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenIds,
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenDirectPurchasePrices(request);
|
|
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, prices } = verifyTokenDirectPurchasePrices(proof.grovedbProof, tokenIds, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (prices == null) {
|
|
32
|
+
throw new Error('Prices 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 prices;
|
|
40
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenTotalSupply } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenTotalSupply } from '../types.js';
|
|
3
3
|
export default function getTokenTotalSupply(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
@@ -1,84 +1,41 @@
|
|
|
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 = getTokenTotalSupply;
|
|
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 getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var tokenId, request, v0, _a, proof, metadata, _b, rootHash, totalBalance, quorumPublicKey, verify;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
tokenId = new pshenmic_dpp_1.IdentifierWASM(tokenIdentifier);
|
|
52
|
-
request = platform_1.GetTokenTotalSupplyRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
tokenId: (tokenId).bytes(),
|
|
55
|
-
prove: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return [4 /*yield*/, grpcPool.getClient().getTokenTotalSupply(request)];
|
|
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.verifyTokenTotalSupplyProof)(proof.grovedbProof, tokenId, true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, totalBalance = _b.totalBalance;
|
|
69
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
70
|
-
case 2:
|
|
71
|
-
quorumPublicKey = _c.sent();
|
|
72
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
73
|
-
if (!verify) {
|
|
74
|
-
throw new Error('Failed to verify query');
|
|
75
|
-
}
|
|
76
|
-
return [2 /*return*/, {
|
|
77
|
-
tokenId: tokenId,
|
|
78
|
-
totalSystemAmount: totalBalance.tokenSupply,
|
|
79
|
-
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
80
|
-
}];
|
|
1
|
+
import { GetTokenTotalSupplyRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenTotalSupplyProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
7
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
8
|
+
const getTokenTotalSupplyRequest = GetTokenTotalSupplyRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenId: (tokenId).bytes(),
|
|
13
|
+
prove: true
|
|
81
14
|
}
|
|
82
|
-
}
|
|
15
|
+
}
|
|
83
16
|
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenTotalSupply(getTokenTotalSupplyRequest);
|
|
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, totalBalance } = verifyTokenTotalSupplyProof(proof.grovedbProof, tokenId, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
32
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
33
|
+
if (!verify) {
|
|
34
|
+
throw new Error('Failed to verify query');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
tokenId,
|
|
38
|
+
totalSystemAmount: totalBalance.tokenSupply,
|
|
39
|
+
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
40
|
+
};
|
|
84
41
|
}
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
|
-
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances';
|
|
4
|
-
import { IdentityTokenBalances } from './getIdentityTokensBalances';
|
|
5
|
-
import { TokenContractInfo } from './getTokenContractInfo';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types.js';
|
|
3
|
+
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances.js';
|
|
4
|
+
import { IdentityTokenBalances } from './getIdentityTokensBalances.js';
|
|
5
|
+
import { TokenContractInfo } from './getTokenContractInfo.js';
|
|
6
6
|
import { StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
7
7
|
/**
|
|
8
8
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
@@ -47,6 +47,14 @@ export declare class TokensController {
|
|
|
47
47
|
* @return {Promise<TokenTotalSupply>}
|
|
48
48
|
*/
|
|
49
49
|
getTokenTotalSupply(tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a tokens prices
|
|
52
|
+
*
|
|
53
|
+
* @param tokenIdentifiers {IdentifierLike[]} - token ids which price we need
|
|
54
|
+
*
|
|
55
|
+
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
56
|
+
*/
|
|
57
|
+
getTokensDirectPurchasePrice(tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
50
58
|
/**
|
|
51
59
|
* Creates a Token Base Transition that contains base information about token transition
|
|
52
60
|
*
|