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

Function arrayDeterministic

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

Source from the content-addressed store, hash-verified

125// Returns length of the CBOR array in bytes and checks that each item on it
126// follows the deterministic principles.
127function arrayDeterministic(input: Uint8Array, index: number): number {
128 const { lengthInBytes, value } = unsignedIntegerDeterministic(input, index);
129
130 // Skip the starter byte and the bytes stating the number of elements the array has.
131 let startIndexOfNextElement = index + 1 + lengthInBytes;
132
133 for (let /*element on the array*/ i = 0; i < Number(value); i++) {
134 if (startIndexOfNextElement >= input.length) {
135 throw new Error(
136 'Number of items on CBOR array is less than the number of items it claims.'
137 );
138 }
139 startIndexOfNextElement += deterministicRec(input, startIndexOfNextElement);
140 }
141
142 return startIndexOfNextElement - index;
143}
144
145// Returns the length of the CBOR map in bytes and checks that each item on it
146// follows the deterministic principles. Additionally to ensure deterministicity

Callers 1

deterministicRecFunction · 0.70

Calls 2

deterministicRecFunction · 0.70

Tested by

no test coverage detected