bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Home Page:https://libauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

encodeTransaction incompatible with Safari (Mac/iOS)

rkalis opened this issue · comments

encodeTransaction calls encodeInputs and encodeOutputsForTransaction which call bigIntToBitcoinVarInt, which calls bigIntToBinUint64LE. bigIntToBinUint64LE in turn looks like this:

export const bigIntToBinUint64LE = (value: bigint) => {
  const uint64Length = 8;
  const bin = new Uint8Array(uint64Length);
  const writeAsLittleEndian = true;
  const view = new DataView(bin.buffer, bin.byteOffset, bin.byteLength);
  // eslint-disable-next-line functional/no-expression-statement
  view.setBigUint64(0, value, writeAsLittleEndian);
  return bin;
};

view.setBigUint64(...) is not supported by Safari on macOS or iOS (see DataView.prototype.setBigUint64). Note that most iOS browsers are Safari under the hood, so this propagates to those iOS browsers as well. This accounts for about 20% of the global browser market share.

I am not yet sure how to fix this, but I think it is important that this does get fixed, since transaction encoding is a pretty important part of Bitcoin applications, and excluding 20% of potential users is not something you want to do.

Thanks for opening an issue!

It's looks like Safari finally released support for BigInt, I'm a little surprised setBigUint64 isn't in there. In the meantime, I'd definitely appreciate a PR implementing a backward-compatible version. 👍