WIP: bootstrap and partial real Solana watcher implementation

This commit is contained in:
2026-08-16 09:17:45 +00:00
commit dc23412c3f
7232 changed files with 1687637 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
/**
* @fileoverview Rule to flag use of function declaration identifiers as variables.
* @author Ian Christian Myers
*/
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../types').Rule.RuleModule} */
module.exports = {
meta: {
type: "problem",
docs: {
description: "Disallow reassigning `function` declarations",
recommended: true,
url: "https://eslint.org/docs/latest/rules/no-func-assign",
},
schema: [],
messages: {
isAFunction: "'{{name}}' is a function.",
},
},
create(context) {
const sourceCode = context.sourceCode;
/**
* Reports a reference if is non initializer and writable.
* @param {References} references Collection of reference to check.
* @returns {void}
*/
function checkReference(references) {
astUtils.getModifyingReferences(references).forEach(reference => {
context.report({
node: reference.identifier,
messageId: "isAFunction",
data: {
name: reference.identifier.name,
},
});
});
}
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
if (variable.defs[0].type === "FunctionName") {
checkReference(variable.references);
}
}
/**
* Checks parameters of a given function node.
* @param {ASTNode} node A function node to check.
* @returns {void}
*/
function checkForFunction(node) {
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}
return {
FunctionDeclaration: checkForFunction,
FunctionExpression: checkForFunction,
};
},
};

View File

@@ -0,0 +1,38 @@
import { DevEnvironment } from 'vite';
import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.DtoKVV2s.js';
/**
* Generate a unique cache identifier.
*
* Return `false` to disable caching of the file.
* @experimental
*/
interface CacheKeyIdGenerator {
(context: CacheKeyIdGeneratorContext): string | undefined | null | false;
}
/**
* @experimental
*/
interface CacheKeyIdGeneratorContext {
environment: DevEnvironment;
id: string;
sourceCode: string;
}
interface VitestPluginContext {
vitest: Vitest;
project: TestProject;
injectTestProjects: (config: TestProjectConfiguration | TestProjectConfiguration[]) => Promise<TestProject[]>;
/**
* Define a generator that will be applied before hashing the cache key.
*
* Use this to make sure Vitest generates correct hash. It is a good idea
* to define this function if your plugin can be registered with different options.
*
* This is called only if `experimental.fsModuleCache` is defined.
* @experimental
*/
experimental_defineCacheKeyGenerator: (callback: CacheKeyIdGenerator) => void;
}
export type { CacheKeyIdGenerator as C, VitestPluginContext as V, CacheKeyIdGeneratorContext as a };

View File

@@ -0,0 +1,10 @@
'use strict'
const neostandard = require('neostandard')
module.exports = neostandard({
ignores: [
'test/ts/**/*',
'test/syntax-error.mjs'
]
})

View File

@@ -0,0 +1,28 @@
// @ts-ignore TS6133
import { expect, test } from "vitest";
import * as z from "zod/v3";
import { util } from "../helpers/util.js";
test("check any inference", () => {
const t1 = z.any();
t1.optional();
t1.nullable();
type t1 = z.infer<typeof t1>;
util.assertEqual<t1, any>(true);
});
test("check unknown inference", () => {
const t1 = z.unknown();
t1.optional();
t1.nullable();
type t1 = z.infer<typeof t1>;
util.assertEqual<t1, unknown>(true);
});
test("check never inference", () => {
const t1 = z.never();
expect(() => t1.parse(undefined)).toThrow();
expect(() => t1.parse("asdf")).toThrow();
expect(() => t1.parse(null)).toThrow();
});

View File

