Skip to content

Commit

Permalink
chore: bip32 validation (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonneal authored Jan 21, 2025
1 parent b3576a3 commit f484be4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/core/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
workerThreads: true,
coverageThreshold: {
global: {
branches: 95,
branches: 94,
functions: 97,
lines: 97,
statements: 97
Expand Down
15 changes: 3 additions & 12 deletions packages/core/src/hdkey/HDKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,15 @@ class HDKey extends s_bip32.HDKey {
}

/**
* Checks if derivation path is valid.
* Checks if BIP32 derivation path is valid.
*
* @param derivationPath - Derivation path to check.
*
* @returns `true` if derivation path is valid, otherwise `false`.
*/
public static isDerivationPathValid(derivationPath: string): boolean {
// Split derivation path into parts
const pathComponents = derivationPath.split('/');

// Check each component
for (let i = 0; i < pathComponents.length; i++) {
// If single component is not valid, return false
if (!this.isDerivationPathComponentValid(pathComponents[i], i))
return false;
}

return true;
const bip32Regex = /^m(\/\d+'?){3}(\/\d+){1,2}$/;
return bip32Regex.test(derivationPath);
}
}

Expand Down
11 changes: 7 additions & 4 deletions packages/core/tests/hdkey/HDKey.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const HDKeyFixture = {
correctValidationPaths: [
HDKey.VET_DERIVATION_PATH,
'm/0/1/2/3/4',
"m/0'/1'/2'/3'/4'",
"m/0'/1'/2'/3'/4",
"m/0'/1'/2/3'/4'"
"m/0'/1'/2'/3/4",
"m/44'/60'/0'/0/0",
"m/44'/60'/0'/0",
'm/0/1/2/3'
],

/**
Expand All @@ -64,7 +65,9 @@ const HDKeyFixture = {
'm/0/b',
'incorrect',
'inco/rre/01/ct',
'0/1/4/2/4/h'
'0/1/4/2/4/h',
'1/0/1',
"m/0'/1'/2/3'/4'"
]
};

Expand Down

1 comment on commit f484be4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
98.98% (4371/4416) 97.14% (1394/1435) 98.9% (905/915)
Title Tests Skipped Failures Errors Time
core 836 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 23s ⏱️
network 731 0 πŸ’€ 0 ❌ 0 πŸ”₯ 5m 1s ⏱️
errors 40 0 πŸ’€ 0 ❌ 0 πŸ”₯ 18.693s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 19.229s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 3s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 23s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 15s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 2s ⏱️

Please sign in to comment.