Skip to content

Commit a392d9b

Browse files
author
AJ ONeal
committed
ref!: remove setPublicKey()
1 parent abb677d commit a392d9b

File tree

4 files changed

+19
-53
lines changed

4 files changed

+19
-53
lines changed

dashhd.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@
3939
* @prop {HDMaybeGetString} getPrivateExtendedKey
4040
* @prop {HDMaybeGetBuffer} getPrivateKey
4141
* @prop {HDGetString} getPublicExtendedKey
42-
* @prop {HDSetBuffer} setPublicKey
4342
* @prop {HDSetBuffer} setPrivateKey
4443
* @prop {HDWipePrivates} wipePrivateData - randomizes private key buffer in-place
45-
* @prop {Function} _setPublicKey
4644
*/
4745

4846
/** @type {DashHD} */
@@ -235,28 +233,11 @@ var DashHd = ("object" === typeof module && exports) || {};
235233
hdkey.getPrivateKey = function () {
236234
return _privateKey;
237235
};
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.");
240238

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);
260241
};
261242

262243
hdkey.getPrivateExtendedKey = async function () {
@@ -366,8 +347,7 @@ var DashHd = ("object" === typeof module && exports) || {};
366347
let nextPrivKey = await Utils.privateKeyTweakAdd(_privateKey, IL);
367348
await _hdkey.setPrivateKey(nextPrivKey);
368349
} else {
369-
let nextPubKey = await Utils.publicKeyTweakAdd(hdkey.publicKey, IL);
370-
await _hdkey.setPublicKey(nextPubKey);
350+
_hdkey.publicKey = await Utils.publicKeyTweakAdd(hdkey.publicKey, IL);
371351
}
372352

373353
return _hdkey;
@@ -468,10 +448,13 @@ var DashHd = ("object" === typeof module && exports) || {};
468448
version === versions.public,
469449
"Version mismatch: version does not match public",
470450
);
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);
475458
}
476459
}
477460

package-lock.json

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
"files": [],
3434
"devDependencies": {
3535
"@dashincubator/secp256k1": "^1.7.1-4",
36-
"bigi": "^1.1.0",
37-
"ecurve": "^1.0.0",
3836
"mocha": "^10.2.0",
3937
"mocha-lcov-reporter": "0.0.1"
4038
},

test/hdkey.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

33
var assert = require("assert");
4-
var BigInteger = require("bigi");
5-
var crypto = require("crypto");
6-
var ecurve = require("ecurve");
7-
var curve = ecurve.getCurveByName("secp256k1");
4+
//var BigInteger = require("bigi");
5+
//var crypto = require("crypto");
6+
//var ecurve = require("ecurve");
7+
//var curve = ecurve.getCurveByName("secp256k1");
88
var DashHd = require("../");
99
var fixtures = require("./fixtures/hdkey");
1010

@@ -61,6 +61,8 @@ describe("hdkey", function () {
6161
});
6262
});
6363

64+
/*
65+
// TODO adapt to XPub Key data
6466
describe("- publicKey", function () {
6567
it("should throw an error if incorrect key size", async function () {
6668
assert.rejects(async function () {
@@ -89,6 +91,7 @@ describe("hdkey", function () {
8991
await hdkey.setPublicKey(new Uint8Array(pub));
9092
});
9193
});
94+
*/
9295

9396
describe("+ fromExtendedKey()", function () {
9497
describe("> when private", function () {

0 commit comments

Comments
 (0)