aboutsummaryrefslogtreecommitdiff
path: root/src/modules/finance/bitcoin.ts
diff options
context:
space:
mode:
authorDavid Simão <[email protected]>2024-06-05 09:01:26 +0100
committerGitHub <[email protected]>2024-06-05 10:01:26 +0200
commit3ae93934bc4cf5f6414acfa28ea727f758d18756 (patch)
treede1c649f829dbcdca838c4fedcac76c3450ccff6 /src/modules/finance/bitcoin.ts
parentbadaa6d60593fe41a1afa0e9a8bef6ae5bb8a352 (diff)
downloadfaker-3ae93934bc4cf5f6414acfa28ea727f758d18756.tar.xz
faker-3ae93934bc4cf5f6414acfa28ea727f758d18756.zip
feat(bitcoinAddress): multiple bitcoin address types and testnet (#2922)
Diffstat (limited to 'src/modules/finance/bitcoin.ts')
-rw-r--r--src/modules/finance/bitcoin.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/modules/finance/bitcoin.ts b/src/modules/finance/bitcoin.ts
new file mode 100644
index 00000000..f7cfaf70
--- /dev/null
+++ b/src/modules/finance/bitcoin.ts
@@ -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',
+ },
+};