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

Function pad

src/utils/nip44.ts:72–82  ·  view source on GitHub ↗
(plaintext: string)

Source from the content-addressed store, hash-verified

70}
71
72function pad(plaintext: string): Buffer {
73 const unpadded = Buffer.from(plaintext, 'utf8')
74 const unpaddedLen = unpadded.length
75 if (unpaddedLen < MIN_PLAINTEXT_SIZE || unpaddedLen > MAX_PLAINTEXT_SIZE) {
76 throw new Error('invalid plaintext length')
77 }
78 const prefix = Buffer.alloc(2)
79 prefix.writeUInt16BE(unpaddedLen, 0)
80 const suffix = Buffer.alloc(calcPaddedLen(unpaddedLen) - unpaddedLen)
81 return Buffer.concat([prefix, unpadded, suffix])
82}
83
84function unpad(padded: Buffer): string {
85 const unpaddedLen = padded.readUInt16BE(0)

Callers 1

nip44EncryptFunction · 0.85

Calls 1

calcPaddedLenFunction · 0.85

Tested by

no test coverage detected