dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/bundle.min.js +21 -2
  2. package/index.js +2 -5
  3. package/package.json +30 -31
  4. package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
  5. package/proto/generated/google/protobuf/wrappers.js +562 -345
  6. package/proto/generated/platform.client.d.ts +251 -0
  7. package/proto/generated/platform.client.js +175 -0
  8. package/proto/generated/platform.d.ts +3682 -1939
  9. package/proto/generated/platform.js +8119 -18366
  10. package/src/DashPlatformSDK.d.ts +5 -4
  11. package/src/DashPlatformSDK.js +56 -46
  12. package/src/constants.js +7 -10
  13. package/src/contestedResources/createStateTransition.d.ts +1 -2
  14. package/src/contestedResources/createStateTransition.js +4 -7
  15. package/src/contestedResources/getContestedResourceVoteState.js +67 -118
  16. package/src/contestedResources/index.js +9 -55
  17. package/src/dataContracts/create.js +5 -8
  18. package/src/dataContracts/createStateTransition.js +10 -14
  19. package/src/dataContracts/getDataContractByIdentifier.js +40 -83
  20. package/src/dataContracts/index.js +17 -63
  21. package/src/documents/create.js +3 -6
  22. package/src/documents/createStateTransition.js +19 -31
  23. package/src/documents/index.js +25 -72
  24. package/src/documents/query.js +58 -90
  25. package/src/grpcConnectionPool.d.ts +30 -8
  26. package/src/grpcConnectionPool.js +63 -121
  27. package/src/identities/createStateTransition.js +14 -26
  28. package/src/identities/getIdentityBalance.js +37 -80
  29. package/src/identities/getIdentityByIdentifier.js +37 -80
  30. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
  31. package/src/identities/getIdentityByPublicKeyHash.js +37 -80
  32. package/src/identities/getIdentityContractNonce.js +40 -83
  33. package/src/identities/getIdentityNonce.js +38 -81
  34. package/src/identities/getIdentityPublicKeys.js +43 -81
  35. package/src/identities/index.js +57 -153
  36. package/src/keyPair/deriveChild.d.ts +2 -2
  37. package/src/keyPair/deriveChild.js +2 -49
  38. package/src/keyPair/derivePath.d.ts +2 -2
  39. package/src/keyPair/derivePath.js +2 -49
  40. package/src/keyPair/index.d.ts +39 -114
  41. package/src/keyPair/index.js +62 -296
  42. package/src/keyPair/mnemonicToSeed.d.ts +1 -1
  43. package/src/keyPair/mnemonicToSeed.js +3 -46
  44. package/src/names/index.js +43 -111
  45. package/src/names/registerName.js +60 -127
  46. package/src/names/searchByIdentity.d.ts +1 -1
  47. package/src/names/searchByIdentity.js +4 -50
  48. package/src/names/searchByName.js +15 -63
  49. package/src/names/testNameContested.js +1 -4
  50. package/src/names/validateName.js +3 -6
  51. package/src/node/epochs.js +43 -85
  52. package/src/node/index.d.ts +3 -3
  53. package/src/node/index.js +18 -77
  54. package/src/node/status.js +37 -81
  55. package/src/node/totalCredits.d.ts +2 -1
  56. package/src/node/totalCredits.js +32 -73
  57. package/src/signer/AbstractSigner.js +1 -2
  58. package/src/signer/setSigner.js +1 -4
  59. package/src/stateTransitions/broadcast.js +7 -57
  60. package/src/stateTransitions/index.js +13 -66
  61. package/src/stateTransitions/waitForStateTransitionResult.js +6 -58
  62. package/src/tokens/createStateTransition.js +23 -35
  63. package/src/tokens/getIdentitiesTokenBalances.js +40 -83
  64. package/src/tokens/getIdentityTokensBalances.js +40 -83
  65. package/src/tokens/getTokenContractInfo.js +40 -83
  66. package/src/tokens/getTokenDirectPurchasePrices.js +37 -80
  67. package/src/tokens/getTokenTotalSupply.js +38 -81
  68. package/src/tokens/index.js +39 -124
  69. package/src/types.d.ts +6 -12
  70. package/src/types.js +6 -16
  71. package/src/utils/base58ToBytes.js +3 -6
  72. package/src/utils/bytesToHex.js +2 -5
  73. package/src/utils/bytesToTypedArray.d.ts +1 -0
  74. package/src/utils/bytesToTypedArray.js +3 -0
  75. package/src/utils/calculateMsgHash.d.ts +1 -1
  76. package/src/utils/calculateMsgHash.js +10 -13
  77. package/src/utils/calculateSignHash.d.ts +1 -1
  78. package/src/utils/calculateSignHash.js +7 -10
  79. package/src/utils/calculateStateIdHash.d.ts +1 -1
  80. package/src/utils/calculateStateIdHash.js +8 -10
  81. package/src/utils/convertToHomographSafeChars.js +2 -5
  82. package/src/utils/createVoterIdentityId.d.ts +1 -1
  83. package/src/utils/createVoterIdentityId.js +12 -11
  84. package/src/utils/getEvonodeList.d.ts +2 -2
  85. package/src/utils/getEvonodeList.js +10 -61
  86. package/src/utils/getQuorumPublicKey.js +15 -66
  87. package/src/utils/getRandomArrayItem.js +1 -4
  88. package/src/utils/getRandomBytes.js +2 -5
  89. package/src/utils/hexToBytes.js +2 -6
  90. package/src/utils/index.js +21 -28
  91. package/src/utils/indexBytesToString.js +2 -5
  92. package/src/utils/sha256.d.ts +1 -1
  93. package/src/utils/sha256.js +10 -8
  94. package/src/utils/signHash.d.ts +1 -1
  95. package/src/utils/signHash.js +9 -12
  96. package/src/utils/signRequestId.d.ts +1 -1
  97. package/src/utils/signRequestId.js +9 -12
  98. package/src/utils/sleep.js +2 -50
  99. package/src/utils/stringToIndexValueBytes.js +4 -7
  100. package/src/utils/verifyTenderdashProof.d.ts +1 -1
  101. package/src/utils/verifyTenderdashProof.js +13 -17
  102. package/src/voting/createStateTransition.d.ts +1 -2
  103. package/src/voting/createStateTransition.js +4 -7
  104. package/src/voting/createVote.js +4 -7
  105. package/src/voting/index.d.ts +3 -4
  106. package/src/voting/index.js +19 -26
  107. package/test/unit/ContestedResources.spec.js +92 -177
  108. package/test/unit/DataContract.spec.js +44 -111
  109. package/test/unit/Document.spec.js +93 -183
  110. package/test/unit/Identity.spec.js +221 -346
  111. package/test/unit/KeyPair.spec.js +30 -145
  112. package/test/unit/Names.spec.js +27 -90
  113. package/test/unit/Node.spec.js +55 -126
  114. package/test/unit/SDK.spec.js +7 -9
  115. package/test/unit/Tokens.spec.js +111 -278
  116. package/bundle.min.js.LICENSE.txt +0 -1
  117. package/src/keyPair/keyToPublicKey.d.ts +0 -2
  118. package/src/keyPair/keyToPublicKey.js +0 -47
  119. package/src/keyPair/keyToWalletId.d.ts +0 -2
  120. package/src/keyPair/keyToWalletId.js +0 -50
  121. package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
  122. package/src/keyPair/keyToXPrivateKey.js +0 -50
  123. package/src/keyPair/keyToXPublicKey.d.ts +0 -3
  124. package/src/keyPair/keyToXPublicKey.js +0 -50
  125. package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
  126. package/src/keyPair/mnemonicToIdentityKey.js +0 -57
  127. package/src/keyPair/mnemonicToWallet.d.ts +0 -2
  128. package/src/keyPair/mnemonicToWallet.js +0 -55
  129. package/src/keyPair/privateKeyToWif.d.ts +0 -2
  130. package/src/keyPair/privateKeyToWif.js +0 -50
  131. package/src/keyPair/publicKeyToAddress.d.ts +0 -2
  132. package/src/keyPair/publicKeyToAddress.js +0 -50
  133. package/src/keyPair/seedToWallet.d.ts +0 -2
  134. package/src/keyPair/seedToWallet.js +0 -50
  135. package/src/keyPair/walletToIdentityKey.d.ts +0 -3
  136. package/src/keyPair/walletToIdentityKey.js +0 -56
  137. package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
  138. package/src/keyPair/xkeyToHDXKey.js +0 -50
