forked from faker-js/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bitcoinAddress): multiple bitcoin address types and testnet (fak…
- Loading branch information
Showing
5 changed files
with
235 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Casing } from '../string'; | ||
|
||
/** | ||
* The bitcoin address families. | ||
*/ | ||
export enum BitcoinAddressFamily { | ||
Legacy = 'legacy', | ||
Segwit = 'segwit', | ||
Bech32 = 'bech32', | ||
Taproot = 'taproot', | ||
} | ||
|
||
/** | ||
* The bitcoin address families. | ||
*/ | ||
export type BitcoinAddressFamilyType = `${BitcoinAddressFamily}`; | ||
|
||
/** | ||
* The different bitcoin networks. | ||
*/ | ||
export enum BitcoinNetwork { | ||
Mainnet = 'mainnet', | ||
Testnet = 'testnet', | ||
} | ||
|
||
/** | ||
* The different bitcoin networks. | ||
*/ | ||
export type BitcoinNetworkType = `${BitcoinNetwork}`; | ||
|
||
type BitcoinAddressOptions = { | ||
prefix: Record<BitcoinNetworkType, string>; | ||
length: { min: number; max: number }; | ||
casing: Casing; | ||
exclude: string; | ||
}; | ||
|
||
export const BitcoinAddressSpecs: Record< | ||
BitcoinAddressFamilyType, | ||
BitcoinAddressOptions | ||
> = { | ||
[BitcoinAddressFamily.Legacy]: { | ||
prefix: { [BitcoinNetwork.Mainnet]: '1', [BitcoinNetwork.Testnet]: 'm' }, | ||
length: { min: 26, max: 34 }, | ||
casing: 'mixed', | ||
exclude: '0OIl', | ||
}, | ||
[BitcoinAddressFamily.Segwit]: { | ||
prefix: { [BitcoinNetwork.Mainnet]: '3', [BitcoinNetwork.Testnet]: '2' }, | ||
length: { min: 26, max: 34 }, | ||
casing: 'mixed', | ||
exclude: '0OIl', | ||
}, | ||
[BitcoinAddressFamily.Bech32]: { | ||
prefix: { | ||
[BitcoinNetwork.Mainnet]: 'bc1', | ||
[BitcoinNetwork.Testnet]: 'tb1', | ||
}, | ||
length: { min: 42, max: 42 }, | ||
casing: 'lower', | ||
exclude: '1bBiIoO', | ||
}, | ||
[BitcoinAddressFamily.Taproot]: { | ||
prefix: { | ||
[BitcoinNetwork.Mainnet]: 'bc1p', | ||
[BitcoinNetwork.Testnet]: 'tb1p', | ||
}, | ||
length: { min: 62, max: 62 }, | ||
casing: 'lower', | ||
exclude: '1bBiIoO', | ||
}, | ||
}; |
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