Javascript: How can export a PNG image with a black background and white brush from canvas?

Input:
An original image is uploaded then a canvas overlay with the size of the image and then brush painted on.

https://i.stack.imgur.com/7UKsG.png

Output:
Is the mask image, defining the areas that need to be removed

  • The mask image should be a PNG, and should have the same resolution as the original image
  • The mask should be black and white with no grey pixels

https://i.stack.imgur.com/7UKsG.png