MCPcopy Create free account
hub / github.com/AztecProtocol/aztec-packages / arrayToBoundedVec

Function arrayToBoundedVec

yarn-project/txe/src/util/encoding.ts:101–116  ·  view source on GitHub ↗
(
  bVecStorage: ForeignCallArray,
  maxLen: number,
)

Source from the content-addressed store, hash-verified

99 * @returns a tuple representing a BoundedVec.
100 */
101export function arrayToBoundedVec(
102 bVecStorage: ForeignCallArray,
103 maxLen: number,
104): [ForeignCallArray, ForeignCallSingle] {
105 if (bVecStorage.length > maxLen) {
106 throw new Error(`Array of length ${bVecStorage.length} larger than maxLen ${maxLen}`);
107 }
108 const lengthDiff = maxLen - bVecStorage.length;
109 // We pad the array to the maxLen of the BoundedVec.
110 const zeroPaddingArray = toArray(Array(lengthDiff).fill(new Fr(0)));
111
112 // These variable names match with the BoundedVec members in nr:
113 const storage = bVecStorage.concat(zeroPaddingArray);
114 const len = toSingle(new Fr(bVecStorage.length));
115 return [storage, len];
116}
117
118/**
119 * Converts an array of arrays representing Noir BoundedVec of nested arrays into its Noir serialized form.

Callers 2

Calls 4

toSingleFunction · 0.85
fillMethod · 0.80
toArrayFunction · 0.70
ArrayClass · 0.50

Tested by

no test coverage detected