Skip to content

Commit

Permalink
fixup! add test to have 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Mar 6, 2024
1 parent af22882 commit e6b759a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/derivers/bip39.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import * as hmacModule from '@noble/hashes/hmac';

import fixtures from '../../test/fixtures';
import { secp256k1, ed25519Bip32 } from '../curves';
import { secp256k1, ed25519Bip32, type Curve } from '../curves';
import {
entropyToCip3MasterNode,
createBip39KeyFromSeed,
Expand Down Expand Up @@ -69,6 +69,17 @@ describe('createBip39KeyFromSeed', () => {
);
},
);

it('throws with unsupported masterNodeGenerationSpec error', async () => {
await expect(
deriveChildKey({
path: '',
curve: {
masterNodeGenerationSpec: 'notValidMasterNodeGenerationSpec',
} as unknown as Curve,
}),
).rejects.toThrow('Unsupported master node generation spec.');
});
});

describe('Cip3', () => {
Expand Down
15 changes: 14 additions & 1 deletion src/derivers/cip3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { bytesToHex, hexToBytes } from '@metamask/utils';

import fixtures from '../../test/fixtures';
import { BIP_32_HARDENED_OFFSET } from '../constants';
import { ed25519Bip32 } from '../curves';
import { ed25519, ed25519Bip32 } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import {
add,
bigIntToBytes,
bytesToBigInt,
type Cip3SupportedCurve,
deriveChainCode,
deriveChildKey,
derivePrivateKey,
Expand Down Expand Up @@ -165,6 +166,18 @@ describe('Cip3', () => {
JSON.stringify(addressIndexNode),
);
});

it('throws with unsupported curve error', async () => {
await expect(
deriveChildKey({
node: await SLIP10Node.fromJSON(bip39Node),
path: purpose,
curve: ed25519 as unknown as Cip3SupportedCurve,
}),
).rejects.toThrow(
`Unsupported curve: Only ed25519Bip32 is supported by CIP3.`,
);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/derivers/cip3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const getKeyExtension = (
]);
};

type Cip3SupportedCurve = Extract<Curve, { name: 'ed25519Bip32' }>;
export type Cip3SupportedCurve = Extract<Curve, { name: 'ed25519Bip32' }>;

type DeriveKeyBaseArgs = { childIndex: number };

Expand Down

0 comments on commit e6b759a

Please sign in to comment.