aboutsummaryrefslogtreecommitdiff
path: root/src/modules/finance/bitcoin.ts
blob: f7cfaf70ac3b81818b995ffcb1e5f5cf62cf753a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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',
  },
};