Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- feat: management canister interface updates for schnorr signatures
- feat: ensure that identity-secp256k1 seed phrase must produce a 64 byte seed
- docs: documentation and metadata for use-auth-client

### Changed
Expand Down
13 changes: 13 additions & 0 deletions packages/identity-secp256k1/src/secp256k1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,17 @@ describe('public key serialization from various types', () => {
const shouldFailHex = () => Secp256k1PublicKey.from('not a hex string');
expect(shouldFailHex).toThrow('Invalid hexadecimal string');
});

it('should throw an error serializing a too short seed phrase', () => {
const shouldFail = () => Secp256k1KeyIdentity.fromSeedPhrase('one two three');
expect(shouldFail).toThrow('Invalid mnemonic');
});

it('should throw an error serializing a too long seed phrase', () => {
const shouldFail = () =>
Secp256k1KeyIdentity.fromSeedPhrase(
'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen',
);
expect(shouldFail).toThrow('Invalid mnemonic');
});
});
4 changes: 4 additions & 0 deletions packages/identity-secp256k1/src/secp256k1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export class Secp256k1KeyIdentity extends SignIdentity {
}

const seed = bip39.mnemonicToSeedSync(phrase, password);
// Ensure the seed is 64 bytes long
if (seed.byteLength !== 64) {
throw new Error('Derived seed must be 64 bytes long.');
}
const root = HDKey.fromMasterSeed(seed);
const addrnode = root.derive("m/44'/223'/0'/0/0");

Expand Down