-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9ac595
commit e387351
Showing
18 changed files
with
128 additions
and
24 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 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
File renamed without changes.
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,3 @@ | ||
export function checkIfDigitsOnly(value: string) { | ||
return /^\d+$/.test(value); | ||
} |
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,53 @@ | ||
import { AddressType, Network, getAddressInfo, validate } from 'bitcoin-address-validation'; | ||
import * as yup from 'yup'; | ||
|
||
import { BitcoinNetworkModes } from '@shared/constants'; | ||
import { FormErrorMessages } from '@shared/error-messages'; | ||
import { isString } from '@shared/utils'; | ||
|
||
export function btcAddressValidator() { | ||
return yup | ||
.string() | ||
.defined(FormErrorMessages.AddressRequired) | ||
.test((input, context) => { | ||
if (!input) return false; | ||
if (!validate(input)) | ||
return context.createError({ | ||
message: FormErrorMessages.InvalidAddress, | ||
}); | ||
return true; | ||
}); | ||
} | ||
|
||
// ts-unused-exports:disable-next-line | ||
export function btcTaprootAddressValidator() { | ||
return yup.string().test((input, context) => { | ||
if (!input || !validate(input)) return false; | ||
if (getAddressInfo(input).type !== AddressType.p2tr) | ||
return context.createError({ | ||
message: 'Only taproot addresses are supported', | ||
}); | ||
return true; | ||
}); | ||
} | ||
|
||
function btcAddressNetworkValidatorFactory(network: BitcoinNetworkModes) { | ||
function getAddressNetworkType(network: BitcoinNetworkModes): Network { | ||
// Signet uses testnet address format, this parsing is to please the | ||
// validation library | ||
if (network === 'signet') return Network.testnet; | ||
return network as Network; | ||
} | ||
|
||
return (value?: string) => { | ||
if (!isString(value)) return false; | ||
return validate(value, getAddressNetworkType(network)); | ||
}; | ||
} | ||
|
||
export function btcAddressNetworkValidator(network: BitcoinNetworkModes) { | ||
return yup.string().test({ | ||
test: btcAddressNetworkValidatorFactory(network), | ||
message: FormErrorMessages.IncorrectNetworkAddress, | ||
}); | ||
} |
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