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.
Files changed (189) hide show
  1. package/bundle.min.js +21 -2
  2. package/index.d.ts +1 -1
  3. package/index.js +2 -5
  4. package/package.json +32 -31
  5. package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
  6. package/proto/generated/google/protobuf/wrappers.js +562 -345
  7. package/proto/generated/platform.client.d.ts +251 -0
  8. package/proto/generated/platform.client.js +175 -0
  9. package/proto/generated/platform.d.ts +3682 -1939
  10. package/proto/generated/platform.js +8119 -18366
  11. package/src/DashPlatformSDK.d.ts +18 -19
  12. package/src/DashPlatformSDK.js +52 -45
  13. package/src/constants.d.ts +2 -0
  14. package/src/constants.js +7 -8
  15. package/src/contestedResources/createStateTransition.d.ts +2 -0
  16. package/src/contestedResources/createStateTransition.js +6 -0
  17. package/src/contestedResources/getContestedResourceVoteState.d.ts +3 -3
  18. package/src/contestedResources/getContestedResourceVoteState.js +67 -118
  19. package/src/contestedResources/index.d.ts +3 -3
  20. package/src/contestedResources/index.js +9 -55
  21. package/src/dataContracts/create.d.ts +1 -1
  22. package/src/dataContracts/create.js +5 -8
  23. package/src/dataContracts/createStateTransition.js +10 -14
  24. package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -2
  25. package/src/dataContracts/getDataContractByIdentifier.js +40 -79
  26. package/src/dataContracts/index.d.ts +2 -2
  27. package/src/dataContracts/index.js +17 -63
  28. package/src/documents/create.d.ts +1 -1
  29. package/src/documents/create.js +3 -6
  30. package/src/documents/createStateTransition.d.ts +1 -1
  31. package/src/documents/createStateTransition.js +19 -31
  32. package/src/documents/index.d.ts +2 -2
  33. package/src/documents/index.js +25 -72
  34. package/src/documents/query.d.ts +2 -2
  35. package/src/documents/query.js +58 -90
  36. package/src/grpcConnectionPool.d.ts +30 -8
  37. package/src/grpcConnectionPool.js +63 -121
  38. package/src/identities/createStateTransition.d.ts +2 -2
  39. package/src/identities/createStateTransition.js +24 -26
  40. package/src/identities/getIdentityBalance.d.ts +2 -2
  41. package/src/identities/getIdentityBalance.js +37 -80
  42. package/src/identities/getIdentityByIdentifier.d.ts +2 -2
  43. package/src/identities/getIdentityByIdentifier.js +37 -80
  44. package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +1 -1
  45. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
  46. package/src/identities/getIdentityByPublicKeyHash.d.ts +1 -1
  47. package/src/identities/getIdentityByPublicKeyHash.js +37 -80
  48. package/src/identities/getIdentityContractNonce.d.ts +2 -2
  49. package/src/identities/getIdentityContractNonce.js +40 -83
  50. package/src/identities/getIdentityNonce.d.ts +2 -2
  51. package/src/identities/getIdentityNonce.js +38 -81
  52. package/src/identities/getIdentityPublicKeys.d.ts +2 -2
  53. package/src/identities/getIdentityPublicKeys.js +43 -81
  54. package/src/identities/index.d.ts +6 -4
  55. package/src/identities/index.js +70 -154
  56. package/src/keyPair/deriveChild.d.ts +2 -2
  57. package/src/keyPair/deriveChild.js +2 -49
  58. package/src/keyPair/derivePath.d.ts +2 -2
  59. package/src/keyPair/derivePath.js +2 -49
  60. package/src/keyPair/index.d.ts +39 -114
  61. package/src/keyPair/index.js +62 -296
  62. package/src/keyPair/mnemonicToSeed.d.ts +1 -1
  63. package/src/keyPair/mnemonicToSeed.js +3 -46
  64. package/src/names/index.d.ts +44 -3
  65. package/src/names/index.js +81 -69
  66. package/src/names/registerName.d.ts +3 -0
  67. package/src/names/registerName.js +64 -0
  68. package/src/names/searchByIdentity.d.ts +3 -0
  69. package/src/names/searchByIdentity.js +5 -0
  70. package/src/names/searchByName.d.ts +3 -0
  71. package/src/names/searchByName.js +16 -0
  72. package/src/names/testNameContested.d.ts +1 -0
  73. package/src/names/testNameContested.js +3 -0
  74. package/src/names/validateName.d.ts +1 -0
  75. package/src/names/validateName.js +11 -0
  76. package/src/node/epochs.d.ts +1 -1
  77. package/src/node/epochs.js +43 -85
  78. package/src/node/index.d.ts +5 -5
  79. package/src/node/index.js +18 -77
  80. package/src/node/status.d.ts +2 -2
  81. package/src/node/status.js +37 -81
  82. package/src/node/totalCredits.d.ts +3 -2
  83. package/src/node/totalCredits.js +32 -73
  84. package/src/stateTransitions/broadcast.d.ts +1 -1
  85. package/src/stateTransitions/broadcast.js +7 -57
  86. package/src/stateTransitions/index.d.ts +1 -1
  87. package/src/stateTransitions/index.js +13 -66
  88. package/src/stateTransitions/waitForStateTransitionResult.d.ts +1 -1
  89. package/src/stateTransitions/waitForStateTransitionResult.js +6 -62
  90. package/src/tokens/createStateTransition.d.ts +1 -1
  91. package/src/tokens/createStateTransition.js +23 -35
  92. package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -2
  93. package/src/tokens/getIdentitiesTokenBalances.js +40 -83
  94. package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
  95. package/src/tokens/getIdentityTokensBalances.js +40 -83
  96. package/src/tokens/getTokenContractInfo.d.ts +2 -2
  97. package/src/tokens/getTokenContractInfo.js +40 -83
  98. package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
  99. package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
  100. package/src/tokens/getTokenTotalSupply.d.ts +2 -2
  101. package/src/tokens/getTokenTotalSupply.js +38 -81
  102. package/src/tokens/index.d.ts +13 -5
  103. package/src/tokens/index.js +46 -113
  104. package/src/types.d.ts +20 -16
  105. package/src/types.js +6 -16
  106. package/src/utils/base58ToBytes.js +3 -6
  107. package/src/utils/bytesToHex.js +2 -5
  108. package/src/utils/bytesToTypedArray.d.ts +1 -0
  109. package/src/utils/bytesToTypedArray.js +3 -0
  110. package/src/utils/calculateMsgHash.d.ts +1 -1
  111. package/src/utils/calculateMsgHash.js +10 -13
  112. package/src/utils/calculateSignHash.d.ts +2 -2
  113. package/src/utils/calculateSignHash.js +7 -10
  114. package/src/utils/calculateStateIdHash.d.ts +2 -2
  115. package/src/utils/calculateStateIdHash.js +8 -10
  116. package/src/utils/convertToHomographSafeChars.d.ts +0 -4
  117. package/src/utils/convertToHomographSafeChars.js +2 -9
  118. package/src/utils/createMasternodeIdentityId.d.ts +2 -0
  119. package/src/utils/createMasternodeIdentityId.js +4 -0
  120. package/src/utils/createVoterIdentityId.d.ts +2 -0
  121. package/src/utils/createVoterIdentityId.js +13 -0
  122. package/src/utils/getEvonodeList.d.ts +2 -2
  123. package/src/utils/getEvonodeList.js +10 -61
  124. package/src/utils/getQuorumPublicKey.js +15 -66
  125. package/src/utils/getRandomArrayItem.js +1 -4
  126. package/src/utils/getRandomBytes.d.ts +1 -0
  127. package/src/utils/getRandomBytes.js +4 -0
  128. package/src/utils/hexToBytes.js +2 -6
  129. package/src/utils/index.d.ts +19 -3
  130. package/src/utils/index.js +45 -31
  131. package/src/utils/indexBytesToString.js +2 -5
  132. package/src/utils/sha256.d.ts +1 -1
  133. package/src/utils/sha256.js +10 -8
  134. package/src/utils/signHash.d.ts +1 -1
  135. package/src/utils/signHash.js +9 -12
  136. package/src/utils/signRequestId.d.ts +1 -1
  137. package/src/utils/signRequestId.js +9 -12
  138. package/src/utils/sleep.d.ts +1 -0
  139. package/src/utils/sleep.js +3 -0
  140. package/src/utils/stringToIndexValueBytes.js +4 -7
  141. package/src/utils/verifyTenderdashProof.d.ts +2 -2
  142. package/src/utils/verifyTenderdashProof.js +13 -17
  143. package/src/voting/createStateTransition.d.ts +2 -0
  144. package/src/voting/createStateTransition.js +6 -0
  145. package/src/voting/createVote.d.ts +2 -0
  146. package/src/voting/createVote.js +5 -0
  147. package/src/voting/index.d.ts +37 -0
  148. package/src/voting/index.js +55 -0
  149. package/test/unit/ContestedResources.spec.js +91 -90
  150. package/test/unit/DataContract.spec.js +44 -111
  151. package/test/unit/Document.spec.js +93 -183
  152. package/test/unit/Identity.spec.js +254 -357
  153. package/test/unit/KeyPair.spec.js +30 -145
  154. package/test/unit/Names.spec.d.ts +1 -0
  155. package/test/unit/Names.spec.js +33 -0
  156. package/test/unit/Node.spec.js +55 -126
  157. package/test/unit/SDK.spec.js +7 -9
  158. package/test/unit/Tokens.spec.js +112 -262
  159. package/bundle.min.js.LICENSE.txt +0 -1
  160. package/src/keyPair/keyToPublicKey.d.ts +0 -2
  161. package/src/keyPair/keyToPublicKey.js +0 -47
  162. package/src/keyPair/keyToWalletId.d.ts +0 -2
  163. package/src/keyPair/keyToWalletId.js +0 -50
  164. package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
  165. package/src/keyPair/keyToXPrivateKey.js +0 -50
  166. package/src/keyPair/keyToXPublicKey.d.ts +0 -3
  167. package/src/keyPair/keyToXPublicKey.js +0 -50
  168. package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
  169. package/src/keyPair/mnemonicToIdentityKey.js +0 -57
  170. package/src/keyPair/mnemonicToWallet.d.ts +0 -2
  171. package/src/keyPair/mnemonicToWallet.js +0 -55
  172. package/src/keyPair/privateKeyToWif.d.ts +0 -2
  173. package/src/keyPair/privateKeyToWif.js +0 -50
  174. package/src/keyPair/publicKeyToAddress.d.ts +0 -2
  175. package/src/keyPair/publicKeyToAddress.js +0 -50
  176. package/src/keyPair/seedToWallet.d.ts +0 -2
  177. package/src/keyPair/seedToWallet.js +0 -50
  178. package/src/keyPair/walletToIdentityKey.d.ts +0 -3
  179. package/src/keyPair/walletToIdentityKey.js +0 -56
  180. package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
  181. package/src/keyPair/xkeyToHDXKey.js +0 -50
  182. package/src/names/search.d.ts +0 -3
  183. package/src/names/search.js +0 -63
  184. package/src/signer/AbstractSigner.d.ts +0 -12
  185. package/src/signer/AbstractSigner.js +0 -2
  186. package/src/signer/PrivateKeySigner.d.ts +0 -0
  187. package/src/signer/PrivateKeySigner.js +0 -64
  188. package/src/signer/setSigner.d.ts +0 -2
  189. package/src/signer/setSigner.js +0 -8
