Skip to content

Commit bcfd2c6

Browse files
committed
lints and fix phrasing in one of the tests
1 parent bcbfb70 commit bcfd2c6

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/core/crypto/slhDsaSha2128s.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ export class SlhDsaSha2128sPrivateKey extends Serializable implements PrivateKey
197197
/**
198198
* The SLH-DSA-SHA2-128s key seed to use for BIP-32 compatibility
199199
* See more {@link https://github.com/satoshilabs/slips/blob/master/slip-0010.md}
200-
*
200+
*
201201
* TODO: This is not standardized... AFAIK.
202-
*
202+
*
203203
* @group Implementation
204204
* @category Serialization
205205
*/
@@ -286,7 +286,6 @@ export class SlhDsaSha2128sPrivateKey extends Serializable implements PrivateKey
286286
return new SlhDsaSha2128sSignature(signatureBytes);
287287
}
288288

289-
290289
/**
291290
* Derives a private key from a mnemonic seed phrase using a specified BIP44 path.
292291
* To derive multiple keys from the same phrase, change the path
@@ -308,7 +307,7 @@ export class SlhDsaSha2128sPrivateKey extends Serializable implements PrivateKey
308307

309308
/**
310309
* Derives a child private key from a given BIP44 path and seed.
311-
*
310+
*
312311
* We derive our 48-byte SLH-DSA key (three 16-byte seeds) from:
313312
* - the 32-byte, BIP-32-derived, secret key
314313
* - the first 16 bytes of the BIP-32-derived chain code
@@ -320,24 +319,31 @@ export class SlhDsaSha2128sPrivateKey extends Serializable implements PrivateKey
320319
* @group Implementation
321320
* @category Serialization
322321
*/
323-
private static fromDerivationPathInner(path: string, seed: Uint8Array, offset = HARDENED_OFFSET): SlhDsaSha2128sPrivateKey {
322+
private static fromDerivationPathInner(
323+
path: string,
324+
seed: Uint8Array,
325+
offset = HARDENED_OFFSET,
326+
): SlhDsaSha2128sPrivateKey {
324327
const { key, chainCode } = deriveKey(SlhDsaSha2128sPrivateKey.SLIP_0010_SEED, seed);
325328

326329
const segments = splitPath(path).map((el) => parseInt(el, 10));
327330

328331
// Derive the child key based on the path
329-
const { key: privateKey, chainCode: finalChainCode } = segments.reduce((parentKeys, segment) => CKDPriv(parentKeys, segment + offset), {
330-
key,
331-
chainCode,
332-
});
333-
332+
const { key: privateKey, chainCode: finalChainCode } = segments.reduce(
333+
(parentKeys, segment) => CKDPriv(parentKeys, segment + offset),
334+
{
335+
key,
336+
chainCode,
337+
},
338+
);
339+
334340
const threeSeeds = new Uint8Array(48);
335341
threeSeeds.set(privateKey, 0); // First 32 bytes from the derived secret key
336342

337343
// TODO: We would need to reason about the security of this.
338344
// e.g., is it okay to treat the chain code as public?
339345
threeSeeds.set(finalChainCode.slice(0, 16), 32); // Last 16 bytes from the derived chain code
340-
346+
341347
return new SlhDsaSha2128sPrivateKey(threeSeeds, false);
342348
}
343349

tests/unit/hdKey.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { secp256k1WalletTestObject, wallet } from "./helper";
2-
import { Ed25519PrivateKey, Hex, isValidBIP44Path, isValidHardenedPath, Secp256k1PrivateKey, SlhDsaSha2128sPrivateKey } from "../../src";
2+
import {
3+
Ed25519PrivateKey,
4+
Hex,
5+
isValidBIP44Path,
6+
isValidHardenedPath,
7+
Secp256k1PrivateKey,
8+
SlhDsaSha2128sPrivateKey,
9+
} from "../../src";
310

411
describe("Hierarchical Deterministic Key (hdkey)", () => {
512
describe("hardened path", () => {

tests/unit/slhDsaSha2128s.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ describe("SlhDsaSha2128sPrivateKey", () => {
173173
expect(deserializedPrivateKey.toUint8Array()).toEqual(privateKey.toUint8Array());
174174
});
175175

176-
it("should derive public key from private key seed", () => {
176+
it("should derive same public key from randomly-generated private key or from-bytes private key", () => {
177177
const keyPair = SlhDsaSha2128sKeyPair.generate();
178178
const privateKeyBytes = keyPair.privateKey.toUint8Array();
179-
// Create a new private key instance from the seed
179+
// Create a new private key instance
180180
const privateKey = new SlhDsaSha2128sPrivateKey(privateKeyBytes, false);
181-
// Public key should be derivable from the seed
181+
// Public key should be derivable
182182
const derivedPublicKey = privateKey.publicKey();
183183
expect(derivedPublicKey).toBeInstanceOf(SlhDsaSha2128sPublicKey);
184184
expect(derivedPublicKey.toUint8Array()).toEqual(keyPair.publicKey.toUint8Array());

0 commit comments

Comments
 (0)