-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove redundant assertions (#313)
* fix: remove assertions.ts form index.ts * feat: assert for array * feat: assert for hdnode.ts * fix: missing * feat: common assertion for secp256k1.ts and some typo fix * feat: common assertion for transaction sign handler * fix: missing tsdoc * feat: common assertion for transaction * feat: common assertion for poll * feat: common assertion for transaction thorest client * feat: common assertion for accounts thorest client * feat: contrib guidelines for common assertions * fix: typo * fix: remove assertion wrong
- Loading branch information
1 parent
e9772f8
commit e2ae986
Showing
26 changed files
with
357 additions
and
251 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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { assert, HDNODE } from '@vechainfoundation/vechain-sdk-errors'; | ||
import { isDerivationPathValid } from '../../utils'; | ||
|
||
/** | ||
* Asserts that the derivation path is valid. | ||
* | ||
* @param path - The derivation path to validate. | ||
*/ | ||
function assertIsValidHdNodeDerivationPath(path: string): void { | ||
assert( | ||
isDerivationPathValid(path), | ||
HDNODE.INVALID_HDNODE_DERIVATION_PATH, | ||
'Invalid derivation path.', | ||
{ path } | ||
); | ||
} | ||
|
||
/** | ||
* Asserts that the chain code is valid. | ||
* | ||
* @param chainCode - The chain code to validate. | ||
*/ | ||
function assertIsValidHdNodeChainCode(chainCode: Buffer): void { | ||
assert( | ||
chainCode.length === 32, | ||
HDNODE.INVALID_HDNODE_CHAIN_CODE, | ||
'Invalid chain code. Length must be 32 bytes.', | ||
{ chainCode } | ||
); | ||
} | ||
|
||
export { assertIsValidHdNodeDerivationPath, assertIsValidHdNodeChainCode }; |
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,39 @@ | ||
import { assert, SECP256K1 } from '@vechainfoundation/vechain-sdk-errors'; | ||
|
||
/** | ||
* Assert if private key is valid | ||
* | ||
* @param privateKey - Private key to assert | ||
* @param isValidPrivateKeyFunction - Function to assert private key | ||
*/ | ||
function assertIsValidPrivateKey( | ||
privateKey: Buffer, | ||
isValidPrivateKeyFunction: (privateKey: Buffer) => boolean | ||
): void { | ||
assert( | ||
isValidPrivateKeyFunction(privateKey), | ||
SECP256K1.INVALID_SECP256k1_PRIVATE_KEY, | ||
'Invalid private key given as input. Length must be 32 bytes', | ||
{ privateKey } | ||
); | ||
} | ||
|
||
/** | ||
* Assert if message hash is valid | ||
* | ||
* @param msgHash - Message hash to assert | ||
* @param isValidMessageHashFunction - Function to assert message hash | ||
*/ | ||
function assertIsValidSecp256k1MessageHash( | ||
msgHash: Buffer, | ||
isValidMessageHashFunction: (messageHash: Buffer) => boolean | ||
): void { | ||
assert( | ||
isValidMessageHashFunction(msgHash), | ||
SECP256K1.INVALID_SECP256k1_MESSAGE_HASH, | ||
'Invalid message hash given as input. Length must be 32 bytes', | ||
{ msgHash } | ||
); | ||
} | ||
|
||
export { assertIsValidPrivateKey, assertIsValidSecp256k1MessageHash }; |
Oops, something went wrong.
e2ae986
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Coverage
Summary