Skip to content

Commit

Permalink
Merge pull request #3 from schwarmco/export-default
Browse files Browse the repository at this point in the history
Add Default Exports
  • Loading branch information
ovx authored Apr 18, 2024
2 parents 55fb530 + 0d1da4d commit 7e5fd00
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
7 changes: 7 additions & 0 deletions cjs/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
controller: AbortController;
};
export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
declare const _default: {
createChallenge: typeof createChallenge;
verifySolution: typeof verifySolution;
solveChallenge: typeof solveChallenge;
solveChallengeWorkers: typeof solveChallengeWorkers;
};
export default _default;
6 changes: 6 additions & 0 deletions cjs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ exports.solveChallengeWorkers = solveChallengeWorkers;
async function hashChallenge(salt, num, algorithm) {
return (0, helpers_js_1.ab2hex)(await crypto.subtle.digest(algorithm.toUpperCase(), helpers_js_1.encoder.encode(salt + num)));
}
exports.default = {
createChallenge,
verifySolution,
solveChallenge,
solveChallengeWorkers,
};
20 changes: 9 additions & 11 deletions deno_dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ALTCHA JS Library is a lightweight, zero-dependency library designed for creatin

## Compatibility

This library utilizes [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) and can be used in modern browsers and supported server environments:
This library utilizes [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) and is intended for server-side use.

- Node.js 16+
- Bun 1+
Expand Down Expand Up @@ -103,18 +103,16 @@ const solution = await solveChallengeWorkers(

```
> solveChallenge()
- n = 1,000............................... 319 ops/s ±2.04%
- n = 10,000.............................. 31 ops/s ±1.02%
- n = 50,000.............................. 6 ops/s ±1.48%
- n = 100,000............................. 3 ops/s ±0.27%
- n = 500,000............................. 0 ops/s ±0.36%
- n = 1,000............................... 317 ops/s ±2.63%
- n = 10,000.............................. 32 ops/s ±1.88%
- n = 100,000............................. 3 ops/s ±0.34%
- n = 500,000............................. 0 ops/s ±0.32%
> solveChallengeWorkers() (8 workers)
- n = 1,000............................... 62 ops/s ±5.69%
- n = 10,000.............................. 30 ops/s ±4.35%
- n = 50,000.............................. 12 ops/s ±2.89%
- n = 100,000............................. 7 ops/s ±2.33%
- n = 500,000............................. 1 ops/s ±2.22%
- n = 1,000............................... 66 ops/s ±3.44%
- n = 10,000.............................. 31 ops/s ±4.28%
- n = 100,000............................. 7 ops/s ±4.40%
- n = 500,000............................. 1 ops/s ±2.49%
```

Run with Bun on MacBook Pro M3-Pro. See [/benchmark](/benchmark/) folder for more details.
Expand Down
7 changes: 7 additions & 0 deletions deno_dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ async function hashChallenge(salt: string, num: number, algorithm: string) {
)
);
}

export default {
createChallenge,
verifySolution,
solveChallenge,
solveChallengeWorkers,
};
7 changes: 7 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
controller: AbortController;
};
export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
declare const _default: {
createChallenge: typeof createChallenge;
verifySolution: typeof verifySolution;
solveChallenge: typeof solveChallenge;
solveChallengeWorkers: typeof solveChallengeWorkers;
};
export default _default;
6 changes: 6 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ export async function solveChallengeWorkers(workerScript, concurrency, challenge
async function hashChallenge(salt, num, algorithm) {
return ab2hex(await crypto.subtle.digest(algorithm.toUpperCase(), encoder.encode(salt + num)));
}
export default {
createChallenge,
verifySolution,
solveChallenge,
solveChallengeWorkers,
};
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ async function hashChallenge(salt: string, num: number, algorithm: string) {
)
);
}

export default {
createChallenge,
verifySolution,
solveChallenge,
solveChallengeWorkers,
};

0 comments on commit 7e5fd00

Please sign in to comment.