Spaces:
Running on Zero
Running on Zero
Add optional HF OAuth visitor identity for Protected GPU requests
Browse files- BETA_TESTING.md +6 -4
- DATA_POLICY.md +19 -1
- FRONTEND_SOURCE.json +1 -1
- README.md +5 -1
- RELEASE_MANIFEST.json +15 -9
- STORAGE_BOUNDARY.md +2 -1
- app.py +6 -0
- client.js +23 -5
- hf-auth-callback.html +12 -0
- hf-auth.js +80 -0
- hf_identity.py +32 -0
- index.html +3 -2
- server.py +13 -1
- vendor/hf-oauth/LICENSE +21 -0
- vendor/hf-oauth/index.js +2738 -0
- vendor/hf-oauth/package.json +75 -0
BETA_TESTING.md
CHANGED
|
@@ -15,14 +15,16 @@ URL for Protected Spaces. Source access is not required for anonymous CPU use.
|
|
| 15 |
CPU processing and complete browser usability are separate acceptance checks.
|
| 16 |
The interface permits GPU on the direct entry when the server reports it available;
|
| 17 |
HF still enforces quota. Direct GPU may use the limited anonymous allowance.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
Before remote testers receive the expanded interface:
|
| 23 |
|
| 24 |
1. Freeze an allow-listed clean package and verify its manifest.
|
| 25 |
-
2. Deploy it to the existing
|
| 26 |
3. Verify hosted CPU and one bounded GPU upload → run → download → deletion path
|
| 27 |
using disposable, user-owned/generated files. Check HF allowance before GPU.
|
| 28 |
4. Confirm recipe persistence/import/export and batch completion/stop in both
|
|
|
|
| 15 |
CPU processing and complete browser usability are separate acceptance checks.
|
| 16 |
The interface permits GPU on the direct entry when the server reports it available;
|
| 17 |
HF still enforces quota. Direct GPU may use the limited anonymous allowance.
|
| 18 |
+
Optional HF sign-in identifies the visitor through an official PKCE flow using
|
| 19 |
+
openid/profile only. Tokens stay in page memory; no personal-token field or app
|
| 20 |
+
password is introduced. Verify HF identity — no GPU checks the same queue/client
|
| 21 |
+
credential path before a run. Hosted OAuth/account-quota acceptance must still
|
| 22 |
+
be qualified for each build; a completed anonymous run is not account attribution.
|
| 23 |
|
| 24 |
Before remote testers receive the expanded interface:
|
| 25 |
|
| 26 |
1. Freeze an allow-listed clean package and verify its manifest.
|
| 27 |
+
2. Deploy it to the existing Protected test Space without changing visibility.
|
| 28 |
3. Verify hosted CPU and one bounded GPU upload → run → download → deletion path
|
| 29 |
using disposable, user-owned/generated files. Check HF allowance before GPU.
|
| 30 |
4. Confirm recipe persistence/import/export and batch completion/stop in both
|
DATA_POLICY.md
CHANGED
|
@@ -16,7 +16,7 @@ uploads and run history are disabled. These restrictions are not secure RAM eras
|
|
| 16 |
|
| 17 |
Each job uses temporary files removed before a successful result is published.
|
| 18 |
The application result store is memory-only. No public file URL is created.
|
| 19 |
-
The browser holds a random job access key in memory,
|
| 20 |
Anyone who obtains that key can access the job; do not share it. Reloading the
|
| 21 |
page loses access. Expiry is fixed at 30 minutes from result publication.
|
| 22 |
|
|
@@ -34,6 +34,24 @@ This is deletion of application-controlled files and stored results, not a claim
|
|
| 34 |
of physical RAM/disk erasure, prevention of swap, or deletion of response buffers.
|
| 35 |
No claim is made about hosting-provider logs or infrastructure retention.
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
Results received by the browser and files saved locally are the user's to manage.
|
| 38 |
The browser retains its received result in page memory so Save received result
|
| 39 |
again can retry a local save without another server retrieval. Discard browser
|
|
|
|
| 16 |
|
| 17 |
Each job uses temporary files removed before a successful result is published.
|
| 18 |
The application result store is memory-only. No public file URL is created.
|
| 19 |
+
The browser holds a random job access key in memory, independently of optional HF sign-in.
|
| 20 |
Anyone who obtains that key can access the job; do not share it. Reloading the
|
| 21 |
page loses access. Expiry is fixed at 30 minutes from result publication.
|
| 22 |
|
|
|
|
| 34 |
of physical RAM/disk erasure, prevention of swap, or deletion of response buffers.
|
| 35 |
No claim is made about hosting-provider logs or infrastructure retention.
|
| 36 |
|
| 37 |
+
Optional HF sign-in uses the official HF OAuth authorization-code/PKCE flow with
|
| 38 |
+
only openid/profile scopes. Credentials and basic profile details live in browser
|
| 39 |
+
page memory, not cookies, localStorage, recipes, or a server session database.
|
| 40 |
+
HF handles password entry and authorization. The callback briefly carries a
|
| 41 |
+
one-use authorization code and state in its URL; the app clears that URL before
|
| 42 |
+
returning to the main window. HF/proxy infrastructure handling is outside this
|
| 43 |
+
application's deletion guarantee. The app does not request email, billing,
|
| 44 |
+
repository access, or persistent bucket access.
|
| 45 |
+
|
| 46 |
+
A non-GPU queue check forwards the visitor bearer credential to HF's fixed
|
| 47 |
+
userinfo endpoint and returns only the username, PRO flag, and authentication
|
| 48 |
+
path. The queue also receives that visitor credential for GPU calls. Credentials
|
| 49 |
+
are never sent to the native simulator or written to application logs/results.
|
| 50 |
+
HF and framework transient request buffers remain outside secure-erasure claims.
|
| 51 |
+
Sign out clears this page's credential; expiry or closing/reloading the page also
|
| 52 |
+
loses it. Sign out does not revoke the HF OAuth grant or sign out of HF itself;
|
| 53 |
+
users may revoke the grant in HF account settings. CPU does not require sign-in.
|
| 54 |
+
|
| 55 |
Results received by the browser and files saved locally are the user's to manage.
|
| 56 |
The browser retains its received result in page memory so Save received result
|
| 57 |
again can retry a local save without another server retrieval. Discard browser
|
FRONTEND_SOURCE.json
CHANGED
|
@@ -4,5 +4,5 @@
|
|
| 4 |
"output_sha256": "135a0c57be851af2879660ae6584a4bfa0a9280fc33e2c0372bc47b531f1960f",
|
| 5 |
"scope": "Frontend only; no engine, private data, track assets, API calls or storage copied",
|
| 6 |
"status": "Local candidate: configurable training, browser recipes, bounded sequential batches, browser network editor; track renderer and star evaluation unconnected",
|
| 7 |
-
"candidate_sha256": "
|
| 8 |
}
|
|
|
|
| 4 |
"output_sha256": "135a0c57be851af2879660ae6584a4bfa0a9280fc33e2c0372bc47b531f1960f",
|
| 5 |
"scope": "Frontend only; no engine, private data, track assets, API calls or storage copied",
|
| 6 |
"status": "Local candidate: configurable training, browser recipes, bounded sequential batches, browser network editor; track renderer and star evaluation unconnected",
|
| 7 |
+
"candidate_sha256": "9e5b6bd69dd587f0e5c0f551b291de4d6a729e601916042cde0449ba2162bee8"
|
| 8 |
}
|
README.md
CHANGED
|
@@ -4,9 +4,11 @@ sdk: gradio
|
|
| 4 |
sdk_version: 6.29.1
|
| 5 |
python_version: "3.10"
|
| 6 |
app_file: app.py
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
-
|
| 10 |
Simulator: https://github.com/Zorro909/driving_sim_rs
|
| 11 |
Hosting adaptation and UI: TiGa https://github.com/seeker-cyber-maker/driving_sim_rs
|
| 12 |
CPU is the default; GPU requests explicitly use ZeroGPU. No automatic fallback. No bundled tracks or networks.
|
|
@@ -17,3 +19,5 @@ Expanded runner UI beta candidate: configurable training, settings-only browser
|
|
| 17 |
recipes, bounded sequential batches, browser-local network creation/editing.
|
| 18 |
Track rendering and star evaluation are not connected. This new package is
|
| 19 |
not hosted-qualified. See BETA_TESTING.md and STORAGE_BOUNDARY.md.
|
|
|
|
|
|
|
|
|
| 4 |
sdk_version: 6.29.1
|
| 5 |
python_version: "3.10"
|
| 6 |
app_file: app.py
|
| 7 |
+
hf_oauth: true
|
| 8 |
+
hf_oauth_expiration_minutes: 60
|
| 9 |
---
|
| 10 |
|
| 11 |
+
Protected CPU/ZeroGPU integration candidate. Custom interface with Gradio Server on port 7860.
|
| 12 |
Simulator: https://github.com/Zorro909/driving_sim_rs
|
| 13 |
Hosting adaptation and UI: TiGa https://github.com/seeker-cyber-maker/driving_sim_rs
|
| 14 |
CPU is the default; GPU requests explicitly use ZeroGPU. No automatic fallback. No bundled tracks or networks.
|
|
|
|
| 19 |
recipes, bounded sequential batches, browser-local network creation/editing.
|
| 20 |
Track rendering and star evaluation are not connected. This new package is
|
| 21 |
not hosted-qualified. See BETA_TESTING.md and STORAGE_BOUNDARY.md.
|
| 22 |
+
|
| 23 |
+
Optional HF OAuth: openid/profile only. CPU remains anonymous. Visitor tokens live in browser memory; queue identity is checked before GPU dispatch. No personal token entry, server session store, or automatic CPU fallback.
|
RELEASE_MANIFEST.json
CHANGED
|
@@ -1,30 +1,36 @@
|
|
| 1 |
{
|
| 2 |
"backend": "cpu+zerogpu",
|
| 3 |
"files": {
|
| 4 |
-
"BETA_TESTING.md": "
|
| 5 |
-
"DATA_POLICY.md": "
|
| 6 |
-
"FRONTEND_SOURCE.json": "
|
| 7 |
"GODOT_LICENSE": "fb2b3bb82c60f1e76841ba2122eb902f8e39c151476fe21ce10c9a05d1045304",
|
| 8 |
"IMPORTER_BUILD_RECEIPT.json": "4ba5c533cc617105478e4d85c83f456a7dfa68b1388049624619871ba9e42e9d",
|
| 9 |
"LICENSE": "53d5851b6440feeae36f72a5f57fcab37858c48b7084765ece4b0c54b9a28ed8",
|
| 10 |
-
"README.md": "
|
| 11 |
-
"STORAGE_BOUNDARY.md": "
|
| 12 |
-
"app.py": "
|
| 13 |
"app_release.py": "7482559c667a665fd3cb6aa8af6c78422a822b515e14589db8306f7fd4860a8b",
|
| 14 |
"assets/formula_template.json": "80f745df82bb7be45af52785fd582460bcddc63c5a4e1d8375d85b3122db4c6b",
|
| 15 |
"bin/altd-sim": "2f2f2144ae14b0ef599ca8510f95712da00243c6875881491d384b394e7499f7",
|
| 16 |
"bin/extract_saved_track": "3a7733c45b4301a786fcbfe92660a1c484749272da5f608d62f34878bd4ff31a",
|
| 17 |
"bin/libaltd_gpu.so": "279d6353b4c691686d6aeeae6abfd4a82b959e9b604f079a6c45f9823b48a87a",
|
| 18 |
-
"client.js": "
|
| 19 |
"delivery.py": "4f5a4e45df92e5cbfdef6eb449ede9ba26217fe24da376fafddae5cbbb73847a",
|
| 20 |
"gpu_tickets.py": "c32cb5de751d49d3e1cd970c7d6328a42ebe71602dd9fd3788c872eef42611da",
|
| 21 |
-
"
|
|
|
|
|
|
|
|
|
|
| 22 |
"requirements.txt": "9b532747e51bd052e82090ece860d6dafe027407f4512dc74272c148ea104c22",
|
| 23 |
-
"server.py": "
|
| 24 |
"training_config.py": "2b9768876fdc60b16afb45b98023c6c31666e30f7c56f1292f6071775e6da0c5",
|
| 25 |
"vendor/gradio-client/LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4",
|
| 26 |
"vendor/gradio-client/dist/index.min.js": "fdd776db8633354f118fe2908c980592283968737e6b91dc3aa86d648da5c3fd",
|
| 27 |
"vendor/gradio-client/package.json": "96c5b9e6d3587fb7bd8e5bb28775ece222de1043045afc4e6389c88db137ad0e",
|
|
|
|
|
|
|
|
|
|
| 28 |
"worker.py": "934fb941a7f73a82c9bbcff5f3290103d4dd55e66542e71d56ae8fe7101f0e57"
|
| 29 |
},
|
| 30 |
"hosted_verified": false,
|
|
|
|
| 1 |
{
|
| 2 |
"backend": "cpu+zerogpu",
|
| 3 |
"files": {
|
| 4 |
+
"BETA_TESTING.md": "d511965b9d675a092571f8815348da991ef1ef6be3766266c1f98ff393fd3a4d",
|
| 5 |
+
"DATA_POLICY.md": "72bf2be8b87d948501ea44cbdcb2d6d7680f7387ed1c39fd1d3afdf094cf5487",
|
| 6 |
+
"FRONTEND_SOURCE.json": "1e31b153757fd42c3bc2abaa1982a44e19a2ed7dc259d32781f36bb9a3ee10b7",
|
| 7 |
"GODOT_LICENSE": "fb2b3bb82c60f1e76841ba2122eb902f8e39c151476fe21ce10c9a05d1045304",
|
| 8 |
"IMPORTER_BUILD_RECEIPT.json": "4ba5c533cc617105478e4d85c83f456a7dfa68b1388049624619871ba9e42e9d",
|
| 9 |
"LICENSE": "53d5851b6440feeae36f72a5f57fcab37858c48b7084765ece4b0c54b9a28ed8",
|
| 10 |
+
"README.md": "11abed635d4192b5ea8d8891fc38e3a60989ad5b4696683d0321f3bc12eba20f",
|
| 11 |
+
"STORAGE_BOUNDARY.md": "3b91d8db71ece1bb55f38685610d722b162a78af0a602926c16792075e48ef99",
|
| 12 |
+
"app.py": "704f789a41846b0a5bc1d3f6f5305d7ac5a6b1719ff77c23585b89fd3e68d55d",
|
| 13 |
"app_release.py": "7482559c667a665fd3cb6aa8af6c78422a822b515e14589db8306f7fd4860a8b",
|
| 14 |
"assets/formula_template.json": "80f745df82bb7be45af52785fd582460bcddc63c5a4e1d8375d85b3122db4c6b",
|
| 15 |
"bin/altd-sim": "2f2f2144ae14b0ef599ca8510f95712da00243c6875881491d384b394e7499f7",
|
| 16 |
"bin/extract_saved_track": "3a7733c45b4301a786fcbfe92660a1c484749272da5f608d62f34878bd4ff31a",
|
| 17 |
"bin/libaltd_gpu.so": "279d6353b4c691686d6aeeae6abfd4a82b959e9b604f079a6c45f9823b48a87a",
|
| 18 |
+
"client.js": "79a34470942132a4e4a4100ae92b805ff02f7fe344e7962cfcff6a1208cef54a",
|
| 19 |
"delivery.py": "4f5a4e45df92e5cbfdef6eb449ede9ba26217fe24da376fafddae5cbbb73847a",
|
| 20 |
"gpu_tickets.py": "c32cb5de751d49d3e1cd970c7d6328a42ebe71602dd9fd3788c872eef42611da",
|
| 21 |
+
"hf-auth-callback.html": "07a753a8a70a145d4fc22ae4b259259f4aa202e3d3ae58b9077d271a8ccb7928",
|
| 22 |
+
"hf-auth.js": "d39981c98eec48d941a8e8b31b49ba0c44b7debe628c92681dfd26324782e545",
|
| 23 |
+
"hf_identity.py": "6993d0238ada835606dbdc3275c17a3fe5a5cac5ad2156ab78230acf2d051eba",
|
| 24 |
+
"index.html": "9e5b6bd69dd587f0e5c0f551b291de4d6a729e601916042cde0449ba2162bee8",
|
| 25 |
"requirements.txt": "9b532747e51bd052e82090ece860d6dafe027407f4512dc74272c148ea104c22",
|
| 26 |
+
"server.py": "f0fa001000a55503ac62498105cb9f3a3798051582eac27c46b56ff592d5c734",
|
| 27 |
"training_config.py": "2b9768876fdc60b16afb45b98023c6c31666e30f7c56f1292f6071775e6da0c5",
|
| 28 |
"vendor/gradio-client/LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4",
|
| 29 |
"vendor/gradio-client/dist/index.min.js": "fdd776db8633354f118fe2908c980592283968737e6b91dc3aa86d648da5c3fd",
|
| 30 |
"vendor/gradio-client/package.json": "96c5b9e6d3587fb7bd8e5bb28775ece222de1043045afc4e6389c88db137ad0e",
|
| 31 |
+
"vendor/hf-oauth/LICENSE": "d6e7b19451c1b3d1d66353bb4b1274138953b3bfd9ae60c56e77b1f548796982",
|
| 32 |
+
"vendor/hf-oauth/index.js": "53282844000a171011e547f6472a3846bb4cecb5071adafea079fcac3a2aee7e",
|
| 33 |
+
"vendor/hf-oauth/package.json": "fafd4d8891023a1961546a7d3bc25cd24f64923a2ebfc449fe6d516a2949bda8",
|
| 34 |
"worker.py": "934fb941a7f73a82c9bbcff5f3290103d4dd55e66542e71d56ae8fe7101f0e57"
|
| 35 |
},
|
| 36 |
"hosted_verified": false,
|
STORAGE_BOUNDARY.md
CHANGED
|
@@ -12,6 +12,7 @@ same settings contract is used independently of the selected storage policy.
|
|
| 12 |
| Single-run output | Memory result store and random job key | Receipt ACK in automatic mode, manual delete, fixed 30-minute expiry, or shutdown |
|
| 13 |
| Batch intermediates | Same job contract, always automatic | Verified size/hash and deletion ACK before advancement |
|
| 14 |
| Received candidate / receipt | Browser page memory | Explicit discard, replacement, page reload/close; explicit export to disk |
|
|
|
|
| 15 |
| User bucket | Not implemented | Must require an explicit opt-in adapter and separate retention policy |
|
| 16 |
|
| 17 |
`recipes.cjs` has no host/network dependency. Its `createStore(storage)` receives
|
|
@@ -21,7 +22,7 @@ bytes to recipe JSON. A public profile must not inherit private persistent
|
|
| 21 |
artifact storage implicitly. Server cleanup must never clear the recipe library;
|
| 22 |
clearing recipes must never delete a server job, bucket, or downloaded file.
|
| 23 |
|
| 24 |
-
The current app has no bucket credentials, HF identity storage, telemetry, or
|
| 25 |
automatic recipe upload. Browser-local storage is site-specific and may be
|
| 26 |
blocked by browser privacy settings. A local runner and an HF iframe do not
|
| 27 |
automatically share their library; explicit JSON export/import is the bridge.
|
|
|
|
| 12 |
| Single-run output | Memory result store and random job key | Receipt ACK in automatic mode, manual delete, fixed 30-minute expiry, or shutdown |
|
| 13 |
| Batch intermediates | Same job contract, always automatic | Verified size/hash and deletion ACK before advancement |
|
| 14 |
| Received candidate / receipt | Browser page memory | Explicit discard, replacement, page reload/close; explicit export to disk |
|
| 15 |
+
| Optional HF identity / token / PKCE state | Browser page memory, separate from job/recipe storage | Sign out, expiry, or page reload/close; no app auth cookie or server session database |
|
| 16 |
| User bucket | Not implemented | Must require an explicit opt-in adapter and separate retention policy |
|
| 17 |
|
| 18 |
`recipes.cjs` has no host/network dependency. Its `createStore(storage)` receives
|
|
|
|
| 22 |
artifact storage implicitly. Server cleanup must never clear the recipe library;
|
| 23 |
clearing recipes must never delete a server job, bucket, or downloaded file.
|
| 24 |
|
| 25 |
+
The current app has no bucket credentials, persistent HF identity storage, telemetry, or
|
| 26 |
automatic recipe upload. Browser-local storage is site-specific and may be
|
| 27 |
blocked by browser privacy settings. A local runner and an HF iframe do not
|
| 28 |
automatically share their library; explicit JSON export/import is the bridge.
|
app.py
CHANGED
|
@@ -19,6 +19,7 @@ from gpu_tickets import InputTickets
|
|
| 19 |
from server import create_app
|
| 20 |
from worker import run_native,track_input,network_input
|
| 21 |
from training_config import validate_config
|
|
|
|
| 22 |
|
| 23 |
def build_app(cuda_call):
|
| 24 |
base=create_app(worker=cpu_worker)
|
|
@@ -86,6 +87,11 @@ def build_app(cuda_call):
|
|
| 86 |
return {**base.state.results.publish(payload,automatic),'backend':'gpu','report':report}
|
| 87 |
finally:admission.release()
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# Existing download/status/ACK/delete and CPU routes use the same result store.
|
| 90 |
for route in base.router.routes:
|
| 91 |
if getattr(route,'path',None)!='/api/capabilities':app.router.routes.append(route)
|
|
|
|
| 19 |
from server import create_app
|
| 20 |
from worker import run_native,track_input,network_input
|
| 21 |
from training_config import validate_config
|
| 22 |
+
from hf_identity import visitor_identity
|
| 23 |
|
| 24 |
def build_app(cuda_call):
|
| 25 |
base=create_app(worker=cpu_worker)
|
|
|
|
| 87 |
return {**base.state.results.publish(payload,automatic),'backend':'gpu','report':report}
|
| 88 |
finally:admission.release()
|
| 89 |
|
| 90 |
+
@app.api(name='visitor_identity',api_visibility='undocumented')
|
| 91 |
+
def queue_identity(request:gr.Request)->dict:
|
| 92 |
+
# Same queue/client credential path, but no GPU decorator or user files.
|
| 93 |
+
return visitor_identity(request.headers or {})
|
| 94 |
+
|
| 95 |
# Existing download/status/ACK/delete and CPU routes use the same result store.
|
| 96 |
for route in base.router.routes:
|
| 97 |
if getattr(route,'path',None)!='/api/capabilities':app.router.routes.append(route)
|
client.js
CHANGED
|
@@ -14,6 +14,7 @@ let batchReceipt = null;
|
|
| 14 |
const hostedStandalone = location.hostname.endsWith('.hf.space') && window.self === window.top;
|
| 15 |
const say = text => { $('status').textContent = text; };
|
| 16 |
function buttons() {
|
|
|
|
| 17 |
window.setTrainingBusy?.(busy || !!job);
|
| 18 |
window.setEditorBusy?.(busy || !!job);
|
| 19 |
$('run').disabled = busy || !!job || !capabilitiesReady;
|
|
@@ -64,16 +65,33 @@ window.TrainingClient={
|
|
| 64 |
};
|
| 65 |
async function submit(body){
|
| 66 |
if(body.backend==='gpu' && gpuTransport==='gradio-ticket'){
|
| 67 |
-
|
| 68 |
-
const {Client}=await import('/gradio-client.js');
|
| 69 |
-
gradioClient=await Client.connect(location.origin);
|
| 70 |
-
}
|
| 71 |
const prepared=await (await request('/api/gpu/prepare',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})).json();
|
| 72 |
const result=await gradioClient.predict('/gpu_train',[prepared.ticket]);
|
| 73 |
return result.data[0];
|
| 74 |
}
|
| 75 |
return (await request('/api/process',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})).json();
|
| 76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
async function receive(current){
|
| 78 |
const response=await request('/api/jobs/'+current.id+'/download',{method:'POST',headers:{'X-Job-Key':current.key}});
|
| 79 |
const bytes=await response.arrayBuffer();
|
|
@@ -226,7 +244,7 @@ async function connect(){
|
|
| 226 |
if(capabilities.cpu!==true)throw new Error('CPU unavailable');
|
| 227 |
gpuTransport=capabilities.gpu_transport??null;
|
| 228 |
$('gpuOption').disabled=!capabilities.gpu;
|
| 229 |
-
$('backendNote').textContent=capabilities.gpu?(hostedStandalone?'CPU uses no GPU allowance.
|
| 230 |
capabilitiesReady=true; buttons();
|
| 231 |
say('Connected. Choose your track and network, then run the test.');
|
| 232 |
} catch(error) {
|
|
|
|
| 14 |
const hostedStandalone = location.hostname.endsWith('.hf.space') && window.self === window.top;
|
| 15 |
const say = text => { $('status').textContent = text; };
|
| 16 |
function buttons() {
|
| 17 |
+
window.HFAuth?.setBusy(busy || !!job);
|
| 18 |
window.setTrainingBusy?.(busy || !!job);
|
| 19 |
window.setEditorBusy?.(busy || !!job);
|
| 20 |
$('run').disabled = busy || !!job || !capabilitiesReady;
|
|
|
|
| 65 |
};
|
| 66 |
async function submit(body){
|
| 67 |
if(body.backend==='gpu' && gpuTransport==='gradio-ticket'){
|
| 68 |
+
await verifyGpuIdentity();
|
|
|
|
|
|
|
|
|
|
| 69 |
const prepared=await (await request('/api/gpu/prepare',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})).json();
|
| 70 |
const result=await gradioClient.predict('/gpu_train',[prepared.ticket]);
|
| 71 |
return result.data[0];
|
| 72 |
}
|
| 73 |
return (await request('/api/process',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})).json();
|
| 74 |
}
|
| 75 |
+
async function verifyGpuIdentity(){
|
| 76 |
+
const credentials=window.HFAuth?.credentials()??{};
|
| 77 |
+
if(!gradioClient){
|
| 78 |
+
const {Client}=await import('/gradio-client.js');
|
| 79 |
+
gradioClient=await Client.connect(location.origin,credentials);
|
| 80 |
+
}
|
| 81 |
+
const result=await gradioClient.predict('/visitor_identity',[]);
|
| 82 |
+
window.HFAuth?.verify(result.data[0]);
|
| 83 |
+
return result.data[0];
|
| 84 |
+
}
|
| 85 |
+
window.addEventListener('hf-auth-change',()=>{
|
| 86 |
+
const previous=gradioClient;gradioClient=null;
|
| 87 |
+
if(previous)Promise.resolve(previous.close()).catch(()=>{});
|
| 88 |
+
});
|
| 89 |
+
window.TrainingClient.verifyIdentity=async()=>{
|
| 90 |
+
if(busy||job)throw Error('Finish the current result before checking identity');
|
| 91 |
+
busy=true;buttons();
|
| 92 |
+
try{return await verifyGpuIdentity();}
|
| 93 |
+
finally{busy=false;buttons();}
|
| 94 |
+
};
|
| 95 |
async function receive(current){
|
| 96 |
const response=await request('/api/jobs/'+current.id+'/download',{method:'POST',headers:{'X-Job-Key':current.key}});
|
| 97 |
const bytes=await response.arrayBuffer();
|
|
|
|
| 244 |
if(capabilities.cpu!==true)throw new Error('CPU unavailable');
|
| 245 |
gpuTransport=capabilities.gpu_transport??null;
|
| 246 |
$('gpuOption').disabled=!capabilities.gpu;
|
| 247 |
+
$('backendNote').textContent=capabilities.gpu?(hostedStandalone?'CPU uses no GPU allowance. Optional HF sign-in identifies account GPU requests; without sign-in, direct requests may use the limited anonymous allowance. No automatic switching.':'CPU uses no GPU allowance. GPU is subject to HF quota through the official client; optional HF sign-in explicitly identifies the caller. No automatic switching.'):'CPU available. GPU is not connected on this deployment; no GPU allowance is needed for CPU.';
|
| 248 |
capabilitiesReady=true; buttons();
|
| 249 |
say('Connected. Choose your track and network, then run the test.');
|
| 250 |
} catch(error) {
|
hf-auth-callback.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html><html lang="en"><meta charset="utf-8"><title>HF sign-in return</title>
|
| 2 |
+
<meta name="referrer" content="no-referrer">
|
| 3 |
+
<body><p>Returning sign-in to your training window. If that window was closed, close this tab and sign in again.</p>
|
| 4 |
+
<script>
|
| 5 |
+
'use strict';
|
| 6 |
+
const returnUrl=location.href;
|
| 7 |
+
history.replaceState(null,'','/auth/callback');
|
| 8 |
+
if(window.opener){
|
| 9 |
+
window.opener.postMessage({type:'hf-oauth-return',url:returnUrl},location.origin);
|
| 10 |
+
window.close();
|
| 11 |
+
}
|
| 12 |
+
</script></body></html>
|
hf-auth.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
// Official HF PKCE helpers; nonce/verifier and visitor token live in page RAM only.
|
| 3 |
+
(() => {
|
| 4 |
+
const node=id=>document.getElementById(id);
|
| 5 |
+
let session=null,pending=null,locked=false,ready=false,config=null,exchanging=false;
|
| 6 |
+
const message=text=>{node('hfIdentity').textContent=text;};
|
| 7 |
+
function render(){
|
| 8 |
+
node('hfSignIn').disabled=locked||!!pending||!ready;
|
| 9 |
+
node('hfSignOut').disabled=locked||!!pending||!session;
|
| 10 |
+
node('hfVerify').disabled=locked||!!pending||!session;
|
| 11 |
+
}
|
| 12 |
+
function clear(){session=null;window.dispatchEvent(new Event('hf-auth-change'));render();}
|
| 13 |
+
window.HFAuth={
|
| 14 |
+
setBusy(value){locked=value;render();},
|
| 15 |
+
credentials(){
|
| 16 |
+
if(pending||exchanging)throw Error('Complete or cancel HF sign-in before starting GPU');
|
| 17 |
+
if(session && session.accessTokenExpiresAt.getTime()<=Date.now()){
|
| 18 |
+
clear();message('HF sign-in expired. Sign in again before an account GPU request.');
|
| 19 |
+
throw Error('HF sign-in expired; sign in again');
|
| 20 |
+
}
|
| 21 |
+
return session?{token:session.accessToken}:{};
|
| 22 |
+
},
|
| 23 |
+
verify(identity){
|
| 24 |
+
if(session && (!identity.authenticated||identity.auth_path!=='queue-bearer'||identity.username!==session.userInfo.preferred_username))
|
| 25 |
+
throw Error('GPU queue visitor identity did not match your HF sign-in; no GPU request started');
|
| 26 |
+
if(session)message('HF visitor verified through GPU queue: '+identity.username+'. GPU allowance remains subject to HF limits.');
|
| 27 |
+
}
|
| 28 |
+
};
|
| 29 |
+
node('hfSignOut').onclick=()=>{clear();message('Signed out of this app. CPU remains anonymous. HF website sign-in is unchanged.');};
|
| 30 |
+
node('hfVerify').onclick=async()=>{
|
| 31 |
+
try{await window.TrainingClient.verifyIdentity();}
|
| 32 |
+
catch{message('Queue identity check failed. No GPU request started. Sign in again or use CPU.');}
|
| 33 |
+
};
|
| 34 |
+
node('hfSignIn').onclick=async()=>{
|
| 35 |
+
if(locked||pending||!ready)return;
|
| 36 |
+
const popup=window.open('about:blank','ald-hf-sign-in','popup,width=620,height=760');
|
| 37 |
+
if(!popup){message('Sign-in window blocked. Allow this sign-in popup or use anonymous CPU.');return;}
|
| 38 |
+
const state={};
|
| 39 |
+
pending={popup,state,started:Date.now()};render();
|
| 40 |
+
try{
|
| 41 |
+
const helpers=await import('/hf-oauth.js');
|
| 42 |
+
const url=await helpers.oauthLoginUrl({clientId:config.client_id,scopes:'openid profile',
|
| 43 |
+
redirectUrl:location.origin+'/auth/callback',localStorage:state});
|
| 44 |
+
if(!pending || pending.popup!==popup)return;
|
| 45 |
+
popup.location.href=url;message('Complete the optional sign-in on Hugging Face. No password or personal token is entered here.');
|
| 46 |
+
}catch{
|
| 47 |
+
pending=null;popup.close();render();message('HF sign-in could not start. CPU remains available.');
|
| 48 |
+
}
|
| 49 |
+
};
|
| 50 |
+
window.addEventListener('message',async event=>{
|
| 51 |
+
if(!pending||event.origin!==location.origin||event.source!==pending.popup||event.data?.type!=='hf-oauth-return')return;
|
| 52 |
+
const flow=pending;pending=null;ready=false;exchanging=true;render();
|
| 53 |
+
try{
|
| 54 |
+
const returned=new URL(event.data.url);
|
| 55 |
+
if(returned.origin!==location.origin||returned.pathname!=='/auth/callback')throw Error();
|
| 56 |
+
const helpers=await import('/hf-oauth.js');
|
| 57 |
+
const result=await helpers.oauthHandleRedirect({redirectedUrl:returned.href,
|
| 58 |
+
nonce:flow.state.nonce,codeVerifier:flow.state.codeVerifier});
|
| 59 |
+
const scopes=new Set(result.scope.split(/\s+/));
|
| 60 |
+
if([...scopes].some(scope=>!['openid','profile'].includes(scope)))throw Error();
|
| 61 |
+
if(!result.accessToken||!result.userInfo.preferred_username||result.accessTokenExpiresAt.getTime()<=Date.now())throw Error();
|
| 62 |
+
session=result;window.dispatchEvent(new Event('hf-auth-change'));
|
| 63 |
+
message('Signed in with HF: '+result.userInfo.preferred_username+'. Verify queue identity before GPU use.');
|
| 64 |
+
}catch{
|
| 65 |
+
clear();message('HF sign-in was cancelled or could not be verified. No GPU request started; CPU remains available.');
|
| 66 |
+
}finally{
|
| 67 |
+
flow.state.nonce=null;flow.state.codeVerifier=null;ready=true;exchanging=false;render();
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
setInterval(()=>{
|
| 71 |
+
if(pending&&(pending.popup.closed||Date.now()-pending.started>300000)){
|
| 72 |
+
pending.popup.close();pending=null;render();message('HF sign-in window closed or timed out. CPU remains available.');
|
| 73 |
+
}
|
| 74 |
+
},1000);
|
| 75 |
+
fetch('/api/auth/config',{cache:'no-store',credentials:'omit'}).then(async response=>{
|
| 76 |
+
if(!response.ok)throw Error();config=await response.json();ready=config.enabled===true;render();
|
| 77 |
+
message(ready?'Optional: sign in with HF to identify account GPU requests. CPU needs no sign-in. Token stays in this page’s memory until sign-out, expiry, or page close.':
|
| 78 |
+
'HF sign-in is not configured on this deployment. CPU remains anonymous.');
|
| 79 |
+
}).catch(()=>{message('HF sign-in unavailable. CPU remains anonymous.');render();});
|
| 80 |
+
})();
|
hf_identity.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-only visitor identity check; never retain or log bearer credentials."""
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from urllib.request import Request, urlopen
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def oauth_config():
|
| 8 |
+
client_id = os.environ.get('OAUTH_CLIENT_ID', '')
|
| 9 |
+
return {'enabled': bool(client_id), 'client_id': client_id,
|
| 10 |
+
'scopes': 'openid profile'}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def visitor_identity(headers):
|
| 14 |
+
authorization = headers.get('authorization', '')
|
| 15 |
+
if not authorization:
|
| 16 |
+
return {'authenticated': False, 'auth_path': 'anonymous'}
|
| 17 |
+
if not authorization.startswith('Bearer ') or len(authorization) > 8192:
|
| 18 |
+
raise ValueError('Visitor authentication is invalid; sign in again')
|
| 19 |
+
# Fixed HF endpoint only: no caller-controlled network destinations.
|
| 20 |
+
try:
|
| 21 |
+
request = Request('https://huggingface.co/oauth/userinfo',
|
| 22 |
+
headers={'Authorization': authorization})
|
| 23 |
+
with urlopen(request, timeout=8) as response:
|
| 24 |
+
profile = json.loads(response.read(65536))
|
| 25 |
+
username = profile['preferred_username']
|
| 26 |
+
if not isinstance(username, str) or not username or len(username) > 200:
|
| 27 |
+
raise ValueError()
|
| 28 |
+
return {'authenticated': True, 'username': username,
|
| 29 |
+
'auth_path': 'queue-bearer', 'is_pro': profile.get('isPro') is True}
|
| 30 |
+
except Exception:
|
| 31 |
+
# Never echo provider bodies, headers, credentials, or callback URLs.
|
| 32 |
+
raise ValueError('Visitor identity could not be verified; sign in again') from None
|
index.html
CHANGED
|
@@ -2,10 +2,11 @@
|
|
| 2 |
<style>
|
| 3 |
:root{color-scheme:dark;font:16px system-ui;background:#0c1420;color:#e5edf5}body{max-width:1320px;margin:auto;padding:28px}h1{font-size:32px;margin:0}h2{font-size:21px;margin:0 0 14px}small,.hint{color:#a2b4c8;line-height:1.6}.grid{display:grid;grid-template-columns:minmax(350px,430px) minmax(0,1fr);gap:24px}.card{background:#152233;border:1px solid #2a3d52;border-radius:16px;padding:22px;margin-top:20px}label{display:block;margin:12px 0 5px}input,select,button{font:inherit;background:#0c1725;color:#e5edf5;border:1px solid #49627c;border-radius:7px;padding:9px}input[type=number],select{width:100%;box-sizing:border-box}input[type=file]{max-width:100%;box-sizing:border-box}button{cursor:pointer}button.primary{background:#62dfb1;color:#102522;font-weight:700}button:disabled{opacity:.4;cursor:default}.row{display:grid;grid-template-columns:1fr 1fr;gap:15px}.reward{display:grid;grid-template-columns:1.7fr 1fr 70px 30px;gap:5px;margin:8px 0}.reward input{width:70px;box-sizing:border-box}a{color:#7ce4c3}canvas{width:100%;background:#09111b;border-radius:10px}#status{white-space:pre-wrap;line-height:1.7}table{width:100%;text-align:left;border-collapse:collapse;font-size:14px}td,th{padding:9px;border-bottom:1px solid #2a3d52}.pill{display:inline-block;background:#284539;border-radius:20px;padding:5px 12px;color:#91efc6;margin:6px 0}#error{color:#ffb5a2;white-space:pre-wrap}.toolbar{display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding-bottom:16px;border-bottom:1px solid #2a3d52;margin-bottom:15px}.run-card{position:sticky;top:20px}details{margin-top:18px;border-top:1px solid #2a3d52;padding-top:14px}summary{cursor:pointer;font-weight:600;color:#c6d9e9}details[open]>summary{margin-bottom:12px}[hidden]{display:none!important}#map_note{font-size:14px}#runs{max-height:380px;overflow:auto}.table-scroll{overflow:auto}@media(max-width:850px){.grid{grid-template-columns:1fr}#drive .grid>section:nth-child(2){order:-1}.run-card{position:static}body{padding:16px}}
|
| 4 |
.tabs{display:flex;flex-wrap:wrap;gap:10px;margin:20px 0}.tabs button[aria-selected=true]{background:#62dfb1;color:#102522}.library{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:20px}.library input[type=text]{width:100%;box-sizing:border-box}.queue-row{display:flex;gap:8px;margin:8px 0}.queue-row select{flex:1}.pane{min-width:0}.map{min-height:260px;background:#09111b;border-radius:12px;display:flex;flex-direction:column;justify-content:center;align-items:center}pre{white-space:pre-wrap;overflow-wrap:anywhere}input[type=text]{width:100%;box-sizing:border-box}#editor_parameters input{max-width:240px}</style>
|
| 5 |
-
<header><h1>AI Learns To Drive</h1><p class="hint">Simulator by Zorro909 · UI and HF implementation by TiGa (seeker-cyber-maker).</p><p><a href="https://github.com/Zorro909/driving_sim_rs">Upstream simulator</a> · <a href="https://github.com/seeker-cyber-maker/driving_sim_rs">Implementation fork</a> · <a href="https://store.steampowered.com/app/3312030/AI_Learns_To_Drive/">Game by ActivationFunction on Steam</a></p><p role="status">Runner interface migration candidate — configurable single-run training, browser-local recipes and bounded batches. Network inspection and editing run in your browser. Track rendering and star evaluation are not connected.</p><p><a href="https://tiga-rce-ald-tao-gpu.hf.space/" target="_blank" rel="noopener noreferrer">Open the Protected beta app</a> · Share this app address with testers; the HF repository page remains restricted. CPU
|
| 6 |
<nav class="tabs" aria-label="Lab sections"><button data-tab="drive" aria-selected="true">1 · Drive & view</button><button data-tab="training" aria-selected="false">2 · Training runs & presets</button><button data-tab="batch" aria-selected="false">3 · Batches</button><button data-tab="editor" aria-selected="false">4 · Network editor</button></nav><div id="drive" class="pane"><div class="grid"><section class="card"><h2>Simulation</h2><p>Training uses the settings on the Training runs & presets tab. Formula networks, steering and acceleration; speed and raycast sensors. Supported networks: Formula, steering and acceleration, speed/raycast sensors, 2–4 layers with up to 16 nodes.</p>
|
| 7 |
<p><label for="backend">Compute</label><select id="backend" disabled><option value="cpu">CPU — no GPU allowance</option><option id="gpuOption" value="gpu" disabled>GPU — uses GPU allowance</option></select></p><p id="backendNote" class="hint">Checking available backends…</p>
|
| 8 |
<button id="retry" type="button">Retry connection</button>
|
|
|
|
| 9 |
<p><label>Track (.track) <input id="track" type="file" accept=".track"></label></p>
|
| 10 |
<p><label>Formula network (.evolution) <input id="network" type="file" accept=".evolution"></label></p>
|
| 11 |
<p id="networkChoice" role="status">Choose an uploaded file or use a network from the browser editor.</p><p><label><input id="automatic" type="checkbox" checked> Automatically delete server-side job data after receiving the result</label></p>
|
|
@@ -287,7 +288,7 @@
|
|
| 287 |
message('Batch '+batch.slot+' loaded. Loading a batch does not start it.');
|
| 288 |
});
|
| 289 |
})();
|
| 290 |
-
</script><script src="/client.js"></script><script>'use strict';
|
| 291 |
// Navigation only. Editor and training/storage adapters are separate layers.
|
| 292 |
document.querySelectorAll('[data-tab]').forEach(button=>button.addEventListener('click',()=>{
|
| 293 |
document.querySelectorAll('.pane').forEach(pane=>pane.hidden=pane.id!==button.dataset.tab);
|
|
|
|
| 2 |
<style>
|
| 3 |
:root{color-scheme:dark;font:16px system-ui;background:#0c1420;color:#e5edf5}body{max-width:1320px;margin:auto;padding:28px}h1{font-size:32px;margin:0}h2{font-size:21px;margin:0 0 14px}small,.hint{color:#a2b4c8;line-height:1.6}.grid{display:grid;grid-template-columns:minmax(350px,430px) minmax(0,1fr);gap:24px}.card{background:#152233;border:1px solid #2a3d52;border-radius:16px;padding:22px;margin-top:20px}label{display:block;margin:12px 0 5px}input,select,button{font:inherit;background:#0c1725;color:#e5edf5;border:1px solid #49627c;border-radius:7px;padding:9px}input[type=number],select{width:100%;box-sizing:border-box}input[type=file]{max-width:100%;box-sizing:border-box}button{cursor:pointer}button.primary{background:#62dfb1;color:#102522;font-weight:700}button:disabled{opacity:.4;cursor:default}.row{display:grid;grid-template-columns:1fr 1fr;gap:15px}.reward{display:grid;grid-template-columns:1.7fr 1fr 70px 30px;gap:5px;margin:8px 0}.reward input{width:70px;box-sizing:border-box}a{color:#7ce4c3}canvas{width:100%;background:#09111b;border-radius:10px}#status{white-space:pre-wrap;line-height:1.7}table{width:100%;text-align:left;border-collapse:collapse;font-size:14px}td,th{padding:9px;border-bottom:1px solid #2a3d52}.pill{display:inline-block;background:#284539;border-radius:20px;padding:5px 12px;color:#91efc6;margin:6px 0}#error{color:#ffb5a2;white-space:pre-wrap}.toolbar{display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding-bottom:16px;border-bottom:1px solid #2a3d52;margin-bottom:15px}.run-card{position:sticky;top:20px}details{margin-top:18px;border-top:1px solid #2a3d52;padding-top:14px}summary{cursor:pointer;font-weight:600;color:#c6d9e9}details[open]>summary{margin-bottom:12px}[hidden]{display:none!important}#map_note{font-size:14px}#runs{max-height:380px;overflow:auto}.table-scroll{overflow:auto}@media(max-width:850px){.grid{grid-template-columns:1fr}#drive .grid>section:nth-child(2){order:-1}.run-card{position:static}body{padding:16px}}
|
| 4 |
.tabs{display:flex;flex-wrap:wrap;gap:10px;margin:20px 0}.tabs button[aria-selected=true]{background:#62dfb1;color:#102522}.library{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:20px}.library input[type=text]{width:100%;box-sizing:border-box}.queue-row{display:flex;gap:8px;margin:8px 0}.queue-row select{flex:1}.pane{min-width:0}.map{min-height:260px;background:#09111b;border-radius:12px;display:flex;flex-direction:column;justify-content:center;align-items:center}pre{white-space:pre-wrap;overflow-wrap:anywhere}input[type=text]{width:100%;box-sizing:border-box}#editor_parameters input{max-width:240px}</style>
|
| 5 |
+
<header><h1>AI Learns To Drive</h1><p class="hint">Simulator by Zorro909 · UI and HF implementation by TiGa (seeker-cyber-maker).</p><p><a href="https://github.com/Zorro909/driving_sim_rs">Upstream simulator</a> · <a href="https://github.com/seeker-cyber-maker/driving_sim_rs">Implementation fork</a> · <a href="https://store.steampowered.com/app/3312030/AI_Learns_To_Drive/">Game by ActivationFunction on Steam</a></p><p role="status">Runner interface migration candidate — configurable single-run training, browser-local recipes and bounded batches. Network inspection and editing run in your browser. Track rendering and star evaluation are not connected.</p><p><a href="https://tiga-rce-ald-tao-gpu.hf.space/" target="_blank" rel="noopener noreferrer">Open the Protected beta app</a> · Share this app address with testers; the HF repository page remains restricted. CPU is anonymous. Optional HF sign-in identifies account GPU requests; otherwise the limited anonymous allowance may apply. No personal token entry is requested.</p></header>
|
| 6 |
<nav class="tabs" aria-label="Lab sections"><button data-tab="drive" aria-selected="true">1 · Drive & view</button><button data-tab="training" aria-selected="false">2 · Training runs & presets</button><button data-tab="batch" aria-selected="false">3 · Batches</button><button data-tab="editor" aria-selected="false">4 · Network editor</button></nav><div id="drive" class="pane"><div class="grid"><section class="card"><h2>Simulation</h2><p>Training uses the settings on the Training runs & presets tab. Formula networks, steering and acceleration; speed and raycast sensors. Supported networks: Formula, steering and acceleration, speed/raycast sensors, 2–4 layers with up to 16 nodes.</p>
|
| 7 |
<p><label for="backend">Compute</label><select id="backend" disabled><option value="cpu">CPU — no GPU allowance</option><option id="gpuOption" value="gpu" disabled>GPU — uses GPU allowance</option></select></p><p id="backendNote" class="hint">Checking available backends…</p>
|
| 8 |
<button id="retry" type="button">Retry connection</button>
|
| 9 |
+
<p><button id="hfSignIn" type="button" disabled>Sign in with Hugging Face</button> <button id="hfSignOut" type="button" disabled>Sign out of this app</button> <button id="hfVerify" type="button" disabled>Verify HF identity — no GPU</button></p><p id="hfIdentity" role="status" class="hint">CPU needs no sign-in. Checking optional HF sign-in…</p>
|
| 10 |
<p><label>Track (.track) <input id="track" type="file" accept=".track"></label></p>
|
| 11 |
<p><label>Formula network (.evolution) <input id="network" type="file" accept=".evolution"></label></p>
|
| 12 |
<p id="networkChoice" role="status">Choose an uploaded file or use a network from the browser editor.</p><p><label><input id="automatic" type="checkbox" checked> Automatically delete server-side job data after receiving the result</label></p>
|
|
|
|
| 288 |
message('Batch '+batch.slot+' loaded. Loading a batch does not start it.');
|
| 289 |
});
|
| 290 |
})();
|
| 291 |
+
</script><script src="/client.js"></script><script src="/hf-auth.js"></script><script>'use strict';
|
| 292 |
// Navigation only. Editor and training/storage adapters are separate layers.
|
| 293 |
document.querySelectorAll('[data-tab]').forEach(button=>button.addEventListener('click',()=>{
|
| 294 |
document.querySelectorAll('.pane').forEach(pane=>pane.hidden=pane.id!==button.dataset.tab);
|
server.py
CHANGED
|
@@ -4,17 +4,29 @@ import json
|
|
| 4 |
from pathlib import Path
|
| 5 |
import threading
|
| 6 |
from fastapi import HTTPException, Request
|
| 7 |
-
from fastapi.responses import FileResponse, Response, HTMLResponse
|
| 8 |
from starlette.concurrency import run_in_threadpool
|
| 9 |
from delivery import create_api, CapacityExceeded
|
| 10 |
from worker import run_reported
|
| 11 |
from training_config import validate_config
|
|
|
|
| 12 |
|
| 13 |
ROOT=Path(__file__).resolve().parent
|
| 14 |
|
| 15 |
def create_app(worker=run_reported,store=None,gpu_worker=None):
|
| 16 |
app=create_api(store)
|
| 17 |
admission=threading.BoundedSemaphore(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
@app.get('/api/capabilities')
|
| 19 |
def capabilities():
|
| 20 |
return {'cpu':True,'gpu':gpu_worker is not None,'default':'cpu','configurable_training':True}
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
import threading
|
| 6 |
from fastapi import HTTPException, Request
|
| 7 |
+
from fastapi.responses import FileResponse, Response, HTMLResponse, JSONResponse
|
| 8 |
from starlette.concurrency import run_in_threadpool
|
| 9 |
from delivery import create_api, CapacityExceeded
|
| 10 |
from worker import run_reported
|
| 11 |
from training_config import validate_config
|
| 12 |
+
from hf_identity import oauth_config
|
| 13 |
|
| 14 |
ROOT=Path(__file__).resolve().parent
|
| 15 |
|
| 16 |
def create_app(worker=run_reported,store=None,gpu_worker=None):
|
| 17 |
app=create_api(store)
|
| 18 |
admission=threading.BoundedSemaphore(1)
|
| 19 |
+
@app.get('/api/auth/config')
|
| 20 |
+
def auth_config():
|
| 21 |
+
return JSONResponse(oauth_config(),headers={'Cache-Control':'no-store'})
|
| 22 |
+
@app.get('/auth/callback')
|
| 23 |
+
def auth_callback():
|
| 24 |
+
return FileResponse(ROOT/'hf-auth-callback.html',media_type='text/html',
|
| 25 |
+
headers={'Cache-Control':'no-store','Referrer-Policy':'no-referrer'})
|
| 26 |
+
@app.get('/hf-auth.js')
|
| 27 |
+
def auth_script(): return FileResponse(ROOT/'hf-auth.js',media_type='text/javascript')
|
| 28 |
+
@app.get('/hf-oauth.js')
|
| 29 |
+
def oauth_script(): return FileResponse(ROOT/'vendor/hf-oauth/index.js',media_type='text/javascript')
|
| 30 |
@app.get('/api/capabilities')
|
| 31 |
def capabilities():
|
| 32 |
return {'cpu':True,'gpu':gpu_worker is not None,'default':'cpu','configurable_training':True}
|
vendor/hf-oauth/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 Hugging Face
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
vendor/hf-oauth/index.js
ADDED
|
@@ -0,0 +1,2738 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/gearhash-jit/dist/esm/wasm.js
|
| 2 |
+
var INPUT_OFFSET = 4096;
|
| 3 |
+
var PAGES = 8;
|
| 4 |
+
var MAX_INPUT_SIZE = PAGES * 65536 - INPUT_OFFSET;
|
| 5 |
+
|
| 6 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/compress.js
|
| 7 |
+
function compress(cv, cvOff, block, blockOff, out, outOff, full, counter, blockLen, flags) {
|
| 8 |
+
let m0 = block[blockOff] | 0;
|
| 9 |
+
let m1 = block[blockOff + 1] | 0;
|
| 10 |
+
let m2 = block[blockOff + 2] | 0;
|
| 11 |
+
let m3 = block[blockOff + 3] | 0;
|
| 12 |
+
let m4 = block[blockOff + 4] | 0;
|
| 13 |
+
let m5 = block[blockOff + 5] | 0;
|
| 14 |
+
let m6 = block[blockOff + 6] | 0;
|
| 15 |
+
let m7 = block[blockOff + 7] | 0;
|
| 16 |
+
let m8 = block[blockOff + 8] | 0;
|
| 17 |
+
let m9 = block[blockOff + 9] | 0;
|
| 18 |
+
let m10 = block[blockOff + 10] | 0;
|
| 19 |
+
let m11 = block[blockOff + 11] | 0;
|
| 20 |
+
let m12 = block[blockOff + 12] | 0;
|
| 21 |
+
let m13 = block[blockOff + 13] | 0;
|
| 22 |
+
let m14 = block[blockOff + 14] | 0;
|
| 23 |
+
let m15 = block[blockOff + 15] | 0;
|
| 24 |
+
let s0 = cv[cvOff] | 0;
|
| 25 |
+
let s1 = cv[cvOff + 1] | 0;
|
| 26 |
+
let s2 = cv[cvOff + 2] | 0;
|
| 27 |
+
let s3 = cv[cvOff + 3] | 0;
|
| 28 |
+
let s4 = cv[cvOff + 4] | 0;
|
| 29 |
+
let s5 = cv[cvOff + 5] | 0;
|
| 30 |
+
let s6 = cv[cvOff + 6] | 0;
|
| 31 |
+
let s7 = cv[cvOff + 7] | 0;
|
| 32 |
+
let s8 = 1779033703;
|
| 33 |
+
let s9 = 3144134277;
|
| 34 |
+
let s10 = 1013904242;
|
| 35 |
+
let s11 = 2773480762;
|
| 36 |
+
let s12 = counter | 0;
|
| 37 |
+
let s13 = counter / 4294967296 | 0;
|
| 38 |
+
let s14 = blockLen | 0;
|
| 39 |
+
let s15 = flags | 0;
|
| 40 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 41 |
+
s12 ^= s0;
|
| 42 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 43 |
+
s8 = s8 + s12 | 0;
|
| 44 |
+
s4 ^= s8;
|
| 45 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 46 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 47 |
+
s12 ^= s0;
|
| 48 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 49 |
+
s8 = s8 + s12 | 0;
|
| 50 |
+
s4 ^= s8;
|
| 51 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 52 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 53 |
+
s13 ^= s1;
|
| 54 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 55 |
+
s9 = s9 + s13 | 0;
|
| 56 |
+
s5 ^= s9;
|
| 57 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 58 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 59 |
+
s13 ^= s1;
|
| 60 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 61 |
+
s9 = s9 + s13 | 0;
|
| 62 |
+
s5 ^= s9;
|
| 63 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 64 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 65 |
+
s14 ^= s2;
|
| 66 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 67 |
+
s10 = s10 + s14 | 0;
|
| 68 |
+
s6 ^= s10;
|
| 69 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 70 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 71 |
+
s14 ^= s2;
|
| 72 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 73 |
+
s10 = s10 + s14 | 0;
|
| 74 |
+
s6 ^= s10;
|
| 75 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 76 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 77 |
+
s15 ^= s3;
|
| 78 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 79 |
+
s11 = s11 + s15 | 0;
|
| 80 |
+
s7 ^= s11;
|
| 81 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 82 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 83 |
+
s15 ^= s3;
|
| 84 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 85 |
+
s11 = s11 + s15 | 0;
|
| 86 |
+
s7 ^= s11;
|
| 87 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 88 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 89 |
+
s15 ^= s0;
|
| 90 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 91 |
+
s10 = s10 + s15 | 0;
|
| 92 |
+
s5 ^= s10;
|
| 93 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 94 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 95 |
+
s15 ^= s0;
|
| 96 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 97 |
+
s10 = s10 + s15 | 0;
|
| 98 |
+
s5 ^= s10;
|
| 99 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 100 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 101 |
+
s12 ^= s1;
|
| 102 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 103 |
+
s11 = s11 + s12 | 0;
|
| 104 |
+
s6 ^= s11;
|
| 105 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 106 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 107 |
+
s12 ^= s1;
|
| 108 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 109 |
+
s11 = s11 + s12 | 0;
|
| 110 |
+
s6 ^= s11;
|
| 111 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 112 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 113 |
+
s13 ^= s2;
|
| 114 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 115 |
+
s8 = s8 + s13 | 0;
|
| 116 |
+
s7 ^= s8;
|
| 117 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 118 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 119 |
+
s13 ^= s2;
|
| 120 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 121 |
+
s8 = s8 + s13 | 0;
|
| 122 |
+
s7 ^= s8;
|
| 123 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 124 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 125 |
+
s14 ^= s3;
|
| 126 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 127 |
+
s9 = s9 + s14 | 0;
|
| 128 |
+
s4 ^= s9;
|
| 129 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 130 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 131 |
+
s14 ^= s3;
|
| 132 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 133 |
+
s9 = s9 + s14 | 0;
|
| 134 |
+
s4 ^= s9;
|
| 135 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 136 |
+
{
|
| 137 |
+
const t0 = m0, t1 = m1;
|
| 138 |
+
m0 = m2;
|
| 139 |
+
m2 = m3;
|
| 140 |
+
m3 = m10;
|
| 141 |
+
m10 = m12;
|
| 142 |
+
m12 = m9;
|
| 143 |
+
m9 = m11;
|
| 144 |
+
m11 = m5;
|
| 145 |
+
m5 = t0;
|
| 146 |
+
m1 = m6;
|
| 147 |
+
m6 = m4;
|
| 148 |
+
m4 = m7;
|
| 149 |
+
m7 = m13;
|
| 150 |
+
m13 = m14;
|
| 151 |
+
m14 = m15;
|
| 152 |
+
m15 = m8;
|
| 153 |
+
m8 = t1;
|
| 154 |
+
}
|
| 155 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 156 |
+
s12 ^= s0;
|
| 157 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 158 |
+
s8 = s8 + s12 | 0;
|
| 159 |
+
s4 ^= s8;
|
| 160 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 161 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 162 |
+
s12 ^= s0;
|
| 163 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 164 |
+
s8 = s8 + s12 | 0;
|
| 165 |
+
s4 ^= s8;
|
| 166 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 167 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 168 |
+
s13 ^= s1;
|
| 169 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 170 |
+
s9 = s9 + s13 | 0;
|
| 171 |
+
s5 ^= s9;
|
| 172 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 173 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 174 |
+
s13 ^= s1;
|
| 175 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 176 |
+
s9 = s9 + s13 | 0;
|
| 177 |
+
s5 ^= s9;
|
| 178 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 179 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 180 |
+
s14 ^= s2;
|
| 181 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 182 |
+
s10 = s10 + s14 | 0;
|
| 183 |
+
s6 ^= s10;
|
| 184 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 185 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 186 |
+
s14 ^= s2;
|
| 187 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 188 |
+
s10 = s10 + s14 | 0;
|
| 189 |
+
s6 ^= s10;
|
| 190 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 191 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 192 |
+
s15 ^= s3;
|
| 193 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 194 |
+
s11 = s11 + s15 | 0;
|
| 195 |
+
s7 ^= s11;
|
| 196 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 197 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 198 |
+
s15 ^= s3;
|
| 199 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 200 |
+
s11 = s11 + s15 | 0;
|
| 201 |
+
s7 ^= s11;
|
| 202 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 203 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 204 |
+
s15 ^= s0;
|
| 205 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 206 |
+
s10 = s10 + s15 | 0;
|
| 207 |
+
s5 ^= s10;
|
| 208 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 209 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 210 |
+
s15 ^= s0;
|
| 211 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 212 |
+
s10 = s10 + s15 | 0;
|
| 213 |
+
s5 ^= s10;
|
| 214 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 215 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 216 |
+
s12 ^= s1;
|
| 217 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 218 |
+
s11 = s11 + s12 | 0;
|
| 219 |
+
s6 ^= s11;
|
| 220 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 221 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 222 |
+
s12 ^= s1;
|
| 223 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 224 |
+
s11 = s11 + s12 | 0;
|
| 225 |
+
s6 ^= s11;
|
| 226 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 227 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 228 |
+
s13 ^= s2;
|
| 229 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 230 |
+
s8 = s8 + s13 | 0;
|
| 231 |
+
s7 ^= s8;
|
| 232 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 233 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 234 |
+
s13 ^= s2;
|
| 235 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 236 |
+
s8 = s8 + s13 | 0;
|
| 237 |
+
s7 ^= s8;
|
| 238 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 239 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 240 |
+
s14 ^= s3;
|
| 241 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 242 |
+
s9 = s9 + s14 | 0;
|
| 243 |
+
s4 ^= s9;
|
| 244 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 245 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 246 |
+
s14 ^= s3;
|
| 247 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 248 |
+
s9 = s9 + s14 | 0;
|
| 249 |
+
s4 ^= s9;
|
| 250 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 251 |
+
{
|
| 252 |
+
const t0 = m0, t1 = m1;
|
| 253 |
+
m0 = m2;
|
| 254 |
+
m2 = m3;
|
| 255 |
+
m3 = m10;
|
| 256 |
+
m10 = m12;
|
| 257 |
+
m12 = m9;
|
| 258 |
+
m9 = m11;
|
| 259 |
+
m11 = m5;
|
| 260 |
+
m5 = t0;
|
| 261 |
+
m1 = m6;
|
| 262 |
+
m6 = m4;
|
| 263 |
+
m4 = m7;
|
| 264 |
+
m7 = m13;
|
| 265 |
+
m13 = m14;
|
| 266 |
+
m14 = m15;
|
| 267 |
+
m15 = m8;
|
| 268 |
+
m8 = t1;
|
| 269 |
+
}
|
| 270 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 271 |
+
s12 ^= s0;
|
| 272 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 273 |
+
s8 = s8 + s12 | 0;
|
| 274 |
+
s4 ^= s8;
|
| 275 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 276 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 277 |
+
s12 ^= s0;
|
| 278 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 279 |
+
s8 = s8 + s12 | 0;
|
| 280 |
+
s4 ^= s8;
|
| 281 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 282 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 283 |
+
s13 ^= s1;
|
| 284 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 285 |
+
s9 = s9 + s13 | 0;
|
| 286 |
+
s5 ^= s9;
|
| 287 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 288 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 289 |
+
s13 ^= s1;
|
| 290 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 291 |
+
s9 = s9 + s13 | 0;
|
| 292 |
+
s5 ^= s9;
|
| 293 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 294 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 295 |
+
s14 ^= s2;
|
| 296 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 297 |
+
s10 = s10 + s14 | 0;
|
| 298 |
+
s6 ^= s10;
|
| 299 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 300 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 301 |
+
s14 ^= s2;
|
| 302 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 303 |
+
s10 = s10 + s14 | 0;
|
| 304 |
+
s6 ^= s10;
|
| 305 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 306 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 307 |
+
s15 ^= s3;
|
| 308 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 309 |
+
s11 = s11 + s15 | 0;
|
| 310 |
+
s7 ^= s11;
|
| 311 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 312 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 313 |
+
s15 ^= s3;
|
| 314 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 315 |
+
s11 = s11 + s15 | 0;
|
| 316 |
+
s7 ^= s11;
|
| 317 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 318 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 319 |
+
s15 ^= s0;
|
| 320 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 321 |
+
s10 = s10 + s15 | 0;
|
| 322 |
+
s5 ^= s10;
|
| 323 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 324 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 325 |
+
s15 ^= s0;
|
| 326 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 327 |
+
s10 = s10 + s15 | 0;
|
| 328 |
+
s5 ^= s10;
|
| 329 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 330 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 331 |
+
s12 ^= s1;
|
| 332 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 333 |
+
s11 = s11 + s12 | 0;
|
| 334 |
+
s6 ^= s11;
|
| 335 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 336 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 337 |
+
s12 ^= s1;
|
| 338 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 339 |
+
s11 = s11 + s12 | 0;
|
| 340 |
+
s6 ^= s11;
|
| 341 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 342 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 343 |
+
s13 ^= s2;
|
| 344 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 345 |
+
s8 = s8 + s13 | 0;
|
| 346 |
+
s7 ^= s8;
|
| 347 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 348 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 349 |
+
s13 ^= s2;
|
| 350 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 351 |
+
s8 = s8 + s13 | 0;
|
| 352 |
+
s7 ^= s8;
|
| 353 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 354 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 355 |
+
s14 ^= s3;
|
| 356 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 357 |
+
s9 = s9 + s14 | 0;
|
| 358 |
+
s4 ^= s9;
|
| 359 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 360 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 361 |
+
s14 ^= s3;
|
| 362 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 363 |
+
s9 = s9 + s14 | 0;
|
| 364 |
+
s4 ^= s9;
|
| 365 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 366 |
+
{
|
| 367 |
+
const t0 = m0, t1 = m1;
|
| 368 |
+
m0 = m2;
|
| 369 |
+
m2 = m3;
|
| 370 |
+
m3 = m10;
|
| 371 |
+
m10 = m12;
|
| 372 |
+
m12 = m9;
|
| 373 |
+
m9 = m11;
|
| 374 |
+
m11 = m5;
|
| 375 |
+
m5 = t0;
|
| 376 |
+
m1 = m6;
|
| 377 |
+
m6 = m4;
|
| 378 |
+
m4 = m7;
|
| 379 |
+
m7 = m13;
|
| 380 |
+
m13 = m14;
|
| 381 |
+
m14 = m15;
|
| 382 |
+
m15 = m8;
|
| 383 |
+
m8 = t1;
|
| 384 |
+
}
|
| 385 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 386 |
+
s12 ^= s0;
|
| 387 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 388 |
+
s8 = s8 + s12 | 0;
|
| 389 |
+
s4 ^= s8;
|
| 390 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 391 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 392 |
+
s12 ^= s0;
|
| 393 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 394 |
+
s8 = s8 + s12 | 0;
|
| 395 |
+
s4 ^= s8;
|
| 396 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 397 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 398 |
+
s13 ^= s1;
|
| 399 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 400 |
+
s9 = s9 + s13 | 0;
|
| 401 |
+
s5 ^= s9;
|
| 402 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 403 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 404 |
+
s13 ^= s1;
|
| 405 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 406 |
+
s9 = s9 + s13 | 0;
|
| 407 |
+
s5 ^= s9;
|
| 408 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 409 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 410 |
+
s14 ^= s2;
|
| 411 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 412 |
+
s10 = s10 + s14 | 0;
|
| 413 |
+
s6 ^= s10;
|
| 414 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 415 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 416 |
+
s14 ^= s2;
|
| 417 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 418 |
+
s10 = s10 + s14 | 0;
|
| 419 |
+
s6 ^= s10;
|
| 420 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 421 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 422 |
+
s15 ^= s3;
|
| 423 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 424 |
+
s11 = s11 + s15 | 0;
|
| 425 |
+
s7 ^= s11;
|
| 426 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 427 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 428 |
+
s15 ^= s3;
|
| 429 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 430 |
+
s11 = s11 + s15 | 0;
|
| 431 |
+
s7 ^= s11;
|
| 432 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 433 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 434 |
+
s15 ^= s0;
|
| 435 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 436 |
+
s10 = s10 + s15 | 0;
|
| 437 |
+
s5 ^= s10;
|
| 438 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 439 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 440 |
+
s15 ^= s0;
|
| 441 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 442 |
+
s10 = s10 + s15 | 0;
|
| 443 |
+
s5 ^= s10;
|
| 444 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 445 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 446 |
+
s12 ^= s1;
|
| 447 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 448 |
+
s11 = s11 + s12 | 0;
|
| 449 |
+
s6 ^= s11;
|
| 450 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 451 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 452 |
+
s12 ^= s1;
|
| 453 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 454 |
+
s11 = s11 + s12 | 0;
|
| 455 |
+
s6 ^= s11;
|
| 456 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 457 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 458 |
+
s13 ^= s2;
|
| 459 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 460 |
+
s8 = s8 + s13 | 0;
|
| 461 |
+
s7 ^= s8;
|
| 462 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 463 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 464 |
+
s13 ^= s2;
|
| 465 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 466 |
+
s8 = s8 + s13 | 0;
|
| 467 |
+
s7 ^= s8;
|
| 468 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 469 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 470 |
+
s14 ^= s3;
|
| 471 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 472 |
+
s9 = s9 + s14 | 0;
|
| 473 |
+
s4 ^= s9;
|
| 474 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 475 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 476 |
+
s14 ^= s3;
|
| 477 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 478 |
+
s9 = s9 + s14 | 0;
|
| 479 |
+
s4 ^= s9;
|
| 480 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 481 |
+
{
|
| 482 |
+
const t0 = m0, t1 = m1;
|
| 483 |
+
m0 = m2;
|
| 484 |
+
m2 = m3;
|
| 485 |
+
m3 = m10;
|
| 486 |
+
m10 = m12;
|
| 487 |
+
m12 = m9;
|
| 488 |
+
m9 = m11;
|
| 489 |
+
m11 = m5;
|
| 490 |
+
m5 = t0;
|
| 491 |
+
m1 = m6;
|
| 492 |
+
m6 = m4;
|
| 493 |
+
m4 = m7;
|
| 494 |
+
m7 = m13;
|
| 495 |
+
m13 = m14;
|
| 496 |
+
m14 = m15;
|
| 497 |
+
m15 = m8;
|
| 498 |
+
m8 = t1;
|
| 499 |
+
}
|
| 500 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 501 |
+
s12 ^= s0;
|
| 502 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 503 |
+
s8 = s8 + s12 | 0;
|
| 504 |
+
s4 ^= s8;
|
| 505 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 506 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 507 |
+
s12 ^= s0;
|
| 508 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 509 |
+
s8 = s8 + s12 | 0;
|
| 510 |
+
s4 ^= s8;
|
| 511 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 512 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 513 |
+
s13 ^= s1;
|
| 514 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 515 |
+
s9 = s9 + s13 | 0;
|
| 516 |
+
s5 ^= s9;
|
| 517 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 518 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 519 |
+
s13 ^= s1;
|
| 520 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 521 |
+
s9 = s9 + s13 | 0;
|
| 522 |
+
s5 ^= s9;
|
| 523 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 524 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 525 |
+
s14 ^= s2;
|
| 526 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 527 |
+
s10 = s10 + s14 | 0;
|
| 528 |
+
s6 ^= s10;
|
| 529 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 530 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 531 |
+
s14 ^= s2;
|
| 532 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 533 |
+
s10 = s10 + s14 | 0;
|
| 534 |
+
s6 ^= s10;
|
| 535 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 536 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 537 |
+
s15 ^= s3;
|
| 538 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 539 |
+
s11 = s11 + s15 | 0;
|
| 540 |
+
s7 ^= s11;
|
| 541 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 542 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 543 |
+
s15 ^= s3;
|
| 544 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 545 |
+
s11 = s11 + s15 | 0;
|
| 546 |
+
s7 ^= s11;
|
| 547 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 548 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 549 |
+
s15 ^= s0;
|
| 550 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 551 |
+
s10 = s10 + s15 | 0;
|
| 552 |
+
s5 ^= s10;
|
| 553 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 554 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 555 |
+
s15 ^= s0;
|
| 556 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 557 |
+
s10 = s10 + s15 | 0;
|
| 558 |
+
s5 ^= s10;
|
| 559 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 560 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 561 |
+
s12 ^= s1;
|
| 562 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 563 |
+
s11 = s11 + s12 | 0;
|
| 564 |
+
s6 ^= s11;
|
| 565 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 566 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 567 |
+
s12 ^= s1;
|
| 568 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 569 |
+
s11 = s11 + s12 | 0;
|
| 570 |
+
s6 ^= s11;
|
| 571 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 572 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 573 |
+
s13 ^= s2;
|
| 574 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 575 |
+
s8 = s8 + s13 | 0;
|
| 576 |
+
s7 ^= s8;
|
| 577 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 578 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 579 |
+
s13 ^= s2;
|
| 580 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 581 |
+
s8 = s8 + s13 | 0;
|
| 582 |
+
s7 ^= s8;
|
| 583 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 584 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 585 |
+
s14 ^= s3;
|
| 586 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 587 |
+
s9 = s9 + s14 | 0;
|
| 588 |
+
s4 ^= s9;
|
| 589 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 590 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 591 |
+
s14 ^= s3;
|
| 592 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 593 |
+
s9 = s9 + s14 | 0;
|
| 594 |
+
s4 ^= s9;
|
| 595 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 596 |
+
{
|
| 597 |
+
const t0 = m0, t1 = m1;
|
| 598 |
+
m0 = m2;
|
| 599 |
+
m2 = m3;
|
| 600 |
+
m3 = m10;
|
| 601 |
+
m10 = m12;
|
| 602 |
+
m12 = m9;
|
| 603 |
+
m9 = m11;
|
| 604 |
+
m11 = m5;
|
| 605 |
+
m5 = t0;
|
| 606 |
+
m1 = m6;
|
| 607 |
+
m6 = m4;
|
| 608 |
+
m4 = m7;
|
| 609 |
+
m7 = m13;
|
| 610 |
+
m13 = m14;
|
| 611 |
+
m14 = m15;
|
| 612 |
+
m15 = m8;
|
| 613 |
+
m8 = t1;
|
| 614 |
+
}
|
| 615 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 616 |
+
s12 ^= s0;
|
| 617 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 618 |
+
s8 = s8 + s12 | 0;
|
| 619 |
+
s4 ^= s8;
|
| 620 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 621 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 622 |
+
s12 ^= s0;
|
| 623 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 624 |
+
s8 = s8 + s12 | 0;
|
| 625 |
+
s4 ^= s8;
|
| 626 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 627 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 628 |
+
s13 ^= s1;
|
| 629 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 630 |
+
s9 = s9 + s13 | 0;
|
| 631 |
+
s5 ^= s9;
|
| 632 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 633 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 634 |
+
s13 ^= s1;
|
| 635 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 636 |
+
s9 = s9 + s13 | 0;
|
| 637 |
+
s5 ^= s9;
|
| 638 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 639 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 640 |
+
s14 ^= s2;
|
| 641 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 642 |
+
s10 = s10 + s14 | 0;
|
| 643 |
+
s6 ^= s10;
|
| 644 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 645 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 646 |
+
s14 ^= s2;
|
| 647 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 648 |
+
s10 = s10 + s14 | 0;
|
| 649 |
+
s6 ^= s10;
|
| 650 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 651 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 652 |
+
s15 ^= s3;
|
| 653 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 654 |
+
s11 = s11 + s15 | 0;
|
| 655 |
+
s7 ^= s11;
|
| 656 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 657 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 658 |
+
s15 ^= s3;
|
| 659 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 660 |
+
s11 = s11 + s15 | 0;
|
| 661 |
+
s7 ^= s11;
|
| 662 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 663 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 664 |
+
s15 ^= s0;
|
| 665 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 666 |
+
s10 = s10 + s15 | 0;
|
| 667 |
+
s5 ^= s10;
|
| 668 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 669 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 670 |
+
s15 ^= s0;
|
| 671 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 672 |
+
s10 = s10 + s15 | 0;
|
| 673 |
+
s5 ^= s10;
|
| 674 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 675 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 676 |
+
s12 ^= s1;
|
| 677 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 678 |
+
s11 = s11 + s12 | 0;
|
| 679 |
+
s6 ^= s11;
|
| 680 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 681 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 682 |
+
s12 ^= s1;
|
| 683 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 684 |
+
s11 = s11 + s12 | 0;
|
| 685 |
+
s6 ^= s11;
|
| 686 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 687 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 688 |
+
s13 ^= s2;
|
| 689 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 690 |
+
s8 = s8 + s13 | 0;
|
| 691 |
+
s7 ^= s8;
|
| 692 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 693 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 694 |
+
s13 ^= s2;
|
| 695 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 696 |
+
s8 = s8 + s13 | 0;
|
| 697 |
+
s7 ^= s8;
|
| 698 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 699 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 700 |
+
s14 ^= s3;
|
| 701 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 702 |
+
s9 = s9 + s14 | 0;
|
| 703 |
+
s4 ^= s9;
|
| 704 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 705 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 706 |
+
s14 ^= s3;
|
| 707 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 708 |
+
s9 = s9 + s14 | 0;
|
| 709 |
+
s4 ^= s9;
|
| 710 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 711 |
+
{
|
| 712 |
+
const t0 = m0, t1 = m1;
|
| 713 |
+
m0 = m2;
|
| 714 |
+
m2 = m3;
|
| 715 |
+
m3 = m10;
|
| 716 |
+
m10 = m12;
|
| 717 |
+
m12 = m9;
|
| 718 |
+
m9 = m11;
|
| 719 |
+
m11 = m5;
|
| 720 |
+
m5 = t0;
|
| 721 |
+
m1 = m6;
|
| 722 |
+
m6 = m4;
|
| 723 |
+
m4 = m7;
|
| 724 |
+
m7 = m13;
|
| 725 |
+
m13 = m14;
|
| 726 |
+
m14 = m15;
|
| 727 |
+
m15 = m8;
|
| 728 |
+
m8 = t1;
|
| 729 |
+
}
|
| 730 |
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
| 731 |
+
s12 ^= s0;
|
| 732 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 733 |
+
s8 = s8 + s12 | 0;
|
| 734 |
+
s4 ^= s8;
|
| 735 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 736 |
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
| 737 |
+
s12 ^= s0;
|
| 738 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 739 |
+
s8 = s8 + s12 | 0;
|
| 740 |
+
s4 ^= s8;
|
| 741 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 742 |
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
| 743 |
+
s13 ^= s1;
|
| 744 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 745 |
+
s9 = s9 + s13 | 0;
|
| 746 |
+
s5 ^= s9;
|
| 747 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 748 |
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
| 749 |
+
s13 ^= s1;
|
| 750 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 751 |
+
s9 = s9 + s13 | 0;
|
| 752 |
+
s5 ^= s9;
|
| 753 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 754 |
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
| 755 |
+
s14 ^= s2;
|
| 756 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 757 |
+
s10 = s10 + s14 | 0;
|
| 758 |
+
s6 ^= s10;
|
| 759 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 760 |
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
| 761 |
+
s14 ^= s2;
|
| 762 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 763 |
+
s10 = s10 + s14 | 0;
|
| 764 |
+
s6 ^= s10;
|
| 765 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 766 |
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
| 767 |
+
s15 ^= s3;
|
| 768 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 769 |
+
s11 = s11 + s15 | 0;
|
| 770 |
+
s7 ^= s11;
|
| 771 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 772 |
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
| 773 |
+
s15 ^= s3;
|
| 774 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 775 |
+
s11 = s11 + s15 | 0;
|
| 776 |
+
s7 ^= s11;
|
| 777 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 778 |
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
| 779 |
+
s15 ^= s0;
|
| 780 |
+
s15 = s15 >>> 16 | s15 << 16;
|
| 781 |
+
s10 = s10 + s15 | 0;
|
| 782 |
+
s5 ^= s10;
|
| 783 |
+
s5 = s5 >>> 12 | s5 << 20;
|
| 784 |
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
| 785 |
+
s15 ^= s0;
|
| 786 |
+
s15 = s15 >>> 8 | s15 << 24;
|
| 787 |
+
s10 = s10 + s15 | 0;
|
| 788 |
+
s5 ^= s10;
|
| 789 |
+
s5 = s5 >>> 7 | s5 << 25;
|
| 790 |
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
| 791 |
+
s12 ^= s1;
|
| 792 |
+
s12 = s12 >>> 16 | s12 << 16;
|
| 793 |
+
s11 = s11 + s12 | 0;
|
| 794 |
+
s6 ^= s11;
|
| 795 |
+
s6 = s6 >>> 12 | s6 << 20;
|
| 796 |
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
| 797 |
+
s12 ^= s1;
|
| 798 |
+
s12 = s12 >>> 8 | s12 << 24;
|
| 799 |
+
s11 = s11 + s12 | 0;
|
| 800 |
+
s6 ^= s11;
|
| 801 |
+
s6 = s6 >>> 7 | s6 << 25;
|
| 802 |
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
| 803 |
+
s13 ^= s2;
|
| 804 |
+
s13 = s13 >>> 16 | s13 << 16;
|
| 805 |
+
s8 = s8 + s13 | 0;
|
| 806 |
+
s7 ^= s8;
|
| 807 |
+
s7 = s7 >>> 12 | s7 << 20;
|
| 808 |
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
| 809 |
+
s13 ^= s2;
|
| 810 |
+
s13 = s13 >>> 8 | s13 << 24;
|
| 811 |
+
s8 = s8 + s13 | 0;
|
| 812 |
+
s7 ^= s8;
|
| 813 |
+
s7 = s7 >>> 7 | s7 << 25;
|
| 814 |
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
| 815 |
+
s14 ^= s3;
|
| 816 |
+
s14 = s14 >>> 16 | s14 << 16;
|
| 817 |
+
s9 = s9 + s14 | 0;
|
| 818 |
+
s4 ^= s9;
|
| 819 |
+
s4 = s4 >>> 12 | s4 << 20;
|
| 820 |
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
| 821 |
+
s14 ^= s3;
|
| 822 |
+
s14 = s14 >>> 8 | s14 << 24;
|
| 823 |
+
s9 = s9 + s14 | 0;
|
| 824 |
+
s4 ^= s9;
|
| 825 |
+
s4 = s4 >>> 7 | s4 << 25;
|
| 826 |
+
if (full) {
|
| 827 |
+
out[outOff + 8] = s8 ^ cv[cvOff];
|
| 828 |
+
out[outOff + 9] = s9 ^ cv[cvOff + 1];
|
| 829 |
+
out[outOff + 10] = s10 ^ cv[cvOff + 2];
|
| 830 |
+
out[outOff + 11] = s11 ^ cv[cvOff + 3];
|
| 831 |
+
out[outOff + 12] = s12 ^ cv[cvOff + 4];
|
| 832 |
+
out[outOff + 13] = s13 ^ cv[cvOff + 5];
|
| 833 |
+
out[outOff + 14] = s14 ^ cv[cvOff + 6];
|
| 834 |
+
out[outOff + 15] = s15 ^ cv[cvOff + 7];
|
| 835 |
+
}
|
| 836 |
+
out[outOff] = s0 ^ s8;
|
| 837 |
+
out[outOff + 1] = s1 ^ s9;
|
| 838 |
+
out[outOff + 2] = s2 ^ s10;
|
| 839 |
+
out[outOff + 3] = s3 ^ s11;
|
| 840 |
+
out[outOff + 4] = s4 ^ s12;
|
| 841 |
+
out[outOff + 5] = s5 ^ s13;
|
| 842 |
+
out[outOff + 6] = s6 ^ s14;
|
| 843 |
+
out[outOff + 7] = s7 ^ s15;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/constants.js
|
| 847 |
+
var IV = new Uint32Array([
|
| 848 |
+
1779033703,
|
| 849 |
+
3144134277,
|
| 850 |
+
1013904242,
|
| 851 |
+
2773480762,
|
| 852 |
+
1359893119,
|
| 853 |
+
2600822924,
|
| 854 |
+
528734635,
|
| 855 |
+
1541459225
|
| 856 |
+
]);
|
| 857 |
+
var CHUNK_START = 1;
|
| 858 |
+
var CHUNK_END = 1 << 1;
|
| 859 |
+
var PARENT = 1 << 2;
|
| 860 |
+
var ROOT = 1 << 3;
|
| 861 |
+
var KEYED_HASH = 1 << 4;
|
| 862 |
+
var DERIVE_KEY_CONTEXT = 1 << 5;
|
| 863 |
+
var DERIVE_KEY_MATERIAL = 1 << 6;
|
| 864 |
+
var OUT_LEN = 32;
|
| 865 |
+
var KEY_LEN = 32;
|
| 866 |
+
var BLOCK_LEN = 64;
|
| 867 |
+
var CHUNK_LEN = 1024;
|
| 868 |
+
var MAX_DEPTH = 54;
|
| 869 |
+
var PERMUTATIONS = new Uint8Array([
|
| 870 |
+
0,
|
| 871 |
+
1,
|
| 872 |
+
2,
|
| 873 |
+
3,
|
| 874 |
+
4,
|
| 875 |
+
5,
|
| 876 |
+
6,
|
| 877 |
+
7,
|
| 878 |
+
8,
|
| 879 |
+
9,
|
| 880 |
+
10,
|
| 881 |
+
11,
|
| 882 |
+
12,
|
| 883 |
+
13,
|
| 884 |
+
14,
|
| 885 |
+
15,
|
| 886 |
+
2,
|
| 887 |
+
6,
|
| 888 |
+
3,
|
| 889 |
+
10,
|
| 890 |
+
7,
|
| 891 |
+
0,
|
| 892 |
+
4,
|
| 893 |
+
13,
|
| 894 |
+
1,
|
| 895 |
+
11,
|
| 896 |
+
12,
|
| 897 |
+
5,
|
| 898 |
+
9,
|
| 899 |
+
14,
|
| 900 |
+
15,
|
| 901 |
+
8,
|
| 902 |
+
3,
|
| 903 |
+
4,
|
| 904 |
+
10,
|
| 905 |
+
12,
|
| 906 |
+
13,
|
| 907 |
+
2,
|
| 908 |
+
7,
|
| 909 |
+
14,
|
| 910 |
+
6,
|
| 911 |
+
5,
|
| 912 |
+
9,
|
| 913 |
+
0,
|
| 914 |
+
11,
|
| 915 |
+
15,
|
| 916 |
+
8,
|
| 917 |
+
1,
|
| 918 |
+
10,
|
| 919 |
+
7,
|
| 920 |
+
12,
|
| 921 |
+
9,
|
| 922 |
+
14,
|
| 923 |
+
3,
|
| 924 |
+
13,
|
| 925 |
+
15,
|
| 926 |
+
4,
|
| 927 |
+
0,
|
| 928 |
+
11,
|
| 929 |
+
2,
|
| 930 |
+
5,
|
| 931 |
+
8,
|
| 932 |
+
1,
|
| 933 |
+
6,
|
| 934 |
+
12,
|
| 935 |
+
13,
|
| 936 |
+
9,
|
| 937 |
+
11,
|
| 938 |
+
15,
|
| 939 |
+
10,
|
| 940 |
+
14,
|
| 941 |
+
8,
|
| 942 |
+
7,
|
| 943 |
+
2,
|
| 944 |
+
5,
|
| 945 |
+
3,
|
| 946 |
+
0,
|
| 947 |
+
1,
|
| 948 |
+
6,
|
| 949 |
+
4,
|
| 950 |
+
9,
|
| 951 |
+
14,
|
| 952 |
+
11,
|
| 953 |
+
5,
|
| 954 |
+
8,
|
| 955 |
+
12,
|
| 956 |
+
15,
|
| 957 |
+
1,
|
| 958 |
+
13,
|
| 959 |
+
3,
|
| 960 |
+
0,
|
| 961 |
+
10,
|
| 962 |
+
2,
|
| 963 |
+
6,
|
| 964 |
+
4,
|
| 965 |
+
7,
|
| 966 |
+
11,
|
| 967 |
+
15,
|
| 968 |
+
5,
|
| 969 |
+
0,
|
| 970 |
+
1,
|
| 971 |
+
9,
|
| 972 |
+
8,
|
| 973 |
+
6,
|
| 974 |
+
14,
|
| 975 |
+
10,
|
| 976 |
+
2,
|
| 977 |
+
12,
|
| 978 |
+
3,
|
| 979 |
+
4,
|
| 980 |
+
7,
|
| 981 |
+
13
|
| 982 |
+
]);
|
| 983 |
+
|
| 984 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/utils.js
|
| 985 |
+
var IS_LITTLE_ENDIAN = new Uint8Array(new Uint32Array([16909060]).buffer)[0] === 4;
|
| 986 |
+
function readLittleEndianWordsFull(input, offset, words) {
|
| 987 |
+
for (let i = 0; i < 16; ++i, offset += 4) {
|
| 988 |
+
words[i] = input[offset] | input[offset + 1] << 8 | input[offset + 2] << 16 | input[offset + 3] << 24;
|
| 989 |
+
}
|
| 990 |
+
}
|
| 991 |
+
function writeLittleEndianBytesPartial(words, wordOffset, output, byteOffset, byteCount) {
|
| 992 |
+
const fullWords = byteCount >>> 2;
|
| 993 |
+
let i = 0;
|
| 994 |
+
for (; i < fullWords; ++i, byteOffset += 4) {
|
| 995 |
+
const w = words[wordOffset + i];
|
| 996 |
+
output[byteOffset] = w & 255;
|
| 997 |
+
output[byteOffset + 1] = w >>> 8 & 255;
|
| 998 |
+
output[byteOffset + 2] = w >>> 16 & 255;
|
| 999 |
+
output[byteOffset + 3] = w >>> 24 & 255;
|
| 1000 |
+
}
|
| 1001 |
+
const remaining = byteCount & 3;
|
| 1002 |
+
if (remaining > 0) {
|
| 1003 |
+
const w = words[wordOffset + i];
|
| 1004 |
+
output[byteOffset] = w & 255;
|
| 1005 |
+
if (remaining > 1)
|
| 1006 |
+
output[byteOffset + 1] = w >>> 8 & 255;
|
| 1007 |
+
if (remaining > 2)
|
| 1008 |
+
output[byteOffset + 2] = w >>> 16 & 255;
|
| 1009 |
+
}
|
| 1010 |
+
}
|
| 1011 |
+
function encodeUTF8(str) {
|
| 1012 |
+
if (typeof TextEncoder !== "undefined") {
|
| 1013 |
+
return new TextEncoder().encode(str);
|
| 1014 |
+
}
|
| 1015 |
+
const bytes = [];
|
| 1016 |
+
for (let i = 0; i < str.length; i++) {
|
| 1017 |
+
let c = str.charCodeAt(i);
|
| 1018 |
+
if (c < 128) {
|
| 1019 |
+
bytes.push(c);
|
| 1020 |
+
} else if (c < 2048) {
|
| 1021 |
+
bytes.push(192 | c >> 6, 128 | c & 63);
|
| 1022 |
+
} else if (c < 55296 || c >= 57344) {
|
| 1023 |
+
bytes.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
| 1024 |
+
} else {
|
| 1025 |
+
i++;
|
| 1026 |
+
c = 65536 + ((c & 1023) << 10 | str.charCodeAt(i) & 1023);
|
| 1027 |
+
bytes.push(240 | c >> 18, 128 | c >> 12 & 63, 128 | c >> 6 & 63, 128 | c & 63);
|
| 1028 |
+
}
|
| 1029 |
+
}
|
| 1030 |
+
return new Uint8Array(bytes);
|
| 1031 |
+
}
|
| 1032 |
+
var CTZ32_TABLE = new Uint8Array([
|
| 1033 |
+
0,
|
| 1034 |
+
1,
|
| 1035 |
+
28,
|
| 1036 |
+
2,
|
| 1037 |
+
29,
|
| 1038 |
+
14,
|
| 1039 |
+
24,
|
| 1040 |
+
3,
|
| 1041 |
+
30,
|
| 1042 |
+
22,
|
| 1043 |
+
20,
|
| 1044 |
+
15,
|
| 1045 |
+
25,
|
| 1046 |
+
17,
|
| 1047 |
+
4,
|
| 1048 |
+
8,
|
| 1049 |
+
31,
|
| 1050 |
+
27,
|
| 1051 |
+
13,
|
| 1052 |
+
23,
|
| 1053 |
+
21,
|
| 1054 |
+
19,
|
| 1055 |
+
16,
|
| 1056 |
+
7,
|
| 1057 |
+
26,
|
| 1058 |
+
12,
|
| 1059 |
+
18,
|
| 1060 |
+
6,
|
| 1061 |
+
11,
|
| 1062 |
+
5,
|
| 1063 |
+
10,
|
| 1064 |
+
9
|
| 1065 |
+
]);
|
| 1066 |
+
|
| 1067 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/hasher.js
|
| 1068 |
+
var XofReader = class {
|
| 1069 |
+
inputCv;
|
| 1070 |
+
blockWords;
|
| 1071 |
+
counter;
|
| 1072 |
+
blockLen;
|
| 1073 |
+
flags;
|
| 1074 |
+
outputBlock;
|
| 1075 |
+
outputBlockOffset;
|
| 1076 |
+
constructor(inputCv, blockWords, counter, blockLen, flags) {
|
| 1077 |
+
this.inputCv = inputCv;
|
| 1078 |
+
this.blockWords = blockWords;
|
| 1079 |
+
this.counter = counter;
|
| 1080 |
+
this.blockLen = blockLen;
|
| 1081 |
+
this.flags = flags | ROOT;
|
| 1082 |
+
this.outputBlock = new Uint32Array(16);
|
| 1083 |
+
this.outputBlockOffset = 64;
|
| 1084 |
+
}
|
| 1085 |
+
/**
|
| 1086 |
+
* Read the next `length` bytes of output.
|
| 1087 |
+
*/
|
| 1088 |
+
read(length) {
|
| 1089 |
+
const output = new Uint8Array(length);
|
| 1090 |
+
let outputOffset = 0;
|
| 1091 |
+
while (outputOffset < length) {
|
| 1092 |
+
if (this.outputBlockOffset >= 64) {
|
| 1093 |
+
compress(
|
| 1094 |
+
this.inputCv,
|
| 1095 |
+
0,
|
| 1096 |
+
this.blockWords,
|
| 1097 |
+
0,
|
| 1098 |
+
this.outputBlock,
|
| 1099 |
+
0,
|
| 1100 |
+
true,
|
| 1101 |
+
// full 64-byte output
|
| 1102 |
+
this.counter++,
|
| 1103 |
+
this.blockLen,
|
| 1104 |
+
this.flags
|
| 1105 |
+
);
|
| 1106 |
+
this.outputBlockOffset = 0;
|
| 1107 |
+
}
|
| 1108 |
+
const available = 64 - this.outputBlockOffset;
|
| 1109 |
+
const toCopy = Math.min(available, length - outputOffset);
|
| 1110 |
+
const wordOffset = this.outputBlockOffset >>> 2;
|
| 1111 |
+
const byteWithinWord = this.outputBlockOffset & 3;
|
| 1112 |
+
if (byteWithinWord === 0 && toCopy >= 4) {
|
| 1113 |
+
const fullWords = toCopy >>> 2;
|
| 1114 |
+
writeLittleEndianBytesPartial(this.outputBlock, wordOffset, output, outputOffset, fullWords << 2);
|
| 1115 |
+
const bytesCopied = fullWords << 2;
|
| 1116 |
+
outputOffset += bytesCopied;
|
| 1117 |
+
this.outputBlockOffset += bytesCopied;
|
| 1118 |
+
} else {
|
| 1119 |
+
for (let i = 0; i < toCopy; i++) {
|
| 1120 |
+
const wordIdx = this.outputBlockOffset + i >>> 2;
|
| 1121 |
+
const byteIdx = this.outputBlockOffset + i & 3;
|
| 1122 |
+
output[outputOffset + i] = this.outputBlock[wordIdx] >>> (byteIdx << 3) & 255;
|
| 1123 |
+
}
|
| 1124 |
+
outputOffset += toCopy;
|
| 1125 |
+
this.outputBlockOffset += toCopy;
|
| 1126 |
+
}
|
| 1127 |
+
}
|
| 1128 |
+
return output;
|
| 1129 |
+
}
|
| 1130 |
+
};
|
| 1131 |
+
var ChunkState = class {
|
| 1132 |
+
chainingValue;
|
| 1133 |
+
chunkCounter;
|
| 1134 |
+
blockWords;
|
| 1135 |
+
blockLen;
|
| 1136 |
+
blocksCompressed;
|
| 1137 |
+
flags;
|
| 1138 |
+
constructor(keyWords, chunkCounter, flags) {
|
| 1139 |
+
this.chainingValue = new Uint32Array(keyWords);
|
| 1140 |
+
this.chunkCounter = chunkCounter;
|
| 1141 |
+
this.blockWords = new Uint32Array(16);
|
| 1142 |
+
this.blockLen = 0;
|
| 1143 |
+
this.blocksCompressed = 0;
|
| 1144 |
+
this.flags = flags;
|
| 1145 |
+
}
|
| 1146 |
+
resetTo(keyWords, chunkCounter, flags) {
|
| 1147 |
+
this.chainingValue.set(keyWords);
|
| 1148 |
+
this.chunkCounter = chunkCounter;
|
| 1149 |
+
this.blockLen = 0;
|
| 1150 |
+
this.blocksCompressed = 0;
|
| 1151 |
+
this.flags = flags;
|
| 1152 |
+
}
|
| 1153 |
+
/**
|
| 1154 |
+
* Get the flags for the current block.
|
| 1155 |
+
*/
|
| 1156 |
+
startFlag() {
|
| 1157 |
+
return this.blocksCompressed === 0 ? CHUNK_START : 0;
|
| 1158 |
+
}
|
| 1159 |
+
/**
|
| 1160 |
+
* Update the chunk state with input data.
|
| 1161 |
+
* Returns the number of bytes consumed.
|
| 1162 |
+
*/
|
| 1163 |
+
update(input, inputOffset, inputLen) {
|
| 1164 |
+
let consumed = 0;
|
| 1165 |
+
while (inputLen > 0) {
|
| 1166 |
+
if (this.blockLen === BLOCK_LEN) {
|
| 1167 |
+
compress(this.chainingValue, 0, this.blockWords, 0, this.chainingValue, 0, false, this.chunkCounter, BLOCK_LEN, this.flags | this.startFlag());
|
| 1168 |
+
this.blocksCompressed++;
|
| 1169 |
+
this.blockLen = 0;
|
| 1170 |
+
}
|
| 1171 |
+
const want = BLOCK_LEN - this.blockLen;
|
| 1172 |
+
const take = Math.min(want, inputLen);
|
| 1173 |
+
if (this.blockLen === 0 && take === BLOCK_LEN) {
|
| 1174 |
+
readLittleEndianWordsFull(input, inputOffset, this.blockWords);
|
| 1175 |
+
} else {
|
| 1176 |
+
for (let i = 0; i < take; i++) {
|
| 1177 |
+
const pos = this.blockLen + i;
|
| 1178 |
+
const wordIdx = pos >>> 2;
|
| 1179 |
+
const byteIdx = pos & 3;
|
| 1180 |
+
if (byteIdx === 0) {
|
| 1181 |
+
this.blockWords[wordIdx] = input[inputOffset + i];
|
| 1182 |
+
} else {
|
| 1183 |
+
this.blockWords[wordIdx] |= input[inputOffset + i] << (byteIdx << 3);
|
| 1184 |
+
}
|
| 1185 |
+
}
|
| 1186 |
+
}
|
| 1187 |
+
this.blockLen += take;
|
| 1188 |
+
inputOffset += take;
|
| 1189 |
+
inputLen -= take;
|
| 1190 |
+
consumed += take;
|
| 1191 |
+
}
|
| 1192 |
+
return consumed;
|
| 1193 |
+
}
|
| 1194 |
+
/**
|
| 1195 |
+
* Finalize this chunk and return its output.
|
| 1196 |
+
* Returns 8 words (chaining value) or 16 words (if root).
|
| 1197 |
+
*/
|
| 1198 |
+
output() {
|
| 1199 |
+
const usedWords = this.blockLen + 3 >>> 2;
|
| 1200 |
+
for (let i = usedWords; i < 16; i++) {
|
| 1201 |
+
this.blockWords[i] = 0;
|
| 1202 |
+
}
|
| 1203 |
+
return {
|
| 1204 |
+
inputCv: this.chainingValue,
|
| 1205 |
+
blockWords: this.blockWords,
|
| 1206 |
+
blockLen: this.blockLen,
|
| 1207 |
+
counter: this.chunkCounter,
|
| 1208 |
+
flags: this.flags | this.startFlag() | CHUNK_END
|
| 1209 |
+
};
|
| 1210 |
+
}
|
| 1211 |
+
/**
|
| 1212 |
+
* Get the number of bytes in this chunk.
|
| 1213 |
+
*/
|
| 1214 |
+
len() {
|
| 1215 |
+
return this.blocksCompressed * BLOCK_LEN + this.blockLen;
|
| 1216 |
+
}
|
| 1217 |
+
};
|
| 1218 |
+
var Hasher = class _Hasher {
|
| 1219 |
+
chunkState;
|
| 1220 |
+
keyWords;
|
| 1221 |
+
cvStack;
|
| 1222 |
+
cvStackLen;
|
| 1223 |
+
flags;
|
| 1224 |
+
parentBlock;
|
| 1225 |
+
parentCv;
|
| 1226 |
+
chunkCv;
|
| 1227 |
+
outWords;
|
| 1228 |
+
finalizeCv;
|
| 1229 |
+
/**
|
| 1230 |
+
* Create a new Hasher.
|
| 1231 |
+
*
|
| 1232 |
+
* @param keyWords - Initial key words (IV for regular hashing)
|
| 1233 |
+
* @param flags - Domain separation flags
|
| 1234 |
+
*/
|
| 1235 |
+
constructor(keyWords, flags) {
|
| 1236 |
+
this.keyWords = keyWords ? new Uint32Array(keyWords) : new Uint32Array(IV);
|
| 1237 |
+
this.flags = flags ?? 0;
|
| 1238 |
+
this.chunkState = new ChunkState(this.keyWords, 0, this.flags);
|
| 1239 |
+
this.cvStack = new Uint32Array(MAX_DEPTH * 8);
|
| 1240 |
+
this.cvStackLen = 0;
|
| 1241 |
+
this.parentBlock = new Uint32Array(16);
|
| 1242 |
+
this.parentCv = new Uint32Array(8);
|
| 1243 |
+
this.chunkCv = new Uint32Array(8);
|
| 1244 |
+
this.outWords = new Uint32Array(16);
|
| 1245 |
+
this.finalizeCv = new Uint32Array(8);
|
| 1246 |
+
}
|
| 1247 |
+
/**
|
| 1248 |
+
* Reset the hasher to process a new message with the same key/flags.
|
| 1249 |
+
* Reuses all internal buffers — zero allocations.
|
| 1250 |
+
*/
|
| 1251 |
+
reset() {
|
| 1252 |
+
this.chunkState.resetTo(this.keyWords, 0, this.flags);
|
| 1253 |
+
this.cvStackLen = 0;
|
| 1254 |
+
return this;
|
| 1255 |
+
}
|
| 1256 |
+
/**
|
| 1257 |
+
* Create a new keyed hasher (MAC).
|
| 1258 |
+
*
|
| 1259 |
+
* @param key - 32-byte key
|
| 1260 |
+
*/
|
| 1261 |
+
static newKeyed(key) {
|
| 1262 |
+
if (key.length !== KEY_LEN) {
|
| 1263 |
+
throw new Error(`Key must be ${KEY_LEN} bytes, got ${key.length}`);
|
| 1264 |
+
}
|
| 1265 |
+
const keyWords = new Uint32Array(8);
|
| 1266 |
+
if (IS_LITTLE_ENDIAN) {
|
| 1267 |
+
const view = new Uint32Array(key.buffer, key.byteOffset, 8);
|
| 1268 |
+
keyWords.set(view);
|
| 1269 |
+
} else {
|
| 1270 |
+
for (let i = 0; i < 8; i++) {
|
| 1271 |
+
const off = i * 4;
|
| 1272 |
+
keyWords[i] = key[off] | key[off + 1] << 8 | key[off + 2] << 16 | key[off + 3] << 24;
|
| 1273 |
+
}
|
| 1274 |
+
}
|
| 1275 |
+
return new _Hasher(keyWords, KEYED_HASH);
|
| 1276 |
+
}
|
| 1277 |
+
/**
|
| 1278 |
+
* Create a new key derivation hasher.
|
| 1279 |
+
*
|
| 1280 |
+
* @param context - Context string for domain separation
|
| 1281 |
+
*/
|
| 1282 |
+
static newDeriveKey(context) {
|
| 1283 |
+
const contextBytes = encodeUTF8(context);
|
| 1284 |
+
const contextHasher = new _Hasher(new Uint32Array(IV), DERIVE_KEY_CONTEXT);
|
| 1285 |
+
contextHasher.update(contextBytes);
|
| 1286 |
+
const contextKey = new Uint32Array(8);
|
| 1287 |
+
const output = contextHasher.finalizeOutput();
|
| 1288 |
+
compress(output.inputCv, 0, output.blockWords, 0, contextKey, 0, false, output.counter, output.blockLen, output.flags | ROOT);
|
| 1289 |
+
return new _Hasher(contextKey, DERIVE_KEY_MATERIAL);
|
| 1290 |
+
}
|
| 1291 |
+
/**
|
| 1292 |
+
* Push a chaining value onto the stack.
|
| 1293 |
+
*/
|
| 1294 |
+
pushCv(cv, cvOffset) {
|
| 1295 |
+
this.cvStack.set(cv.subarray(cvOffset, cvOffset + 8), this.cvStackLen * 8);
|
| 1296 |
+
this.cvStackLen++;
|
| 1297 |
+
}
|
| 1298 |
+
/**
|
| 1299 |
+
* Pop a chaining value from the stack.
|
| 1300 |
+
*/
|
| 1301 |
+
popCv(out, outOffset) {
|
| 1302 |
+
this.cvStackLen--;
|
| 1303 |
+
out.set(this.cvStack.subarray(this.cvStackLen * 8, (this.cvStackLen + 1) * 8), outOffset);
|
| 1304 |
+
}
|
| 1305 |
+
/**
|
| 1306 |
+
* Add a chunk's chaining value and merge completed subtrees.
|
| 1307 |
+
*/
|
| 1308 |
+
addChunkCv(newCv, newCvOffset, totalChunks) {
|
| 1309 |
+
const parentBlock = this.parentBlock;
|
| 1310 |
+
const parentCv = this.parentCv;
|
| 1311 |
+
while ((totalChunks & 1) === 0) {
|
| 1312 |
+
this.popCv(parentBlock, 0);
|
| 1313 |
+
parentBlock.set(newCv.subarray(newCvOffset, newCvOffset + 8), 8);
|
| 1314 |
+
compress(this.keyWords, 0, parentBlock, 0, parentCv, 0, false, 0, BLOCK_LEN, this.flags | PARENT);
|
| 1315 |
+
newCv = parentCv;
|
| 1316 |
+
newCvOffset = 0;
|
| 1317 |
+
totalChunks >>>= 1;
|
| 1318 |
+
}
|
| 1319 |
+
this.pushCv(newCv, newCvOffset);
|
| 1320 |
+
}
|
| 1321 |
+
/**
|
| 1322 |
+
* Update the hasher with input data.
|
| 1323 |
+
*
|
| 1324 |
+
* @param input - Data to hash
|
| 1325 |
+
* @returns this (for chaining)
|
| 1326 |
+
*/
|
| 1327 |
+
update(input) {
|
| 1328 |
+
let inputOffset = 0;
|
| 1329 |
+
let inputLen = input.length;
|
| 1330 |
+
while (inputLen > 0) {
|
| 1331 |
+
if (this.chunkState.len() === CHUNK_LEN) {
|
| 1332 |
+
const output = this.chunkState.output();
|
| 1333 |
+
const chunkCv = this.chunkCv;
|
| 1334 |
+
compress(output.inputCv, 0, output.blockWords, 0, chunkCv, 0, false, output.counter, output.blockLen, output.flags);
|
| 1335 |
+
const totalChunks = this.chunkState.chunkCounter + 1;
|
| 1336 |
+
this.addChunkCv(chunkCv, 0, totalChunks);
|
| 1337 |
+
this.chunkState.resetTo(this.keyWords, totalChunks, this.flags);
|
| 1338 |
+
}
|
| 1339 |
+
const want = CHUNK_LEN - this.chunkState.len();
|
| 1340 |
+
const take = Math.min(want, inputLen);
|
| 1341 |
+
this.chunkState.update(input, inputOffset, take);
|
| 1342 |
+
inputOffset += take;
|
| 1343 |
+
inputLen -= take;
|
| 1344 |
+
}
|
| 1345 |
+
return this;
|
| 1346 |
+
}
|
| 1347 |
+
/**
|
| 1348 |
+
* Get the output parameters (for XOF mode or finalization).
|
| 1349 |
+
*/
|
| 1350 |
+
finalizeOutput() {
|
| 1351 |
+
let output = this.chunkState.output();
|
| 1352 |
+
let parentBlock = this.parentBlock;
|
| 1353 |
+
let cv = this.finalizeCv;
|
| 1354 |
+
if (this.cvStackLen > 0) {
|
| 1355 |
+
compress(output.inputCv, 0, output.blockWords, 0, cv, 0, false, output.counter, output.blockLen, output.flags);
|
| 1356 |
+
while (this.cvStackLen > 0) {
|
| 1357 |
+
this.cvStackLen--;
|
| 1358 |
+
parentBlock.set(this.cvStack.subarray(this.cvStackLen * 8, (this.cvStackLen + 1) * 8), 0);
|
| 1359 |
+
parentBlock.set(cv, 8);
|
| 1360 |
+
if (this.cvStackLen > 0) {
|
| 1361 |
+
compress(this.keyWords, 0, parentBlock, 0, cv, 0, false, 0, BLOCK_LEN, this.flags | PARENT);
|
| 1362 |
+
} else {
|
| 1363 |
+
return {
|
| 1364 |
+
inputCv: this.keyWords,
|
| 1365 |
+
blockWords: parentBlock,
|
| 1366 |
+
blockLen: BLOCK_LEN,
|
| 1367 |
+
counter: 0,
|
| 1368 |
+
flags: this.flags | PARENT
|
| 1369 |
+
};
|
| 1370 |
+
}
|
| 1371 |
+
}
|
| 1372 |
+
}
|
| 1373 |
+
return output;
|
| 1374 |
+
}
|
| 1375 |
+
/**
|
| 1376 |
+
* Finalize the hash and return the result.
|
| 1377 |
+
*
|
| 1378 |
+
* @param outputLength - Number of bytes to output (default: 32)
|
| 1379 |
+
* @returns The hash output
|
| 1380 |
+
*/
|
| 1381 |
+
finalize(outputLength = OUT_LEN) {
|
| 1382 |
+
const output = this.finalizeOutput();
|
| 1383 |
+
const result = new Uint8Array(outputLength);
|
| 1384 |
+
if (outputLength <= 64) {
|
| 1385 |
+
const outWords = this.outWords;
|
| 1386 |
+
compress(
|
| 1387 |
+
output.inputCv,
|
| 1388 |
+
0,
|
| 1389 |
+
output.blockWords,
|
| 1390 |
+
0,
|
| 1391 |
+
outWords,
|
| 1392 |
+
0,
|
| 1393 |
+
outputLength > 32,
|
| 1394 |
+
// full output if > 32 bytes
|
| 1395 |
+
output.counter,
|
| 1396 |
+
output.blockLen,
|
| 1397 |
+
output.flags | ROOT
|
| 1398 |
+
);
|
| 1399 |
+
if (IS_LITTLE_ENDIAN) {
|
| 1400 |
+
const outBytes = new Uint8Array(outWords.buffer);
|
| 1401 |
+
result.set(outBytes.subarray(0, outputLength));
|
| 1402 |
+
} else {
|
| 1403 |
+
writeLittleEndianBytesPartial(outWords, 0, result, 0, outputLength);
|
| 1404 |
+
}
|
| 1405 |
+
} else {
|
| 1406 |
+
const xof = this.finalizeXof();
|
| 1407 |
+
const full = xof.read(outputLength);
|
| 1408 |
+
result.set(full);
|
| 1409 |
+
}
|
| 1410 |
+
return result;
|
| 1411 |
+
}
|
| 1412 |
+
/**
|
| 1413 |
+
* Finalize and return an XOF reader for arbitrary-length output.
|
| 1414 |
+
*/
|
| 1415 |
+
finalizeXof() {
|
| 1416 |
+
const output = this.finalizeOutput();
|
| 1417 |
+
return new XofReader(new Uint32Array(output.inputCv), new Uint32Array(output.blockWords), output.counter, output.blockLen, output.flags);
|
| 1418 |
+
}
|
| 1419 |
+
};
|
| 1420 |
+
|
| 1421 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/wasm-simd.js
|
| 1422 |
+
function toLebU32Min2(n) {
|
| 1423 |
+
return [n & 127 | 128, n >>> 7 & 127];
|
| 1424 |
+
}
|
| 1425 |
+
function toLebU32Padded5(n) {
|
| 1426 |
+
return [
|
| 1427 |
+
n & 127 | 128,
|
| 1428 |
+
n >>> 7 & 127 | 128,
|
| 1429 |
+
n >>> 14 & 127 | 128,
|
| 1430 |
+
n >>> 21 & 127 | 128,
|
| 1431 |
+
n >>> 28 & 15
|
| 1432 |
+
// Last byte has no continuation bit
|
| 1433 |
+
];
|
| 1434 |
+
}
|
| 1435 |
+
function toSignedLeb128_i32(n) {
|
| 1436 |
+
const bytes = [];
|
| 1437 |
+
let value = n | 0;
|
| 1438 |
+
let more = true;
|
| 1439 |
+
while (more) {
|
| 1440 |
+
let byte = value & 127;
|
| 1441 |
+
value >>= 7;
|
| 1442 |
+
if (value === 0 && (byte & 64) === 0 || value === -1 && (byte & 64) !== 0) {
|
| 1443 |
+
more = false;
|
| 1444 |
+
} else {
|
| 1445 |
+
byte |= 128;
|
| 1446 |
+
}
|
| 1447 |
+
bytes.push(byte);
|
| 1448 |
+
}
|
| 1449 |
+
return bytes;
|
| 1450 |
+
}
|
| 1451 |
+
var MSG_ACCESS_ORDER = [
|
| 1452 |
+
// Round 1: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
|
| 1453 |
+
0,
|
| 1454 |
+
1,
|
| 1455 |
+
2,
|
| 1456 |
+
3,
|
| 1457 |
+
4,
|
| 1458 |
+
5,
|
| 1459 |
+
6,
|
| 1460 |
+
7,
|
| 1461 |
+
8,
|
| 1462 |
+
9,
|
| 1463 |
+
10,
|
| 1464 |
+
11,
|
| 1465 |
+
12,
|
| 1466 |
+
13,
|
| 1467 |
+
14,
|
| 1468 |
+
15,
|
| 1469 |
+
// Round 2: 2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8
|
| 1470 |
+
2,
|
| 1471 |
+
6,
|
| 1472 |
+
3,
|
| 1473 |
+
10,
|
| 1474 |
+
7,
|
| 1475 |
+
0,
|
| 1476 |
+
4,
|
| 1477 |
+
13,
|
| 1478 |
+
1,
|
| 1479 |
+
11,
|
| 1480 |
+
12,
|
| 1481 |
+
5,
|
| 1482 |
+
9,
|
| 1483 |
+
14,
|
| 1484 |
+
15,
|
| 1485 |
+
8,
|
| 1486 |
+
// Round 3: 3,4,10,12,13,2,7,14,6,5,9,0,11,15,8,1
|
| 1487 |
+
3,
|
| 1488 |
+
4,
|
| 1489 |
+
10,
|
| 1490 |
+
12,
|
| 1491 |
+
13,
|
| 1492 |
+
2,
|
| 1493 |
+
7,
|
| 1494 |
+
14,
|
| 1495 |
+
6,
|
| 1496 |
+
5,
|
| 1497 |
+
9,
|
| 1498 |
+
0,
|
| 1499 |
+
11,
|
| 1500 |
+
15,
|
| 1501 |
+
8,
|
| 1502 |
+
1,
|
| 1503 |
+
// Round 4: 10,7,12,9,14,3,13,15,4,0,11,2,5,8,1,6
|
| 1504 |
+
10,
|
| 1505 |
+
7,
|
| 1506 |
+
12,
|
| 1507 |
+
9,
|
| 1508 |
+
14,
|
| 1509 |
+
3,
|
| 1510 |
+
13,
|
| 1511 |
+
15,
|
| 1512 |
+
4,
|
| 1513 |
+
0,
|
| 1514 |
+
11,
|
| 1515 |
+
2,
|
| 1516 |
+
5,
|
| 1517 |
+
8,
|
| 1518 |
+
1,
|
| 1519 |
+
6,
|
| 1520 |
+
// Round 5: 12,13,9,11,15,10,14,8,7,2,5,3,0,1,6,4
|
| 1521 |
+
12,
|
| 1522 |
+
13,
|
| 1523 |
+
9,
|
| 1524 |
+
11,
|
| 1525 |
+
15,
|
| 1526 |
+
10,
|
| 1527 |
+
14,
|
| 1528 |
+
8,
|
| 1529 |
+
7,
|
| 1530 |
+
2,
|
| 1531 |
+
5,
|
| 1532 |
+
3,
|
| 1533 |
+
0,
|
| 1534 |
+
1,
|
| 1535 |
+
6,
|
| 1536 |
+
4,
|
| 1537 |
+
// Round 6: 9,14,11,5,8,12,15,1,13,3,0,10,2,6,4,7
|
| 1538 |
+
9,
|
| 1539 |
+
14,
|
| 1540 |
+
11,
|
| 1541 |
+
5,
|
| 1542 |
+
8,
|
| 1543 |
+
12,
|
| 1544 |
+
15,
|
| 1545 |
+
1,
|
| 1546 |
+
13,
|
| 1547 |
+
3,
|
| 1548 |
+
0,
|
| 1549 |
+
10,
|
| 1550 |
+
2,
|
| 1551 |
+
6,
|
| 1552 |
+
4,
|
| 1553 |
+
7,
|
| 1554 |
+
// Round 7: 11,15,5,0,1,9,8,6,14,10,2,12,3,4,7,13
|
| 1555 |
+
11,
|
| 1556 |
+
15,
|
| 1557 |
+
5,
|
| 1558 |
+
0,
|
| 1559 |
+
1,
|
| 1560 |
+
9,
|
| 1561 |
+
8,
|
| 1562 |
+
6,
|
| 1563 |
+
14,
|
| 1564 |
+
10,
|
| 1565 |
+
2,
|
| 1566 |
+
12,
|
| 1567 |
+
3,
|
| 1568 |
+
4,
|
| 1569 |
+
7,
|
| 1570 |
+
13
|
| 1571 |
+
];
|
| 1572 |
+
function generateWasmBytes() {
|
| 1573 |
+
const code = [];
|
| 1574 |
+
function put(bytes) {
|
| 1575 |
+
code.push(...bytes);
|
| 1576 |
+
}
|
| 1577 |
+
put([0, 97, 115, 109]);
|
| 1578 |
+
put([1, 0, 0, 0]);
|
| 1579 |
+
put([1]);
|
| 1580 |
+
put([4]);
|
| 1581 |
+
put([1]);
|
| 1582 |
+
put([96, 0, 0]);
|
| 1583 |
+
put([2]);
|
| 1584 |
+
put([11]);
|
| 1585 |
+
put([1]);
|
| 1586 |
+
put([2, 106, 115]);
|
| 1587 |
+
put([3, 109, 101, 109]);
|
| 1588 |
+
put([2, 0, 1]);
|
| 1589 |
+
put([3]);
|
| 1590 |
+
put([4]);
|
| 1591 |
+
put([3]);
|
| 1592 |
+
put([0]);
|
| 1593 |
+
put([0]);
|
| 1594 |
+
put([0]);
|
| 1595 |
+
put([7]);
|
| 1596 |
+
put([50]);
|
| 1597 |
+
put([3]);
|
| 1598 |
+
put([10]);
|
| 1599 |
+
put([99, 111, 109, 112, 114, 101, 115, 115, 52, 120]);
|
| 1600 |
+
put([0, 0]);
|
| 1601 |
+
put([16]);
|
| 1602 |
+
put([
|
| 1603 |
+
99,
|
| 1604 |
+
111,
|
| 1605 |
+
109,
|
| 1606 |
+
112,
|
| 1607 |
+
114,
|
| 1608 |
+
101,
|
| 1609 |
+
115,
|
| 1610 |
+
115,
|
| 1611 |
+
67,
|
| 1612 |
+
104,
|
| 1613 |
+
117,
|
| 1614 |
+
110,
|
| 1615 |
+
107,
|
| 1616 |
+
115,
|
| 1617 |
+
52,
|
| 1618 |
+
120
|
| 1619 |
+
]);
|
| 1620 |
+
put([0, 1]);
|
| 1621 |
+
put([14]);
|
| 1622 |
+
put([99, 111, 109, 112, 114, 101, 115, 115, 80, 97, 114, 101, 110, 116]);
|
| 1623 |
+
put([0, 2]);
|
| 1624 |
+
put([10]);
|
| 1625 |
+
const sectionSizeOffset = code.length;
|
| 1626 |
+
put([0, 0, 0, 0, 0]);
|
| 1627 |
+
put([3]);
|
| 1628 |
+
const funcSizeOffset = code.length;
|
| 1629 |
+
put([0, 0, 0, 0, 0]);
|
| 1630 |
+
const funcBodyStart = code.length;
|
| 1631 |
+
put([1]);
|
| 1632 |
+
put([32, 123]);
|
| 1633 |
+
for (let i = 0; i < 16; i++) {
|
| 1634 |
+
put([65, ...toLebU32Min2(i * 16)]);
|
| 1635 |
+
put([253, 0, 2, 0]);
|
| 1636 |
+
put([33, i]);
|
| 1637 |
+
}
|
| 1638 |
+
for (let i = 0; i < 8; i++) {
|
| 1639 |
+
put([65, ...toLebU32Min2(512 + i * 16)]);
|
| 1640 |
+
put([253, 0, 2, 0]);
|
| 1641 |
+
put([33, 16 + i]);
|
| 1642 |
+
}
|
| 1643 |
+
const IV2 = [1779033703, 3144134277, 1013904242, 2773480762];
|
| 1644 |
+
for (let i = 0; i < 4; i++) {
|
| 1645 |
+
const ivBytes = [];
|
| 1646 |
+
for (let j = 0; j < 4; j++) {
|
| 1647 |
+
ivBytes.push(IV2[i] & 255);
|
| 1648 |
+
ivBytes.push(IV2[i] >>> 8 & 255);
|
| 1649 |
+
ivBytes.push(IV2[i] >>> 16 & 255);
|
| 1650 |
+
ivBytes.push(IV2[i] >>> 24 & 255);
|
| 1651 |
+
}
|
| 1652 |
+
put([253, 12, ...ivBytes]);
|
| 1653 |
+
put([33, 24 + i]);
|
| 1654 |
+
}
|
| 1655 |
+
put([65, ...toLebU32Min2(768)]);
|
| 1656 |
+
put([253, 0, 2, 0]);
|
| 1657 |
+
put([33, 28]);
|
| 1658 |
+
put([65, ...toLebU32Min2(784)]);
|
| 1659 |
+
put([253, 0, 2, 0]);
|
| 1660 |
+
put([33, 29]);
|
| 1661 |
+
put([65, ...toLebU32Min2(800)]);
|
| 1662 |
+
put([253, 0, 2, 0]);
|
| 1663 |
+
put([33, 30]);
|
| 1664 |
+
put([65, ...toLebU32Min2(816)]);
|
| 1665 |
+
put([253, 0, 2, 0]);
|
| 1666 |
+
put([33, 31]);
|
| 1667 |
+
let msgIdx = 0;
|
| 1668 |
+
function g(a, b, c, d) {
|
| 1669 |
+
const mx = MSG_ACCESS_ORDER[msgIdx++];
|
| 1670 |
+
const my = MSG_ACCESS_ORDER[msgIdx++];
|
| 1671 |
+
put([32, 16 + a]);
|
| 1672 |
+
put([32, 16 + b]);
|
| 1673 |
+
put([253, 174, 1]);
|
| 1674 |
+
put([32, mx]);
|
| 1675 |
+
put([253, 174, 1]);
|
| 1676 |
+
put([33, 16 + a]);
|
| 1677 |
+
put([32, 16 + d]);
|
| 1678 |
+
put([32, 16 + a]);
|
| 1679 |
+
put([253, 81]);
|
| 1680 |
+
put([34, 16 + d]);
|
| 1681 |
+
put([32, 16 + d]);
|
| 1682 |
+
put([253, 13, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13]);
|
| 1683 |
+
put([33, 16 + d]);
|
| 1684 |
+
put([32, 16 + c]);
|
| 1685 |
+
put([32, 16 + d]);
|
| 1686 |
+
put([253, 174, 1]);
|
| 1687 |
+
put([33, 16 + c]);
|
| 1688 |
+
put([32, 16 + b]);
|
| 1689 |
+
put([32, 16 + c]);
|
| 1690 |
+
put([253, 81]);
|
| 1691 |
+
put([34, 16 + b]);
|
| 1692 |
+
put([65, 12]);
|
| 1693 |
+
put([253, 173, 1]);
|
| 1694 |
+
put([32, 16 + b]);
|
| 1695 |
+
put([65, 20]);
|
| 1696 |
+
put([253, 171, 1]);
|
| 1697 |
+
put([253, 80]);
|
| 1698 |
+
put([33, 16 + b]);
|
| 1699 |
+
put([32, 16 + a]);
|
| 1700 |
+
put([32, 16 + b]);
|
| 1701 |
+
put([253, 174, 1]);
|
| 1702 |
+
put([32, my]);
|
| 1703 |
+
put([253, 174, 1]);
|
| 1704 |
+
put([33, 16 + a]);
|
| 1705 |
+
put([32, 16 + d]);
|
| 1706 |
+
put([32, 16 + a]);
|
| 1707 |
+
put([253, 81]);
|
| 1708 |
+
put([34, 16 + d]);
|
| 1709 |
+
put([32, 16 + d]);
|
| 1710 |
+
put([253, 13, 1, 2, 3, 0, 5, 6, 7, 4, 9, 10, 11, 8, 13, 14, 15, 12]);
|
| 1711 |
+
put([33, 16 + d]);
|
| 1712 |
+
put([32, 16 + c]);
|
| 1713 |
+
put([32, 16 + d]);
|
| 1714 |
+
put([253, 174, 1]);
|
| 1715 |
+
put([33, 16 + c]);
|
| 1716 |
+
put([32, 16 + b]);
|
| 1717 |
+
put([32, 16 + c]);
|
| 1718 |
+
put([253, 81]);
|
| 1719 |
+
put([34, 16 + b]);
|
| 1720 |
+
put([65, 7]);
|
| 1721 |
+
put([253, 173, 1]);
|
| 1722 |
+
put([32, 16 + b]);
|
| 1723 |
+
put([65, 25]);
|
| 1724 |
+
put([253, 171, 1]);
|
| 1725 |
+
put([253, 80]);
|
| 1726 |
+
put([33, 16 + b]);
|
| 1727 |
+
}
|
| 1728 |
+
for (let round = 0; round < 7; round++) {
|
| 1729 |
+
g(0, 4, 8, 12);
|
| 1730 |
+
g(1, 5, 9, 13);
|
| 1731 |
+
g(2, 6, 10, 14);
|
| 1732 |
+
g(3, 7, 11, 15);
|
| 1733 |
+
g(0, 5, 10, 15);
|
| 1734 |
+
g(1, 6, 11, 12);
|
| 1735 |
+
g(2, 7, 8, 13);
|
| 1736 |
+
g(3, 4, 9, 14);
|
| 1737 |
+
}
|
| 1738 |
+
for (let i = 0; i < 8; i++) {
|
| 1739 |
+
put([65, ...toLebU32Min2(640 + i * 16)]);
|
| 1740 |
+
put([32, 16 + i]);
|
| 1741 |
+
put([32, 24 + i]);
|
| 1742 |
+
put([253, 81]);
|
| 1743 |
+
put([253, 11, 2, 0]);
|
| 1744 |
+
}
|
| 1745 |
+
put([11]);
|
| 1746 |
+
const funcBodySize = code.length - funcBodyStart;
|
| 1747 |
+
const funcSizeBytes = toLebU32Padded5(funcBodySize);
|
| 1748 |
+
for (let i = 0; i < 5; i++) {
|
| 1749 |
+
code[funcSizeOffset + i] = funcSizeBytes[i];
|
| 1750 |
+
}
|
| 1751 |
+
const func1SizeOffset = code.length;
|
| 1752 |
+
put([0, 0, 0, 0, 0]);
|
| 1753 |
+
const func1BodyStart = code.length;
|
| 1754 |
+
const compressChunksBody = generateCompressChunks4xBody();
|
| 1755 |
+
put(compressChunksBody);
|
| 1756 |
+
const func1BodySize = code.length - func1BodyStart;
|
| 1757 |
+
const func1SizeBytes = toLebU32Padded5(func1BodySize);
|
| 1758 |
+
for (let i = 0; i < 5; i++) {
|
| 1759 |
+
code[func1SizeOffset + i] = func1SizeBytes[i];
|
| 1760 |
+
}
|
| 1761 |
+
const func2SizeOffset = code.length;
|
| 1762 |
+
put([0, 0, 0, 0, 0]);
|
| 1763 |
+
const func2BodyStart = code.length;
|
| 1764 |
+
const compressParentBody = generateCompressParentBody();
|
| 1765 |
+
put(compressParentBody);
|
| 1766 |
+
const func2BodySize = code.length - func2BodyStart;
|
| 1767 |
+
const func2SizeBytes = toLebU32Padded5(func2BodySize);
|
| 1768 |
+
for (let i = 0; i < 5; i++) {
|
| 1769 |
+
code[func2SizeOffset + i] = func2SizeBytes[i];
|
| 1770 |
+
}
|
| 1771 |
+
const sectionSize = code.length - sectionSizeOffset - 5;
|
| 1772 |
+
const sectionSizeBytes = toLebU32Padded5(sectionSize);
|
| 1773 |
+
for (let i = 0; i < 5; i++) {
|
| 1774 |
+
code[sectionSizeOffset + i] = sectionSizeBytes[i];
|
| 1775 |
+
}
|
| 1776 |
+
return new Uint8Array(code);
|
| 1777 |
+
}
|
| 1778 |
+
function generateCompressChunks4xBody() {
|
| 1779 |
+
const code = [];
|
| 1780 |
+
function put(bytes) {
|
| 1781 |
+
code.push(...bytes);
|
| 1782 |
+
}
|
| 1783 |
+
put([2]);
|
| 1784 |
+
put([32, 123]);
|
| 1785 |
+
put([1, 127]);
|
| 1786 |
+
const BATCH_BLOCK_WORDS = SIMD_MEMORY.BATCH_BLOCK_WORDS;
|
| 1787 |
+
const BATCH_CV = SIMD_MEMORY.BATCH_CV;
|
| 1788 |
+
const BATCH_COUNTER_LOW = SIMD_MEMORY.BATCH_COUNTER_LOW;
|
| 1789 |
+
const BATCH_FLAGS_BASE = SIMD_MEMORY.BATCH_FLAGS_BASE;
|
| 1790 |
+
const BATCH_OUTPUT = SIMD_MEMORY.BATCH_OUTPUT;
|
| 1791 |
+
const IV2 = [1779033703, 3144134277, 1013904242, 2773480762];
|
| 1792 |
+
for (let i = 0; i < 8; i++) {
|
| 1793 |
+
put([65, ...toLebU32Min2(BATCH_CV + i * 16)]);
|
| 1794 |
+
put([253, 0, 2, 0]);
|
| 1795 |
+
put([33, 16 + i]);
|
| 1796 |
+
}
|
| 1797 |
+
put([65, 0]);
|
| 1798 |
+
put([33, 32]);
|
| 1799 |
+
put([2, 64]);
|
| 1800 |
+
put([3, 64]);
|
| 1801 |
+
for (let w = 0; w < 16; w++) {
|
| 1802 |
+
put([32, 32]);
|
| 1803 |
+
put([65, ...toLebU32Min2(256)]);
|
| 1804 |
+
put([108]);
|
| 1805 |
+
put([65, ...toLebU32Min2(BATCH_BLOCK_WORDS + w * 16)]);
|
| 1806 |
+
put([106]);
|
| 1807 |
+
put([253, 0, 2, 0]);
|
| 1808 |
+
put([33, w]);
|
| 1809 |
+
}
|
| 1810 |
+
for (let i = 0; i < 4; i++) {
|
| 1811 |
+
const ivBytes = [];
|
| 1812 |
+
for (let j = 0; j < 4; j++) {
|
| 1813 |
+
ivBytes.push(IV2[i] & 255);
|
| 1814 |
+
ivBytes.push(IV2[i] >>> 8 & 255);
|
| 1815 |
+
ivBytes.push(IV2[i] >>> 16 & 255);
|
| 1816 |
+
ivBytes.push(IV2[i] >>> 24 & 255);
|
| 1817 |
+
}
|
| 1818 |
+
put([253, 12, ...ivBytes]);
|
| 1819 |
+
put([33, 24 + i]);
|
| 1820 |
+
}
|
| 1821 |
+
put([65, ...toLebU32Min2(BATCH_COUNTER_LOW)]);
|
| 1822 |
+
put([253, 0, 2, 0]);
|
| 1823 |
+
put([33, 28]);
|
| 1824 |
+
put([253, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
| 1825 |
+
put([33, 29]);
|
| 1826 |
+
const blockLen64 = [];
|
| 1827 |
+
for (let j = 0; j < 4; j++) {
|
| 1828 |
+
blockLen64.push(64, 0, 0, 0);
|
| 1829 |
+
}
|
| 1830 |
+
put([253, 12, ...blockLen64]);
|
| 1831 |
+
put([33, 30]);
|
| 1832 |
+
put([65, ...toLebU32Min2(BATCH_FLAGS_BASE)]);
|
| 1833 |
+
put([253, 0, 2, 0]);
|
| 1834 |
+
put([32, 32]);
|
| 1835 |
+
put([69]);
|
| 1836 |
+
put([32, 32]);
|
| 1837 |
+
put([65, 15]);
|
| 1838 |
+
put([70]);
|
| 1839 |
+
put([65, 1]);
|
| 1840 |
+
put([116]);
|
| 1841 |
+
put([114]);
|
| 1842 |
+
put([253, 17]);
|
| 1843 |
+
put([253, 80]);
|
| 1844 |
+
put([33, 31]);
|
| 1845 |
+
let msgIdx = 0;
|
| 1846 |
+
function g(a, b, c, d) {
|
| 1847 |
+
const mx = MSG_ACCESS_ORDER[msgIdx++];
|
| 1848 |
+
const my = MSG_ACCESS_ORDER[msgIdx++];
|
| 1849 |
+
put([32, 16 + a]);
|
| 1850 |
+
put([32, 16 + b]);
|
| 1851 |
+
put([253, 174, 1]);
|
| 1852 |
+
put([32, mx]);
|
| 1853 |
+
put([253, 174, 1]);
|
| 1854 |
+
put([33, 16 + a]);
|
| 1855 |
+
put([32, 16 + d]);
|
| 1856 |
+
put([32, 16 + a]);
|
| 1857 |
+
put([253, 81]);
|
| 1858 |
+
put([34, 16 + d]);
|
| 1859 |
+
put([32, 16 + d]);
|
| 1860 |
+
put([253, 13, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13]);
|
| 1861 |
+
put([33, 16 + d]);
|
| 1862 |
+
put([32, 16 + c]);
|
| 1863 |
+
put([32, 16 + d]);
|
| 1864 |
+
put([253, 174, 1]);
|
| 1865 |
+
put([33, 16 + c]);
|
| 1866 |
+
put([32, 16 + b]);
|
| 1867 |
+
put([32, 16 + c]);
|
| 1868 |
+
put([253, 81]);
|
| 1869 |
+
put([34, 16 + b]);
|
| 1870 |
+
put([65, 12]);
|
| 1871 |
+
put([253, 173, 1]);
|
| 1872 |
+
put([32, 16 + b]);
|
| 1873 |
+
put([65, 20]);
|
| 1874 |
+
put([253, 171, 1]);
|
| 1875 |
+
put([253, 80]);
|
| 1876 |
+
put([33, 16 + b]);
|
| 1877 |
+
put([32, 16 + a]);
|
| 1878 |
+
put([32, 16 + b]);
|
| 1879 |
+
put([253, 174, 1]);
|
| 1880 |
+
put([32, my]);
|
| 1881 |
+
put([253, 174, 1]);
|
| 1882 |
+
put([33, 16 + a]);
|
| 1883 |
+
put([32, 16 + d]);
|
| 1884 |
+
put([32, 16 + a]);
|
| 1885 |
+
put([253, 81]);
|
| 1886 |
+
put([34, 16 + d]);
|
| 1887 |
+
put([32, 16 + d]);
|
| 1888 |
+
put([253, 13, 1, 2, 3, 0, 5, 6, 7, 4, 9, 10, 11, 8, 13, 14, 15, 12]);
|
| 1889 |
+
put([33, 16 + d]);
|
| 1890 |
+
put([32, 16 + c]);
|
| 1891 |
+
put([32, 16 + d]);
|
| 1892 |
+
put([253, 174, 1]);
|
| 1893 |
+
put([33, 16 + c]);
|
| 1894 |
+
put([32, 16 + b]);
|
| 1895 |
+
put([32, 16 + c]);
|
| 1896 |
+
put([253, 81]);
|
| 1897 |
+
put([34, 16 + b]);
|
| 1898 |
+
put([65, 7]);
|
| 1899 |
+
put([253, 173, 1]);
|
| 1900 |
+
put([32, 16 + b]);
|
| 1901 |
+
put([65, 25]);
|
| 1902 |
+
put([253, 171, 1]);
|
| 1903 |
+
put([253, 80]);
|
| 1904 |
+
put([33, 16 + b]);
|
| 1905 |
+
}
|
| 1906 |
+
for (let round = 0; round < 7; round++) {
|
| 1907 |
+
g(0, 4, 8, 12);
|
| 1908 |
+
g(1, 5, 9, 13);
|
| 1909 |
+
g(2, 6, 10, 14);
|
| 1910 |
+
g(3, 7, 11, 15);
|
| 1911 |
+
g(0, 5, 10, 15);
|
| 1912 |
+
g(1, 6, 11, 12);
|
| 1913 |
+
g(2, 7, 8, 13);
|
| 1914 |
+
g(3, 4, 9, 14);
|
| 1915 |
+
}
|
| 1916 |
+
for (let i = 0; i < 8; i++) {
|
| 1917 |
+
put([32, 16 + i]);
|
| 1918 |
+
put([32, 24 + i]);
|
| 1919 |
+
put([253, 81]);
|
| 1920 |
+
put([33, 16 + i]);
|
| 1921 |
+
}
|
| 1922 |
+
put([32, 32]);
|
| 1923 |
+
put([65, 1]);
|
| 1924 |
+
put([106]);
|
| 1925 |
+
put([34, 32]);
|
| 1926 |
+
put([65, 16]);
|
| 1927 |
+
put([73]);
|
| 1928 |
+
put([13, 0]);
|
| 1929 |
+
put([11]);
|
| 1930 |
+
put([11]);
|
| 1931 |
+
for (let i = 0; i < 8; i++) {
|
| 1932 |
+
put([65, ...toLebU32Min2(BATCH_OUTPUT + i * 16)]);
|
| 1933 |
+
put([32, 16 + i]);
|
| 1934 |
+
put([253, 11, 2, 0]);
|
| 1935 |
+
}
|
| 1936 |
+
put([11]);
|
| 1937 |
+
return code;
|
| 1938 |
+
}
|
| 1939 |
+
function generateCompressParentBody() {
|
| 1940 |
+
const code = [];
|
| 1941 |
+
function put(bytes) {
|
| 1942 |
+
code.push(...bytes);
|
| 1943 |
+
}
|
| 1944 |
+
put([1]);
|
| 1945 |
+
put([32, 127]);
|
| 1946 |
+
const PARENT_BLOCK_OFFSET = SIMD_MEMORY.PARENT_BLOCK;
|
| 1947 |
+
const CHUNK_CV_OFFSET = SIMD_MEMORY.CHUNK_CV;
|
| 1948 |
+
const IV2 = [
|
| 1949 |
+
1779033703,
|
| 1950 |
+
3144134277,
|
| 1951 |
+
1013904242,
|
| 1952 |
+
2773480762,
|
| 1953 |
+
1359893119,
|
| 1954 |
+
2600822924,
|
| 1955 |
+
528734635,
|
| 1956 |
+
1541459225
|
| 1957 |
+
];
|
| 1958 |
+
for (let i = 0; i < 16; i++) {
|
| 1959 |
+
put([65, ...toLebU32Min2(PARENT_BLOCK_OFFSET + i * 4)]);
|
| 1960 |
+
put([40, 2, 0]);
|
| 1961 |
+
put([33, i]);
|
| 1962 |
+
}
|
| 1963 |
+
for (let i = 0; i < 8; i++) {
|
| 1964 |
+
put([65, ...toSignedLeb128_i32(IV2[i])]);
|
| 1965 |
+
put([33, 16 + i]);
|
| 1966 |
+
}
|
| 1967 |
+
for (let i = 0; i < 4; i++) {
|
| 1968 |
+
put([65, ...toSignedLeb128_i32(IV2[i])]);
|
| 1969 |
+
put([33, 24 + i]);
|
| 1970 |
+
}
|
| 1971 |
+
put([65, 0]);
|
| 1972 |
+
put([33, 28]);
|
| 1973 |
+
put([65, 0]);
|
| 1974 |
+
put([33, 29]);
|
| 1975 |
+
put([65, 192, 0]);
|
| 1976 |
+
put([33, 30]);
|
| 1977 |
+
put([65, 4]);
|
| 1978 |
+
put([33, 31]);
|
| 1979 |
+
function g(a, b, c, d, mx, my) {
|
| 1980 |
+
const sa = 16 + a, sb = 16 + b, sc = 16 + c, sd = 16 + d;
|
| 1981 |
+
put([32, sa]);
|
| 1982 |
+
put([32, sb]);
|
| 1983 |
+
put([106]);
|
| 1984 |
+
put([32, mx]);
|
| 1985 |
+
put([106]);
|
| 1986 |
+
put([33, sa]);
|
| 1987 |
+
put([32, sd]);
|
| 1988 |
+
put([32, sa]);
|
| 1989 |
+
put([115]);
|
| 1990 |
+
put([65, 16]);
|
| 1991 |
+
put([120]);
|
| 1992 |
+
put([33, sd]);
|
| 1993 |
+
put([32, sc]);
|
| 1994 |
+
put([32, sd]);
|
| 1995 |
+
put([106]);
|
| 1996 |
+
put([33, sc]);
|
| 1997 |
+
put([32, sb]);
|
| 1998 |
+
put([32, sc]);
|
| 1999 |
+
put([115]);
|
| 2000 |
+
put([65, 12]);
|
| 2001 |
+
put([120]);
|
| 2002 |
+
put([33, sb]);
|
| 2003 |
+
put([32, sa]);
|
| 2004 |
+
put([32, sb]);
|
| 2005 |
+
put([106]);
|
| 2006 |
+
put([32, my]);
|
| 2007 |
+
put([106]);
|
| 2008 |
+
put([33, sa]);
|
| 2009 |
+
put([32, sd]);
|
| 2010 |
+
put([32, sa]);
|
| 2011 |
+
put([115]);
|
| 2012 |
+
put([65, 8]);
|
| 2013 |
+
put([120]);
|
| 2014 |
+
put([33, sd]);
|
| 2015 |
+
put([32, sc]);
|
| 2016 |
+
put([32, sd]);
|
| 2017 |
+
put([106]);
|
| 2018 |
+
put([33, sc]);
|
| 2019 |
+
put([32, sb]);
|
| 2020 |
+
put([32, sc]);
|
| 2021 |
+
put([115]);
|
| 2022 |
+
put([65, 7]);
|
| 2023 |
+
put([120]);
|
| 2024 |
+
put([33, sb]);
|
| 2025 |
+
}
|
| 2026 |
+
let msgIdx = 0;
|
| 2027 |
+
for (let round = 0; round < 7; round++) {
|
| 2028 |
+
g(0, 4, 8, 12, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2029 |
+
msgIdx += 2;
|
| 2030 |
+
g(1, 5, 9, 13, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2031 |
+
msgIdx += 2;
|
| 2032 |
+
g(2, 6, 10, 14, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2033 |
+
msgIdx += 2;
|
| 2034 |
+
g(3, 7, 11, 15, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2035 |
+
msgIdx += 2;
|
| 2036 |
+
g(0, 5, 10, 15, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2037 |
+
msgIdx += 2;
|
| 2038 |
+
g(1, 6, 11, 12, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2039 |
+
msgIdx += 2;
|
| 2040 |
+
g(2, 7, 8, 13, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2041 |
+
msgIdx += 2;
|
| 2042 |
+
g(3, 4, 9, 14, MSG_ACCESS_ORDER[msgIdx], MSG_ACCESS_ORDER[msgIdx + 1]);
|
| 2043 |
+
msgIdx += 2;
|
| 2044 |
+
}
|
| 2045 |
+
for (let i = 0; i < 8; i++) {
|
| 2046 |
+
put([65, ...toLebU32Min2(CHUNK_CV_OFFSET + i * 4)]);
|
| 2047 |
+
put([32, 16 + i]);
|
| 2048 |
+
put([32, 24 + i]);
|
| 2049 |
+
put([115]);
|
| 2050 |
+
put([54, 2, 0]);
|
| 2051 |
+
}
|
| 2052 |
+
put([11]);
|
| 2053 |
+
return code;
|
| 2054 |
+
}
|
| 2055 |
+
var wasmInstance = null;
|
| 2056 |
+
var wasmMemory = null;
|
| 2057 |
+
var wasmCompress4x = null;
|
| 2058 |
+
var wasmCompressChunks4x = null;
|
| 2059 |
+
var wasmCompressParent = null;
|
| 2060 |
+
var wasmMemoryView = null;
|
| 2061 |
+
var wasmMemoryView32 = null;
|
| 2062 |
+
function isSimdSupported() {
|
| 2063 |
+
try {
|
| 2064 |
+
const simdTest = new Uint8Array([
|
| 2065 |
+
0,
|
| 2066 |
+
97,
|
| 2067 |
+
115,
|
| 2068 |
+
109,
|
| 2069 |
+
// magic: \0asm
|
| 2070 |
+
1,
|
| 2071 |
+
0,
|
| 2072 |
+
0,
|
| 2073 |
+
0,
|
| 2074 |
+
// version: 1
|
| 2075 |
+
// Type section (id=1): () -> v128
|
| 2076 |
+
1,
|
| 2077 |
+
// section id = 1 (type)
|
| 2078 |
+
5,
|
| 2079 |
+
// section length = 5
|
| 2080 |
+
1,
|
| 2081 |
+
// 1 type
|
| 2082 |
+
96,
|
| 2083 |
+
0,
|
| 2084 |
+
1,
|
| 2085 |
+
123,
|
| 2086 |
+
// func () -> v128
|
| 2087 |
+
// Function section (id=3)
|
| 2088 |
+
3,
|
| 2089 |
+
// section id = 3 (function)
|
| 2090 |
+
2,
|
| 2091 |
+
// section length = 2
|
| 2092 |
+
1,
|
| 2093 |
+
// 1 function
|
| 2094 |
+
0,
|
| 2095 |
+
// type index 0
|
| 2096 |
+
// Code section (id=10) with v128.const
|
| 2097 |
+
10,
|
| 2098 |
+
// section id = 10 (code)
|
| 2099 |
+
22,
|
| 2100 |
+
// section length = 22
|
| 2101 |
+
1,
|
| 2102 |
+
// 1 function body
|
| 2103 |
+
20,
|
| 2104 |
+
// body length = 20
|
| 2105 |
+
0,
|
| 2106 |
+
// 0 locals
|
| 2107 |
+
253,
|
| 2108 |
+
12,
|
| 2109 |
+
// v128.const opcode
|
| 2110 |
+
0,
|
| 2111 |
+
0,
|
| 2112 |
+
0,
|
| 2113 |
+
0,
|
| 2114 |
+
0,
|
| 2115 |
+
0,
|
| 2116 |
+
0,
|
| 2117 |
+
0,
|
| 2118 |
+
0,
|
| 2119 |
+
0,
|
| 2120 |
+
0,
|
| 2121 |
+
0,
|
| 2122 |
+
0,
|
| 2123 |
+
0,
|
| 2124 |
+
0,
|
| 2125 |
+
0,
|
| 2126 |
+
11
|
| 2127 |
+
// end
|
| 2128 |
+
]);
|
| 2129 |
+
return WebAssembly.validate(simdTest);
|
| 2130 |
+
} catch {
|
| 2131 |
+
return false;
|
| 2132 |
+
}
|
| 2133 |
+
}
|
| 2134 |
+
function setupArenaViews() {
|
| 2135 |
+
if (!wasmMemory)
|
| 2136 |
+
return;
|
| 2137 |
+
const buffer = wasmMemory.buffer;
|
| 2138 |
+
arenaCvStack = new Uint32Array(buffer, SIMD_MEMORY.CV_STACK, 64 * 8);
|
| 2139 |
+
arenaParentBlock = new Uint32Array(buffer, SIMD_MEMORY.PARENT_BLOCK, 16);
|
| 2140 |
+
arenaChunkCv = new Uint32Array(buffer, SIMD_MEMORY.CHUNK_CV, 8);
|
| 2141 |
+
arenaTempCvs = new Uint32Array(buffer, SIMD_MEMORY.TEMP_CVS, 32);
|
| 2142 |
+
arenaBatchBlockWords = new Uint32Array(buffer, SIMD_MEMORY.BATCH_BLOCK_WORDS, 16 * 16 * 4);
|
| 2143 |
+
arenaBatchCv = new Uint32Array(buffer, SIMD_MEMORY.BATCH_CV, 32);
|
| 2144 |
+
arenaBatchCounterLow = new Uint32Array(buffer, SIMD_MEMORY.BATCH_COUNTER_LOW, 4);
|
| 2145 |
+
arenaBatchFlagsBase = new Uint32Array(buffer, SIMD_MEMORY.BATCH_FLAGS_BASE, 4);
|
| 2146 |
+
arenaBatchOutput = new Uint32Array(buffer, SIMD_MEMORY.BATCH_OUTPUT, 32);
|
| 2147 |
+
}
|
| 2148 |
+
var cachedWasmBytes = null;
|
| 2149 |
+
function initSimdSync() {
|
| 2150 |
+
if (wasmInstance)
|
| 2151 |
+
return true;
|
| 2152 |
+
if (!isSimdSupported()) {
|
| 2153 |
+
return false;
|
| 2154 |
+
}
|
| 2155 |
+
try {
|
| 2156 |
+
const wasmBytes = cachedWasmBytes || generateWasmBytes();
|
| 2157 |
+
cachedWasmBytes = wasmBytes;
|
| 2158 |
+
wasmMemory = new WebAssembly.Memory({ initial: 1 });
|
| 2159 |
+
const importObject = {
|
| 2160 |
+
js: { mem: wasmMemory }
|
| 2161 |
+
};
|
| 2162 |
+
const module = new WebAssembly.Module(wasmBytes.buffer);
|
| 2163 |
+
wasmInstance = new WebAssembly.Instance(module, importObject);
|
| 2164 |
+
wasmCompress4x = wasmInstance.exports.compress4x;
|
| 2165 |
+
wasmCompressChunks4x = wasmInstance.exports.compressChunks4x;
|
| 2166 |
+
wasmCompressParent = wasmInstance.exports.compressParent;
|
| 2167 |
+
wasmMemoryView = new Uint8Array(wasmMemory.buffer);
|
| 2168 |
+
wasmMemoryView32 = new Uint32Array(wasmMemory.buffer);
|
| 2169 |
+
setupArenaViews();
|
| 2170 |
+
return true;
|
| 2171 |
+
} catch (e) {
|
| 2172 |
+
console.warn("Failed to initialize WASM SIMD:", e);
|
| 2173 |
+
return false;
|
| 2174 |
+
}
|
| 2175 |
+
}
|
| 2176 |
+
var SIMD_MEMORY = {
|
| 2177 |
+
// SIMD compress4x working area (used by WASM code) - single block
|
| 2178 |
+
BLOCK_WORDS: 0,
|
| 2179 |
+
// 4 x 16 words = 512 bytes (transposed layout)
|
| 2180 |
+
CHAINING_VALUES: 512,
|
| 2181 |
+
// 4 x 8 words = 128 bytes
|
| 2182 |
+
OUTPUT: 640,
|
| 2183 |
+
// 4 x 8 words = 128 bytes
|
| 2184 |
+
COUNTER_LOW: 768,
|
| 2185 |
+
// 4 words = 16 bytes
|
| 2186 |
+
COUNTER_HIGH: 784,
|
| 2187 |
+
// 4 words = 16 bytes
|
| 2188 |
+
BLOCK_LEN: 800,
|
| 2189 |
+
// 4 words = 16 bytes
|
| 2190 |
+
FLAGS: 816,
|
| 2191 |
+
// 4 words = 16 bytes
|
| 2192 |
+
// End of single-block SIMD working area: 832 bytes
|
| 2193 |
+
// SIMD compressChunks4x working area - 16 blocks batched
|
| 2194 |
+
// Each block position has 16 v128 values (one per message word) = 256 bytes
|
| 2195 |
+
// 16 block positions = 16 × 256 = 4096 bytes
|
| 2196 |
+
BATCH_BLOCK_WORDS: 832,
|
| 2197 |
+
// 16 positions × 256 bytes = 4096 bytes (transposed), ends at 4928
|
| 2198 |
+
BATCH_CV: 4928,
|
| 2199 |
+
// 4 × 8 words × 4 bytes = 128 bytes (working CVs), ends at 5056
|
| 2200 |
+
BATCH_COUNTER_LOW: 5056,
|
| 2201 |
+
// 4 words × 4 bytes = 16 bytes (per-chunk counters), ends at 5072
|
| 2202 |
+
BATCH_FLAGS_BASE: 5072,
|
| 2203 |
+
// 4 words × 4 bytes = 16 bytes (base flags, no START/END), ends at 5088
|
| 2204 |
+
BATCH_OUTPUT: 5088,
|
| 2205 |
+
// 4 × 8 words × 4 bytes = 128 bytes (final output), ends at 5216
|
| 2206 |
+
// End of batch working area: 5216 bytes
|
| 2207 |
+
// WASM Arena: JS working buffers (accessed via TypedArray views)
|
| 2208 |
+
CV_STACK: 5216,
|
| 2209 |
+
// 64 levels × 8 words × 4 bytes = 2048 bytes, ends at 7264
|
| 2210 |
+
PARENT_BLOCK: 7264,
|
| 2211 |
+
// 16 words × 4 bytes = 64 bytes, ends at 7328
|
| 2212 |
+
CHUNK_CV: 7328,
|
| 2213 |
+
// 8 words × 4 bytes = 32 bytes, ends at 7360
|
| 2214 |
+
TEMP_CVS: 7360
|
| 2215 |
+
// 4 × 8 words × 4 bytes = 128 bytes, ends at 7488
|
| 2216 |
+
// Total arena usage: ~7488 bytes (fits comfortably in 64KB page)
|
| 2217 |
+
};
|
| 2218 |
+
var arenaCvStack = null;
|
| 2219 |
+
var arenaParentBlock = null;
|
| 2220 |
+
var arenaChunkCv = null;
|
| 2221 |
+
var arenaTempCvs = null;
|
| 2222 |
+
var arenaBatchBlockWords = null;
|
| 2223 |
+
var arenaBatchCv = null;
|
| 2224 |
+
var arenaBatchCounterLow = null;
|
| 2225 |
+
var arenaBatchFlagsBase = null;
|
| 2226 |
+
var arenaBatchOutput = null;
|
| 2227 |
+
|
| 2228 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/hash.js
|
| 2229 |
+
var CV_STACK_DEPTH = 64;
|
| 2230 |
+
var HYPER_CV_STACK = new Uint32Array(CV_STACK_DEPTH * 8);
|
| 2231 |
+
var CV_POOL_SIZE = 64;
|
| 2232 |
+
var CV_POOL = new Uint32Array(CV_POOL_SIZE * 8);
|
| 2233 |
+
var CV_VIEWS = [];
|
| 2234 |
+
for (let i = 0; i < CV_POOL_SIZE; i++) {
|
| 2235 |
+
CV_VIEWS.push(CV_POOL.subarray(i * 8, i * 8 + 8));
|
| 2236 |
+
}
|
| 2237 |
+
var simdAvailable = false;
|
| 2238 |
+
var SIMD_THRESHOLD = 4 * CHUNK_LEN;
|
| 2239 |
+
function ensureSimdSync() {
|
| 2240 |
+
if (simdAvailable)
|
| 2241 |
+
return true;
|
| 2242 |
+
simdAvailable = initSimdSync();
|
| 2243 |
+
return simdAvailable;
|
| 2244 |
+
}
|
| 2245 |
+
var simdChunkCvs = new Uint32Array(32);
|
| 2246 |
+
var reusableTempCv = new Uint32Array(8);
|
| 2247 |
+
var reusableChunkCv = new Uint32Array(8);
|
| 2248 |
+
var reusablePureParentBlock = new Uint32Array(16);
|
| 2249 |
+
var reusablePureParentCv = new Uint32Array(8);
|
| 2250 |
+
var reusableSimdCvs = new Uint32Array(32);
|
| 2251 |
+
var reusableSimdParentBlock = new Uint32Array(16);
|
| 2252 |
+
var reusableSimdParentCv = new Uint32Array(8);
|
| 2253 |
+
var reusableOffsets = new Uint32Array(4);
|
| 2254 |
+
var reusableCounters = new Uint32Array(4);
|
| 2255 |
+
var reusableBlockLens = new Uint32Array(4);
|
| 2256 |
+
var reusableFlags = new Uint32Array(4);
|
| 2257 |
+
var reusableOut8 = new Uint32Array(8);
|
| 2258 |
+
var reusableOut8View = new Uint8Array(reusableOut8.buffer, 0, 32);
|
| 2259 |
+
var SIMD_CV_BASE = SIMD_MEMORY.CHAINING_VALUES / 4;
|
| 2260 |
+
var SIMD_OUT_BASE = SIMD_MEMORY.OUTPUT / 4;
|
| 2261 |
+
var SIMD_COUNTER_LOW_BASE = SIMD_MEMORY.COUNTER_LOW / 4;
|
| 2262 |
+
var SIMD_COUNTER_HIGH_BASE = SIMD_MEMORY.COUNTER_HIGH / 4;
|
| 2263 |
+
var SIMD_BLOCK_LEN_BASE = SIMD_MEMORY.BLOCK_LEN / 4;
|
| 2264 |
+
var BATCH_CV_BASE = SIMD_MEMORY.BATCH_CV / 4;
|
| 2265 |
+
var BATCH_COUNTER_LOW_BASE = SIMD_MEMORY.BATCH_COUNTER_LOW / 4;
|
| 2266 |
+
var BATCH_FLAGS_BASE_OFFSET = SIMD_MEMORY.BATCH_FLAGS_BASE / 4;
|
| 2267 |
+
var BATCH_OUTPUT_BASE = SIMD_MEMORY.BATCH_OUTPUT / 4;
|
| 2268 |
+
var batchChunkOffsets = new Uint32Array(4);
|
| 2269 |
+
var SIMD_FLAGS_BASE = SIMD_MEMORY.FLAGS / 4;
|
| 2270 |
+
function warmupSimd() {
|
| 2271 |
+
return ensureSimdSync();
|
| 2272 |
+
}
|
| 2273 |
+
|
| 2274 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/blake3-jit/dist/esm/index.js
|
| 2275 |
+
if (typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined") {
|
| 2276 |
+
queueMicrotask(() => {
|
| 2277 |
+
warmupSimd();
|
| 2278 |
+
});
|
| 2279 |
+
}
|
| 2280 |
+
|
| 2281 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/xetchunk-wasm/dist/esm/xet-chunker.js
|
| 2282 |
+
var TARGET_CHUNK_SIZE = 64 * 1024;
|
| 2283 |
+
var BLAKE3_DATA_KEY = new Uint8Array([
|
| 2284 |
+
102,
|
| 2285 |
+
151,
|
| 2286 |
+
245,
|
| 2287 |
+
119,
|
| 2288 |
+
91,
|
| 2289 |
+
149,
|
| 2290 |
+
80,
|
| 2291 |
+
222,
|
| 2292 |
+
49,
|
| 2293 |
+
53,
|
| 2294 |
+
203,
|
| 2295 |
+
172,
|
| 2296 |
+
165,
|
| 2297 |
+
151,
|
| 2298 |
+
24,
|
| 2299 |
+
28,
|
| 2300 |
+
157,
|
| 2301 |
+
228,
|
| 2302 |
+
33,
|
| 2303 |
+
16,
|
| 2304 |
+
155,
|
| 2305 |
+
235,
|
| 2306 |
+
43,
|
| 2307 |
+
88,
|
| 2308 |
+
180,
|
| 2309 |
+
208,
|
| 2310 |
+
176,
|
| 2311 |
+
75,
|
| 2312 |
+
147,
|
| 2313 |
+
173,
|
| 2314 |
+
242,
|
| 2315 |
+
41
|
| 2316 |
+
]);
|
| 2317 |
+
|
| 2318 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/xetchunk-wasm/dist/esm/xorb-hash.js
|
| 2319 |
+
var BLAKE3_NODE_KEY = new Uint8Array([
|
| 2320 |
+
1,
|
| 2321 |
+
126,
|
| 2322 |
+
197,
|
| 2323 |
+
199,
|
| 2324 |
+
165,
|
| 2325 |
+
71,
|
| 2326 |
+
41,
|
| 2327 |
+
150,
|
| 2328 |
+
253,
|
| 2329 |
+
148,
|
| 2330 |
+
102,
|
| 2331 |
+
102,
|
| 2332 |
+
180,
|
| 2333 |
+
138,
|
| 2334 |
+
2,
|
| 2335 |
+
230,
|
| 2336 |
+
93,
|
| 2337 |
+
221,
|
| 2338 |
+
83,
|
| 2339 |
+
111,
|
| 2340 |
+
55,
|
| 2341 |
+
199,
|
| 2342 |
+
109,
|
| 2343 |
+
210,
|
| 2344 |
+
248,
|
| 2345 |
+
99,
|
| 2346 |
+
82,
|
| 2347 |
+
230,
|
| 2348 |
+
74,
|
| 2349 |
+
83,
|
| 2350 |
+
113,
|
| 2351 |
+
63
|
| 2352 |
+
]);
|
| 2353 |
+
var INDEX_OF_LAST_BYTE_OF_LAST_U64_IN_CHUNK_HASH = 3 * 8;
|
| 2354 |
+
var nodeHasher = Hasher.newKeyed(BLAKE3_NODE_KEY);
|
| 2355 |
+
|
| 2356 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/xetchunk-wasm/dist/esm/hash-utils.js
|
| 2357 |
+
var ZERO_KEY = new Uint8Array(32);
|
| 2358 |
+
var VERIFICATION_KEY = new Uint8Array([
|
| 2359 |
+
127,
|
| 2360 |
+
24,
|
| 2361 |
+
87,
|
| 2362 |
+
214,
|
| 2363 |
+
206,
|
| 2364 |
+
86,
|
| 2365 |
+
237,
|
| 2366 |
+
102,
|
| 2367 |
+
18,
|
| 2368 |
+
127,
|
| 2369 |
+
249,
|
| 2370 |
+
19,
|
| 2371 |
+
231,
|
| 2372 |
+
165,
|
| 2373 |
+
195,
|
| 2374 |
+
243,
|
| 2375 |
+
164,
|
| 2376 |
+
205,
|
| 2377 |
+
38,
|
| 2378 |
+
213,
|
| 2379 |
+
181,
|
| 2380 |
+
219,
|
| 2381 |
+
73,
|
| 2382 |
+
230,
|
| 2383 |
+
65,
|
| 2384 |
+
36,
|
| 2385 |
+
152,
|
| 2386 |
+
127,
|
| 2387 |
+
40,
|
| 2388 |
+
251,
|
| 2389 |
+
148,
|
| 2390 |
+
195
|
| 2391 |
+
]);
|
| 2392 |
+
var fileHasher = Hasher.newKeyed(ZERO_KEY);
|
| 2393 |
+
var verificationHasher = Hasher.newKeyed(VERIFICATION_KEY);
|
| 2394 |
+
|
| 2395 |
+
// ../../../hf-oauth-build-pRp19k/node_modules/@huggingface/hub/dist/browser/index.mjs
|
| 2396 |
+
var HUB_URL = "https://huggingface.co";
|
| 2397 |
+
async function createApiError(response, opts) {
|
| 2398 |
+
const error = new HubApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId);
|
| 2399 |
+
error.message = `Api error with status ${error.statusCode}${opts?.message ? `. ${opts.message}` : ""}`;
|
| 2400 |
+
const trailer = [`URL: ${error.url}`, error.requestId ? `Request ID: ${error.requestId}` : void 0].filter(Boolean).join(". ");
|
| 2401 |
+
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
|
| 2402 |
+
const json = await response.json();
|
| 2403 |
+
error.message = json.error || json.message || error.message;
|
| 2404 |
+
if (json.error_description) {
|
| 2405 |
+
error.message = error.message ? error.message + `: ${json.error_description}` : json.error_description;
|
| 2406 |
+
}
|
| 2407 |
+
error.data = json;
|
| 2408 |
+
} else {
|
| 2409 |
+
error.data = { message: await response.text() };
|
| 2410 |
+
}
|
| 2411 |
+
error.message += `. ${trailer}`;
|
| 2412 |
+
throw error;
|
| 2413 |
+
}
|
| 2414 |
+
var HubApiError = class extends Error {
|
| 2415 |
+
statusCode;
|
| 2416 |
+
url;
|
| 2417 |
+
requestId;
|
| 2418 |
+
data;
|
| 2419 |
+
constructor(url, statusCode, requestId, message) {
|
| 2420 |
+
super(message);
|
| 2421 |
+
this.statusCode = statusCode;
|
| 2422 |
+
this.requestId = requestId;
|
| 2423 |
+
this.url = url;
|
| 2424 |
+
}
|
| 2425 |
+
};
|
| 2426 |
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
| 2427 |
+
var isWebWorker = typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
|
| 2428 |
+
var isBackend = !isBrowser && !isWebWorker;
|
| 2429 |
+
var isFrontend = !isBackend;
|
| 2430 |
+
var resolve;
|
| 2431 |
+
var waitPromise = new Promise((r) => {
|
| 2432 |
+
resolve = r;
|
| 2433 |
+
});
|
| 2434 |
+
function base64FromBytes(arr) {
|
| 2435 |
+
if (globalThis.Buffer) {
|
| 2436 |
+
return globalThis.Buffer.from(arr).toString("base64");
|
| 2437 |
+
} else {
|
| 2438 |
+
const bin = [];
|
| 2439 |
+
arr.forEach((byte) => {
|
| 2440 |
+
bin.push(String.fromCharCode(byte));
|
| 2441 |
+
});
|
| 2442 |
+
return globalThis.btoa(bin.join(""));
|
| 2443 |
+
}
|
| 2444 |
+
}
|
| 2445 |
+
var hashSize = 1 << 16;
|
| 2446 |
+
var mlBits = 4;
|
| 2447 |
+
var mlMask = (1 << mlBits) - 1;
|
| 2448 |
+
var runBits = 4;
|
| 2449 |
+
var runMask = (1 << runBits) - 1;
|
| 2450 |
+
var blockBuf = makeBuffer(5 << 20);
|
| 2451 |
+
var hashTable = makeHashTable();
|
| 2452 |
+
function makeHashTable() {
|
| 2453 |
+
try {
|
| 2454 |
+
return new Uint32Array(hashSize);
|
| 2455 |
+
} catch (error) {
|
| 2456 |
+
const hashTable2 = new Array(hashSize);
|
| 2457 |
+
for (let i = 0; i < hashSize; i++) {
|
| 2458 |
+
hashTable2[i] = 0;
|
| 2459 |
+
}
|
| 2460 |
+
return hashTable2;
|
| 2461 |
+
}
|
| 2462 |
+
}
|
| 2463 |
+
function makeBuffer(size) {
|
| 2464 |
+
return new Uint8Array(size);
|
| 2465 |
+
}
|
| 2466 |
+
var textEncoder = new TextEncoder();
|
| 2467 |
+
var CRLF = textEncoder.encode("\r\n");
|
| 2468 |
+
var HEADER_SEPARATOR = textEncoder.encode("\r\n\r\n");
|
| 2469 |
+
function hasH2Fetch(versions = typeof process !== "undefined" ? process.versions : void 0, frontend = isFrontend) {
|
| 2470 |
+
if (frontend || !versions?.undici || versions.bun) {
|
| 2471 |
+
return false;
|
| 2472 |
+
}
|
| 2473 |
+
return Number(versions.undici.split(".")[0]) >= 8;
|
| 2474 |
+
}
|
| 2475 |
+
var GLOBAL_DISPATCHER_KEYS = [/* @__PURE__ */ Symbol.for("undici.globalDispatcher.2"), /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1")];
|
| 2476 |
+
function withHttp1(base) {
|
| 2477 |
+
return {
|
| 2478 |
+
dispatch: (options, handler) => base.dispatch({ ...options, allowH2: false }, handler)
|
| 2479 |
+
};
|
| 2480 |
+
}
|
| 2481 |
+
var cached;
|
| 2482 |
+
async function getHttp1Dispatcher() {
|
| 2483 |
+
const globals = globalThis;
|
| 2484 |
+
const find = () => GLOBAL_DISPATCHER_KEYS.map((key) => globals[key]).find((d) => typeof d?.dispatch === "function");
|
| 2485 |
+
let base = find();
|
| 2486 |
+
if (base === void 0) {
|
| 2487 |
+
await (await fetch("data:,")).arrayBuffer();
|
| 2488 |
+
base = find();
|
| 2489 |
+
}
|
| 2490 |
+
if (base === void 0) {
|
| 2491 |
+
return void 0;
|
| 2492 |
+
}
|
| 2493 |
+
if (cached?.base !== base) {
|
| 2494 |
+
cached = { base, http1: withHttp1(base) };
|
| 2495 |
+
}
|
| 2496 |
+
return cached.http1;
|
| 2497 |
+
}
|
| 2498 |
+
var undiciHttp1Fetch = async (input, init) => {
|
| 2499 |
+
const dispatcher = await getHttp1Dispatcher();
|
| 2500 |
+
return dispatcher ? fetch(input, { ...init, dispatcher }) : fetch(input, init);
|
| 2501 |
+
};
|
| 2502 |
+
var http1Fetch = hasH2Fetch() ? undiciHttp1Fetch : (input, init) => fetch(input, init);
|
| 2503 |
+
var PARALLEL_MIN_IN_FLIGHT_BYTES = 64 * 1024 * 1024;
|
| 2504 |
+
var PARALLEL_MAX_IN_FLIGHT_BYTES = 256 * 1024 * 1024;
|
| 2505 |
+
var HASH_LENGTH = 32;
|
| 2506 |
+
var XORB_HASH_BOOKEND = "ff".repeat(HASH_LENGTH);
|
| 2507 |
+
var ZERO_KEY2 = new Uint8Array(32);
|
| 2508 |
+
var TARGET_CHUNK_SIZE2 = 64 * 1024;
|
| 2509 |
+
var MAX_CHUNK_SIZE = 2 * TARGET_CHUNK_SIZE2;
|
| 2510 |
+
var XORB_SIZE = 64 * 1024 * 1024;
|
| 2511 |
+
var MAX_XORB_CHUNKS = 8 * 1024;
|
| 2512 |
+
var PROCESSING_PROGRESS_RATIO = 0.1;
|
| 2513 |
+
var UPLOADING_PROGRESS_RATIO = 1 - PROCESSING_PROGRESS_RATIO;
|
| 2514 |
+
var SHARD_MAX_SIZE = 64 * 1024 * 1024;
|
| 2515 |
+
var SHARD_MAGIC_TAG = new Uint8Array([
|
| 2516 |
+
"H".charCodeAt(0),
|
| 2517 |
+
"F".charCodeAt(0),
|
| 2518 |
+
"R".charCodeAt(0),
|
| 2519 |
+
"e".charCodeAt(0),
|
| 2520 |
+
"p".charCodeAt(0),
|
| 2521 |
+
"o".charCodeAt(0),
|
| 2522 |
+
"M".charCodeAt(0),
|
| 2523 |
+
"e".charCodeAt(0),
|
| 2524 |
+
"t".charCodeAt(0),
|
| 2525 |
+
"a".charCodeAt(0),
|
| 2526 |
+
"D".charCodeAt(0),
|
| 2527 |
+
"a".charCodeAt(0),
|
| 2528 |
+
"t".charCodeAt(0),
|
| 2529 |
+
"a".charCodeAt(0),
|
| 2530 |
+
0,
|
| 2531 |
+
85,
|
| 2532 |
+
105,
|
| 2533 |
+
103,
|
| 2534 |
+
69,
|
| 2535 |
+
106,
|
| 2536 |
+
123,
|
| 2537 |
+
129,
|
| 2538 |
+
87,
|
| 2539 |
+
131,
|
| 2540 |
+
165,
|
| 2541 |
+
189,
|
| 2542 |
+
217,
|
| 2543 |
+
92,
|
| 2544 |
+
205,
|
| 2545 |
+
209,
|
| 2546 |
+
74,
|
| 2547 |
+
169
|
| 2548 |
+
]);
|
| 2549 |
+
async function oauthHandleRedirect(opts) {
|
| 2550 |
+
if (typeof window === "undefined" && !opts?.redirectedUrl) {
|
| 2551 |
+
throw new Error("oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl");
|
| 2552 |
+
}
|
| 2553 |
+
if (typeof localStorage === "undefined" && (!opts?.nonce || !opts?.codeVerifier)) {
|
| 2554 |
+
throw new Error(
|
| 2555 |
+
"oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier"
|
| 2556 |
+
);
|
| 2557 |
+
}
|
| 2558 |
+
const redirectedUrl = opts?.redirectedUrl ?? window.location.href;
|
| 2559 |
+
const searchParams = (() => {
|
| 2560 |
+
try {
|
| 2561 |
+
return new URL(redirectedUrl).searchParams;
|
| 2562 |
+
} catch (err) {
|
| 2563 |
+
throw new Error("Failed to parse redirected URL: " + redirectedUrl);
|
| 2564 |
+
}
|
| 2565 |
+
})();
|
| 2566 |
+
const [error, errorDescription] = [searchParams.get("error"), searchParams.get("error_description")];
|
| 2567 |
+
if (error) {
|
| 2568 |
+
throw new Error(`${error}: ${errorDescription}`);
|
| 2569 |
+
}
|
| 2570 |
+
const code = searchParams.get("code");
|
| 2571 |
+
const nonce = opts?.nonce ?? localStorage.getItem("huggingface.co:oauth:nonce");
|
| 2572 |
+
if (!code) {
|
| 2573 |
+
throw new Error("Missing oauth code from query parameters in redirected URL: " + redirectedUrl);
|
| 2574 |
+
}
|
| 2575 |
+
if (!nonce) {
|
| 2576 |
+
throw new Error("Missing oauth nonce from localStorage");
|
| 2577 |
+
}
|
| 2578 |
+
const codeVerifier = opts?.codeVerifier ?? localStorage.getItem("huggingface.co:oauth:code_verifier");
|
| 2579 |
+
if (!codeVerifier) {
|
| 2580 |
+
throw new Error("Missing oauth code_verifier from localStorage");
|
| 2581 |
+
}
|
| 2582 |
+
const state = searchParams.get("state");
|
| 2583 |
+
if (!state) {
|
| 2584 |
+
throw new Error("Missing oauth state from query parameters in redirected URL");
|
| 2585 |
+
}
|
| 2586 |
+
let parsedState;
|
| 2587 |
+
try {
|
| 2588 |
+
parsedState = JSON.parse(state);
|
| 2589 |
+
} catch {
|
| 2590 |
+
throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: " + state);
|
| 2591 |
+
}
|
| 2592 |
+
if (parsedState.nonce !== nonce) {
|
| 2593 |
+
throw new Error("Invalid oauth state in redirected URL");
|
| 2594 |
+
}
|
| 2595 |
+
const hubUrl = opts?.hubUrl || HUB_URL;
|
| 2596 |
+
const openidConfigUrl = `${new URL(hubUrl).origin}/.well-known/openid-configuration`;
|
| 2597 |
+
const openidConfigRes = await fetch(openidConfigUrl, {
|
| 2598 |
+
headers: {
|
| 2599 |
+
Accept: "application/json"
|
| 2600 |
+
}
|
| 2601 |
+
});
|
| 2602 |
+
if (!openidConfigRes.ok) {
|
| 2603 |
+
throw await createApiError(openidConfigRes);
|
| 2604 |
+
}
|
| 2605 |
+
const openidConfig = await openidConfigRes.json();
|
| 2606 |
+
const tokenRes = await fetch(openidConfig.token_endpoint, {
|
| 2607 |
+
method: "POST",
|
| 2608 |
+
headers: {
|
| 2609 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
| 2610 |
+
},
|
| 2611 |
+
body: new URLSearchParams({
|
| 2612 |
+
grant_type: "authorization_code",
|
| 2613 |
+
code,
|
| 2614 |
+
redirect_uri: parsedState.redirectUri,
|
| 2615 |
+
code_verifier: codeVerifier
|
| 2616 |
+
}).toString()
|
| 2617 |
+
});
|
| 2618 |
+
if (!opts?.codeVerifier) {
|
| 2619 |
+
localStorage.removeItem("huggingface.co:oauth:code_verifier");
|
| 2620 |
+
}
|
| 2621 |
+
if (!opts?.nonce) {
|
| 2622 |
+
localStorage.removeItem("huggingface.co:oauth:nonce");
|
| 2623 |
+
}
|
| 2624 |
+
if (!tokenRes.ok) {
|
| 2625 |
+
throw await createApiError(tokenRes);
|
| 2626 |
+
}
|
| 2627 |
+
const token = await tokenRes.json();
|
| 2628 |
+
const accessTokenExpiresAt = new Date(Date.now() + token.expires_in * 1e3);
|
| 2629 |
+
const userInfoRes = await fetch(openidConfig.userinfo_endpoint, {
|
| 2630 |
+
headers: {
|
| 2631 |
+
Authorization: `Bearer ${token.access_token}`
|
| 2632 |
+
}
|
| 2633 |
+
});
|
| 2634 |
+
if (!userInfoRes.ok) {
|
| 2635 |
+
throw await createApiError(userInfoRes);
|
| 2636 |
+
}
|
| 2637 |
+
const userInfo = await userInfoRes.json();
|
| 2638 |
+
return {
|
| 2639 |
+
accessToken: token.access_token,
|
| 2640 |
+
accessTokenExpiresAt,
|
| 2641 |
+
userInfo,
|
| 2642 |
+
state: parsedState.state,
|
| 2643 |
+
scope: token.scope
|
| 2644 |
+
};
|
| 2645 |
+
}
|
| 2646 |
+
async function oauthLoginUrl(opts) {
|
| 2647 |
+
if (typeof window === "undefined" && (!opts?.redirectUrl || !opts?.clientId)) {
|
| 2648 |
+
throw new Error("oauthLogin is only available in the browser, unless you provide clientId and redirectUrl");
|
| 2649 |
+
}
|
| 2650 |
+
if (typeof localStorage === "undefined" && !opts?.localStorage) {
|
| 2651 |
+
throw new Error(
|
| 2652 |
+
"oauthLogin requires localStorage to be available in the context, unless you provide a localStorage empty object as argument"
|
| 2653 |
+
);
|
| 2654 |
+
}
|
| 2655 |
+
const hubUrl = opts?.hubUrl || HUB_URL;
|
| 2656 |
+
const openidConfigUrl = `${new URL(hubUrl).origin}/.well-known/openid-configuration`;
|
| 2657 |
+
const openidConfigRes = await fetch(openidConfigUrl, {
|
| 2658 |
+
headers: {
|
| 2659 |
+
Accept: "application/json"
|
| 2660 |
+
}
|
| 2661 |
+
});
|
| 2662 |
+
if (!openidConfigRes.ok) {
|
| 2663 |
+
throw await createApiError(openidConfigRes);
|
| 2664 |
+
}
|
| 2665 |
+
const opendidConfig = await openidConfigRes.json();
|
| 2666 |
+
const newNonce = globalThis.crypto.randomUUID();
|
| 2667 |
+
const newCodeVerifier = globalThis.crypto.randomUUID() + globalThis.crypto.randomUUID();
|
| 2668 |
+
if (opts?.localStorage) {
|
| 2669 |
+
if (opts.localStorage.codeVerifier !== void 0 && opts.localStorage.codeVerifier !== null) {
|
| 2670 |
+
throw new Error(
|
| 2671 |
+
"localStorage.codeVerifier must be initially set to null or undefined, and will be filled by oauthLoginUrl"
|
| 2672 |
+
);
|
| 2673 |
+
}
|
| 2674 |
+
if (opts.localStorage.nonce !== void 0 && opts.localStorage.nonce !== null) {
|
| 2675 |
+
throw new Error(
|
| 2676 |
+
"localStorage.nonce must be initially set to null or undefined, and will be filled by oauthLoginUrl"
|
| 2677 |
+
);
|
| 2678 |
+
}
|
| 2679 |
+
opts.localStorage.codeVerifier = newCodeVerifier;
|
| 2680 |
+
opts.localStorage.nonce = newNonce;
|
| 2681 |
+
} else {
|
| 2682 |
+
localStorage.setItem("huggingface.co:oauth:nonce", newNonce);
|
| 2683 |
+
localStorage.setItem("huggingface.co:oauth:code_verifier", newCodeVerifier);
|
| 2684 |
+
}
|
| 2685 |
+
const redirectUri = opts?.redirectUrl || (typeof window !== "undefined" ? window.location.href : void 0);
|
| 2686 |
+
if (!redirectUri) {
|
| 2687 |
+
throw new Error("Missing redirectUrl");
|
| 2688 |
+
}
|
| 2689 |
+
const state = JSON.stringify({
|
| 2690 |
+
nonce: newNonce,
|
| 2691 |
+
redirectUri,
|
| 2692 |
+
state: opts?.state
|
| 2693 |
+
});
|
| 2694 |
+
const variables = (
|
| 2695 |
+
// @ts-expect-error window.huggingface is defined inside static Spaces.
|
| 2696 |
+
typeof window !== "undefined" ? window.huggingface?.variables ?? null : null
|
| 2697 |
+
);
|
| 2698 |
+
const clientId = opts?.clientId || variables?.OAUTH_CLIENT_ID;
|
| 2699 |
+
if (!clientId) {
|
| 2700 |
+
if (variables) {
|
| 2701 |
+
throw new Error("Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space");
|
| 2702 |
+
}
|
| 2703 |
+
throw new Error("Missing clientId");
|
| 2704 |
+
}
|
| 2705 |
+
const challenge = base64FromBytes(
|
| 2706 |
+
new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(newCodeVerifier)))
|
| 2707 |
+
).replace(/[+]/g, "-").replace(/[/]/g, "_").replace(/=/g, "");
|
| 2708 |
+
return `${opendidConfig.authorization_endpoint}?${new URLSearchParams({
|
| 2709 |
+
client_id: clientId,
|
| 2710 |
+
scope: opts?.scopes || variables?.OAUTH_SCOPES || "openid profile",
|
| 2711 |
+
response_type: "code",
|
| 2712 |
+
redirect_uri: redirectUri,
|
| 2713 |
+
state,
|
| 2714 |
+
code_challenge: challenge,
|
| 2715 |
+
code_challenge_method: "S256"
|
| 2716 |
+
}).toString()}`;
|
| 2717 |
+
}
|
| 2718 |
+
var DIFFUSERS_SAFETENSORS_FILE = "diffusion_pytorch_model.safetensors";
|
| 2719 |
+
var DIFFUSERS_SAFETENSORS_INDEX_FILE = "diffusion_pytorch_model.safetensors.index.json";
|
| 2720 |
+
var DIFFUSERS_WEIGHTS_SUBFOLDERS = ["transformer", "unet"];
|
| 2721 |
+
var MAX_TENSOR_DIM = 2 ** 32;
|
| 2722 |
+
var LIBRARY_WEIGHT_CANDIDATES = {
|
| 2723 |
+
// diffusers keeps the main module (the diffusion transformer / U-Net) under a subfolder,
|
| 2724 |
+
// or at the repo root for single-component repos (ControlNets, standalone VAEs). This matches
|
| 2725 |
+
// how a diffusion model's size is conventionally reported: the diffusion transformer / U-Net,
|
| 2726 |
+
// not the sum of VAE + text encoders.
|
| 2727 |
+
diffusers: [
|
| 2728 |
+
...DIFFUSERS_WEIGHTS_SUBFOLDERS.map((folder) => ({
|
| 2729 |
+
single: `${folder}/${DIFFUSERS_SAFETENSORS_FILE}`,
|
| 2730 |
+
index: `${folder}/${DIFFUSERS_SAFETENSORS_INDEX_FILE}`
|
| 2731 |
+
})),
|
| 2732 |
+
{ single: DIFFUSERS_SAFETENSORS_FILE, index: DIFFUSERS_SAFETENSORS_INDEX_FILE }
|
| 2733 |
+
]
|
| 2734 |
+
};
|
| 2735 |
+
export {
|
| 2736 |
+
oauthHandleRedirect,
|
| 2737 |
+
oauthLoginUrl
|
| 2738 |
+
};
|
vendor/hf-oauth/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@huggingface/hub",
|
| 3 |
+
"version": "2.17.6",
|
| 4 |
+
"description": "Utilities to interact with the Hugging Face hub",
|
| 5 |
+
"keywords": [
|
| 6 |
+
"api",
|
| 7 |
+
"client",
|
| 8 |
+
"face",
|
| 9 |
+
"hub",
|
| 10 |
+
"hugging",
|
| 11 |
+
"huggingface"
|
| 12 |
+
],
|
| 13 |
+
"license": "MIT",
|
| 14 |
+
"author": "Hugging Face",
|
| 15 |
+
"repository": "https://github.com/huggingface/huggingface.js.git",
|
| 16 |
+
"bin": {
|
| 17 |
+
"hfjs": "./dist/cli.js"
|
| 18 |
+
},
|
| 19 |
+
"source": "index.ts",
|
| 20 |
+
"files": [
|
| 21 |
+
"dist",
|
| 22 |
+
"index.ts",
|
| 23 |
+
"src",
|
| 24 |
+
"tsconfig.json"
|
| 25 |
+
],
|
| 26 |
+
"main": "./dist/index.js",
|
| 27 |
+
"module": "./dist/index.mjs",
|
| 28 |
+
"browser": {
|
| 29 |
+
"./src/utils/sha256-node.ts": false,
|
| 30 |
+
"./src/utils/sub-paths.ts": false,
|
| 31 |
+
"./src/utils/FileBlob.ts": false,
|
| 32 |
+
"./src/lib/cache-management.ts": false,
|
| 33 |
+
"./src/lib/download-file-to-cache-dir.ts": false,
|
| 34 |
+
"./src/lib/snapshot-download.ts": false,
|
| 35 |
+
"./dist/index.js": "./dist/browser/index.js",
|
| 36 |
+
"./dist/index.mjs": "./dist/browser/index.mjs"
|
| 37 |
+
},
|
| 38 |
+
"types": "./dist/index.d.ts",
|
| 39 |
+
"exports": {
|
| 40 |
+
".": {
|
| 41 |
+
"types": "./dist/index.d.ts",
|
| 42 |
+
"require": "./dist/index.js",
|
| 43 |
+
"import": "./dist/index.mjs"
|
| 44 |
+
}
|
| 45 |
+
},
|
| 46 |
+
"publishConfig": {
|
| 47 |
+
"access": "public"
|
| 48 |
+
},
|
| 49 |
+
"dependencies": {
|
| 50 |
+
"@huggingface/xetchunk-wasm": "^0.2.0",
|
| 51 |
+
"@huggingface/tasks": "^0.21.58"
|
| 52 |
+
},
|
| 53 |
+
"devDependencies": {
|
| 54 |
+
"@types/cli-progress": "^3.11.6"
|
| 55 |
+
},
|
| 56 |
+
"optionalDependencies": {
|
| 57 |
+
"cli-progress": "^3.12.0"
|
| 58 |
+
},
|
| 59 |
+
"engines": {
|
| 60 |
+
"node": ">=18"
|
| 61 |
+
},
|
| 62 |
+
"scripts": {
|
| 63 |
+
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
|
| 64 |
+
"lint:check": "eslint --ext .cjs,.ts .",
|
| 65 |
+
"format": "oxfmt .",
|
| 66 |
+
"format:check": "oxfmt --check .",
|
| 67 |
+
"build": "tsup && tsc --emitDeclarationOnly --declaration",
|
| 68 |
+
"test": "vitest run",
|
| 69 |
+
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts",
|
| 70 |
+
"check": "tsc",
|
| 71 |
+
"build:xet-wasm": "./scripts/build-xet-wasm.sh -t bundler --clean",
|
| 72 |
+
"bench": "tsx scripts/bench.ts",
|
| 73 |
+
"debug-xet": "tsx scripts/debug-xet.ts"
|
| 74 |
+
}
|
| 75 |
+
}
|