|
39 | 39 | * @prop {HDMaybeGetString} getPrivateExtendedKey
|
40 | 40 | * @prop {HDMaybeGetBuffer} getPrivateKey
|
41 | 41 | * @prop {HDGetString} getPublicExtendedKey
|
42 |
| - * @prop {HDSetBuffer} setPublicKey |
43 | 42 | * @prop {HDSetBuffer} setPrivateKey
|
44 | 43 | * @prop {HDWipePrivates} wipePrivateData - randomizes private key buffer in-place
|
45 |
| - * @prop {Function} _setPublicKey |
46 | 44 | */
|
47 | 45 |
|
48 | 46 | /** @type {DashHD} */
|
@@ -235,28 +233,11 @@ var DashHd = ("object" === typeof module && exports) || {};
|
235 | 233 | hdkey.getPrivateKey = function () {
|
236 | 234 | return _privateKey;
|
237 | 235 | };
|
238 |
| - hdkey.setPrivateKey = async function (value) { |
239 |
| - assert(value.length === 32, "Private key must be 32 bytes."); |
| 236 | + hdkey.setPrivateKey = async function (privBytes) { |
| 237 | + assert(privBytes.length === 32, "Private key must be 32 bytes."); |
240 | 238 |
|
241 |
| - _privateKey = value; |
242 |
| - hdkey.publicKey = await Utils.toPublicKey(value); |
243 |
| - }; |
244 |
| - |
245 |
| - hdkey.setPublicKey = async function (value) { |
246 |
| - assert( |
247 |
| - value.length === 33 || value.length === 65, |
248 |
| - "Public key must be 33 or 65 bytes.", |
249 |
| - ); |
250 |
| - let publicKey = await Utils.publicKeyNormalize(value); |
251 |
| - await hdkey._setPublicKey(publicKey); |
252 |
| - }; |
253 |
| - |
254 |
| - /** |
255 |
| - * @param {Uint8Array} publicKey |
256 |
| - */ |
257 |
| - hdkey._setPublicKey = async function (publicKey) { |
258 |
| - hdkey.publicKey = publicKey; |
259 |
| - _privateKey = null; |
| 239 | + _privateKey = privBytes; |
| 240 | + hdkey.publicKey = await Utils.toPublicKey(_privateKey); |
260 | 241 | };
|
261 | 242 |
|
262 | 243 | hdkey.getPrivateExtendedKey = async function () {
|
@@ -366,8 +347,7 @@ var DashHd = ("object" === typeof module && exports) || {};
|
366 | 347 | let nextPrivKey = await Utils.privateKeyTweakAdd(_privateKey, IL);
|
367 | 348 | await _hdkey.setPrivateKey(nextPrivKey);
|
368 | 349 | } else {
|
369 |
| - let nextPubKey = await Utils.publicKeyTweakAdd(hdkey.publicKey, IL); |
370 |
| - await _hdkey.setPublicKey(nextPubKey); |
| 350 | + _hdkey.publicKey = await Utils.publicKeyTweakAdd(hdkey.publicKey, IL); |
371 | 351 | }
|
372 | 352 |
|
373 | 353 | return _hdkey;
|
@@ -468,10 +448,13 @@ var DashHd = ("object" === typeof module && exports) || {};
|
468 | 448 | version === versions.public,
|
469 | 449 | "Version mismatch: version does not match public",
|
470 | 450 | );
|
471 |
| - if (skipVerification) { |
472 |
| - await hdkey._setPublicKey(key); |
473 |
| - } else { |
474 |
| - await hdkey.setPublicKey(key); |
| 451 | + assert( |
| 452 | + key.length === 33 || key.length === 65, |
| 453 | + "Public key must be 33 or 65 bytes.", |
| 454 | + ); |
| 455 | + hdkey.publicKey = key; |
| 456 | + if (!skipVerification) { |
| 457 | + hdkey.publicKey = await Utils.publicKeyNormalize(hdkey.publicKey); |
475 | 458 | }
|
476 | 459 | }
|
477 | 460 |
|
|
0 commit comments