message: Improvements to IsoBuffer.from(): supporting TypedArrays and proper detection of ArrayBuffers
diff: */
  import * as base64js from "base64-js";
  +import { assert } from "./assert";
  /**
  * Converts a Uint8Array to a string of the provided encoding
  @@ -45,14 +46,30 @@ export const bufferToString = (blob: ArrayBufferLike, encoding: string): string
  IsoBuffer.from(blob).toString(encoding);
  /**
  - * Minimal implementation of Buffer for our usages in the browser environment.
  + * Determines if an object is an array buffer
  + * Will detect and reject TypedArrays, like Uint8Array.
  + * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
  + * math properly (i.e. take into account byteOffset at minimum).
  + * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
  + * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
  + * ignoring byteOffice, length)
  + * @param obj - The object to determine if it is an ArrayBuffer
  */
  -export class IsoBuffer extends Uint8Array {
  - // Need to have ctor for it to be in proto chain for instanceof check in from() method to work
  - public constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number) {
  - super(buffer, byteOffset, length);
  +export function isArrayBuffer(obj: any): obj is ArrayBuffer {
  + const maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined;
  + return obj instanceof ArrayBuffer
  + || (typeof maybe === "object"
  + && maybe !== null
  + && typeof maybe.byteLength === "number"
  + && typeof maybe.slice === "function"
  + && maybe.byteOffset === undefined
  + && maybe.buffer === undefined);
  }
  +/**
  + * Minimal implementation of Buffer for our usages in the browser environment.
  + */
  +export class IsoBuffer extends Uint8Array {
  /**
  * Convert the buffer to a string.
  * Only supports encoding the whole string (unlike the Node Buffer equivalent)
  @@ -71,9 +88,13 @@ export class IsoBuffer extends Uint8Array {
  static from(value, encodingOrOffset?, length?): IsoBuffer {
  if (typeof value === "string") {
  return IsoBuffer.fromString(value, encodingOrOffset as string | undefined);
  - } else if (value instanceof IsoBuffer) {
  - return value;
  - } else if (value instanceof ArrayBuffer) {
  + // Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
  + } else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) {
  + // Support currently for full array, no view ports! (though it can be added in future)
  + assert(value.byteOffset === 0);
  + assert(value.byteLength === value.buffer.byteLength);
  + return IsoBuffer.fromArrayBuffer(value.buffer, encodingOrOffset as number | undefined, length);
  + } else if (isArrayBuffer(value)) {
  return IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length);
  } else {
  throw new TypeError();
  