tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

noble-ed25519.js (20252B)


      1 /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
      2 /**
      3 * 4KB JS implementation of ed25519 EDDSA signatures compliant with RFC8032, FIPS 186-5 & ZIP215.
      4 * @module
      5 */
      6 const P = 2n ** 255n - 19n; // ed25519 is twisted edwards curve
      7 const N = 2n ** 252n + 27742317777372353535851937790883648493n; // curve's (group) order
      8 const Gx = 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an; // base point x
      9 const Gy = 0x6666666666666666666666666666666666666666666666666666666666666658n; // base point y
     10 const _d = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
     11 /**
     12 * ed25519 curve parameters. Equation is −x² + y² = -a + dx²y².
     13 * Gx and Gy are generator coordinates. p is field order, n is group order.
     14 * h is cofactor.
     15 */
     16 const CURVE = {
     17    a: -1n, // -1 mod p
     18    d: _d, // -(121665/121666) mod p
     19    p: P, n: N, h: 8, Gx: Gx, Gy: Gy // field prime, curve (group) order, cofactor
     20 };
     21 const err = (m = '') => { throw new Error(m); }; // error helper, messes-up stack trace
     22 const isS = (s) => typeof s === 'string'; // is string
     23 const isu8 = (a) => (a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array'));
     24 const au8 = (a, l) => // is Uint8Array (of specific length)
     25 !isu8(a) || (typeof l === 'number' && l > 0 && a.length !== l) ?
     26    err('Uint8Array of valid length expected') : a;
     27 const u8n = (data) => new Uint8Array(data); // creates Uint8Array
     28 const toU8 = (a, len) => au8(isS(a) ? h2b(a) : u8n(au8(a)), len); // norm(hex/u8a) to u8a
     29 const M = (a, b = P) => { let r = a % b; return r >= 0n ? r : b + r; }; // mod division
     30 const isPoint = (p) => (p instanceof Point ? p : err('Point expected')); // is xyzt point
     31 /** Point in xyzt extended coordinates. */
     32 class Point {
     33    constructor(ex, ey, ez, et) {
     34        this.ex = ex;
     35        this.ey = ey;
     36        this.ez = ez;
     37        this.et = et;
     38    }
     39    static fromAffine(p) { return new Point(p.x, p.y, 1n, M(p.x * p.y)); }
     40    /** RFC8032 5.1.3: hex / Uint8Array to Point. */
     41    static fromHex(hex, zip215 = false) {
     42        const { d } = CURVE;
     43        hex = toU8(hex, 32);
     44        const normed = hex.slice(); // copy the array to not mess it up
     45        const lastByte = hex[31];
     46        normed[31] = lastByte & ~0x80; // adjust first LE byte = last BE byte
     47        const y = b2n_LE(normed); // decode as little-endian, convert to num
     48        if (zip215 && !(0n <= y && y < 2n ** 256n))
     49            err('bad y coord 1'); // zip215=true  [1..2^256-1]
     50        if (!zip215 && !(0n <= y && y < P))
     51            err('bad y coord 2'); // zip215=false [1..P-1]
     52        const y2 = M(y * y); // y²
     53        const u = M(y2 - 1n); // u=y²-1
     54        const v = M(d * y2 + 1n); // v=dy²+1
     55        let { isValid, value: x } = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root
     56        if (!isValid)
     57            err('bad y coordinate 3'); // not square root: bad point
     58        const isXOdd = (x & 1n) === 1n; // adjust sign of x coordinate
     59        const isLastByteOdd = (lastByte & 0x80) !== 0; // x_0, last bit
     60        if (!zip215 && x === 0n && isLastByteOdd)
     61            err('bad y coord 3'); // x=0 and x_0 = 1
     62        if (isLastByteOdd !== isXOdd)
     63            x = M(-x);
     64        return new Point(x, y, 1n, M(x * y)); // Z=1, T=xy
     65    }
     66    get x() { return this.toAffine().x; } // .x, .y will call expensive toAffine.
     67    get y() { return this.toAffine().y; } // Should be used with care.
     68    equals(other) {
     69        const { ex: X1, ey: Y1, ez: Z1 } = this;
     70        const { ex: X2, ey: Y2, ez: Z2 } = isPoint(other); // isPoint() checks class equality
     71        const X1Z2 = M(X1 * Z2), X2Z1 = M(X2 * Z1);
     72        const Y1Z2 = M(Y1 * Z2), Y2Z1 = M(Y2 * Z1);
     73        return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
     74    }
     75    is0() { return this.equals(I); }
     76    negate() {
     77        return new Point(M(-this.ex), this.ey, this.ez, M(-this.et));
     78    }
     79    /** Point doubling. Complete formula. */
     80    double() {
     81        const { ex: X1, ey: Y1, ez: Z1 } = this; // Cost: 4M + 4S + 1*a + 6add + 1*2
     82        const { a } = CURVE; // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
     83        const A = M(X1 * X1);
     84        const B = M(Y1 * Y1);
     85        const C = M(2n * M(Z1 * Z1));
     86        const D = M(a * A);
     87        const x1y1 = X1 + Y1;
     88        const E = M(M(x1y1 * x1y1) - A - B);
     89        const G = D + B;
     90        const F = G - C;
     91        const H = D - B;
     92        const X3 = M(E * F);
     93        const Y3 = M(G * H);
     94        const T3 = M(E * H);
     95        const Z3 = M(F * G);
     96        return new Point(X3, Y3, Z3, T3);
     97    }
     98    /** Point addition. Complete formula. */
     99    add(other) {
    100        const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this; // Cost: 8M + 1*k + 8add + 1*2.
    101        const { ex: X2, ey: Y2, ez: Z2, et: T2 } = isPoint(other); // doesn't check if other on-curve
    102        const { a, d } = CURVE; // http://hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#addition-add-2008-hwcd-3
    103        const A = M(X1 * X2);
    104        const B = M(Y1 * Y2);
    105        const C = M(T1 * d * T2);
    106        const D = M(Z1 * Z2);
    107        const E = M((X1 + Y1) * (X2 + Y2) - A - B);
    108        const F = M(D - C);
    109        const G = M(D + C);
    110        const H = M(B - a * A);
    111        const X3 = M(E * F);
    112        const Y3 = M(G * H);
    113        const T3 = M(E * H);
    114        const Z3 = M(F * G);
    115        return new Point(X3, Y3, Z3, T3);
    116    }
    117    mul(n, safe = true) {
    118        if (n === 0n)
    119            return safe === true ? err('cannot multiply by 0') : I;
    120        if (!(typeof n === 'bigint' && 0n < n && n < N))
    121            err('invalid scalar, must be < L');
    122        if (!safe && this.is0() || n === 1n)
    123            return this; // safe=true bans 0. safe=false allows 0.
    124        if (this.equals(G))
    125            return wNAF(n).p; // use wNAF precomputes for base points
    126        let p = I, f = G; // init result point & fake point
    127        for (let d = this; n > 0n; d = d.double(), n >>= 1n) { // double-and-add ladder
    128            if (n & 1n)
    129                p = p.add(d); // if bit is present, add to point
    130            else if (safe)
    131                f = f.add(d); // if not, add to fake for timing safety
    132        }
    133        return p;
    134    }
    135    multiply(scalar) { return this.mul(scalar); } // Aliases for compatibilty
    136    clearCofactor() { return this.mul(BigInt(CURVE.h), false); } // multiply by cofactor
    137    isSmallOrder() { return this.clearCofactor().is0(); } // check if P is small order
    138    isTorsionFree() {
    139        let p = this.mul(N / 2n, false).double(); // ensures the point is not "bad".
    140        if (N % 2n)
    141            p = p.add(this); // P^(N+1)             // P*N == (P*(N/2))*2+P
    142        return p.is0();
    143    }
    144    /** converts point to 2d xy affine point. (x, y, z, t) ∋ (x=x/z, y=y/z, t=xy). */
    145    toAffine() {
    146        const { ex: x, ey: y, ez: z } = this;
    147        if (this.equals(I))
    148            return { x: 0n, y: 1n }; // fast-path for zero point
    149        const iz = invert(z, P); // z^-1: invert z
    150        if (M(z * iz) !== 1n)
    151            err('invalid inverse'); // (z * z^-1) must be 1, otherwise bad math
    152        return { x: M(x * iz), y: M(y * iz) }; // x = x*z^-1; y = y*z^-1
    153    }
    154    toRawBytes() {
    155        const { x, y } = this.toAffine(); // convert to affine 2d point
    156        const b = n2b_32LE(y); // encode number to 32 bytes
    157        b[31] |= x & 1n ? 0x80 : 0; // store sign in first LE byte
    158        return b;
    159    }
    160    toHex() { return b2h(this.toRawBytes()); } // encode to hex string
    161 }
    162 /** Generator / Base point */
    163 Point.BASE = new Point(Gx, Gy, 1n, M(Gx * Gy));
    164 /** Identity / Zero point */
    165 Point.ZERO = new Point(0n, 1n, 1n, 0n);
    166 const { BASE: G, ZERO: I } = Point; // Generator, identity points
    167 const padh = (num, pad) => num.toString(16).padStart(pad, '0');
    168 const b2h = (b) => Array.from(au8(b)).map(e => padh(e, 2)).join(''); // bytes to hex
    169 const C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }; // ASCII characters
    170 const _ch = (ch) => {
    171    if (ch >= C._0 && ch <= C._9)
    172        return ch - C._0; // '2' => 50-48
    173    if (ch >= C.A && ch <= C.F)
    174        return ch - (C.A - 10); // 'B' => 66-(65-10)
    175    if (ch >= C.a && ch <= C.f)
    176        return ch - (C.a - 10); // 'b' => 98-(97-10)
    177    return;
    178 };
    179 const h2b = (hex) => {
    180    const e = 'hex invalid';
    181    if (!isS(hex))
    182        return err(e);
    183    const hl = hex.length, al = hl / 2;
    184    if (hl % 2)
    185        return err(e);
    186    const array = u8n(al);
    187    for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) { // treat each char as ASCII
    188        const n1 = _ch(hex.charCodeAt(hi)); // parse first char, multiply it by 16
    189        const n2 = _ch(hex.charCodeAt(hi + 1)); // parse second char
    190        if (n1 === undefined || n2 === undefined)
    191            return err(e);
    192        array[ai] = n1 * 16 + n2; // example: 'A9' => 10*16 + 9
    193    }
    194    return array;
    195 };
    196 const n2b_32LE = (num) => h2b(padh(num, 32 * 2)).reverse(); // number to bytes LE
    197 const b2n_LE = (b) => BigInt('0x' + b2h(u8n(au8(b)).reverse())); // bytes LE to num
    198 const concatB = (...arrs) => {
    199    const r = u8n(arrs.reduce((sum, a) => sum + au8(a).length, 0)); // create u8a of summed length
    200    let pad = 0; // walk through each array,
    201    arrs.forEach(a => { r.set(a, pad); pad += a.length; }); // ensure they have proper type
    202    return r;
    203 };
    204 const invert = (num, md) => {
    205    if (num === 0n || md <= 0n)
    206        err('no inverse n=' + num + ' mod=' + md); // no neg exponent for now
    207    let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
    208    while (a !== 0n) { // uses euclidean gcd algorithm
    209        const q = b / a, r = b % a; // not constant-time
    210        const m = x - u * q, n = y - v * q;
    211        b = a, a = r, x = u, y = v, u = m, v = n;
    212    }
    213    return b === 1n ? M(x, md) : err('no inverse'); // b is gcd at this point
    214 };
    215 const pow2 = (x, power) => {
    216    let r = x;
    217    while (power-- > 0n) {
    218        r *= r;
    219        r %= P;
    220    }
    221    return r;
    222 };
    223 const pow_2_252_3 = (x) => {
    224    const x2 = (x * x) % P; // x^2,       bits 1
    225    const b2 = (x2 * x) % P; // x^3,       bits 11
    226    const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111
    227    const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111
    228    const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)
    229    const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)
    230    const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)
    231    const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)
    232    const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)
    233    const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)
    234    const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)
    235    const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.
    236    return { pow_p_5_8, b2 };
    237 };
    238 const RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n; // √-1
    239 const uvRatio = (u, v) => {
    240    const v3 = M(v * v * v); // v³
    241    const v7 = M(v3 * v3 * v); // v⁷
    242    const pow = pow_2_252_3(u * v7).pow_p_5_8; // (uv⁷)^(p-5)/8
    243    let x = M(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8
    244    const vx2 = M(v * x * x); // vx²
    245    const root1 = x; // First root candidate
    246    const root2 = M(x * RM1); // Second root candidate; RM1 is √-1
    247    const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root
    248    const useRoot2 = vx2 === M(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)
    249    const noRoot = vx2 === M(-u * RM1); // There is no valid root, vx² = -u√-1
    250    if (useRoot1)
    251        x = root1;
    252    if (useRoot2 || noRoot)
    253        x = root2; // We return root2 anyway, for const-time
    254    if ((M(x) & 1n) === 1n)
    255        x = M(-x); // edIsNegative
    256    return { isValid: useRoot1 || useRoot2, value: x };
    257 };
    258 const modL_LE = (hash) => M(b2n_LE(hash), N); // modulo L; but little-endian
    259 let _shaS;
    260 const sha512a = (...m) => etc.sha512Async(...m); // Async SHA512
    261 const sha512s = (...m) => // Sync SHA512, not set by default
    262 typeof _shaS === 'function' ? _shaS(...m) : err('etc.sha512Sync not set');
    263 const hash2extK = (hashed) => {
    264    const head = hashed.slice(0, 32); // slice creates a copy, unlike subarray
    265    head[0] &= 248; // Clamp bits: 0b1111_1000,
    266    head[31] &= 127; // 0b0111_1111,
    267    head[31] |= 64; // 0b0100_0000
    268    const prefix = hashed.slice(32, 64); // private key "prefix"
    269    const scalar = modL_LE(head); // modular division over curve order
    270    const point = G.mul(scalar); // public key point
    271    const pointBytes = point.toRawBytes(); // point serialized to Uint8Array
    272    return { head, prefix, scalar, point, pointBytes };
    273 };
    274 // RFC8032 5.1.5; getPublicKey async, sync. Hash priv key and extract point.
    275 const getExtendedPublicKeyAsync = (priv) => sha512a(toU8(priv, 32)).then(hash2extK);
    276 const getExtendedPublicKey = (priv) => hash2extK(sha512s(toU8(priv, 32)));
    277 /** Creates 32-byte ed25519 public key from 32-byte private key. Async. */
    278 const getPublicKeyAsync = (priv) => getExtendedPublicKeyAsync(priv).then(p => p.pointBytes);
    279 /** Creates 32-byte ed25519 public key from 32-byte private key. To use, set `etc.sha512Sync` first. */
    280 const getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
    281 function hashFinish(asynchronous, res) {
    282    if (asynchronous)
    283        return sha512a(res.hashable).then(res.finish);
    284    return res.finish(sha512s(res.hashable));
    285 }
    286 const _sign = (e, rBytes, msg) => {
    287    const { pointBytes: P, scalar: s } = e;
    288    const r = modL_LE(rBytes); // r was created outside, reduce it modulo L
    289    const R = G.mul(r).toRawBytes(); // R = [r]B
    290    const hashable = concatB(R, P, msg); // dom2(F, C) || R || A || PH(M)
    291    const finish = (hashed) => {
    292        const S = M(r + modL_LE(hashed) * s, N); // S = (r + k * s) mod L; 0 <= s < l
    293        return au8(concatB(R, n2b_32LE(S)), 64); // 64-byte sig: 32b R.x + 32b LE(S)
    294    };
    295    return { hashable, finish };
    296 };
    297 /** Signs message (NOT message hash) using private key. Async. */
    298 const signAsync = async (msg, privKey) => {
    299    const m = toU8(msg); // RFC8032 5.1.6: sign msg with key async
    300    const e = await getExtendedPublicKeyAsync(privKey); // pub,prfx
    301    const rBytes = await sha512a(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
    302    return hashFinish(true, _sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
    303 };
    304 /** Signs message (NOT message hash) using private key. To use, set `etc.sha512Sync` first. */
    305 const sign = (msg, privKey) => {
    306    const m = toU8(msg); // RFC8032 5.1.6: sign msg with key sync
    307    const e = getExtendedPublicKey(privKey); // pub,prfx
    308    const rBytes = sha512s(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
    309    return hashFinish(false, _sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
    310 };
    311 const dvo = { zip215: true };
    312 const _verify = (sig, msg, pub, opts = dvo) => {
    313    sig = toU8(sig, 64); // Signature hex str/Bytes, must be 64 bytes
    314    msg = toU8(msg); // Message hex str/Bytes
    315    pub = toU8(pub, 32);
    316    const { zip215 } = opts; // switch between zip215 and rfc8032 verif
    317    let A, R, s, SB, hashable = new Uint8Array();
    318    try {
    319        A = Point.fromHex(pub, zip215); // public key A decoded
    320        R = Point.fromHex(sig.slice(0, 32), zip215); // 0 <= R < 2^256: ZIP215 R can be >= P
    321        s = b2n_LE(sig.slice(32, 64)); // Decode second half as an integer S
    322        SB = G.mul(s, false); // in the range 0 <= s < L
    323        hashable = concatB(R.toRawBytes(), A.toRawBytes(), msg); // dom2(F, C) || R || A || PH(M)
    324    }
    325    catch (error) { }
    326    const finish = (hashed) => {
    327        if (SB == null)
    328            return false; // false if try-catch catched an error
    329        if (!zip215 && A.isSmallOrder())
    330            return false; // false for SBS: Strongly Binding Signature
    331        const k = modL_LE(hashed); // decode in little-endian, modulo L
    332        const RkA = R.add(A.mul(k, false)); // [8]R + [8][k]A'
    333        return RkA.add(SB.negate()).clearCofactor().is0(); // [8][S]B = [8]R + [8][k]A'
    334    };
    335    return { hashable, finish };
    336 };
    337 // RFC8032 5.1.7: verification async, sync
    338 /** Verifies signature on message and public key. Async. */
    339 const verifyAsync = async (s, m, p, opts = dvo) => hashFinish(true, _verify(s, m, p, opts));
    340 /** Verifies signature on message and public key. To use, set `etc.sha512Sync` first. */
    341 const verify = (s, m, p, opts = dvo) => hashFinish(false, _verify(s, m, p, opts));
    342 const cr = () => // We support: 1) browsers 2) node.js 19+
    343 typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
    344 /** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
    345 const etc = {
    346    bytesToHex: b2h,
    347    hexToBytes: h2b,
    348    concatBytes: concatB,
    349    mod: M,
    350    invert: invert,
    351    randomBytes: (len = 32) => {
    352        const c = cr(); // Can be shimmed in node.js <= 18 to prevent error:
    353        // import { webcrypto } from 'node:crypto';
    354        // if (!globalThis.crypto) globalThis.crypto = webcrypto;
    355        if (!c || !c.getRandomValues)
    356            err('crypto.getRandomValues must be defined');
    357        return c.getRandomValues(u8n(len));
    358    },
    359    sha512Async: async (...messages) => {
    360        const c = cr();
    361        const s = c && c.subtle;
    362        if (!s)
    363            err('etc.sha512Async or crypto.subtle must be defined');
    364        const m = concatB(...messages);
    365        return u8n(await s.digest('SHA-512', m.buffer));
    366    },
    367    sha512Sync: undefined, // Actual logic below
    368 };
    369 Object.defineProperties(etc, { sha512Sync: {
    370        configurable: false, get() { return _shaS; }, set(f) { if (!_shaS)
    371            _shaS = f; },
    372    } });
    373 /** ed25519-specific key utilities. */
    374 const utils = {
    375    getExtendedPublicKeyAsync: getExtendedPublicKeyAsync,
    376    getExtendedPublicKey: getExtendedPublicKey,
    377    randomPrivateKey: () => etc.randomBytes(32),
    378    precompute: (w = 8, p = G) => { p.multiply(3n); w; return p; }, // no-op
    379 };
    380 const W = 8; // Precomputes-related code. W = window size
    381 const precompute = () => {
    382    const points = []; // 10x sign(), 2x verify(). To achieve this,
    383    const windows = 256 / W + 1; // app needs to spend 40ms+ to calculate
    384    let p = G, b = p; // a lot of points related to base point G.
    385    for (let w = 0; w < windows; w++) { // Points are stored in array and used
    386        b = p; // any time Gx multiplication is done.
    387        points.push(b); // They consume 16-32 MiB of RAM.
    388        for (let i = 1; i < 2 ** (W - 1); i++) {
    389            b = b.add(p);
    390            points.push(b);
    391        }
    392        p = b.double(); // Precomputes don't speed-up getSharedKey,
    393    } // which multiplies user point by scalar,
    394    return points; // when precomputes are using base point
    395 };
    396 let Gpows = undefined; // precomputes for base point G
    397 const wNAF = (n) => {
    398    // Compared to other point mult methods,
    399    const comp = Gpows || (Gpows = precompute()); // stores 2x less points using subtraction
    400    const neg = (cnd, p) => { let n = p.negate(); return cnd ? n : p; }; // negate
    401    let p = I, f = G; // f must be G, or could become I in the end
    402    const windows = 1 + 256 / W; // W=8 17 windows
    403    const wsize = 2 ** (W - 1); // W=8 128 window size
    404    const mask = BigInt(2 ** W - 1); // W=8 will create mask 0b11111111
    405    const maxNum = 2 ** W; // W=8 256
    406    const shiftBy = BigInt(W); // W=8 8
    407    for (let w = 0; w < windows; w++) {
    408        const off = w * wsize;
    409        let wbits = Number(n & mask); // extract W bits.
    410        n >>= shiftBy; // shift number by W bits.
    411        if (wbits > wsize) {
    412            wbits -= maxNum;
    413            n += 1n;
    414        } // split if bits > max: +224 => 256-32
    415        const off1 = off, off2 = off + Math.abs(wbits) - 1; // offsets, evaluate both
    416        const cnd1 = w % 2 !== 0, cnd2 = wbits < 0; // conditions, evaluate both
    417        if (wbits === 0) {
    418            f = f.add(neg(cnd1, comp[off1])); // bits are 0: add garbage to fake point
    419        }
    420        else { //          ^ can't add off2, off2 = I
    421            p = p.add(neg(cnd2, comp[off2])); // bits are 1: add to result point
    422        }
    423    }
    424    return { p, f }; // return both real and fake points for JIT
    425 }; // !! you can disable precomputes by commenting-out call of the wNAF() inside Point#mul()
    426 export { getPublicKey, getPublicKeyAsync, sign, verify, // Remove the export to easily use in REPL
    427 signAsync, verifyAsync, CURVE, etc, utils, Point as ExtendedPoint }; // envs like browser console