Created
July 9, 2024 03:51
-
-
Save sc0Vu/467d6b89cfab4fdb6122fc7657e4bf9f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// NOTE: it's experimental. | |
// https://gist.github.com/sc0Vu/09e7f1838785825de800cd3422e4511a | |
// https://github.com/paulmillr/scure-starknet/blob/main/index.ts | |
const PEDERSEN_POINTS = [ | |
new ProjectivePoint(2089986280348253421170679821480865132823066470938446095505822317253594081284n, 1713931329540660377023406109199410414810705867260802078187082345529207694986n, 1n), | |
new ProjectivePoint(996781205833008774514500082376783249102396023663454813447423147977397232763n, 1668503676786377725805489344771023921079126552019160156920634619255970485781n, 1n), | |
new ProjectivePoint(2251563274489750535117886426533222435294046428347329203627021249169616184184n, 1798716007562728905295480679789526322175868328062420237419143593021674992973n, 1n), | |
new ProjectivePoint(2138414695194151160943305727036575959195309218611738193261179310511854807447n, 113410276730064486255102093846540133784865286929052426931474106396135072156n, 1n), | |
new ProjectivePoint(2379962749567351885752724891227938183011949129833673362440656643086021394946n, 776496453633298175483985398648758586525933812536653089401905292063708816422n, 1n), | |
]; | |
function pedersenSingle(value, p1, p2) { | |
let x = pedersenArg(value); | |
if ( | |
x < 0 || | |
x >= BigInt(3618502788666131213697322783095070105623107215331596699973092056135872020481) | |
) throw new Error('invalid value'); | |
const highNibble = x >> 248n; | |
const lowPart = x & (2n ** 248n - 1n); | |
return p1.multiplyUnsafe(lowPart).add(p2.multiplyUnsafe(highNibble)); | |
} | |
// shift_point + x_low * P_0 + x_high * P1 + y_low * P2 + y_high * P3 | |
export function pedersen(x, y) { | |
let point = PEDERSEN_POINTS[0]; | |
point = point.add(pedersenSingle(x, PEDERSEN_POINTS[1], PEDERSEN_POINTS[2])) | |
point = point.add(pedersenSingle(y, PEDERSEN_POINTS[3], PEDERSEN_POINTS[4])) | |
return extractX(point.toRawBytes(true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment