dash-platform-sdk 1.2.0 → 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 -34
- 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 -49
- 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 -119
- 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 -80
- 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 -91
- 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 -81
- package/src/identities/getIdentityByIdentifier.d.ts +2 -2
- package/src/identities/getIdentityByIdentifier.js +37 -81
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -84
- package/src/identities/getIdentityByPublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByPublicKeyHash.js +37 -81
- package/src/identities/getIdentityContractNonce.d.ts +2 -2
- package/src/identities/getIdentityContractNonce.js +40 -84
- package/src/identities/getIdentityNonce.d.ts +2 -2
- package/src/identities/getIdentityNonce.js +38 -82
- 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 -79
- 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 -74
- 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 -84
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
- package/src/tokens/getIdentityTokensBalances.js +40 -84
- package/src/tokens/getTokenContractInfo.d.ts +2 -2
- package/src/tokens/getTokenContractInfo.js +40 -84
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
- package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
- package/src/tokens/getTokenTotalSupply.d.ts +2 -8
- package/src/tokens/getTokenTotalSupply.js +38 -82
- package/src/tokens/index.d.ts +13 -6
- package/src/tokens/index.js +46 -113
- package/src/types.d.ts +26 -17
- 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 -16
- 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 -5
- 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/utils/verifyBls.d.ts +0 -1
- package/src/utils/verifyBls.js +0 -15
package/src/names/index.js
CHANGED
|
@@ -1,50 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.NamesController = void 0;
|
|
40
|
-
var search_1 = require("./search");
|
|
1
|
+
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import searchByName from './searchByName.js';
|
|
3
|
+
import searchByIdentity from './searchByIdentity.js';
|
|
4
|
+
import registerName from './registerName.js';
|
|
5
|
+
import validateName from './validateName.js';
|
|
6
|
+
import getIdentityByIdentifier from '../identities/getIdentityByIdentifier.js';
|
|
7
|
+
import convertToHomographSafeChars from '../utils/convertToHomographSafeChars.js';
|
|
8
|
+
import testNameContested from './testNameContested.js';
|
|
41
9
|
/**
|
|
42
10
|
* Functions related to DPNS names (usernames)
|
|
43
11
|
*
|
|
44
12
|
* @hideconstructor
|
|
45
13
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
14
|
+
export class NamesController {
|
|
15
|
+
/** @ignore **/
|
|
16
|
+
grpcPool;
|
|
17
|
+
constructor(grpcPool) {
|
|
48
18
|
this.grpcPool = grpcPool;
|
|
49
19
|
}
|
|
50
20
|
/**
|
|
@@ -61,30 +31,72 @@ var NamesController = /** @class */ (function () {
|
|
|
61
31
|
*
|
|
62
32
|
* @return Promise<DocumentWASM | null>
|
|
63
33
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
34
|
+
async searchByName(name) {
|
|
35
|
+
const validation = validateName(name);
|
|
36
|
+
if (validation != null) {
|
|
37
|
+
throw new Error(validation);
|
|
38
|
+
}
|
|
39
|
+
return await searchByName(this.grpcPool, name);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Tests a given username against contested names rules.
|
|
43
|
+
* Contested names includes an additional fee of 0.2 Dash
|
|
44
|
+
* as a voting resolution fee
|
|
45
|
+
*
|
|
46
|
+
* This function return boolean whether given username (f.e pshenmic.dash)
|
|
47
|
+
* falls under contested names rules.
|
|
48
|
+
* @param name
|
|
49
|
+
*/
|
|
50
|
+
testNameContested(name) {
|
|
51
|
+
const validation = validateName(name);
|
|
52
|
+
if (validation != null) {
|
|
53
|
+
throw new Error(validation);
|
|
54
|
+
}
|
|
55
|
+
const [label] = name.split('.');
|
|
56
|
+
const normalizedLabel = convertToHomographSafeChars(label);
|
|
57
|
+
return testNameContested(normalizedLabel);
|
|
58
|
+
}
|
|
59
|
+
async searchByIdentity(identifier) {
|
|
60
|
+
return await searchByIdentity(this.grpcPool, new IdentifierWASM(identifier));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Performs a DPNS name registration sequence
|
|
64
|
+
* Contested names are include additional fee of 0.2 Dash
|
|
65
|
+
* Check your name is contested with .testNameContested(name) method to check if additional fee will be charged
|
|
66
|
+
*
|
|
67
|
+
* @param name {string} username (ex. pshenmic.dash)
|
|
68
|
+
* @param identityId {IdentifierLike} identity identifier
|
|
69
|
+
* @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
|
|
70
|
+
*/
|
|
71
|
+
async registerName(name, identityId, privateKey) {
|
|
72
|
+
const validation = validateName(name);
|
|
73
|
+
if (validation != null) {
|
|
74
|
+
throw new Error(validation);
|
|
75
|
+
}
|
|
76
|
+
const identity = await getIdentityByIdentifier(this.grpcPool, identityId);
|
|
77
|
+
await registerName(this.grpcPool, name, identity, privateKey);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
|
|
81
|
+
*
|
|
82
|
+
* source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
|
|
83
|
+
*
|
|
84
|
+
*
|
|
85
|
+
* @param label {string}
|
|
86
|
+
*
|
|
87
|
+
* @return {string}
|
|
88
|
+
*/
|
|
89
|
+
normalizeLabel(label) {
|
|
90
|
+
return convertToHomographSafeChars(label);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Validates a DPNS name that you would like to register
|
|
94
|
+
*
|
|
95
|
+
* @param fullName {string} full DPNS name (ex. pshenmic.dash)
|
|
96
|
+
*
|
|
97
|
+
* @return {string} null if valid or string with a reason
|
|
98
|
+
*/
|
|
99
|
+
validateName(fullName) {
|
|
100
|
+
return validateName(fullName);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import convertToHomographSafeChars from '../utils/convertToHomographSafeChars.js';
|
|
2
|
+
import { PrefundedVotingBalanceWASM } from 'pshenmic-dpp';
|
|
3
|
+
import getRandomBytes from '../utils/getRandomBytes.js';
|
|
4
|
+
import sha256 from '../utils/sha256.js';
|
|
5
|
+
import createDocument from '../documents/create.js';
|
|
6
|
+
import createStateTransition from '../documents/createStateTransition.js';
|
|
7
|
+
import getIdentityContractNonce from '../identities/getIdentityContractNonce.js';
|
|
8
|
+
import broadcast from '../stateTransitions/broadcast.js';
|
|
9
|
+
import waitForStateTransitionResult from '../stateTransitions/waitForStateTransitionResult.js';
|
|
10
|
+
import testNameContested from './testNameContested.js';
|
|
11
|
+
import { DPNS_DATA_CONTRACT_ID } from '../constants.js';
|
|
12
|
+
export default async function registerName(grpcPool, name, identity, privateKey) {
|
|
13
|
+
const [identityPublicKey] = identity.getPublicKeys().filter(identityPublicKey => identityPublicKey.getPublicKeyHash() === privateKey.getPublicKeyHash());
|
|
14
|
+
if (identityPublicKey == null) {
|
|
15
|
+
throw new Error('Private key does not match the identity');
|
|
16
|
+
}
|
|
17
|
+
if (identityPublicKey.securityLevel !== 'HIGH' && identityPublicKey.purpose !== 'AUTHENTICATION') {
|
|
18
|
+
throw new Error('Wrong private key, must be from AUTHENTICATION HIGH identity public key');
|
|
19
|
+
}
|
|
20
|
+
const [label, parentDomainName] = name.split('.');
|
|
21
|
+
const salt = getRandomBytes(32);
|
|
22
|
+
const normalizedParentDomainName = convertToHomographSafeChars(parentDomainName);
|
|
23
|
+
const normalizedLabel = convertToHomographSafeChars(label);
|
|
24
|
+
const normalizedFullDomainName = `${normalizedLabel}.${normalizedParentDomainName}`;
|
|
25
|
+
const saltedDomainHash = await sha256(await sha256(new Uint8Array([
|
|
26
|
+
...salt,
|
|
27
|
+
...new TextEncoder().encode(normalizedFullDomainName)
|
|
28
|
+
])));
|
|
29
|
+
let document;
|
|
30
|
+
let stateTransition;
|
|
31
|
+
// 1. Create preorder document
|
|
32
|
+
const preorderData = {
|
|
33
|
+
saltedDomainHash: Array.from(saltedDomainHash)
|
|
34
|
+
};
|
|
35
|
+
const identityContractNonce = await getIdentityContractNonce(grpcPool, identity.id, DPNS_DATA_CONTRACT_ID);
|
|
36
|
+
document = createDocument(DPNS_DATA_CONTRACT_ID, 'preorder', preorderData, identity.id.base58());
|
|
37
|
+
stateTransition = createStateTransition(document, 'create', { identityContractNonce: identityContractNonce + BigInt(1) });
|
|
38
|
+
await stateTransition.sign(privateKey, identityPublicKey);
|
|
39
|
+
await broadcast(grpcPool, stateTransition);
|
|
40
|
+
// wait for state transition confirmation before next broadcast
|
|
41
|
+
await waitForStateTransitionResult(grpcPool, stateTransition);
|
|
42
|
+
// 2. Create domain document
|
|
43
|
+
const domainData = {
|
|
44
|
+
label,
|
|
45
|
+
normalizedLabel,
|
|
46
|
+
parentDomainName,
|
|
47
|
+
normalizedParentDomainName,
|
|
48
|
+
preorderSalt: Array.from(salt),
|
|
49
|
+
records: {
|
|
50
|
+
identity: Array.from(identity.id.bytes())
|
|
51
|
+
},
|
|
52
|
+
subdomainRules: {
|
|
53
|
+
allowSubdomains: false
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
document = createDocument(DPNS_DATA_CONTRACT_ID, 'domain', domainData, identity.id.base58());
|
|
57
|
+
stateTransition = createStateTransition(document, 'create', {
|
|
58
|
+
identityContractNonce: identityContractNonce + BigInt(2),
|
|
59
|
+
// @ts-expect-error
|
|
60
|
+
prefundedVotingBalance: testNameContested(normalizedLabel) ? new PrefundedVotingBalanceWASM('parentNameAndLabel', BigInt(20000000000)) : undefined
|
|
61
|
+
});
|
|
62
|
+
await stateTransition.sign(privateKey, identityPublicKey);
|
|
63
|
+
await broadcast(grpcPool, stateTransition);
|
|
64
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import query from '../documents/query.js';
|
|
2
|
+
const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
3
|
+
export default async function searchByIdentity(grpcPool, identifier) {
|
|
4
|
+
return await query(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', [['records.identity', '=', identifier.base58()]], [['records.identity', 'asc']]);
|
|
5
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import convertToHomographSafeChars from '../utils/convertToHomographSafeChars.js';
|
|
2
|
+
import query from '../documents/query.js';
|
|
3
|
+
const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
4
|
+
export default async function search(grpcPool, name) {
|
|
5
|
+
const [label, parentDomainName] = name.split('.');
|
|
6
|
+
const normalizedParentDomainName = convertToHomographSafeChars(parentDomainName);
|
|
7
|
+
const normalizedLabelPrefix = convertToHomographSafeChars(label);
|
|
8
|
+
const where = [
|
|
9
|
+
['normalizedParentDomainName', '==', normalizedParentDomainName],
|
|
10
|
+
['normalizedLabel', 'startsWith', normalizedLabelPrefix]
|
|
11
|
+
];
|
|
12
|
+
const orderBy = [
|
|
13
|
+
['normalizedLabel', 'asc']
|
|
14
|
+
];
|
|
15
|
+
return await query(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', where, orderBy);
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function testNameContested(normalizedLabel: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function validateName(fullName: string): string | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function validateName(fullName) {
|
|
2
|
+
const chunks = fullName.split('.');
|
|
3
|
+
if (chunks.length !== 2) {
|
|
4
|
+
return 'Name to search should be a full domain name (ex. pshenmic.dash)';
|
|
5
|
+
}
|
|
6
|
+
const [label, parentDomainName] = chunks;
|
|
7
|
+
if (parentDomainName !== 'dash') {
|
|
8
|
+
return 'Root domain must be .dash';
|
|
9
|
+
}
|
|
10
|
+
return /^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$/.test(label) ? null : 'Unacceptable label name';
|
|
11
|
+
}
|
package/src/node/epochs.d.ts
CHANGED
package/src/node/epochs.js
CHANGED
|
@@ -1,82 +1,46 @@
|
|
|
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 = epochs;
|
|
40
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
-
var wasm_drive_verify_1 = require("wasm-drive-verify");
|
|
42
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
43
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
44
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
45
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
46
|
-
function epochs(grpcPool, count, ascending, start) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var request, v0, _a, proof, metadata, _b, rootHash, epochInfos, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
request = platform_1.GetEpochsInfoRequest.fromPartial({
|
|
53
|
-
v0: {
|
|
54
|
-
startEpoch: start,
|
|
55
|
-
count: count,
|
|
56
|
-
ascending: ascending,
|
|
57
|
-
prove: true
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return [4 /*yield*/, grpcPool.getClient().getEpochsInfo(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, wasm_drive_verify_1.verifyEpochInfos)(proof.grovedbProof, metadata.epoch, start, count, ascending, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, epochInfos = _b.epoch_infos;
|
|
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*/, epochInfos];
|
|
1
|
+
import { GetEpochsInfoRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { PlatformVersionWASM, verifyEpochsInfoProof } 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
|
+
import { UInt32Value } from '../../proto/generated/google/protobuf/wrappers.js';
|
|
7
|
+
export default async function epochs(grpcPool, count, ascending, start) {
|
|
8
|
+
const getEpochsInfoRequest = GetEpochsInfoRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
startEpoch: start != null ? UInt32Value.create({ value: start }) : undefined,
|
|
13
|
+
count,
|
|
14
|
+
ascending,
|
|
15
|
+
prove: true
|
|
79
16
|
}
|
|
80
|
-
}
|
|
17
|
+
}
|
|
81
18
|
});
|
|
19
|
+
const { response } = await grpcPool.getClient().getEpochsInfo(getEpochsInfoRequest);
|
|
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, epochsInfo } = verifyEpochsInfoProof(proof.grovedbProof, metadata.epoch, start, count, ascending, 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 epochsInfo.map(info => ({
|
|
39
|
+
number: info.index,
|
|
40
|
+
firstBlockHeight: info.firstBlockHeight,
|
|
41
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
42
|
+
startTime: info.firstBlockTime,
|
|
43
|
+
feeMultiplier: info.feeMultiplierPermille,
|
|
44
|
+
protocolVersion: info.protocolVersion
|
|
45
|
+
}));
|
|
82
46
|
}
|
package/src/node/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { NodeStatus } from '../types';
|
|
3
|
-
import { EpochInfo } from './epochs';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { Network, NodeStatus } from '../types.js';
|
|
3
|
+
import { EpochInfo } from './epochs.js';
|
|
4
4
|
/**
|
|
5
5
|
* Node controller for requesting information about DAPI node
|
|
6
6
|
*
|
|
@@ -9,8 +9,8 @@ import { EpochInfo } from './epochs';
|
|
|
9
9
|
export declare class NodeController {
|
|
10
10
|
/** @ignore **/
|
|
11
11
|
grpcPool: GRPCConnectionPool;
|
|
12
|
-
network:
|
|
13
|
-
constructor(grpcPool: GRPCConnectionPool, network:
|
|
12
|
+
network: Network;
|
|
13
|
+
constructor(grpcPool: GRPCConnectionPool, network: Network);
|
|
14
14
|
/**
|
|
15
15
|
* Retrieves an info about node
|
|
16
16
|
* Includes information about genesis, chain, software versions
|
package/src/node/index.js
CHANGED
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.NodeController = void 0;
|
|
40
|
-
var status_1 = require("./status");
|
|
41
|
-
var epochs_1 = require("./epochs");
|
|
42
|
-
var totalCredits_1 = require("./totalCredits");
|
|
1
|
+
import getStatus from './status.js';
|
|
2
|
+
import getEpochsInfo from './epochs.js';
|
|
3
|
+
import getTotalCredits from './totalCredits.js';
|
|
43
4
|
/**
|
|
44
5
|
* Node controller for requesting information about DAPI node
|
|
45
6
|
*
|
|
46
7
|
* @hideconstructor
|
|
47
8
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
9
|
+
export class NodeController {
|
|
10
|
+
/** @ignore **/
|
|
11
|
+
grpcPool;
|
|
12
|
+
network;
|
|
13
|
+
constructor(grpcPool, network) {
|
|
50
14
|
this.grpcPool = grpcPool;
|
|
51
15
|
this.network = network;
|
|
52
16
|
}
|
|
@@ -56,47 +20,24 @@ var NodeController = /** @class */ (function () {
|
|
|
56
20
|
*
|
|
57
21
|
* @return {Promise<NodeStatus>}
|
|
58
22
|
*/
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, (0, status_1.default)(this.grpcPool)];
|
|
64
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
};
|
|
23
|
+
async status() {
|
|
24
|
+
return await getStatus(this.grpcPool);
|
|
25
|
+
}
|
|
69
26
|
/**
|
|
70
27
|
* Returns total credits amount in platform
|
|
71
28
|
*
|
|
72
29
|
* @return {Promise<bigint>}
|
|
73
30
|
*/
|
|
74
|
-
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0: return [4 /*yield*/, (0, totalCredits_1.default)(this.grpcPool, this.network)];
|
|
79
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
31
|
+
async totalCredits() {
|
|
32
|
+
return await getTotalCredits(this.grpcPool, this.network);
|
|
33
|
+
}
|
|
84
34
|
/**
|
|
85
35
|
* Retrieves an info about epochs
|
|
86
36
|
* Includes information about first block height, time, fee multiplier, number
|
|
87
37
|
*
|
|
88
38
|
* @return {Promise<EpochInfo[]>}
|
|
89
39
|
*/
|
|
90
|
-
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case 0: return [4 /*yield*/, (0, epochs_1.default)(this.grpcPool, count, ascending, start)];
|
|
95
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
return NodeController;
|
|
101
|
-
}());
|
|
102
|
-
exports.NodeController = NodeController;
|
|
40
|
+
async getEpochsInfo(count, ascending, start) {
|
|
41
|
+
return await getEpochsInfo(this.grpcPool, count, ascending, start);
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/node/status.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NodeStatus } from '../types';
|
|
2
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
1
|
+
import { NodeStatus } from '../types.js';
|
|
2
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function status(grpcPool: GRPCConnectionPool): Promise<NodeStatus>;
|