WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Minimal `EventEmitter` interface that is molded against the Node.js
|
||||
* `EventEmitter` interface.
|
||||
*/
|
||||
declare class EventEmitter<
|
||||
EventTypes extends EventEmitter.ValidEventTypes = string | symbol,
|
||||
Context extends any = any
|
||||
> {
|
||||
static prefixed: string | boolean;
|
||||
|
||||
/**
|
||||
* Return an array listing the events for which the emitter has registered
|
||||
* listeners.
|
||||
*/
|
||||
eventNames(): Array<EventEmitter.EventNames<EventTypes>>;
|
||||
|
||||
/**
|
||||
* Return the listeners registered for a given event.
|
||||
*/
|
||||
listeners<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T
|
||||
): Array<EventEmitter.EventListener<EventTypes, T>>;
|
||||
|
||||
/**
|
||||
* Return the number of listeners listening to a given event.
|
||||
*/
|
||||
listenerCount(event: EventEmitter.EventNames<EventTypes>): number;
|
||||
|
||||
/**
|
||||
* Calls each of the listeners registered for a given event.
|
||||
*/
|
||||
emit<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
...args: EventEmitter.EventArgs<EventTypes, T>
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Add a listener for a given event.
|
||||
*/
|
||||
on<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
fn: EventEmitter.EventListener<EventTypes, T>,
|
||||
context?: Context
|
||||
): this;
|
||||
addListener<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
fn: EventEmitter.EventListener<EventTypes, T>,
|
||||
context?: Context
|
||||
): this;
|
||||
|
||||
/**
|
||||
* Add a one-time listener for a given event.
|
||||
*/
|
||||
once<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
fn: EventEmitter.EventListener<EventTypes, T>,
|
||||
context?: Context
|
||||
): this;
|
||||
|
||||
/**
|
||||
* Remove the listeners of a given event.
|
||||
*/
|
||||
removeListener<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
fn?: EventEmitter.EventListener<EventTypes, T>,
|
||||
context?: Context,
|
||||
once?: boolean
|
||||
): this;
|
||||
off<T extends EventEmitter.EventNames<EventTypes>>(
|
||||
event: T,
|
||||
fn?: EventEmitter.EventListener<EventTypes, T>,
|
||||
context?: Context,
|
||||
once?: boolean
|
||||
): this;
|
||||
|
||||
/**
|
||||
* Remove all listeners, or those of the specified event.
|
||||
*/
|
||||
removeAllListeners(event?: EventEmitter.EventNames<EventTypes>): this;
|
||||
}
|
||||
|
||||
declare namespace EventEmitter {
|
||||
export interface ListenerFn<Args extends any[] = any[]> {
|
||||
(...args: Args): void;
|
||||
}
|
||||
|
||||
export interface EventEmitterStatic {
|
||||
new <
|
||||
EventTypes extends ValidEventTypes = string | symbol,
|
||||
Context = any
|
||||
>(): EventEmitter<EventTypes, Context>;
|
||||
}
|
||||
|
||||
/**
|
||||
* `object` should be in either of the following forms:
|
||||
* ```
|
||||
* interface EventTypes {
|
||||
* 'event-with-parameters': any[]
|
||||
* 'event-with-example-handler': (...args: any[]) => void
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export type ValidEventTypes = string | symbol | object;
|
||||
|
||||
export type EventNames<T extends ValidEventTypes> = T extends string | symbol
|
||||
? T
|
||||
: keyof T;
|
||||
|
||||
export type ArgumentMap<T extends object> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => void
|
||||
? Parameters<T[K]>
|
||||
: T[K] extends any[]
|
||||
? T[K]
|
||||
: any[];
|
||||
};
|
||||
|
||||
export type EventListener<
|
||||
T extends ValidEventTypes,
|
||||
K extends EventNames<T>
|
||||
> = T extends string | symbol
|
||||
? (...args: any[]) => void
|
||||
: (
|
||||
...args: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>]
|
||||
) => void;
|
||||
|
||||
export type EventArgs<
|
||||
T extends ValidEventTypes,
|
||||
K extends EventNames<T>
|
||||
> = Parameters<EventListener<T, K>>;
|
||||
|
||||
export const EventEmitter: EventEmitterStatic;
|
||||
}
|
||||
|
||||
export { EventEmitter }
|
||||
export default EventEmitter;
|
||||
@@ -0,0 +1,77 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2018.asynciterable" />
|
||||
|
||||
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
|
||||
return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
|
||||
throw(e: any): Promise<IteratorResult<T, TReturn>>;
|
||||
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
interface AsyncGeneratorFunction {
|
||||
/**
|
||||
* Creates a new AsyncGenerator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: any[]): AsyncGenerator;
|
||||
/**
|
||||
* Creates a new AsyncGenerator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: any[]): AsyncGenerator;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: AsyncGenerator;
|
||||
}
|
||||
|
||||
interface AsyncGeneratorFunctionConstructor {
|
||||
/**
|
||||
* Creates a new AsyncGenerator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: string[]): AsyncGeneratorFunction;
|
||||
/**
|
||||
* Creates a new AsyncGenerator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: string[]): AsyncGeneratorFunction;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: AsyncGeneratorFunction;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const pico = require('./lib/picomatch');
|
||||
const utils = require('./lib/utils');
|
||||
|
||||
function picomatch(glob, options, returnState = false) {
|
||||
// default to os.platform()
|
||||
if (options && (options.windows === null || options.windows === undefined)) {
|
||||
// don't mutate the original options object
|
||||
options = { ...options, windows: utils.isWindows() };
|
||||
}
|
||||
|
||||
return pico(glob, options, returnState);
|
||||
}
|
||||
|
||||
Object.assign(picomatch, pico);
|
||||
module.exports = picomatch;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* This package contains codecs for numbers of different sizes and endianness.
|
||||
* It can be used standalone, but it is also exported as part of Kit
|
||||
* [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).
|
||||
*
|
||||
* This package is also part of the [`@solana/codecs` package](https://github.com/anza-xyz/kit/tree/main/packages/codecs)
|
||||
* which acts as an entry point for all codec packages as well as for their documentation.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
export * from './assertions';
|
||||
export * from './common';
|
||||
export * from './f32';
|
||||
export * from './f64';
|
||||
export * from './i128';
|
||||
export * from './i16';
|
||||
export * from './i32';
|
||||
export * from './i64';
|
||||
export * from './i8';
|
||||
export * from './short-u16';
|
||||
export * from './u128';
|
||||
export * from './u16';
|
||||
export * from './u32';
|
||||
export * from './u64';
|
||||
export * from './u8';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
@@ -0,0 +1,552 @@
|
||||
/**
|
||||
* Edwards448 (not Ed448-Goldilocks) curve with following addons:
|
||||
* - X448 ECDH
|
||||
* - Decaf cofactor elimination
|
||||
* - Elligator hash-to-group / point indistinguishability
|
||||
* Conforms to RFC 8032 https://www.rfc-editor.org/rfc/rfc8032.html#section-5.2
|
||||
* @module
|
||||
*/
|
||||
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
||||
import { shake256 } from '@noble/hashes/sha3.js';
|
||||
import { abytes, concatBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
|
||||
import type { AffinePoint } from './abstract/curve.ts';
|
||||
import { pippenger } from './abstract/curve.ts';
|
||||
import {
|
||||
edwards,
|
||||
PrimeEdwardsPoint,
|
||||
twistedEdwards,
|
||||
type CurveFn,
|
||||
type EdwardsOpts,
|
||||
type EdwardsPoint,
|
||||
type EdwardsPointCons,
|
||||
} from './abstract/edwards.ts';
|
||||
import {
|
||||
_DST_scalar,
|
||||
createHasher,
|
||||
expand_message_xof,
|
||||
type H2CHasher,
|
||||
type H2CHasherBase,
|
||||
type H2CMethod,
|
||||
type htfBasicOpts,
|
||||
} from './abstract/hash-to-curve.ts';
|
||||
import { Field, FpInvertBatch, isNegativeLE, mod, pow2, type IField } from './abstract/modular.ts';
|
||||
import { montgomery, type MontgomeryECDH as XCurveFn } from './abstract/montgomery.ts';
|
||||
import { asciiToBytes, bytesToNumberLE, ensureBytes, equalBytes, type Hex } from './utils.ts';
|
||||
|
||||
// edwards448 curve
|
||||
// a = 1n
|
||||
// d = Fp.neg(39081n)
|
||||
// Finite field 2n**448n - 2n**224n - 1n
|
||||
// Subgroup order
|
||||
// 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
|
||||
const ed448_CURVE: EdwardsOpts = {
|
||||
p: BigInt(
|
||||
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
||||
),
|
||||
n: BigInt(
|
||||
'0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'
|
||||
),
|
||||
h: BigInt(4),
|
||||
a: BigInt(1),
|
||||
d: BigInt(
|
||||
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffff6756'
|
||||
),
|
||||
Gx: BigInt(
|
||||
'0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'
|
||||
),
|
||||
Gy: BigInt(
|
||||
'0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'
|
||||
),
|
||||
};
|
||||
|
||||
// E448 NIST curve is identical to edwards448, except for:
|
||||
// d = 39082/39081
|
||||
// Gx = 3/2
|
||||
const E448_CURVE: EdwardsOpts = Object.assign({}, ed448_CURVE, {
|
||||
d: BigInt(
|
||||
'0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'
|
||||
),
|
||||
Gx: BigInt(
|
||||
'0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'
|
||||
),
|
||||
Gy: BigInt(
|
||||
'0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'
|
||||
),
|
||||
});
|
||||
|
||||
const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
|
||||
const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
|
||||
|
||||
// prettier-ignore
|
||||
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
|
||||
// prettier-ignore
|
||||
const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
|
||||
|
||||
// powPminus3div4 calculates z = x^k mod p, where k = (p-3)/4.
|
||||
// Used for efficient square root calculation.
|
||||
// ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
|
||||
function ed448_pow_Pminus3div4(x: bigint): bigint {
|
||||
const P = ed448_CURVE.p;
|
||||
const b2 = (x * x * x) % P;
|
||||
const b3 = (b2 * b2 * x) % P;
|
||||
const b6 = (pow2(b3, _3n, P) * b3) % P;
|
||||
const b9 = (pow2(b6, _3n, P) * b3) % P;
|
||||
const b11 = (pow2(b9, _2n, P) * b2) % P;
|
||||
const b22 = (pow2(b11, _11n, P) * b11) % P;
|
||||
const b44 = (pow2(b22, _22n, P) * b22) % P;
|
||||
const b88 = (pow2(b44, _44n, P) * b44) % P;
|
||||
const b176 = (pow2(b88, _88n, P) * b88) % P;
|
||||
const b220 = (pow2(b176, _44n, P) * b44) % P;
|
||||
const b222 = (pow2(b220, _2n, P) * b2) % P;
|
||||
const b223 = (pow2(b222, _1n, P) * x) % P;
|
||||
return (pow2(b223, _223n, P) * b222) % P;
|
||||
}
|
||||
|
||||
function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
|
||||
// Section 5: Likewise, for X448, set the two least significant bits of the first byte to 0,
|
||||
bytes[0] &= 252; // 0b11111100
|
||||
// and the most significant bit of the last byte to 1.
|
||||
bytes[55] |= 128; // 0b10000000
|
||||
// NOTE: is NOOP for 56 bytes scalars (X25519/X448)
|
||||
bytes[56] = 0; // Byte outside of group (456 buts vs 448 bits)
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
|
||||
// Uses algo from RFC8032 5.1.3.
|
||||
function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
|
||||
const P = ed448_CURVE.p;
|
||||
// https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
|
||||
// To compute the square root of (u/v), the first step is to compute the
|
||||
// candidate root x = (u/v)^((p+1)/4). This can be done using the
|
||||
// following trick, to use a single modular powering for both the
|
||||
// inversion of v and the square root:
|
||||
// x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
|
||||
const u2v = mod(u * u * v, P); // u²v
|
||||
const u3v = mod(u2v * u, P); // u³v
|
||||
const u5v3 = mod(u3v * u2v * v, P); // u⁵v³
|
||||
const root = ed448_pow_Pminus3div4(u5v3);
|
||||
const x = mod(u3v * root, P);
|
||||
// Verify that root is exists
|
||||
const x2 = mod(x * x, P); // x²
|
||||
// If vx² = u, the recovered x-coordinate is x. Otherwise, no
|
||||
// square root exists, and the decoding fails.
|
||||
return { isValid: mod(x2 * v, P) === u, value: x };
|
||||
}
|
||||
|
||||
// Finite field 2n**448n - 2n**224n - 1n
|
||||
// The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
|
||||
// - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
|
||||
// - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
|
||||
const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE.p, { BITS: 456, isLE: true }))();
|
||||
const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
|
||||
// decaf448 uses 448-bit (56-byte) keys
|
||||
const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE.p, { BITS: 448, isLE: true }))();
|
||||
const Fn448 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
|
||||
|
||||
// SHAKE256(dom4(phflag,context)||x, 114)
|
||||
function dom4(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
||||
if (ctx.length > 255) throw new Error('context must be smaller than 255, got: ' + ctx.length);
|
||||
return concatBytes(
|
||||
asciiToBytes('SigEd448'),
|
||||
new Uint8Array([phflag ? 1 : 0, ctx.length]),
|
||||
ctx,
|
||||
data
|
||||
);
|
||||
}
|
||||
// const ed448_eddsa_opts = { adjustScalarBytes, domain: dom4 };
|
||||
// const ed448_Point = edwards(ed448_CURVE, { Fp, Fn, uvRatio });
|
||||
|
||||
const ED448_DEF = /* @__PURE__ */ (() => ({
|
||||
...ed448_CURVE,
|
||||
Fp,
|
||||
Fn,
|
||||
nBitLength: Fn.BITS,
|
||||
hash: shake256_114,
|
||||
adjustScalarBytes,
|
||||
domain: dom4,
|
||||
uvRatio,
|
||||
}))();
|
||||
|
||||
/**
|
||||
* ed448 EdDSA curve and methods.
|
||||
* @example
|
||||
* import { ed448 } from '@noble/curves/ed448';
|
||||
* const { secretKey, publicKey } = ed448.keygen();
|
||||
* const msg = new TextEncoder().encode('hello');
|
||||
* const sig = ed448.sign(msg, secretKey);
|
||||
* const isValid = ed448.verify(sig, msg, publicKey);
|
||||
*/
|
||||
export const ed448: CurveFn = twistedEdwards(ED448_DEF);
|
||||
|
||||
// There is no ed448ctx, since ed448 supports ctx by default
|
||||
/** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
|
||||
export const ed448ph: CurveFn = /* @__PURE__ */ (() =>
|
||||
twistedEdwards({
|
||||
...ED448_DEF,
|
||||
prehash: shake256_64,
|
||||
}))();
|
||||
|
||||
/**
|
||||
* E448 curve, defined by NIST.
|
||||
* E448 != edwards448 used in ed448.
|
||||
* E448 is birationally equivalent to edwards448.
|
||||
*/
|
||||
export const E448: EdwardsPointCons = edwards(E448_CURVE);
|
||||
|
||||
/**
|
||||
* ECDH using curve448 aka x448.
|
||||
* x448 has 56-byte keys as per RFC 7748, while
|
||||
* ed448 has 57-byte keys as per RFC 8032.
|
||||
*/
|
||||
export const x448: XCurveFn = /* @__PURE__ */ (() => {
|
||||
const P = ed448_CURVE.p;
|
||||
return montgomery({
|
||||
P,
|
||||
type: 'x448',
|
||||
powPminus2: (x: bigint): bigint => {
|
||||
const Pminus3div4 = ed448_pow_Pminus3div4(x);
|
||||
const Pminus3 = pow2(Pminus3div4, _2n, P);
|
||||
return mod(Pminus3 * x, P); // Pminus3 * x = Pminus2
|
||||
},
|
||||
adjustScalarBytes,
|
||||
});
|
||||
})();
|
||||
|
||||
// Hash To Curve Elligator2 Map
|
||||
const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
|
||||
const ELL2_J = /* @__PURE__ */ BigInt(156326);
|
||||
|
||||
function map_to_curve_elligator2_curve448(u: bigint) {
|
||||
let tv1 = Fp.sqr(u); // 1. tv1 = u^2
|
||||
let e1 = Fp.eql(tv1, Fp.ONE); // 2. e1 = tv1 == 1
|
||||
tv1 = Fp.cmov(tv1, Fp.ZERO, e1); // 3. tv1 = CMOV(tv1, 0, e1) # If Z * u^2 == -1, set tv1 = 0
|
||||
let xd = Fp.sub(Fp.ONE, tv1); // 4. xd = 1 - tv1
|
||||
let x1n = Fp.neg(ELL2_J); // 5. x1n = -J
|
||||
let tv2 = Fp.sqr(xd); // 6. tv2 = xd^2
|
||||
let gxd = Fp.mul(tv2, xd); // 7. gxd = tv2 * xd # gxd = xd^3
|
||||
let gx1 = Fp.mul(tv1, Fp.neg(ELL2_J)); // 8. gx1 = -J * tv1 # x1n + J * xd
|
||||
gx1 = Fp.mul(gx1, x1n); // 9. gx1 = gx1 * x1n # x1n^2 + J * x1n * xd
|
||||
gx1 = Fp.add(gx1, tv2); // 10. gx1 = gx1 + tv2 # x1n^2 + J * x1n * xd + xd^2
|
||||
gx1 = Fp.mul(gx1, x1n); // 11. gx1 = gx1 * x1n # x1n^3 + J * x1n^2 * xd + x1n * xd^2
|
||||
let tv3 = Fp.sqr(gxd); // 12. tv3 = gxd^2
|
||||
tv2 = Fp.mul(gx1, gxd); // 13. tv2 = gx1 * gxd # gx1 * gxd
|
||||
tv3 = Fp.mul(tv3, tv2); // 14. tv3 = tv3 * tv2 # gx1 * gxd^3
|
||||
let y1 = Fp.pow(tv3, ELL2_C1); // 15. y1 = tv3^c1 # (gx1 * gxd^3)^((p - 3) / 4)
|
||||
y1 = Fp.mul(y1, tv2); // 16. y1 = y1 * tv2 # gx1 * gxd * (gx1 * gxd^3)^((p - 3) / 4)
|
||||
let x2n = Fp.mul(x1n, Fp.neg(tv1)); // 17. x2n = -tv1 * x1n # x2 = x2n / xd = -1 * u^2 * x1n / xd
|
||||
let y2 = Fp.mul(y1, u); // 18. y2 = y1 * u
|
||||
y2 = Fp.cmov(y2, Fp.ZERO, e1); // 19. y2 = CMOV(y2, 0, e1)
|
||||
tv2 = Fp.sqr(y1); // 20. tv2 = y1^2
|
||||
tv2 = Fp.mul(tv2, gxd); // 21. tv2 = tv2 * gxd
|
||||
let e2 = Fp.eql(tv2, gx1); // 22. e2 = tv2 == gx1
|
||||
let xn = Fp.cmov(x2n, x1n, e2); // 23. xn = CMOV(x2n, x1n, e2) # If e2, x = x1, else x = x2
|
||||
let y = Fp.cmov(y2, y1, e2); // 24. y = CMOV(y2, y1, e2) # If e2, y = y1, else y = y2
|
||||
let e3 = Fp.isOdd(y); // 25. e3 = sgn0(y) == 1 # Fix sign of y
|
||||
y = Fp.cmov(y, Fp.neg(y), e2 !== e3); // 26. y = CMOV(y, -y, e2 XOR e3)
|
||||
return { xn, xd, yn: y, yd: Fp.ONE }; // 27. return (xn, xd, y, 1)
|
||||
}
|
||||
|
||||
function map_to_curve_elligator2_edwards448(u: bigint) {
|
||||
let { xn, xd, yn, yd } = map_to_curve_elligator2_curve448(u); // 1. (xn, xd, yn, yd) = map_to_curve_elligator2_curve448(u)
|
||||
let xn2 = Fp.sqr(xn); // 2. xn2 = xn^2
|
||||
let xd2 = Fp.sqr(xd); // 3. xd2 = xd^2
|
||||
let xd4 = Fp.sqr(xd2); // 4. xd4 = xd2^2
|
||||
let yn2 = Fp.sqr(yn); // 5. yn2 = yn^2
|
||||
let yd2 = Fp.sqr(yd); // 6. yd2 = yd^2
|
||||
let xEn = Fp.sub(xn2, xd2); // 7. xEn = xn2 - xd2
|
||||
let tv2 = Fp.sub(xEn, xd2); // 8. tv2 = xEn - xd2
|
||||
xEn = Fp.mul(xEn, xd2); // 9. xEn = xEn * xd2
|
||||
xEn = Fp.mul(xEn, yd); // 10. xEn = xEn * yd
|
||||
xEn = Fp.mul(xEn, yn); // 11. xEn = xEn * yn
|
||||
xEn = Fp.mul(xEn, _4n); // 12. xEn = xEn * 4
|
||||
tv2 = Fp.mul(tv2, xn2); // 13. tv2 = tv2 * xn2
|
||||
tv2 = Fp.mul(tv2, yd2); // 14. tv2 = tv2 * yd2
|
||||
let tv3 = Fp.mul(yn2, _4n); // 15. tv3 = 4 * yn2
|
||||
let tv1 = Fp.add(tv3, yd2); // 16. tv1 = tv3 + yd2
|
||||
tv1 = Fp.mul(tv1, xd4); // 17. tv1 = tv1 * xd4
|
||||
let xEd = Fp.add(tv1, tv2); // 18. xEd = tv1 + tv2
|
||||
tv2 = Fp.mul(tv2, xn); // 19. tv2 = tv2 * xn
|
||||
let tv4 = Fp.mul(xn, xd4); // 20. tv4 = xn * xd4
|
||||
let yEn = Fp.sub(tv3, yd2); // 21. yEn = tv3 - yd2
|
||||
yEn = Fp.mul(yEn, tv4); // 22. yEn = yEn * tv4
|
||||
yEn = Fp.sub(yEn, tv2); // 23. yEn = yEn - tv2
|
||||
tv1 = Fp.add(xn2, xd2); // 24. tv1 = xn2 + xd2
|
||||
tv1 = Fp.mul(tv1, xd2); // 25. tv1 = tv1 * xd2
|
||||
tv1 = Fp.mul(tv1, xd); // 26. tv1 = tv1 * xd
|
||||
tv1 = Fp.mul(tv1, yn2); // 27. tv1 = tv1 * yn2
|
||||
tv1 = Fp.mul(tv1, BigInt(-2)); // 28. tv1 = -2 * tv1
|
||||
let yEd = Fp.add(tv2, tv1); // 29. yEd = tv2 + tv1
|
||||
tv4 = Fp.mul(tv4, yd2); // 30. tv4 = tv4 * yd2
|
||||
yEd = Fp.add(yEd, tv4); // 31. yEd = yEd + tv4
|
||||
tv1 = Fp.mul(xEd, yEd); // 32. tv1 = xEd * yEd
|
||||
let e = Fp.eql(tv1, Fp.ZERO); // 33. e = tv1 == 0
|
||||
xEn = Fp.cmov(xEn, Fp.ZERO, e); // 34. xEn = CMOV(xEn, 0, e)
|
||||
xEd = Fp.cmov(xEd, Fp.ONE, e); // 35. xEd = CMOV(xEd, 1, e)
|
||||
yEn = Fp.cmov(yEn, Fp.ONE, e); // 36. yEn = CMOV(yEn, 1, e)
|
||||
yEd = Fp.cmov(yEd, Fp.ONE, e); // 37. yEd = CMOV(yEd, 1, e)
|
||||
|
||||
const inv = FpInvertBatch(Fp, [xEd, yEd], true); // batch division
|
||||
return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
|
||||
}
|
||||
|
||||
/** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
|
||||
export const ed448_hasher: H2CHasher<bigint> = /* @__PURE__ */ (() =>
|
||||
createHasher(ed448.Point, (scalars: bigint[]) => map_to_curve_elligator2_edwards448(scalars[0]), {
|
||||
DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
|
||||
encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
|
||||
p: Fp.ORDER,
|
||||
m: 1,
|
||||
k: 224,
|
||||
expand: 'xof',
|
||||
hash: shake256,
|
||||
}))();
|
||||
|
||||
// 1-d
|
||||
const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
|
||||
// 1-2d
|
||||
const ONE_MINUS_TWO_D = /* @__PURE__ */ BigInt('78163');
|
||||
// √(-d)
|
||||
const SQRT_MINUS_D = /* @__PURE__ */ BigInt(
|
||||
'98944233647732219769177004876929019128417576295529901074099889598043702116001257856802131563896515373927712232092845883226922417596214'
|
||||
);
|
||||
// 1 / √(-d)
|
||||
const INVSQRT_MINUS_D = /* @__PURE__ */ BigInt(
|
||||
'315019913931389607337177038330951043522456072897266928557328499619017160722351061360252776265186336876723201881398623946864393857820716'
|
||||
);
|
||||
// Calculates 1/√(number)
|
||||
const invertSqrt = (number: bigint) => uvRatio(_1n, number);
|
||||
|
||||
/**
|
||||
* Elligator map for hash-to-curve of decaf448.
|
||||
* Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C)
|
||||
* and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
|
||||
*/
|
||||
function calcElligatorDecafMap(r0: bigint): EdwardsPoint {
|
||||
const { d } = ed448_CURVE;
|
||||
const P = Fp.ORDER;
|
||||
const mod = (n: bigint) => Fp.create(n);
|
||||
|
||||
const r = mod(-(r0 * r0)); // 1
|
||||
const u0 = mod(d * (r - _1n)); // 2
|
||||
const u1 = mod((u0 + _1n) * (u0 - r)); // 3
|
||||
|
||||
const { isValid: was_square, value: v } = uvRatio(ONE_MINUS_TWO_D, mod((r + _1n) * u1)); // 4
|
||||
|
||||
let v_prime = v; // 5
|
||||
if (!was_square) v_prime = mod(r0 * v);
|
||||
|
||||
let sgn = _1n; // 6
|
||||
if (!was_square) sgn = mod(-_1n);
|
||||
|
||||
const s = mod(v_prime * (r + _1n)); // 7
|
||||
let s_abs = s;
|
||||
if (isNegativeLE(s, P)) s_abs = mod(-s);
|
||||
|
||||
const s2 = s * s;
|
||||
const W0 = mod(s_abs * _2n); // 8
|
||||
const W1 = mod(s2 + _1n); // 9
|
||||
const W2 = mod(s2 - _1n); // 10
|
||||
const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
|
||||
return new ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
|
||||
}
|
||||
|
||||
function decaf448_map(bytes: Uint8Array): _DecafPoint {
|
||||
abytes(bytes, 112);
|
||||
const skipValidation = true;
|
||||
// Note: Similar to the field element decoding described in
|
||||
// [RFC7748], and unlike the field element decoding described in
|
||||
// Section 5.3.1, non-canonical values are accepted.
|
||||
const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
|
||||
const R1 = calcElligatorDecafMap(r1);
|
||||
const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
|
||||
const R2 = calcElligatorDecafMap(r2);
|
||||
return new _DecafPoint(R1.add(R2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Each ed448/EdwardsPoint has 4 different equivalent points. This can be
|
||||
* a source of bugs for protocols like ring signatures. Decaf was created to solve this.
|
||||
* Decaf point operates in X:Y:Z:T extended coordinates like EdwardsPoint,
|
||||
* but it should work in its own namespace: do not combine those two.
|
||||
* See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
|
||||
*/
|
||||
class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
||||
// The following gymnastics is done because typescript strips comments otherwise
|
||||
// prettier-ignore
|
||||
static BASE: _DecafPoint =
|
||||
/* @__PURE__ */ (() => new _DecafPoint(ed448.Point.BASE).multiplyUnsafe(_2n))();
|
||||
// prettier-ignore
|
||||
static ZERO: _DecafPoint =
|
||||
/* @__PURE__ */ (() => new _DecafPoint(ed448.Point.ZERO))();
|
||||
// prettier-ignore
|
||||
static Fp: IField<bigint> =
|
||||
/* @__PURE__ */ (() => Fp448)();
|
||||
// prettier-ignore
|
||||
static Fn: IField<bigint> =
|
||||
/* @__PURE__ */ (() => Fn448)();
|
||||
|
||||
constructor(ep: EdwardsPoint) {
|
||||
super(ep);
|
||||
}
|
||||
|
||||
static fromAffine(ap: AffinePoint<bigint>): _DecafPoint {
|
||||
return new _DecafPoint(ed448.Point.fromAffine(ap));
|
||||
}
|
||||
|
||||
protected assertSame(other: _DecafPoint): void {
|
||||
if (!(other instanceof _DecafPoint)) throw new Error('DecafPoint expected');
|
||||
}
|
||||
|
||||
protected init(ep: EdwardsPoint): _DecafPoint {
|
||||
return new _DecafPoint(ep);
|
||||
}
|
||||
|
||||
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
||||
static hashToCurve(hex: Hex): _DecafPoint {
|
||||
return decaf448_map(ensureBytes('decafHash', hex, 112));
|
||||
}
|
||||
|
||||
static fromBytes(bytes: Uint8Array): _DecafPoint {
|
||||
abytes(bytes, 56);
|
||||
const { d } = ed448_CURVE;
|
||||
const P = Fp.ORDER;
|
||||
const mod = (n: bigint) => Fp448.create(n);
|
||||
const s = Fp448.fromBytes(bytes);
|
||||
|
||||
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
||||
// 2. Check that s is non-negative, or else abort
|
||||
|
||||
if (!equalBytes(Fn448.toBytes(s), bytes) || isNegativeLE(s, P))
|
||||
throw new Error('invalid decaf448 encoding 1');
|
||||
|
||||
const s2 = mod(s * s); // 1
|
||||
const u1 = mod(_1n + s2); // 2
|
||||
const u1sq = mod(u1 * u1);
|
||||
const u2 = mod(u1sq - _4n * d * s2); // 3
|
||||
|
||||
const { isValid, value: invsqrt } = invertSqrt(mod(u2 * u1sq)); // 4
|
||||
|
||||
let u3 = mod((s + s) * invsqrt * u1 * SQRT_MINUS_D); // 5
|
||||
if (isNegativeLE(u3, P)) u3 = mod(-u3);
|
||||
|
||||
const x = mod(u3 * invsqrt * u2 * INVSQRT_MINUS_D); // 6
|
||||
const y = mod((_1n - s2) * invsqrt * u1); // 7
|
||||
const t = mod(x * y); // 8
|
||||
|
||||
if (!isValid) throw new Error('invalid decaf448 encoding 2');
|
||||
return new _DecafPoint(new ed448.Point(x, y, _1n, t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts decaf-encoded string to decaf point.
|
||||
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
|
||||
* @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
|
||||
*/
|
||||
static fromHex(hex: Hex): _DecafPoint {
|
||||
return _DecafPoint.fromBytes(ensureBytes('decafHex', hex, 56));
|
||||
}
|
||||
|
||||
/** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
|
||||
static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint {
|
||||
return pippenger(_DecafPoint, Fn, points, scalars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes decaf point to Uint8Array.
|
||||
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
|
||||
*/
|
||||
toBytes(): Uint8Array {
|
||||
const { X, Z, T } = this.ep;
|
||||
const P = Fp.ORDER;
|
||||
const mod = (n: bigint) => Fp.create(n);
|
||||
const u1 = mod(mod(X + T) * mod(X - T)); // 1
|
||||
const x2 = mod(X * X);
|
||||
const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
|
||||
let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
|
||||
if (isNegativeLE(ratio, P)) ratio = mod(-ratio);
|
||||
const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
|
||||
let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
|
||||
if (isNegativeLE(s, P)) s = mod(-s);
|
||||
return Fn448.toBytes(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare one point to another.
|
||||
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
|
||||
*/
|
||||
equals(other: _DecafPoint): boolean {
|
||||
this.assertSame(other);
|
||||
const { X: X1, Y: Y1 } = this.ep;
|
||||
const { X: X2, Y: Y2 } = other.ep;
|
||||
// (x1 * y2 == y1 * x2)
|
||||
return Fp.create(X1 * Y2) === Fp.create(Y1 * X2);
|
||||
}
|
||||
|
||||
is0(): boolean {
|
||||
return this.equals(_DecafPoint.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
export const decaf448: {
|
||||
Point: typeof _DecafPoint;
|
||||
} = { Point: _DecafPoint };
|
||||
|
||||
/** Hashing to decaf448 points / field. RFC 9380 methods. */
|
||||
export const decaf448_hasher: H2CHasherBase<bigint> = {
|
||||
hashToCurve(msg: Uint8Array, options?: htfBasicOpts): _DecafPoint {
|
||||
const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
|
||||
return decaf448_map(expand_message_xof(msg, DST, 112, 224, shake256));
|
||||
},
|
||||
// Warning: has big modulo bias of 2^-64.
|
||||
// RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
|
||||
// it must use 84-byte xof (56+56/2), not 64.
|
||||
hashToScalar(msg: Uint8Array, options: htfBasicOpts = { DST: _DST_scalar }) {
|
||||
// Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
|
||||
const xof = expand_message_xof(msg, options.DST, 64, 256, shake256);
|
||||
return Fn448.create(bytesToNumberLE(xof));
|
||||
},
|
||||
};
|
||||
|
||||
// export const decaf448_oprf: OPRF = createORPF({
|
||||
// name: 'decaf448-SHAKE256',
|
||||
// Point: DecafPoint,
|
||||
// hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
|
||||
// hashToGroup: decaf448_hasher.hashToCurve,
|
||||
// hashToScalar: decaf448_hasher.hashToScalar,
|
||||
// });
|
||||
|
||||
/**
|
||||
* Weird / bogus points, useful for debugging.
|
||||
* Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
|
||||
* Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
|
||||
* (0, 1), (0, -1), (-1, 0), (1, 0).
|
||||
*/
|
||||
export const ED448_TORSION_SUBGROUP: string[] = [
|
||||
'010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
||||
'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
|
||||
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
||||
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
|
||||
];
|
||||
|
||||
type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
|
||||
|
||||
/** @deprecated use `decaf448.Point` */
|
||||
export const DecafPoint: typeof _DecafPoint = _DecafPoint;
|
||||
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
||||
export const hashToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
|
||||
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
||||
export const encodeToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() =>
|
||||
ed448_hasher.encodeToCurve)();
|
||||
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
||||
export const hashToDecaf448: DcfHasher = /* @__PURE__ */ (() =>
|
||||
decaf448_hasher.hashToCurve as DcfHasher)();
|
||||
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
||||
export const hash_to_decaf448: DcfHasher = /* @__PURE__ */ (() =>
|
||||
decaf448_hasher.hashToCurve as DcfHasher)();
|
||||
/** @deprecated use `ed448.utils.toMontgomery` */
|
||||
export function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array {
|
||||
return ed448.utils.toMontgomery(ensureBytes('pub', edwardsPub));
|
||||
}
|
||||
/** @deprecated use `ed448.utils.toMontgomery` */
|
||||
export const edwardsToMontgomery: typeof edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
var _construct = require("./_construct.cjs");
|
||||
var _get_prototype_of = require("./_get_prototype_of.cjs");
|
||||
var _is_native_function = require("./_is_native_function.cjs");
|
||||
var _set_prototype_of = require("./_set_prototype_of.cjs");
|
||||
|
||||
function _wrap_native_super(Class) {
|
||||
var _cache = typeof Map === "function" ? new Map() : undefined;
|
||||
exports._ = _wrap_native_super = function(Class) {
|
||||
if (Class === null || !_is_native_function._(Class)) return Class;
|
||||
if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
|
||||
if (typeof _cache !== "undefined") {
|
||||
if (_cache.has(Class)) return _cache.get(Class);
|
||||
_cache.set(Class, Wrapper);
|
||||
}
|
||||
|
||||
function Wrapper() {
|
||||
return _construct._(Class, arguments, _get_prototype_of._(this).constructor);
|
||||
}
|
||||
Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
|
||||
|
||||
return _set_prototype_of._(Wrapper, Class);
|
||||
};
|
||||
|
||||
return _wrap_native_super(Class);
|
||||
}
|
||||
exports._ = _wrap_native_super;
|
||||
@@ -0,0 +1 @@
|
||||
function e(e){"@hwc/retry"===globalThis?.process?.env.DEBUG&&console.debug(e)}class RetryTask{id=Math.random().toString(36).slice(2);fn;error;timestamp=Date.now();lastAttempt=this.timestamp;resolve;reject;signal;constructor(e,t,r,i,s){this.fn=e,this.error=t,this.timestamp=Date.now(),this.lastAttempt=Date.now(),this.resolve=r,this.reject=i,this.signal=s}get age(){return Date.now()-this.timestamp}}class Retrier{#e=[];#t=[];#r=0;#i;#s;#n;#o;#c;constructor(e,{timeout:t=6e4,maxDelay:r=100,concurrency:i=1e3}={}){if("function"!=typeof e)throw new Error("Missing function to check errors");this.#o=e,this.#i=t,this.#s=r,this.#c=i}get retrying(){return this.#e.length}get pending(){return this.#t.length}get working(){return this.#r}#a(t,{signal:r,promise:i,resolve:s,reject:n}){let o;try{o=t()}catch(e){return n(new Error(`Synchronous error: ${e.message}`,{cause:e})),i}return o&&"function"==typeof o.then?(this.#r++,i.finally((()=>{this.#r--,this.#h()})).catch((()=>{})),Promise.resolve(o).then((t=>{e("Function called successfully without retry."),s(t)})).catch((i=>{if(!this.#o(i))return void n(i);const o=new RetryTask(t,i,s,n,r);e(`Function failed, queuing for retry with task ${o.id}.`),this.#e.push(o),r?.addEventListener("abort",(()=>{e(`Task ${o.id} was aborted due to AbortSignal.`),n(r.reason)})),this.#g()})),i):(n(new Error("Result is not a promise.")),i)}retry(e,{signal:t}={}){t?.throwIfAborted();const{promise:r,resolve:i,reject:s}=function(){if(Promise.withResolvers)return Promise.withResolvers();let e,t;const r=new Promise(((r,i)=>{e=r,t=i}));if(void 0===e||void 0===t)throw new Error("Promise executor did not initialize resolve or reject.");return{promise:r,resolve:e,reject:t}}();return this.#t.push((()=>this.#a(e,{signal:t,promise:r,resolve:i,reject:s}))),this.#h(),r}#u(){this.pending&&this.#h(),this.retrying&&this.#g()}#h(){e(`Processing pending tasks: ${this.pending} pending, ${this.working} working.`);const t=this.#c-this.working;if(t<=0)return;const r=Math.min(this.pending,t);for(let e=0;e<r;e++){const e=this.#t.shift();e?.()}e(`Processed pending tasks: ${this.pending} pending, ${this.working} working.`)}#g(){clearTimeout(this.#n),this.#n=void 0,e(`Processing retry queue: ${this.retrying} retrying, ${this.working} working.`);const t=()=>{this.#n=setTimeout((()=>this.#u()),0)},r=this.#e.shift();return r?function(e,t){return e.age>t}(r,this.#i)?(e(`Task ${r.id} was abandoned due to timeout.`),r.reject(r.error),void t()):function(e,t){const r=Date.now()-e.lastAttempt,i=Math.max(e.lastAttempt-e.timestamp,1);return r>=Math.min(1.2*i,t)}(r,this.#s)?(r.lastAttempt=Date.now(),void Promise.resolve(r.fn()).then((t=>{e(`Task ${r.id} succeeded after ${r.age}ms.`),r.resolve(t)})).catch((t=>{if(!this.#o(t))return e(`Task ${r.id} failed with non-retryable error: ${t.message}.`),void r.reject(t);r.lastAttempt=Date.now(),this.#e.push(r),e(`Task ${r.id} failed, requeueing to try again.`)})).finally((()=>{this.#u()}))):(e(`Task ${r.id} is not ready to retry, skipping.`),this.#e.push(r),void t()):(e("Queue is empty, exiting."),void(this.pending&&t()))}}export{Retrier};
|
||||
@@ -0,0 +1,24 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2021" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRule = void 0;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
exports.createRule = utils_1.ESLintUtils.RuleCreator(name => `https://typescript-eslint.io/rules/${name}`);
|
||||
@@ -0,0 +1,495 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that returns the default iterator for an object. Called by the semantics of the
|
||||
* for-of statement.
|
||||
*/
|
||||
readonly iterator: unique symbol;
|
||||
}
|
||||
|
||||
interface IteratorYieldResult<TYield> {
|
||||
done?: false;
|
||||
value: TYield;
|
||||
}
|
||||
|
||||
interface IteratorReturnResult<TReturn> {
|
||||
done: true;
|
||||
value: TReturn;
|
||||
}
|
||||
|
||||
type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
|
||||
|
||||
interface Iterator<T, TReturn = any, TNext = undefined> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
|
||||
return?(value?: TReturn): IteratorResult<T, TReturn>;
|
||||
throw?(e?: any): IteratorResult<T, TReturn>;
|
||||
}
|
||||
|
||||
interface Iterable<T> {
|
||||
[Symbol.iterator](): Iterator<T>;
|
||||
}
|
||||
|
||||
interface IterableIterator<T> extends Iterator<T> {
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface Array<T> {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface ArrayConstructor {
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
*/
|
||||
from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
|
||||
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/** Iterator of values in the array. */
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface IArguments {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): IterableIterator<any>;
|
||||
}
|
||||
|
||||
interface Map<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): IterableIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): IterableIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): IterableIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): IterableIterator<V>;
|
||||
}
|
||||
|
||||
interface ReadonlyMap<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): IterableIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): IterableIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): IterableIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): IterableIterator<V>;
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new <K extends WeakKey, V>(iterable: Iterable<readonly [K, V]>): WeakMap<K, V>;
|
||||
}
|
||||
|
||||
interface Set<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): IterableIterator<[T, T]>;
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface ReadonlySet<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): IterableIterator<[T, T]>;
|
||||
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new <T>(iterable?: Iterable<T> | null): Set<T>;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends WeakKey = WeakKey>(iterable: Iterable<T>): WeakSet<T>;
|
||||
}
|
||||
|
||||
interface Promise<T> {}
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any Promise is rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
||||
}
|
||||
|
||||
interface String {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): IterableIterator<string>;
|
||||
}
|
||||
|
||||
interface Int8Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Int8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int8Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
|
||||
}
|
||||
|
||||
interface Uint8Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8ClampedArray;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
|
||||
}
|
||||
|
||||
interface Int16Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Int16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
|
||||
}
|
||||
|
||||
interface Uint16Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
|
||||
}
|
||||
|
||||
interface Int32Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Int32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int32Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
|
||||
}
|
||||
|
||||
interface Uint32Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint32Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
|
||||
}
|
||||
|
||||
interface Float32Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Float32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float32Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
|
||||
}
|
||||
|
||||
interface Float64Array {
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
|
||||
interface Float64ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float64Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like or iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cd ./test/ts;
|
||||
|
||||
if (echo "${npm_config_user_agent}" | grep "yarn"); then
|
||||
export RUNNER="yarn";
|
||||
else
|
||||
export RUNNER="npx";
|
||||
fi
|
||||
|
||||
test ./to-file.ts -ot ./to-file.es5.cjs || ("${RUNNER}" tsc --skipLibCheck --target es5 ./to-file.ts && mv ./to-file.js ./to-file.es5.cjs);
|
||||
test ./to-file.ts -ot ./to-file.es6.mjs || ("${RUNNER}" tsc --skipLibCheck --target es6 ./to-file.ts && mv ./to-file.js ./to-file.es6.mjs);
|
||||
test ./to-file.ts -ot ./to-file.es6.cjs || ("${RUNNER}" tsc --skipLibCheck --target es6 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es6.cjs);
|
||||
test ./to-file.ts -ot ./to-file.es2017.mjs || ("${RUNNER}" tsc --skipLibCheck --target es2017 ./to-file.ts && mv ./to-file.js ./to-file.es2017.mjs);
|
||||
test ./to-file.ts -ot ./to-file.es2017.cjs || ("${RUNNER}" tsc --skipLibCheck --target es2017 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es2017.cjs);
|
||||
test ./to-file.ts -ot ./to-file.esnext.mjs || ("${RUNNER}" tsc --skipLibCheck --target esnext --module esnext ./to-file.ts && mv ./to-file.js ./to-file.esnext.mjs);
|
||||
test ./to-file.ts -ot ./to-file.esnext.cjs || ("${RUNNER}" tsc --skipLibCheck --target esnext --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.esnext.cjs);
|
||||
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
isArray
|
||||
} from "../utils";
|
||||
|
||||
/**
|
||||
`Promise.race` returns a new promise which is settled in the same way as the
|
||||
first passed promise to settle.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
let promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 2');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// result === 'promise 2' because it was resolved before promise1
|
||||
// was resolved.
|
||||
});
|
||||
```
|
||||
|
||||
`Promise.race` is deterministic in that only the state of the first
|
||||
settled promise matters. For example, even if other promises given to the
|
||||
`promises` array argument are resolved, but the first settled promise has
|
||||
become rejected before the other promises became fulfilled, the returned
|
||||
promise will become rejected:
|
||||
|
||||
```javascript
|
||||
let promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
let promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
reject(new Error('promise 2'));
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// Code here never runs
|
||||
}, function(reason){
|
||||
// reason.message === 'promise 2' because promise 2 became rejected before
|
||||
// promise 1 became fulfilled
|
||||
});
|
||||
```
|
||||
|
||||
An example real-world use case is implementing timeouts:
|
||||
|
||||
```javascript
|
||||
Promise.race([ajax('foo.json'), timeout(5000)])
|
||||
```
|
||||
|
||||
@method race
|
||||
@static
|
||||
@param {Array} promises array of promises to observe
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise which settles in the same way as the first passed
|
||||
promise to settle.
|
||||
*/
|
||||
export default function race(entries) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
|
||||
if (!isArray(entries)) {
|
||||
return new Constructor((_, reject) => reject(new TypeError('You must pass an array to race.')));
|
||||
} else {
|
||||
return new Constructor((resolve, reject) => {
|
||||
let length = entries.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
Constructor.resolve(entries[i]).then(resolve, reject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce spacing around embedded expressions of template strings
|
||||
* @author Toru Nagashima
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "template-curly-spacing",
|
||||
url: "https://eslint.style/rules/template-curly-spacing",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require or disallow spacing around embedded expressions of template strings",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/template-curly-spacing",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [{ enum: ["always", "never"] }],
|
||||
messages: {
|
||||
expectedBefore: "Expected space(s) before '}'.",
|
||||
expectedAfter: "Expected space(s) after '${'.",
|
||||
unexpectedBefore: "Unexpected space(s) before '}'.",
|
||||
unexpectedAfter: "Unexpected space(s) after '${'.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
const always = context.options[0] === "always";
|
||||
|
||||
/**
|
||||
* Checks spacing before `}` of a given token.
|
||||
* @param {Token} token A token to check. This is a Template token.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingBefore(token) {
|
||||
if (!token.value.startsWith("}")) {
|
||||
return; // starts with a backtick, this is the first template element in the template literal
|
||||
}
|
||||
|
||||
const prevToken = sourceCode.getTokenBefore(token, {
|
||||
includeComments: true,
|
||||
}),
|
||||
hasSpace = sourceCode.isSpaceBetween(prevToken, token);
|
||||
|
||||
if (!astUtils.isTokenOnSameLine(prevToken, token)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (always && !hasSpace) {
|
||||
context.report({
|
||||
loc: {
|
||||
start: token.loc.start,
|
||||
end: {
|
||||
line: token.loc.start.line,
|
||||
column: token.loc.start.column + 1,
|
||||
},
|
||||
},
|
||||
messageId: "expectedBefore",
|
||||
fix: fixer => fixer.insertTextBefore(token, " "),
|
||||
});
|
||||
}
|
||||
|
||||
if (!always && hasSpace) {
|
||||
context.report({
|
||||
loc: {
|
||||
start: prevToken.loc.end,
|
||||
end: token.loc.start,
|
||||
},
|
||||
messageId: "unexpectedBefore",
|
||||
fix: fixer =>
|
||||
fixer.removeRange([prevToken.range[1], token.range[0]]),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks spacing after `${` of a given token.
|
||||
* @param {Token} token A token to check. This is a Template token.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingAfter(token) {
|
||||
if (!token.value.endsWith("${")) {
|
||||
return; // ends with a backtick, this is the last template element in the template literal
|
||||
}
|
||||
|
||||
const nextToken = sourceCode.getTokenAfter(token, {
|
||||
includeComments: true,
|
||||
}),
|
||||
hasSpace = sourceCode.isSpaceBetween(token, nextToken);
|
||||
|
||||
if (!astUtils.isTokenOnSameLine(token, nextToken)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (always && !hasSpace) {
|
||||
context.report({
|
||||
loc: {
|
||||
start: {
|
||||
line: token.loc.end.line,
|
||||
column: token.loc.end.column - 2,
|
||||
},
|
||||
end: token.loc.end,
|
||||
},
|
||||
messageId: "expectedAfter",
|
||||
fix: fixer => fixer.insertTextAfter(token, " "),
|
||||
});
|
||||
}
|
||||
|
||||
if (!always && hasSpace) {
|
||||
context.report({
|
||||
loc: {
|
||||
start: token.loc.end,
|
||||
end: nextToken.loc.start,
|
||||
},
|
||||
messageId: "unexpectedAfter",
|
||||
fix: fixer =>
|
||||
fixer.removeRange([token.range[1], nextToken.range[0]]),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
TemplateElement(node) {
|
||||
const token = sourceCode.getFirstToken(node);
|
||||
|
||||
checkSpacingBefore(token);
|
||||
checkSpacingAfter(token);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Disposable } from './disposable';
|
||||
/**
|
||||
* Represents a typed event.
|
||||
*/
|
||||
export interface Event<T> {
|
||||
/**
|
||||
*
|
||||
* @param listener The listener function will be called when the event happens.
|
||||
* @param thisArgs The 'this' which will be used when calling the event listener.
|
||||
* @param disposables An array to which a {{IDisposable}} will be added.
|
||||
* @return
|
||||
*/
|
||||
(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
|
||||
}
|
||||
export declare namespace Event {
|
||||
const None: Event<any>;
|
||||
}
|
||||
export interface EmitterOptions {
|
||||
onFirstListenerAdd?: Function;
|
||||
onLastListenerRemove?: Function;
|
||||
}
|
||||
export declare class Emitter<T> {
|
||||
private _options?;
|
||||
private static _noop;
|
||||
private _event;
|
||||
private _callbacks;
|
||||
constructor(_options?: EmitterOptions | undefined);
|
||||
/**
|
||||
* For the public to allow to subscribe
|
||||
* to events from this Emitter
|
||||
*/
|
||||
get event(): Event<T>;
|
||||
/**
|
||||
* To be kept private to fire an event to
|
||||
* subscribers
|
||||
*/
|
||||
fire(event: T): any;
|
||||
dispose(): void;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2010 - 2021 Brian Carlson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,64 @@
|
||||
declare const _default: {
|
||||
extends: string[];
|
||||
rules: {
|
||||
'@typescript-eslint/await-thenable': "error";
|
||||
'@typescript-eslint/no-array-delete': "error";
|
||||
'@typescript-eslint/no-base-to-string': "error";
|
||||
'@typescript-eslint/no-confusing-void-expression': "error";
|
||||
'@typescript-eslint/no-deprecated': "error";
|
||||
'@typescript-eslint/no-duplicate-type-constituents': "error";
|
||||
'@typescript-eslint/no-floating-promises': "error";
|
||||
'@typescript-eslint/no-for-in-array': "error";
|
||||
'no-implied-eval': "off";
|
||||
'@typescript-eslint/no-implied-eval': "error";
|
||||
'@typescript-eslint/no-meaningless-void-operator': "error";
|
||||
'@typescript-eslint/no-misused-promises': "error";
|
||||
'@typescript-eslint/no-misused-spread': "error";
|
||||
'@typescript-eslint/no-mixed-enums': "error";
|
||||
'@typescript-eslint/no-redundant-type-constituents': "error";
|
||||
'@typescript-eslint/no-unnecessary-boolean-literal-compare': "error";
|
||||
'@typescript-eslint/no-unnecessary-condition': "error";
|
||||
'@typescript-eslint/no-unnecessary-template-expression': "error";
|
||||
'@typescript-eslint/no-unnecessary-type-arguments': "error";
|
||||
'@typescript-eslint/no-unnecessary-type-assertion': "error";
|
||||
'@typescript-eslint/no-unnecessary-type-conversion': "error";
|
||||
'@typescript-eslint/no-unnecessary-type-parameters': "error";
|
||||
'@typescript-eslint/no-unsafe-argument': "error";
|
||||
'@typescript-eslint/no-unsafe-assignment': "error";
|
||||
'@typescript-eslint/no-unsafe-call': "error";
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': "error";
|
||||
'@typescript-eslint/no-unsafe-member-access': "error";
|
||||
'@typescript-eslint/no-unsafe-return': "error";
|
||||
'@typescript-eslint/no-unsafe-unary-minus': "error";
|
||||
'@typescript-eslint/no-useless-default-assignment': "error";
|
||||
'no-throw-literal': "off";
|
||||
'@typescript-eslint/only-throw-error': "error";
|
||||
'prefer-promise-reject-errors': "off";
|
||||
'@typescript-eslint/prefer-promise-reject-errors': "error";
|
||||
'@typescript-eslint/prefer-reduce-type-parameter': "error";
|
||||
'@typescript-eslint/prefer-return-this-type': "error";
|
||||
'@typescript-eslint/related-getter-setter-pairs': "error";
|
||||
'require-await': "off";
|
||||
'@typescript-eslint/require-await': "error";
|
||||
'@typescript-eslint/restrict-plus-operands': ["error", {
|
||||
allowAny: boolean;
|
||||
allowBoolean: boolean;
|
||||
allowNullish: boolean;
|
||||
allowNumberAndString: boolean;
|
||||
allowRegExp: boolean;
|
||||
}];
|
||||
'@typescript-eslint/restrict-template-expressions': ["error", {
|
||||
allowAny: boolean;
|
||||
allowBoolean: boolean;
|
||||
allowNever: boolean;
|
||||
allowNullish: boolean;
|
||||
allowNumber: boolean;
|
||||
allowRegExp: boolean;
|
||||
}];
|
||||
'no-return-await': "off";
|
||||
'@typescript-eslint/return-await': ["error", string];
|
||||
'@typescript-eslint/unbound-method': "error";
|
||||
'@typescript-eslint/use-unknown-in-catch-callback-variable': "error";
|
||||
};
|
||||
};
|
||||
export = _default;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.esnext_asynciterable = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
const es2015_iterable_1 = require("./es2015.iterable");
|
||||
const es2015_symbol_1 = require("./es2015.symbol");
|
||||
exports.esnext_asynciterable = {
|
||||
libs: [es2015_symbol_1.es2015_symbol, es2015_iterable_1.es2015_iterable],
|
||||
variables: [
|
||||
['SymbolConstructor', base_config_1.TYPE],
|
||||
['AsyncIterator', base_config_1.TYPE],
|
||||
['AsyncIterable', base_config_1.TYPE],
|
||||
['AsyncIterableIterator', base_config_1.TYPE],
|
||||
['AsyncIteratorObject', base_config_1.TYPE],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference types="node" />
|
||||
declare function base(ALPHABET: string): base.BaseConverter;
|
||||
export = base;
|
||||
declare namespace base {
|
||||
interface BaseConverter {
|
||||
encode(buffer: Buffer | number[] | Uint8Array): string;
|
||||
decodeUnsafe(string: string): Buffer | undefined;
|
||||
decode(string: string): Buffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user