-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: expose util func to convert field compressed string back to st…
- Loading branch information
Showing
5 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
yarn-project/aztec.js/src/utils/field_compressed_string.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Fr } from '@aztec/circuits.js'; | ||
|
||
/** | ||
* The representation of a FieldCompressedString in aztec.nr | ||
*/ | ||
interface NoirFieldCompressedString { | ||
/** | ||
* The field value of the string | ||
*/ | ||
value: bigint; | ||
} | ||
/** | ||
* This turns | ||
* @param field - The field that contains the string | ||
* @returns - the string that is decoded from the field | ||
*/ | ||
export const readFieldCompressedString = (field: NoirFieldCompressedString): string => { | ||
const vals: number[] = Array.from(new Fr(field.value).toBuffer()); | ||
|
||
let str = ''; | ||
for (let i = 0; i < vals.length; i++) { | ||
if (vals[i] != 0) { | ||
str += String.fromCharCode(Number(vals[i])); | ||
} | ||
} | ||
return str; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters