MCPcopy Create free account
hub / github.com/WICG/webpackage / textOrByteStringDeterministic

Function textOrByteStringDeterministic

js/sign/src/cbor/deterministic.ts:107–123  ·  view source on GitHub ↗
(
  input: Uint8Array,
  index: number
)

Source from the content-addressed store, hash-verified

105// Returns length of the text or byte string element in bytes for which its
106// deterministicy has been ensured.
107function textOrByteStringDeterministic(
108 input: Uint8Array,
109 index: number
110): number {
111 // lengthInBytes is the length of the number representing the length of the
112 // text/byte string.
113 const { lengthInBytes, value } = unsignedIntegerDeterministic(input, index);
114 const totalLength = lengthInBytes + Number(value);
115
116 if (totalLength >= input.length - index) {
117 throw new Error(
118 "Text or byte string's length cannot exceed the number of bytes left on the input array."
119 );
120 }
121
122 return totalLength;
123}
124
125// Returns length of the CBOR array in bytes and checks that each item on it
126// follows the deterministic principles.

Callers 1

deterministicRecFunction · 0.70

Calls 1

Tested by

no test coverage detected