Skip to content

Instantly share code, notes, and snippets.

@shramee
Last active October 12, 2022 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shramee/5a2e32ccc30cec9f6f375670eeda5f00 to your computer and use it in GitHub Desktop.
Save shramee/5a2e32ccc30cec9f6f375670eeda5f00 to your computer and use it in GitHub Desktop.
Converts a string to felt, @uses BigInt
function asciiToFelt(str) {
if ( ! isNaN( str ) ) return '' + str;
var arr1 = [];
for (var n = 0, l = str.length; n < l; n++) {
const hex = Number(str.charCodeAt(n)).toString(16);
arr1.push(hex);
}
let hex = arr1.join("");
if ( hex %2 ) hex = '0' + hex;
return BigInt('0x' + hex).toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment