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,177 @@
/**
* @fileoverview A rule to disallow `this` keywords in contexts where the value of `this` is `undefined`.
* @author Toru Nagashima
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Determines if the given code path is a code path with lexical `this` binding.
* That is, if `this` within the code path refers to `this` of surrounding code path.
* @param {CodePath} codePath Code path.
* @param {ASTNode} node Node that started the code path.
* @returns {boolean} `true` if it is a code path with lexical `this` binding.
*/
function isCodePathWithLexicalThis(codePath, node) {
return (
codePath.origin === "function" &&
node.type === "ArrowFunctionExpression"
);
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../types').Rule.RuleModule} */
module.exports = {
meta: {
type: "suggestion",
defaultOptions: [{ capIsConstructor: true }],
docs: {
description:
"Disallow use of `this` in contexts where the value of `this` is `undefined`",
dialects: ["JavaScript", "TypeScript"],
recommended: false,
url: "https://eslint.org/docs/latest/rules/no-invalid-this",
},
schema: [
{
type: "object",
properties: {
capIsConstructor: {
type: "boolean",
},
},
additionalProperties: false,
},
],
messages: {
unexpectedThis: "Unexpected 'this'.",
},
},
create(context) {
const [{ capIsConstructor }] = context.options;
const stack = [],
sourceCode = context.sourceCode;
/**
* Gets the current checking context.
*
* The return value has a flag that whether or not `this` keyword is valid.
* The flag is initialized when got at the first time.
* @returns {{valid: boolean}}
* an object which has a flag that whether or not `this` keyword is valid.
*/
stack.getCurrent = function () {
const current = this.at(-1);
if (!current.init) {
current.init = true;
current.valid = !astUtils.isDefaultThisBinding(
current.node,
sourceCode,
{ capIsConstructor },
);
}
return current;
};
return {
onCodePathStart(codePath, node) {
if (isCodePathWithLexicalThis(codePath, node)) {
return;
}
if (codePath.origin === "program") {
const scope = sourceCode.getScope(node);
const features =
context.languageOptions.parserOptions.ecmaFeatures ||
{};
// `this` at the top level of scripts always refers to the global object
stack.push({
init: true,
node,
valid: !(
node.sourceType === "module" ||
(features.globalReturn &&
scope.childScopes[0].isStrict)
),
});
return;
}
/*
* `init: false` means that `valid` isn't determined yet.
* Most functions don't use `this`, and the calculation for `valid`
* is relatively costly, so we'll calculate it lazily when the first
* `this` within the function is traversed. A special case are non-strict
* functions, because `this` refers to the global object and therefore is
* always valid, so we can set `init: true` right away.
*/
stack.push({
init: !sourceCode.getScope(node).isStrict,
node,
valid: true,
});
},
onCodePathEnd(codePath, node) {
if (isCodePathWithLexicalThis(codePath, node)) {
return;
}
stack.pop();
},
"AccessorProperty > *.value"(node) {
stack.push({
init: true,
node,
valid: true,
});
},
"AccessorProperty:exit"() {
stack.pop();
},
// Reports if `this` of the current context is invalid.
ThisExpression(node) {
// Special case: skip `this` if it's the value of an AccessorProperty
if (
node.parent.type === "AccessorProperty" &&
node.parent.value === node
) {
return;
}
const current = stack.getCurrent();
if (current && !current.valid) {
context.report({
node,
messageId: "unexpectedThis",
});
}
},
};
},
};

View File

@@ -0,0 +1 @@
{"version":3,"file":"elementFlags.enum.js","sourceRoot":"","sources":["../../src/enums/elementFlags.enum.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACpB,+CAAQ,CAAA;IACR,uDAAiB,CAAA;IACjB,uDAAiB,CAAA;IACjB,+CAAa,CAAA;IACb,uDAAiB,CAAA;IACjB,iDAA2B,CAAA;IAC3B,wDAA0B,CAAA;IAC1B,8DAAwC,CAAA;IACxC,sDAAwC,CAAA;AAC5C,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB"}

View File

@@ -0,0 +1,22 @@
import type { MinimatchOptions } from './index.js';
/**
* Un-escape a string that has been escaped with {@link escape}.
*
* If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
* square-bracket escapes are removed, but not backslash escapes.
*
* For example, it will turn the string `'[*]'` into `*`, but it will not
* turn `'\\*'` into `'*'`, because `\` is a path separator in
* `windowsPathsNoEscape` mode.
*
* When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
* backslash escapes are removed.
*
* Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
* or unescaped.
*
* When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
* unescaped.
*/
export declare const unescape: (s: string, { windowsPathsNoEscape, magicalBraces, }?: Pick<MinimatchOptions, "windowsPathsNoEscape" | "magicalBraces">) => string;
//# sourceMappingURL=unescape.d.ts.map

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypeOfPropertyOfName = getTypeOfPropertyOfName;
exports.getTypeOfPropertyOfType = getTypeOfPropertyOfType;
function getTypeOfPropertyOfName(checker, type, name, escapedName) {
// Most names are directly usable in the checker and aren't different from escaped names
if (!escapedName || !isSymbol(escapedName)) {
return checker.getTypeOfPropertyOfType(type, name);
}
// Symbolic names may differ in their escaped name compared to their human-readable name
// https://github.com/typescript-eslint/typescript-eslint/issues/2143
const escapedProperty = type
.getProperties()
.find(property => property.escapedName === escapedName);
return escapedProperty
? checker.getDeclaredTypeOfSymbol(escapedProperty)
: undefined;
}
function getTypeOfPropertyOfType(checker, type, property) {
return getTypeOfPropertyOfName(checker, type, property.getName(), property.getEscapedName());
}
// Symbolic names need to be specially handled because TS api is not sufficient for these cases.
// Source based on:
// https://github.com/microsoft/TypeScript/blob/0043abe982aae0d35f8df59f9715be6ada758ff7/src/compiler/utilities.ts#L3388-L3402
function isSymbol(escapedName) {
return isKnownSymbol(escapedName) || isPrivateIdentifierSymbol(escapedName);
}
// case for escapedName: "__@foo@10", name: "__@foo@10"
function isKnownSymbol(escapedName) {
return escapedName.startsWith('__@');
}
// case for escapedName: "__#1@#foo", name: "#foo"
function isPrivateIdentifierSymbol(escapedName) {
return escapedName.startsWith('__#');
}

View File

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

View File

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

View File

@@ -0,0 +1,6 @@
import type { TSESLint } from '@typescript-eslint/utils';
export type MessageIds = 'noNonNull' | 'suggestOptionalChain';
declare const _default: TSESLint.RuleModule<MessageIds, [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
name: string;
};
export default _default;

View File

@@ -0,0 +1,5 @@
import uk from "./uk.js";
/** @deprecated Use `uk` instead. */
export default function () {
return uk();
}

View File

@@ -0,0 +1,37 @@
{
"name": "lightningcss-linux-x64-gnu",
"version": "1.33.0",
"license": "MPL-2.0",
"description": "A CSS parser, transformer, and minifier written in Rust",
"main": "lightningcss.linux-x64-gnu.node",
"browserslist": "last 2 versions, not dead",
"publishConfig": {
"access": "public"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
},
"repository": {
"type": "git",
"url": "https://github.com/parcel-bundler/lightningcss.git"
},
"engines": {
"node": ">= 12.0.0"
},
"files": [
"lightningcss.linux-x64-gnu.node"
],
"resolutions": {
"lightningcss": "link:."
},
"os": [
"linux"
],
"cpu": [
"x64"
],
"libc": [
"glibc"
]
}

View File

@@ -0,0 +1,57 @@
{
"reg": {
"name": "reg",
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
"suite": "escape-short",
"hz": 419028.44034580654,
"success": true,
"fastest": false,
"rme": 0.025905905131812446,
"rhz": 0.4073284694703158,
"sampleSize": 171
},
"fn if": {
"name": "fn if",
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
"suite": "escape-short",
"hz": 902805.3886212112,
"success": true,
"fastest": false,
"rme": 0.026929282009452646,
"rhz": 0.877597560855661,
"sampleSize": 163
},
"fn if reverse": {
"name": "fn if reverse",
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
"suite": "escape-short",
"hz": 890390.3422737826,
"success": true,
"fastest": false,
"rme": 0.02730976550531793,
"rhz": 0.8655291632477855,
"sampleSize": 163
},
"escape31": {
"name": "escape31",
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
"suite": "escape-short",
"hz": 1028723.6757369431,
"success": true,
"fastest": true,
"rme": 0.02519295334946404,
"rhz": 1,
"sampleSize": 161
},
"native": {
"name": "native",
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
"suite": "escape-short",
"hz": 773500.4517877887,
"success": true,
"fastest": false,
"rme": 0.05956270707829001,
"rhz": 0.7519030328855597,
"sampleSize": 168
}
}

View File

@@ -0,0 +1,7 @@
import * as ts from 'typescript';
/**
* Get the type name of a given type.
* @param typeChecker The context sensitive TypeScript TypeChecker.
* @param type The type to get the name of.
*/
export declare function getTypeName(typeChecker: ts.TypeChecker, type: ts.Type): string;

View File

@@ -0,0 +1,53 @@
/**
* Options for the Visitor constructor and visit function.
*/
interface VisitorOptions {
/**
* Fallback strategy for unknown node types.
* @default 'iteration'
*/
fallback?: "iteration" | ((node: any) => string[]);
/**
* Custom keys for child nodes by node type.
* @default {}
*/
childVisitorKeys?: Record<string, string[]>;
}
/**
* A visitor class for recursively traversing ECMAScript AST.
*/
declare class Visitor {
/**
* Creates a new Visitor instance.
* @param options Configuration options for the visitor.
*/
constructor(visitor?: Visitor | null, options?: VisitorOptions | null);
/**
* Visits a node, invoking the appropriate handler.
* @param node The AST node to visit.
*/
visit(node: any): void;
/**
* Visits the children of a node based on childVisitorKeys.
* @param node The AST node whose children to visit.
*/
visitChildren(node: any): void;
}
/**
* Visits an AST node with the specified visitor.
* @param ast The AST node to traverse.
* @param visitor A visitor instance or visitor object.
* @param options Configuration options for the traversal.
*/
declare function visit(
ast: any,
visitor?: Visitor | Record<string, (node: any) => void> | null,
options?: VisitorOptions,
): void;
export { visit, Visitor, type VisitorOptions };

View File

@@ -0,0 +1 @@
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../../src/abstract/fft.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,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C,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAC7C,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAChB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}

View File

@@ -0,0 +1,31 @@
import { SolanaErrorCode } from './codes';
import { SolanaErrorContext } from './context';
import { SolanaError } from './error';
type Config = Readonly<{
/**
* Oh, hello. You might wonder what in tarnation is going on here. Allow us to explain.
*
* One of the goals of `@solana/errors` is to allow errors that are not interesting to your
* application to shake out of your app bundle in production. This means that we must never
* export large hardcoded maps of error codes/messages.
*
* Unfortunately, where instruction and transaction errors from the RPC are concerned, we have
* no choice but to keep a map between the RPC `rpcEnumError` enum name and its corresponding
* `SolanaError` code. In the interest of implementing that map in as few bytes of source code
* as possible, we do the following:
*
* 1. Reserve a block of sequential error codes for the enum in question
* 2. Hardcode the list of enum names in that same order
* 3. Match the enum error name from the RPC with its index in that list, and reconstruct the
* `SolanaError` code by adding the `errorCodeBaseOffset` to that index
*/
errorCodeBaseOffset: number;
getErrorContext: (errorCode: SolanaErrorCode, rpcErrorName: string, rpcErrorContext?: unknown) => SolanaErrorContext[SolanaErrorCode];
orderedErrorNames: string[];
rpcEnumError: string | {
[key: string]: unknown;
};
}>;
export declare function getSolanaErrorFromRpcError({ errorCodeBaseOffset, getErrorContext, orderedErrorNames, rpcEnumError }: Config, constructorOpt: Function): SolanaError;
export {};
//# sourceMappingURL=rpc-enum-errors.d.ts.map

View File

@@ -0,0 +1,281 @@
/**
SHA1 (RFC 3174), MD5 (RFC 1321) and RIPEMD160 (RFC 2286) legacy, weak hash functions.
Don't use them in a new protocol. What "weak" means:
- Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.
- No practical pre-image attacks (only theoretical, 2^123.4)
- HMAC seems kinda ok: https://datatracker.ietf.org/doc/html/rfc6151
* @module
*/
import { Chi, HashMD, Maj } from "./_md.js";
import { clean, createHasher, rotl } from "./utils.js";
/** Initial SHA1 state */
const SHA1_IV = /* @__PURE__ */ Uint32Array.from([
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
]);
// Reusable temporary buffer
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
/** SHA1 legacy hash class. */
export class SHA1 extends HashMD {
constructor() {
super(64, 20, 8, false);
this.A = SHA1_IV[0] | 0;
this.B = SHA1_IV[1] | 0;
this.C = SHA1_IV[2] | 0;
this.D = SHA1_IV[3] | 0;
this.E = SHA1_IV[4] | 0;
}
get() {
const { A, B, C, D, E } = this;
return [A, B, C, D, E];
}
set(A, B, C, D, E) {
this.A = A | 0;
this.B = B | 0;
this.C = C | 0;
this.D = D | 0;
this.E = E | 0;
}
process(view, offset) {
for (let i = 0; i < 16; i++, offset += 4)
SHA1_W[i] = view.getUint32(offset, false);
for (let i = 16; i < 80; i++)
SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);
// Compression function main loop, 80 rounds
let { A, B, C, D, E } = this;
for (let i = 0; i < 80; i++) {
let F, K;
if (i < 20) {
F = Chi(B, C, D);
K = 0x5a827999;
}
else if (i < 40) {
F = B ^ C ^ D;
K = 0x6ed9eba1;
}
else if (i < 60) {
F = Maj(B, C, D);
K = 0x8f1bbcdc;
}
else {
F = B ^ C ^ D;
K = 0xca62c1d6;
}
const T = (rotl(A, 5) + F + E + K + SHA1_W[i]) | 0;
E = D;
D = C;
C = rotl(B, 30);
B = A;
A = T;
}
// Add the compressed chunk to the current hash value
A = (A + this.A) | 0;
B = (B + this.B) | 0;
C = (C + this.C) | 0;
D = (D + this.D) | 0;
E = (E + this.E) | 0;
this.set(A, B, C, D, E);
}
roundClean() {
clean(SHA1_W);
}
destroy() {
this.set(0, 0, 0, 0, 0);
clean(this.buffer);
}
}
/** SHA1 (RFC 3174) legacy hash function. It was cryptographically broken. */
export const sha1 = /* @__PURE__ */ createHasher(() => new SHA1());
/** Per-round constants */
const p32 = /* @__PURE__ */ Math.pow(2, 32);
const K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
/** md5 initial state: same as sha1, but 4 u32 instead of 5. */
const MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
// Reusable temporary buffer
const MD5_W = /* @__PURE__ */ new Uint32Array(16);
/** MD5 legacy hash class. */
export class MD5 extends HashMD {
constructor() {
super(64, 16, 8, true);
this.A = MD5_IV[0] | 0;
this.B = MD5_IV[1] | 0;
this.C = MD5_IV[2] | 0;
this.D = MD5_IV[3] | 0;
}
get() {
const { A, B, C, D } = this;
return [A, B, C, D];
}
set(A, B, C, D) {
this.A = A | 0;
this.B = B | 0;
this.C = C | 0;
this.D = D | 0;
}
process(view, offset) {
for (let i = 0; i < 16; i++, offset += 4)
MD5_W[i] = view.getUint32(offset, true);
// Compression function main loop, 64 rounds
let { A, B, C, D } = this;
for (let i = 0; i < 64; i++) {
let F, g, s;
if (i < 16) {
F = Chi(B, C, D);
g = i;
s = [7, 12, 17, 22];
}
else if (i < 32) {
F = Chi(D, B, C);
g = (5 * i + 1) % 16;
s = [5, 9, 14, 20];
}
else if (i < 48) {
F = B ^ C ^ D;
g = (3 * i + 5) % 16;
s = [4, 11, 16, 23];
}
else {
F = C ^ (B | ~D);
g = (7 * i) % 16;
s = [6, 10, 15, 21];
}
F = F + A + K[i] + MD5_W[g];
A = D;
D = C;
C = B;
B = B + rotl(F, s[i % 4]);
}
// Add the compressed chunk to the current hash value
A = (A + this.A) | 0;
B = (B + this.B) | 0;
C = (C + this.C) | 0;
D = (D + this.D) | 0;
this.set(A, B, C, D);
}
roundClean() {
clean(MD5_W);
}
destroy() {
this.set(0, 0, 0, 0);
clean(this.buffer);
}
}
/**
* MD5 (RFC 1321) legacy hash function. It was cryptographically broken.
* MD5 architecture is similar to SHA1, with some differences:
* - Reduced output length: 16 bytes (128 bit) instead of 20
* - 64 rounds, instead of 80
* - Little-endian: could be faster, but will require more code
* - Non-linear index selection: huge speed-up for unroll
* - Per round constants: more memory accesses, additional speed-up for unroll
*/
export const md5 = /* @__PURE__ */ createHasher(() => new MD5());
// RIPEMD-160
const Rho160 = /* @__PURE__ */ Uint8Array.from([
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
]);
const Id160 = /* @__PURE__ */ (() => Uint8Array.from(new Array(16).fill(0).map((_, i) => i)))();
const Pi160 = /* @__PURE__ */ (() => Id160.map((i) => (9 * i + 5) % 16))();
const idxLR = /* @__PURE__ */ (() => {
const L = [Id160];
const R = [Pi160];
const res = [L, R];
for (let i = 0; i < 4; i++)
for (let j of res)
j.push(j[i].map((k) => Rho160[k]));
return res;
})();
const idxL = /* @__PURE__ */ (() => idxLR[0])();
const idxR = /* @__PURE__ */ (() => idxLR[1])();
// const [idxL, idxR] = idxLR;
const shifts160 = /* @__PURE__ */ [
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5],
].map((i) => Uint8Array.from(i));
const shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
const shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
const Kl160 = /* @__PURE__ */ Uint32Array.from([
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
]);
const Kr160 = /* @__PURE__ */ Uint32Array.from([
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
]);
// It's called f() in spec.
function ripemd_f(group, x, y, z) {
if (group === 0)
return x ^ y ^ z;
if (group === 1)
return (x & y) | (~x & z);
if (group === 2)
return (x | ~y) ^ z;
if (group === 3)
return (x & z) | (y & ~z);
return x ^ (y | ~z);
}
// Reusable temporary buffer
const BUF_160 = /* @__PURE__ */ new Uint32Array(16);
export class RIPEMD160 extends HashMD {
constructor() {
super(64, 20, 8, true);
this.h0 = 0x67452301 | 0;
this.h1 = 0xefcdab89 | 0;
this.h2 = 0x98badcfe | 0;
this.h3 = 0x10325476 | 0;
this.h4 = 0xc3d2e1f0 | 0;
}
get() {
const { h0, h1, h2, h3, h4 } = this;
return [h0, h1, h2, h3, h4];
}
set(h0, h1, h2, h3, h4) {
this.h0 = h0 | 0;
this.h1 = h1 | 0;
this.h2 = h2 | 0;
this.h3 = h3 | 0;
this.h4 = h4 | 0;
}
process(view, offset) {
for (let i = 0; i < 16; i++, offset += 4)
BUF_160[i] = view.getUint32(offset, true);
// prettier-ignore
let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
// Instead of iterating 0 to 80, we split it into 5 groups
// And use the groups in constants, functions, etc. Much simpler
for (let group = 0; group < 5; group++) {
const rGroup = 4 - group;
const hbl = Kl160[group], hbr = Kr160[group]; // prettier-ignore
const rl = idxL[group], rr = idxR[group]; // prettier-ignore
const sl = shiftsL160[group], sr = shiftsR160[group]; // prettier-ignore
for (let i = 0; i < 16; i++) {
const tl = (rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el) | 0;
al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl; // prettier-ignore
}
// 2 loops are 10% faster
for (let i = 0; i < 16; i++) {
const tr = (rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er) | 0;
ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr; // prettier-ignore
}
}
// Add the compressed chunk to the current hash value
this.set((this.h1 + cl + dr) | 0, (this.h2 + dl + er) | 0, (this.h3 + el + ar) | 0, (this.h4 + al + br) | 0, (this.h0 + bl + cr) | 0);
}
roundClean() {
clean(BUF_160);
}
destroy() {
this.destroyed = true;
clean(this.buffer);
this.set(0, 0, 0, 0, 0);
}
}
/**
* RIPEMD-160 - a legacy hash function from 1990s.
* * https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
* * https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
*/
export const ripemd160 = /* @__PURE__ */ createHasher(() => new RIPEMD160());
//# sourceMappingURL=legacy.js.map

View File

@@ -0,0 +1,45 @@
import { urlAlphabet } from './url-alphabet/index.js'
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
if (size <= 0) return ''
let id = ''
while (true) {
let bytes = getRandom(step)
let j = step | 0
while (j--) {
id += alphabet[bytes[j] & mask] || ''
if (id.length === size) return id
}
}
}
}
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) =>
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
byte &= 63
if (byte < 36) {
id += byte.toString(36)
} else if (byte < 62) {
id += (byte - 26).toString(36).toUpperCase()
} else if (byte > 62) {
id += '-'
} else {
id += '_'
}
return id
}, '')
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015-2018 Peter A. Bigot
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.

View File

@@ -0,0 +1 @@
{"version":3,"file":"unescape.d.ts","sourceRoot":"","sources":["../../src/unescape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AAEH,eAAO,MAAM,QAAQ,GACnB,GAAG,MAAM,EACT,2CAGG,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,GAAG,eAAe,CAAM,WAczE,CAAA"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/api/fs.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACvB,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAC;IACjE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,SA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