Convert base64 for use with rect.fills imageHash

In my code.ts I have a JPEG image that’s been converted to base64 and I am attempting to use it as the imageHash value but am getting Invalid SHA1 hash error.

const img = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA...

const rect = figma.createRectangle();
rect.fills = [{ type: 'IMAGE', scaleMode: 'FIT', imageHash: img }];

What conversion needs to happen to the base64 string in order to use it this way?

The Plugin API says that images should be converted to Uint8Array.

Thank you. I realized I was trying to do the conversion inside code.ts but it needs to happen in ui.html. In ui.html I’m using a helper function to convert the base64 string.

  function _base64ToUint8Array(base64) {
    var binary_string = window.atob(base64);
    var len = binary_string.length;
    var bytes = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
      bytes[i] = binary_string.charCodeAt(i);
    return new Uint8Array(bytes.buffer);