Skip to content

Commit 779da13

Browse files
authored
Update starkCurve.ts
1 parent b81173b commit 779da13

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils/ec/starkCurve.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { BigNumberish } from '../../types';
99
// Stark curve params (copied from Starknet.js)
1010
const CURVE_P = BigInt('0x800000000000011000000000000000000000000000000000000000000000001');
1111
const CURVE_A = BigInt(1);
12-
//const CURVE_B = BigInt('3141592653589793238462643383279502884197169399375105820974944592307816406665');
12+
13+
// const CURVE_B = BigInt('3141592653589793238462643383279502884197169399375105820974944592307816406665');
1314
const CURVE_Gx = BigInt('874739451078007766457464989774322083649278607533249481151382481072868806602');
1415
const CURVE_Gy = BigInt('152666792071518830868575557812948353041420400780739481342941381225525861407');
1516
const CURVE_N = BigInt('3618502788666131213697322783095070105526743751716087489154079457884512865583');
@@ -51,7 +52,7 @@ function pointAdd(x1: bigint, y1: bigint, x2: bigint, y2: bigint): [bigint, bigi
5152
}
5253

5354
function modInv(a: bigint, m: bigint): bigint {
54-
let [g, x] = egcd(a, m);
55+
const [g, x] = egcd(a, m);
5556
if (g !== 1n) throw new Error('modInv: no inverse');
5657
return mod(x, m);
5758
}
@@ -64,7 +65,7 @@ function egcd(a: bigint, b: bigint): [bigint, bigint] {
6465

6566
function scalarMultBase(scalar: bigint): [bigint, bigint] {
6667
// Simple double-and-add for G
67-
let x = CURVE_Gx, y = CURVE_Gy;
68+
const x = CURVE_Gx, y = CURVE_Gy;
6869
let resX = 0n, resY = 0n;
6970
let started = false;
7071
for (let i = 251; i >= 0; i--) {
@@ -120,7 +121,7 @@ function getStarkKey(privateKey: BigNumberish): string {
120121
else priv = BigInt('0x' + privateKey.toString().replace(/^0x/i, ''));
121122
priv = mod(priv, CURVE_N);
122123
if (priv === 0n) throw new Error('Invalid private key');
123-
const [pubX, _pubY] = scalarMultBase(priv);
124+
const [pubX] = scalarMultBase(priv);
124125
// Return as 0x-prefixed hex string
125126
const pubXHex = pubX.toString(16).padStart(64, '0');
126127
return '0x' + pubXHex;

0 commit comments

Comments
 (0)