@@ -0,0 +1,132 @@
import type { $ZodStringFormats } from "../core/checks.js";
import type * as errors from "../core/errors.js";
import * as util from "../core/util.js";
const error: () => errors.$ZodErrorMap = () => {
const Sizable: Record<string, { unit: string; verb: string }> = {
string: { unit: "caractères", verb: "avoir" },
file: { unit: "octets", verb: "avoir" },
array: { unit: "éléments", verb: "avoir" },
set: { unit: "éléments", verb: "avoir" },
};
function getSizing(origin: string): { unit: string; verb: string } | null {
return Sizable[origin] ?? null;
}
const FormatDictionary: {
[k in $ZodStringFormats | (string & {})]?: string;
} = {
regex: "entrée",
email: "adresse e-mail",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "date et heure ISO",
date: "date ISO",
time: "heure ISO",
duration: "durée ISO",
ipv4: "adresse IPv4",
ipv6: "adresse IPv6",
cidrv4: "plage IPv4",
cidrv6: "plage IPv6",
base64: "chaîne encodée en base64",
base64url: "chaîne encodée en base64url",
json_string: "chaîne JSON",
e164: "numéro E.164",
jwt: "JWT",
template_literal: "entrée",
};
const TypeDictionary: {
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
} = {
string: "chaîne",
number: "nombre",
int: "entier",
boolean: "booléen",
bigint: "grand entier",
symbol: "symbole",
undefined: "indéfini",
null: "null",
never: "jamais",
void: "vide",
date: "date",
array: "tableau",
object: "objet",
tuple: "tuple",
record: "enregistrement",
map: "carte",
set: "ensemble",
file: "fichier",
nonoptional: "non-optionnel",
nan: "NaN",
function: "fonction",
};
return (issue) => {
switch (issue.code) {
case "invalid_type": {
const expected = TypeDictionary[issue.expected] ?? issue.expected;
const receivedType = util.parsedType(issue.input);
const received = TypeDictionary[receivedType] ?? receivedType;
if (/^[A-Z]/.test(issue.expected)) {
return `Entrée invalide : instanceof ${issue.expected} attendu, ${received} reçu`;
}
return `Entrée invalide : ${expected} attendu, ${received} reçu`;
}
case "invalid_value":
if (issue.values.length === 1) return `Entrée invalide : ${util.stringifyPrimitive(issue.values[0])} attendu`;
return `Option invalide : une valeur parmi ${util.joinValues(issue.values, "|")} attendue`;
case "too_big": {
const adj = issue.inclusive ? "<=" : "<";
const sizing = getSizing(issue.origin);
if (sizing)
return `Trop grand : ${TypeDictionary[issue.origin] ?? "valeur"} doit ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "élément(s)"}`;
return `Trop grand : ${TypeDictionary[issue.origin] ?? "valeur"} doit être ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
if (sizing)
return `Trop petit : ${TypeDictionary[issue.origin] ?? "valeur"} doit ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
return `Trop petit : ${TypeDictionary[issue.origin] ?? "valeur"} doit être ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue as errors.$ZodStringFormatIssues;
if (_issue.format === "starts_with") return `Chaîne invalide : doit commencer par "${_issue.prefix}"`;
if (_issue.format === "ends_with") return `Chaîne invalide : doit se terminer par "${_issue.suffix}"`;
if (_issue.format === "includes") return `Chaîne invalide : doit inclure "${_issue.includes}"`;
if (_issue.format === "regex") return `Chaîne invalide : doit correspondre au modèle ${_issue.pattern}`;
return `${FormatDictionary[_issue.format] ?? issue.format} invalide`;
}
case "not_multiple_of":
return `Nombre invalide : doit être un multiple de ${issue.divisor}`;
case "unrecognized_keys":
return `Clé${issue.keys.length > 1 ? "s" : ""} non reconnue${issue.keys.length > 1 ? "s" : ""} : ${util.joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Clé invalide dans ${issue.origin}`;
case "invalid_union":
return "Entrée invalide";
case "invalid_element":
return `Valeur invalide dans ${issue.origin}`;
default:
return `Entrée invalide`;
}
};
};
export default function (): { localeError: errors.$ZodErrorMap } {
return {
localeError: error(),
};
}

View File

@@ -0,0 +1,9 @@
import { _ as _assert_this_initialized } from "./_assert_this_initialized.js";
import { _ as _type_of } from "./_type_of.js";
function _possible_constructor_return(self, call) {
if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
return _assert_this_initialized(self);
}
export { _possible_constructor_return as _ };

View File

@@ -0,0 +1,30 @@
"use strict";
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
exports._ = _object_spread_props;

View File

@@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) Open JS Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,125 @@
/**
* @fileoverview enforce the location of arrow function bodies
* @author Sharmila Jesupaul
* @deprecated in ESLint v8.53.0
*/
"use strict";
const { isCommentToken, isNotOpeningParenToken } = 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: "implicit-arrow-linebreak",
url: "https://eslint.style/rules/implicit-arrow-linebreak",
},
},
],
},
type: "layout",
docs: {
description: "Enforce the location of arrow function bodies",
recommended: false,
url: "https://eslint.org/docs/latest/rules/implicit-arrow-linebreak",
},
fixable: "whitespace",
schema: [
{
enum: ["beside", "below"],
},
],
messages: {
expected: "Expected a linebreak before this expression.",
unexpected: "Expected no linebreak before this expression.",
},
},
create(context) {
const sourceCode = context.sourceCode;
const option = context.options[0] || "beside";
/**
* Validates the location of an arrow function body
* @param {ASTNode} node The arrow function body
* @returns {void}
*/
function validateExpression(node) {
if (node.body.type === "BlockStatement") {
return;
}
const arrowToken = sourceCode.getTokenBefore(
node.body,
isNotOpeningParenToken,
);
const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);
if (
arrowToken.loc.end.line === firstTokenOfBody.loc.start.line &&
option === "below"
) {
context.report({
node: firstTokenOfBody,
messageId: "expected",
fix: fixer =>
fixer.insertTextBefore(firstTokenOfBody, "\n"),
});
} else if (
arrowToken.loc.end.line !== firstTokenOfBody.loc.start.line &&
option === "beside"
) {
context.report({
node: firstTokenOfBody,
messageId: "unexpected",
fix(fixer) {
if (
sourceCode.getFirstTokenBetween(
arrowToken,
firstTokenOfBody,
{
includeComments: true,
filter: isCommentToken,
},
)
) {
return null;
}
return fixer.replaceTextRange(
[arrowToken.range[1], firstTokenOfBody.range[0]],
" ",
);
},
});
}
}
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
ArrowFunctionExpression: node => validateExpression(node),
};
},
};

View File

@@ -0,0 +1,150 @@
'use strict'
const { test } = require('node:test')
const assert = require('node:assert')
const { fork } = require('child_process')
const { join } = require('path')
const { readFile } = require('fs').promises
const { file } = require('./helper')
const { once } = require('events')
const ThreadStream = require('..')
test('exits with 0', async function (t) {
const dest = file()
const child = fork(join(__dirname, 'create-and-exit.js'), [dest])
const [code] = await once(child, 'exit')
assert.strictEqual(code, 0)
const data = await readFile(dest, 'utf8')
assert.strictEqual(data, 'hello world\n')
})
test('emit error if thread exits', async function (t) {
const stream = new ThreadStream({
filename: join(__dirname, 'exit.js'),
sync: true
})
const closed = once(stream, 'close').catch(() => {})
// Keep a persistent error listener to avoid unhandled late error events
// reported as asynchronous activity by stricter test runners.
stream.on('error', () => {})
stream.on('ready', () => {
stream.write('hello world\n')
})
let [err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker thread exited')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
await closed
})
test('emit error if thread have unhandledRejection', async function (t) {
const stream = new ThreadStream({
filename: join(__dirname, 'unhandledRejection.js'),
sync: true
})
const closed = once(stream, 'close').catch(() => {})
// Keep a persistent error listener to avoid unhandled late error events
// reported as asynchronous activity by stricter test runners.
stream.on('error', () => {})
stream.on('ready', () => {
stream.write('hello world\n')
})
let [err] = await once(stream, 'error')
assert.strictEqual(err.message, 'kaboom')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
await closed
})
test('emit error if worker stream emit error', async function (t) {
const stream = new ThreadStream({
filename: join(__dirname, 'error.js'),
sync: true
})
const closed = once(stream, 'close').catch(() => {})
// Keep a persistent error listener to avoid unhandled late error events
// reported as asynchronous activity by stricter test runners.
stream.on('error', () => {})
stream.on('ready', () => {
stream.write('hello world\n')
})
let [err] = await once(stream, 'error')
assert.strictEqual(err.message, 'kaboom')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
await closed
})
test('emit error if thread have uncaughtException', async function (t) {
const stream = new ThreadStream({
filename: join(__dirname, 'uncaughtException.js'),
sync: true
})
const closed = once(stream, 'close').catch(() => {})
// Keep a persistent error listener to avoid unhandled late error events
// reported as asynchronous activity by stricter test runners.
stream.on('error', () => {})
stream.on('ready', () => {
stream.write('hello world\n')
})
let [err] = await once(stream, 'error')
assert.strictEqual(err.message, 'kaboom')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
stream.write('noop');
[err] = await once(stream, 'error')
assert.strictEqual(err.message, 'the worker has exited')
await closed
})
test('close the work if out of scope on gc', { skip: !global.WeakRef }, async function (t) {
const dest = file()
const child = fork(join(__dirname, 'close-on-gc.js'), [dest], {
execArgv: ['--expose-gc']
})
const [code] = await once(child, 'exit')
assert.strictEqual(code, 0)
const data = await readFile(dest, 'utf8')
assert.strictEqual(data, 'hello world\n')
})

View File

@@ -0,0 +1,268 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
exports.default = (0, util_1.createRule)({
name: 'no-type-alias',
meta: {
type: 'suggestion',
deprecated: {
deprecatedSince: '6.0.0',
replacedBy: [
{
rule: {
name: '@typescript-eslint/consistent-type-definitions',
url: 'https://typescript-eslint.io/rules/consistent-type-definitions',
},
},
],
url: 'https://github.com/typescript-eslint/typescript-eslint/pull/6229',
},
docs: {
description: 'Disallow type aliases',
// too opinionated to be recommended
},
messages: {
noCompositionAlias: '{{typeName}} in {{compositionType}} types are not allowed.',
noTypeAlias: 'Type {{alias}} are not allowed.',
},
schema: [
{
type: 'object',
$defs: {
expandedOptions: {
type: 'string',
enum: [
'always',
'never',
'in-unions',
'in-intersections',
'in-unions-and-intersections',
],
},
simpleOptions: {
type: 'string',
enum: ['always', 'never'],
},
},
additionalProperties: false,
properties: {
allowAliases: {
$ref: '#/items/0/$defs/expandedOptions',
description: 'Whether to allow direct one-to-one type aliases.',
},
allowCallbacks: {
$ref: '#/items/0/$defs/simpleOptions',
description: 'Whether to allow type aliases for callbacks.',
},
allowConditionalTypes: {
$ref: '#/items/0/$defs/simpleOptions',
description: 'Whether to allow type aliases for conditional types.',
},
allowConstructors: {
$ref: '#/items/0/$defs/simpleOptions',
description: 'Whether to allow type aliases with constructors.',
},
allowGenerics: {
$ref: '#/items/0/$defs/simpleOptions',
description: 'Whether to allow type aliases with generic types.',
},
allowLiterals: {
$ref: '#/items/0/$defs/expandedOptions',
description: 'Whether to allow type aliases with object literal types.',
},
allowMappedTypes: {
$ref: '#/items/0/$defs/expandedOptions',
description: 'Whether to allow type aliases with mapped types.',
},
allowTupleTypes: {
$ref: '#/items/0/$defs/expandedOptions',
description: 'Whether to allow type aliases with tuple types.',
},
},
},
],
},
defaultOptions: [
{
allowAliases: 'never',
allowCallbacks: 'never',
allowConditionalTypes: 'never',
allowConstructors: 'never',
allowGenerics: 'never',
allowLiterals: 'never',
allowMappedTypes: 'never',
allowTupleTypes: 'never',
},
],
create(context, [{ allowAliases, allowCallbacks, allowConditionalTypes, allowConstructors, allowGenerics, allowLiterals, allowMappedTypes, allowTupleTypes, },]) {
const unions = ['always', 'in-unions', 'in-unions-and-intersections'];
const intersections = [
'always',
'in-intersections',
'in-unions-and-intersections',
];
const compositions = [
'in-unions',
'in-intersections',
'in-unions-and-intersections',
];
const aliasTypes = new Set([
utils_1.AST_NODE_TYPES.TSArrayType,
utils_1.AST_NODE_TYPES.TSImportType,
utils_1.AST_NODE_TYPES.TSIndexedAccessType,
utils_1.AST_NODE_TYPES.TSLiteralType,
utils_1.AST_NODE_TYPES.TSTemplateLiteralType,
utils_1.AST_NODE_TYPES.TSTypeQuery,
utils_1.AST_NODE_TYPES.TSTypeReference,
]);
/**
* Determines if the composition type is supported by the allowed flags.
* @param isTopLevel a flag indicating this is the top level node.
* @param compositionType the composition type (either TSUnionType or TSIntersectionType)
* @param allowed the currently allowed flags.
*/
function isSupportedComposition(isTopLevel, compositionType, allowed) {
return (!compositions.includes(allowed) ||
(!isTopLevel &&
((compositionType === utils_1.AST_NODE_TYPES.TSUnionType &&
unions.includes(allowed)) ||
(compositionType === utils_1.AST_NODE_TYPES.TSIntersectionType &&
intersections.includes(allowed)))));
}
/**
* Gets the message to be displayed based on the node type and whether the node is a top level declaration.
* @param node the location
* @param compositionType the type of composition this alias is part of (undefined if not
* part of a composition)
* @param isRoot a flag indicating we are dealing with the top level declaration.
* @param type the kind of type alias being validated.
*/
function reportError(node, compositionType, isRoot, type) {
if (isRoot) {
return context.report({
node,
messageId: 'noTypeAlias',
data: {
alias: type.toLowerCase(),
},
});
}
return context.report({
node,
messageId: 'noCompositionAlias',
data: {
compositionType: compositionType === utils_1.AST_NODE_TYPES.TSUnionType
? 'union'
: 'intersection',
typeName: type,
},
});
}
const isValidTupleType = (type) => {
if (type.node.type === utils_1.AST_NODE_TYPES.TSTupleType) {
return true;
}
if (type.node.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
['keyof', 'readonly'].includes(type.node.operator) &&
type.node.typeAnnotation?.type === utils_1.AST_NODE_TYPES.TSTupleType) {
return true;
}
return false;
};
const isValidGeneric = (type) => {
return (type.node.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
type.node.typeArguments != null);
};
const checkAndReport = (optionValue, isTopLevel, type, label) => {
if (optionValue === 'never' ||
!isSupportedComposition(isTopLevel, type.compositionType, optionValue)) {
reportError(type.node, type.compositionType, isTopLevel, label);
}
};
/**
* Validates the node looking for aliases, callbacks and literals.
* @param type the type of composition this alias is part of (null if not
* part of a composition)
* @param isTopLevel a flag indicating this is the top level node.
*/
function validateTypeAliases(type, isTopLevel = false) {
// https://github.com/typescript-eslint/typescript-eslint/issues/5439
/* eslint-disable @typescript-eslint/no-non-null-assertion */
if (type.node.type === utils_1.AST_NODE_TYPES.TSFunctionType) {
// callback
if (allowCallbacks === 'never') {
reportError(type.node, type.compositionType, isTopLevel, 'Callbacks');
}
}
else if (type.node.type === utils_1.AST_NODE_TYPES.TSConditionalType) {
// conditional type
if (allowConditionalTypes === 'never') {
reportError(type.node, type.compositionType, isTopLevel, 'Conditional types');
}
}
else if (type.node.type === utils_1.AST_NODE_TYPES.TSConstructorType) {
if (allowConstructors === 'never') {
reportError(type.node, type.compositionType, isTopLevel, 'Constructors');
}
}
else if (type.node.type === utils_1.AST_NODE_TYPES.TSTypeLiteral) {
// literal object type
checkAndReport(allowLiterals, isTopLevel, type, 'Literals');
}
else if (type.node.type === utils_1.AST_NODE_TYPES.TSMappedType) {
// mapped type
checkAndReport(allowMappedTypes, isTopLevel, type, 'Mapped types');
}
else if (isValidTupleType(type)) {
// tuple types
checkAndReport(allowTupleTypes, isTopLevel, type, 'Tuple Types');
}
else if (isValidGeneric(type)) {
if (allowGenerics === 'never') {
reportError(type.node, type.compositionType, isTopLevel, 'Generics');
}
}
else if (type.node.type.endsWith(utils_1.AST_TOKEN_TYPES.Keyword) ||
aliasTypes.has(type.node.type) ||
(type.node.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
(type.node.operator === 'keyof' ||
(type.node.operator === 'readonly' &&
type.node.typeAnnotation &&
aliasTypes.has(type.node.typeAnnotation.type))))) {
// alias / keyword
checkAndReport(allowAliases, isTopLevel, type, 'Aliases');
}
else {
// unhandled type - shouldn't happen
reportError(type.node, type.compositionType, isTopLevel, 'Unhandled');
}
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}
/**
* Flatten the given type into an array of its dependencies
*/
function getTypes(node, compositionType = null) {
if (node.type === utils_1.AST_NODE_TYPES.TSUnionType ||
node.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
return node.types.flatMap(type => getTypes(type, node.type));
}
return [{ node, compositionType }];
}
return {
TSTypeAliasDeclaration(node) {
const types = getTypes(node.typeAnnotation);
if (types.length === 1) {
// is a top level type annotation
validateTypeAliases(types[0], true);
}
else {
// is a composition type
types.forEach(type => {
validateTypeAliases(type);
});
}
},
};
},
});

View File

@@ -0,0 +1,2 @@
import type { LibDefinition } from '../variable';
export declare const es2021_weakref: LibDefinition;

View File

@@ -0,0 +1,7 @@
// ast.ts — Hand-written AST type definitions
// Generated types are in ast.generated.ts
import { SyntaxKind } from "#enums/syntaxKind";
export { SyntaxKind } from "#enums/syntaxKind";
export { TokenFlags } from "#enums/tokenFlags";
export * from "./ast.generated.js";
//# sourceMappingURL=ast.js.map

View File

@@ -0,0 +1,9 @@
// Code generated by Herebyfile.mjs generate:enums from internal/diagnostics/diagnostics.go. DO NOT EDIT.
export var DiagnosticCategory;
(function (DiagnosticCategory) {
DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
DiagnosticCategory[DiagnosticCategory["Suggestion"] = 2] = "Suggestion";
DiagnosticCategory[DiagnosticCategory["Message"] = 3] = "Message";
})(DiagnosticCategory || (DiagnosticCategory = {}));
//# sourceMappingURL=diagnosticCategory.enum.js.map

View File

@@ -0,0 +1,67 @@
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
/**
* Encode an integer in the range of 0 to 63 to a single base 64 digit.
*/
exports.encode = function (number) {
if (0 <= number && number < intToCharMap.length) {
return intToCharMap[number];
}
throw new TypeError("Must be between 0 and 63: " + number);
};
/**
* Decode a single base 64 character code digit to an integer. Returns -1 on
* failure.
*/
exports.decode = function (charCode) {
var bigA = 65; // 'A'
var bigZ = 90; // 'Z'
var littleA = 97; // 'a'
var littleZ = 122; // 'z'
var zero = 48; // '0'
var nine = 57; // '9'
var plus = 43; // '+'
var slash = 47; // '/'
var littleOffset = 26;
var numberOffset = 52;
// 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
if (bigA <= charCode && charCode <= bigZ) {
return (charCode - bigA);
}
// 26 - 51: abcdefghijklmnopqrstuvwxyz
if (littleA <= charCode && charCode <= littleZ) {
return (charCode - littleA + littleOffset);
}
// 52 - 61: 0123456789
if (zero <= charCode && charCode <= nine) {
return (charCode - zero + numberOffset);
}
// 62: +
if (charCode == plus) {
return 62;
}
// 63: /
if (charCode == slash) {
return 63;
}
// Invalid base64 digit.
return -1;
};

View File

@@ -0,0 +1,74 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createProjectProgramError = createProjectProgramError;
const node_path_1 = __importDefault(require("node:path"));
const describeFilePath_1 = require("./describeFilePath");
const shared_1 = require("./shared");
function createProjectProgramError(parseSettings, programsForProjects) {
const describedFilePath = (0, describeFilePath_1.describeFilePath)(parseSettings.filePath, parseSettings.tsconfigRootDir);
return [
getErrorStart(describedFilePath, parseSettings),
...getErrorDetails(describedFilePath, parseSettings, programsForProjects),
];
}
function getErrorStart(describedFilePath, parseSettings) {
const relativeProjects = [...parseSettings.projects.values()].map(projectFile => (0, describeFilePath_1.describeFilePath)(projectFile, parseSettings.tsconfigRootDir));
const describedPrograms = relativeProjects.length === 1
? ` ${relativeProjects[0]}`
: `\n${relativeProjects.map(project => `- ${project}`).join('\n')}`;
return `ESLint was configured to run on \`${describedFilePath}\` using \`parserOptions.project\`:${describedPrograms}`;
}
function getErrorDetails(describedFilePath, parseSettings, programsForProjects) {
if (programsForProjects.length === 1 &&
programsForProjects[0].getProjectReferences()?.length) {
return [
`That TSConfig uses project "references" and doesn't include \`${describedFilePath}\` directly, which is not supported by \`parserOptions.project\`.`,
`Either:`,
`- Switch to \`parserOptions.projectService\``,
`- Use an ESLint-specific TSConfig`,
`See the typescript-eslint docs for more info: https://tseslint.com/are-project-references-supported`,
];
}
const { extraFileExtensions } = parseSettings;
const details = [];
for (const extraExtension of extraFileExtensions) {
if (!extraExtension.startsWith('.')) {
details.push(`Found unexpected extension \`${extraExtension}\` specified with the \`parserOptions.extraFileExtensions\` option. Did you mean \`.${extraExtension}\`?`);
}
if (shared_1.DEFAULT_EXTRA_FILE_EXTENSIONS.has(extraExtension)) {
details.push(`You unnecessarily included the extension \`${extraExtension}\` with the \`parserOptions.extraFileExtensions\` option. This extension is already handled by the parser by default.`);
}
}
const fileExtension = node_path_1.default.extname(parseSettings.filePath);
if (!shared_1.DEFAULT_EXTRA_FILE_EXTENSIONS.has(fileExtension)) {
const nonStandardExt = `The extension for the file (\`${fileExtension}\`) is non-standard`;
if (extraFileExtensions.length > 0) {
if (!extraFileExtensions.includes(fileExtension)) {
return [
...details,
`${nonStandardExt}. It should be added to your existing \`parserOptions.extraFileExtensions\`.`,
];
}
}
else {
return [
...details,
`${nonStandardExt}. You should add \`parserOptions.extraFileExtensions\` to your config.`,
];
}
}
const [describedInclusions, describedSpecifiers] = parseSettings.projects.size === 1
? ['that TSConfig does not', 'that TSConfig']
: ['none of those TSConfigs', 'one of those TSConfigs'];
return [
...details,
`However, ${describedInclusions} include this file. Either:`,
`- Change ESLint's list of included files to not include this file`,
`- Change ${describedSpecifiers} to include this file`,
`- Create a new TSConfig that includes this file and include it in your parserOptions.project`,
`See the typescript-eslint docs for more info: https://tseslint.com/none-of-those-tsconfigs-include-this-file`,
];
}

View File

@@ -0,0 +1,184 @@
'use strict'
const dns = require('dns')
const defaults = require('./defaults')
const parse = require('pg-connection-string').parse // parses a connection string
const val = function (key, config, envVar) {
if (config[key]) {
return config[key]
}
if (envVar === undefined) {
envVar = process.env['PG' + key.toUpperCase()]
} else if (envVar === false) {
// do nothing ... use false
} else {
envVar = process.env[envVar]
}
return envVar || defaults[key]
}
const readSSLConfigFromEnvironment = function () {
switch (process.env.PGSSLMODE) {
case 'disable':
return false
case 'prefer':
case 'require':
case 'verify-ca':
case 'verify-full':
return true
case 'no-verify':
return { rejectUnauthorized: false }
}
return defaults.ssl
}
// Convert arg to a string, surround in single quotes, and escape single quotes and backslashes
const quoteParamValue = function (value) {
return "'" + ('' + value).replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'"
}
const add = function (params, config, paramName) {
const value = config[paramName]
if (value !== undefined && value !== null) {
params.push(paramName + '=' + quoteParamValue(value))
}
}
class ConnectionParameters {
constructor(config) {
// if a string is passed, it is a raw connection string so we parse it into a config
config = typeof config === 'string' ? parse(config) : config || {}
// if the config has a connectionString defined, parse IT into the config we use
// this will override other default values with what is stored in connectionString
if (config.connectionString) {
config = Object.assign({}, config, parse(config.connectionString))
}
this.user = val('user', config)
this.database = val('database', config)
if (this.database === undefined) {
this.database = this.user
}
this.port = parseInt(val('port', config), 10)
this.host = val('host', config)
// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
writable: true,
value: val('password', config),
})
this.binary = val('binary', config)
this.options = val('options', config)
this.ssl = typeof config.ssl === 'undefined' ? readSSLConfigFromEnvironment() : config.ssl
if (typeof this.ssl === 'string') {
if (this.ssl === 'true') {
this.ssl = true
}
}
// support passing in ssl=no-verify via connection string
if (this.ssl === 'no-verify') {
this.ssl = { rejectUnauthorized: false }
}
if (this.ssl && this.ssl.key) {
Object.defineProperty(this.ssl, 'key', {
enumerable: false,
})
}
// How to negotiate SSL: 'postgres' (default, the traditional SSLRequest
// handshake) or 'direct' (start the TLS handshake immediately on connect).
this.sslnegotiation = val('sslnegotiation', config, 'PGSSLNEGOTIATION')
if (this.sslnegotiation !== undefined && this.sslnegotiation !== 'postgres' && this.sslnegotiation !== 'direct') {
throw new Error(
`Invalid sslnegotiation value: "${this.sslnegotiation}". Valid values are "postgres" and "direct".`
)
}
if (this.sslnegotiation === 'direct' && !this.ssl) {
throw new Error('sslnegotiation=direct requires SSL to be enabled')
}
this.client_encoding = val('client_encoding', config)
this.replication = val('replication', config)
// a domain socket begins with '/'
this.isDomainSocket = !(this.host || '').indexOf('/')
this.application_name = val('application_name', config, 'PGAPPNAME')
this.fallback_application_name = val('fallback_application_name', config, false)
this.statement_timeout = val('statement_timeout', config, false)
this.lock_timeout = val('lock_timeout', config, false)
this.idle_in_transaction_session_timeout = val('idle_in_transaction_session_timeout', config, false)
this.query_timeout = val('query_timeout', config, false)
if (config.connectionTimeoutMillis === undefined) {
this.connect_timeout = process.env.PGCONNECT_TIMEOUT || 0
} else {
this.connect_timeout = Math.floor(config.connectionTimeoutMillis / 1000)
}
if (config.keepAlive === false) {
this.keepalives = 0
} else if (config.keepAlive === true) {
this.keepalives = 1
}
if (typeof config.keepAliveInitialDelayMillis === 'number') {
this.keepalives_idle = Math.floor(config.keepAliveInitialDelayMillis / 1000)
}
}
getLibpqConnectionString(cb) {
const params = []
add(params, this, 'user')
add(params, this, 'password')
add(params, this, 'port')
add(params, this, 'application_name')
add(params, this, 'fallback_application_name')
add(params, this, 'connect_timeout')
add(params, this, 'options')
const ssl = typeof this.ssl === 'object' ? this.ssl : this.ssl ? { sslmode: this.ssl } : {}
add(params, ssl, 'sslmode')
add(params, ssl, 'sslca')
add(params, ssl, 'sslkey')
add(params, ssl, 'sslcert')
add(params, ssl, 'sslrootcert')
add(params, this, 'sslnegotiation')
if (this.database) {
params.push('dbname=' + quoteParamValue(this.database))
}
if (this.replication) {
params.push('replication=' + quoteParamValue(this.replication))
}
if (this.host) {
params.push('host=' + quoteParamValue(this.host))
}
if (this.isDomainSocket) {
return cb(null, params.join(' '))
}
if (this.client_encoding) {
params.push('client_encoding=' + quoteParamValue(this.client_encoding))
}
dns.lookup(this.host, function (err, address) {
if (err) return cb(err, null)
params.push('hostaddr=' + quoteParamValue(address))
return cb(null, params.join(' '))
})
}
}
module.exports = ConnectionParameters

View File

@@ -0,0 +1,708 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bls12_381 = exports.bls12_381_Fr = void 0;
/**
* bls12-381 is pairing-friendly Barreto-Lynn-Scott elliptic curve construction allowing to:
* Construct zk-SNARKs at the ~120-bit security, as per [Barbulescu-Duquesne 2017](https://hal.science/hal-01534101/file/main.pdf)
* Efficiently verify N aggregate signatures with 1 pairing and N ec additions:
the Boneh-Lynn-Shacham signature scheme is orders of magnitude more efficient than Schnorr
BLS can mean 2 different things:
* Barreto-Lynn-Scott: BLS12, a Pairing Friendly Elliptic Curve
* Boneh-Lynn-Shacham: A Signature Scheme.
### Summary
1. BLS Relies on expensive bilinear pairing
2. Secret Keys: 32 bytes
3. Public Keys: 48 OR 96 bytes - big-endian x coordinate of point on G1 OR G2 curve
4. Signatures: 96 OR 48 bytes - big-endian x coordinate of point on G2 OR G1 curve
5. The 12 stands for the Embedding degree.
Modes of operation:
* Long signatures: 48-byte keys + 96-byte sigs (G1 keys + G2 sigs).
* Short signatures: 96-byte keys + 48-byte sigs (G2 keys + G1 sigs).
### Formulas
- `P = pk x G` - public keys
- `S = pk x H(m)` - signing, uses hash-to-curve on m
- `e(P, H(m)) == e(G, S)` - verification using pairings
- `e(G, S) = e(G, SUM(n)(Si)) = MUL(n)(e(G, Si))` - signature aggregation
### Curves
G1 is ordinary elliptic curve. G2 is extension field curve, think "over complex numbers".
- G1: y² = x³ + 4
- G2: y² = x³ + 4(u + 1) where u = √1; r-order subgroup of E'(Fp²), M-type twist
### Towers
Pairing G1 + G2 produces element in Fp₁₂, 12-degree polynomial.
Fp₁₂ is usually implemented using tower of lower-degree polynomials for speed.
- Fp₁₂ = Fp₆² => Fp₂³
- Fp(u) / (u² - β) where β = -1
- Fp₂(v) / (v³ - ξ) where ξ = u + 1
- Fp₆(w) / (w² - γ) where γ = v
- Fp²[u] = Fp/u²+1
- Fp⁶[v] = Fp²/v³-1-u
- Fp¹²[w] = Fp⁶/w²-v
### Params
* Embedding degree (k): 12
* Seed is sometimes named x or t
* t = -15132376222941642752
* p = (t-1)² * (t⁴-t²+1)/3 + t
* r = t⁴-t²+1
* Ate loop size: X
To verify curve parameters, see
[pairing-friendly-curves spec](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-11).
Basic math is done over finite fields over p.
More complicated math is done over polynominal extension fields.
### Compatibility and notes
1. It is compatible with Algorand, Chia, Dfinity, Ethereum, Filecoin, ZEC.
Filecoin uses little endian byte arrays for secret keys - make sure to reverse byte order.
2. Make sure to correctly select mode: "long signature" or "short signature".
3. Compatible with specs:
RFC 9380,
[cfrg-pairing-friendly-curves-11](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-11),
[cfrg-bls-signature-05](https://datatracker.ietf.org/doc/draft-irtf-cfrg-bls-signature/).
*
* @module
*/
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const sha2_js_1 = require("@noble/hashes/sha2.js");
const bls_ts_1 = require("./abstract/bls.js");
const modular_ts_1 = require("./abstract/modular.js");
const utils_ts_1 = require("./utils.js");
// Types
const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
const tower_ts_1 = require("./abstract/tower.js");
const weierstrass_ts_1 = require("./abstract/weierstrass.js");
// Be friendly to bad ECMAScript parsers by not using bigint literals
// prettier-ignore
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4);
// To verify math:
// https://tools.ietf.org/html/draft-irtf-cfrg-pairing-friendly-curves-11
// The BLS parameter x (seed) for BLS12-381. NOTE: it is negative!
// x = -2^63 - 2^62 - 2^60 - 2^57 - 2^48 - 2^16
const BLS_X = BigInt('0xd201000000010000');
// t = x (called differently in different places)
// const t = -BLS_X;
const BLS_X_LEN = (0, utils_ts_1.bitLen)(BLS_X);
// a=0, b=4
// P is characteristic of field Fp, in which curve calculations are done.
// p = (t-1)² * (t⁴-t²+1)/3 + t
// bls12_381_Fp = (t-1n)**2n * (t**4n - t**2n + 1n) / 3n + t
// r*h is curve order, amount of points on curve,
// where r is order of prime subgroup and h is cofactor.
// r = t⁴-t²+1
// r = (t**4n - t**2n + 1n)
// cofactor h of G1: (t - 1)²/3
// cofactorG1 = (t-1n)**2n/3n
// x = 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
// y = 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569
const bls12_381_CURVE_G1 = {
p: BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab'),
n: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001'),
h: BigInt('0x396c8c005555e1568c00aaab0000aaab'),
a: _0n,
b: _4n,
Gx: BigInt('0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb'),
Gy: BigInt('0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1'),
};
// CURVE FIELDS
exports.bls12_381_Fr = (0, modular_ts_1.Field)(bls12_381_CURVE_G1.n, {
modFromBytes: true,
isLE: true,
});
const { Fp, Fp2, Fp6, Fp12 } = (0, tower_ts_1.tower12)({
ORDER: bls12_381_CURVE_G1.p,
X_LEN: BLS_X_LEN,
// Finite extension field over irreducible polynominal.
// Fp(u) / (u² - β) where β = -1
FP2_NONRESIDUE: [_1n, _1n],
Fp2mulByB: ({ c0, c1 }) => {
const t0 = Fp.mul(c0, _4n); // 4 * c0
const t1 = Fp.mul(c1, _4n); // 4 * c1
// (T0-T1) + (T0+T1)*i
return { c0: Fp.sub(t0, t1), c1: Fp.add(t0, t1) };
},
Fp12finalExponentiate: (num) => {
const x = BLS_X;
// this^(q⁶) / this
const t0 = Fp12.div(Fp12.frobeniusMap(num, 6), num);
// t0^(q²) * t0
const t1 = Fp12.mul(Fp12.frobeniusMap(t0, 2), t0);
const t2 = Fp12.conjugate(Fp12._cyclotomicExp(t1, x));
const t3 = Fp12.mul(Fp12.conjugate(Fp12._cyclotomicSquare(t1)), t2);
const t4 = Fp12.conjugate(Fp12._cyclotomicExp(t3, x));
const t5 = Fp12.conjugate(Fp12._cyclotomicExp(t4, x));
const t6 = Fp12.mul(Fp12.conjugate(Fp12._cyclotomicExp(t5, x)), Fp12._cyclotomicSquare(t2));
const t7 = Fp12.conjugate(Fp12._cyclotomicExp(t6, x));
const t2_t5_pow_q2 = Fp12.frobeniusMap(Fp12.mul(t2, t5), 2);
const t4_t1_pow_q3 = Fp12.frobeniusMap(Fp12.mul(t4, t1), 3);
const t6_t1c_pow_q1 = Fp12.frobeniusMap(Fp12.mul(t6, Fp12.conjugate(t1)), 1);
const t7_t3c_t1 = Fp12.mul(Fp12.mul(t7, Fp12.conjugate(t3)), t1);
// (t2 * t5)^(q²) * (t4 * t1)^(q³) * (t6 * t1.conj)^(q^1) * t7 * t3.conj * t1
return Fp12.mul(Fp12.mul(Fp12.mul(t2_t5_pow_q2, t4_t1_pow_q3), t6_t1c_pow_q1), t7_t3c_t1);
},
});
// GLV endomorphism Ψ(P), for fast cofactor clearing
const { G2psi, G2psi2 } = (0, tower_ts_1.psiFrobenius)(Fp, Fp2, Fp2.div(Fp2.ONE, Fp2.NONRESIDUE)); // 1/(u+1)
/**
* Default hash_to_field / hash-to-curve for BLS.
* m: 1 for G1, 2 for G2
* k: target security level in bits
* hash: any function, e.g. BBS+ uses BLAKE2: see [github](https://github.com/hyperledger/aries-framework-go/issues/2247).
* Parameter values come from [section 8.8.2 of RFC 9380](https://www.rfc-editor.org/rfc/rfc9380#section-8.8.2).
*/
const htfDefaults = Object.freeze({
DST: 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_',
encodeDST: 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_',
p: Fp.ORDER,
m: 2,
k: 128,
expand: 'xmd',
hash: sha2_js_1.sha256,
});
// a=0, b=4
// cofactor h of G2
// (t^8 - 4t^7 + 5t^6 - 4t^4 + 6t^3 - 4t^2 - 4t + 13)/9
// cofactorG2 = (t**8n - 4n*t**7n + 5n*t**6n - 4n*t**4n + 6n*t**3n - 4n*t**2n - 4n*t+13n)/9n
// x = 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758*u + 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160
// y = 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582*u + 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
const bls12_381_CURVE_G2 = {
p: Fp2.ORDER,
n: bls12_381_CURVE_G1.n,
h: BigInt('0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5'),
a: Fp2.ZERO,
b: Fp2.fromBigTuple([_4n, _4n]),
Gx: Fp2.fromBigTuple([
BigInt('0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8'),
BigInt('0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e'),
]),
Gy: Fp2.fromBigTuple([
BigInt('0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801'),
BigInt('0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be'),
]),
};
// Encoding utils
// Compressed point of infinity
// Set compressed & point-at-infinity bits
const COMPZERO = setMask(Fp.toBytes(_0n), { infinity: true, compressed: true });
function parseMask(bytes) {
// Copy, so we can remove mask data. It will be removed also later, when Fp.create will call modulo.
bytes = bytes.slice();
const mask = bytes[0] & 224;
const compressed = !!((mask >> 7) & 1); // compression bit (0b1000_0000)
const infinity = !!((mask >> 6) & 1); // point at infinity bit (0b0100_0000)
const sort = !!((mask >> 5) & 1); // sort bit (0b0010_0000)
bytes[0] &= 31; // clear mask (zero first 3 bits)
return { compressed, infinity, sort, value: bytes };
}
function setMask(bytes, mask) {
if (bytes[0] & 224)
throw new Error('setMask: non-empty mask');
if (mask.compressed)
bytes[0] |= 128;
if (mask.infinity)
bytes[0] |= 64;
if (mask.sort)
bytes[0] |= 32;
return bytes;
}
function pointG1ToBytes(_c, point, isComp) {
const { BYTES: L, ORDER: P } = Fp;
const is0 = point.is0();
const { x, y } = point.toAffine();
if (isComp) {
if (is0)
return COMPZERO.slice();
const sort = Boolean((y * _2n) / P);
return setMask((0, utils_ts_1.numberToBytesBE)(x, L), { compressed: true, sort });
}
else {
if (is0) {
return (0, utils_ts_1.concatBytes)(Uint8Array.of(0x40), new Uint8Array(2 * L - 1));
}
else {
return (0, utils_ts_1.concatBytes)((0, utils_ts_1.numberToBytesBE)(x, L), (0, utils_ts_1.numberToBytesBE)(y, L));
}
}
}
function signatureG1ToBytes(point) {
point.assertValidity();
const { BYTES: L, ORDER: P } = Fp;
const { x, y } = point.toAffine();
if (point.is0())
return COMPZERO.slice();
const sort = Boolean((y * _2n) / P);
return setMask((0, utils_ts_1.numberToBytesBE)(x, L), { compressed: true, sort });
}
function pointG1FromBytes(bytes) {
const { compressed, infinity, sort, value } = parseMask(bytes);
const { BYTES: L, ORDER: P } = Fp;
if (value.length === 48 && compressed) {
const compressedValue = (0, utils_ts_1.bytesToNumberBE)(value);
// Zero
const x = Fp.create(compressedValue & (0, utils_ts_1.bitMask)(Fp.BITS));
if (infinity) {
if (x !== _0n)
throw new Error('invalid G1 point: non-empty, at infinity, with compression');
return { x: _0n, y: _0n };
}
const right = Fp.add(Fp.pow(x, _3n), Fp.create(bls12_381_CURVE_G1.b)); // y² = x³ + b
let y = Fp.sqrt(right);
if (!y)
throw new Error('invalid G1 point: compressed point');
if ((y * _2n) / P !== BigInt(sort))
y = Fp.neg(y);
return { x: Fp.create(x), y: Fp.create(y) };
}
else if (value.length === 96 && !compressed) {
// Check if the infinity flag is set
const x = (0, utils_ts_1.bytesToNumberBE)(value.subarray(0, L));
const y = (0, utils_ts_1.bytesToNumberBE)(value.subarray(L));
if (infinity) {
if (x !== _0n || y !== _0n)
throw new Error('G1: non-empty point at infinity');
return exports.bls12_381.G1.Point.ZERO.toAffine();
}
return { x: Fp.create(x), y: Fp.create(y) };
}
else {
throw new Error('invalid G1 point: expected 48/96 bytes');
}
}
function signatureG1FromBytes(hex) {
const { infinity, sort, value } = parseMask((0, utils_ts_1.ensureBytes)('signatureHex', hex, 48));
const P = Fp.ORDER;
const Point = exports.bls12_381.G1.Point;
const compressedValue = (0, utils_ts_1.bytesToNumberBE)(value);
// Zero
if (infinity)
return Point.ZERO;
const x = Fp.create(compressedValue & (0, utils_ts_1.bitMask)(Fp.BITS));
const right = Fp.add(Fp.pow(x, _3n), Fp.create(bls12_381_CURVE_G1.b)); // y² = x³ + b
let y = Fp.sqrt(right);
if (!y)
throw new Error('invalid G1 point: compressed');
const aflag = BigInt(sort);
if ((y * _2n) / P !== aflag)
y = Fp.neg(y);
const point = Point.fromAffine({ x, y });
point.assertValidity();
return point;
}
function pointG2ToBytes(_c, point, isComp) {
const { BYTES: L, ORDER: P } = Fp;
const is0 = point.is0();
const { x, y } = point.toAffine();
if (isComp) {
if (is0)
return (0, utils_ts_1.concatBytes)(COMPZERO, (0, utils_ts_1.numberToBytesBE)(_0n, L));
const flag = Boolean(y.c1 === _0n ? (y.c0 * _2n) / P : (y.c1 * _2n) / P);
return (0, utils_ts_1.concatBytes)(setMask((0, utils_ts_1.numberToBytesBE)(x.c1, L), { compressed: true, sort: flag }), (0, utils_ts_1.numberToBytesBE)(x.c0, L));
}
else {
if (is0)
return (0, utils_ts_1.concatBytes)(Uint8Array.of(0x40), new Uint8Array(4 * L - 1));
const { re: x0, im: x1 } = Fp2.reim(x);
const { re: y0, im: y1 } = Fp2.reim(y);
return (0, utils_ts_1.concatBytes)((0, utils_ts_1.numberToBytesBE)(x1, L), (0, utils_ts_1.numberToBytesBE)(x0, L), (0, utils_ts_1.numberToBytesBE)(y1, L), (0, utils_ts_1.numberToBytesBE)(y0, L));
}
}
function signatureG2ToBytes(point) {
point.assertValidity();
const { BYTES: L } = Fp;
if (point.is0())
return (0, utils_ts_1.concatBytes)(COMPZERO, (0, utils_ts_1.numberToBytesBE)(_0n, L));
const { x, y } = point.toAffine();
const { re: x0, im: x1 } = Fp2.reim(x);
const { re: y0, im: y1 } = Fp2.reim(y);
const tmp = y1 > _0n ? y1 * _2n : y0 * _2n;
const sort = Boolean((tmp / Fp.ORDER) & _1n);
const z2 = x0;
return (0, utils_ts_1.concatBytes)(setMask((0, utils_ts_1.numberToBytesBE)(x1, L), { sort, compressed: true }), (0, utils_ts_1.numberToBytesBE)(z2, L));
}
function pointG2FromBytes(bytes) {
const { BYTES: L, ORDER: P } = Fp;
const { compressed, infinity, sort, value } = parseMask(bytes);
if ((!compressed && !infinity && sort) || // 00100000
(!compressed && infinity && sort) || // 01100000
(sort && infinity && compressed) // 11100000
) {
throw new Error('invalid encoding flag: ' + (bytes[0] & 224));
}
const slc = (b, from, to) => (0, utils_ts_1.bytesToNumberBE)(b.slice(from, to));
if (value.length === 96 && compressed) {
if (infinity) {
// check that all bytes are 0
if (value.reduce((p, c) => (p !== 0 ? c + 1 : c), 0) > 0) {
throw new Error('invalid G2 point: compressed');
}
return { x: Fp2.ZERO, y: Fp2.ZERO };
}
const x_1 = slc(value, 0, L);
const x_0 = slc(value, L, 2 * L);
const x = Fp2.create({ c0: Fp.create(x_0), c1: Fp.create(x_1) });
const right = Fp2.add(Fp2.pow(x, _3n), bls12_381_CURVE_G2.b); // y² = x³ + 4 * (u+1) = x³ + b
let y = Fp2.sqrt(right);
const Y_bit = y.c1 === _0n ? (y.c0 * _2n) / P : (y.c1 * _2n) / P ? _1n : _0n;
y = sort && Y_bit > 0 ? y : Fp2.neg(y);
return { x, y };
}
else if (value.length === 192 && !compressed) {
if (infinity) {
if (value.reduce((p, c) => (p !== 0 ? c + 1 : c), 0) > 0) {
throw new Error('invalid G2 point: uncompressed');
}
return { x: Fp2.ZERO, y: Fp2.ZERO };
}
const x1 = slc(value, 0 * L, 1 * L);
const x0 = slc(value, 1 * L, 2 * L);
const y1 = slc(value, 2 * L, 3 * L);
const y0 = slc(value, 3 * L, 4 * L);
return { x: Fp2.fromBigTuple([x0, x1]), y: Fp2.fromBigTuple([y0, y1]) };
}
else {
throw new Error('invalid G2 point: expected 96/192 bytes');
}
}
function signatureG2FromBytes(hex) {
const { ORDER: P } = Fp;
// TODO: Optimize, it's very slow because of sqrt.
const { infinity, sort, value } = parseMask((0, utils_ts_1.ensureBytes)('signatureHex', hex));
const Point = exports.bls12_381.G2.Point;
const half = value.length / 2;
if (half !== 48 && half !== 96)
throw new Error('invalid compressed signature length, expected 96/192 bytes');
const z1 = (0, utils_ts_1.bytesToNumberBE)(value.slice(0, half));
const z2 = (0, utils_ts_1.bytesToNumberBE)(value.slice(half));
// Indicates the infinity point
if (infinity)
return Point.ZERO;
const x1 = Fp.create(z1 & (0, utils_ts_1.bitMask)(Fp.BITS));
const x2 = Fp.create(z2);
const x = Fp2.create({ c0: x2, c1: x1 });
const y2 = Fp2.add(Fp2.pow(x, _3n), bls12_381_CURVE_G2.b); // y² = x³ + 4
// The slow part
let y = Fp2.sqrt(y2);
if (!y)
throw new Error('Failed to find a square root');
// Choose the y whose leftmost bit of the imaginary part is equal to the a_flag1
// If y1 happens to be zero, then use the bit of y0
const { re: y0, im: y1 } = Fp2.reim(y);
const aflag1 = BigInt(sort);
const isGreater = y1 > _0n && (y1 * _2n) / P !== aflag1;
const is0 = y1 === _0n && (y0 * _2n) / P !== aflag1;
if (isGreater || is0)
y = Fp2.neg(y);
const point = Point.fromAffine({ x, y });
point.assertValidity();
return point;
}
/**
* bls12-381 pairing-friendly curve.
* @example
* import { bls12_381 as bls } from '@noble/curves/bls12-381';
* // G1 keys, G2 signatures
* const privateKey = '67d53f170b908cabb9eb326c3c337762d59289a8fec79f7bc9254b584b73265c';
* const message = '64726e3da8';
* const publicKey = bls.getPublicKey(privateKey);
* const signature = bls.sign(message, privateKey);
* const isValid = bls.verify(signature, message, publicKey);
*/
exports.bls12_381 = (0, bls_ts_1.bls)({
// Fields
fields: {
Fp,
Fp2,
Fp6,
Fp12,
Fr: exports.bls12_381_Fr,
},
// G1: y² = x³ + 4
G1: {
...bls12_381_CURVE_G1,
Fp,
htfDefaults: { ...htfDefaults, m: 1, DST: 'BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_' },
wrapPrivateKey: true,
allowInfinityPoint: true,
// Checks is the point resides in prime-order subgroup.
// point.isTorsionFree() should return true for valid points
// It returns false for shitty points.
// https://eprint.iacr.org/2021/1130.pdf
isTorsionFree: (c, point) => {
// GLV endomorphism ψ(P)
const beta = BigInt('0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe');
const phi = new c(Fp.mul(point.X, beta), point.Y, point.Z);
// TODO: unroll
const xP = point.multiplyUnsafe(BLS_X).negate(); // [x]P
const u2P = xP.multiplyUnsafe(BLS_X); // [u2]P
return u2P.equals(phi);
},
// Clear cofactor of G1
// https://eprint.iacr.org/2019/403
clearCofactor: (_c, point) => {
// return this.multiplyUnsafe(CURVE.h);
return point.multiplyUnsafe(BLS_X).add(point); // x*P + P
},
mapToCurve: mapToG1,
fromBytes: pointG1FromBytes,
toBytes: pointG1ToBytes,
ShortSignature: {
fromBytes(bytes) {
(0, utils_ts_1.abytes)(bytes);
return signatureG1FromBytes(bytes);
},
fromHex(hex) {
return signatureG1FromBytes(hex);
},
toBytes(point) {
return signatureG1ToBytes(point);
},
toRawBytes(point) {
return signatureG1ToBytes(point);
},
toHex(point) {
return (0, utils_ts_1.bytesToHex)(signatureG1ToBytes(point));
},
},
},
G2: {
...bls12_381_CURVE_G2,
Fp: Fp2,
// https://datatracker.ietf.org/doc/html/rfc9380#name-clearing-the-cofactor
// https://datatracker.ietf.org/doc/html/rfc9380#name-cofactor-clearing-for-bls12
hEff: BigInt('0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551'),
htfDefaults: { ...htfDefaults },
wrapPrivateKey: true,
allowInfinityPoint: true,
mapToCurve: mapToG2,
// Checks is the point resides in prime-order subgroup.
// point.isTorsionFree() should return true for valid points
// It returns false for shitty points.
// https://eprint.iacr.org/2021/1130.pdf
// Older version: https://eprint.iacr.org/2019/814.pdf
isTorsionFree: (c, P) => {
return P.multiplyUnsafe(BLS_X).negate().equals(G2psi(c, P)); // ψ(P) == [u](P)
},
// Maps the point into the prime-order subgroup G2.
// clear_cofactor_bls12381_g2 from RFC 9380.
// https://eprint.iacr.org/2017/419.pdf
// prettier-ignore
clearCofactor: (c, P) => {
const x = BLS_X;
let t1 = P.multiplyUnsafe(x).negate(); // [-x]P
let t2 = G2psi(c, P); // Ψ(P)
let t3 = P.double(); // 2P
t3 = G2psi2(c, t3); // Ψ²(2P)
t3 = t3.subtract(t2); // Ψ²(2P) - Ψ(P)
t2 = t1.add(t2); // [-x]P + Ψ(P)
t2 = t2.multiplyUnsafe(x).negate(); // [x²]P - [x]Ψ(P)
t3 = t3.add(t2); // Ψ²(2P) - Ψ(P) + [x²]P - [x]Ψ(P)
t3 = t3.subtract(t1); // Ψ²(2P) - Ψ(P) + [x²]P - [x]Ψ(P) + [x]P
const Q = t3.subtract(P); // Ψ²(2P) - Ψ(P) + [x²]P - [x]Ψ(P) + [x]P - 1P
return Q; // [x²-x-1]P + [x-1]Ψ(P) + Ψ²(2P)
},
fromBytes: pointG2FromBytes,
toBytes: pointG2ToBytes,
Signature: {
fromBytes(bytes) {
(0, utils_ts_1.abytes)(bytes);
return signatureG2FromBytes(bytes);
},
fromHex(hex) {
return signatureG2FromBytes(hex);
},
toBytes(point) {
return signatureG2ToBytes(point);
},
toRawBytes(point) {
return signatureG2ToBytes(point);
},
toHex(point) {
return (0, utils_ts_1.bytesToHex)(signatureG2ToBytes(point));
},
},
},
params: {
ateLoopSize: BLS_X, // The BLS parameter x for BLS12-381
r: bls12_381_CURVE_G1.n, // order; z⁴ z² + 1; CURVE.n from other curves
xNegative: true,
twistType: 'multiplicative',
},
htfDefaults,
hash: sha2_js_1.sha256,
});
// 3-isogeny map from E' to E https://www.rfc-editor.org/rfc/rfc9380#appendix-E.3
const isogenyMapG2 = (0, hash_to_curve_ts_1.isogenyMap)(Fp2, [
// xNum
[
[
'0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6',
'0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6',
],
[
'0x0',
'0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a',
],
[
'0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e',
'0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d',
],
[
'0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1',
'0x0',
],
],
// xDen
[
[
'0x0',
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63',
],
[
'0xc',
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f',
],
['0x1', '0x0'], // LAST 1
],
// yNum
[
[
'0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706',
'0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706',
],
[
'0x0',
'0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be',
],
[
'0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c',
'0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f',
],
[
'0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10',
'0x0',
],
],
// yDen
[
[
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb',
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb',
],
[
'0x0',
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3',
],
[
'0x12',
'0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99',
],
['0x1', '0x0'], // LAST 1
],
].map((i) => i.map((pair) => Fp2.fromBigTuple(pair.map(BigInt)))));
// 11-isogeny map from E' to E
const isogenyMapG1 = (0, hash_to_curve_ts_1.isogenyMap)(Fp, [
// xNum
[
'0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7',
'0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb',
'0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0',
'0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861',
'0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9',
'0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983',
'0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84',
'0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e',
'0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317',
'0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e',
'0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b',
'0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229',
],
// xDen
[
'0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c',
'0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff',
'0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19',
'0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8',
'0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e',
'0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5',
'0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a',
'0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e',
'0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641',
'0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a',
'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', // LAST 1
],
// yNum
[
'0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33',
'0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696',
'0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6',
'0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb',
'0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb',
'0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0',
'0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2',
'0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29',
'0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587',
'0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30',
'0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132',
'0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e',
'0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8',
'0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133',
'0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b',
'0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604',
],
// yDen
[
'0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1',
'0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d',
'0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2',
'0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416',
'0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d',
'0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac',
'0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c',
'0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9',
'0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a',
'0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55',
'0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8',
'0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092',
'0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc',
'0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7',
'0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f',
'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001', // LAST 1
],
].map((i) => i.map((j) => BigInt(j))));
// Optimized SWU Map - Fp to G1
const G1_SWU = (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fp, {
A: Fp.create(BigInt('0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d')),
B: Fp.create(BigInt('0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0')),
Z: Fp.create(BigInt(11)),
});
// SWU Map - Fp2 to G2': y² = x³ + 240i * x + 1012 + 1012i
const G2_SWU = (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fp2, {
A: Fp2.create({ c0: Fp.create(_0n), c1: Fp.create(BigInt(240)) }), // A' = 240 * I
B: Fp2.create({ c0: Fp.create(BigInt(1012)), c1: Fp.create(BigInt(1012)) }), // B' = 1012 * (1 + I)
Z: Fp2.create({ c0: Fp.create(BigInt(-2)), c1: Fp.create(BigInt(-1)) }), // Z: -(2 + I)
});
function mapToG1(scalars) {
const { x, y } = G1_SWU(Fp.create(scalars[0]));
return isogenyMapG1(x, y);
}
function mapToG2(scalars) {
const { x, y } = G2_SWU(Fp2.fromBigTuple(scalars));
return isogenyMapG2(x, y);
}
//# sourceMappingURL=bls12-381.js.map

View File

@@ -0,0 +1,102 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeModifiers = exports.Modifiers = exports.MetaSelectors = exports.Selectors = exports.UnderscoreOptions = exports.PredefinedFormats = void 0;
var PredefinedFormats;
(function (PredefinedFormats) {
PredefinedFormats[PredefinedFormats["camelCase"] = 1] = "camelCase";
PredefinedFormats[PredefinedFormats["strictCamelCase"] = 2] = "strictCamelCase";
PredefinedFormats[PredefinedFormats["PascalCase"] = 3] = "PascalCase";
PredefinedFormats[PredefinedFormats["StrictPascalCase"] = 4] = "StrictPascalCase";
PredefinedFormats[PredefinedFormats["snake_case"] = 5] = "snake_case";
PredefinedFormats[PredefinedFormats["UPPER_CASE"] = 6] = "UPPER_CASE";
})(PredefinedFormats || (exports.PredefinedFormats = PredefinedFormats = {}));
var UnderscoreOptions;
(function (UnderscoreOptions) {
UnderscoreOptions[UnderscoreOptions["forbid"] = 1] = "forbid";
UnderscoreOptions[UnderscoreOptions["allow"] = 2] = "allow";
UnderscoreOptions[UnderscoreOptions["require"] = 3] = "require";
// special cases as it's common practice to use double underscore
UnderscoreOptions[UnderscoreOptions["requireDouble"] = 4] = "requireDouble";
UnderscoreOptions[UnderscoreOptions["allowDouble"] = 5] = "allowDouble";
UnderscoreOptions[UnderscoreOptions["allowSingleOrDouble"] = 6] = "allowSingleOrDouble";
})(UnderscoreOptions || (exports.UnderscoreOptions = UnderscoreOptions = {}));
var Selectors;
(function (Selectors) {
// variableLike
Selectors[Selectors["variable"] = 1] = "variable";
Selectors[Selectors["function"] = 2] = "function";
Selectors[Selectors["parameter"] = 4] = "parameter";
// memberLike
Selectors[Selectors["parameterProperty"] = 8] = "parameterProperty";
Selectors[Selectors["classicAccessor"] = 16] = "classicAccessor";
Selectors[Selectors["enumMember"] = 32] = "enumMember";
Selectors[Selectors["classMethod"] = 64] = "classMethod";
Selectors[Selectors["objectLiteralMethod"] = 128] = "objectLiteralMethod";
Selectors[Selectors["typeMethod"] = 256] = "typeMethod";
Selectors[Selectors["classProperty"] = 512] = "classProperty";
Selectors[Selectors["objectLiteralProperty"] = 1024] = "objectLiteralProperty";
Selectors[Selectors["typeProperty"] = 2048] = "typeProperty";
Selectors[Selectors["autoAccessor"] = 4096] = "autoAccessor";
// typeLike
Selectors[Selectors["class"] = 8192] = "class";
Selectors[Selectors["interface"] = 16384] = "interface";
Selectors[Selectors["typeAlias"] = 32768] = "typeAlias";
Selectors[Selectors["enum"] = 65536] = "enum";
Selectors[Selectors["typeParameter"] = 131072] = "typeParameter";
// other
Selectors[Selectors["import"] = 262144] = "import";
})(Selectors || (exports.Selectors = Selectors = {}));
var MetaSelectors;
(function (MetaSelectors) {
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
MetaSelectors[MetaSelectors["default"] = -1] = "default";
MetaSelectors[MetaSelectors["variableLike"] = 7] = "variableLike";
MetaSelectors[MetaSelectors["memberLike"] = 8184] = "memberLike";
MetaSelectors[MetaSelectors["typeLike"] = 253952] = "typeLike";
MetaSelectors[MetaSelectors["method"] = 448] = "method";
MetaSelectors[MetaSelectors["property"] = 3584] = "property";
MetaSelectors[MetaSelectors["accessor"] = 4112] = "accessor";
/* eslint-enable @typescript-eslint/prefer-literal-enum-member */
})(MetaSelectors || (exports.MetaSelectors = MetaSelectors = {}));
var Modifiers;
(function (Modifiers) {
// const variable
Modifiers[Modifiers["const"] = 1] = "const";
// readonly members
Modifiers[Modifiers["readonly"] = 2] = "readonly";
// static members
Modifiers[Modifiers["static"] = 4] = "static";
// member accessibility
Modifiers[Modifiers["public"] = 8] = "public";
Modifiers[Modifiers["protected"] = 16] = "protected";
Modifiers[Modifiers["private"] = 32] = "private";
Modifiers[Modifiers["#private"] = 64] = "#private";
Modifiers[Modifiers["abstract"] = 128] = "abstract";
// destructured variable
Modifiers[Modifiers["destructured"] = 256] = "destructured";
// variables declared in the top-level scope
Modifiers[Modifiers["global"] = 512] = "global";
// things that are exported
Modifiers[Modifiers["exported"] = 1024] = "exported";
// things that are unused
Modifiers[Modifiers["unused"] = 2048] = "unused";
// properties that require quoting
Modifiers[Modifiers["requiresQuotes"] = 4096] = "requiresQuotes";
// class members that are overridden
Modifiers[Modifiers["override"] = 8192] = "override";
// class methods, object function properties, or functions that are async via the `async` keyword
Modifiers[Modifiers["async"] = 16384] = "async";
// default imports
Modifiers[Modifiers["default"] = 32768] = "default";
// namespace imports
Modifiers[Modifiers["namespace"] = 65536] = "namespace";
// make sure TypeModifiers starts at Modifiers + 1 or else sorting won't work
})(Modifiers || (exports.Modifiers = Modifiers = {}));
var TypeModifiers;
(function (TypeModifiers) {
TypeModifiers[TypeModifiers["boolean"] = 131072] = "boolean";
TypeModifiers[TypeModifiers["string"] = 262144] = "string";
TypeModifiers[TypeModifiers["number"] = 524288] = "number";
TypeModifiers[TypeModifiers["function"] = 1048576] = "function";
TypeModifiers[TypeModifiers["array"] = 2097152] = "array";
})(TypeModifiers || (exports.TypeModifiers = TypeModifiers = {}));

View File

@@ -0,0 +1,40 @@
import { a as makeBuiltinPluginCallable, n as BuiltinPlugin } from "./shared/normalize-string-or-regex-BxRYnPRv.mjs";
import { t as esmExternalRequirePlugin } from "./shared/constructors-u6EEiG8n.mjs";
//#region src/builtin-plugin/replace-plugin.ts
/**
* Replaces targeted strings in files while bundling.
*
* @example
* **Basic usage**
* ```js
* replacePlugin({
* 'process.env.NODE_ENV': JSON.stringify('production'),
* __buildVersion: 15
* })
* ```
* @example
* **With options**
* ```js
* replacePlugin({
* 'process.env.NODE_ENV': JSON.stringify('production'),
* __buildVersion: 15
* }, {
* preventAssignment: false,
* })
* ```
*
* @see https://rolldown.rs/builtin-plugins/replace
* @category Builtin Plugins
*/
function replacePlugin(values = {}, options = {}) {
Object.keys(values).forEach((key) => {
const value = values[key];
if (typeof value !== "string") values[key] = String(value);
});
return makeBuiltinPluginCallable(new BuiltinPlugin("builtin:replace", {
...options,
values
}));
}
//#endregion
export { esmExternalRequirePlugin, replacePlugin };