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

Function validateNip44Payload

src/utils/nip44.ts:158–180  ·  view source on GitHub ↗
(payload: string)

Source from the content-addressed store, hash-verified

156const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/
157
158export function validateNip44Payload(payload: string): string | undefined {
159 if (!payload || payload[0] === '#') {
160 return 'unsupported encryption version'
161 }
162 if (payload.length < 132 || payload.length > 87472) {
163 return 'invalid payload size'
164 }
165
166 if (payload.length % 4 !== 0 || !BASE64_RE.test(payload)) {
167 return 'payload is not valid base64'
168 }
169
170 const data = Buffer.from(payload, 'base64')
171
172 if (data.length < 99 || data.length > 65603) {
173 return 'invalid decoded payload size'
174 }
175 if (data[0] !== 2) {
176 return `unsupported encryption version ${data[0]}`
177 }
178
179 return undefined
180}

Callers 2

nip44.spec.tsFile · 0.90
validateGiftWrapMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected