( bVecStorage: ForeignCallArray, maxLen: number, )
| 99 | * @returns a tuple representing a BoundedVec. |
| 100 | */ |
| 101 | export 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. |
no test coverage detected