@@ -1,323 +1,89 @@
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
- });
1
+ import { HDKey } from '@scure/bip32';
2
+ import mnemonicToSeed from './mnemonicToSeed';
3
+ import deriveChild from './deriveChild';
4
+ import derivePath from './derivePath';
5
+ import { p2pkh } from '@scure/btc-signer';
6
+ const DASH_VERSIONS = {
7
+ mainnet: { pubKeyHash: 0x4c, scriptHash: 0x10, bech32: 'dc', wif: 0xcc, private: 0x0488ade4, public: 0x0488b21e },
8
+ testnet: { pubKeyHash: 0x8c, scriptHash: 0x13, bech32: 'dc', wif: 0xef, private: 0x04358394, public: 0x043587cf }
10
9
  };
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.KeyPairController = void 0;
40
- var deriveChild_1 = require("./deriveChild");
41
- var derivePath_1 = require("./derivePath");
42
- var keyToXPublicKey_1 = require("./keyToXPublicKey");
43
- var keyToWalletId_1 = require("./keyToWalletId");
44
- var keyToXPrivateKey_1 = require("./keyToXPrivateKey");
45
- var mnemonicToIdentityKey_1 = require("./mnemonicToIdentityKey");
46
- var mnemonicToSeed_1 = require("./mnemonicToSeed");
47
- var mnemonicToWallet_1 = require("./mnemonicToWallet");
48
- var privateKeyToWif_1 = require("./privateKeyToWif");
49
- var publicKeyToAddress_1 = require("./publicKeyToAddress");
50
- var seedToWallet_1 = require("./seedToWallet");
51
- var walletToIdentityKey_1 = require("./walletToIdentityKey");
52
- var xkeyToHDXKey_1 = require("./xkeyToHDXKey");
53
10
  /**
54
11
  * Collection of functions to work with private keys and seed phrases
55
12
  *
56
13
  * @hideconstructor
57
14
  */
