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
package/src/documents/query.js
CHANGED
|
@@ -1,94 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 };
|
|
1
|
+
import { GetDocumentsRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyDocumentsProof } from 'pshenmic-dpp';
|
|
3
|
+
import { DAPI_DEFAULT_LIMIT } from '../constants.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
import { encode } from 'cbor-x';
|
|
8
|
+
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
9
|
+
export default async function query(grpcPool, dataContractId, documentTypeName, where, orderBy, limit = 100, startAt, startAfter) {
|
|
10
|
+
if ([startAt, startAfter].filter(e => e != null).length === 2) {
|
|
11
|
+
throw new Error('Only startAt or startAfter could be specified at one time');
|
|
12
|
+
}
|
|
13
|
+
let start;
|
|
14
|
+
if (startAt != null) {
|
|
15
|
+
start = {
|
|
16
|
+
oneofKind: 'startAt',
|
|
17
|
+
startAt: startAt.base58()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (startAfter != null) {
|
|
21
|
+
start = {
|
|
22
|
+
oneofKind: 'startAfter',
|
|
23
|
+
startAt: startAfter.base58()
|
|
24
|
+
};
|
|
36
25
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 : []];
|
|
26
|
+
const getDocumentsRequest = GetDocumentsRequest.create({
|
|
27
|
+
version: {
|
|
28
|
+
oneofKind: 'v0',
|
|
29
|
+
v0: {
|
|
30
|
+
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
31
|
+
documentType: documentTypeName,
|
|
32
|
+
where: encode(where),
|
|
33
|
+
orderBy: encode(orderBy),
|
|
34
|
+
limit: limit ?? DAPI_DEFAULT_LIMIT,
|
|
35
|
+
start,
|
|
36
|
+
prove: true
|
|
91
37
|
}
|
|
92
|
-
}
|
|
38
|
+
}
|
|
93
39
|
});
|
|
40
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
41
|
+
const { response } = await grpcPool.getClient().getDocuments(getDocumentsRequest);
|
|
42
|
+
const { version } = response;
|
|
43
|
+
if (version.oneofKind !== 'v0') {
|
|
44
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
45
|
+
}
|
|
46
|
+
const { v0 } = version;
|
|
47
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
48
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
49
|
+
}
|
|
50
|
+
const { result: { proof }, metadata } = v0;
|
|
51
|
+
if (metadata == null) {
|
|
52
|
+
throw new Error('Metadata not found');
|
|
53
|
+
}
|
|
54
|
+
const startAtIncluded = startAt != null;
|
|
55
|
+
const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startAt?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), PlatformVersionWASM.PLATFORM_V9);
|
|
56
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
57
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
58
|
+
if (!verify) {
|
|
59
|
+
throw new Error('Failed to verify query');
|
|
60
|
+
}
|
|
61
|
+
return documents ?? [];
|
|
94
62
|
}
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { PlatformClient } from '../proto/generated/platform.client.js';
|
|
2
|
+
import { Network } from './types.js';
|
|
3
|
+
export type MasternodeList = Record<string, MasternodeInfo>;
|
|
4
|
+
export interface GRPCOptions {
|
|
5
|
+
poolLimit: 5;
|
|
6
|
+
dapiUrl?: string | string[];
|
|
7
|
+
}
|
|
8
|
+
export interface MasternodeInfo {
|
|
9
|
+
proTxHash: string;
|
|
10
|
+
address: string;
|
|
11
|
+
payee: string;
|
|
12
|
+
status: string;
|
|
13
|
+
type: string;
|
|
14
|
+
platformNodeID: string;
|
|
15
|
+
platformP2PPort: number;
|
|
16
|
+
platformHTTPPort: number;
|
|
17
|
+
pospenaltyscore: number;
|
|
18
|
+
consecutivePayments: number;
|
|
19
|
+
lastpaidtime: number;
|
|
20
|
+
lastpaidblock: number;
|
|
21
|
+
owneraddress: string;
|
|
22
|
+
votingaddress: string;
|
|
23
|
+
collateraladdress: string;
|
|
24
|
+
pubkeyoperator: string;
|
|
25
|
+
}
|
|
4
26
|
export default class GRPCConnectionPool {
|
|
5
|
-
|
|
6
|
-
network:
|
|
7
|
-
constructor(network:
|
|
8
|
-
_initialize(network:
|
|
9
|
-
getClient():
|
|
27
|
+
dapiUrls: string[];
|
|
28
|
+
network: Network;
|
|
29
|
+
constructor(network: Network, grpcOptions?: GRPCOptions);
|
|
30
|
+
_initialize(network: Network, poolLimit: number, dapiUrl?: string | string[]): Promise<void>;
|
|
31
|
+
getClient(abortController?: AbortController): PlatformClient;
|
|
10
32
|
}
|
|
@@ -1,47 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 = {
|
|
1
|
+
import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';
|
|
2
|
+
import { PlatformClient } from '../proto/generated/platform.client.js';
|
|
3
|
+
import getEvonodeList from './utils/getEvonodeList.js';
|
|
4
|
+
import { GetStatusRequest } from '../proto/generated/platform.js';
|
|
5
|
+
import getRandomArrayItem from './utils/getRandomArrayItem.js';
|
|
6
|
+
const GRPC_DEFAULT_POOL_LIMIT = 5;
|
|
7
|
+
const seedNodes = {
|
|
45
8
|
testnet: [
|
|
46
9
|
// seed-1.pshenmic.dev
|
|
47
10
|
'https://158.160.14.115:1443'
|
|
@@ -55,83 +18,62 @@ var seedNodes = {
|
|
|
55
18
|
// 'https://34.211.174.194'
|
|
56
19
|
]
|
|
57
20
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
21
|
+
const createClient = (url, abortController) => {
|
|
22
|
+
return new PlatformClient(new GrpcWebFetchTransport({
|
|
23
|
+
baseUrl: url,
|
|
24
|
+
abort: abortController?.signal
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
export default class GRPCConnectionPool {
|
|
28
|
+
dapiUrls;
|
|
29
|
+
network;
|
|
30
|
+
constructor(network, grpcOptions) {
|
|
31
|
+
const grpcPoolLimit = grpcOptions?.poolLimit ?? GRPC_DEFAULT_POOL_LIMIT;
|
|
62
32
|
this.network = network;
|
|
63
|
-
this._initialize(network, grpcPoolLimit, grpcOptions
|
|
33
|
+
this._initialize(network, grpcPoolLimit, grpcOptions?.dapiUrl).catch(console.error);
|
|
64
34
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
});
|
|
35
|
+
async _initialize(network, poolLimit, dapiUrl) {
|
|
36
|
+
if (typeof dapiUrl === 'string') {
|
|
37
|
+
this.dapiUrls = [dapiUrl];
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(dapiUrl)) {
|
|
41
|
+
this.dapiUrls = dapiUrl;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (dapiUrl != null) {
|
|
45
|
+
throw new Error('Unrecognized DAPI URL');
|
|
46
|
+
}
|
|
47
|
+
// Add default seed nodes
|
|
48
|
+
this.dapiUrls = seedNodes[network];
|
|
49
|
+
// retrieve last evonodes list
|
|
50
|
+
const evonodeList = await getEvonodeList(network);
|
|
51
|
+
// map it to array of dapiUrls
|
|
52
|
+
const networkDAPIUrls = Object.entries(evonodeList)
|
|
53
|
+
.map(([, info]) => info)
|
|
54
|
+
.filter((info) => info.status === 'ENABLED')
|
|
55
|
+
.map((info) => {
|
|
56
|
+
const [host] = info.address.split(':');
|
|
57
|
+
return `https://${host}:${info.platformHTTPPort}`;
|
|
129
58
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
59
|
+
// healthcheck nodes
|
|
60
|
+
for (const url of networkDAPIUrls) {
|
|
61
|
+
if (this.dapiUrls.length > poolLimit) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const client = createClient(url);
|
|
66
|
+
const { response } = await client.getStatus(GetStatusRequest.create({}));
|
|
67
|
+
if (response.version.oneofKind === 'v0' && response.version.v0.chain != null) {
|
|
68
|
+
this.dapiUrls.push(url);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
getClient(abortController) {
|
|
76
|
+
const dapiUrl = getRandomArrayItem(this.dapiUrls);
|
|
77
|
+
return createClient(dapiUrl, abortController);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentityTransitionParams } from '../types';
|
|
3
|
-
export default function createStateTransition(type: 'create' | 'update' | 'topUp', params: IdentityTransitionParams): StateTransitionWASM;
|
|
2
|
+
import { IdentityTransitionParams } from '../types.js';
|
|
3
|
+
export default function createStateTransition(type: 'create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal', params: IdentityTransitionParams): StateTransitionWASM;
|
|
@@ -1,46 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {
|
|
1
|
+
import { IdentityCreateTransitionWASM, IdentityTopUpTransitionWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, IdentityCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
const identityTransitionsMap = {
|
|
15
3
|
create: {
|
|
16
|
-
class:
|
|
4
|
+
class: IdentityCreateTransitionWASM,
|
|
17
5
|
arguments: ['publicKeys', 'assetLockProof'],
|
|
18
6
|
optionalArguments: ['signature', 'userFeeIncrease']
|
|
19
7
|
},
|
|
20
8
|
topUp: {
|
|
21
|
-
class:
|
|
9
|
+
class: IdentityTopUpTransitionWASM,
|
|
22
10
|
arguments: ['assetLockProof', 'identityId'],
|
|
23
11
|
optionalArguments: ['userFeeIncrease']
|
|
24
12
|
},
|
|
25
13
|
update: {
|
|
26
|
-
class:
|
|
14
|
+
class: IdentityUpdateTransitionWASM,
|
|
27
15
|
arguments: ['identityId', 'revision', 'identityNonce', 'addPublicKeys', 'disablePublicKeyIds'],
|
|
28
16
|
optionalArguments: ['userFeeIncrease']
|
|
17
|
+
},
|
|
18
|
+
creditTransfer: {
|
|
19
|
+
class: IdentityCreditTransferWASM,
|
|
20
|
+
arguments: ['identityId', 'amount', 'recipientId', 'identityNonce'],
|
|
21
|
+
optionalArguments: ['userFeeIncrease']
|
|
22
|
+
},
|
|
23
|
+
withdrawal: {
|
|
24
|
+
class: IdentityCreditWithdrawalTransitionWASM,
|
|
25
|
+
arguments: ['identityId', 'amount', 'coreFeePerByte', 'pooling', 'identityNonce', 'outputScript'],
|
|
26
|
+
optionalArguments: ['userFeeIncrease']
|
|
29
27
|
}
|
|
30
28
|
};
|
|
31
|
-
function createStateTransition(type, params) {
|
|
32
|
-
|
|
29
|
+
export default function createStateTransition(type, params) {
|
|
30
|
+
const { class: TransitionClass, arguments: classArguments, optionalArguments } = identityTransitionsMap[type];
|
|
33
31
|
if (TransitionClass == null) {
|
|
34
|
-
throw new Error(
|
|
32
|
+
throw new Error(`Unimplemented transition type: ${type}`);
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
.filter(
|
|
38
|
-
!(optionalArguments).includes(classArgument)
|
|
34
|
+
const [missingArgument] = classArguments
|
|
35
|
+
.filter((classArgument) => params[classArgument] == null &&
|
|
36
|
+
!(optionalArguments).includes(classArgument));
|
|
39
37
|
if (missingArgument != null) {
|
|
40
|
-
throw new Error(
|
|
38
|
+
throw new Error(`Token transition param "${missingArgument}" is missing`);
|
|
41
39
|
}
|
|
42
|
-
|
|
40
|
+
const transitionParams = classArguments.map((classArgument) => params[classArgument]);
|
|
43
41
|
// @ts-expect-error
|
|
44
|
-
|
|
42
|
+
const identityTransition = new TransitionClass(...transitionParams);
|
|
45
43
|
return identityTransition.toStateTransition();
|
|
46
44
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IdentifierLike } from '../types';
|
|
2
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
1
|
+
import { IdentifierLike } from '../types.js';
|
|
2
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function getIdentityBalance(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<bigint>;
|
|
@@ -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 = 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)];
|
|
1
|
+
import { GetIdentityBalanceRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyIdentityBalanceProof } from 'pshenmic-dpp';
|
|
3
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
export default async function getIdentityBalance(grpcPool, identifier) {
|
|
7
|
+
const id = new IdentifierWASM(identifier);
|
|
8
|
+
const getIdentityBalanceRequest = GetIdentityBalanceRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
id: id.bytes(),
|
|
13
|
+
prove: true
|
|
80
14
|
}
|
|
81
|
-
}
|
|
15
|
+
}
|
|
82
16
|
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getIdentityBalance(getIdentityBalanceRequest);
|
|
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, balance } = verifyIdentityBalanceProof(proof.grovedbProof, id.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (balance == null) {
|
|
32
|
+
throw new Error(`Failed to fetch balance for identifier ${id.base58()}`);
|
|
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 BigInt(balance);
|
|
83
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IdentityWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
3
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
4
|
export default function getIdentityByIdentifier(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<IdentityWASM>;
|