@@ -1,69 +1,18 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1
+ const cache = {};
2
+ export async function getQuorumPublicKey(network, quorumType, quorumHash) {
3
+ const cached = cache[`${quorumType}_${quorumHash}`];
4
+ if (cached != null) {
5
+ return cached;
36
6
  }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getQuorumPublicKey = getQuorumPublicKey;
40
- var cache = {};
41
- function getQuorumPublicKey(network, quorumType, quorumHash) {
42
- return __awaiter(this, void 0, void 0, function () {
43
- var cached, url, resp, data, quorumPublicKey;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0:
47
- cached = cache["".concat(quorumType, "_").concat(quorumHash)];
48
- if (cached != null) {
49
- return [2 /*return*/, cached];
50
- }
51
- url = "https://".concat(network === 'mainnet' ? '' : 'testnet.', "platform-explorer.pshenmic.dev/quorum/info?quorumType=").concat(quorumType, "&quorumHash=").concat(quorumHash);
52
- return [4 /*yield*/, fetch(url, {
53
- method: 'GET'
54
- })];
55
- case 1:
56
- resp = _a.sent();
57
- if (resp.status !== 200) {
58
- throw new Error('Failed to query Platform Explorer for quorum public keys');
59
- }
60
- return [4 /*yield*/, resp.json()];
61
- case 2:
62
- data = _a.sent();
63
- quorumPublicKey = data.quorumPublicKey;
64
- cache["".concat(quorumType, "_").concat(quorumHash)] = quorumPublicKey;
65
- return [2 /*return*/, quorumPublicKey];
66
- }
67
- });
7
+ const url = `https://${network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/quorum/info?quorumType=${quorumType}&quorumHash=${quorumHash}`;
8
+ const resp = await fetch(url, {
9
+ method: 'GET'
68
10
  });
11
+ if (resp.status !== 200) {
12
+ throw new Error('Failed to query Platform Explorer for quorum public keys');
13
+ }
14
+ const data = await resp.json();
15
+ const { quorumPublicKey } = data;
16
+ cache[`${quorumType}_${quorumHash}`] = quorumPublicKey;
17
+ return quorumPublicKey;
69
18
  }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = getRandomArrayItem;
