Thruput TypeScript protocol bindings
    Preparing search index...

    Function fixedBytes

    • Check that data is exactly length bytes and return it as a FixedBytes.

      The byte counterpart to fixedArray: a fixed length is a literal type, so a plain Uint8Array (length number) cannot be assigned to FixedBytes<N> directly. This is the checked construction path.

      const salt = fixedBytes(crypto.getRandomValues(new Uint8Array(32)), 32);
      

      Returns a copy, so later writes through the caller's reference cannot change the bytes behind the result — the same caller-owned convention the readers use for readFixedOpaque. Copying a view copies only that view's range. Unlike fixedArray the result is not frozen: Object.freeze throws on a non-empty typed array. Nothing is lost by that, since a Uint8Array's length cannot change through an alias at all — only its contents, which the copy already isolates.

      Type Parameters

      • N extends number

      Parameters

      • data: Uint8Array
      • length: N

      Returns FixedBytes<N>

      if data.length !== length.