Skip to content

Commit 17b1301

Browse files
committed
Rename back
1 parent 7fda75e commit 17b1301

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Point {
5656
this.pz = afield0(Z);
5757
frz(this);
5858
}
59-
static from(bytes: Bytes): Point {
59+
static fromBytes(bytes: Bytes): Point {
6060
au8(bytes);
6161
let p: Point | undefined = undefined;
6262
const head = bytes[0], tail = bytes.subarray(1); // first byte is prefix, rest is data
@@ -202,14 +202,14 @@ const inv = (num: bigint, md: bigint): bigint => { // modular inversion
202202
}
203203
return b === _1 ? M(x, md) : err('no inverse'); // b is gcd at this point
204204
};
205-
const normPriv = (pr: Bytes): bigint => { // normalize private key to bigint
205+
const toPriv = (pr: Bytes): bigint => { // normalize private key to bigint
206206
let num = b2n(au8(pr, L)); // convert to bigint when bytes
207207
return arange(num, _1, N, 'private key invalid 3'); // check if bigint is in range
208208
};
209209
const highS = (n: bigint): boolean => n > (N >> _1); // if a number is bigger than CURVE.n/2
210210
/** Creates 33/65-byte public key from 32-byte private key. */
211211
const getPublicKey = (privKey: Bytes, isCompressed = true): Bytes => {
212-
return G.mul(normPriv(privKey)).toBytes(isCompressed);
212+
return G.mul(toPriv(privKey)).toBytes(isCompressed);
213213
}
214214
/** ECDSA Signature class. Supports only compact 64-byte representation, not DER. */
215215
class Signature {
@@ -254,7 +254,7 @@ const prepSig = (msgh: Bytes, priv: Bytes, opts: OptS = optS): BC => {// prepare
254254
if (lowS == null) lowS = true; // RFC6979 3.2: we skip step A
255255
const h1i = bits2int_modN(msgh); // msg bigint
256256
const h1o = i2o(h1i); // msg octets
257-
const d = normPriv(priv); // validate private key, convert to bigint
257+
const d = toPriv(priv); // validate private key, convert to bigint
258258
const seed = [i2o(d), h1o]; // Step D of RFC6979 3.2
259259
// RFC6979 3.6: additional k' (optional)
260260
if (extraEntropy) { // K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1) || k')
@@ -381,7 +381,7 @@ const verify = (sig: Bytes, msgh: Bytes, pub: Bytes, opts: OptV = optV): boolean
381381
let { r, s } = new Signature(slc(sig, 0, L), slc(sig, L, L2)) // throw error when DER is suspected now.
382382
try {
383383
h = bits2int_modN(msgh); // Truncate hash
384-
P = Point.from(pub); // Validate public key
384+
P = Point.fromBytes(pub); // Validate public key
385385
} catch (e) { return false; } // Check sig for validity in both cases
386386
if (lowS && highS(s)) return false; // lowS bans sig.s >= CURVE.n/2
387387
let R: AffinePoint; // Actual verification code begins here
@@ -406,7 +406,7 @@ const recoverPublicKey = (point: SignatureWithRecovery, msgh: Bytes): Point => {
406406
const radj = rec === 2 || rec === 3 ? r + N : r; // If rec was 2 or 3, q.x is bigger than n
407407
afield(radj); // ensure q.x is still a field element
408408
const head = isEvenN(rec) ? '02' : '03'; // head is 0x02 or 0x03
409-
const R = Point.from(h2b(head + n2h(radj))); // concat head + hex repr of r
409+
const R = Point.fromBytes(h2b(head + n2h(radj))); // concat head + hex repr of r
410410
const ir = inv(radj, N); // r^-1
411411
const u1 = modN(-h * ir); // -hr^-1
412412
const u2 = modN(s * ir); // sr^-1
@@ -423,7 +423,7 @@ const recoverPublicKey = (point: SignatureWithRecovery, msgh: Bytes): Point => {
423423
* @returns public key C
424424
*/
425425
const getSharedSecret = (privA: Bytes, pubB: Bytes, isCompressed = true): Bytes => {
426-
return Point.from(pubB).mul(normPriv(privA)).toBytes(isCompressed); // ECDH
426+
return Point.fromBytes(pubB).mul(toPriv(privA)).toBytes(isCompressed); // ECDH
427427
};
428428
const randomBytes = (len = L): Bytes => { // CSPRNG (random number generator)
429429
const crypto = cr(); // Must be shimmed in node.js <= 18 to prevent error. See README.
@@ -461,7 +461,7 @@ const randomPrivateKey = (): Bytes => {
461461
}; // FIPS 186 B.4.1.
462462
/** Curve-specific utilities for private keys. */
463463
const utils = { // utilities
464-
isValidPrivateKey: (key: Bytes): boolean => { try { return !!normPriv(key); } catch (e) { return false; } },
464+
isValidPrivateKey: (key: Bytes): boolean => { try { return !!toPriv(key); } catch (e) { return false; } },
465465
randomPrivateKey: randomPrivateKey as () => Bytes,
466466
// precompute: (w=8, p: Point = G): Point => { p.multiply(3n); w; return p; }, // no-op
467467
};
@@ -529,7 +529,7 @@ const taggedHashAsync = async (tag: string, ...messages: Bytes[]): Promise<Bytes
529529
const pointToBytes = (point: Point): Uint8Array<ArrayBuffer> => point.toBytes(true).slice(1);
530530
// Calculate point, scalar and bytes
531531
const extpubSchnorr = (priv: Bytes) => {
532-
const d_ = normPriv(priv); // same method executed in fromPrivateKey
532+
const d_ = toPriv(priv); // same method executed in fromPrivateKey
533533
const p = G.mul(d_); // P = d'⋅G; 0 < d' < n check is done inside
534534
const d = isEvenB(p.aff().y) ? d_ : modN(-d_);
535535
const px = pointToBytes(p);

0 commit comments

Comments
 (0)