4
- function getRandomArrayItem(array) {
1
+ export default function getRandomArrayItem(array) {
5
2
  return array[Math.floor((Math.random() * array.length))];
6
3
  }
@@ -0,0 +1 @@
1
+ export default function getRandomBytes(length: number): Uint8Array;
@@ -0,0 +1,4 @@
1
+ export default function getRandomBytes(length) {
2
+ const array = Uint8Array.from({ length });
3
+ return crypto.getRandomValues(array);
4
+ }
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = hexToBytes;
4
- function hexToBytes(hex) {
5
- var _a;
6
- return Uint8Array.from(((_a = hex.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map(function (byte) { return parseInt(byte, 16); }));
1
+ export default function hexToBytes(hex) {
2
+ return Uint8Array.from((hex.match(/.{1,2}/g) ?? []).map((byte) => parseInt(byte, 16)));
7
3
  }
@@ -1,3 +1,4 @@
1
+ import { IdentifierWASM } from 'pshenmic-dpp';
1
2
  /**
2
3
  * Collection of conversion functions
3
4
  *
@@ -37,13 +38,28 @@ export declare class UtilsController {
37
38
  */
38
39
  hexToBytes(hex: string): Uint8Array;
39
40
  /**
40
- * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
41
- *
42
- * source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
41
+ * @deprecated use sdk.names.normalizeLabel()
43
42
  *
44
43
  * @param str {string}
45
44
  *
46
45
  * @return {string}
47
46
  */
48
47
  convertToHomographSafeChars(str: string): string;
48
+ /**
49
+ * Creates a voting identity identifier from proTxHash and voting address
50
+ *
51
+ * @param proTxHash {string} Pro TX Hash in hex format
52
+ * @param publicKeyHash {string} Voting address's public key hash (20 bytes), in hex
53
+ *
54
+ * @return {Promise<string>}
55
+ */
56
+ createVoterIdentifier(proTxHash: string, publicKeyHash: string): Promise<IdentifierWASM>;
57
+ /**
58
+ * Creates a masternode identity identifier from proTxHash
59
+ *
60
+ * @param proTxHash {string} Pro TX Hash in hex format
61
+ *
62
+ * @return {string}
63
+ * */
64
+ createMasternodeIdentifier(proTxHash: string): IdentifierWASM;
49
65
  }
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UtilsController = void 0;
4
- var convertToHomographSafeChars_1 = require("./convertToHomographSafeChars");
5
- var base_1 = require("@scure/base");
6
- var hexToBytes_1 = require("./hexToBytes");
7
- var bytesToHex_1 = require("./bytesToHex");
1
+ import convertToHomographSafeChars from './convertToHomographSafeChars.js';
2
+ import { base58 } from '@scure/base';
3
+ import hexToBytes from './hexToBytes.js';
4
+ import bytesToHex from './bytesToHex.js';
5
+ import { createVoterIdentityId } from './createVoterIdentityId.js';
6
+ import { createMasternodeIdentityId } from './createMasternodeIdentityId.js';
8
7
  /**
9
8
  * Collection of conversion functions
10
9
  *
11
10
  * @hideconstructor
12
11
  */
13
- var UtilsController = /** @class */ (function () {
14
- function UtilsController() {
15
- }
12
+ export class UtilsController {
16
13
  /**
17
14
  * Converts base58 string to an Uint8Array
18
15
  *
@@ -20,9 +17,9 @@ var UtilsController = /** @class */ (function () {
20
17
  *
21
18
  * @returns {Uint8Array}
22
19
  */
23
- UtilsController.prototype.base58ToBytes = function (str) {
24
- return base_1.base58.decode(str);
25
- };
20
+ base58ToBytes(str) {
21
+ return base58.decode(str);
22
+ }
26
23
  /**
27
24
  * Converts Uint8Array to base58 string
28
25
  *
@@ -30,9 +27,9 @@ var UtilsController = /** @class */ (function () {
30
27
  *
31
28
  * @return {string}
32
29
  */
33
- UtilsController.prototype.bytesToBase58 = function (bytes) {
34
- return base_1.base58.encode(bytes);
35
- };
30
+ bytesToBase58(bytes) {
31
+ return base58.encode(bytes);
32
+ }
36
33
  /**
37
34
  * Converts Uint8Array to hex string
38
35
  *
@@ -40,9 +37,9 @@ var UtilsController = /** @class */ (function () {
40
37
  *
41
38
  * @return {string}
42
39
  */
43
- UtilsController.prototype.bytesToHex = function (bytes) {
44
- return (0, bytesToHex_1.default)(bytes);
45
- };
40
+ bytesToHex(bytes) {
41
+ return bytesToHex(bytes);
42
+ }
46
43
  /**
47
44
  * Converts a hex string to Uint8Array
48
45
  *
@@ -50,21 +47,38 @@ var UtilsController = /** @class */ (function () {
50
47
  *
51
48
  * @return {Uint8Array}
52
49
  */
53
- UtilsController.prototype.hexToBytes = function (hex) {
54
- return (0, hexToBytes_1.default)(hex);
55
- };
50
+ hexToBytes(hex) {
51
+ return hexToBytes(hex);
52
+ }
56
53
  /**
57
- * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
58
- *
59
- * source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
54
+ * @deprecated use sdk.names.normalizeLabel()
60
55
  *
61
56
  * @param str {string}
62
57
  *
63
58
  * @return {string}
64
59
  */
65
- UtilsController.prototype.convertToHomographSafeChars = function (str) {
66
- return (0, convertToHomographSafeChars_1.default)(str);
67
- };
68
- return UtilsController;
69
- }());
70
- exports.UtilsController = UtilsController;
60
+ convertToHomographSafeChars(str) {
61
+ return convertToHomographSafeChars(str);
62
+ }
63
+ /**
64
+ * Creates a voting identity identifier from proTxHash and voting address
65
+ *
66
+ * @param proTxHash {string} Pro TX Hash in hex format
67
+ * @param publicKeyHash {string} Voting address's public key hash (20 bytes), in hex
68
+ *
69
+ * @return {Promise<string>}
70
+ */
71
+ async createVoterIdentifier(proTxHash, publicKeyHash) {
72
+ return await createVoterIdentityId(proTxHash, publicKeyHash);
73
+ }
74
+ /**
75
+ * Creates a masternode identity identifier from proTxHash
76
+ *
77
+ * @param proTxHash {string} Pro TX Hash in hex format
78
+ *
79
+ * @return {string}
80
+ * */
81
+ createMasternodeIdentifier(proTxHash) {
82
+ return createMasternodeIdentityId(proTxHash);
83
+ }
84
+ }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = indexValueBytesToString;
4
- function indexValueBytesToString(value) {
5
- var decoder = new TextDecoder();
1
+ export default function indexValueBytesToString(value) {
2
+ const decoder = new TextDecoder();
6
3
  return decoder.decode(value).slice(2);
7
4
  }
@@ -1 +1 @@
1
- export default function sha256(input: Uint8Array | string): Uint8Array | string;
1
+ export default function sha256(input: Uint8Array | string): Promise<Uint8Array | string>;
@@ -1,13 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = sha256;
4
- var hash_js_1 = require("hash.js");
5
- function sha256(input) {
6
- var hash = (0, hash_js_1.sha256)().update(input);
1
+ import bytesToHex from './bytesToHex.js';
2
+ import { typedArrayToBuffer } from './bytesToTypedArray.js';
3
+ export default async function sha256(input) {
7
4
  if (typeof input === 'string') {
8
- return hash.digest('hex');
5
+ const encoder = new TextEncoder();
6
+ const data = encoder.encode(input);
7
+ const hash = await crypto.subtle.digest('SHA-256', data);
8
+ return bytesToHex(new Uint8Array(hash));
9
9
  }
10
10
  else {
11
- return Uint8Array.from(hash.digest());
11
+ const arrayBuffer = typedArrayToBuffer(input);
12
+ const hash = await crypto.subtle.digest('SHA-256', arrayBuffer);
13
+ return new Uint8Array(hash);
12
14
  }
13
15
  }
@@ -1 +1 @@
1
- export default function signHash(quorumType: number, quorumHash: Uint8Array, requestId: Uint8Array, signBytesHash: Uint8Array): Uint8Array;
1
+ export default function signHash(quorumType: number, quorumHash: Uint8Array, requestId: Uint8Array, signBytesHash: Uint8Array): Promise<Uint8Array>;
@@ -1,25 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = signHash;
4
- var sha256_1 = require("./sha256");
5
- function signHash(quorumType, quorumHash, requestId, signBytesHash) {
1
+ import sha256 from './sha256.js';
2
+ export default async function signHash(quorumType, quorumHash, requestId, signBytesHash) {
6
3
  // Calculate total length: 1 byte for quorumType + 3 arrays of 32 bytes each
7
- var totalLength = 1 + quorumHash.length + requestId.length + signBytesHash.length;
8
- var combined = new Uint8Array(totalLength);
9
- var offset = 0;
4
+ const totalLength = 1 + quorumHash.length + requestId.length + signBytesHash.length;
5
+ const combined = new Uint8Array(totalLength);
6
+ let offset = 0;
10
7
  // Add quorumType as single byte
11
8
  combined[offset] = quorumType;
12
9
  offset += 1;
13
10
  // Add reversed quorumHash
14
- var reversedQuorumHash = new Uint8Array(quorumHash).reverse();
11
+ const reversedQuorumHash = new Uint8Array(quorumHash).reverse();
15
12
  combined.set(reversedQuorumHash, offset);
16
13
  offset += quorumHash.length;
17
14
  // Add reversed requestId
18
- var reversedRequestId = new Uint8Array(requestId).reverse();
15
+ const reversedRequestId = new Uint8Array(requestId).reverse();
19
16
  combined.set(reversedRequestId, offset);
20
17
  offset += requestId.length;
21
18
  // Add reversed signBytesHash
22
- var reversedSignBytesHash = new Uint8Array(signBytesHash).reverse();
19
+ const reversedSignBytesHash = new Uint8Array(signBytesHash).reverse();
23
20
  combined.set(reversedSignBytesHash, offset);
24
- return (0, sha256_1.default)((0, sha256_1.default)(combined));
21
+ return await sha256(await sha256(combined));
25
22
  }
@@ -1 +1 @@
1
- export default function signRequestId(prefix: string, height: bigint, round: number): Uint8Array;
1
+ export default function signRequestId(prefix: string, height: bigint, round: number): Promise<Uint8Array>;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = signRequestId;
4
- var sha256_1 = require("./sha256");
5
- function signRequestId(prefix, height, round) {
6
- var prefixBytes = new TextEncoder().encode(prefix);
1
+ import sha256 from './sha256.js';
2
+ export default async function signRequestId(prefix, height, round) {
3
+ const prefixBytes = new TextEncoder().encode(prefix);
7
4
  // len + i64 + i32 (prefix length + 8 bytes for height + 4 bytes for round)
8
- var totalLength = prefixBytes.length + 8 + 4;
9
- var buffer = new ArrayBuffer(totalLength);
10
- var view = new DataView(buffer);
11
- var uint8View = new Uint8Array(buffer);
12
- var offset = 0;
5
+ const totalLength = prefixBytes.length + 8 + 4;
6
+ const buffer = new ArrayBuffer(totalLength);
7
+ const view = new DataView(buffer);
8
+ const uint8View = new Uint8Array(buffer);
9
+ let offset = 0;
13
10
  // Copy prefix bytes
14
11
  uint8View.set(prefixBytes, offset);
15
12
  offset += prefixBytes.length;
@@ -18,5 +15,5 @@ function signRequestId(prefix, height, round) {
18
15
  offset += 8;
19
16
  // Write round as 32-bit little-endian integer
20
17
  view.setInt32(offset, round, true);
21
- return (0, sha256_1.default)(uint8View);
18
+ return await sha256(uint8View);
22
19
  }
@@ -0,0 +1 @@
1
+ export default function sleep(ms: number): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export default async function sleep(ms) {
2
+ await new Promise(resolve => setTimeout(resolve, ms));
3
+ }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = stringToIndexValueBytes;
4
- function stringToIndexValueBytes(name) {
5
- var lengthBuffer = new Uint8Array(1);
1
+ export default function stringToIndexValueBytes(name) {
2
+ const lengthBuffer = new Uint8Array(1);
6
3
  lengthBuffer[0] = name.length;
7
- var nameBuffer = new TextEncoder().encode(name);
8
- var result = new Uint8Array(1 + 1 + nameBuffer.length);
4
+ const nameBuffer = new TextEncoder().encode(name);
5
+ const result = new Uint8Array(1 + 1 + nameBuffer.length);
9
6
  result[0] = 0x12;
10
7
  result[1] = lengthBuffer[0];
11
8
  result.set(nameBuffer, 2);
@@ -1,2 +1,2 @@
1
- import { Proof, ResponseMetadata } from '../../proto/generated/platform';
2
- export default function verifyTenderdashProof(proof: Proof, metadata: ResponseMetadata, rootHash: Uint8Array, quorumPublicKey: string): boolean;
1
+ import { Proof, ResponseMetadata } from '../../proto/generated/platform.js';
2
+ export default function verifyTenderdashProof(proof: Proof, metadata: ResponseMetadata, rootHash: Uint8Array, quorumPublicKey: string): Promise<boolean>;
@@ -1,30 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = verifyTenderdashProof;
4
- var platform_1 = require("../../proto/generated/platform");
5
- var calculateSignHash_1 = require("./calculateSignHash");
6
- var calculateStateIdHash_1 = require("./calculateStateIdHash");
7
- // import verifyBls from './verifyBls'
8
- var pshenmic_dpp_1 = require("pshenmic-dpp");
9
- var hexToBytes_1 = require("./hexToBytes");
10
- function verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey) {
11
- var stateId = platform_1.StateId.fromPartial({
1
+ import { CanonicalVote, SignedMsgType, StateId } from '../../proto/generated/platform.js';
2
+ import { calculateSignHash } from './calculateSignHash.js';
3
+ import { calculateStateIdHash } from './calculateStateIdHash.js';
4
+ import { verifySignatureDigest } from 'pshenmic-dpp';
5
+ import hexToBytes from './hexToBytes.js';
6
+ export default async function verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey) {
7
+ const stateId = StateId.create({
12
8
  appVersion: String(metadata.protocolVersion),
13
9
  coreChainLockedHeight: metadata.coreChainLockedHeight,
14
10
  time: metadata.timeMs,
15
11
  appHash: rootHash,
16
12
  height: metadata.height
17
13
  });
18
- var stateIdHash = (0, calculateStateIdHash_1.calculateStateIdHash)(stateId);
19
- var commit = platform_1.CanonicalVote.fromPartial({
20
- type: platform_1.SignedMsgType.PRECOMMIT,
14
+ const stateIdHash = await calculateStateIdHash(stateId);
15
+ const commit = CanonicalVote.create({
16
+ type: SignedMsgType.PRECOMMIT,
21
17
  blockId: proof.blockIdHash,
22
18
  chainId: metadata.chainId,
23
19
  height: metadata.height,
24
20
  round: String(proof.round),
25
21
  stateId: stateIdHash
26
22
  });
27
- var signDigest = (0, calculateSignHash_1.calculateSignHash)(commit, metadata.chainId, proof.quorumType, proof.quorumHash, BigInt(metadata.height), proof.round);
28
- var signature = proof.signature;
29
- return (0, pshenmic_dpp_1.verifySignatureDigest)(Uint8Array.from(signDigest), signature, (0, hexToBytes_1.default)(quorumPublicKey));
23
+ const signDigest = await calculateSignHash(commit, metadata.chainId, proof.quorumType, proof.quorumHash, BigInt(metadata.height), proof.round);
24
+ const { signature } = proof;
25
+ return verifySignatureDigest(Uint8Array.from(signDigest), signature, hexToBytes(quorumPublicKey));
30
26
  }
@@ -0,0 +1,2 @@
1
+ import { StateTransitionWASM, VoteWASM } from 'pshenmic-dpp';
2
+ export default function createStateTransition(voteWASM: VoteWASM, proTxHash: string, identityNonce: bigint): StateTransitionWASM;
@@ -0,0 +1,6 @@
1
+ import { IdentifierWASM, MasternodeVoteTransitionWASM } from 'pshenmic-dpp';
2
+ export default function createStateTransition(voteWASM, proTxHash, identityNonce) {
3
+ const voterIdentity = IdentifierWASM.fromHex(proTxHash);
4
+ const masternodeVoteTransition = new MasternodeVoteTransitionWASM(proTxHash, voterIdentity, voteWASM, identityNonce);
5
+ return masternodeVoteTransition.toStateTransition();
6
+ }
@@ -0,0 +1,2 @@
1
+ import { IdentifierWASM, ResourceVoteChoiceWASM, VoteWASM } from 'pshenmic-dpp';
2
+ export default function createVote(dataContractId: IdentifierWASM, documentTypeName: string, indexName: string, indexValues: string[], choice: ResourceVoteChoiceWASM): VoteWASM;
@@ -0,0 +1,5 @@
1
+ import { VotePollWASM, VoteWASM } from 'pshenmic-dpp';
2
+ export default function createVote(dataContractId, documentTypeName, indexName, indexValues, choice) {
3
+ const votePoll = new VotePollWASM(dataContractId, documentTypeName, indexName, indexValues);
4
+ return new VoteWASM(votePoll, choice);
5
+ }
@@ -0,0 +1,37 @@
1
+ import { IdentifierLike, ResourceVoteChoice } from '../types.js';
2
+ import { IdentifierWASM, StateTransitionWASM, VoteWASM } from 'pshenmic-dpp';
3
+ /**
4
+ * Voting controller for performing masternode votes
5
+ *
6
+ * @hideconstructor
7
+ */
8
+ export declare class VotingController {
9
+ /**
10
+ * Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
11
+ *
12
+ * @param proTxHash {string} voter's masternode pro tx hash
13
+ * @param publicKeyHash {string} voter address's public key hash
14
+ *
15
+ * @return {Promise<IdentifierWASM>}
16
+ */
17
+ createVoterIdentityId(proTxHash: string, publicKeyHash: string): Promise<IdentifierWASM>;
18
+ /**
19
+ * Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
20
+ *
21
+ * @param dataContractId {DataContractWASM}
22
+ * @param documentTypeName {string}
23
+ * @param indexName {string}
24
+ * @param indexValues {string[]}
25
+ * @param choice {ResourceVoteChoice}
26
+ */
27
+ createVote(dataContractId: IdentifierLike, documentTypeName: string, indexName: string, indexValues: string[], choice: ResourceVoteChoice): VoteWASM;
28
+ /**
29
+ * Creates a {StateTransitionWASM} from masternode Pro Tx Hash and voter identity
30
+ *
31
+ * @param voteWASM {VoteWASM} vote instance from .createMasternodeVote() method
32
+ * @param proTxHash {string} pro tx hash of the masternode as hex
33
+ * @param voterIdentity {IdentifierWASM} voter identity identifier
34
+ * @param identityNonce {BigInt} identity nonce
35
+ */
36
+ createStateTransition(voteWASM: VoteWASM, proTxHash: string, voterIdentity: IdentifierWASM, identityNonce: bigint): StateTransitionWASM;
37
+ }
@@ -0,0 +1,55 @@
1
+ import createVote from './createVote.js';
2
+ import { IdentifierWASM, MasternodeVoteTransitionWASM, ResourceVoteChoiceWASM } from 'pshenmic-dpp';
3
+ import { createVoterIdentityId } from '../utils/createVoterIdentityId.js';
4
+ /**
5
+ * Voting controller for performing masternode votes
6
+ *
7
+ * @hideconstructor
8
+ */
9
+ export class VotingController {
10
+ /**
11
+ * Creates an {IdentifierWASM} from masternode pro tx hash and voting address (public key hash)
12
+ *
13
+ * @param proTxHash {string} voter's masternode pro tx hash
14
+ * @param publicKeyHash {string} voter address's public key hash
15
+ *
16
+ * @return {Promise<IdentifierWASM>}
17
+ */
18
+ async createVoterIdentityId(proTxHash, publicKeyHash) {
19
+ return await createVoterIdentityId(proTxHash, publicKeyHash);
20
+ }
21
+ /**
22
+ * Creates a {VoteWASM} with all information about the vote, such as data contract id, choice, and target index
23
+ *
24
+ * @param dataContractId {DataContractWASM}
25
+ * @param documentTypeName {string}
26
+ * @param indexName {string}
27
+ * @param indexValues {string[]}
28
+ * @param choice {ResourceVoteChoice}
29
+ */
30
+ createVote(dataContractId, documentTypeName, indexName, indexValues, choice) {
31
+ let resourceVoteChoice;
32
+ if (choice === 'lock') {
33
+ resourceVoteChoice = ResourceVoteChoiceWASM.Lock();
34
+ }
35
+ else if (choice === 'abstain') {
36
+ resourceVoteChoice = ResourceVoteChoiceWASM.Abstain();
37
+ }
38
+ else {
39
+ resourceVoteChoice = ResourceVoteChoiceWASM.TowardsIdentity(new IdentifierWASM(choice));
40
+ }
41
+ return createVote(new IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
42
+ }
43
+ /**
44
+ * Creates a {StateTransitionWASM} from masternode Pro Tx Hash and voter identity
45
+ *
46
+ * @param voteWASM {VoteWASM} vote instance from .createMasternodeVote() method
47
+ * @param proTxHash {string} pro tx hash of the masternode as hex
48
+ * @param voterIdentity {IdentifierWASM} voter identity identifier
49
+ * @param identityNonce {BigInt} identity nonce
50
+ */
51
+ createStateTransition(voteWASM, proTxHash, voterIdentity, identityNonce) {
52
+ const transition = new MasternodeVoteTransitionWASM(IdentifierWASM.fromHex(proTxHash), new IdentifierWASM(voterIdentity), voteWASM, identityNonce);
53
+ return transition.toStateTransition();
54
+ }
55
+ }