(input: string)
| 144 | }) |
| 145 | |
| 146 | export const fromBech32 = (input: string) => { |
| 147 | const normalizedInput = input.toLowerCase() |
| 148 | |
| 149 | if (input !== normalizedInput && input !== input.toUpperCase()) { |
| 150 | throw new Error('Bech32 mixed-case input is invalid') |
| 151 | } |
| 152 | |
| 153 | const { prefix, words } = bech32Decode(input) |
| 154 | if (!normalizedInput.startsWith(prefix)) { |
| 155 | throw new Error(`Bech32 invalid prefix: ${prefix}`) |
| 156 | } |
| 157 | |
| 158 | return Buffer.from( |
| 159 | bech32Convert(words, 5, 8, false).slice(0, 32) |
| 160 | ).toString('hex') |
| 161 | } |
| 162 | |
| 163 | export const toBech32 = (prefix: string) => (input: string): string => { |
| 164 | return bech32Encode(prefix, bech32Convert(Array.from(Buffer.from(input, 'hex')), 8, 5, true)) |
no test coverage detected