58
- var KeyPairController = /** @class */ (function () {
59
- function KeyPairController() {
60
- }
61
- /**
62
- * Allows to derive child HD Key
63
- *
64
- * @param parent {HDKey} - The HDKey parent instance
65
- * @param index {number} - Index of child
66
- * @param hardened {boolean} - hardened or no
67
- *
68
- * @return {Promise<HDKey>} A promise that resolves child key
69
- */
70
- KeyPairController.prototype.deriveChild = function (parent, index, hardened) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0: return [4 /*yield*/, (0, deriveChild_1.default)(parent, index, hardened)];
75
- case 1: return [2 /*return*/, _a.sent()];
76
- }
77
- });
78
- });
79
- };
80
- /**
81
- * Allows to derive HD key by path
82
- *
83
- * @param parent {HDKey} - The HDKey parent instance
84
- * @param path {string} - Path of children
85
- *
86
- * @return {Promise<HDKey>} A promise that resolves key by path
87
- */
88
- KeyPairController.prototype.derivePath = function (parent, path) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, (0, derivePath_1.default)(parent, path)];
93
- case 1: return [2 /*return*/, _a.sent()];
94
- }
95
- });
96
- });
97
- };
98
- /**
99
- * Convert a HDKey to a public key
100
- *
101
- * @param hdKey {HDKey} - The HDKey to be converted into a public key
102
- * @param opts {NetworkVersion=} - Network version
103
- *
104
- * @return {Promise<Uint8Array>} - converted public key
105
- */
106
- KeyPairController.prototype.keyToPublicKey = function (hdKey, opts) {
107
- return __awaiter(this, void 0, void 0, function () {
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0: return [4 /*yield*/, (0, keyToXPublicKey_1.default)(hdKey, opts)];
111
- case 1: return [2 /*return*/, _a.sent()];
112
- }
113
- });
114
- });
115
- };
116
- /**
117
- * Converts a HDKey to a wallet ID
118
- *
119
- * @param hdKey {HDKey} - The HDKey to be converted into a wallet id.
120
- *
121
- * @return {Promise<string>} Wallet id from used key
122
- */
123
- KeyPairController.prototype.keyToWalletId = function (hdKey) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0: return [4 /*yield*/, (0, keyToWalletId_1.default)(hdKey)];
128
- case 1: return [2 /*return*/, _a.sent()];
129
- }
130
- });
131
- });
132
- };
133
- /**
134
- * Converts an HDKey instance to an extended private key (xprv)
135
- *
136
- * @param hdKey {HDKey} - The HDKey instance to convert
137
- * @param opts {NetworkVersion=} - Optional, containing the version
138
- *
139
- * @returns {Promise<string>} A promise that resolves to the xPrivateKey string
140
- */
141
- KeyPairController.prototype.keyToXPrivateKey = function (hdKey, opts) {
142
- return __awaiter(this, void 0, void 0, function () {
143
- return __generator(this, function (_a) {
144
- switch (_a.label) {
145
- case 0: return [4 /*yield*/, (0, keyToXPrivateKey_1.default)(hdKey, opts)];
146
- case 1: return [2 /*return*/, _a.sent()];
147
- }
148
- });
149
- });
150
- };
151
- /**
152
- * Convert a HDKey to a xPublicKey
153
- * @param hdKey {HDKey} - The HDKey instance to convert
154
- * @param opts {NetworkVersion=} - Optional, containing the version
155
- *
156
- * @return {Promise<Uint8Array>}
157
- */
158
- KeyPairController.prototype.keyToXPublicKey = function (hdKey, opts) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, (0, keyToXPublicKey_1.default)(hdKey, opts)];
163
- case 1: return [2 /*return*/, _a.sent()];
164
- }
165
- });
166
- });
167
- };
168
- /**
169
- * Derives an Identity HDKey from a mnemonic phrase.
170
- *
171
- * @param mnemonic {string} - The BIP39 mnemonic phrase.
172
- * @param identityIndex {number} - The identity index (default: 0).
173
- * @param keyIndex {number} - The key index within the identity (default: 0).
174
- * @param salt {string=} - Optional salt for seed derivation.
175
- * @param verify {boolean=} - Whether to verify the mnemonic during derivation.
176
- * @param opts {(HDFromSeedOptions & WalletToIdentityKeyOpts)=} - Additional options for HD seed derivation and wallet-to-identity conversion.
177
- *
178
- * @returns {Promise<HDKey>} A promise that resolves to the derived identity HDKey.
179
- */
180
- KeyPairController.prototype.mnemonicToIdentityKey = function (mnemonic, identityIndex, keyIndex, salt, verify, opts) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
184
- case 0: return [4 /*yield*/, (0, mnemonicToIdentityKey_1.default)(mnemonic, identityIndex !== null && identityIndex !== void 0 ? identityIndex : 0, keyIndex !== null && keyIndex !== void 0 ? keyIndex : 0, salt, verify, opts)];
185
- case 1: return [2 /*return*/, _a.sent()];
186
- }
187
- });
188
- });
189
- };
15
+ export class KeyPairController {
190
16
  /**
191
17
  * Returns seed from mnemonic phrase
192
18
  *
193
19
  * @param mnemonic {string} - The BIP39 mnemonic phrase.
194
20
  * @param salt {string=} - Optional salt for seed derivation.
195
- * @param verify {boolean=} - Whether to verify the mnemonic during derivation.
196
21
  *
197
- * @return {Promise<Uint8Array>} Seed bytes
22
+ * @return {Uint8Array} Seed bytes
198
23
  */
199
- KeyPairController.prototype.mnemonicToSeed = function (mnemonic, salt, verify) {
200
- return __awaiter(this, void 0, void 0, function () {
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0: return [4 /*yield*/, (0, mnemonicToSeed_1.default)(mnemonic, salt, verify)];
204
- case 1: return [2 /*return*/, _a.sent()];
205
- }
206
- });
207
- });
208
- };
24
+ mnemonicToSeed(mnemonic, salt) {
25
+ return mnemonicToSeed(mnemonic, salt);
26
+ }
209
27
  /**
210
- * Returns wallet from mnemonic phrase
28
+ * Returns seed from mnemonic phrase
211
29
  *
212
- * @param mnemonic {string} - The BIP39 mnemonic phrase.
213
- * @param salt {string=} - Optional salt for seed derivation.
214
- * @param verify {boolean=} - Whether to verify the mnemonic during derivation.
215
- * @param opts {HDFromSeedOptions=} - Optional derivation settings
30
+ * @param seed {Uint8Array}
31
+ * @param network {Network} network
216
32
  *
217
- * @return {Promise<HDWallet>} Wallet from mnemonic
33
+ * @return {HDKey} HDKey
218
34
  */
