-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve(hd-wallet): verify that the derivation path template includes…
… <index> (#2168)
- Loading branch information
Showing
6 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kadena/hd-wallet": patch | ||
--- | ||
|
||
Verify that the derivation path template includes `<index>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/libs/hd-wallet/src/SLIP10/utils/isDerivationPathTemplateValid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function isDerivationPathTemplateValid( | ||
derivationPathTemplate: string, | ||
): boolean { | ||
return ( | ||
typeof derivationPathTemplate === 'string' && | ||
derivationPathTemplate.includes('<index>') | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/libs/hd-wallet/src/SLIP10/utils/tests/isDerivationPathTemplateValid.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { isDerivationPathTemplateValid } from '../isDerivationPathTemplateValid.js'; | ||
|
||
describe('isDerivationPathTemplateValid', () => { | ||
it("should return true if derivationPathTemplate is a string and includes '<index>'", () => { | ||
expect(isDerivationPathTemplateValid("m'/44'/626'/<index>'")).toBe(true); | ||
}); | ||
it('should return false if derivationPathTemplate is not a string', () => { | ||
expect(isDerivationPathTemplateValid(123 as unknown as string)).toBe(false); | ||
}); | ||
it("should return false if derivationPathTemplate does not include '<index>'", () => { | ||
expect(isDerivationPathTemplateValid("m'/44'/626'/index'")).toBe(false); | ||
}); | ||
it('returns false if derivationPathTemplate is an empty string', () => { | ||
expect(isDerivationPathTemplateValid('')).toBe(false); | ||
}); | ||
}); |