feat: Replace aCAPTCHA with official ALTCHA (altcha.org) Proof-of-Work web component widget

This commit is contained in:
Richard
2026-07-31 11:39:29 +02:00
parent 6ef74c7cf4
commit 83c782c469
417 changed files with 100543 additions and 317 deletions
+60
View File
@@ -0,0 +1,60 @@
import { type IDataType, type IEmbeddedWasm } from "./util";
export declare const MAX_HEAP: number;
type ThenArg<T> = T extends Promise<infer U> ? U : T extends (...args: any[]) => Promise<infer V> ? V : T;
export type IHasher = {
/**
* Initializes hash state to default value
*/
init: () => IHasher;
/**
* Updates the hash content with the given data
*/
update: (data: IDataType) => IHasher;
/**
* Calculates the hash of all of the data passed to be hashed with hash.update().
* Defaults to hexadecimal string
* @param outputType If outputType is "binary", it returns Uint8Array. Otherwise it
* returns hexadecimal string
*/
digest: {
(outputType: "binary"): Uint8Array;
(outputType?: "hex"): string;
};
/**
* Save the current internal state of the hasher for later resumption with load().
* Cannot be called before .init() or after .digest()
*
* Note that this state can include arbitrary information about the value being hashed (e.g.
* could include N plaintext bytes from the value), so needs to be treated as being as
* sensitive as the input value itself.
*/
save: () => Uint8Array;
/**
* Resume a state that was created by save(). If this state was not created by a
* compatible build of hash-wasm, an exception will be thrown.
*/
load: (state: Uint8Array) => IHasher;
/**
* Block size in bytes
*/
blockSize: number;
/**
* Digest size in bytes
*/
digestSize: number;
};
export declare function WASMInterface(binary: IEmbeddedWasm, hashLength: number): Promise<{
getMemory: () => Uint8Array;
writeMemory: (data: Uint8Array, offset?: number) => void;
getExports: () => any;
setMemorySize: (totalSize: number) => void;
init: (bits?: number) => void;
update: (data: IDataType) => void;
digest: (outputType: "hex" | "binary", padding?: number) => Uint8Array | string;
save: () => Uint8Array;
load: (state: Uint8Array) => void;
calculate: (data: IDataType, initParam?: any, digestParam?: any) => string;
hashLength: number;
}>;
export type IWASMInterface = ThenArg<ReturnType<typeof WASMInterface>>;
export {};
+14
View File
@@ -0,0 +1,14 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates Adler-32 hash. The resulting 32-bit hash is stored in
* network byte order (big-endian).
*
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function adler32(data: IDataType): Promise<string>;
/**
* Creates a new Adler-32 hash instance
*/
export declare function createAdler32(): Promise<IHasher>;
+74
View File
@@ -0,0 +1,74 @@
import { type IDataType } from "./util";
export interface IArgon2Options {
/**
* Password (or message) to be hashed
*/
password: IDataType;
/**
* Salt (usually containing random bytes)
*/
salt: IDataType;
/**
* Secret for keyed hashing
*/
secret?: IDataType;
/**
* Number of iterations to perform
*/
iterations: number;
/**
* Degree of parallelism
*/
parallelism: number;
/**
* Amount of memory to be used in kibibytes (1024 bytes)
*/
memorySize: number;
/**
* Output size in bytes
*/
hashLength: number;
/**
* Desired output type. Defaults to 'hex'
*/
outputType?: "hex" | "binary" | "encoded";
}
interface IArgon2OptionsBinary {
outputType: "binary";
}
type Argon2ReturnType<T> = T extends IArgon2OptionsBinary ? Uint8Array : string;
/**
* Calculates hash using the argon2i password-hashing function
* @returns Computed hash
*/
export declare function argon2i<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
/**
* Calculates hash using the argon2id password-hashing function
* @returns Computed hash
*/
export declare function argon2id<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
/**
* Calculates hash using the argon2d password-hashing function
* @returns Computed hash
*/
export declare function argon2d<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
export interface Argon2VerifyOptions {
/**
* Password to be verified
*/
password: IDataType;
/**
* Secret used on hash creation
*/
secret?: IDataType;
/**
* A previously generated argon2 hash in the 'encoded' output format
*/
hash: string;
}
/**
* Verifies password using the argon2 password-hashing function
* @returns True if the encoded hash matches the password
*/
export declare function argon2Verify(options: Argon2VerifyOptions): Promise<boolean>;
export {};
+44
View File
@@ -0,0 +1,44 @@
import { type IDataType } from "./util";
export interface BcryptOptions {
/**
* Password to be hashed
*/
password: IDataType;
/**
* Salt (16 bytes long - usually containing random bytes)
*/
salt: IDataType;
/**
* Number of iterations to perform (4 - 31)
*/
costFactor: number;
/**
* Desired output type. Defaults to 'encoded'
*/
outputType?: "hex" | "binary" | "encoded";
}
interface IBcryptOptionsBinary {
outputType: "binary";
}
type BcryptReturnType<T> = T extends IBcryptOptionsBinary ? Uint8Array : string;
/**
* Calculates hash using the bcrypt password-hashing function
* @returns Computed hash
*/
export declare function bcrypt<T extends BcryptOptions>(options: T): Promise<BcryptReturnType<T>>;
export interface BcryptVerifyOptions {
/**
* Password to be verified
*/
password: IDataType;
/**
* A previously generated bcrypt hash in the 'encoded' output format
*/
hash: string;
}
/**
* Verifies password using bcrypt password-hashing function
* @returns True if the encoded hash matches the password
*/
export declare function bcryptVerify(options: BcryptVerifyOptions): Promise<boolean>;
export {};
+18
View File
@@ -0,0 +1,18 @@
import { type IHasher } from "./WASMInterface";
import { type IDataType } from "./util";
/**
* Calculates BLAKE2b hash
* @param data Input data (string, Buffer or TypedArray)
* @param bits Number of output bits, which has to be a number
* divisible by 8, between 8 and 512. Defaults to 512.
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
* @returns Computed hash as a hexadecimal string
*/
export declare function blake2b(data: IDataType, bits?: number, key?: IDataType): Promise<string>;
/**
* Creates a new BLAKE2b hash instance
* @param bits Number of output bits, which has to be a number
* divisible by 8, between 8 and 512. Defaults to 512.
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
*/
export declare function createBLAKE2b(bits?: number, key?: IDataType): Promise<IHasher>;
+18
View File
@@ -0,0 +1,18 @@
import { type IHasher } from "./WASMInterface";
import { type IDataType } from "./util";
/**
* Calculates BLAKE2s hash
* @param data Input data (string, Buffer or TypedArray)
* @param bits Number of output bits, which has to be a number
* divisible by 8, between 8 and 256. Defaults to 256.
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 32 bytes.
* @returns Computed hash as a hexadecimal string
*/
export declare function blake2s(data: IDataType, bits?: number, key?: IDataType): Promise<string>;
/**
* Creates a new BLAKE2s hash instance
* @param bits Number of output bits, which has to be a number
* divisible by 8, between 8 and 256. Defaults to 256.
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 32 bytes.
*/
export declare function createBLAKE2s(bits?: number, key?: IDataType): Promise<IHasher>;
+18
View File
@@ -0,0 +1,18 @@
import { type IHasher } from "./WASMInterface";
import { type IDataType } from "./util";
/**
* Calculates BLAKE3 hash
* @param data Input data (string, Buffer or TypedArray)
* @param bits Number of output bits, which has to be a number
* divisible by 8. Defaults to 256.
* @param key Optional key (string, Buffer or TypedArray). Length should be 32 bytes.
* @returns Computed hash as a hexadecimal string
*/
export declare function blake3(data: IDataType, bits?: number, key?: IDataType): Promise<string>;
/**
* Creates a new BLAKE3 hash instance
* @param bits Number of output bits, which has to be a number
* divisible by 8. Defaults to 256.
* @param key Optional key (string, Buffer or TypedArray). Length should be 32 bytes.
*/
export declare function createBLAKE3(bits?: number, key?: IDataType): Promise<IHasher>;
+14
View File
@@ -0,0 +1,14 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates CRC-32 hash
* @param data Input data (string, Buffer or TypedArray)
* @param polynomial Input polynomial (defaults to 0xedb88320, for CRC32C use 0x82f63b78)
* @returns Computed hash as a hexadecimal string
*/
export declare function crc32(data: IDataType, polynomial?: number): Promise<string>;
/**
* Creates a new CRC-32 hash instance
* @param polynomial Input polynomial (defaults to 0xedb88320, for CRC32C use 0x82f63b78)
*/
export declare function createCRC32(polynomial?: number): Promise<IHasher>;
+14
View File
@@ -0,0 +1,14 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates CRC-64 hash
* @param data Input data (string, Buffer or TypedArray)
* @param polynomial Input polynomial (defaults to 'c96c5795d7870f42' - ECMA)
* @returns Computed hash as a hexadecimal string
*/
export declare function crc64(data: IDataType, polynomial?: string): Promise<string>;
/**
* Creates a new CRC-64 hash instance
* @param polynomial Input polynomial (defaults to 'c96c5795d7870f42' - ECMA)
*/
export declare function createCRC64(polynomial?: string): Promise<IHasher>;
+8
View File
@@ -0,0 +1,8 @@
import type { IHasher } from "./WASMInterface";
import { type IDataType } from "./util";
/**
* Calculates HMAC hash
* @param hash Hash algorithm to use. It has to be the return value of a function like createSHA1()
* @param key Key (string, Buffer or TypedArray)
*/
export declare function createHMAC(hash: Promise<IHasher>, key: IDataType): Promise<IHasher>;
+29
View File
@@ -0,0 +1,29 @@
export * from "./adler32";
export * from "./argon2";
export * from "./blake2b";
export * from "./blake2s";
export * from "./blake3";
export * from "./crc32";
export * from "./crc64";
export * from "./md4";
export * from "./md5";
export * from "./sha1";
export * from "./sha3";
export * from "./keccak";
export * from "./sha224";
export * from "./sha256";
export * from "./sha384";
export * from "./sha512";
export * from "./xxhash32";
export * from "./xxhash64";
export * from "./xxhash3";
export * from "./xxhash128";
export * from "./ripemd160";
export * from "./hmac";
export * from "./pbkdf2";
export * from "./scrypt";
export * from "./bcrypt";
export * from "./whirlpool";
export * from "./sm3";
export type { IDataType } from "./util";
export type { IHasher } from "./WASMInterface";
+16
View File
@@ -0,0 +1,16 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
type IValidBits = 224 | 256 | 384 | 512;
/**
* Calculates Keccak hash
* @param data Input data (string, Buffer or TypedArray)
* @param bits Number of output bits. Valid values: 224, 256, 384, 512
* @returns Computed hash as a hexadecimal string
*/
export declare function keccak(data: IDataType, bits?: IValidBits): Promise<string>;
/**
* Creates a new Keccak hash instance
* @param bits Number of output bits. Valid values: 224, 256, 384, 512
*/
export declare function createKeccak(bits?: IValidBits): Promise<IHasher>;
export {};
+4
View File
@@ -0,0 +1,4 @@
import { type IWASMInterface } from "./WASMInterface";
import type Mutex from "./mutex";
import type { IEmbeddedWasm } from "./util";
export default function lockedCreate(mutex: Mutex, binary: IEmbeddedWasm, hashLength: number): Promise<IWASMInterface>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates MD4 hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function md4(data: IDataType): Promise<string>;
/**
* Creates a new MD4 hash instance
*/
export declare function createMD4(): Promise<IHasher>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates MD5 hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function md5(data: IDataType): Promise<string>;
/**
* Creates a new MD5 hash instance
*/
export declare function createMD5(): Promise<IHasher>;
+6
View File
@@ -0,0 +1,6 @@
declare class Mutex {
private mutex;
lock(): PromiseLike<() => void>;
dispatch<T>(fn: () => PromiseLike<T>): Promise<T>;
}
export default Mutex;
+37
View File
@@ -0,0 +1,37 @@
import type { IHasher } from "./WASMInterface";
import { type IDataType } from "./util";
export interface IPBKDF2Options {
/**
* Password (or message) to be hashed
*/
password: IDataType;
/**
* Salt (usually containing random bytes)
*/
salt: IDataType;
/**
* Number of iterations to perform
*/
iterations: number;
/**
* Output size in bytes
*/
hashLength: number;
/**
* Hash algorithm to use. It has to be the return value of a function like createSHA1()
*/
hashFunction: Promise<IHasher>;
/**
* Desired output type. Defaults to 'hex'
*/
outputType?: "hex" | "binary";
}
interface IPBKDF2OptionsBinary {
outputType: "binary";
}
type PBKDF2ReturnType<T> = T extends IPBKDF2OptionsBinary ? Uint8Array : string;
/**
* Generates a new PBKDF2 hash for the supplied password
*/
export declare function pbkdf2<T extends IPBKDF2Options>(options: T): Promise<PBKDF2ReturnType<T>>;
export {};
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates RIPEMD-160 hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function ripemd160(data: IDataType): Promise<string>;
/**
* Creates a new RIPEMD-160 hash instance
*/
export declare function createRIPEMD160(): Promise<IHasher>;
+42
View File
@@ -0,0 +1,42 @@
import { type IDataType } from "./util";
export interface ScryptOptions {
/**
* Password (or message) to be hashed
*/
password: IDataType;
/**
* Salt (usually containing random bytes)
*/
salt: IDataType;
/**
* CPU / memory cost - must be a power of 2 (e.g. 1024)
*/
costFactor: number;
/**
* Block size (8 is commonly used)
*/
blockSize: number;
/**
* Degree of parallelism
*/
parallelism: number;
/**
* Output size in bytes
*/
hashLength: number;
/**
* Output data type. Defaults to hexadecimal string
*/
outputType?: "hex" | "binary";
}
interface IScryptOptionsBinary {
outputType: "binary";
}
type ScryptReturnType<T> = T extends IScryptOptionsBinary ? Uint8Array : string;
/**
* Calculates hash using the scrypt password-based key derivation function
* @returns Computed hash as a hexadecimal string or as
* Uint8Array depending on the outputType option
*/
export declare function scrypt<T extends ScryptOptions>(options: T): Promise<ScryptReturnType<T>>;
export {};
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SHA-1 hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sha1(data: IDataType): Promise<string>;
/**
* Creates a new SHA-1 hash instance
*/
export declare function createSHA1(): Promise<IHasher>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SHA-2 (SHA-224) hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sha224(data: IDataType): Promise<string>;
/**
* Creates a new SHA-2 (SHA-224) hash instance
*/
export declare function createSHA224(): Promise<IHasher>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SHA-2 (SHA-256) hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sha256(data: IDataType): Promise<string>;
/**
* Creates a new SHA-2 (SHA-256) hash instance
*/
export declare function createSHA256(): Promise<IHasher>;
+16
View File
@@ -0,0 +1,16 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
type IValidBits = 224 | 256 | 384 | 512;
/**
* Calculates SHA-3 hash
* @param data Input data (string, Buffer or TypedArray)
* @param bits Number of output bits. Valid values: 224, 256, 384, 512
* @returns Computed hash as a hexadecimal string
*/
export declare function sha3(data: IDataType, bits?: IValidBits): Promise<string>;
/**
* Creates a new SHA-3 hash instance
* @param bits Number of output bits. Valid values: 224, 256, 384, 512
*/
export declare function createSHA3(bits?: IValidBits): Promise<IHasher>;
export {};
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SHA-2 (SHA-384) hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sha384(data: IDataType): Promise<string>;
/**
* Creates a new SHA-2 (SHA-384) hash instance
*/
export declare function createSHA384(): Promise<IHasher>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SHA-2 (SHA-512) hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sha512(data: IDataType): Promise<string>;
/**
* Creates a new SHA-2 (SHA-512) hash instance
*/
export declare function createSHA512(): Promise<IHasher>;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates SM3 hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function sm3(data: IDataType): Promise<string>;
/**
* Creates a new SM3 hash instance
*/
export declare function createSM3(): Promise<IHasher>;
+15
View File
@@ -0,0 +1,15 @@
export type ITypedArray = Uint8Array | Uint16Array | Uint32Array;
export type IDataType = string | Buffer | ITypedArray;
export type IEmbeddedWasm = {
name: string;
data: string;
hash: string;
};
export declare function intArrayToString(arr: Uint8Array, len: number): string;
export declare function writeHexToUInt8(buf: Uint8Array, str: string): void;
export declare function hexStringEqualsUInt8(str: string, buf: Uint8Array): boolean;
export declare function getDigestHex(tmpBuffer: Uint8Array, input: Uint8Array, hashLength: number): string;
export declare const getUInt8Buffer: (data: IDataType) => Uint8Array;
export declare function encodeBase64(data: Uint8Array, pad?: boolean): string;
export declare function getDecodeBase64Length(data: string): number;
export declare function decodeBase64(data: string): Uint8Array;
+12
View File
@@ -0,0 +1,12 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates Whirlpool hash
* @param data Input data (string, Buffer or TypedArray)
* @returns Computed hash as a hexadecimal string
*/
export declare function whirlpool(data: IDataType): Promise<string>;
/**
* Creates a new Whirlpool hash instance
*/
export declare function createWhirlpool(): Promise<IHasher>;
+20
View File
@@ -0,0 +1,20 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates xxHash128 hash
* @param data Input data (string, Buffer or TypedArray)
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @returns Computed hash as a hexadecimal string
*/
export declare function xxhash128(data: IDataType, seedLow?: number, seedHigh?: number): Promise<string>;
/**
* Creates a new xxHash128 hash instance
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
*/
export declare function createXXHash128(seedLow?: number, seedHigh?: number): Promise<IHasher>;
+20
View File
@@ -0,0 +1,20 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates xxHash3 hash
* @param data Input data (string, Buffer or TypedArray)
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @returns Computed hash as a hexadecimal string
*/
export declare function xxhash3(data: IDataType, seedLow?: number, seedHigh?: number): Promise<string>;
/**
* Creates a new xxHash3 hash instance
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
*/
export declare function createXXHash3(seedLow?: number, seedHigh?: number): Promise<IHasher>;
+15
View File
@@ -0,0 +1,15 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates xxHash32 hash
* @param data Input data (string, Buffer or TypedArray)
* @param seed Number used to initialize the internal state of the algorithm (defaults to 0)
* @returns Computed hash as a hexadecimal string
*/
export declare function xxhash32(data: IDataType, seed?: number): Promise<string>;
/**
* Creates a new xxHash32 hash instance
* @param data Input data (string, Buffer or TypedArray)
* @param seed Number used to initialize the internal state of the algorithm (defaults to 0)
*/
export declare function createXXHash32(seed?: number): Promise<IHasher>;
+20
View File
@@ -0,0 +1,20 @@
import { type IHasher } from "./WASMInterface";
import type { IDataType } from "./util";
/**
* Calculates xxHash64 hash
* @param data Input data (string, Buffer or TypedArray)
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @returns Computed hash as a hexadecimal string
*/
export declare function xxhash64(data: IDataType, seedLow?: number, seedHigh?: number): Promise<string>;
/**
* Creates a new xxHash64 hash instance
* @param seedLow Lower 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
* @param seedHigh Higher 32 bits of the number used to
* initialize the internal state of the algorithm (defaults to 0)
*/
export declare function createXXHash64(seedLow?: number, seedHigh?: number): Promise<IHasher>;