219
- KeyPairController.prototype.mnemonicToWallet = function (mnemonic, salt, verify, opts) {
220
- return __awaiter(this, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0: return [4 /*yield*/, (0, mnemonicToWallet_1.default)(mnemonic, salt, verify, opts)];
224
- case 1: return [2 /*return*/, _a.sent()];
225
- }
226
- });
227
- });
228
- };
35
+ seedToHdKey(seed, network = 'mainnet') {
36
+ return HDKey.fromMasterSeed(seed, DASH_VERSIONS[network]);
37
+ }
229
38
  /**
230
- * Convert a private key to WIF
231
- *
232
- * @param privateKeyBytes {Uint8Array} - Private key bytes
233
- * @param opts {NetworkVersion=} - Optional options with network version
234
- *
235
- * @return {Promise<string>} WIF
236
- */
237
- KeyPairController.prototype.privateKeyToWif = function (privateKeyBytes, opts) {
238
- return __awaiter(this, void 0, void 0, function () {
239
- return __generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0: return [4 /*yield*/, (0, privateKeyToWif_1.default)(privateKeyBytes, opts)];
242
- case 1: return [2 /*return*/, _a.sent()];
243
- }
244
- });
245
- });
246
- };
39
+ * Allows to derive child HD Key
40
+ *
41
+ * @param hdKey {HDKey} - The HDKey parent instance
42
+ * @param index {number} - Index of child
43
+ *
44
+ * @return {Promise<HDKey>} A promise that resolves child key
45
+ */
46
+ async deriveChild(hdKey, index) {
47
+ return deriveChild(hdKey, index);
48
+ }
247
49
  /**
248
- * Convert public key to address
249
- *
250
- * @param publicKeyBytes {Uint8Array} - Bytes of public key
251
- * @param opts {NetworkVersion=} - Optional options with network version
252
- *
253
- * @return {Promise<string>} address string
254
- */
255
- KeyPairController.prototype.publicKeyToAddress = function (publicKeyBytes, opts) {
256
- return __awaiter(this, void 0, void 0, function () {
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0: return [4 /*yield*/, (0, publicKeyToAddress_1.default)(publicKeyBytes, opts)];
260
- case 1: return [2 /*return*/, _a.sent()];
261
- }
262
- });
263
- });
264
- };
50
+ * Allows to derive HD key by path
51
+ *
52
+ * @param hdKey {HDKey} - The HDKey parent instance
53
+ * @param path {string} - Path of children
54
+ *
55
+ * @return {Promise<HDKey>} A promise that resolves key by path
56
+ */
57
+ async derivePath(hdKey, path) {
58
+ return derivePath(hdKey, path);
59
+ }
265
60
  /**
266
- * Convert seed bytes to wallet
61
+ * Derives an {HDKey} child by identity index and key index from an {HDKey}
267
62
  *
268
- * @param seed {Uint8Array} - seed bytes
269
- * @param opts {HDFromSeedOptions?} - Optional options with network version
63
+ * Usually used to get a identity private key from seed
270
64
  *
271
- * @return {Promise<HDWallet>}
272
- */
273
- KeyPairController.prototype.seedToWallet = function (seed, opts) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- return __generator(this, function (_a) {
276
- switch (_a.label) {
277
- case 0: return [4 /*yield*/, (0, seedToWallet_1.default)(seed, opts)];
278
- case 1: return [2 /*return*/, _a.sent()];
279
- }
280
- });
281
- });
282
- };
283
- /**
284
- * Returns identity key from wallet
285
- *
286
- * @param wallet {HDWallet | HDKey} - wallet that will be used
287
- * @param identityIndex {number} - index of identity for wallet
288
- * @param keyIndex {number} - index of key for identity
289
- * @param opts {WalletToIdentityKeyOpts=} - optional options
65
+ * @param hdKey {HDKey}
66
+ * @param identityIndex {number}
67
+ * @param keyIndex {number}
68
+ * @param network {Network}
290
69
  *
291
- * @return {Promise<HDKey>}
70
+ * @returns {HDKey}
292
71
  */
