feat: Replace aCAPTCHA with official ALTCHA (altcha.org) Proof-of-Work web component widget
This commit is contained in:
1 parent
6ef74c7cf4
commit
83c782c469
417 files changed
+100543
-317
No files matched your search
+480
@@ -0,0 +1,480 @@
|
||||
// Generated by dts-bundle-generator v9.5.1
|
||||
|
||||
export interface AltchaGlobal {
|
||||
algorithms: Map<string, () => Worker | Promise<Worker>>;
|
||||
defaults: Store<Partial<Configuration>>;
|
||||
i18n: Store<Record<string, Record<string, string>>>;
|
||||
instances: Set<HTMLElement>;
|
||||
plugins: Set<new (host: HTMLElement & WidgetMethods) => any>;
|
||||
}
|
||||
export declare enum AudioState {
|
||||
ERROR = "error",
|
||||
LOADING = "loading",
|
||||
PLAYING = "playing",
|
||||
PAUSED = "paused",
|
||||
READY = "ready"
|
||||
}
|
||||
export interface Configuration {
|
||||
/**
|
||||
* Forces a specific language for audio-based challenges.
|
||||
*/
|
||||
audioChallengeLanguage: string;
|
||||
/**
|
||||
* Determines when verification triggers automatically.
|
||||
* @default 'off'
|
||||
*/
|
||||
auto: "off" | "onfocus" | "onload" | "onsubmit";
|
||||
/**
|
||||
* Vertical position of the widget when `display` is set to `bar`.
|
||||
*/
|
||||
barPlacement: "bottom" | "top";
|
||||
/**
|
||||
* The challenge data or the URL to fetch a new challenge from.
|
||||
*/
|
||||
challenge: Challenge | string | null;
|
||||
/**
|
||||
* A specific code-challenge object. Overrides values provided in the `challenge` property.
|
||||
*/
|
||||
codeChallenge: CodeChallenge | null;
|
||||
/**
|
||||
* The UI layout used for the code-challenge modal.
|
||||
*/
|
||||
codeChallengeDisplay: "standard" | "overlay" | "bottomsheet";
|
||||
/**
|
||||
* Defines how credentials (cookies/auth headers) are handled during the challenge request.
|
||||
*/
|
||||
credentials: RequestCredentials | null;
|
||||
/**
|
||||
* Enables verbose logging in the browser console for debugging.
|
||||
*/
|
||||
debug: boolean;
|
||||
/**
|
||||
* Prevents the code-challenge modal from stealing focus when opened.
|
||||
*/
|
||||
disableAutoFocus: boolean;
|
||||
/**
|
||||
* The visual layout mode of the widget.
|
||||
*/
|
||||
display: "standard" | "bar" | "floating" | "overlay" | "invisible";
|
||||
/**
|
||||
* A custom `fetch` implementation for network requests.
|
||||
*/
|
||||
fetch: typeof fetch;
|
||||
/**
|
||||
* The element or CSS selector the floating UI attaches to.
|
||||
* Defaults to the first `submit` button in the parent form.
|
||||
*/
|
||||
floatingAnchor: string | HTMLElement | null;
|
||||
/**
|
||||
* Vertical offset (in pixels) between the floating UI and its anchor.
|
||||
* @default 12
|
||||
*/
|
||||
floatingOffset: number;
|
||||
/**
|
||||
* Controls whether the floating widget remains visible after successful verification.
|
||||
*/
|
||||
floatingPersist: boolean | "focus";
|
||||
/**
|
||||
* Preferred position of the floating widget relative to the anchor.
|
||||
*/
|
||||
floatingPlacement: "auto" | "bottom" | "top";
|
||||
/**
|
||||
* Hides the "ALTCHA" attribution link.
|
||||
*/
|
||||
hideFooter: boolean;
|
||||
/**
|
||||
* Hides the ALTCHA logo icon.
|
||||
*/
|
||||
hideLogo: boolean;
|
||||
/**
|
||||
* Enables the collection of pointer and scroll events for ALTCHA HIS mechanism (defaults to true).
|
||||
*/
|
||||
humanInteractionSignature: boolean;
|
||||
/**
|
||||
* The ISO alpha-2 language code for localization (requires corresponding i18n file).
|
||||
*/
|
||||
language: string;
|
||||
/**
|
||||
* The minimum verification time in milliseconds (adds an artificial delay if the PoW is faster).
|
||||
* @default 500
|
||||
*/
|
||||
minDuration: number;
|
||||
/**
|
||||
* Forces the widget into a failed state with a mock error for UI testing.
|
||||
*/
|
||||
mockError: boolean;
|
||||
/**
|
||||
* The `name` attribute of the hidden input field containing the payload.
|
||||
* @default 'altcha'
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* CSS selector for an element to be mirrored inside the overlay modal.
|
||||
*/
|
||||
overlayContent: string | null;
|
||||
/**
|
||||
* Configures the placement (top / bottom) for popovers. Defaults to 'auto'.
|
||||
*/
|
||||
popoverPlacement: "auto" | "bottom" | "top";
|
||||
/**
|
||||
* Automatically attempts to restart verification with fewer workers if the browser runs out of memory (Argon2 and Scrypt only).
|
||||
*/
|
||||
retryOnOutOfMemoryError: boolean;
|
||||
/**
|
||||
* Includes other form field values in the server-side verification request.
|
||||
*/
|
||||
serverVerificationFields: boolean;
|
||||
/**
|
||||
* Includes the user's time zone in the server-side verification request.
|
||||
*/
|
||||
serverVerificationTimeZone: boolean;
|
||||
/**
|
||||
* When set, the widget will set a configured cookie for the payload instead of sending it as form field.
|
||||
*/
|
||||
setCookie: SetCookieOptions | null;
|
||||
/**
|
||||
* Mocks a successful verification. Useful for testing environments without network access.
|
||||
*/
|
||||
test: boolean;
|
||||
/**
|
||||
* PoW verification timeout in milliseconds. Defaults to 90_000 ms.
|
||||
*/
|
||||
timeout: number;
|
||||
/**
|
||||
* The visual style of the interaction element.
|
||||
*/
|
||||
type: "native" | "checkbox" | "switch";
|
||||
/**
|
||||
* Custom validation message for the HTML5 `setCustomValidity` API.
|
||||
*/
|
||||
validationMessage: string;
|
||||
/**
|
||||
* A custom verification handler. Overrides the default network-based verification.
|
||||
*/
|
||||
verifyFunction: ((payload: string, code?: string) => Promise<ServerVerificationResult | null>) | null;
|
||||
/**
|
||||
* The endpoint URL for server-side verification.
|
||||
*/
|
||||
verifyUrl: string | null;
|
||||
/**
|
||||
* The number of Web Workers to spawn for proof-of-work calculations.
|
||||
*/
|
||||
workers: number;
|
||||
}
|
||||
export interface Challenge {
|
||||
codeChallenge?: CodeChallenge;
|
||||
parameters: ChallengeParameters;
|
||||
signature?: string;
|
||||
}
|
||||
export interface ChallengeParameters {
|
||||
algorithm: string;
|
||||
nonce: string;
|
||||
salt: string;
|
||||
cost: number;
|
||||
keyLength: number;
|
||||
keyPrefix: string;
|
||||
keySignature?: string;
|
||||
memoryCost?: number;
|
||||
parallelism?: number;
|
||||
expiresAt?: number;
|
||||
data?: Record<string, string | number | boolean | null>;
|
||||
}
|
||||
export interface ChallengeV1 {
|
||||
algorithm: string;
|
||||
challenge: string;
|
||||
codeChallenge?: CodeChallenge;
|
||||
salt: string;
|
||||
maxnumber?: number;
|
||||
maxNumber?: number;
|
||||
signature: string;
|
||||
}
|
||||
export interface CodeChallenge {
|
||||
image: string;
|
||||
audio?: string;
|
||||
length?: number;
|
||||
}
|
||||
export interface CreateChallengeOptions {
|
||||
algorithm: string;
|
||||
counter?: number;
|
||||
counterMode?: "uint32" | "string";
|
||||
cost: number;
|
||||
data?: Record<string, string | number | boolean | null>;
|
||||
deriveKey: DeriveKeyFunction;
|
||||
expiresAt?: number | Date;
|
||||
hmacAlgorithm?: HmacAlgorithm;
|
||||
hmacKeySignatureSecret?: string;
|
||||
hmacSignatureSecret?: string;
|
||||
keyLength?: number;
|
||||
keyPrefix?: string;
|
||||
keyPrefixLength?: number;
|
||||
memoryCost?: number;
|
||||
parallelism?: number;
|
||||
}
|
||||
export interface CSSVariables {
|
||||
"--altcha-border-color": string;
|
||||
"--altcha-border-width": string;
|
||||
"--altcha-border-radius": string;
|
||||
"--altcha-color-base": string;
|
||||
"--altcha-color-base-content": string;
|
||||
"--altcha-color-error": string;
|
||||
"--altcha-color-error-content": string;
|
||||
"--altcha-color-neutral": string;
|
||||
"--altcha-color-neutral-content": string;
|
||||
"--altcha-color-primary": string;
|
||||
"--altcha-color-primary-content": string;
|
||||
"--altcha-color-success": string;
|
||||
"--altcha-color-success-content": string;
|
||||
"--altcha-checkbox-border-color": string;
|
||||
"--altcha-checkbox-border-radius": string;
|
||||
"--altcha-checkbox-border-width": string;
|
||||
"--altcha-checkbox-outline": string;
|
||||
"--altcha-checkbox-outline-offset": string;
|
||||
"--altcha-checkbox-size": string;
|
||||
"--altcha-checkbox-transition-duration": string;
|
||||
"--altcha-input-background-color": string;
|
||||
"--altcha-input-border-radius": string;
|
||||
"--altcha-input-border-width": string;
|
||||
"--altcha-max-width": string;
|
||||
"--altcha-padding": string;
|
||||
"--altcha-popover-arrow-size": string;
|
||||
"--altcha-popover-color": string;
|
||||
"--altcha-shadow": string;
|
||||
"--altcha-spinner-color": string;
|
||||
"--altcha-switch-background-color": string;
|
||||
"--altcha-switch-border-radius": string;
|
||||
"--altcha-switch-height": string;
|
||||
"--altcha-switch-padding": string;
|
||||
"--altcha-switch-width": string;
|
||||
"--altcha-switch-toggle-border-radius": string;
|
||||
"--altcha-switch-toggle-color": string;
|
||||
"--altcha-switch-toggle-size": string;
|
||||
"--altcha-transition-duration": string;
|
||||
"--altcha-z-index": string | number;
|
||||
"--altcha-z-index-popover": string | number;
|
||||
}
|
||||
export type DeriveKeyFunction = (parameters: ChallengeParameters, salt: Uint8Array, password: Uint8Array) => Promise<DeriveKeyFunctionResult>;
|
||||
export interface DeriveKeyFunctionResult {
|
||||
parameters?: Partial<ChallengeParameters>;
|
||||
derivedKey: Uint8Array;
|
||||
}
|
||||
export declare enum HmacAlgorithm {
|
||||
SHA_256 = "SHA-256",
|
||||
SHA_384 = "SHA-384",
|
||||
SHA_512 = "SHA-512"
|
||||
}
|
||||
export interface Payload {
|
||||
challenge: Omit<Challenge, "codeChallenge">;
|
||||
solution: Solution;
|
||||
}
|
||||
export interface PayloadV1 {
|
||||
algorithm: string;
|
||||
challenge: string;
|
||||
number: number;
|
||||
salt: string;
|
||||
signature?: string;
|
||||
took: number;
|
||||
}
|
||||
export interface SetCookieOptions {
|
||||
domain?: string;
|
||||
name?: string;
|
||||
maxAge?: number;
|
||||
path?: string;
|
||||
sameSite?: string;
|
||||
secure?: boolean;
|
||||
}
|
||||
export type ServerClassification = "BAD" | "GOOD" | "NEUTRAL";
|
||||
export interface ServerSignaturePayload {
|
||||
algorithm: string;
|
||||
apiKey?: string;
|
||||
id?: string;
|
||||
signature: string;
|
||||
verificationData: string;
|
||||
verified: boolean;
|
||||
}
|
||||
export interface ServerSignatureVerificationData {
|
||||
[key: string]: string | unknown;
|
||||
classification?: ServerClassification;
|
||||
email?: string;
|
||||
expire?: number;
|
||||
fields?: string[];
|
||||
fieldsHash?: string;
|
||||
id?: string;
|
||||
ipAddress?: string;
|
||||
reasons?: string[];
|
||||
score?: number;
|
||||
time?: number;
|
||||
verified?: boolean;
|
||||
}
|
||||
export interface ServerVerificationResult {
|
||||
algorithm?: string;
|
||||
apiKey?: string;
|
||||
id?: string;
|
||||
payload?: string;
|
||||
reason?: string;
|
||||
score?: number;
|
||||
signature?: string;
|
||||
verificationData?: string;
|
||||
verified?: boolean;
|
||||
}
|
||||
export interface SolveChallengeOptions {
|
||||
challenge: Challenge;
|
||||
controller?: AbortController;
|
||||
counterStart?: number;
|
||||
counterStep?: number;
|
||||
counterMode?: "uint32" | "string";
|
||||
deriveKey: DeriveKeyFunction;
|
||||
timeout?: number;
|
||||
}
|
||||
export interface Strings {
|
||||
ariaLinkLabel: string;
|
||||
enterCode: string;
|
||||
enterCodeAria: string;
|
||||
error: string;
|
||||
expired: string;
|
||||
footer: string;
|
||||
getAudioChallenge: string;
|
||||
label: string;
|
||||
loading: string;
|
||||
reload: string;
|
||||
verify: string;
|
||||
verificationRequired: string;
|
||||
verified: string;
|
||||
verifying: string;
|
||||
waitAlert: string;
|
||||
}
|
||||
export declare enum State {
|
||||
CODE = "code",
|
||||
ERROR = "error",
|
||||
VERIFIED = "verified",
|
||||
VERIFYING = "verifying",
|
||||
UNVERIFIED = "unverified",
|
||||
EXPIRED = "expired"
|
||||
}
|
||||
export interface Solution {
|
||||
counter: number;
|
||||
derivedKey: string;
|
||||
time?: number;
|
||||
}
|
||||
export type Store<T extends object, K extends keyof T = keyof T> = {
|
||||
get: (name: K) => T[K];
|
||||
set: <N extends K>(name: N | T, value?: T[N]) => void;
|
||||
store: Writable<T>;
|
||||
};
|
||||
export interface VerifyOptions {
|
||||
concurrency?: number;
|
||||
controller?: AbortController;
|
||||
minDuration?: number;
|
||||
}
|
||||
export interface VerifyResult {
|
||||
challenge?: Challenge;
|
||||
payload: string;
|
||||
solution?: Solution;
|
||||
}
|
||||
export interface VerifyServerSignatureResult extends VerifySolutionResult {
|
||||
verificationData?: ServerSignatureVerificationData | null;
|
||||
}
|
||||
export interface VerifySolutionOptions {
|
||||
challenge: Challenge;
|
||||
counterMode?: "uint32" | "string";
|
||||
deriveKey: DeriveKeyFunction;
|
||||
hmacAlgorithm?: HmacAlgorithm;
|
||||
hmacKeySignatureSecret?: string;
|
||||
hmacSignatureSecret: string;
|
||||
solution: Solution;
|
||||
}
|
||||
export interface VerifySolutionResult {
|
||||
expired: boolean;
|
||||
invalidSignature: boolean | null;
|
||||
invalidSolution: boolean | null;
|
||||
time: number;
|
||||
verified: boolean;
|
||||
}
|
||||
export interface WidgetAttributes extends Partial<Pick<Configuration, "auto" | "display" | "language" | "name" | "type">> {
|
||||
challenge?: string;
|
||||
configuration?: string;
|
||||
}
|
||||
export interface WidgetMethods {
|
||||
configure: (config: Partial<Configuration>) => Promise<void>;
|
||||
getConfiguration: () => Configuration;
|
||||
getState: () => State;
|
||||
hide: () => void;
|
||||
reset: (newState?: State, err?: string | null) => void;
|
||||
setState: (newState: State, err?: string | null) => void;
|
||||
show: () => void;
|
||||
updateUI: () => void;
|
||||
verify: (options?: VerifyOptions) => Promise<VerifyResult | null>;
|
||||
}
|
||||
export type Writable<T = Record<string, Record<string, string>>> = {
|
||||
set(this: void, value: T): void;
|
||||
update(this: void, updater: (value: T) => T): void;
|
||||
subscribe(this: void, run: (value: T) => void, invalidate?: () => void): () => void;
|
||||
};
|
||||
declare function deriveKey(parameters: ChallengeParameters, salt: Uint8Array, password: Uint8Array): Promise<DeriveKeyFunctionResult>;
|
||||
declare function deriveKey$1(parameters: ChallengeParameters, salt: Uint8Array, password: Uint8Array): Promise<DeriveKeyFunctionResult>;
|
||||
declare function deriveKey$2(parameters: ChallengeParameters, salt: Uint8Array, password: Uint8Array): Promise<DeriveKeyFunctionResult>;
|
||||
declare function deriveKey$3(parameters: ChallengeParameters, salt: Uint8Array, password: Uint8Array): Promise<DeriveKeyFunctionResult>;
|
||||
/**
|
||||
* Creates a new proof-of-work challenge.
|
||||
*
|
||||
* Generates random nonce and salt, optionally pre-computes a key prefix
|
||||
* from a known counter value, and optionally signs the challenge with HMAC.
|
||||
*/
|
||||
export declare function createChallenge(options: CreateChallengeOptions): Promise<Challenge>;
|
||||
/**
|
||||
* Solves a challenge by brute-forcing counter values until the derived key
|
||||
* starts with the required prefix. Returns the solution or null on timeout/abort.
|
||||
*/
|
||||
export declare function solveChallenge(options: SolveChallengeOptions): Promise<Solution | null>;
|
||||
/**
|
||||
* Solves a challenge using multiple Web Workers in parallel.
|
||||
* Each worker tests a different subset of counter values (interleaved by concurrency).
|
||||
* Automatically retries with fewer workers on out-of-memory errors.
|
||||
*/
|
||||
export declare function solveChallengeWorkers(options: Omit<SolveChallengeOptions, "deriveKey"> & {
|
||||
concurrency: number;
|
||||
createWorker: (algorithm: string) => Worker | Promise<Worker>;
|
||||
onOutOfMemory?: (concurrency: number) => number | void;
|
||||
}): Promise<Solution | null>;
|
||||
/**
|
||||
* Verifies a submitted solution against a challenge.
|
||||
*
|
||||
* Checks (in order):
|
||||
* 1. Whether the challenge has expired.
|
||||
* 2. Whether the challenge has signature parameter.
|
||||
* 3. Whether the challenge signature is valid (tamper check).
|
||||
* 4. Whether the derived key matches — either via key signature or by re-deriving.
|
||||
*/
|
||||
export declare function verifySolution(options: VerifySolutionOptions): Promise<VerifySolutionResult>;
|
||||
export declare function parseVerificationData(data: string, convertToArray?: string[]): ServerSignatureVerificationData | null;
|
||||
export declare function verifyFieldsHash(options: {
|
||||
formData: FormData | Record<string, unknown>;
|
||||
fields: string[];
|
||||
fieldsHash: string;
|
||||
algorithm?: string;
|
||||
}): Promise<boolean>;
|
||||
export declare function verifyServerSignature(options: {
|
||||
payload: ServerSignaturePayload;
|
||||
hmacSecret: string;
|
||||
}): Promise<VerifyServerSignatureResult>;
|
||||
|
||||
declare namespace sha {
|
||||
export { deriveKey$3 as deriveKey };
|
||||
}
|
||||
declare namespace argon2id {
|
||||
export { deriveKey };
|
||||
}
|
||||
declare namespace pbkdf2 {
|
||||
export { deriveKey$1 as deriveKey };
|
||||
}
|
||||
declare namespace scrypt {
|
||||
export { deriveKey$2 as deriveKey };
|
||||
}
|
||||
|
||||
export {
|
||||
argon2id,
|
||||
pbkdf2,
|
||||
scrypt,
|
||||
sha,
|
||||
};
|
||||
|
||||
export {};
|
||||
+1422
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
function A(A,I,g,i){return new(g||(g=Promise))(function(I,B){function Q(A){try{e(i.next(A))}catch(A){B(A)}}function C(A){try{e(i.throw(A))}catch(A){B(A)}}function e(A){var i;A.done?I(A.value):(i=A.value,i instanceof g?i:new g(function(A){A(i)})).then(Q,C)}e((i=i.apply(A,[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class I{constructor(){this.mutex=Promise.resolve()}lock(){let A=()=>{};return this.mutex=this.mutex.then(()=>new Promise(A)),new Promise(I=>{A=I})}dispatch(I){return A(this,0,void 0,function*(){const A=yield this.lock();try{return yield Promise.resolve(I())}finally{A()}})}}var g;const i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,B=null!==(g=i.Buffer)&&void 0!==g?g:null,Q=i.TextEncoder?new i.TextEncoder:null;function C(A,I){return(15&A)+(A>>6|A>>3&8)<<4|(15&I)+(I>>6|I>>3&8)}function e(A,I){const g=I.length>>1;for(let i=0;i<g;i++){const g=i<<1;A[i]=C(I.charCodeAt(g),I.charCodeAt(g+1))}}const E="a".charCodeAt(0)-10,t="0".charCodeAt(0);function o(A,I,g){let i=0;for(let B=0;B<g;B++){let g=I[B]>>>4;A[i++]=g>9?g+E:g+t,g=15&I[B],A[i++]=g>9?g+E:g+t}return String.fromCharCode.apply(null,A)}const n=null!==B?A=>{if("string"==typeof A){const I=B.from(A,"utf8");return new Uint8Array(I.buffer,I.byteOffset,I.length)}if(B.isBuffer(A))return new Uint8Array(A.buffer,A.byteOffset,A.length);if(ArrayBuffer.isView(A))return new Uint8Array(A.buffer,A.byteOffset,A.byteLength);throw new Error("Invalid data type!")}:A=>{if("string"==typeof A)return Q.encode(A);if(ArrayBuffer.isView(A))return new Uint8Array(A.buffer,A.byteOffset,A.byteLength);throw new Error("Invalid data type!")},a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=new Uint8Array(256);for(let A=0;A<64;A++)c[a.charCodeAt(A)]=A;function r(A,I=!0){const g=A.length,i=g%3,B=[],Q=g-i;for(let I=0;I<Q;I+=3){const g=(A[I]<<16&16711680)+(A[I+1]<<8&65280)+(255&A[I+2]),i=a.charAt(g>>18&63)+a.charAt(g>>12&63)+a.charAt(g>>6&63)+a.charAt(63&g);B.push(i)}if(1===i){const i=A[g-1],Q=a.charAt(i>>2),C=a.charAt(i<<4&63);B.push(`${Q}${C}`),I&&B.push("==")}else if(2===i){const i=(A[g-2]<<8)+A[g-1],Q=a.charAt(i>>10),C=a.charAt(i>>4&63),e=a.charAt(i<<2&63);B.push(`${Q}${C}${e}`),I&&B.push("=")}return B.join("")}function h(A){const I=function(A){let I=Math.floor(.75*A.length);const g=A.length;return"="===A[g-1]&&(I-=1,"="===A[g-2]&&(I-=1)),I}(A),g=A.length,i=new Uint8Array(I);let B=0;for(let I=0;I<g;I+=4){const g=c[A.charCodeAt(I)],Q=c[A.charCodeAt(I+1)],C=c[A.charCodeAt(I+2)],e=c[A.charCodeAt(I+3)];i[B]=g<<2|Q>>4,B+=1,i[B]=(15&Q)<<4|C>>2,B+=1,i[B]=(3&C)<<6|63&e,B+=1}return i}const w=16384,D=new I,d=new Map;function y(I,g){return A(this,0,void 0,function*(){let i=null,B=null,Q=!1;if("undefined"==typeof WebAssembly)throw new Error("WebAssembly is not supported in this environment!");const E=()=>new DataView(i.exports.memory.buffer).getUint32(i.exports.STATE_SIZE,!0),t=D.dispatch(()=>A(this,0,void 0,function*(){if(!d.has(I.name)){const A=h(I.data),g=WebAssembly.compile(A);d.set(I.name,g)}const A=yield d.get(I.name);i=yield WebAssembly.instantiate(A,{})})),a=(A=null)=>{Q=!0,i.exports.Hash_Init(A)},c=A=>{if(!Q)throw new Error("update() called before init()");(A=>{let I=0;for(;I<A.length;){const g=A.subarray(I,I+w);I+=g.length,B.set(g),i.exports.Hash_Update(g.length)}})(n(A))},r=new Uint8Array(2*g),y=(A,I=null)=>{if(!Q)throw new Error("digest() called before init()");return Q=!1,i.exports.Hash_Final(I),"binary"===A?B.slice(0,g):o(r,B,g)},F=A=>"string"==typeof A?A.length<4096:A.byteLength<w;let k=F;switch(I.name){case"argon2":case"scrypt":k=()=>!0;break;case"blake2b":case"blake2s":k=(A,I)=>I<=512&&F(A);break;case"blake3":k=(A,I)=>0===I&&F(A);break;case"xxhash64":case"xxhash3":case"xxhash128":case"crc64":k=()=>!1}return yield(()=>A(this,0,void 0,function*(){i||(yield t);const A=i.exports.Hash_GetBuffer(),I=i.exports.memory.buffer;B=new Uint8Array(I,A,w)}))(),{getMemory:()=>B,writeMemory:(A,I=0)=>{B.set(A,I)},getExports:()=>i.exports,setMemorySize:A=>{i.exports.Hash_SetMemorySize(A);const I=i.exports.Hash_GetBuffer(),g=i.exports.memory.buffer;B=new Uint8Array(g,I,A)},init:a,update:c,digest:y,save:()=>{if(!Q)throw new Error("save() can only be called after init() and before digest()");const A=i.exports.Hash_GetState(),g=E(),B=i.exports.memory.buffer,C=new Uint8Array(B,A,g),t=new Uint8Array(4+g);return e(t,I.hash),t.set(C,4),t},load:A=>{if(!(A instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");const g=i.exports.Hash_GetState(),B=E(),e=4+B,t=i.exports.memory.buffer;if(A.length!==e)throw new Error(`Bad state length (expected ${e} bytes, got ${A.length})`);if(!function(A,I){if(A.length!==2*I.length)return!1;for(let g=0;g<I.length;g++){const i=g<<1;if(I[g]!==C(A.charCodeAt(i),A.charCodeAt(i+1)))return!1}return!0}(I.hash,A.subarray(0,4)))throw new Error("This state was written by an incompatible hash implementation");const o=A.subarray(4);new Uint8ALine truncated
|
||||
+1426
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
!function(A,I){"object"==typeof exports&&"undefined"!=typeof module?I(exports):"function"==typeof define&&define.amd?define(["exports"],I):I((A="undefined"!=typeof globalThis?globalThis:A||self).plibow={})}(this,function(A){"use strict";function I(A,I,g,i){return new(g||(g=Promise))(function(I,B){function Q(A){try{e(i.next(A))}catch(A){B(A)}}function C(A){try{e(i.throw(A))}catch(A){B(A)}}function e(A){var i;A.done?I(A.value):(i=A.value,i instanceof g?i:new g(function(A){A(i)})).then(Q,C)}e((i=i.apply(A,[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class g{constructor(){this.mutex=Promise.resolve()}lock(){let A=()=>{};return this.mutex=this.mutex.then(()=>new Promise(A)),new Promise(I=>{A=I})}dispatch(A){return I(this,0,void 0,function*(){const I=yield this.lock();try{return yield Promise.resolve(A())}finally{I()}})}}var i;const B="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,Q=null!==(i=B.Buffer)&&void 0!==i?i:null,C=B.TextEncoder?new B.TextEncoder:null;function e(A,I){return(15&A)+(A>>6|A>>3&8)<<4|(15&I)+(I>>6|I>>3&8)}function E(A,I){const g=I.length>>1;for(let i=0;i<g;i++){const g=i<<1;A[i]=e(I.charCodeAt(g),I.charCodeAt(g+1))}}const t="a".charCodeAt(0)-10,o="0".charCodeAt(0);function n(A,I,g){let i=0;for(let B=0;B<g;B++){let g=I[B]>>>4;A[i++]=g>9?g+t:g+o,g=15&I[B],A[i++]=g>9?g+t:g+o}return String.fromCharCode.apply(null,A)}const a=null!==Q?A=>{if("string"==typeof A){const I=Q.from(A,"utf8");return new Uint8Array(I.buffer,I.byteOffset,I.length)}if(Q.isBuffer(A))return new Uint8Array(A.buffer,A.byteOffset,A.length);if(ArrayBuffer.isView(A))return new Uint8Array(A.buffer,A.byteOffset,A.byteLength);throw new Error("Invalid data type!")}:A=>{if("string"==typeof A)return C.encode(A);if(ArrayBuffer.isView(A))return new Uint8Array(A.buffer,A.byteOffset,A.byteLength);throw new Error("Invalid data type!")},c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=new Uint8Array(256);for(let A=0;A<64;A++)r[c.charCodeAt(A)]=A;function h(A,I=!0){const g=A.length,i=g%3,B=[],Q=g-i;for(let I=0;I<Q;I+=3){const g=(A[I]<<16&16711680)+(A[I+1]<<8&65280)+(255&A[I+2]),i=c.charAt(g>>18&63)+c.charAt(g>>12&63)+c.charAt(g>>6&63)+c.charAt(63&g);B.push(i)}if(1===i){const i=A[g-1],Q=c.charAt(i>>2),C=c.charAt(i<<4&63);B.push(`${Q}${C}`),I&&B.push("==")}else if(2===i){const i=(A[g-2]<<8)+A[g-1],Q=c.charAt(i>>10),C=c.charAt(i>>4&63),e=c.charAt(i<<2&63);B.push(`${Q}${C}${e}`),I&&B.push("=")}return B.join("")}function w(A){const I=function(A){let I=Math.floor(.75*A.length);const g=A.length;return"="===A[g-1]&&(I-=1,"="===A[g-2]&&(I-=1)),I}(A),g=A.length,i=new Uint8Array(I);let B=0;for(let I=0;I<g;I+=4){const g=r[A.charCodeAt(I)],Q=r[A.charCodeAt(I+1)],C=r[A.charCodeAt(I+2)],e=r[A.charCodeAt(I+3)];i[B]=g<<2|Q>>4,B+=1,i[B]=(15&Q)<<4|C>>2,B+=1,i[B]=(3&C)<<6|63&e,B+=1}return i}const D=16384,d=new g,y=new Map;function F(A,g){return I(this,0,void 0,function*(){let i=null,B=null,Q=!1;if("undefined"==typeof WebAssembly)throw new Error("WebAssembly is not supported in this environment!");const C=()=>new DataView(i.exports.memory.buffer).getUint32(i.exports.STATE_SIZE,!0),t=d.dispatch(()=>I(this,0,void 0,function*(){if(!y.has(A.name)){const I=w(A.data),g=WebAssembly.compile(I);y.set(A.name,g)}const I=yield y.get(A.name);i=yield WebAssembly.instantiate(I,{})})),o=(A=null)=>{Q=!0,i.exports.Hash_Init(A)},c=A=>{if(!Q)throw new Error("update() called before init()");(A=>{let I=0;for(;I<A.length;){const g=A.subarray(I,I+D);I+=g.length,B.set(g),i.exports.Hash_Update(g.length)}})(a(A))},r=new Uint8Array(2*g),h=(A,I=null)=>{if(!Q)throw new Error("digest() called before init()");return Q=!1,i.exports.Hash_Final(I),"binary"===A?B.slice(0,g):n(r,B,g)},F=A=>"string"==typeof A?A.length<4096:A.byteLength<D;let s=F;switch(A.name){case"argon2":case"scrypt":s=()=>!0;break;case"blake2b":case"blake2s":s=(A,I)=>I<=512&&F(A);break;case"blake3":s=(A,I)=>0===I&&F(A);break;case"xxhash64":case"xxhash3":case"xxhash128":case"crc64":s=()=>!1}return yield(()=>I(this,0,void 0,function*(){i||(yield t);const A=i.exports.Hash_GetBuffer(),I=i.exports.memory.buffer;B=new Uint8Array(I,A,D)}))(),{getMemory:()=>B,writeMemory:(A,I=0)=>{B.set(A,I)},getExports:()=>i.exports,setMemorySize:A=>{i.exports.Hash_SetMemorySize(A);const I=i.exports.Hash_GetBuffer(),g=i.exports.memory.buffer;B=new Uint8Array(g,I,A)},init:o,update:c,digest:h,save:()=>{if(!Q)throw new Error("save() can only be called after init() and before digest()");const I=i.exports.Hash_GetState(),g=C(),B=i.exports.memory.buffer,e=new Uint8Array(B,I,g),t=new Uint8Array(4+g);return E(t,A.hash),t.set(e,4),t},load:I=>{if(!(I instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");const g=i.exports.Hash_GetState(),B=C(),E=4+B,t=i.exports.memory.buffer;if(I.length!==E)throw new Error(`Bad state length (expected ${E} bytes, got ${I.length})`);if(!function(A,I){if(A.length!==2*I.length)return!1;for(letLine truncated
|
||||
Reference in new issue
Block a user