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

Function unsignedIntegerDeterministic

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

Source from the content-addressed store, hash-verified

53// the right amount of bytes is used in the CBOR encoding. It returns both,
54// the length of the bytes array and the value of the unsigned integer.
55function unsignedIntegerDeterministic(
56 input: Uint8Array,
57 index: number
58): { lengthInBytes: number; value: bigint } {
59 const info = convertToAdditionalInfo(input[index]);
60 const lengthInBytes = getAdditionalInfoLength(info);
61 const value = getUnsignedIntegerValue(
62 input.slice(index, index + lengthInBytes + /*add info byte*/ 1),
63 info
64 );
65
66 if (value < getAdditionalInfoValueLowerLimit(info)) {
67 throw new Error(
68 `${value} should not be represented with ${lengthInBytes} bytes in deterministic CBOR.`
69 );
70 }
71
72 return { lengthInBytes, value };
73}
74
75export function getUnsignedIntegerValue(
76 input: Uint8Array,

Callers 4

deterministicRecFunction · 0.70
arrayDeterministicFunction · 0.70
mapDeterministicFunction · 0.70

Calls 4

convertToAdditionalInfoFunction · 0.90
getAdditionalInfoLengthFunction · 0.90
getUnsignedIntegerValueFunction · 0.70

Tested by

no test coverage detected