293
- KeyPairController.prototype.walletToIdentityKey = function (wallet_1, identityIndex_1, keyIndex_1) {
294
- return __awaiter(this, arguments, void 0, function (wallet, identityIndex, keyIndex, opts) {
295
- if (opts === void 0) { opts = { network: 'testnet' }; }
296
- return __generator(this, function (_a) {
297
- switch (_a.label) {
298
- case 0: return [4 /*yield*/, (0, walletToIdentityKey_1.default)(wallet, identityIndex, keyIndex, opts)];
299
- case 1: return [2 /*return*/, _a.sent()];
300
- }
301
- });
302
- });
303
- };
72
+ deriveIdentityPrivateKey(hdKey, identityIndex, keyIndex, network) {
73
+ const networkIndex = network === 'mainnet' ? 5 : 1;
74
+ const pathPostfix = `/5'/0'/0'/${identityIndex}'/${keyIndex}'`;
75
+ return derivePath(hdKey, `m/9'/${networkIndex}'${pathPostfix}`);
76
+ }
304
77
  /**
305
- * Allows to convert xKey to HDXKey
78
+ * Converts {PublicKey} to a Dash network address (P2PKH)
79
+ *
80
+ * @param publicKey {Uint8Array}
81
+ * @param network {Network}
306
82
  *
307
- * @param xKey {string} - String with xKey
308
- * @param opts {HDFromXKeyOptions=} - Optional options
309
- * @return {Promise<HDXKey>}
83
+ * @returns {string}
310
84
  */
