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

Function unpad

src/utils/nip44.ts:84–91  ·  view source on GitHub ↗
(padded: Buffer)

Source from the content-addressed store, hash-verified

82}
83
84function unpad(padded: Buffer): string {
85 const unpaddedLen = padded.readUInt16BE(0)
86 const unpadded = padded.subarray(2, 2 + unpaddedLen)
87 if (unpaddedLen === 0 || unpadded.length !== unpaddedLen || padded.length !== 2 + calcPaddedLen(unpaddedLen)) {
88 throw new Error('invalid padding')
89 }
90 return unpadded.toString('utf8')
91}
92
93/**
94 * Encrypt plaintext using NIP-44 v2.

Callers 1

nip44DecryptFunction · 0.85

Calls 2

calcPaddedLenFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected