dash-platform-sdk 1.3.0-dev.1 → 1.3.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.min.js +21 -2
- package/index.d.ts +1 -1
- package/index.js +2 -5
- package/package.json +32 -31
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/google/protobuf/wrappers.js +562 -345
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/proto/generated/platform.js +8119 -18366
- package/src/DashPlatformSDK.d.ts +18 -19
- package/src/DashPlatformSDK.js +52 -45
- package/src/constants.d.ts +2 -0
- package/src/constants.js +7 -8
- package/src/contestedResources/createStateTransition.d.ts +2 -0
- package/src/contestedResources/createStateTransition.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +3 -3
- package/src/contestedResources/getContestedResourceVoteState.js +67 -118
- package/src/contestedResources/index.d.ts +3 -3
- package/src/contestedResources/index.js +9 -55
- package/src/dataContracts/create.d.ts +1 -1
- package/src/dataContracts/create.js +5 -8
- package/src/dataContracts/createStateTransition.js +10 -14
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -2
- package/src/dataContracts/getDataContractByIdentifier.js +40 -79
- package/src/dataContracts/index.d.ts +2 -2
- package/src/dataContracts/index.js +17 -63
- package/src/documents/create.d.ts +1 -1
- package/src/documents/create.js +3 -6
- package/src/documents/createStateTransition.d.ts +1 -1
- package/src/documents/createStateTransition.js +19 -31
- package/src/documents/index.d.ts +2 -2
- package/src/documents/index.js +25 -72
- package/src/documents/query.d.ts +2 -2
- package/src/documents/query.js +58 -90
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/grpcConnectionPool.js +63 -121
- package/src/identities/createStateTransition.d.ts +2 -2
- package/src/identities/createStateTransition.js +24 -26
- package/src/identities/getIdentityBalance.d.ts +2 -2
- package/src/identities/getIdentityBalance.js +37 -80
- package/src/identities/getIdentityByIdentifier.d.ts +2 -2
- package/src/identities/getIdentityByIdentifier.js +37 -80
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +41 -82
- package/src/identities/getIdentityByPublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByPublicKeyHash.js +37 -80
- package/src/identities/getIdentityContractNonce.d.ts +2 -2
- package/src/identities/getIdentityContractNonce.js +40 -83
- package/src/identities/getIdentityNonce.d.ts +2 -2
- package/src/identities/getIdentityNonce.js +38 -81
- package/src/identities/getIdentityPublicKeys.d.ts +2 -2
- package/src/identities/getIdentityPublicKeys.js +43 -81
- package/src/identities/index.d.ts +6 -4
- package/src/identities/index.js +70 -154
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/deriveChild.js +2 -49
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/derivePath.js +2 -49
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/index.js +62 -296
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/keyPair/mnemonicToSeed.js +3 -46
- package/src/names/index.d.ts +44 -3
- package/src/names/index.js +81 -69
- package/src/names/registerName.d.ts +3 -0
- package/src/names/registerName.js +64 -0
- package/src/names/searchByIdentity.d.ts +3 -0
- package/src/names/searchByIdentity.js +5 -0
- package/src/names/searchByName.d.ts +3 -0
- package/src/names/searchByName.js +16 -0
- package/src/names/testNameContested.d.ts +1 -0
- package/src/names/testNameContested.js +3 -0
- package/src/names/validateName.d.ts +1 -0
- package/src/names/validateName.js +11 -0
- package/src/node/epochs.d.ts +1 -1
- package/src/node/epochs.js +43 -85
- package/src/node/index.d.ts +5 -5
- package/src/node/index.js +18 -77
- package/src/node/status.d.ts +2 -2
- package/src/node/status.js +37 -81
- package/src/node/totalCredits.d.ts +3 -2
- package/src/node/totalCredits.js +32 -73
- package/src/stateTransitions/broadcast.d.ts +1 -1
- package/src/stateTransitions/broadcast.js +7 -57
- package/src/stateTransitions/index.d.ts +1 -1
- package/src/stateTransitions/index.js +13 -66
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +1 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +6 -62
- package/src/tokens/createStateTransition.d.ts +1 -1
- package/src/tokens/createStateTransition.js +23 -35
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -2
- package/src/tokens/getIdentitiesTokenBalances.js +40 -83
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
- package/src/tokens/getIdentityTokensBalances.js +40 -83
- package/src/tokens/getTokenContractInfo.d.ts +2 -2
- package/src/tokens/getTokenContractInfo.js +40 -83
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +3 -0
- package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
- package/src/tokens/getTokenTotalSupply.d.ts +2 -2
- package/src/tokens/getTokenTotalSupply.js +38 -81
- package/src/tokens/index.d.ts +13 -5
- package/src/tokens/index.js +46 -113
- package/src/types.d.ts +20 -16
- package/src/types.js +6 -16
- package/src/utils/base58ToBytes.js +3 -6
- package/src/utils/bytesToHex.js +2 -5
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateMsgHash.js +10 -13
- package/src/utils/calculateSignHash.d.ts +2 -2
- package/src/utils/calculateSignHash.js +7 -10
- package/src/utils/calculateStateIdHash.d.ts +2 -2
- package/src/utils/calculateStateIdHash.js +8 -10
- package/src/utils/convertToHomographSafeChars.d.ts +0 -4
- package/src/utils/convertToHomographSafeChars.js +2 -9
- package/src/utils/createMasternodeIdentityId.d.ts +2 -0
- package/src/utils/createMasternodeIdentityId.js +4 -0
- package/src/utils/createVoterIdentityId.d.ts +2 -0
- package/src/utils/createVoterIdentityId.js +13 -0
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/getEvonodeList.js +10 -61
- package/src/utils/getQuorumPublicKey.js +15 -66
- package/src/utils/getRandomArrayItem.js +1 -4
- package/src/utils/getRandomBytes.d.ts +1 -0
- package/src/utils/getRandomBytes.js +4 -0
- package/src/utils/hexToBytes.js +2 -6
- package/src/utils/index.d.ts +19 -3
- package/src/utils/index.js +45 -31
- package/src/utils/indexBytesToString.js +2 -5
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/sha256.js +10 -8
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signHash.js +9 -12
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/signRequestId.js +9 -12
- package/src/utils/sleep.d.ts +1 -0
- package/src/utils/sleep.js +3 -0
- package/src/utils/stringToIndexValueBytes.js +4 -7
- package/src/utils/verifyTenderdashProof.d.ts +2 -2
- package/src/utils/verifyTenderdashProof.js +13 -17
- package/src/voting/createStateTransition.d.ts +2 -0
- package/src/voting/createStateTransition.js +6 -0
- package/src/voting/createVote.d.ts +2 -0
- package/src/voting/createVote.js +5 -0
- package/src/voting/index.d.ts +37 -0
- package/src/voting/index.js +55 -0
- package/test/unit/ContestedResources.spec.js +91 -90
- package/test/unit/DataContract.spec.js +44 -111
- package/test/unit/Document.spec.js +93 -183
- package/test/unit/Identity.spec.js +254 -357
- package/test/unit/KeyPair.spec.js +30 -145
- package/test/unit/Names.spec.d.ts +1 -0
- package/test/unit/Names.spec.js +33 -0
- package/test/unit/Node.spec.js +55 -126
- package/test/unit/SDK.spec.js +7 -9
- package/test/unit/Tokens.spec.js +112 -262
- package/bundle.min.js.LICENSE.txt +0 -1
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
- package/src/names/search.d.ts +0 -3
- package/src/names/search.js +0 -63
- package/src/signer/AbstractSigner.d.ts +0 -12
- package/src/signer/AbstractSigner.js +0 -2
- package/src/signer/PrivateKeySigner.d.ts +0 -0
- package/src/signer/PrivateKeySigner.js +0 -64
- package/src/signer/setSigner.d.ts +0 -2
- package/src/signer/setSigner.js +0 -8
package/src/keyPair/index.js
CHANGED
|
@@ -1,323 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
1
|
+
import { HDKey } from '@scure/bip32';
|
|
2
|
+
import mnemonicToSeed from './mnemonicToSeed.js';
|
|
3
|
+
import deriveChild from './deriveChild.js';
|
|
4
|
+
import derivePath from './derivePath.js';
|
|
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
|
-
|
|
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 {
|
|
22
|
+
* @return {Uint8Array} Seed bytes
|
|
198
23
|
*/
|
|
199
|
-
|
|
200
|
-
return
|
|
201
|
-
|
|
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
|
|
28
|
+
* Returns seed from mnemonic phrase
|
|
211
29
|
*
|
|
212
|
-
* @param
|
|
213
|
-
* @param
|
|
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 {
|
|
33
|
+
* @return {HDKey} HDKey
|
|
218
34
|
*/
|
|
219
|
-
|
|
220
|
-
return
|
|
221
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return
|
|
239
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return
|
|
257
|
-
|
|
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
|
-
*
|
|
61
|
+
* Derives an {HDKey} child by identity index and key index from an {HDKey}
|
|
267
62
|
*
|
|
268
|
-
*
|
|
269
|
-
* @param opts {HDFromSeedOptions?} - Optional options with network version
|
|
63
|
+
* Usually used to get a identity private key from seed
|
|
270
64
|
*
|
|
271
|
-
* @
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
* @
|
|
70
|
+
* @returns {HDKey}
|
|
292
71
|
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
*
|
|
78
|
+
* Converts {PublicKey} to a Dash network address (P2PKH)
|
|
79
|
+
*
|
|
80
|
+
* @param publicKey {Uint8Array}
|
|
81
|
+
* @param network {Network}
|
|
306
82
|
*
|
|
307
|
-
* @
|
|
308
|
-
* @param opts {HDFromXKeyOptions=} - Optional options
|
|
309
|
-
* @return {Promise<HDXKey>}
|
|
83
|
+
* @returns {string}
|
|
310
84
|
*/
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
|
1
|
+
export default function mnemonicToSeed(mnemonic: string, salt?: string): Uint8Array;
|
|
@@ -1,47 +1,4 @@
|
|
|
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.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
|
}
|
package/src/names/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { DocumentWASM } from 'pshenmic-dpp';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { IdentifierLike } from '../types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Functions related to DPNS names (usernames)
|
|
5
6
|
*
|
|
@@ -23,5 +24,45 @@ export declare class NamesController {
|
|
|
23
24
|
*
|
|
24
25
|
* @return Promise<DocumentWASM | null>
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
searchByName(name: string): Promise<DocumentWASM[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Tests a given username against contested names rules.
|
|
30
|
+
* Contested names includes an additional fee of 0.2 Dash
|
|
31
|
+
* as a voting resolution fee
|
|
32
|
+
*
|
|
33
|
+
* This function return boolean whether given username (f.e pshenmic.dash)
|
|
34
|
+
* falls under contested names rules.
|
|
35
|
+
* @param name
|
|
36
|
+
*/
|
|
37
|
+
testNameContested(name: string): boolean;
|
|
38
|
+
searchByIdentity(identifier: IdentifierLike): Promise<DocumentWASM[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Performs a DPNS name registration sequence
|
|
41
|
+
* Contested names are include additional fee of 0.2 Dash
|
|
42
|
+
* Check your name is contested with .testNameContested(name) method to check if additional fee will be charged
|
|
43
|
+
*
|
|
44
|
+
* @param name {string} username (ex. pshenmic.dash)
|
|
45
|
+
* @param identityId {IdentifierLike} identity identifier
|
|
46
|
+
* @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
|
|
47
|
+
*/
|
|
48
|
+
registerName(name: string, identityId: IdentifierLike, privateKey: PrivateKeyWASM): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
|
|
51
|
+
*
|
|
52
|
+
* source: https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/src/utils/convertToHomographSafeChars.ts
|
|
53
|
+
*
|
|
54
|
+
*
|
|
55
|
+
* @param label {string}
|
|
56
|
+
*
|
|
57
|
+
* @return {string}
|
|
58
|
+
*/
|
|
59
|
+
normalizeLabel(label: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Validates a DPNS name that you would like to register
|
|
62
|
+
*
|
|
63
|
+
* @param fullName {string} full DPNS name (ex. pshenmic.dash)
|
|
64
|
+
*
|
|
65
|
+
* @return {string} null if valid or string with a reason
|
|
66
|
+
*/
|
|
67
|
+
validateName(fullName: string): null | string;
|
|
27
68
|
}
|