311
- KeyPairController.prototype.xKeyToHDXKey = function (xKey, opts) {
312
- return __awaiter(this, void 0, void 0, function () {
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0: return [4 /*yield*/, (0, xkeyToHDXKey_1.default)(xKey, opts)];
316
- case 1: return [2 /*return*/, _a.sent()];
317
- }
318
- });
319
- });
320
- };
321
- return KeyPairController;
322
- }());
323
- exports.KeyPairController = KeyPairController;
85
+ p2pkhAddress(publicKey, network) {
86
+ const P2PKH = p2pkh(publicKey, DASH_VERSIONS[network]);
87
+ return P2PKH.address;
88
+ }
89
+ }
@@ -1 +1 @@
1
- export default function mnemonicToSeed(mnemonic: string, salt?: string, verify?: boolean): Promise<Uint8Array>;
1
+ export default function mnemonicToSeed(mnemonic: string, salt?: string): Uint8Array;
@@ -1,47 +1,4 @@
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 };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = mnemonicToSeed;
40
- var DashPhrase = require("dashphrase");
41
- function mnemonicToSeed(mnemonic, salt, verify) {
42
- return __awaiter(this, void 0, void 0, function () {
43
- return __generator(this, function (_a) {
44
- return [2 /*return*/, DashPhrase.toSeed(mnemonic, salt, { verify: verify })];
45
- });
46
- });
1
+ import { mnemonicToSeedSync as func } from '@scure/bip39';
2
+ export default function mnemonicToSeed(mnemonic, salt) {
3
+ return func(mnemonic, salt);
47
4
  }
@@ -1,57 +1,20 @@
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 };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.NamesController = void 0;
40
- var pshenmic_dpp_1 = require("pshenmic-dpp");
41
- var searchByName_1 = require("./searchByName");
42
- var searchByIdentity_1 = require("./searchByIdentity");
43
- var registerName_1 = require("./registerName");
44
- var validateName_1 = require("./validateName");
45
- var getIdentityByIdentifier_1 = require("../identities/getIdentityByIdentifier");
46
- var convertToHomographSafeChars_1 = require("../utils/convertToHomographSafeChars");
47
- var testNameContested_1 = require("./testNameContested");
1
+ import { IdentifierWASM } from 'pshenmic-dpp';
2
+ import searchByName from './searchByName';
3
+ import searchByIdentity from './searchByIdentity';
4
+ import registerName from './registerName';
5
+ import validateName from './validateName';
6
+ import getIdentityByIdentifier from '../identities/getIdentityByIdentifier';
7
+ import convertToHomographSafeChars from '../utils/convertToHomographSafeChars';
8
+ import testNameContested from './testNameContested';
48
9
  /**
49
10
  * Functions related to DPNS names (usernames)
50
11
  *
51
12
  * @hideconstructor
52
13
  */
53
- var NamesController = /** @class */ (function () {
54
- function NamesController(grpcPool) {
14
+ export class NamesController {
15
+ /** @ignore **/
16
+ grpcPool;
17
+ constructor(grpcPool) {
55
18
  this.grpcPool = grpcPool;
56
19
  }
57
20
  /**
@@ -68,22 +31,13 @@ var NamesController = /** @class */ (function () {
68
31
  *
69
32
  * @return Promise<DocumentWASM | null>
70
33
  */
71
- NamesController.prototype.searchByName = function (name) {
72
- return __awaiter(this, void 0, void 0, function () {
73
- var validation;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- validation = (0, validateName_1.default)(name);
78
- if (validation != null) {
79
- throw new Error(validation);
80
- }
81
- return [4 /*yield*/, (0, searchByName_1.default)(this.grpcPool, name)];
82
- case 1: return [2 /*return*/, _a.sent()];
83
- }
84
- });
85
- });
86
- };
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
+ }
87
41
  /**
88
42
  * Tests a given username against contested names rules.
89
43
  * Contested names includes an additional fee of 0.2 Dash
@@ -93,25 +47,18 @@ var NamesController = /** @class */ (function () {
93
47
  * falls under contested names rules.
94
48
  * @param name
95
49
  */
96
- NamesController.prototype.testNameContested = function (name) {
97
- var validation = (0, validateName_1.default)(name);
50
+ testNameContested(name) {
51
+ const validation = validateName(name);
98
52
  if (validation != null) {
99
53
  throw new Error(validation);
100
54
  }
101
- var label = name.split('.')[0];
102
- var normalizedLabel = (0, convertToHomographSafeChars_1.default)(label);
103
- return (0, testNameContested_1.default)(normalizedLabel);
104
- };
105
- NamesController.prototype.searchByIdentity = function (identifier) {
106
- return __awaiter(this, void 0, void 0, function () {
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0: return [4 /*yield*/, (0, searchByIdentity_1.default)(this.grpcPool, new pshenmic_dpp_1.IdentifierWASM(identifier))];
110
- case 1: return [2 /*return*/, _a.sent()];
111
- }
112
- });
113
- });
114
- };
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
+ }
115
62
  /**
116
63
  * Performs a DPNS name registration sequence
117
64
  * Contested names are include additional fee of 0.2 Dash
@@ -121,27 +68,14 @@ var NamesController = /** @class */ (function () {
121
68
  * @param identityId {IdentifierLike} identity identifier
122
69
  * @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
123
70
  */
124
- NamesController.prototype.registerName = function (name, identityId, privateKey) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- var validation, identity;
127
- return __generator(this, function (_a) {
128
- switch (_a.label) {
129
- case 0:
130
- validation = (0, validateName_1.default)(name);
131
- if (validation != null) {
132
- throw new Error(validation);
133
- }
134
- return [4 /*yield*/, (0, getIdentityByIdentifier_1.default)(this.grpcPool, identityId)];
135
- case 1:
136
- identity = _a.sent();
137
- return [4 /*yield*/, (0, registerName_1.default)(this.grpcPool, name, identity, privateKey)];
138
- case 2:
139
- _a.sent();
140
- return [2 /*return*/];
141
- }
142
- });
143
- });
144
- };
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
+ }
145
79
  /**
146
80
  * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
147
81
  *
@@ -152,9 +86,9 @@ var NamesController = /** @class */ (function () {
152
86
  *
153
87
  * @return {string}
154
88
  */
155
- NamesController.prototype.normalizeLabel = function (label) {
156
- return (0, convertToHomographSafeChars_1.default)(label);
157
- };
89
+ normalizeLabel(label) {
90
+ return convertToHomographSafeChars(label);
91
+ }
158
92
  /**
159
93
  * Validates a DPNS name that you would like to register
160
94
  *
@@ -162,9 +96,7 @@ var NamesController = /** @class */ (function () {
162
96
  *
163
97
  * @return {string} null if valid or string with a reason
164
98
  */
165
- NamesController.prototype.validateName = function (fullName) {
166
- return (0, validateName_1.default)(fullName);
167
- };
168
- return NamesController;
169
- }());
170
- exports.NamesController = NamesController;
99
+ validateName(fullName) {
100
+ return validateName(fullName);
101
+ }
102
+ }