MCPcopy Create free account
hub / github.com/cameri/nostream / fromBech32

Function fromBech32

src/utils/transform.ts:146–161  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

144})
145
146export 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
163export const toBech32 = (prefix: string) => (input: string): string => {
164 return bech32Encode(prefix, bech32Convert(Array.from(Buffer.from(input, 'hex')), 8, 5, true))

Callers 2

handleRequestMethod · 0.90
rootRequestHandlerFunction · 0.90

Calls 3

bech32DecodeFunction · 0.85
bech32ConvertFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected