A raw pointer crosses as a handle: JavaScript allocates the memory, and C++ reads and writes it in place.
allocBuffer(4) reserves four bytes inside the module and returns a handle to them, and writeBuffer copies a Uint8Array in. invert takes the handle as its uint8_t * and changes the bytes where they are; readBuffer copies them back out.
The helpers are imported from the header, beside your own functions. A handle frees its block once the garbage collector reclaims it; memory a library hands out stays the library's to free.
Try it
Invert the block a second time and read it again, then do the same with a block of 8 bytes.