diff --git a/.env.production.example b/.env.production.example new file mode 100644 index 000000000..f1b750ff0 --- /dev/null +++ b/.env.production.example @@ -0,0 +1,12 @@ +# GBrain Remote MCP Server — Production Config +# Copy to .env.production and fill in your values. + +# Supabase pooler URL (Settings > Database > Connection string > Transaction pooler) +# Use the transaction pooler (port 6543), NOT the direct connection. +DATABASE_URL=postgresql://postgres.xxx:password@aws-0-us-west-1.pooler.supabase.com:6543/postgres + +# OpenAI API key for embeddings +OPENAI_API_KEY=sk-... + +# Supabase project ref (the "xxx" from https://xxx.supabase.co) +SUPABASE_PROJECT_REF= diff --git a/.gitignore b/.gitignore index 8d7ebe96b..df915ad5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ bin/ .DS_Store *.log .env.testing +.env.production .18a49dfd730ff378-00000000.bun-build .18a49f9dfb996f70-00000000.bun-build .gstack/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 373d19145..d4748ccc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,37 @@ All notable changes to GBrain will be documented in this file. +## [0.6.0] - 2026-04-10 + +### Added + +- **Access your brain from any AI client.** Deploy GBrain as a serverless remote MCP endpoint on your existing Supabase instance. Works with Claude Desktop, Claude Code, Cowork, and Perplexity Computer. One URL, bearer token auth, zero new infrastructure. Clone the repo, fill in 3 env vars, run `scripts/deploy-remote.sh`, done. +- **Per-client setup guides** in `docs/mcp/` for Claude Code, Claude Desktop, Cowork, Perplexity, and ChatGPT (coming soon, requires OAuth 2.1). Also documents Tailscale Funnel and ngrok as self-hosted alternatives. +- **Token management** via standalone `src/commands/auth.ts`. Create, list, revoke per-client bearer tokens. Includes smoke test: `auth.ts test --token ` verifies the full pipeline (initialize + tools/list + get_stats) in 3 seconds. +- **Usage logging** via `mcp_request_log` table. Every remote tool call logs token name, operation, latency, and status for debugging and security auditing. +- **Hardened health endpoint** at `/health`. Unauthenticated: 200/503 only (no info disclosure). Authenticated: checks postgres, pgvector, and OpenAI API key status. + +### Fixed + +- **MCP server actually connects now.** Handler registration used string literals (`'tools/list' as any`) instead of SDK typed schemas. Replaced with `ListToolsRequestSchema` and `CallToolRequestSchema`. Without this fix, `gbrain serve` silently failed to register handlers. (Issue #9) +- **Search results no longer flooded by one large page.** Keyword search returned ALL chunks from matching pages. Now returns one best chunk per page via `DISTINCT ON`. (Issue #22) +- **Search dedup no longer collapses to one chunk per page.** Layer 1 kept only the single highest-scoring chunk per slug. Now keeps top 3, letting later dedup layers (text similarity, cap per page) do their job. (Issue #22) +- **Transactions no longer corrupt shared state.** Both `PostgresEngine.transaction()` and `db.withTransaction()` swapped the shared connection reference, breaking under concurrent use. Now uses scoped engine via `Object.create` with no shared state mutation. (Issue #22) +- **embed --stale no longer wipes valid embeddings.** `upsertChunks()` deleted all chunks then re-inserted, writing NULL for chunks without new embeddings. Now uses UPSERT (INSERT ON CONFLICT UPDATE) with COALESCE to preserve existing embeddings. (Issue #22) +- **Slug normalization is consistent.** `pathToSlug()` preserved case while `inferSlug()` lowercased. Now `validateSlug()` enforces lowercase at the validation layer, covering all entry points. (Issue #22) +- **initSchema no longer reads from disk at runtime.** Both schema loaders used `readFileSync` with `import.meta.url`, which broke in compiled binaries and Deno Edge Functions. Schema is now embedded at build time via `scripts/build-schema.sh`. (Issue #22) +- **file_upload actually uploads content.** The operation wrote DB metadata but never called the storage backend. Fixed in all 3 paths (operation, CLI upload, CLI sync) with rollback semantics. (Issue #22) +- **S3 storage backend authenticates requests.** `signedFetch()` was just unsigned `fetch()`. Replaced with `@aws-sdk/client-s3` for proper SigV4 signing. Supports R2/MinIO via `forcePathStyle`. (Issue #22) +- **Parallel import uses thread-safe queue.** `queue.shift()` had race conditions under parallel workers. Now uses an atomic index counter. Checkpoint preserved on errors for safe resume. (Issue #22) +- **redirect verifies remote existence before deleting local files.** Previously deleted local files unconditionally. Now checks storage backend before removing. (Issue #22) +- **`gbrain call` respects dry_run.** `handleToolCall()` hardcoded `dryRun: false`. Now reads from params. (Issue #22) + +### Changed + +- Added `@aws-sdk/client-s3` as a dependency for authenticated S3 operations. +- Schema migration v2: unique index on `content_chunks(page_id, chunk_index)` for UPSERT support. +- Schema migration v3: `access_tokens` and `mcp_request_log` tables for remote MCP auth. + ## [0.5.1] - 2026-04-10 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index 060df2a65..ab6ba2ddd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,7 +23,13 @@ server are both generated from this single source. Skills are fat markdown files - `src/core/search/` — Hybrid search: vector + keyword + RRF + multi-query expansion + dedup - `src/core/embedding.ts` — OpenAI text-embedding-3-large, batch, retry, backoff - `src/mcp/server.ts` — MCP stdio server (generated from operations) -- `src/schema.sql` — Full Postgres + pgvector DDL (includes files table) +- `supabase/functions/gbrain-mcp/index.ts` — Remote MCP server (Supabase Edge Function) +- `src/edge-entry.ts` — Curated bundle entry point for Edge Function (excludes fs-dependent modules) +- `src/commands/auth.ts` — Standalone token management (create/list/revoke/test) +- `src/core/schema-embedded.ts` — AUTO-GENERATED from schema.sql (run `bun run build:schema`) +- `src/schema.sql` — Full Postgres + pgvector DDL (source of truth, generates schema-embedded.ts) +- `scripts/deploy-remote.sh` — One-script remote MCP deployment +- `docs/mcp/` — Per-client setup guides (Claude Desktop, Code, Cowork, Perplexity, ChatGPT) - `openclaw.plugin.json` — ClawHub bundle plugin manifest ## Commands @@ -118,6 +124,25 @@ Before shipping (/ship) or reviewing (/review), always run the full test suite: Both must pass. Do not ship with failing E2E tests. Do not skip E2E tests. +## Post-ship requirements (MANDATORY) + +After EVERY /ship, you MUST run /document-release. This is NOT optional. Do NOT +skip it. Do NOT say "docs look fine" without running it. The skill reads every .md +file in the project, cross-references the diff, and updates anything that drifted. + +If /ship's Step 8.5 triggers document-release automatically, that counts. But if +it gets skipped for ANY reason (timeout, error, oversight), you MUST run it manually +before considering the ship complete. + +Files that MUST be checked on every ship: +- README.md — does it reflect new features, commands, or setup steps? +- CLAUDE.md — does it reflect new files, test files, or architecture changes? +- CHANGELOG.md — does it cover every commit? +- TODOS.md — are completed items marked done? +- docs/ — do any guides need updating? + +A ship without updated docs is an incomplete ship. Period. + ## CHANGELOG voice CHANGELOG.md is read by agents during auto-update (Section 17). The agent summarizes diff --git a/README.md b/README.md index 2c80012c7..134f4cafc 100644 --- a/README.md +++ b/README.md @@ -298,6 +298,25 @@ GBrain exposes 30 MCP tools via stdio. Add this to your MCP client config: This gives your agent `get_page`, `put_page`, `search`, `query`, `add_link`, `traverse_graph`, `sync_brain`, `file_upload`, and 22 more tools. All generated from the same operation definitions as the CLI. +#### Remote MCP Server (Claude Desktop, Cowork, Perplexity, ChatGPT) + +Access your brain from any device, any AI client. Deploy as a serverless endpoint on your existing Supabase instance: + +```bash +cp .env.production.example .env.production # fill in 3 values +bash scripts/deploy-remote.sh # links, builds, deploys +bun run src/commands/auth.ts create "claude-desktop" # get a token +``` + +Then add to your AI client: +- **Claude Code:** `claude mcp add gbrain -t http https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp -H "Authorization: Bearer TOKEN"` +- **Claude Desktop:** Settings > Integrations > Add (NOT JSON config) +- **Perplexity Computer:** Settings > Connectors > Add remote MCP + +Per-client setup guides: [`docs/mcp/`](docs/mcp/DEPLOY.md) + +ChatGPT support requires OAuth 2.1 and is coming in v0.7. Self-hosted alternatives (Tailscale Funnel, ngrok) documented in [`docs/mcp/ALTERNATIVES.md`](docs/mcp/ALTERNATIVES.md). + **The tools are not enough.** Your agent also needs the playbook: read [GBRAIN_SKILLPACK.md](docs/GBRAIN_SKILLPACK.md) and paste the relevant sections into your agent's system prompt or project instructions. The skillpack tells the agent WHEN and HOW to use each tool: read before responding, write after learning, detect entities on every message, back-link everything. The skill markdown files in `skills/` are standalone instruction sets. Copy them into your agent's context: @@ -620,7 +639,9 @@ ADMIN gbrain history Page version history gbrain revert Revert to previous version gbrain config [get|set] [value] Brain config - gbrain serve MCP server (stdio) + gbrain serve MCP server (stdio, local) + scripts/deploy-remote.sh Deploy remote MCP server (Supabase Edge Functions) + bun run src/commands/auth.ts Token management (create/list/revoke/test) gbrain call '' Raw tool invocation gbrain --tools-json Tool discovery (JSON) ``` diff --git a/TODOS.md b/TODOS.md index ff6e8c716..823f1b8c2 100644 --- a/TODOS.md +++ b/TODOS.md @@ -17,17 +17,37 @@ **Depends on:** Part 5 (parallel import with per-worker engines) -- already shipped. +## P0 + +### ChatGPT MCP support (OAuth 2.1) +**What:** Add OAuth 2.1 with Dynamic Client Registration to the Edge Function so ChatGPT can connect. + +**Why:** ChatGPT requires OAuth 2.1 for MCP connectors. Bearer token auth is NOT supported. This is the only major AI client that can't use GBrain remotely. + +**Pros:** Completes the "every AI client" promise. ChatGPT has the largest user base. + +**Cons:** OAuth 2.1 is a significant implementation: authorization endpoint, token endpoint, PKCE flow, dynamic client registration. Estimated CC: ~3-4 hours. + +**Context:** Discovered during DX review (2026-04-10). All other clients (Claude Desktop/Code/Cowork, Perplexity) work with bearer tokens. See `docs/mcp/CHATGPT.md` for current status. + +**Depends on:** v0.6.0 remote MCP server (shipped). + ## P2 +### Fly.io HTTP server as alternative deployment +**What:** Add `gbrain serve --http` and a Dockerfile/fly.toml for users who prefer a traditional server over Edge Functions. + +**Why:** Avoids the Deno bundling seam. Bun runs natively. No 60s timeout. No cold start. Codex flagged the bundle strategy as "permanent maintenance tax." + +**Pros:** Simpler code path, no edge-entry.ts needed, no Deno compat concerns. Supports sync_brain and file_upload remotely. + +**Cons:** Users need a Fly.io account. Not zero-infra. + +**Context:** From CEO review (2026-04-10). Edge Functions are the primary path. Fly.io is for power users who want full operation support remotely. + +**Depends on:** v0.6.0 remote MCP server (shipped). + +## Completed + ### Implement AWS Signature V4 for S3 storage backend -**What:** Replace the unsigned `signedFetch()` in `src/core/storage/s3.ts` with proper AWS Signature V4 request signing. - -**Why:** The current S3 implementation accepts `accessKeyId` and `secretAccessKey` but never signs requests. It only works with public buckets or pre-signed URLs. Private S3 buckets return 403. - -**Pros:** Enables private S3/R2/MinIO bucket support. Users can store files securely without relying on public bucket access. - -**Cons:** AWS Sig V4 is complex (canonical request, string to sign, signing key derivation). Could use a lightweight library instead of rolling from scratch. Medium implementation effort. - -**Context:** Identified during CSO security audit (2026-04-10). The code explicitly comments this as "simplified" and not production-ready. Nobody uses S3 storage today (Supabase Storage is the default). Only implement when S3 becomes a real deployment path. - -**Depends on:** Nothing. Self-contained change to `src/core/storage/s3.ts`. +**Completed:** v0.6.0 (2026-04-10) — replaced with @aws-sdk/client-s3 for proper SigV4 signing. diff --git a/VERSION b/VERSION index 4b9fcbec1..a918a2aa1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.1 +0.6.0 diff --git a/bun.lock b/bun.lock index 35d29f47b..a7b4d9e16 100644 --- a/bun.lock +++ b/bun.lock @@ -6,6 +6,7 @@ "name": "gbrain", "dependencies": { "@anthropic-ai/sdk": "^0.30.0", + "@aws-sdk/client-s3": "^3.1028.0", "@modelcontextprotocol/sdk": "^1.0.0", "gray-matter": "^4.0.3", "openai": "^4.0.0", @@ -20,10 +21,190 @@ "packages": { "@anthropic-ai/sdk": ["@anthropic-ai/sdk@0.30.1", "", { "dependencies": { "@types/node": "^18.11.18", "@types/node-fetch": "^2.6.4", "abort-controller": "^3.0.0", "agentkeepalive": "^4.2.1", "form-data-encoder": "1.7.2", "formdata-node": "^4.3.2", "node-fetch": "^2.6.7" } }, "sha512-nuKvp7wOIz6BFei8WrTdhmSsx5mwnArYyJgh4+vYu3V4J0Ltb8Xm3odPm51n1aSI0XxNCrDl7O88cxCtUdAkaw=="], + "@aws-crypto/crc32": ["@aws-crypto/crc32@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-nLbCWqQNgUiwwtFsen1AdzAtvuLRsQS8rYgMuxCrdKf9kOssamGLuPwyTY9wyYblNr9+1XM8v6zoDTPPSIeANg=="], + + "@aws-crypto/crc32c": ["@aws-crypto/crc32c@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-+iWb8qaHLYKrNvGRbiYRHSdKRWhto5XlZUEBwDjYNf+ly5SVYG6zEoYIdxvf5R3zyeP16w4PLBn3rH1xc74Rag=="], + + "@aws-crypto/sha1-browser": ["@aws-crypto/sha1-browser@5.2.0", "", { "dependencies": { "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "sha512-OH6lveCFfcDjX4dbAvCFSYUjJZjDr/3XJ3xHtjn3Oj5b9RjojQo8npoLeA/bNwkOkrSQ0wgrHzXk4tDRxGKJeg=="], + + "@aws-crypto/sha256-browser": ["@aws-crypto/sha256-browser@5.2.0", "", { "dependencies": { "@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw=="], + + "@aws-crypto/sha256-js": ["@aws-crypto/sha256-js@5.2.0", "", { "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA=="], + + "@aws-crypto/supports-web-crypto": ["@aws-crypto/supports-web-crypto@5.2.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg=="], + + "@aws-crypto/util": ["@aws-crypto/util@5.2.0", "", { "dependencies": { "@aws-sdk/types": "^3.222.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ=="], + + "@aws-sdk/client-s3": ["@aws-sdk/client-s3@3.1028.0", "", { "dependencies": { "@aws-crypto/sha1-browser": "5.2.0", "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.27", "@aws-sdk/credential-provider-node": "^3.972.30", "@aws-sdk/middleware-bucket-endpoint": "^3.972.9", "@aws-sdk/middleware-expect-continue": "^3.972.9", "@aws-sdk/middleware-flexible-checksums": "^3.974.7", "@aws-sdk/middleware-host-header": "^3.972.9", "@aws-sdk/middleware-location-constraint": "^3.972.9", "@aws-sdk/middleware-logger": "^3.972.9", "@aws-sdk/middleware-recursion-detection": "^3.972.10", "@aws-sdk/middleware-sdk-s3": "^3.972.28", "@aws-sdk/middleware-ssec": "^3.972.9", "@aws-sdk/middleware-user-agent": "^3.972.29", "@aws-sdk/region-config-resolver": "^3.972.11", "@aws-sdk/signature-v4-multi-region": "^3.996.16", "@aws-sdk/types": "^3.973.7", "@aws-sdk/util-endpoints": "^3.996.6", "@aws-sdk/util-user-agent-browser": "^3.972.9", "@aws-sdk/util-user-agent-node": "^3.973.15", "@smithy/config-resolver": "^4.4.14", "@smithy/core": "^3.23.14", "@smithy/eventstream-serde-browser": "^4.2.13", "@smithy/eventstream-serde-config-resolver": "^4.3.13", "@smithy/eventstream-serde-node": "^4.2.13", "@smithy/fetch-http-handler": "^5.3.16", "@smithy/hash-blob-browser": "^4.2.14", "@smithy/hash-node": "^4.2.13", "@smithy/hash-stream-node": "^4.2.13", "@smithy/invalid-dependency": "^4.2.13", "@smithy/md5-js": "^4.2.13", "@smithy/middleware-content-length": "^4.2.13", "@smithy/middleware-endpoint": "^4.4.29", "@smithy/middleware-retry": "^4.5.0", "@smithy/middleware-serde": "^4.2.17", "@smithy/middleware-stack": "^4.2.13", "@smithy/node-config-provider": "^4.3.13", "@smithy/node-http-handler": "^4.5.2", "@smithy/protocol-http": "^5.3.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.45", "@smithy/util-defaults-mode-node": "^4.2.49", "@smithy/util-endpoints": "^3.3.4", "@smithy/util-middleware": "^4.2.13", "@smithy/util-retry": "^4.3.0", "@smithy/util-stream": "^4.5.22", "@smithy/util-utf8": "^4.2.2", "@smithy/util-waiter": "^4.2.15", "tslib": "^2.6.2" } }, "sha512-KL8PREFJxyWXUjMQR6Krq/OjZ5qbcV1QFjtA7Q7oMW5XaFO9YoSBtBxQeeXO4um6vYSmRVYVDTvEKZDcNbyeXw=="], + + "@aws-sdk/core": ["@aws-sdk/core@3.973.27", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@aws-sdk/xml-builder": "^3.972.17", "@smithy/core": "^3.23.14", "@smithy/node-config-provider": "^4.3.13", "@smithy/property-provider": "^4.2.13", "@smithy/protocol-http": "^5.3.13", "@smithy/signature-v4": "^5.3.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/util-base64": "^4.3.2", "@smithy/util-middleware": "^4.2.13", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-CUZ5m8hwMCH6OYI4Li/WgMfIEx10Q2PLI9Y3XOUTPGZJ53aZ0007jCv+X/ywsaERyKPdw5MRZWk877roQksQ4A=="], + + "@aws-sdk/crc64-nvme": ["@aws-sdk/crc64-nvme@3.972.6", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-NMbiqKdruhwwgI6nzBVe2jWMkXjaoQz2YOs3rFX+2F3gGyrJDkDPwMpV/RsTFeq2vAQ055wZNtOXFK4NYSkM8g=="], + + "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.25", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-6QfI0wv4jpG5CrdO/AO0JfZ2ux+tKwJPrUwmvxXF50vI5KIypKVGNF6b4vlkYEnKumDTI1NX2zUBi8JoU5QU3A=="], + + "@aws-sdk/credential-provider-http": ["@aws-sdk/credential-provider-http@3.972.27", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/types": "^3.973.7", "@smithy/fetch-http-handler": "^5.3.16", "@smithy/node-http-handler": "^4.5.2", "@smithy/property-provider": "^4.2.13", "@smithy/protocol-http": "^5.3.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/util-stream": "^4.5.22", "tslib": "^2.6.2" } }, "sha512-3V3Usj9Gs93h865DqN4M2NWJhC5kXU9BvZskfN3+69omuYlE3TZxOEcVQtBGLOloJB7BVfJKXVLqeNhOzHqSlQ=="], + + "@aws-sdk/credential-provider-ini": ["@aws-sdk/credential-provider-ini@3.972.29", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/credential-provider-env": "^3.972.25", "@aws-sdk/credential-provider-http": "^3.972.27", "@aws-sdk/credential-provider-login": "^3.972.29", "@aws-sdk/credential-provider-process": "^3.972.25", "@aws-sdk/credential-provider-sso": "^3.972.29", "@aws-sdk/credential-provider-web-identity": "^3.972.29", "@aws-sdk/nested-clients": "^3.996.19", "@aws-sdk/types": "^3.973.7", "@smithy/credential-provider-imds": "^4.2.13", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-SiBuAnXecCbT/OpAf3vqyI/AVE3mTaYr9ShXLybxZiPLBiPCCOIWSGAtYYGQWMRvobBTiqOewaB+wcgMMZI2Aw=="], + + "@aws-sdk/credential-provider-login": ["@aws-sdk/credential-provider-login@3.972.29", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/nested-clients": "^3.996.19", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/protocol-http": "^5.3.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-OGOslTbOlxXexKMqhxCEbBQbUIfuhGxU5UXw3Fm56ypXHvrXH4aTt/xb5Y884LOoteP1QST1lVZzHfcTnWhiPQ=="], + + "@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.972.30", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.25", "@aws-sdk/credential-provider-http": "^3.972.27", "@aws-sdk/credential-provider-ini": "^3.972.29", "@aws-sdk/credential-provider-process": "^3.972.25", "@aws-sdk/credential-provider-sso": "^3.972.29", "@aws-sdk/credential-provider-web-identity": "^3.972.29", "@aws-sdk/types": "^3.973.7", "@smithy/credential-provider-imds": "^4.2.13", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-FMnAnWxc8PG+ZrZ2OBKzY4luCUJhe9CG0B9YwYr4pzrYGLXBS2rl+UoUvjGbAwiptxRL6hyA3lFn03Bv1TLqTw=="], + + "@aws-sdk/credential-provider-process": ["@aws-sdk/credential-provider-process@3.972.25", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-HR7ynNRdNhNsdVCOCegy1HsfsRzozCOPtD3RzzT1JouuaHobWyRfJzCBue/3jP7gECHt+kQyZUvwg/cYLWurNQ=="], + + "@aws-sdk/credential-provider-sso": ["@aws-sdk/credential-provider-sso@3.972.29", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/nested-clients": "^3.996.19", "@aws-sdk/token-providers": "3.1026.0", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-HWv4SEq3jZDYPlwryZVef97+U8CxxRos5mK8sgGO1dQaFZpV5giZLzqGE5hkDmh2csYcBO2uf5XHjPTpZcJlig=="], + + "@aws-sdk/credential-provider-web-identity": ["@aws-sdk/credential-provider-web-identity@3.972.29", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/nested-clients": "^3.996.19", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-PdMBza1WEKEUPFEmMGCfnU2RYCz9MskU2e8JxjyUOsMKku7j9YaDKvbDi2dzC0ihFoM6ods2SbhfAAro+Gwlew=="], + + "@aws-sdk/middleware-bucket-endpoint": ["@aws-sdk/middleware-bucket-endpoint@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@aws-sdk/util-arn-parser": "^3.972.3", "@smithy/node-config-provider": "^4.3.13", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/util-config-provider": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-COToYKgquDyligbcAep7ygs48RK+mwe/IYprq4+TSrVFzNOYmzWvHf6werpnKV5VYpRiwdn+Wa5ZXkPqLVwcTg=="], + + "@aws-sdk/middleware-expect-continue": ["@aws-sdk/middleware-expect-continue@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-V/FNCjFxnh4VGu+HdSiW4Yg5GELihA1MIDSAdsEPvuayXBVmr0Jaa6jdLAZLH38KYXl/vVjri9DQJWnTAujHEA=="], + + "@aws-sdk/middleware-flexible-checksums": ["@aws-sdk/middleware-flexible-checksums@3.974.7", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@aws-crypto/crc32c": "5.2.0", "@aws-crypto/util": "5.2.0", "@aws-sdk/core": "^3.973.27", "@aws-sdk/crc64-nvme": "^3.972.6", "@aws-sdk/types": "^3.973.7", "@smithy/is-array-buffer": "^4.2.2", "@smithy/node-config-provider": "^4.3.13", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/util-middleware": "^4.2.13", "@smithy/util-stream": "^4.5.22", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-uU4/ch2CLHB8Phu1oTKnnQ4e8Ujqi49zEnQYBhWYT53zfFvtJCdGsaOoypBr8Fm/pmCBssRmGoIQ4sixgdLP9w=="], + + "@aws-sdk/middleware-host-header": ["@aws-sdk/middleware-host-header@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-je5vRdNw4SkuTnmRbFZLdye4sQ0faLt8kwka5wnnSU30q1mHO4X+idGEJOOE+Tn1ME7Oryn05xxkDvIb3UaLaQ=="], + + "@aws-sdk/middleware-location-constraint": ["@aws-sdk/middleware-location-constraint@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-TyfOi2XNdOZpNKeTJwRUsVAGa+14nkyMb2VVGG+eDgcWG/ed6+NUo72N3hT6QJioxym80NSinErD+LBRF0Ir1w=="], + + "@aws-sdk/middleware-logger": ["@aws-sdk/middleware-logger@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-HsVgDrruhqI28RkaXALm8grJ7Agc1wF6Et0xh6pom8NdO2VdO/SD9U/tPwUjewwK/pVoka+EShBxyCvgsPCtog=="], + + "@aws-sdk/middleware-recursion-detection": ["@aws-sdk/middleware-recursion-detection@3.972.10", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-RVQQbq5orQ/GHUnXvqEOj2HHPBJm+mM+ySwZKS5UaLBwra5ugRtiH09PLUoOZRl7a1YzaOzXSuGbn9iD5j60WQ=="], + + "@aws-sdk/middleware-sdk-s3": ["@aws-sdk/middleware-sdk-s3@3.972.28", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/types": "^3.973.7", "@aws-sdk/util-arn-parser": "^3.972.3", "@smithy/core": "^3.23.14", "@smithy/node-config-provider": "^4.3.13", "@smithy/protocol-http": "^5.3.13", "@smithy/signature-v4": "^5.3.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/util-config-provider": "^4.2.2", "@smithy/util-middleware": "^4.2.13", "@smithy/util-stream": "^4.5.22", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-qJHcJQH9UNPUrnPlRtCozKjtqAaypQ5IgQxTNoPsVYIQeuwNIA8Rwt3NvGij1vCDYDfCmZaPLpnJEHlZXeFqmg=="], + + "@aws-sdk/middleware-ssec": ["@aws-sdk/middleware-ssec@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-wSA2BR7L0CyBNDJeSrleIIzC+DzL93YNTdfU0KPGLiocK6YsRv1nPAzPF+BFSdcs0Qa5ku5Kcf4KvQcWwKGenQ=="], + + "@aws-sdk/middleware-user-agent": ["@aws-sdk/middleware-user-agent@3.972.29", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/types": "^3.973.7", "@aws-sdk/util-endpoints": "^3.996.6", "@smithy/core": "^3.23.14", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/util-retry": "^4.3.0", "tslib": "^2.6.2" } }, "sha512-f/sIRzuTfEjg6NsbMYvye2VsmnQoNgntntleQyx5uGacUYzszbfIlO3GcI6G6daWUmTm0IDZc11qMHWwF0o0mQ=="], + + "@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.996.19", "", { "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.27", "@aws-sdk/middleware-host-header": "^3.972.9", "@aws-sdk/middleware-logger": "^3.972.9", "@aws-sdk/middleware-recursion-detection": "^3.972.10", "@aws-sdk/middleware-user-agent": "^3.972.29", "@aws-sdk/region-config-resolver": "^3.972.11", "@aws-sdk/types": "^3.973.7", "@aws-sdk/util-endpoints": "^3.996.6", "@aws-sdk/util-user-agent-browser": "^3.972.9", "@aws-sdk/util-user-agent-node": "^3.973.15", "@smithy/config-resolver": "^4.4.14", "@smithy/core": "^3.23.14", "@smithy/fetch-http-handler": "^5.3.16", "@smithy/hash-node": "^4.2.13", "@smithy/invalid-dependency": "^4.2.13", "@smithy/middleware-content-length": "^4.2.13", "@smithy/middleware-endpoint": "^4.4.29", "@smithy/middleware-retry": "^4.5.0", "@smithy/middleware-serde": "^4.2.17", "@smithy/middleware-stack": "^4.2.13", "@smithy/node-config-provider": "^4.3.13", "@smithy/node-http-handler": "^4.5.2", "@smithy/protocol-http": "^5.3.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.45", "@smithy/util-defaults-mode-node": "^4.2.49", "@smithy/util-endpoints": "^3.3.4", "@smithy/util-middleware": "^4.2.13", "@smithy/util-retry": "^4.3.0", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-uFkmCDXvmQYLanlYdOFS0+MQWkrj9wPMt/ZCc/0J0fjPim6F5jBVBmEomvGY/j77ILW6GTPwN22Jc174Mhkw6Q=="], + + "@aws-sdk/region-config-resolver": ["@aws-sdk/region-config-resolver@3.972.11", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/config-resolver": "^4.4.14", "@smithy/node-config-provider": "^4.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-6Q8B1dcx6BBqUTY1Mc/eROKA0FImEEY5VPSd6AGPEUf0ErjExz4snVqa9kNJSoVDV1rKaNf3qrWojgcKW+SdDg=="], + + "@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.16", "", { "dependencies": { "@aws-sdk/middleware-sdk-s3": "^3.972.28", "@aws-sdk/types": "^3.973.7", "@smithy/protocol-http": "^5.3.13", "@smithy/signature-v4": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-EMdXYB4r/k5RWq86fugjRhid5JA+Z6MpS7n4sij4u5/C+STrkvuf9aFu41rJA9MjUzxCLzv8U2XL8cH2GSRYpQ=="], + + "@aws-sdk/token-providers": ["@aws-sdk/token-providers@3.1026.0", "", { "dependencies": { "@aws-sdk/core": "^3.973.27", "@aws-sdk/nested-clients": "^3.996.19", "@aws-sdk/types": "^3.973.7", "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-Ieq/HiRrbEtrYP387Nes0XlR7H1pJiJOZKv+QyQzMYpvTiDs0VKy2ZB3E2Zf+aFovWmeE7lRE4lXyF7dYM6GgA=="], + + "@aws-sdk/types": ["@aws-sdk/types@3.973.7", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-reXRwoJ6CfChoqAsBszUYajAF8Z2LRE+CRcKocvFSMpIiLOtYU3aJ9trmn6VVPAzbbY5LXF+FfmUslbXk1SYFg=="], + + "@aws-sdk/util-arn-parser": ["@aws-sdk/util-arn-parser@3.972.3", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-HzSD8PMFrvgi2Kserxuff5VitNq2sgf3w9qxmskKDiDTThWfVteJxuCS9JXiPIPtmCrp+7N9asfIaVhBFORllA=="], + + "@aws-sdk/util-endpoints": ["@aws-sdk/util-endpoints@3.996.6", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "@smithy/util-endpoints": "^3.3.4", "tslib": "^2.6.2" } }, "sha512-2nUQ+2ih7CShuKHpGSIYvvAIOHy52dOZguYG36zptBukhw6iFwcvGfG0tes0oZFWQqEWvgZe9HLWaNlvXGdOrg=="], + + "@aws-sdk/util-locate-window": ["@aws-sdk/util-locate-window@3.965.5", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-WhlJNNINQB+9qtLtZJcpQdgZw3SCDCpXdUJP7cToGwHbCWCnRckGlc6Bx/OhWwIYFNAn+FIydY8SZ0QmVu3xTQ=="], + + "@aws-sdk/util-user-agent-browser": ["@aws-sdk/util-user-agent-browser@3.972.9", "", { "dependencies": { "@aws-sdk/types": "^3.973.7", "@smithy/types": "^4.14.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-sn/LMzTbGjYqCCF24390WxPd6hkpoSptiUn5DzVp4cD71yqw+yGEGm1YCxyEoPXyc8qciM8UzLJcZBFslxo5Uw=="], + + "@aws-sdk/util-user-agent-node": ["@aws-sdk/util-user-agent-node@3.973.15", "", { "dependencies": { "@aws-sdk/middleware-user-agent": "^3.972.29", "@aws-sdk/types": "^3.973.7", "@smithy/node-config-provider": "^4.3.13", "@smithy/types": "^4.14.0", "@smithy/util-config-provider": "^4.2.2", "tslib": "^2.6.2" }, "peerDependencies": { "aws-crt": ">=1.0.0" }, "optionalPeers": ["aws-crt"] }, "sha512-fYn3s9PtKdgQkczGZCFMgkNEe8aq1JCVbnRqjqN9RSVW43xn2RV9xdcZ3z01a48Jpkuh/xCmBKJxdLOo4Ozg7w=="], + + "@aws-sdk/xml-builder": ["@aws-sdk/xml-builder@3.972.17", "", { "dependencies": { "@smithy/types": "^4.14.0", "fast-xml-parser": "5.5.8", "tslib": "^2.6.2" } }, "sha512-Ra7hjqAZf1OXRRMueB13qex7mFJRDK/pgCvdSFemXBT8KCGnQDPoKzHY1SjN+TjJVmnpSF14W5tJ1vDamFu+Gg=="], + + "@aws/lambda-invoke-store": ["@aws/lambda-invoke-store@0.2.4", "", {}, "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ=="], + "@hono/node-server": ["@hono/node-server@1.19.12", "", { "peerDependencies": { "hono": "^4" } }, "sha512-txsUW4SQ1iilgE0l9/e9VQWmELXifEFvmdA1j6WFh/aFPj99hIntrSsq/if0UWyGVkmrRPKA1wCeP+UCr1B9Uw=="], "@modelcontextprotocol/sdk": ["@modelcontextprotocol/sdk@1.29.0", "", { "dependencies": { "@hono/node-server": "^1.19.9", "ajv": "^8.17.1", "ajv-formats": "^3.0.1", "content-type": "^1.0.5", "cors": "^2.8.5", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", "eventsource-parser": "^3.0.0", "express": "^5.2.1", "express-rate-limit": "^8.2.1", "hono": "^4.11.4", "jose": "^6.1.3", "json-schema-typed": "^8.0.2", "pkce-challenge": "^5.0.0", "raw-body": "^3.0.0", "zod": "^3.25 || ^4.0", "zod-to-json-schema": "^3.25.1" }, "peerDependencies": { "@cfworker/json-schema": "^4.1.1" }, "optionalPeers": ["@cfworker/json-schema"] }, "sha512-zo37mZA9hJWpULgkRpowewez1y6ML5GsXJPY8FI0tBBCd77HEvza4jDqRKOXgHNn867PVGCyTdzqpz0izu5ZjQ=="], + "@smithy/chunked-blob-reader": ["@smithy/chunked-blob-reader@5.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-St+kVicSyayWQca+I1rGitaOEH6uKgE8IUWoYnnEX26SWdWQcL6LvMSD19Lg+vYHKdT9B2Zuu7rd3i6Wnyb/iw=="], + + "@smithy/chunked-blob-reader-native": ["@smithy/chunked-blob-reader-native@4.2.3", "", { "dependencies": { "@smithy/util-base64": "^4.3.2", "tslib": "^2.6.2" } }, "sha512-jA5k5Udn7Y5717L86h4EIv06wIr3xn8GM1qHRi/Nf31annXcXHJjBKvgztnbn2TxH3xWrPBfgwHsOwZf0UmQWw=="], + + "@smithy/config-resolver": ["@smithy/config-resolver@4.4.14", "", { "dependencies": { "@smithy/node-config-provider": "^4.3.13", "@smithy/types": "^4.14.0", "@smithy/util-config-provider": "^4.2.2", "@smithy/util-endpoints": "^3.3.4", "@smithy/util-middleware": "^4.2.13", "tslib": "^2.6.2" } }, "sha512-N55f8mPEccpzKetUagdvmAy8oohf0J5cuj9jLI1TaSceRlq0pJsIZepY3kmAXAhyxqXPV6hDerDQhqQPKWgAoQ=="], + + "@smithy/core": ["@smithy/core@3.23.14", "", { "dependencies": { "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-middleware": "^4.2.13", "@smithy/util-stream": "^4.5.22", "@smithy/util-utf8": "^4.2.2", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" } }, "sha512-vJ0IhpZxZAkFYOegMKSrxw7ujhhT2pass/1UEcZ4kfl5srTAqtPU5I7MdYQoreVas3204ykCiNhY1o7Xlz6Yyg=="], + + "@smithy/credential-provider-imds": ["@smithy/credential-provider-imds@4.2.13", "", { "dependencies": { "@smithy/node-config-provider": "^4.3.13", "@smithy/property-provider": "^4.2.13", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "tslib": "^2.6.2" } }, "sha512-wboCPijzf6RJKLOvnjDAiBxGSmSnGXj35o5ZAWKDaHa/cvQ5U3ZJ13D4tMCE8JG4dxVAZFy/P0x/V9CwwdfULQ=="], + + "@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.13", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.14.0", "@smithy/util-hex-encoding": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-vYahwBAtRaAcFbOmE9aLr12z7RiHYDSLcnogSdxfm7kKfsNa3wH+NU5r7vTeB5rKvLsWyPjVX8iH94brP7umiQ=="], + + "@smithy/eventstream-serde-browser": ["@smithy/eventstream-serde-browser@4.2.13", "", { "dependencies": { "@smithy/eventstream-serde-universal": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-wwybfcOX0tLqCcBP378TIU9IqrDuZq/tDV48LlZNydMpCnqnYr+hWBAYbRE+rFFf/p7IkDJySM3bgiMKP2ihPg=="], + + "@smithy/eventstream-serde-config-resolver": ["@smithy/eventstream-serde-config-resolver@4.3.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-ied1lO559PtAsMJzg2TKRlctLnEi1PfkNeMMpdwXDImk1zV9uvS/Oxoy/vcy9uv1GKZAjDAB5xT6ziE9fzm5wA=="], + + "@smithy/eventstream-serde-node": ["@smithy/eventstream-serde-node@4.2.13", "", { "dependencies": { "@smithy/eventstream-serde-universal": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-hFyK+ORJrxAN3RYoaD6+gsGDQjeix8HOEkosoajvXYZ4VeqonM3G4jd9IIRm/sWGXUKmudkY9KdYjzosUqdM8A=="], + + "@smithy/eventstream-serde-universal": ["@smithy/eventstream-serde-universal@4.2.13", "", { "dependencies": { "@smithy/eventstream-codec": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-kRrq4EKLGeOxhC2CBEhRNcu1KSzNJzYY7RK3S7CxMPgB5dRrv55WqQOtRwQxQLC04xqORFLUgnDlc6xrNUULaA=="], + + "@smithy/fetch-http-handler": ["@smithy/fetch-http-handler@5.3.16", "", { "dependencies": { "@smithy/protocol-http": "^5.3.13", "@smithy/querystring-builder": "^4.2.13", "@smithy/types": "^4.14.0", "@smithy/util-base64": "^4.3.2", "tslib": "^2.6.2" } }, "sha512-nYDRUIvNd4mFmuXraRWt6w5UsZTNqtj4hXJA/iiOD4tuseIdLP9Lq38teH/SZTcIFCa2f+27o7hYpIsWktJKEQ=="], + + "@smithy/hash-blob-browser": ["@smithy/hash-blob-browser@4.2.14", "", { "dependencies": { "@smithy/chunked-blob-reader": "^5.2.2", "@smithy/chunked-blob-reader-native": "^4.2.3", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-rtQ5es8r/5v4rav7q5QTsfx9CtCyzrz/g7ZZZBH2xtMmd6G/KQrLOWfSHTvFOUPlVy59RQvxeBYJaLRoybMEyA=="], + + "@smithy/hash-node": ["@smithy/hash-node@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-4/oy9h0jjmY80a2gOIo75iLl8TOPhmtx4E2Hz+PfMjvx/vLtGY4TMU/35WRyH2JHPfT5CVB38u4JRow7gnmzJA=="], + + "@smithy/hash-stream-node": ["@smithy/hash-stream-node@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-WdQ7HwUjINXETeh6dqUeob1UHIYx8kAn9PSp1HhM2WWegiZBYVy2WXIs1lB07SZLan/udys9SBnQGt9MQbDpdg=="], + + "@smithy/invalid-dependency": ["@smithy/invalid-dependency@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-jvC0RB/8BLj2SMIkY0Npl425IdnxZJxInpZJbu563zIRnVjpDMXevU3VMCRSabaLB0kf/eFIOusdGstrLJ8IDg=="], + + "@smithy/is-array-buffer": ["@smithy/is-array-buffer@4.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-n6rQ4N8Jj4YTQO3YFrlgZuwKodf4zUFs7EJIWH86pSCWBaAtAGBFfCM7Wx6D2bBJ2xqFNxGBSrUWswT3M0VJow=="], + + "@smithy/md5-js": ["@smithy/md5-js@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-cNm7I9NXolFxtS20ojROddOEpSAeI1Obq6pd1Kj5HtHws3s9Fkk8DdHDfQSs5KuxCewZuVK6UqrJnfJmiMzDuQ=="], + + "@smithy/middleware-content-length": ["@smithy/middleware-content-length@4.2.13", "", { "dependencies": { "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-IPMLm/LE4AZwu6qiE8Rr8vJsWhs9AtOdySRXrOM7xnvclp77Tyh7hMs/FRrMf26kgIe67vFJXXOSmVxS7oKeig=="], + + "@smithy/middleware-endpoint": ["@smithy/middleware-endpoint@4.4.29", "", { "dependencies": { "@smithy/core": "^3.23.14", "@smithy/middleware-serde": "^4.2.17", "@smithy/node-config-provider": "^4.3.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "@smithy/url-parser": "^4.2.13", "@smithy/util-middleware": "^4.2.13", "tslib": "^2.6.2" } }, "sha512-R9Q/58U+qBiSARGWbAbFLczECg/RmysRksX6Q8BaQEpt75I7LI6WGDZnjuC9GXSGKljEbA7N118LhGaMbfrTXw=="], + + "@smithy/middleware-retry": ["@smithy/middleware-retry@4.5.1", "", { "dependencies": { "@smithy/core": "^3.23.14", "@smithy/node-config-provider": "^4.3.13", "@smithy/protocol-http": "^5.3.13", "@smithy/service-error-classification": "^4.2.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "@smithy/util-middleware": "^4.2.13", "@smithy/util-retry": "^4.3.1", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" } }, "sha512-/zY+Gp7Qj2D2hVm3irkCyONER7E9MiX3cUUm/k2ZmhkzZkrPgwVS4aJ5NriZUEN/M0D1hhjrgjUmX04HhRwdWA=="], + + "@smithy/middleware-serde": ["@smithy/middleware-serde@4.2.17", "", { "dependencies": { "@smithy/core": "^3.23.14", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-0T2mcaM6v9W1xku86Dk0bEW7aEseG6KenFkPK98XNw0ZhOqOiD1MrMsdnQw9QsL3/Oa85T53iSMlm0SZdSuIEQ=="], + + "@smithy/middleware-stack": ["@smithy/middleware-stack@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-g72jN/sGDLyTanrCLH9fhg3oysO3f7tQa6eWWsMyn2BiYNCgjF24n4/I9wff/5XidFvjj9ilipAoQrurTUrLvw=="], + + "@smithy/node-config-provider": ["@smithy/node-config-provider@4.3.13", "", { "dependencies": { "@smithy/property-provider": "^4.2.13", "@smithy/shared-ini-file-loader": "^4.4.8", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-iGxQ04DsKXLckbgnX4ipElrOTk+IHgTyu0q0WssZfYhDm9CQWHmu6cOeI5wmWRxpXbBDhIIfXMWz5tPEtcVqbw=="], + + "@smithy/node-http-handler": ["@smithy/node-http-handler@4.5.2", "", { "dependencies": { "@smithy/protocol-http": "^5.3.13", "@smithy/querystring-builder": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-/oD7u8M0oj2ZTFw7GkuuHWpIxtWdLlnyNkbrWcyVYhd5RJNDuczdkb0wfnQICyNFrVPlr8YHOhamjNy3zidhmA=="], + + "@smithy/property-provider": ["@smithy/property-provider@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-bGzUCthxRmezuxkbu9wD33wWg9KX3hJpCXpQ93vVkPrHn9ZW6KNNdY5xAUWNuRCwQ+VyboFuWirG1lZhhkcyRQ=="], + + "@smithy/protocol-http": ["@smithy/protocol-http@5.3.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-+HsmuJUF4u8POo6s8/a2Yb/AQ5t/YgLovCuHF9oxbocqv+SZ6gd8lC2duBFiCA/vFHoHQhoq7QjqJqZC6xOxxg=="], + + "@smithy/querystring-builder": ["@smithy/querystring-builder@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "@smithy/util-uri-escape": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-tG4aOYFCZdPMjbgfhnIQ322H//ojujldp1SrHPHpBSb3NqgUp3dwiUGRJzie87hS1DYwWGqDuPaowoDF+rYCbQ=="], + + "@smithy/querystring-parser": ["@smithy/querystring-parser@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-hqW3Q4P+CDzUyQ87GrboGMeD7XYNMOF+CuTwu936UQRB/zeYn3jys8C3w+wMkDfY7CyyyVwZQ5cNFoG0x1pYmA=="], + + "@smithy/service-error-classification": ["@smithy/service-error-classification@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0" } }, "sha512-a0s8XZMfOC/qpqq7RCPvJlk93rWFrElH6O++8WJKz0FqnA4Y7fkNi/0mnGgSH1C4x6MFsuBA8VKu4zxFrMe5Vw=="], + + "@smithy/shared-ini-file-loader": ["@smithy/shared-ini-file-loader@4.4.8", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-VZCZx2bZasxdqxVgEAhREvDSlkatTPnkdWy1+Kiy8w7kYPBosW0V5IeDwzDUMvWBt56zpK658rx1cOBFOYaPaw=="], + + "@smithy/signature-v4": ["@smithy/signature-v4@5.3.13", "", { "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-middleware": "^4.2.13", "@smithy/util-uri-escape": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-YpYSyM0vMDwKbHD/JA7bVOF6kToVRpa+FM5ateEVRpsTNu564g1muBlkTubXhSKKYXInhpADF46FPyrZcTLpXg=="], + + "@smithy/smithy-client": ["@smithy/smithy-client@4.12.9", "", { "dependencies": { "@smithy/core": "^3.23.14", "@smithy/middleware-endpoint": "^4.4.29", "@smithy/middleware-stack": "^4.2.13", "@smithy/protocol-http": "^5.3.13", "@smithy/types": "^4.14.0", "@smithy/util-stream": "^4.5.22", "tslib": "^2.6.2" } }, "sha512-ovaLEcTU5olSeHcRXcxV6viaKtpkHZumn6Ps0yn7dRf2rRSfy794vpjOtrWDO0d1auDSvAqxO+lyhERSXQ03EQ=="], + + "@smithy/types": ["@smithy/types@4.14.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-OWgntFLW88kx2qvf/c/67Vno1yuXm/f9M7QFAtVkkO29IJXGBIg0ycEaBTH0kvCtwmvZxRujrgP5a86RvsXJAQ=="], + + "@smithy/url-parser": ["@smithy/url-parser@4.2.13", "", { "dependencies": { "@smithy/querystring-parser": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-2G03yoboIRZlZze2+PT4GZEjgwQsJjUgn6iTsvxA02bVceHR6vp4Cuk7TUnPFWKF+ffNUk3kj4COwkENS2K3vw=="], + + "@smithy/util-base64": ["@smithy/util-base64@4.3.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-XRH6b0H/5A3SgblmMa5ErXQ2XKhfbQB+Fm/oyLZ2O2kCUrwgg55bU0RekmzAhuwOjA9qdN5VU2BprOvGGUkOOQ=="], + + "@smithy/util-body-length-browser": ["@smithy/util-body-length-browser@4.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-JKCrLNOup3OOgmzeaKQwi4ZCTWlYR5H4Gm1r2uTMVBXoemo1UEghk5vtMi1xSu2ymgKVGW631e2fp9/R610ZjQ=="], + + "@smithy/util-body-length-node": ["@smithy/util-body-length-node@4.2.3", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-ZkJGvqBzMHVHE7r/hcuCxlTY8pQr1kMtdsVPs7ex4mMU+EAbcXppfo5NmyxMYi2XU49eqaz56j2gsk4dHHPG/g=="], + + "@smithy/util-buffer-from": ["@smithy/util-buffer-from@4.2.2", "", { "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-FDXD7cvUoFWwN6vtQfEta540Y/YBe5JneK3SoZg9bThSoOAC/eGeYEua6RkBgKjGa/sz6Y+DuBZj3+YEY21y4Q=="], + + "@smithy/util-config-provider": ["@smithy/util-config-provider@4.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-dWU03V3XUprJwaUIFVv4iOnS1FC9HnMHDfUrlNDSh4315v0cWyaIErP8KiqGVbf5z+JupoVpNM7ZB3jFiTejvQ=="], + + "@smithy/util-defaults-mode-browser": ["@smithy/util-defaults-mode-browser@4.3.45", "", { "dependencies": { "@smithy/property-provider": "^4.2.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-ag9sWc6/nWZAuK3Wm9KlFJUnRkXLrXn33RFjIAmCTFThqLHY+7wCst10BGq56FxslsDrjhSie46c8OULS+BiIw=="], + + "@smithy/util-defaults-mode-node": ["@smithy/util-defaults-mode-node@4.2.49", "", { "dependencies": { "@smithy/config-resolver": "^4.4.14", "@smithy/credential-provider-imds": "^4.2.13", "@smithy/node-config-provider": "^4.3.13", "@smithy/property-provider": "^4.2.13", "@smithy/smithy-client": "^4.12.9", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-jlN6vHwE8gY5AfiFBavtD3QtCX2f7lM3BKkz7nFKSNfFR5nXLXLg6sqXTJEEyDwtxbztIDBQCfjsGVXlIru2lQ=="], + + "@smithy/util-endpoints": ["@smithy/util-endpoints@3.3.4", "", { "dependencies": { "@smithy/node-config-provider": "^4.3.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-BKoR/ubPp9KNKFxPpg1J28N1+bgu8NGAtJblBP7yHy8yQPBWhIAv9+l92SlQLpolGm71CVO+btB60gTgzT0wog=="], + + "@smithy/util-hex-encoding": ["@smithy/util-hex-encoding@4.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-Qcz3W5vuHK4sLQdyT93k/rfrUwdJ8/HZ+nMUOyGdpeGA1Wxt65zYwi3oEl9kOM+RswvYq90fzkNDahPS8K0OIg=="], + + "@smithy/util-middleware": ["@smithy/util-middleware@4.2.13", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-GTooyrlmRTqvUen4eK7/K1p6kryF7bnDfq6XsAbIsf2mo51B/utaH+XThY6dKgNCWzMAaH/+OLmqaBuLhLWRow=="], + + "@smithy/util-retry": ["@smithy/util-retry@4.3.1", "", { "dependencies": { "@smithy/service-error-classification": "^4.2.13", "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-FwmicpgWOkP5kZUjN3y+3JIom8NLGqSAJBeoIgK0rIToI817TEBHCrd0A2qGeKQlgDeP+Jzn4i0H/NLAXGy9uQ=="], + + "@smithy/util-stream": ["@smithy/util-stream@4.5.22", "", { "dependencies": { "@smithy/fetch-http-handler": "^5.3.16", "@smithy/node-http-handler": "^4.5.2", "@smithy/types": "^4.14.0", "@smithy/util-base64": "^4.3.2", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-3H8iq/0BfQjUs2/4fbHZ9aG9yNzcuZs24LPkcX1Q7Z+qpqaGM8+qbGmE8zo9m2nCRgamyvS98cHdcWvR6YUsew=="], + + "@smithy/util-uri-escape": ["@smithy/util-uri-escape@4.2.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-2kAStBlvq+lTXHyAZYfJRb/DfS3rsinLiwb+69SstC9Vb0s9vNWkRwpnj918Pfi85mzi42sOqdV72OLxWAISnw=="], + + "@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], + + "@smithy/util-waiter": ["@smithy/util-waiter@4.2.15", "", { "dependencies": { "@smithy/types": "^4.14.0", "tslib": "^2.6.2" } }, "sha512-oUt9o7n8hBv3BL56sLSneL0XeigZSuem0Hr78JaoK33D9oKieyCvVP8eTSe3j7g2mm/S1DvzxKieG7JEWNJUNg=="], + + "@smithy/uuid": ["@smithy/uuid@1.1.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-O/IEdcCUKkubz60tFbGA7ceITTAJsty+lBjNoorP4Z6XRqaFb/OjQjZODophEcuq68nKm6/0r+6/lLQ+XVpk8g=="], + "@types/bun": ["@types/bun@1.3.11", "", { "dependencies": { "bun-types": "1.3.11" } }, "sha512-5vPne5QvtpjGpsGYXiFyycfpDF2ECyPcTSsFBMa0fraoxiQyMJ3SmuQIGhzPg2WJuWxVBoxWJ2kClYTcw/4fAg=="], "@types/node": ["@types/node@18.19.130", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg=="], @@ -46,6 +227,8 @@ "body-parser": ["body-parser@2.2.2", "", { "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", "debug": "^4.4.3", "http-errors": "^2.0.0", "iconv-lite": "^0.7.0", "on-finished": "^2.4.1", "qs": "^6.14.1", "raw-body": "^3.0.1", "type-is": "^2.0.1" } }, "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA=="], + "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "bun-types": ["bun-types@1.3.11", "", { "dependencies": { "@types/node": "*" } }, "sha512-1KGPpoxQWl9f6wcZh57LvrPIInQMn2TQ7jsgxqpRzg+l0QPOFvJVH7HmvHo/AiPgwXy+/Thf6Ov3EdVn1vOabg=="], "bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="], @@ -110,6 +293,10 @@ "fast-uri": ["fast-uri@3.1.0", "", {}, "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA=="], + "fast-xml-builder": ["fast-xml-builder@1.1.4", "", { "dependencies": { "path-expression-matcher": "^1.1.3" } }, "sha512-f2jhpN4Eccy0/Uz9csxh3Nu6q4ErKxf0XIsasomfOihuSUa3/xw6w8dnOtCDgEItQFJG8KyXPzQXzcODDrrbOg=="], + + "fast-xml-parser": ["fast-xml-parser@5.5.8", "", { "dependencies": { "fast-xml-builder": "^1.1.4", "path-expression-matcher": "^1.2.0", "strnum": "^2.2.0" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-Z7Fh2nVQSb2d+poDViM063ix2ZGt9jmY1nWhPfHBOK2Hgnb/OW3P4Et3P/81SEej0J7QbWtJqxO05h8QYfK7LQ=="], + "finalhandler": ["finalhandler@2.1.1", "", { "dependencies": { "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "on-finished": "^2.4.1", "parseurl": "^1.3.3", "statuses": "^2.0.1" } }, "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA=="], "form-data": ["form-data@4.0.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w=="], @@ -198,6 +385,8 @@ "parseurl": ["parseurl@1.3.3", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="], + "path-expression-matcher": ["path-expression-matcher@1.5.0", "", {}, "sha512-cbrerZV+6rvdQrrD+iGMcZFEiiSrbv9Tfdkvnusy6y0x0GKBXREFg/Y65GhIfm0tnLntThhzCnfKwp1WRjeCyQ=="], + "path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="], "path-to-regexp": ["path-to-regexp@8.4.2", "", {}, "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA=="], @@ -248,10 +437,14 @@ "strip-bom-string": ["strip-bom-string@1.0.0", "", {}, "sha512-uCC2VHvQRYu+lMh4My/sFNmF2klFymLX1wHJeXnbEJERpV/ZsVuonzerjfrGpIGF7LBVa1O7i9kjiWvJiFck8g=="], + "strnum": ["strnum@2.2.3", "", {}, "sha512-oKx6RUCuHfT3oyVjtnrmn19H1SiCqgJSg+54XqURKp5aCMbrXrhLjRN9TjuwMjiYstZ0MzDrHqkGZ5dFTKd+zg=="], + "toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="], "tr46": ["tr46@0.0.3", "", {}, "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="], + "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], + "type-is": ["type-is@2.0.1", "", { "dependencies": { "content-type": "^1.0.5", "media-typer": "^1.1.0", "mime-types": "^3.0.0" } }, "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw=="], "undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="], @@ -274,16 +467,34 @@ "zod-to-json-schema": ["zod-to-json-schema@3.25.2", "", { "peerDependencies": { "zod": "^3.25.28 || ^4" } }, "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA=="], + "@aws-crypto/sha1-browser/@smithy/util-utf8": ["@smithy/util-utf8@2.3.0", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="], + + "@aws-crypto/sha256-browser/@smithy/util-utf8": ["@smithy/util-utf8@2.3.0", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="], + + "@aws-crypto/util/@smithy/util-utf8": ["@smithy/util-utf8@2.3.0", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="], + "@types/node-fetch/@types/node": ["@types/node@25.5.2", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-tO4ZIRKNC+MDWV4qKVZe3Ql/woTnmHDr5JD8UI5hn2pwBrHEwOEMZK7WlNb5RKB6EoJ02gwmQS9OrjuFnZYdpg=="], "bun-types/@types/node": ["@types/node@25.5.2", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-tO4ZIRKNC+MDWV4qKVZe3Ql/woTnmHDr5JD8UI5hn2pwBrHEwOEMZK7WlNb5RKB6EoJ02gwmQS9OrjuFnZYdpg=="], "form-data/mime-types": ["mime-types@2.1.35", "", { "dependencies": { "mime-db": "1.52.0" } }, "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw=="], + "@aws-crypto/sha1-browser/@smithy/util-utf8/@smithy/util-buffer-from": ["@smithy/util-buffer-from@2.2.0", "", { "dependencies": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA=="], + + "@aws-crypto/sha256-browser/@smithy/util-utf8/@smithy/util-buffer-from": ["@smithy/util-buffer-from@2.2.0", "", { "dependencies": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA=="], + + "@aws-crypto/util/@smithy/util-utf8/@smithy/util-buffer-from": ["@smithy/util-buffer-from@2.2.0", "", { "dependencies": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA=="], + "@types/node-fetch/@types/node/undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], "bun-types/@types/node/undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], "form-data/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="], + + "@aws-crypto/sha1-browser/@smithy/util-utf8/@smithy/util-buffer-from/@smithy/is-array-buffer": ["@smithy/is-array-buffer@2.2.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA=="], + + "@aws-crypto/sha256-browser/@smithy/util-utf8/@smithy/util-buffer-from/@smithy/is-array-buffer": ["@smithy/is-array-buffer@2.2.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA=="], + + "@aws-crypto/util/@smithy/util-utf8/@smithy/util-buffer-from/@smithy/is-array-buffer": ["@smithy/is-array-buffer@2.2.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA=="], } } diff --git a/docs/mcp/ALTERNATIVES.md b/docs/mcp/ALTERNATIVES.md new file mode 100644 index 000000000..a889176d9 --- /dev/null +++ b/docs/mcp/ALTERNATIVES.md @@ -0,0 +1,54 @@ +# Alternative: Self-Hosted MCP Server + +If you prefer running GBrain on your own machine instead of Supabase Edge Functions, you can expose `gbrain serve --http` via a tunnel. + +## Tailscale Funnel + +[Tailscale Funnel](https://tailscale.com/kb/1223/tailscale-funnel) gives you a permanent public HTTPS URL with automatic TLS. Free tier available. + +```bash +# 1. Install Tailscale +brew install tailscale + +# 2. Start gbrain with HTTP transport (when available) +gbrain serve --http 3000 + +# 3. Expose via Funnel +tailscale funnel 3000 +# Your brain is now at https://your-machine.ts.net +``` + +Pros: zero deployment, no Deno bundling, no cold start, no timeout limits. +Cons: requires your machine to be running and connected. + +## ngrok + +[ngrok](https://ngrok.com) provides temporary or persistent tunnels. + +```bash +# 1. Install ngrok +brew install ngrok + +# 2. Start gbrain with HTTP transport +gbrain serve --http 3000 + +# 3. Expose via ngrok +ngrok http 3000 +# Use the generated URL in your MCP client config +``` + +Pros: quick setup, works behind firewalls. +Cons: free tier URLs change on restart (paid tier for persistent URLs), requires running process. + +## When to use alternatives vs Edge Functions + +| | Edge Functions | Tailscale/ngrok | +|--|---|---| +| Works when laptop is off | Yes | No | +| Zero cold start | No (~300ms) | Yes | +| No timeout limits | No (60s) | Yes | +| sync_brain remotely | No | Yes | +| file_upload remotely | No | Yes | +| Extra accounts needed | None | Tailscale or ngrok | + +Note: `gbrain serve --http` is planned but not yet implemented. Currently only stdio transport is available via `gbrain serve`. diff --git a/docs/mcp/CHATGPT.md b/docs/mcp/CHATGPT.md new file mode 100644 index 000000000..83a5fba9c --- /dev/null +++ b/docs/mcp/CHATGPT.md @@ -0,0 +1,25 @@ +# Connect GBrain to ChatGPT + +**Status: Coming Soon** + +ChatGPT requires OAuth 2.1 with Dynamic Client Registration for MCP connectors. Bearer token authentication is not supported by ChatGPT's MCP integration. + +This is tracked as a P0 priority for GBrain v0.7. + +## What's needed + +- OAuth 2.1 authorization endpoint on the Edge Function +- Token endpoint with PKCE flow +- Dynamic Client Registration support +- ChatGPT Developer Mode (available on Pro/Team/Enterprise/Edu plans) + +## Workaround + +Until OAuth support ships, you can use GBrain with ChatGPT via a bridge: + +1. Run `gbrain serve` locally +2. Use a tool like [mcp-remote](https://github.com/nichochar/mcp-remote) to bridge stdio to HTTP with OAuth support + +## Timeline + +Follow [Issue #22](https://github.com/garrytan/gbrain/issues/22) for updates on ChatGPT OAuth support. diff --git a/docs/mcp/CLAUDE_CODE.md b/docs/mcp/CLAUDE_CODE.md new file mode 100644 index 000000000..9c904415c --- /dev/null +++ b/docs/mcp/CLAUDE_CODE.md @@ -0,0 +1,27 @@ +# Connect GBrain to Claude Code + +## Setup + +```bash +claude mcp add gbrain -t http \ + https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp \ + -H "Authorization: Bearer YOUR_TOKEN" +``` + +Replace `YOUR_REF` with your Supabase project ref and `YOUR_TOKEN` with a token from `bun run src/commands/auth.ts create "claude-code"`. + +## Verify + +In Claude Code, try: + +``` +search for [any topic in your brain] +``` + +You should see results from your GBrain knowledge base. + +## Remove + +```bash +claude mcp remove gbrain +``` diff --git a/docs/mcp/CLAUDE_COWORK.md b/docs/mcp/CLAUDE_COWORK.md new file mode 100644 index 000000000..18488e47f --- /dev/null +++ b/docs/mcp/CLAUDE_COWORK.md @@ -0,0 +1,28 @@ +# Connect GBrain to Claude Cowork + +Two ways to get GBrain into Cowork sessions: + +## Option 1: Remote (via Edge Function) + +For Team/Enterprise plans, an org Owner adds the connector: + +1. Go to **Organization Settings > Connectors** +2. Add a new connector with the MCP server URL: + ``` + https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp + ``` +3. Optionally add Bearer token authentication in Advanced Settings +4. Save + +Note: Cowork connects from Anthropic's cloud, not your device. The Edge Function is already publicly reachable via Supabase. + +## Option 2: Local Bridge (via Claude Desktop) + +If you already have GBrain configured in Claude Desktop (either via `gbrain serve` stdio or the remote MCP integration), Cowork gets access automatically. Claude Desktop bridges local MCP servers into Cowork via its SDK layer. + +This means: if `gbrain serve` is running and configured in Claude Desktop, you don't need the Edge Function for Cowork at all. + +## Which to use? + +- **Remote Edge Function:** works even when your laptop is closed, available to all org members +- **Local Bridge:** zero extra setup if Claude Desktop already has GBrain, but requires your machine to be running diff --git a/docs/mcp/CLAUDE_DESKTOP.md b/docs/mcp/CLAUDE_DESKTOP.md new file mode 100644 index 000000000..da07f374b --- /dev/null +++ b/docs/mcp/CLAUDE_DESKTOP.md @@ -0,0 +1,31 @@ +# Connect GBrain to Claude Desktop + +**Important:** Claude Desktop does NOT connect to remote MCP servers via `claude_desktop_config.json`. That file only works for local stdio servers. Remote HTTP servers must be added through the GUI. + +## Setup + +1. Open Claude Desktop +2. Go to **Settings > Integrations** +3. Click **Add Integration** (or **Add Connector**) +4. Enter the MCP server URL: + ``` + https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp + ``` +5. Set authentication to **Bearer Token** and paste your token +6. Save + +## Verify + +Start a new conversation and try: + +``` +Search my brain for [any topic] +``` + +Claude Desktop will use your GBrain tools automatically. + +## Common Mistakes + +**Using claude_desktop_config.json for remote servers** — this silently fails. The JSON config only works for local stdio MCP servers. Remote HTTP servers must be added via Settings > Integrations. + +**Using the wrong URL** — make sure the URL ends with `/mcp` (not `/health` or just the function name). diff --git a/docs/mcp/DEPLOY.md b/docs/mcp/DEPLOY.md new file mode 100644 index 000000000..28c536d41 --- /dev/null +++ b/docs/mcp/DEPLOY.md @@ -0,0 +1,102 @@ +# Deploy GBrain Remote MCP Server + +Deploy your personal knowledge brain as a serverless MCP endpoint on your existing Supabase instance. Works with Claude Desktop, Claude Code, Cowork, and Perplexity Computer. + +## Prerequisites + +- GBrain already set up (`gbrain init` completed, data imported) +- [Supabase CLI](https://supabase.com/docs/guides/cli) installed +- Your Supabase project ref (the `xxx` from `https://xxx.supabase.co`) + +## Quick Start + +```bash +# 1. Fill in your config +cp .env.production.example .env.production +# Edit .env.production with your DATABASE_URL, OPENAI_API_KEY, SUPABASE_PROJECT_REF + +# 2. Deploy (one command) +bash scripts/deploy-remote.sh + +# 3. Create an access token +DATABASE_URL=$DATABASE_URL bun run src/commands/auth.ts create "my-client" +# Save the token — it's shown once + +# 4. Test it +bun run src/commands/auth.ts test \ + https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp \ + --token YOUR_TOKEN +``` + +## Authentication + +GBrain uses bearer tokens stored in your database (SHA-256 hashed). Each token has a name for identification. + +```bash +# Create a token +bun run src/commands/auth.ts create "claude-desktop" + +# List all tokens +bun run src/commands/auth.ts list + +# Revoke a token +bun run src/commands/auth.ts revoke "claude-desktop" +``` + +Tokens are per-client. Create one for each device/app. Revoke individually if compromised. + +## Updating + +When you update GBrain (new operations, bug fixes): + +```bash +git pull +bash scripts/deploy-remote.sh +``` + +Your tokens survive upgrades. Check your deployed version: + +```bash +curl https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/health +``` + +## Operations + +All 28 GBrain operations are available remotely except: +- `sync_brain` (may exceed 60s Edge Function timeout) +- `file_upload` (may exceed 60s timeout with large files) + +These remain CLI-only via `gbrain serve` (stdio). + +## Troubleshooting + +**"supabase: command not found"** +Install: `brew install supabase/tap/supabase` or `npm install -g supabase` + +**Edge Function deploys but returns 500** +Check that OPENAI_API_KEY is set: `supabase secrets list` + +**"missing_auth" error** +Include the Authorization header: `Authorization: Bearer YOUR_TOKEN` + +**"invalid_token" error** +Run `bun run src/commands/auth.ts list` to see active tokens. The token may have been revoked or mistyped. + +**"service_unavailable" error** +Database connection failed. Check your Supabase dashboard for outages or connection pool limits. + +**Claude Desktop doesn't connect** +Remote MCP servers must be added via Settings > Integrations, NOT claude_desktop_config.json. See [CLAUDE_DESKTOP.md](CLAUDE_DESKTOP.md). + +## Expected Latencies + +| Operation | Typical Latency | Notes | +|-----------|----------------|-------| +| get_page | < 100ms | Single DB query | +| list_pages | < 200ms | DB query with filters | +| search (keyword) | 100-300ms | Full-text search | +| query (hybrid) | 1-3s | Embedding + vector + keyword + RRF | +| put_page | 100-500ms | Write + trigger search_vector update | +| get_stats | < 100ms | Aggregate query | + +Cold start adds ~300-500ms on the first request after idle (Postgres connection setup via pgbouncer). diff --git a/docs/mcp/PERPLEXITY.md b/docs/mcp/PERPLEXITY.md new file mode 100644 index 000000000..5042e02f6 --- /dev/null +++ b/docs/mcp/PERPLEXITY.md @@ -0,0 +1,27 @@ +# Connect GBrain to Perplexity Computer + +Perplexity Computer supports remote MCP servers with bearer token authentication. + +## Setup + +1. Open Perplexity (requires Pro subscription) +2. Go to **Settings > Connectors** (or **MCP Servers**) +3. Add a new remote connector: + - **URL:** `https://YOUR_REF.supabase.co/functions/v1/gbrain-mcp/mcp` + - **Authentication:** API Key / Bearer Token + - **Token:** your GBrain access token +4. Save + +## Verify + +In a Perplexity conversation, ask it to use your brain: + +``` +Use my GBrain to search for [topic] +``` + +## Notes + +- Perplexity Computer is available to Pro subscribers +- Both the Perplexity Mac app and web version support MCP connectors +- The Mac app also supports local MCP servers if you prefer `gbrain serve` (stdio) diff --git a/package.json b/package.json index de0526a45..d16bc0611 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "dev": "bun run src/cli.ts", "build": "bun build --compile --outfile bin/gbrain src/cli.ts", "build:all": "bun build --compile --target=bun-darwin-arm64 --outfile bin/gbrain-darwin-arm64 src/cli.ts && bun build --compile --target=bun-linux-x64 --outfile bin/gbrain-linux-x64 src/cli.ts", + "build:schema": "bash scripts/build-schema.sh", + "build:edge": "bun run build:schema && bun build src/edge-entry.ts --format=esm --outfile=supabase/functions/gbrain-mcp/gbrain-core.js --external=postgres --external=openai --external=fs --external=os --external=path --external=crypto --external=child_process --external=@aws-sdk/client-s3 --external=@anthropic-ai/sdk --external=gray-matter --minify", "test": "bun test", "test:e2e": "bun test test/e2e/", "prepublish:clawhub": "bun run build:all", @@ -29,6 +31,7 @@ }, "dependencies": { "@anthropic-ai/sdk": "^0.30.0", + "@aws-sdk/client-s3": "^3.1028.0", "@modelcontextprotocol/sdk": "^1.0.0", "gray-matter": "^4.0.3", "openai": "^4.0.0", diff --git a/scripts/build-schema.sh b/scripts/build-schema.sh new file mode 100755 index 000000000..e6f66f7d4 --- /dev/null +++ b/scripts/build-schema.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Generate src/core/schema-embedded.ts from src/schema.sql +# One source of truth: schema.sql is the canonical file. +# This script produces a TypeScript constant for use in compiled binaries and Edge Functions. +set -e +SCHEMA_FILE="src/schema.sql" +OUT_FILE="src/core/schema-embedded.ts" +echo "// AUTO-GENERATED — do not edit. Run: bun run build:schema" > "$OUT_FILE" +echo "// Source: $SCHEMA_FILE" >> "$OUT_FILE" +echo "" >> "$OUT_FILE" +echo "export const SCHEMA_SQL = \`" >> "$OUT_FILE" +# Escape backticks and dollar signs in the SQL for template literal safety +sed 's/`/\\`/g; s/\$/\\$/g' "$SCHEMA_FILE" >> "$OUT_FILE" +echo "\`;" >> "$OUT_FILE" +echo "Generated $OUT_FILE from $SCHEMA_FILE" diff --git a/scripts/deploy-remote.sh b/scripts/deploy-remote.sh new file mode 100755 index 000000000..33ff39ad8 --- /dev/null +++ b/scripts/deploy-remote.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Deploy GBrain Remote MCP Server to Supabase Edge Functions. +# Prerequisites: .env.production filled in, supabase CLI installed. +set -e + +# Check supabase CLI +if ! command -v supabase >/dev/null 2>&1; then + echo "Error: supabase CLI not found." + echo "Install: brew install supabase/tap/supabase" + echo " or: npm install -g supabase" + exit 1 +fi + +# Load env +if [ ! -f .env.production ]; then + echo "Error: .env.production not found." + echo "Copy .env.production.example to .env.production and fill in your values." + exit 1 +fi +source .env.production + +if [ -z "$SUPABASE_PROJECT_REF" ]; then + echo "Error: SUPABASE_PROJECT_REF not set in .env.production" + exit 1 +fi + +echo "Deploying GBrain Remote MCP Server..." +echo " Project: $SUPABASE_PROJECT_REF" +echo "" + +# Link project +supabase link --project-ref "$SUPABASE_PROJECT_REF" + +# Set secrets +supabase secrets set OPENAI_API_KEY="$OPENAI_API_KEY" + +# Build the Edge Function bundle +echo "" +echo "Building Edge Function bundle..." +bun install +bun run build:edge +echo "" + +# Deploy +echo "Deploying Edge Function..." +supabase functions deploy gbrain-mcp --no-verify-jwt +echo "" + +# Print success +URL="https://${SUPABASE_PROJECT_REF}.supabase.co/functions/v1/gbrain-mcp/mcp" +echo "================================================" +echo " GBrain Remote MCP Server deployed!" +echo "================================================" +echo "" +echo " URL: $URL" +echo "" +echo " Next steps:" +echo " 1. Create a token:" +echo " DATABASE_URL=\$DATABASE_URL bun run src/commands/auth.ts create \"my-client\"" +echo "" +echo " 2. Test it:" +echo " bun run src/commands/auth.ts test $URL --token " +echo "" +echo " 3. Add to Claude Code:" +echo " claude mcp add gbrain -t http $URL -H \"Authorization: Bearer \"" +echo "" +echo " See docs/mcp/ for per-client setup guides." diff --git a/scripts/smoke-test-mcp.ts b/scripts/smoke-test-mcp.ts new file mode 100644 index 000000000..3d873b573 --- /dev/null +++ b/scripts/smoke-test-mcp.ts @@ -0,0 +1,96 @@ +#!/usr/bin/env bun +/** + * Smoke test: verify MCP tool calls work against a real database. + * Usage: DATABASE_URL=... bun run scripts/smoke-test-mcp.ts + */ +import { PostgresEngine } from '../src/core/postgres-engine.ts'; +import { handleToolCall } from '../src/mcp/server.ts'; + +const DB_URL = process.env.DATABASE_URL; +if (!DB_URL) { console.error('Set DATABASE_URL'); process.exit(1); } + +const eng = new PostgresEngine(); +await eng.connect({ database_url: DB_URL }); + +let passed = 0; +let failed = 0; + +async function test(name: string, fn: () => Promise) { + try { + await fn(); + console.log(` ✓ ${name}`); + passed++; + } catch (e: any) { + console.log(` ✗ ${name}: ${e.message}`); + failed++; + } +} + +console.log('MCP Smoke Test\n'); + +await test('get_stats returns counts', async () => { + const stats = await handleToolCall(eng, 'get_stats', {}) as any; + if (typeof stats.page_count !== 'number') throw new Error('page_count missing'); +}); + +await test('put_page creates a page', async () => { + await handleToolCall(eng, 'put_page', { + slug: 'smoke/test-page', + content: '---\ntitle: Smoke Test Page\ntype: note\n---\n\nThis page was created by the MCP smoke test.', + }); +}); + +await test('get_page retrieves the page', async () => { + const page = await handleToolCall(eng, 'get_page', { slug: 'smoke/test-page' }) as any; + if (page.title !== 'Smoke Test Page') throw new Error(`Wrong title: ${page.title}`); +}); + +await test('dry_run prevents mutation', async () => { + const result = await handleToolCall(eng, 'put_page', { + slug: 'smoke/should-not-exist', + content: '---\ntitle: Should Not Exist\ntype: note\n---\n\ndry run test', + dry_run: true, + }) as any; + if (!result.dry_run) throw new Error('dry_run flag not returned'); + // Verify page was NOT created + try { + await handleToolCall(eng, 'get_page', { slug: 'smoke/should-not-exist' }); + throw new Error('Page was created despite dry_run'); + } catch (e: any) { + if (!e.message.includes('not found') && !e.code) throw e; + } +}); + +await test('search finds the page', async () => { + const results = await handleToolCall(eng, 'search', { query: 'smoke test' }) as any[]; + if (!Array.isArray(results)) throw new Error('search should return array'); + // Keyword search may or may not find it depending on search_vector trigger +}); + +await test('list_pages includes our page', async () => { + const pages = await handleToolCall(eng, 'list_pages', { limit: 100 }) as any[]; + const found = pages.find((p: any) => p.slug === 'smoke/test-page'); + if (!found) throw new Error('smoke/test-page not in list'); +}); + +await test('add_tag and get_tags work', async () => { + await handleToolCall(eng, 'add_tag', { slug: 'smoke/test-page', tag: 'smoke-test' }); + const tags = await handleToolCall(eng, 'get_tags', { slug: 'smoke/test-page' }) as string[]; + if (!tags.includes('smoke-test')) throw new Error('tag not found'); +}); + +await test('delete_page cleans up', async () => { + await handleToolCall(eng, 'delete_page', { slug: 'smoke/test-page' }); + try { + await handleToolCall(eng, 'get_page', { slug: 'smoke/test-page' }); + throw new Error('Page still exists after delete'); + } catch (e: any) { + if (!e.message.includes('not found') && !e.code) throw e; + } +}); + +await eng.disconnect(); + +console.log(`\n${passed} passed, ${failed} failed`); +if (failed > 0) process.exit(1); +console.log('\n🧠 MCP smoke test passed!'); diff --git a/src/commands/auth.ts b/src/commands/auth.ts new file mode 100644 index 000000000..969b063b0 --- /dev/null +++ b/src/commands/auth.ts @@ -0,0 +1,241 @@ +#!/usr/bin/env bun +/** + * GBrain token management — standalone script, no gbrain CLI dependency. + * + * Usage: + * DATABASE_URL=... bun run src/commands/auth.ts create "claude-desktop" + * DATABASE_URL=... bun run src/commands/auth.ts list + * DATABASE_URL=... bun run src/commands/auth.ts revoke "claude-desktop" + * DATABASE_URL=... bun run src/commands/auth.ts test --token + */ +import postgres from 'postgres'; +import { createHash, randomBytes } from 'crypto'; + +const DATABASE_URL = process.env.DATABASE_URL || process.env.GBRAIN_DATABASE_URL; +if (!DATABASE_URL && process.argv[2] !== 'test') { + console.error('Set DATABASE_URL or GBRAIN_DATABASE_URL environment variable.'); + process.exit(1); +} + +function hashToken(token: string): string { + return createHash('sha256').update(token).digest('hex'); +} + +function generateToken(): string { + return 'gbrain_' + randomBytes(32).toString('hex'); +} + +async function create(name: string) { + if (!name) { console.error('Usage: auth create '); process.exit(1); } + const sql = postgres(DATABASE_URL!); + const token = generateToken(); + const hash = hashToken(token); + + try { + await sql` + INSERT INTO access_tokens (name, token_hash) + VALUES (${name}, ${hash}) + `; + console.log(`Token created for "${name}":\n`); + console.log(` ${token}\n`); + console.log('Save this token — it will not be shown again.'); + console.log(`Revoke with: bun run src/commands/auth.ts revoke "${name}"`); + } catch (e: any) { + if (e.code === '23505') { + console.error(`A token named "${name}" already exists. Revoke it first or use a different name.`); + } else { + console.error('Error:', e.message); + } + process.exit(1); + } finally { + await sql.end(); + } +} + +async function list() { + const sql = postgres(DATABASE_URL!); + try { + const rows = await sql` + SELECT name, created_at, last_used_at, revoked_at + FROM access_tokens + ORDER BY created_at DESC + `; + if (rows.length === 0) { + console.log('No tokens found. Create one: bun run src/commands/auth.ts create "my-client"'); + return; + } + console.log('Name Created Last Used Status'); + console.log('─'.repeat(80)); + for (const r of rows) { + const name = (r.name as string).padEnd(20); + const created = new Date(r.created_at as string).toISOString().slice(0, 19); + const lastUsed = r.last_used_at ? new Date(r.last_used_at as string).toISOString().slice(0, 19) : 'never'.padEnd(19); + const status = r.revoked_at ? 'REVOKED' : 'active'; + console.log(`${name} ${created} ${lastUsed} ${status}`); + } + } finally { + await sql.end(); + } +} + +async function revoke(name: string) { + if (!name) { console.error('Usage: auth revoke '); process.exit(1); } + const sql = postgres(DATABASE_URL!); + try { + const result = await sql` + UPDATE access_tokens SET revoked_at = now() + WHERE name = ${name} AND revoked_at IS NULL + `; + if (result.count === 0) { + console.error(`No active token found with name "${name}".`); + process.exit(1); + } + console.log(`Token "${name}" revoked.`); + } finally { + await sql.end(); + } +} + +async function test(url: string, token: string) { + if (!url || !token) { + console.error('Usage: auth test --token '); + process.exit(1); + } + + const startTime = Date.now(); + console.log(`Testing MCP server at ${url}...\n`); + + // Step 1: Initialize + try { + const initRes = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}`, + 'Accept': 'application/json, text/event-stream', + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'initialize', + params: { + protocolVersion: '2025-03-26', + capabilities: {}, + clientInfo: { name: 'gbrain-smoke-test', version: '1.0' }, + }, + id: 1, + }), + }); + + if (!initRes.ok) { + console.error(` Initialize failed: ${initRes.status} ${initRes.statusText}`); + const body = await initRes.text(); + if (body) console.error(` ${body}`); + process.exit(1); + } + console.log(' ✓ Initialize handshake'); + } catch (e: any) { + console.error(` ✗ Connection failed: ${e.message}`); + process.exit(1); + } + + // Step 2: List tools + try { + const listRes = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}`, + 'Accept': 'application/json, text/event-stream', + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'tools/list', + params: {}, + id: 2, + }), + }); + + if (!listRes.ok) { + console.error(` ✗ tools/list failed: ${listRes.status}`); + process.exit(1); + } + + const text = await listRes.text(); + // Parse SSE or JSON response + let toolCount = 0; + if (text.includes('event:')) { + // SSE format: extract data lines + const dataLines = text.split('\n').filter(l => l.startsWith('data:')); + for (const line of dataLines) { + try { + const data = JSON.parse(line.slice(5)); + if (data.result?.tools) toolCount = data.result.tools.length; + } catch { /* skip non-JSON lines */ } + } + } else { + try { + const data = JSON.parse(text); + toolCount = data.result?.tools?.length || 0; + } catch { /* parse error */ } + } + + console.log(` ✓ tools/list: ${toolCount} tools available`); + } catch (e: any) { + console.error(` ✗ tools/list failed: ${e.message}`); + process.exit(1); + } + + // Step 3: Call get_stats (real tool call) + try { + const statsRes = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}`, + 'Accept': 'application/json, text/event-stream', + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'tools/call', + params: { name: 'get_stats', arguments: {} }, + id: 3, + }), + }); + + if (!statsRes.ok) { + console.error(` ✗ get_stats failed: ${statsRes.status}`); + process.exit(1); + } + console.log(' ✓ get_stats: brain is responding'); + } catch (e: any) { + console.error(` ✗ get_stats failed: ${e.message}`); + process.exit(1); + } + + const elapsed = ((Date.now() - startTime) / 1000).toFixed(1); + console.log(`\n🧠 Your brain is live! (${elapsed}s)`); +} + +// CLI dispatch +const [cmd, ...args] = process.argv.slice(2); +switch (cmd) { + case 'create': await create(args[0]); break; + case 'list': await list(); break; + case 'revoke': await revoke(args[0]); break; + case 'test': { + const tokenIdx = args.indexOf('--token'); + const url = args.find(a => !a.startsWith('--') && a !== args[tokenIdx + 1]); + const token = tokenIdx >= 0 ? args[tokenIdx + 1] : ''; + await test(url || '', token || ''); + break; + } + default: + console.log(`GBrain Token Management + +Usage: + bun run src/commands/auth.ts create Create a new access token + bun run src/commands/auth.ts list List all tokens + bun run src/commands/auth.ts revoke Revoke a token + bun run src/commands/auth.ts test --token Smoke test a remote MCP server +`); +} diff --git a/src/commands/files.ts b/src/commands/files.ts index 3473e3c31..dc20857ab 100644 --- a/src/commands/files.ts +++ b/src/commands/files.ts @@ -131,6 +131,16 @@ async function uploadFile(args: string[]) { return; } + // Upload to storage backend if configured + const { loadConfig } = await import('../core/config.ts'); + const config = loadConfig(); + if (config?.storage) { + const { createStorage } = await import('../core/storage.ts'); + const storage = await createStorage(config.storage as any); + const content = readFileSync(filePath); + await storage.upload(storagePath, content, mimeType || undefined); + } + await sql` INSERT INTO files (page_slug, filename, storage_path, mime_type, size_bytes, content_hash, metadata) VALUES (${pageSlug}, ${filename}, ${storagePath}, ${mimeType}, ${stat.size}, ${hash}, ${'{}'}::jsonb) @@ -308,10 +318,31 @@ async function redirectFiles(args: string[]) { return; } + // Verify remote files exist before deleting locals + const { loadConfig } = await import('../core/config.ts'); + const config = loadConfig(); + let storage: any = null; + if (config?.storage) { + const { createStorage } = await import('../core/storage.ts'); + storage = await createStorage(config.storage as any); + } + let redirected = 0; + let skippedMissing = 0; for (const filePath of files) { const relPath = relative(dir, filePath); const hash = fileHash(filePath); + + // Verify remote exists before deleting local + if (storage) { + const remoteExists = await storage.exists(relPath); + if (!remoteExists) { + console.error(` Skipping ${relPath}: not found in remote storage (would lose data)`); + skippedMissing++; + continue; + } + } + const breadcrumb = stringify({ moved_to: 'storage', bucket: marker.bucket || 'brain-files', @@ -325,6 +356,9 @@ async function redirectFiles(args: string[]) { } console.log(`Redirected ${redirected} files. Originals removed, breadcrumbs created.`); + if (skippedMissing > 0) { + console.log(`Skipped ${skippedMissing} files (not found in remote storage — run 'gbrain files mirror' first).`); + } console.log('To undo: gbrain files restore '); } diff --git a/src/commands/import.ts b/src/commands/import.ts index 3fba2d111..cdb013b2a 100644 --- a/src/commands/import.ts +++ b/src/commands/import.ts @@ -109,13 +109,15 @@ export async function runImport(engine: BrainEngine, args: string[]) { processed++; if (processed % 100 === 0 || processed === files.length) { logProgress(); - // Save checkpoint every 100 files + // Save checkpoint every 100 files — track completed file set, not just a counter if (processed % 100 === 0) { try { const cpDir = join(homedir(), '.gbrain'); if (!existsSync(cpDir)) { const { mkdirSync } = await import('fs'); mkdirSync(cpDir, { recursive: true }); } writeFileSync(checkpointPath, JSON.stringify({ - dir, totalFiles: allFiles.length, processedIndex: resumeIndex + processed, + dir, totalFiles: allFiles.length, + processedIndex: resumeIndex + processed, + completedFiles: importedSlugs.length + skipped, timestamp: new Date().toISOString(), })); } catch { /* non-fatal */ } @@ -134,11 +136,13 @@ export async function runImport(engine: BrainEngine, args: string[]) { }) ); - const queue = [...files]; + // Thread-safe queue: use an atomic index counter instead of array.shift() + let queueIndex = 0; await Promise.all(workerEngines.map(async (eng) => { - while (queue.length > 0) { - const file = queue.shift()!; - await processFile(eng, file); + while (true) { + const idx = queueIndex++; + if (idx >= files.length) break; + await processFile(eng, files[idx]); } })); @@ -157,9 +161,11 @@ export async function runImport(engine: BrainEngine, args: string[]) { } } - // Clear checkpoint on successful completion - if (existsSync(checkpointPath)) { + // Clear checkpoint only on successful completion (no errors) + if (errors === 0 && existsSync(checkpointPath)) { try { unlinkSync(checkpointPath); } catch { /* non-fatal */ } + } else if (errors > 0 && existsSync(checkpointPath)) { + console.log(` Checkpoint preserved (${errors} errors). Run again to retry failed files.`); } const totalTime = ((Date.now() - startTime) / 1000).toFixed(1); diff --git a/src/core/config.ts b/src/core/config.ts index a6e032d73..4c94fad1c 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -3,8 +3,9 @@ import { join } from 'path'; import { homedir } from 'os'; import type { EngineConfig } from './types.ts'; -const CONFIG_DIR = join(homedir(), '.gbrain'); -const CONFIG_PATH = join(CONFIG_DIR, 'config.json'); +// Lazy-evaluated to avoid calling homedir() at module scope (breaks in Deno Edge Functions) +function getConfigDir() { return join(homedir(), '.gbrain'); } +function getConfigPath() { return join(getConfigDir(), 'config.json'); } export interface GBrainConfig { engine: 'postgres' | 'sqlite'; @@ -21,7 +22,7 @@ export interface GBrainConfig { export function loadConfig(): GBrainConfig | null { let fileConfig: GBrainConfig | null = null; try { - const raw = readFileSync(CONFIG_PATH, 'utf-8'); + const raw = readFileSync(getConfigPath(), 'utf-8'); fileConfig = JSON.parse(raw) as GBrainConfig; } catch { /* no config file */ } @@ -40,10 +41,10 @@ export function loadConfig(): GBrainConfig | null { } export function saveConfig(config: GBrainConfig): void { - mkdirSync(CONFIG_DIR, { recursive: true }); - writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 }); + mkdirSync(getConfigDir(), { recursive: true }); + writeFileSync(getConfigPath(), JSON.stringify(config, null, 2) + '\n', { mode: 0o600 }); try { - chmodSync(CONFIG_PATH, 0o600); + chmodSync(getConfigPath(), 0o600); } catch { // chmod may fail on some platforms } @@ -57,10 +58,10 @@ export function toEngineConfig(config: GBrainConfig): EngineConfig { }; } -export function getConfigDir(): string { - return CONFIG_DIR; +export function configDir(): string { + return join(homedir(), '.gbrain'); } -export function getConfigPath(): string { - return CONFIG_PATH; +export function configPath(): string { + return join(configDir(), 'config.json'); } diff --git a/src/core/db.ts b/src/core/db.ts index 20b9d4226..69f8ecd78 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -1,7 +1,6 @@ import postgres from 'postgres'; -import { readFileSync } from 'fs'; -import { join, dirname } from 'path'; import { GBrainError, type EngineConfig } from './types.ts'; +import { SCHEMA_SQL } from './schema-embedded.ts'; let sql: ReturnType | null = null; @@ -61,27 +60,18 @@ export async function disconnect(): Promise { export async function initSchema(): Promise { const conn = getConnection(); - - // Read schema SQL and execute as a single statement. - // The postgres driver handles multi-statement SQL natively, including - // PL/pgSQL functions with $$ delimiter blocks that contain semicolons. - // The schema uses IF NOT EXISTS / CREATE OR REPLACE for idempotency. - const schemaPath = join(dirname(new URL(import.meta.url).pathname), '..', 'schema.sql'); - const schemaSql = readFileSync(schemaPath, 'utf-8'); - - await conn.unsafe(schemaSql); + // Advisory lock prevents concurrent initSchema() calls from deadlocking + await conn`SELECT pg_advisory_lock(42)`; + try { + await conn.unsafe(SCHEMA_SQL); + } finally { + await conn`SELECT pg_advisory_unlock(42)`; + } } -export async function withTransaction(fn: () => Promise): Promise { +export async function withTransaction(fn: (tx: ReturnType) => Promise): Promise { const conn = getConnection(); return conn.begin(async (tx) => { - // Temporarily swap global connection to transaction - const prev = sql; - sql = tx as unknown as ReturnType; - try { - return await fn(); - } finally { - sql = prev; - } + return fn(tx as unknown as ReturnType); }); } diff --git a/src/core/migrate.ts b/src/core/migrate.ts index b82905856..d8194a744 100644 --- a/src/core/migrate.ts +++ b/src/core/migrate.ts @@ -48,6 +48,40 @@ const MIGRATIONS: Migration[] = [ if (renamed > 0) console.log(` Renamed ${renamed} slugs`); }, }, + { + version: 3, + name: 'unique_chunk_index', + sql: ` + -- Deduplicate any existing duplicate (page_id, chunk_index) rows before adding constraint + DELETE FROM content_chunks a USING content_chunks b + WHERE a.page_id = b.page_id AND a.chunk_index = b.chunk_index AND a.id > b.id; + CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_page_index ON content_chunks(page_id, chunk_index); + `, + }, + { + version: 4, + name: 'access_tokens_and_mcp_log', + sql: ` + CREATE TABLE IF NOT EXISTS access_tokens ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + scopes TEXT[], + created_at TIMESTAMPTZ DEFAULT now(), + last_used_at TIMESTAMPTZ, + revoked_at TIMESTAMPTZ + ); + CREATE INDEX IF NOT EXISTS idx_access_tokens_hash ON access_tokens (token_hash) WHERE revoked_at IS NULL; + CREATE TABLE IF NOT EXISTS mcp_request_log ( + id SERIAL PRIMARY KEY, + token_name TEXT, + operation TEXT NOT NULL, + latency_ms INTEGER, + status TEXT NOT NULL DEFAULT 'success', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() + ); + `, + }, ]; export const LATEST_VERSION = MIGRATIONS.length > 0 diff --git a/src/core/operations.ts b/src/core/operations.ts index f77eb6214..778e07725 100644 --- a/src/core/operations.ts +++ b/src/core/operations.ts @@ -581,14 +581,37 @@ const file_upload: Operation = { return { status: 'already_exists', storage_path: storagePath }; } - await sql` - INSERT INTO files (page_slug, filename, storage_path, mime_type, size_bytes, content_hash, metadata) - VALUES (${pageSlug}, ${filename}, ${storagePath}, ${mimeType}, ${stat.size}, ${hash}, ${'{}'}::jsonb) - ON CONFLICT (storage_path) DO UPDATE SET - content_hash = EXCLUDED.content_hash, - size_bytes = EXCLUDED.size_bytes, - mime_type = EXCLUDED.mime_type - `; + // Upload to storage backend if configured + if (ctx.config.storage) { + const { createStorage } = await import('./storage.ts'); + const storage = await createStorage(ctx.config.storage as any); + try { + await storage.upload(storagePath, content, mimeType || undefined); + } catch (uploadErr) { + throw new OperationError('storage_error', `Upload failed: ${uploadErr instanceof Error ? uploadErr.message : String(uploadErr)}`); + } + } + + try { + await sql` + INSERT INTO files (page_slug, filename, storage_path, mime_type, size_bytes, content_hash, metadata) + VALUES (${pageSlug}, ${filename}, ${storagePath}, ${mimeType}, ${stat.size}, ${hash}, ${'{}'}::jsonb) + ON CONFLICT (storage_path) DO UPDATE SET + content_hash = EXCLUDED.content_hash, + size_bytes = EXCLUDED.size_bytes, + mime_type = EXCLUDED.mime_type + `; + } catch (dbErr) { + // Rollback: clean up storage if DB write failed + if (ctx.config.storage) { + try { + const { createStorage } = await import('./storage.ts'); + const storage = await createStorage(ctx.config.storage as any); + await storage.delete(storagePath); + } catch { /* best effort cleanup */ } + } + throw dbErr; + } return { status: 'uploaded', storage_path: storagePath, size_bytes: stat.size }; }, diff --git a/src/core/postgres-engine.ts b/src/core/postgres-engine.ts index 5ac3bf422..c1332f66e 100644 --- a/src/core/postgres-engine.ts +++ b/src/core/postgres-engine.ts @@ -1,9 +1,8 @@ import postgres from 'postgres'; import { createHash } from 'crypto'; -import { readFileSync } from 'fs'; -import { join, dirname } from 'path'; import type { BrainEngine } from './engine.ts'; import { runMigrations } from './migrate.ts'; +import { SCHEMA_SQL } from './schema-embedded.ts'; import type { Page, PageInput, PageFilters, PageType, Chunk, ChunkInput, @@ -58,31 +57,31 @@ export class PostgresEngine implements BrainEngine { async initSchema(): Promise { const conn = this.sql; - const schemaPath = join(dirname(new URL(import.meta.url).pathname), '..', 'schema.sql'); - const schemaSql = readFileSync(schemaPath, 'utf-8'); - await conn.unsafe(schemaSql); + // Advisory lock prevents concurrent initSchema() calls from deadlocking + // on DDL statements (DROP TRIGGER + CREATE TRIGGER acquire AccessExclusiveLock) + await conn`SELECT pg_advisory_lock(42)`; + try { + await conn.unsafe(SCHEMA_SQL); - // Run any pending migrations automatically - const { applied } = await runMigrations(this); - if (applied > 0) { - console.log(` ${applied} migration(s) applied`); + // Run any pending migrations automatically + const { applied } = await runMigrations(this); + if (applied > 0) { + console.log(` ${applied} migration(s) applied`); + } + } finally { + await conn`SELECT pg_advisory_unlock(42)`; } } async transaction(fn: (engine: BrainEngine) => Promise): Promise { - if (this._sql) { - // Instance connection: use .begin() directly, no global swap - return this._sql.begin(async (tx) => { - const prev = this._sql; - this._sql = tx as unknown as ReturnType; - try { - return await fn(this); - } finally { - this._sql = prev; - } - }); - } - return db.withTransaction(() => fn(this)); + const conn = this._sql || db.getConnection(); + return conn.begin(async (tx) => { + // Create a scoped engine with tx as its connection, no shared state mutation + const txEngine = Object.create(this) as PostgresEngine; + Object.defineProperty(txEngine, 'sql', { get: () => tx }); + Object.defineProperty(txEngine, '_sql', { value: tx as unknown as ReturnType, writable: false }); + return fn(txEngine); + }); } // Pages CRUD @@ -97,7 +96,7 @@ export class PostgresEngine implements BrainEngine { } async putPage(slug: string, page: PageInput): Promise { - validateSlug(slug); + slug = validateSlug(slug); const sql = this.sql; const hash = page.content_hash || contentHash(page.compiled_truth, page.timeline || ''); const frontmatter = page.frontmatter || {}; @@ -182,7 +181,7 @@ export class PostgresEngine implements BrainEngine { const limit = opts?.limit || 20; const rows = await sql` - SELECT + SELECT DISTINCT ON (p.slug) p.slug, p.id as page_id, p.title, p.type, cc.chunk_text, cc.chunk_source, ts_rank(p.search_vector, websearch_to_tsquery('english', ${query})) AS score, @@ -192,9 +191,11 @@ export class PostgresEngine implements BrainEngine { FROM pages p JOIN content_chunks cc ON cc.page_id = p.id WHERE p.search_vector @@ websearch_to_tsquery('english', ${query}) - ORDER BY score DESC - LIMIT ${limit} + ORDER BY p.slug, score DESC `; + // Re-sort by score (DISTINCT ON requires ORDER BY slug first) and apply limit + rows.sort((a: any, b: any) => b.score - a.score); + rows.splice(limit); return rows.map(rowToSearchResult); } @@ -231,14 +232,17 @@ export class PostgresEngine implements BrainEngine { if (pages.length === 0) throw new Error(`Page not found: ${slug}`); const pageId = pages[0].id; - // Delete existing chunks for this page - await sql`DELETE FROM content_chunks WHERE page_id = ${pageId}`; + // Remove chunks that no longer exist (chunk_index beyond new count) + const newIndices = chunks.map(c => c.chunk_index); + if (newIndices.length > 0) { + await sql`DELETE FROM content_chunks WHERE page_id = ${pageId} AND chunk_index != ALL(${newIndices})`; + } else { + await sql`DELETE FROM content_chunks WHERE page_id = ${pageId}`; + return; + } - // Bulk insert chunks — build multi-row VALUES to reduce round-trips - if (chunks.length === 0) return; - - // postgres.js tagged templates don't handle vector casting in bulk, - // so we build a parameterized raw SQL query + // Batch upsert: build a single multi-row INSERT ON CONFLICT statement + // This avoids per-row round-trips and reduces lock contention under parallel workers const cols = '(page_id, chunk_index, chunk_text, chunk_source, embedding, model, token_count, embedded_at)'; const rows: string[] = []; const params: unknown[] = []; @@ -258,8 +262,16 @@ export class PostgresEngine implements BrainEngine { } } + // Single statement upsert: preserves existing embeddings via COALESCE when new value is NULL await sql.unsafe( - `INSERT INTO content_chunks ${cols} VALUES ${rows.join(', ')}`, + `INSERT INTO content_chunks ${cols} VALUES ${rows.join(', ')} + ON CONFLICT (page_id, chunk_index) DO UPDATE SET + chunk_text = EXCLUDED.chunk_text, + chunk_source = EXCLUDED.chunk_source, + embedding = COALESCE(EXCLUDED.embedding, content_chunks.embedding), + model = COALESCE(EXCLUDED.model, content_chunks.model), + token_count = EXCLUDED.token_count, + embedded_at = COALESCE(EXCLUDED.embedded_at, content_chunks.embedded_at)`, params, ); } @@ -584,7 +596,7 @@ export class PostgresEngine implements BrainEngine { // Sync async updateSlug(oldSlug: string, newSlug: string): Promise { - validateSlug(newSlug); + newSlug = validateSlug(newSlug); const sql = this.sql; await sql`UPDATE pages SET slug = ${newSlug}, updated_at = now() WHERE slug = ${oldSlug}`; } @@ -613,12 +625,13 @@ export class PostgresEngine implements BrainEngine { } // Helpers -function validateSlug(slug: string): void { +function validateSlug(slug: string): string { // Git is the system of record — slugs are lowercased repo-relative paths. - // Only reject empty, path traversal (..), and leading slash. if (!slug || /\.\./.test(slug) || /^\//.test(slug)) { throw new Error(`Invalid slug: "${slug}". Slugs cannot be empty, start with /, or contain path traversal.`); } + // Normalize to lowercase — all entry points (pathToSlug, inferSlug, frontmatter, direct writes) go through here + return slug.toLowerCase(); } function contentHash(compiledTruth: string, timeline: string): string { diff --git a/src/core/schema-embedded.ts b/src/core/schema-embedded.ts new file mode 100644 index 000000000..eb0759e83 --- /dev/null +++ b/src/core/schema-embedded.ts @@ -0,0 +1,279 @@ +// AUTO-GENERATED — do not edit. Run: bun run build:schema +// Source: src/schema.sql + +export const SCHEMA_SQL = ` +-- GBrain Postgres + pgvector schema + +CREATE EXTENSION IF NOT EXISTS vector; +CREATE EXTENSION IF NOT EXISTS pg_trgm; + +-- ============================================================ +-- pages: the core content table +-- ============================================================ +CREATE TABLE IF NOT EXISTS pages ( + id SERIAL PRIMARY KEY, + slug TEXT NOT NULL UNIQUE, + type TEXT NOT NULL, + title TEXT NOT NULL, + compiled_truth TEXT NOT NULL DEFAULT '', + timeline TEXT NOT NULL DEFAULT '', + frontmatter JSONB NOT NULL DEFAULT '{}', + content_hash TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_pages_type ON pages(type); +CREATE INDEX IF NOT EXISTS idx_pages_frontmatter ON pages USING GIN(frontmatter); +CREATE INDEX IF NOT EXISTS idx_pages_trgm ON pages USING GIN(title gin_trgm_ops); + +-- ============================================================ +-- content_chunks: chunked content with embeddings +-- ============================================================ +CREATE TABLE IF NOT EXISTS content_chunks ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + chunk_index INTEGER NOT NULL, + chunk_text TEXT NOT NULL, + chunk_source TEXT NOT NULL DEFAULT 'compiled_truth', + embedding vector(1536), + model TEXT NOT NULL DEFAULT 'text-embedding-3-large', + token_count INTEGER, + embedded_at TIMESTAMPTZ, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_page_index ON content_chunks(page_id, chunk_index); +CREATE INDEX IF NOT EXISTS idx_chunks_page ON content_chunks(page_id); +CREATE INDEX IF NOT EXISTS idx_chunks_embedding ON content_chunks USING hnsw (embedding vector_cosine_ops); + +-- ============================================================ +-- links: cross-references between pages +-- ============================================================ +CREATE TABLE IF NOT EXISTS links ( + id SERIAL PRIMARY KEY, + from_page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + to_page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + link_type TEXT NOT NULL DEFAULT '', + context TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(from_page_id, to_page_id) +); + +CREATE INDEX IF NOT EXISTS idx_links_from ON links(from_page_id); +CREATE INDEX IF NOT EXISTS idx_links_to ON links(to_page_id); + +-- ============================================================ +-- tags +-- ============================================================ +CREATE TABLE IF NOT EXISTS tags ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + tag TEXT NOT NULL, + UNIQUE(page_id, tag) +); + +CREATE INDEX IF NOT EXISTS idx_tags_tag ON tags(tag); +CREATE INDEX IF NOT EXISTS idx_tags_page_id ON tags(page_id); + +-- ============================================================ +-- raw_data: sidecar data (replaces .raw/ JSON files) +-- ============================================================ +CREATE TABLE IF NOT EXISTS raw_data ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + source TEXT NOT NULL, + data JSONB NOT NULL, + fetched_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(page_id, source) +); + +CREATE INDEX IF NOT EXISTS idx_raw_data_page ON raw_data(page_id); + +-- ============================================================ +-- timeline_entries: structured timeline +-- ============================================================ +CREATE TABLE IF NOT EXISTS timeline_entries ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + date DATE NOT NULL, + source TEXT NOT NULL DEFAULT '', + summary TEXT NOT NULL, + detail TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_timeline_page ON timeline_entries(page_id); +CREATE INDEX IF NOT EXISTS idx_timeline_date ON timeline_entries(date); + +-- ============================================================ +-- page_versions: snapshot history for compiled_truth +-- ============================================================ +CREATE TABLE IF NOT EXISTS page_versions ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + compiled_truth TEXT NOT NULL, + frontmatter JSONB NOT NULL DEFAULT '{}', + snapshot_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_versions_page ON page_versions(page_id); + +-- ============================================================ +-- ingest_log +-- ============================================================ +CREATE TABLE IF NOT EXISTS ingest_log ( + id SERIAL PRIMARY KEY, + source_type TEXT NOT NULL, + source_ref TEXT NOT NULL, + pages_updated JSONB NOT NULL DEFAULT '[]', + summary TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +-- ============================================================ +-- config: brain-level settings +-- ============================================================ +CREATE TABLE IF NOT EXISTS config ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL +); + +INSERT INTO config (key, value) VALUES + ('version', '1'), + ('embedding_model', 'text-embedding-3-large'), + ('embedding_dimensions', '1536'), + ('chunk_strategy', 'semantic') +ON CONFLICT (key) DO NOTHING; + +-- ============================================================ +-- access_tokens: bearer tokens for remote MCP access +-- ============================================================ +CREATE TABLE IF NOT EXISTS access_tokens ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + scopes TEXT[], + created_at TIMESTAMPTZ DEFAULT now(), + last_used_at TIMESTAMPTZ, + revoked_at TIMESTAMPTZ +); + +CREATE INDEX IF NOT EXISTS idx_access_tokens_hash ON access_tokens (token_hash) WHERE revoked_at IS NULL; + +-- ============================================================ +-- mcp_request_log: usage logging for remote MCP requests +-- ============================================================ +CREATE TABLE IF NOT EXISTS mcp_request_log ( + id SERIAL PRIMARY KEY, + token_name TEXT, + operation TEXT NOT NULL, + latency_ms INTEGER, + status TEXT NOT NULL DEFAULT 'success', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +-- ============================================================ +-- files: binary attachments stored in Supabase Storage +-- ============================================================ +CREATE TABLE IF NOT EXISTS files ( + id SERIAL PRIMARY KEY, + page_slug TEXT REFERENCES pages(slug) ON DELETE SET NULL ON UPDATE CASCADE, + filename TEXT NOT NULL, + storage_path TEXT NOT NULL, + mime_type TEXT, + size_bytes BIGINT, + content_hash TEXT NOT NULL, + metadata JSONB NOT NULL DEFAULT '{}', + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(storage_path) +); + +-- Migration: drop storage_url if it exists (renamed to storage_path only) +ALTER TABLE files DROP COLUMN IF EXISTS storage_url; + +CREATE INDEX IF NOT EXISTS idx_files_page ON files(page_slug); +CREATE INDEX IF NOT EXISTS idx_files_hash ON files(content_hash); + +-- ============================================================ +-- Trigger-based search_vector (spans pages + timeline_entries) +-- ============================================================ +ALTER TABLE pages ADD COLUMN IF NOT EXISTS search_vector tsvector; + +CREATE INDEX IF NOT EXISTS idx_pages_search ON pages USING GIN(search_vector); + +-- Function to rebuild search_vector for a page +CREATE OR REPLACE FUNCTION update_page_search_vector() RETURNS trigger AS \$\$ +DECLARE + timeline_text TEXT; +BEGIN + -- Gather timeline_entries text for this page + SELECT coalesce(string_agg(summary || ' ' || detail, ' '), '') + INTO timeline_text + FROM timeline_entries + WHERE page_id = NEW.id; + + -- Build weighted tsvector + NEW.search_vector := + setweight(to_tsvector('english', coalesce(NEW.title, '')), 'A') || + setweight(to_tsvector('english', coalesce(NEW.compiled_truth, '')), 'B') || + setweight(to_tsvector('english', coalesce(NEW.timeline, '')), 'C') || + setweight(to_tsvector('english', coalesce(timeline_text, '')), 'C'); + + RETURN NEW; +END; +\$\$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS trg_pages_search_vector ON pages; +CREATE TRIGGER trg_pages_search_vector + BEFORE INSERT OR UPDATE ON pages + FOR EACH ROW + EXECUTE FUNCTION update_page_search_vector(); + +-- When timeline_entries change, update the parent page's search_vector +CREATE OR REPLACE FUNCTION update_page_search_vector_from_timeline() RETURNS trigger AS \$\$ +DECLARE + page_row pages%ROWTYPE; +BEGIN + -- Touch the page to re-fire its trigger + UPDATE pages SET updated_at = now() + WHERE id = coalesce(NEW.page_id, OLD.page_id); + RETURN NEW; +END; +\$\$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS trg_timeline_search_vector ON timeline_entries; +CREATE TRIGGER trg_timeline_search_vector + AFTER INSERT OR UPDATE OR DELETE ON timeline_entries + FOR EACH ROW + EXECUTE FUNCTION update_page_search_vector_from_timeline(); + +-- ============================================================ +-- Row Level Security: block anon access, postgres role bypasses +-- ============================================================ +-- The postgres role (used by gbrain via pooler) has BYPASSRLS. +-- Enabling RLS with no policies means the anon key can't read anything. +-- Only enable if the current role actually has BYPASSRLS privilege, +-- otherwise we'd lock ourselves out. +DO \$\$ +DECLARE + has_bypass BOOLEAN; +BEGIN + SELECT rolbypassrls INTO has_bypass FROM pg_roles WHERE rolname = current_user; + IF has_bypass THEN + ALTER TABLE pages ENABLE ROW LEVEL SECURITY; + ALTER TABLE content_chunks ENABLE ROW LEVEL SECURITY; + ALTER TABLE links ENABLE ROW LEVEL SECURITY; + ALTER TABLE tags ENABLE ROW LEVEL SECURITY; + ALTER TABLE raw_data ENABLE ROW LEVEL SECURITY; + ALTER TABLE timeline_entries ENABLE ROW LEVEL SECURITY; + ALTER TABLE page_versions ENABLE ROW LEVEL SECURITY; + ALTER TABLE ingest_log ENABLE ROW LEVEL SECURITY; + ALTER TABLE config ENABLE ROW LEVEL SECURITY; + ALTER TABLE files ENABLE ROW LEVEL SECURITY; + RAISE NOTICE 'RLS enabled on all tables (role % has BYPASSRLS)', current_user; + ELSE + RAISE WARNING 'Skipping RLS: role % does not have BYPASSRLS privilege. Run as postgres role to enable.', current_user; + END IF; +END \$\$; +`; diff --git a/src/core/search/dedup.ts b/src/core/search/dedup.ts index f8a0e3a2f..2af9c0730 100644 --- a/src/core/search/dedup.ts +++ b/src/core/search/dedup.ts @@ -45,19 +45,25 @@ export function dedupResults( } /** - * Layer 1: Keep only the highest-scoring chunk per page. + * Layer 1: Keep top 3 chunks per page (not just 1). + * Later layers (text similarity, cap per page) handle further reduction. */ function dedupBySource(results: SearchResult[]): SearchResult[] { - const byPage = new Map(); + const byPage = new Map(); for (const r of results) { - const existing = byPage.get(r.slug); - if (!existing || r.score > existing.score) { - byPage.set(r.slug, r); - } + const existing = byPage.get(r.slug) || []; + existing.push(r); + byPage.set(r.slug, existing); } - return Array.from(byPage.values()).sort((a, b) => b.score - a.score); + const kept: SearchResult[] = []; + for (const chunks of byPage.values()) { + chunks.sort((a, b) => b.score - a.score); + kept.push(...chunks.slice(0, 3)); + } + + return kept.sort((a, b) => b.score - a.score); } /** diff --git a/src/core/storage/s3.ts b/src/core/storage/s3.ts index b3648410b..1d91afc2f 100644 --- a/src/core/storage/s3.ts +++ b/src/core/storage/s3.ts @@ -1,79 +1,109 @@ +import { + S3Client, + PutObjectCommand, + GetObjectCommand, + DeleteObjectCommand, + HeadObjectCommand, + ListObjectsV2Command, +} from '@aws-sdk/client-s3'; import type { StorageBackend, StorageConfig } from '../storage.ts'; /** * S3-compatible storage — works with AWS S3, Cloudflare R2, MinIO, etc. - * - * Uses fetch() directly against the S3 REST API with AWS Signature V4. - * No SDK dependency needed — keeps the binary small. + * Uses @aws-sdk/client-s3 for proper authentication and request signing. */ export class S3Storage implements StorageBackend { + private client: S3Client; private bucket: string; - private region: string; - private endpoint: string; - private accessKeyId: string; - private secretAccessKey: string; constructor(config: StorageConfig) { this.bucket = config.bucket; - this.region = config.region || 'us-east-1'; - this.endpoint = config.endpoint || `https://s3.${this.region}.amazonaws.com`; - this.accessKeyId = config.accessKeyId || ''; - this.secretAccessKey = config.secretAccessKey || ''; - if (!this.accessKeyId || !this.secretAccessKey) { + const region = config.region || 'us-east-1'; + + if (!config.accessKeyId || !config.secretAccessKey) { throw new Error('S3 storage requires accessKeyId and secretAccessKey in config'); } - } - private url(path: string): string { - return `${this.endpoint}/${this.bucket}/${path}`; - } - - private async signedFetch(method: string, path: string, body?: Buffer, mime?: string): Promise { - // Simplified S3 request — for production, use proper AWS Sig V4 - // For now, works with public buckets and pre-signed URLs - const url = this.url(path); - const headers: Record = {}; - if (mime) headers['Content-Type'] = mime; - - return fetch(url, { method, body, headers }); + this.client = new S3Client({ + region, + ...(config.endpoint ? { + endpoint: config.endpoint, + forcePathStyle: true, // Required for R2, MinIO, and custom endpoints + } : {}), + credentials: { + accessKeyId: config.accessKeyId, + secretAccessKey: config.secretAccessKey, + }, + }); } async upload(path: string, data: Buffer, mime?: string): Promise { - const res = await this.signedFetch('PUT', path, data, mime || 'application/octet-stream'); - if (!res.ok) throw new Error(`S3 upload failed: ${res.status} ${res.statusText}`); + await this.client.send(new PutObjectCommand({ + Bucket: this.bucket, + Key: path, + Body: data, + ContentType: mime || 'application/octet-stream', + })); } async download(path: string): Promise { - const res = await this.signedFetch('GET', path); - if (!res.ok) throw new Error(`S3 download failed: ${res.status} ${res.statusText}`); - return Buffer.from(await res.arrayBuffer()); + const res = await this.client.send(new GetObjectCommand({ + Bucket: this.bucket, + Key: path, + })); + if (!res.Body) throw new Error(`S3 download returned empty body: ${path}`); + return Buffer.from(await res.Body.transformToByteArray()); } async delete(path: string): Promise { - const res = await this.signedFetch('DELETE', path); - if (!res.ok && res.status !== 404) throw new Error(`S3 delete failed: ${res.status}`); + await this.client.send(new DeleteObjectCommand({ + Bucket: this.bucket, + Key: path, + })); } async exists(path: string): Promise { - const res = await this.signedFetch('HEAD', path); - return res.ok; + try { + await this.client.send(new HeadObjectCommand({ + Bucket: this.bucket, + Key: path, + })); + return true; + } catch (e: any) { + if (e.name === 'NotFound' || e.$metadata?.httpStatusCode === 404) return false; + throw e; + } } async list(prefix: string): Promise { - const url = `${this.endpoint}/${this.bucket}?list-type=2&prefix=${encodeURIComponent(prefix)}`; - const res = await fetch(url); - if (!res.ok) throw new Error(`S3 list failed: ${res.status}`); - const xml = await res.text(); - const keys: string[] = []; - const regex = /([^<]+)<\/Key>/g; - let match; - while ((match = regex.exec(xml)) !== null) { - keys.push(match[1]); - } - return keys; + const res = await this.client.send(new ListObjectsV2Command({ + Bucket: this.bucket, + Prefix: prefix, + })); + return (res.Contents || []).map(obj => obj.Key!).filter(Boolean); } async getUrl(path: string): Promise { - return this.url(path); + // For custom endpoints (R2, MinIO), use the endpoint URL + const endpoint = (this.client.config as any).endpoint; + if (endpoint) { + const base = typeof endpoint === 'function' ? (await endpoint()).url.toString() : endpoint; + return `${base}/${this.bucket}/${path}`; + } + const region = await this.client.config.region(); + return `https://${this.bucket}.s3.${region}.amazonaws.com/${path}`; + } + + async getContentHash(path: string): Promise { + try { + const res = await this.client.send(new HeadObjectCommand({ + Bucket: this.bucket, + Key: path, + })); + // ETag is typically the MD5 hash (quoted), but for multipart uploads it's different + return res.ETag?.replace(/"/g, '') || null; + } catch { + return null; + } } } diff --git a/src/core/sync.ts b/src/core/sync.ts index c37b3dbfd..c71dc8664 100644 --- a/src/core/sync.ts +++ b/src/core/sync.ts @@ -131,5 +131,5 @@ export function slugifyPath(filePath: string): string { export function pathToSlug(filePath: string, repoPrefix?: string): string { let slug = slugifyPath(filePath); if (repoPrefix) slug = `${repoPrefix}/${slug}`; - return slug; + return slug.toLowerCase(); } diff --git a/src/edge-entry.ts b/src/edge-entry.ts new file mode 100644 index 000000000..b8951d068 --- /dev/null +++ b/src/edge-entry.ts @@ -0,0 +1,16 @@ +/** + * Edge Function bundle entry point. + * + * Curated exports for Supabase Edge Functions (Deno runtime). + * Excludes modules that depend on Node.js filesystem APIs: + * - db.ts (reads schema.sql from disk — now uses schema-embedded.ts) + * - config.ts (reads ~/.gbrain/config.json via homedir()) + * - import-file.ts (uses readFileSync/statSync) + * - sync.ts (git-based, local filesystem) + */ +export { operations, operationsByName, OperationError } from './core/operations.ts'; +export type { Operation, OperationContext, ParamDef } from './core/operations.ts'; +export { PostgresEngine } from './core/postgres-engine.ts'; +export type { BrainEngine } from './core/engine.ts'; +export * from './core/types.ts'; +export { VERSION } from './version.ts'; diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 7a286859e..a798b6490 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -1,5 +1,6 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; +import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; import type { BrainEngine } from '../core/engine.ts'; import { operations, OperationError } from '../core/operations.ts'; import type { OperationContext } from '../core/operations.ts'; @@ -13,7 +14,7 @@ export async function startMcpServer(engine: BrainEngine) { ); // Generate tool definitions from operations - server.setRequestHandler('tools/list' as any, async () => ({ + server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: operations.map(op => ({ name: op.name, description: op.description, @@ -35,7 +36,7 @@ export async function startMcpServer(engine: BrainEngine) { })); // Dispatch tool calls to operation handlers - server.setRequestHandler('tools/call' as any, async (request: any) => { + server.setRequestHandler(CallToolRequestSchema, async (request: any) => { const { name, arguments: params } = request.params; const op = operations.find(o => o.name === name); if (!op) { @@ -82,7 +83,7 @@ export async function handleToolCall( engine, config: loadConfig() || { engine: 'postgres' }, logger: { info: console.log, warn: console.warn, error: console.error }, - dryRun: false, + dryRun: !!(params?.dry_run), }; return op.handler(ctx, params); diff --git a/src/schema.sql b/src/schema.sql index 03e611e68..4fb9d95b2 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -39,6 +39,7 @@ CREATE TABLE IF NOT EXISTS content_chunks ( created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); +CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_page_index ON content_chunks(page_id, chunk_index); CREATE INDEX IF NOT EXISTS idx_chunks_page ON content_chunks(page_id); CREATE INDEX IF NOT EXISTS idx_chunks_embedding ON content_chunks USING hnsw (embedding vector_cosine_ops); @@ -141,6 +142,33 @@ INSERT INTO config (key, value) VALUES ('chunk_strategy', 'semantic') ON CONFLICT (key) DO NOTHING; +-- ============================================================ +-- access_tokens: bearer tokens for remote MCP access +-- ============================================================ +CREATE TABLE IF NOT EXISTS access_tokens ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + scopes TEXT[], + created_at TIMESTAMPTZ DEFAULT now(), + last_used_at TIMESTAMPTZ, + revoked_at TIMESTAMPTZ +); + +CREATE INDEX IF NOT EXISTS idx_access_tokens_hash ON access_tokens (token_hash) WHERE revoked_at IS NULL; + +-- ============================================================ +-- mcp_request_log: usage logging for remote MCP requests +-- ============================================================ +CREATE TABLE IF NOT EXISTS mcp_request_log ( + id SERIAL PRIMARY KEY, + token_name TEXT, + operation TEXT NOT NULL, + latency_ms INTEGER, + status TEXT NOT NULL DEFAULT 'success', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + -- ============================================================ -- files: binary attachments stored in Supabase Storage -- ============================================================ diff --git a/supabase/functions/gbrain-mcp/deno.json b/supabase/functions/gbrain-mcp/deno.json new file mode 100644 index 000000000..23fe78234 --- /dev/null +++ b/supabase/functions/gbrain-mcp/deno.json @@ -0,0 +1,10 @@ +{ + "imports": { + "postgres": "npm:postgres@3", + "openai": "npm:openai@4", + "@modelcontextprotocol/sdk/": "npm:@modelcontextprotocol/sdk@1/", + "hono": "npm:hono@4", + "hono/cors": "npm:hono@4/cors", + "crypto": "node:crypto" + } +} diff --git a/supabase/functions/gbrain-mcp/gbrain-core.js b/supabase/functions/gbrain-mcp/gbrain-core.js new file mode 100644 index 000000000..a852ec2d7 --- /dev/null +++ b/supabase/functions/gbrain-mcp/gbrain-core.js @@ -0,0 +1,540 @@ +var{defineProperty:eE,getOwnPropertyNames:jY,getOwnPropertyDescriptor:NY}=Object,BY=Object.prototype.hasOwnProperty;function xY(T){return this[T]}var h0=(T)=>{var Y=(EI??=new WeakMap).get(T),G;if(Y)return Y;if(Y=eE({},"__esModule",{value:!0}),T&&typeof T==="object"||typeof T==="function"){for(var K of jY(T))if(!BY.call(Y,K))eE(Y,K,{get:xY.bind(T,K),enumerable:!(G=NY(T,K))||G.enumerable})}return EI.set(T,Y),Y},EI,gY=(T,Y)=>()=>(Y||T((Y={exports:{}}).exports,Y),Y.exports);var wY=(T)=>T;function yY(T,Y){this[T]=wY.bind(null,Y)}var jU=(T,Y)=>{for(var G in Y)eE(T,G,{get:Y[G],enumerable:!0,configurable:!0,set:yY.bind(Y,G)})};var GU=(T,Y)=>()=>(T&&(Y=T(T=0)),Y);var iE=((T)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(T,{get:(Y,G)=>(typeof require<"u"?require:Y)[G]}):T)(function(T){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+T+'" is not supported')});var KU={};jU(KU,{transcode:()=>DZ,resolveObjectURL:()=>HZ,kStringMaxLength:()=>GI,kMaxLength:()=>OE,isUtf8:()=>RZ,isAscii:()=>CZ,default:()=>zZ,constants:()=>nY,btoa:()=>bY,atob:()=>dY,INSPECT_MAX_BYTES:()=>JI,File:()=>lY,Buffer:()=>J0,Blob:()=>oY});function fY(T){var Y=T.length;if(Y%4>0)throw Error("Invalid string. Length must be a multiple of 4");var G=T.indexOf("=");if(G===-1)G=Y;var K=G===Y?0:4-G%4;return[G,K]}function cY(T,Y){return(T+Y)*3/4-Y}function pY(T){var Y,G=fY(T),K=G[0],L=G[1],W=new Uint8Array(cY(K,L)),O=0,z=L>0?K-4:K,q;for(q=0;q>16&255,W[O++]=Y>>8&255,W[O++]=Y&255;if(L===2)Y=kU[T.charCodeAt(q)]<<2|kU[T.charCodeAt(q+1)]>>4,W[O++]=Y&255;if(L===1)Y=kU[T.charCodeAt(q)]<<10|kU[T.charCodeAt(q+1)]<<4|kU[T.charCodeAt(q+2)]>>2,W[O++]=Y>>8&255,W[O++]=Y&255;return W}function hY(T){return NU[T>>18&63]+NU[T>>12&63]+NU[T>>6&63]+NU[T&63]}function uY(T,Y,G){var K,L=[];for(var W=Y;Wz?z:O+W));if(K===1)Y=T[G-1],L.push(NU[Y>>2]+NU[Y<<4&63]+"==");else if(K===2)Y=(T[G-2]<<8)+T[G-1],L.push(NU[Y>>10]+NU[Y>>4&63]+NU[Y<<2&63]+"=");return L.join("")}function PE(T,Y,G,K,L){var W,O,z=L*8-K-1,q=(1<>1,C=-7,F=G?L-1:0,R=G?-1:1,M=T[Y+F];F+=R,W=M&(1<<-C)-1,M>>=-C,C+=z;for(;C>0;W=W*256+T[Y+F],F+=R,C-=8);O=W&(1<<-C)-1,W>>=-C,C+=K;for(;C>0;O=O*256+T[Y+F],F+=R,C-=8);if(W===0)W=1-D;else if(W===q)return O?NaN:(M?-1:1)*(1/0);else O=O+Math.pow(2,K),W=W-D;return(M?-1:1)*O*Math.pow(2,W-K)}function QI(T,Y,G,K,L,W){var O,z,q,D=W*8-L-1,C=(1<>1,R=L===23?Math.pow(2,-24)-Math.pow(2,-77):0,M=K?0:W-1,P=K?1:-1,k=Y<0||Y===0&&1/Y<0?1:0;if(Y=Math.abs(Y),isNaN(Y)||Y===1/0)z=isNaN(Y)?1:0,O=C;else{if(O=Math.floor(Math.log(Y)/Math.LN2),Y*(q=Math.pow(2,-O))<1)O--,q*=2;if(O+F>=1)Y+=R/q;else Y+=R*Math.pow(2,1-F);if(Y*q>=2)O++,q/=2;if(O+F>=C)z=0,O=C;else if(O+F>=1)z=(Y*q-1)*Math.pow(2,L),O=O+F;else z=Y*Math.pow(2,F-1)*Math.pow(2,L),O=0}for(;L>=8;T[G+M]=z&255,M+=P,z/=256,L-=8);O=O<0;T[G+M]=O&255,M+=P,O/=256,D-=8);T[G+M-P]|=k*128}function wU(T){if(T>OE)throw RangeError('The value "'+T+'" is invalid for option "size"');let Y=new Uint8Array(T);return Object.setPrototypeOf(Y,J0.prototype),Y}function YX(T,Y,G){return class extends G{constructor(){super();Object.defineProperty(this,"message",{value:Y.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${T}]`,this.stack,delete this.name}get code(){return T}set code(K){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:K,writable:!0})}toString(){return`${this.name} [${T}]: ${this.message}`}}}function J0(T,Y,G){if(typeof T==="number"){if(typeof Y==="string")throw TypeError('The "string" argument must be of type string. Received type number');return ZX(T)}return VI(T,Y,G)}function VI(T,Y,G){if(typeof T==="string")return tY(T,Y);if(ArrayBuffer.isView(T))return aY(T);if(T==null)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof T);if(BU(T,ArrayBuffer)||T&&BU(T.buffer,ArrayBuffer))return IX(T,Y,G);if(typeof SharedArrayBuffer<"u"&&(BU(T,SharedArrayBuffer)||T&&BU(T.buffer,SharedArrayBuffer)))return IX(T,Y,G);if(typeof T==="number")throw TypeError('The "value" argument must not be of type number. Received type number');let K=T.valueOf&&T.valueOf();if(K!=null&&K!==T)return J0.from(K,Y,G);let L=eY(T);if(L)return L;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof T[Symbol.toPrimitive]==="function")return J0.from(T[Symbol.toPrimitive]("string"),Y,G);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof T)}function AI(T){if(typeof T!=="number")throw TypeError('"size" argument must be of type number');else if(T<0)throw RangeError('The value "'+T+'" is invalid for option "size"')}function rY(T,Y,G){if(AI(T),T<=0)return wU(T);if(Y!==void 0)return typeof G==="string"?wU(T).fill(Y,G):wU(T).fill(Y);return wU(T)}function ZX(T){return AI(T),wU(T<0?0:OX(T)|0)}function tY(T,Y){if(typeof Y!=="string"||Y==="")Y="utf8";if(!J0.isEncoding(Y))throw TypeError("Unknown encoding: "+Y);let G=LI(T,Y)|0,K=wU(G),L=K.write(T,Y);if(L!==G)K=K.slice(0,L);return K}function XX(T){let Y=T.length<0?0:OX(T.length)|0,G=wU(Y);for(let K=0;K=OE)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+OE.toString(16)+" bytes");return T|0}function LI(T,Y){if(J0.isBuffer(T))return T.length;if(ArrayBuffer.isView(T)||BU(T,ArrayBuffer))return T.byteLength;if(typeof T!=="string")throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof T);let G=T.length,K=arguments.length>2&&arguments[2]===!0;if(!K&&G===0)return 0;let L=!1;for(;;)switch(Y){case"ascii":case"latin1":case"binary":return G;case"utf8":case"utf-8":return TX(T).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return G*2;case"hex":return G>>>1;case"base64":return zI(T).length;default:if(L)return K?-1:TX(T).length;Y=(""+Y).toLowerCase(),L=!0}}function iY(T,Y,G){let K=!1;if(Y===void 0||Y<0)Y=0;if(Y>this.length)return"";if(G===void 0||G>this.length)G=this.length;if(G<=0)return"";if(G>>>=0,Y>>>=0,G<=Y)return"";if(!T)T="utf8";while(!0)switch(T){case"hex":return JZ(this,Y,G);case"utf8":case"utf-8":return KI(this,Y,G);case"ascii":return OZ(this,Y,G);case"latin1":case"binary":return QZ(this,Y,G);case"base64":return YZ(this,Y,G);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return GZ(this,Y,G);default:if(K)throw TypeError("Unknown encoding: "+T);T=(T+"").toLowerCase(),K=!0}}function oU(T,Y,G){let K=T[Y];T[Y]=T[G],T[G]=K}function $I(T,Y,G,K,L){if(T.length===0)return-1;if(typeof G==="string")K=G,G=0;else if(G>2147483647)G=2147483647;else if(G<-2147483648)G=-2147483648;if(G=+G,Number.isNaN(G))G=L?0:T.length-1;if(G<0)G=T.length+G;if(G>=T.length)if(L)return-1;else G=T.length-1;else if(G<0)if(L)G=0;else return-1;if(typeof Y==="string")Y=J0.from(Y,K);if(J0.isBuffer(Y)){if(Y.length===0)return-1;return YI(T,Y,G,K,L)}else if(typeof Y==="number"){if(Y=Y&255,typeof Uint8Array.prototype.indexOf==="function")if(L)return Uint8Array.prototype.indexOf.call(T,Y,G);else return Uint8Array.prototype.lastIndexOf.call(T,Y,G);return YI(T,[Y],G,K,L)}throw TypeError("val must be string, number or Buffer")}function YI(T,Y,G,K,L){let W=1,O=T.length,z=Y.length;if(K!==void 0){if(K=String(K).toLowerCase(),K==="ucs2"||K==="ucs-2"||K==="utf16le"||K==="utf-16le"){if(T.length<2||Y.length<2)return-1;W=2,O/=2,z/=2,G/=2}}function q(C,F){if(W===1)return C[F];else return C.readUInt16BE(F*W)}let D;if(L){let C=-1;for(D=G;DO)G=O-z;for(D=G;D>=0;D--){let C=!0;for(let F=0;FL)K=L;let W=Y.length;if(K>W/2)K=W/2;let O;for(O=0;O239?4:W>223?3:W>191?2:1;if(L+z<=G){let q,D,C,F;switch(z){case 1:if(W<128)O=W;break;case 2:if(q=T[L+1],(q&192)===128){if(F=(W&31)<<6|q&63,F>127)O=F}break;case 3:if(q=T[L+1],D=T[L+2],(q&192)===128&&(D&192)===128){if(F=(W&15)<<12|(q&63)<<6|D&63,F>2047&&(F<55296||F>57343))O=F}break;case 4:if(q=T[L+1],D=T[L+2],C=T[L+3],(q&192)===128&&(D&192)===128&&(C&192)===128){if(F=(W&15)<<18|(q&63)<<12|(D&63)<<6|C&63,F>65535&&F<1114112)O=F}}}if(O===null)O=65533,z=1;else if(O>65535)O-=65536,K.push(O>>>10&1023|55296),O=56320|O&1023;K.push(O),L+=z}return ZZ(K)}function ZZ(T){let Y=T.length;if(Y<=ZI)return String.fromCharCode.apply(String,T);let G="",K=0;while(KK)G=K;let L="";for(let W=Y;WG)throw RangeError("Trying to access beyond buffer length")}function MU(T,Y,G,K,L,W){if(!J0.isBuffer(T))throw TypeError('"buffer" argument must be a Buffer instance');if(Y>L||YT.length)throw RangeError("Index out of range")}function FI(T,Y,G,K,L){DI(Y,K,L,T,G,7);let W=Number(Y&BigInt(4294967295));T[G++]=W,W=W>>8,T[G++]=W,W=W>>8,T[G++]=W,W=W>>8,T[G++]=W;let O=Number(Y>>BigInt(32)&BigInt(4294967295));return T[G++]=O,O=O>>8,T[G++]=O,O=O>>8,T[G++]=O,O=O>>8,T[G++]=O,G}function WI(T,Y,G,K,L){DI(Y,K,L,T,G,7);let W=Number(Y&BigInt(4294967295));T[G+7]=W,W=W>>8,T[G+6]=W,W=W>>8,T[G+5]=W,W=W>>8,T[G+4]=W;let O=Number(Y>>BigInt(32)&BigInt(4294967295));return T[G+3]=O,O=O>>8,T[G+2]=O,O=O>>8,T[G+1]=O,O=O>>8,T[G]=O,G+8}function HI(T,Y,G,K,L,W){if(G+K>T.length)throw RangeError("Index out of range");if(G<0)throw RangeError("Index out of range")}function RI(T,Y,G,K,L){if(Y=+Y,G=G>>>0,!L)HI(T,Y,G,4,340282346638528860000000000000000000000,-340282346638528860000000000000000000000);return QI(T,Y,G,K,23,4),G+4}function CI(T,Y,G,K,L){if(Y=+Y,G=G>>>0,!L)HI(T,Y,G,8,179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);return QI(T,Y,G,K,52,8),G+8}function OI(T){let Y="",G=T.length,K=T[0]==="-"?1:0;for(;G>=K+4;G-=3)Y=`_${T.slice(G-3,G)}${Y}`;return`${T.slice(0,G)}${Y}`}function VZ(T,Y,G){if(iU(Y,"offset"),T[Y]===void 0||T[Y+G]===void 0)QE(Y,T.length-(G+1))}function DI(T,Y,G,K,L,W){if(T>G||T3)if(Y===0||Y===BigInt(0))z=`>= 0${O} and < 2${O} ** ${(W+1)*8}${O}`;else z=`>= -(2${O} ** ${(W+1)*8-1}${O}) and < 2 ** ${(W+1)*8-1}${O}`;else z=`>= ${Y}${O} and <= ${G}${O}`;throw new EX("value",z,T)}VZ(K,L,W)}function iU(T,Y){if(typeof T!=="number")throw new sY(Y,"number",T)}function QE(T,Y,G){if(Math.floor(T)!==T)throw iU(T,G),new EX(G||"offset","an integer",T);if(Y<0)throw new mY;throw new EX(G||"offset",`>= ${G?1:0} and <= ${Y}`,T)}function LZ(T){if(T=T.split("=")[0],T=T.trim().replace(AZ,""),T.length<2)return"";while(T.length%4!==0)T=T+"=";return T}function TX(T,Y){Y=Y||1/0;let G,K=T.length,L=null,W=[];for(let O=0;O55295&&G<57344){if(!L){if(G>56319){if((Y-=3)>-1)W.push(239,191,189);continue}else if(O+1===K){if((Y-=3)>-1)W.push(239,191,189);continue}L=G;continue}if(G<56320){if((Y-=3)>-1)W.push(239,191,189);L=G;continue}G=(L-55296<<10|G-56320)+65536}else if(L){if((Y-=3)>-1)W.push(239,191,189)}if(L=null,G<128){if((Y-=1)<0)break;W.push(G)}else if(G<2048){if((Y-=2)<0)break;W.push(G>>6|192,G&63|128)}else if(G<65536){if((Y-=3)<0)break;W.push(G>>12|224,G>>6&63|128,G&63|128)}else if(G<1114112){if((Y-=4)<0)break;W.push(G>>18|240,G>>12&63|128,G>>6&63|128,G&63|128)}else throw Error("Invalid code point")}return W}function $Z(T){let Y=[];for(let G=0;G>8,L=G%256,W.push(L),W.push(K)}return W}function zI(T){return pY(LZ(T))}function _E(T,Y,G,K){let L;for(L=0;L=Y.length||L>=T.length)break;Y[L+G]=T[L]}return L}function BU(T,Y){return T instanceof Y||T!=null&&T.constructor!=null&&T.constructor.name!=null&&T.constructor.name===Y.name}function hU(T){return typeof BigInt>"u"?WZ:T}function WZ(){throw Error("BigInt not supported")}function QX(T){return()=>{throw Error(T+" is not implemented for node:buffer browser polyfill")}}var NU,kU,UX="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",lU,XI,TI,JI=50,OE=2147483647,GI=536870888,bY,dY,lY,oY,nY,mY,sY,EX,ZI=4096,AZ,FZ,HZ,RZ,CZ=(T)=>{for(let Y of T)if(Y.charCodeAt(0)>127)return!1;return!0},DZ,zZ;var FU=GU(()=>{NU=[],kU=[];for(lU=0,XI=UX.length;lU4294967296)L=OI(String(G));else if(typeof G==="bigint"){if(L=String(G),G>BigInt(2)**BigInt(32)||G<-(BigInt(2)**BigInt(32)))L=OI(L);L+="n"}return K+=` It must be ${Y}. Received ${L}`,K},RangeError);Object.defineProperty(J0.prototype,"parent",{enumerable:!0,get:function(){if(!J0.isBuffer(this))return;return this.buffer}});Object.defineProperty(J0.prototype,"offset",{enumerable:!0,get:function(){if(!J0.isBuffer(this))return;return this.byteOffset}});J0.poolSize=8192;J0.from=function(T,Y,G){return VI(T,Y,G)};Object.setPrototypeOf(J0.prototype,Uint8Array.prototype);Object.setPrototypeOf(J0,Uint8Array);J0.alloc=function(T,Y,G){return rY(T,Y,G)};J0.allocUnsafe=function(T){return ZX(T)};J0.allocUnsafeSlow=function(T){return ZX(T)};J0.isBuffer=function(T){return T!=null&&T._isBuffer===!0&&T!==J0.prototype};J0.compare=function(T,Y){if(BU(T,Uint8Array))T=J0.from(T,T.offset,T.byteLength);if(BU(Y,Uint8Array))Y=J0.from(Y,Y.offset,Y.byteLength);if(!J0.isBuffer(T)||!J0.isBuffer(Y))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(T===Y)return 0;let G=T.length,K=Y.length;for(let L=0,W=Math.min(G,K);LK.length){if(!J0.isBuffer(W))W=J0.from(W);W.copy(K,L)}else Uint8Array.prototype.set.call(K,W,L);else if(!J0.isBuffer(W))throw TypeError('"list" argument must be an Array of Buffers');else W.copy(K,L);L+=W.length}return K};J0.byteLength=LI;J0.prototype._isBuffer=!0;J0.prototype.swap16=function(){let T=this.length;if(T%2!==0)throw RangeError("Buffer size must be a multiple of 16-bits");for(let Y=0;YY)T+=" ... ";return""};if(TI)J0.prototype[TI]=J0.prototype.inspect;J0.prototype.compare=function(T,Y,G,K,L){if(BU(T,Uint8Array))T=J0.from(T,T.offset,T.byteLength);if(!J0.isBuffer(T))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof T);if(Y===void 0)Y=0;if(G===void 0)G=T?T.length:0;if(K===void 0)K=0;if(L===void 0)L=this.length;if(Y<0||G>T.length||K<0||L>this.length)throw RangeError("out of range index");if(K>=L&&Y>=G)return 0;if(K>=L)return-1;if(Y>=G)return 1;if(Y>>>=0,G>>>=0,K>>>=0,L>>>=0,this===T)return 0;let W=L-K,O=G-Y,z=Math.min(W,O),q=this.slice(K,L),D=T.slice(Y,G);for(let C=0;C>>0,isFinite(G)){if(G=G>>>0,K===void 0)K="utf8"}else K=G,G=void 0;else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let L=this.length-Y;if(G===void 0||G>L)G=L;if(T.length>0&&(G<0||Y<0)||Y>this.length)throw RangeError("Attempt to write outside buffer bounds");if(!K)K="utf8";let W=!1;for(;;)switch(K){case"hex":return UZ(this,T,Y,G);case"utf8":case"utf-8":return EZ(this,T,Y,G);case"ascii":case"latin1":case"binary":return XZ(this,T,Y,G);case"base64":return IZ(this,T,Y,G);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return TZ(this,T,Y,G);default:if(W)throw TypeError("Unknown encoding: "+K);K=(""+K).toLowerCase(),W=!0}};J0.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};J0.prototype.slice=function(T,Y){let G=this.length;if(T=~~T,Y=Y===void 0?G:~~Y,T<0){if(T+=G,T<0)T=0}else if(T>G)T=G;if(Y<0){if(Y+=G,Y<0)Y=0}else if(Y>G)Y=G;if(Y>>0,Y=Y>>>0,!G)$U(T,Y,this.length);let K=this[T],L=1,W=0;while(++W>>0,Y=Y>>>0,!G)$U(T,Y,this.length);let K=this[T+--Y],L=1;while(Y>0&&(L*=256))K+=this[T+--Y]*L;return K};J0.prototype.readUint8=J0.prototype.readUInt8=function(T,Y){if(T=T>>>0,!Y)$U(T,1,this.length);return this[T]};J0.prototype.readUint16LE=J0.prototype.readUInt16LE=function(T,Y){if(T=T>>>0,!Y)$U(T,2,this.length);return this[T]|this[T+1]<<8};J0.prototype.readUint16BE=J0.prototype.readUInt16BE=function(T,Y){if(T=T>>>0,!Y)$U(T,2,this.length);return this[T]<<8|this[T+1]};J0.prototype.readUint32LE=J0.prototype.readUInt32LE=function(T,Y){if(T=T>>>0,!Y)$U(T,4,this.length);return(this[T]|this[T+1]<<8|this[T+2]<<16)+this[T+3]*16777216};J0.prototype.readUint32BE=J0.prototype.readUInt32BE=function(T,Y){if(T=T>>>0,!Y)$U(T,4,this.length);return this[T]*16777216+(this[T+1]<<16|this[T+2]<<8|this[T+3])};J0.prototype.readBigUInt64LE=hU(function(T){T=T>>>0,iU(T,"offset");let Y=this[T],G=this[T+7];if(Y===void 0||G===void 0)QE(T,this.length-8);let K=Y+this[++T]*256+this[++T]*65536+this[++T]*16777216,L=this[++T]+this[++T]*256+this[++T]*65536+G*16777216;return BigInt(K)+(BigInt(L)<>>0,iU(T,"offset");let Y=this[T],G=this[T+7];if(Y===void 0||G===void 0)QE(T,this.length-8);let K=Y*16777216+this[++T]*65536+this[++T]*256+this[++T],L=this[++T]*16777216+this[++T]*65536+this[++T]*256+G;return(BigInt(K)<>>0,Y=Y>>>0,!G)$U(T,Y,this.length);let K=this[T],L=1,W=0;while(++W=L)K-=Math.pow(2,8*Y);return K};J0.prototype.readIntBE=function(T,Y,G){if(T=T>>>0,Y=Y>>>0,!G)$U(T,Y,this.length);let K=Y,L=1,W=this[T+--K];while(K>0&&(L*=256))W+=this[T+--K]*L;if(L*=128,W>=L)W-=Math.pow(2,8*Y);return W};J0.prototype.readInt8=function(T,Y){if(T=T>>>0,!Y)$U(T,1,this.length);if(!(this[T]&128))return this[T];return(255-this[T]+1)*-1};J0.prototype.readInt16LE=function(T,Y){if(T=T>>>0,!Y)$U(T,2,this.length);let G=this[T]|this[T+1]<<8;return G&32768?G|4294901760:G};J0.prototype.readInt16BE=function(T,Y){if(T=T>>>0,!Y)$U(T,2,this.length);let G=this[T+1]|this[T]<<8;return G&32768?G|4294901760:G};J0.prototype.readInt32LE=function(T,Y){if(T=T>>>0,!Y)$U(T,4,this.length);return this[T]|this[T+1]<<8|this[T+2]<<16|this[T+3]<<24};J0.prototype.readInt32BE=function(T,Y){if(T=T>>>0,!Y)$U(T,4,this.length);return this[T]<<24|this[T+1]<<16|this[T+2]<<8|this[T+3]};J0.prototype.readBigInt64LE=hU(function(T){T=T>>>0,iU(T,"offset");let Y=this[T],G=this[T+7];if(Y===void 0||G===void 0)QE(T,this.length-8);let K=this[T+4]+this[T+5]*256+this[T+6]*65536+(G<<24);return(BigInt(K)<>>0,iU(T,"offset");let Y=this[T],G=this[T+7];if(Y===void 0||G===void 0)QE(T,this.length-8);let K=(Y<<24)+this[++T]*65536+this[++T]*256+this[++T];return(BigInt(K)<>>0,!Y)$U(T,4,this.length);return PE(this,T,!0,23,4)};J0.prototype.readFloatBE=function(T,Y){if(T=T>>>0,!Y)$U(T,4,this.length);return PE(this,T,!1,23,4)};J0.prototype.readDoubleLE=function(T,Y){if(T=T>>>0,!Y)$U(T,8,this.length);return PE(this,T,!0,52,8)};J0.prototype.readDoubleBE=function(T,Y){if(T=T>>>0,!Y)$U(T,8,this.length);return PE(this,T,!1,52,8)};J0.prototype.writeUintLE=J0.prototype.writeUIntLE=function(T,Y,G,K){if(T=+T,Y=Y>>>0,G=G>>>0,!K){let O=Math.pow(2,8*G)-1;MU(this,T,Y,G,O,0)}let L=1,W=0;this[Y]=T&255;while(++W>>0,G=G>>>0,!K){let O=Math.pow(2,8*G)-1;MU(this,T,Y,G,O,0)}let L=G-1,W=1;this[Y+L]=T&255;while(--L>=0&&(W*=256))this[Y+L]=T/W&255;return Y+G};J0.prototype.writeUint8=J0.prototype.writeUInt8=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,1,255,0);return this[Y]=T&255,Y+1};J0.prototype.writeUint16LE=J0.prototype.writeUInt16LE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,2,65535,0);return this[Y]=T&255,this[Y+1]=T>>>8,Y+2};J0.prototype.writeUint16BE=J0.prototype.writeUInt16BE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,2,65535,0);return this[Y]=T>>>8,this[Y+1]=T&255,Y+2};J0.prototype.writeUint32LE=J0.prototype.writeUInt32LE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,4,4294967295,0);return this[Y+3]=T>>>24,this[Y+2]=T>>>16,this[Y+1]=T>>>8,this[Y]=T&255,Y+4};J0.prototype.writeUint32BE=J0.prototype.writeUInt32BE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,4,4294967295,0);return this[Y]=T>>>24,this[Y+1]=T>>>16,this[Y+2]=T>>>8,this[Y+3]=T&255,Y+4};J0.prototype.writeBigUInt64LE=hU(function(T,Y=0){return FI(this,T,Y,BigInt(0),BigInt("0xffffffffffffffff"))});J0.prototype.writeBigUInt64BE=hU(function(T,Y=0){return WI(this,T,Y,BigInt(0),BigInt("0xffffffffffffffff"))});J0.prototype.writeIntLE=function(T,Y,G,K){if(T=+T,Y=Y>>>0,!K){let z=Math.pow(2,8*G-1);MU(this,T,Y,G,z-1,-z)}let L=0,W=1,O=0;this[Y]=T&255;while(++L>0)-O&255}return Y+G};J0.prototype.writeIntBE=function(T,Y,G,K){if(T=+T,Y=Y>>>0,!K){let z=Math.pow(2,8*G-1);MU(this,T,Y,G,z-1,-z)}let L=G-1,W=1,O=0;this[Y+L]=T&255;while(--L>=0&&(W*=256)){if(T<0&&O===0&&this[Y+L+1]!==0)O=1;this[Y+L]=(T/W>>0)-O&255}return Y+G};J0.prototype.writeInt8=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,1,127,-128);if(T<0)T=255+T+1;return this[Y]=T&255,Y+1};J0.prototype.writeInt16LE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,2,32767,-32768);return this[Y]=T&255,this[Y+1]=T>>>8,Y+2};J0.prototype.writeInt16BE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,2,32767,-32768);return this[Y]=T>>>8,this[Y+1]=T&255,Y+2};J0.prototype.writeInt32LE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,4,2147483647,-2147483648);return this[Y]=T&255,this[Y+1]=T>>>8,this[Y+2]=T>>>16,this[Y+3]=T>>>24,Y+4};J0.prototype.writeInt32BE=function(T,Y,G){if(T=+T,Y=Y>>>0,!G)MU(this,T,Y,4,2147483647,-2147483648);if(T<0)T=4294967295+T+1;return this[Y]=T>>>24,this[Y+1]=T>>>16,this[Y+2]=T>>>8,this[Y+3]=T&255,Y+4};J0.prototype.writeBigInt64LE=hU(function(T,Y=0){return FI(this,T,Y,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});J0.prototype.writeBigInt64BE=hU(function(T,Y=0){return WI(this,T,Y,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});J0.prototype.writeFloatLE=function(T,Y,G){return RI(this,T,Y,!0,G)};J0.prototype.writeFloatBE=function(T,Y,G){return RI(this,T,Y,!1,G)};J0.prototype.writeDoubleLE=function(T,Y,G){return CI(this,T,Y,!0,G)};J0.prototype.writeDoubleBE=function(T,Y,G){return CI(this,T,Y,!1,G)};J0.prototype.copy=function(T,Y,G,K){if(!J0.isBuffer(T))throw TypeError("argument should be a Buffer");if(!G)G=0;if(!K&&K!==0)K=this.length;if(Y>=T.length)Y=T.length;if(!Y)Y=0;if(K>0&&K=this.length)throw RangeError("Index out of range");if(K<0)throw RangeError("sourceEnd out of bounds");if(K>this.length)K=this.length;if(T.length-Y>>0,G=G===void 0?this.length:G>>>0,!T)T=0;let L;if(typeof T==="number")for(L=Y;LBZ,promisify:()=>kI,log:()=>qI,isUndefined:()=>UE,isSymbol:()=>gZ,isString:()=>xE,isRegExp:()=>kE,isPrimitive:()=>wZ,isObject:()=>EE,isNumber:()=>MI,isNullOrUndefined:()=>xZ,isNull:()=>BE,isFunction:()=>jE,isError:()=>vE,isDate:()=>AX,isBuffer:()=>yZ,isBoolean:()=>$X,isArray:()=>SI,inspect:()=>nU,inherits:()=>PI,format:()=>LX,deprecate:()=>MZ,default:()=>pZ,debuglog:()=>qZ,callbackifyOnRejected:()=>WX,callbackify:()=>vI,_extend:()=>FX,TextEncoder:()=>jI,TextDecoder:()=>NI});function LX(T,...Y){if(!xE(T)){var G=[T];for(var K=0;K=L)return z;switch(z){case"%s":return String(Y[K++]);case"%d":return Number(Y[K++]);case"%j":try{return JSON.stringify(Y[K++])}catch(q){return"[Circular]"}default:return z}});for(var O=Y[K];K"u"||process?.noDeprecation===!0)return T;var G=!1;function K(...L){if(!G){if(process.throwDeprecation)throw Error(Y);else if(process.traceDeprecation)console.trace(Y);else console.error(Y);G=!0}return T.apply(this,...L)}return K}function PZ(T,Y){var G=nU.styles[Y];if(G)return"\x1B["+nU.colors[G][0]+"m"+T+"\x1B["+nU.colors[G][1]+"m";else return T}function _Z(T,Y){return T}function kZ(T){var Y={};return T.forEach(function(G,K){Y[G]=!0}),Y}function NE(T,Y,G){if(T.customInspect&&Y&&jE(Y.inspect)&&Y.inspect!==nU&&!(Y.constructor&&Y.constructor.prototype===Y)){var K=Y.inspect(G,T);if(!xE(K))K=NE(T,K,G);return K}var L=vZ(T,Y);if(L)return L;var W=Object.keys(Y),O=kZ(W);if(T.showHidden)W=Object.getOwnPropertyNames(Y);if(vE(Y)&&(W.indexOf("message")>=0||W.indexOf("description")>=0))return JX(Y);if(W.length===0){if(jE(Y)){var z=Y.name?": "+Y.name:"";return T.stylize("[Function"+z+"]","special")}if(kE(Y))return T.stylize(RegExp.prototype.toString.call(Y),"regexp");if(AX(Y))return T.stylize(Date.prototype.toString.call(Y),"date");if(vE(Y))return JX(Y)}var q="",D=!1,C=["{","}"];if(SI(Y))D=!0,C=["[","]"];if(jE(Y)){var F=Y.name?": "+Y.name:"";q=" [Function"+F+"]"}if(kE(Y))q=" "+RegExp.prototype.toString.call(Y);if(AX(Y))q=" "+Date.prototype.toUTCString.call(Y);if(vE(Y))q=" "+JX(Y);if(W.length===0&&(!D||Y.length==0))return C[0]+q+C[1];if(G<0)if(kE(Y))return T.stylize(RegExp.prototype.toString.call(Y),"regexp");else return T.stylize("[Object]","special");T.seen.push(Y);var R;if(D)R=jZ(T,Y,G,O,W);else R=W.map(function(M){return VX(T,Y,G,O,M,D)});return T.seen.pop(),NZ(R,q,C)}function vZ(T,Y){if(UE(Y))return T.stylize("undefined","undefined");if(xE(Y)){var G="'"+JSON.stringify(Y).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return T.stylize(G,"string")}if(MI(Y))return T.stylize(""+Y,"number");if($X(Y))return T.stylize(""+Y,"boolean");if(BE(Y))return T.stylize("null","null")}function JX(T){return"["+Error.prototype.toString.call(T)+"]"}function jZ(T,Y,G,K,L){var W=[];for(var O=0,z=Y.length;O-1)if(W)z=z.split(` +`).map(function(D){return" "+D}).join(` +`).slice(2);else z=` +`+z.split(` +`).map(function(D){return" "+D}).join(` +`)}else z=T.stylize("[Circular]","special");if(UE(O)){if(W&&L.match(/^\d+$/))return z;if(O=JSON.stringify(""+L),O.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/))O=O.slice(1,-1),O=T.stylize(O,"name");else O=O.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),O=T.stylize(O,"string")}return O+": "+z}function NZ(T,Y,G){var K=0,L=T.reduce(function(W,O){if(K++,O.indexOf(` +`)>=0)K++;return W+O.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(L>60)return G[0]+(Y===""?"":Y+` + `)+" "+T.join(`, + `)+" "+G[1];return G[0]+Y+" "+T.join(", ")+" "+G[1]}function SI(T){return Array.isArray(T)}function $X(T){return typeof T==="boolean"}function BE(T){return T===null}function xZ(T){return T==null}function MI(T){return typeof T==="number"}function xE(T){return typeof T==="string"}function gZ(T){return typeof T==="symbol"}function UE(T){return T===void 0}function kE(T){return EE(T)&&KX(T)==="[object RegExp]"}function EE(T){return typeof T==="object"&&T!==null}function AX(T){return EE(T)&&KX(T)==="[object Date]"}function vE(T){return EE(T)&&(KX(T)==="[object Error]"||T instanceof Error)}function jE(T){return typeof T==="function"}function wZ(T){return T===null||typeof T==="boolean"||typeof T==="number"||typeof T==="string"||typeof T==="symbol"||typeof T>"u"}function yZ(T){return T instanceof Buffer}function KX(T){return Object.prototype.toString.call(T)}function GX(T){return T<10?"0"+T.toString(10):T.toString(10)}function cZ(){var T=new Date,Y=[GX(T.getHours()),GX(T.getMinutes()),GX(T.getSeconds())].join(":");return[T.getDate(),fZ[T.getMonth()],Y].join(" ")}function qI(...T){console.log("%s - %s",cZ(),LX.apply(null,T))}function PI(T,Y){if(Y)T.super_=Y,T.prototype=Object.create(Y.prototype,{constructor:{value:T,enumerable:!1,writable:!0,configurable:!0}})}function FX(T,Y){if(!Y||!EE(Y))return T;var G=Object.keys(Y),K=G.length;while(K--)T[G[K]]=Y[G[K]];return T}function _I(T,Y){return Object.prototype.hasOwnProperty.call(T,Y)}function WX(T,Y){if(!T){var G=Error("Promise was rejected with a falsy value");G.reason=T,T=G}return Y(T)}function vI(T){if(typeof T!=="function")throw TypeError('The "original" argument must be of type Function');function Y(...G){var K=G.pop();if(typeof K!=="function")throw TypeError("The last argument must be of type Function");var L=this,W=function(...O){return K.apply(L,...O)};T.apply(this,G).then(function(O){process.nextTick(W.bind(null,null,O))},function(O){process.nextTick(WX.bind(null,O,W))})}return Object.setPrototypeOf(Y,Object.getPrototypeOf(T)),Object.defineProperties(Y,Object.getOwnPropertyDescriptors(T)),Y}var SZ,qZ,nU,BZ=()=>{},fZ,kI,jI,NI,pZ;var xI=GU(()=>{SZ=/%[sdj%]/g;qZ=((T={},Y={},G)=>((G=typeof process<"u"&&!1)&&(G=G.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".*").replace(/,/g,"$|^").toUpperCase()),Y=new RegExp("^"+G+"$","i"),(K)=>{if(K=K.toUpperCase(),!T[K])if(Y.test(K))T[K]=function(...L){console.error("%s: %s",K,pid,LX.apply(null,...L))};else T[K]=function(){};return T[K]}))(),nU=((T)=>(T.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},T.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},T.custom=Symbol.for("nodejs.util.inspect.custom"),T))(function(T,Y,...G){var K={seen:[],stylize:_Z};if(G.length>=1)K.depth=G[0];if(G.length>=2)K.colors=G[1];if($X(Y))K.showHidden=Y;else if(Y)FX(K,Y);if(UE(K.showHidden))K.showHidden=!1;if(UE(K.depth))K.depth=2;if(UE(K.colors))K.colors=!1;if(K.colors)K.stylize=PZ;return NE(K,T,K.depth)});fZ=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];kI=((T)=>(T.custom=Symbol.for("nodejs.util.promisify.custom"),T))(function(T){if(typeof T!=="function")throw TypeError('The "original" argument must be of type Function');if(kCustomPromisifiedSymbol&&T[kCustomPromisifiedSymbol]){var Y=T[kCustomPromisifiedSymbol];if(typeof Y!=="function")throw TypeError('The "nodejs.util.promisify.custom" argument must be of type Function');return Object.defineProperty(Y,kCustomPromisifiedSymbol,{value:Y,enumerable:!1,writable:!1,configurable:!0}),Y}function Y(...G){var K,L,W=new Promise(function(O,z){K=O,L=z});G.push(function(O,z){if(O)L(O);else K(z)});try{T.apply(this,G)}catch(O){L(O)}return W}if(Object.setPrototypeOf(Y,Object.getPrototypeOf(T)),kCustomPromisifiedSymbol)Object.defineProperty(Y,kCustomPromisifiedSymbol,{value:Y,enumerable:!1,writable:!1,configurable:!0});return Object.defineProperties(Y,Object.getOwnPropertyDescriptors(T))});({TextEncoder:jI,TextDecoder:NI}=globalThis),pZ={TextEncoder:jI,TextDecoder:NI,promisify:kI,log:qI,inherits:PI,_extend:FX,callbackifyOnRejected:WX,callbackify:vI}});var GE={};jU(GE,{setMaxListeners:()=>lI,once:()=>bI,listenerCount:()=>oI,init:()=>uU,getMaxListeners:()=>mI,getEventListeners:()=>dI,default:()=>sZ,captureRejectionSymbol:()=>cI,addAbortListener:()=>sI,EventEmitter:()=>uU});function pI(T,Y){var{_events:G}=T;if(Y[0]??=Error("Unhandled error."),!G)throw Y[0];var K=G[fI];if(K)for(var L of wI.call(K))L.apply(T,Y);var W=G.error;if(!W)throw Y[0];for(var L of wI.call(W))L.apply(T,Y);return!0}function bZ(T,Y,G,K){Y.then(void 0,function(L){queueMicrotask(()=>dZ(T,L,G,K))})}function dZ(T,Y,G,K){if(typeof T[gI]==="function")T[gI](Y,G,...K);else try{T[mU]=!1,T.emit("error",Y)}finally{T[mU]=!0}}function hI(T,Y,G){G.warned=!0;let K=Error(`Possible EventEmitter memory leak detected. ${G.length} ${String(Y)} listeners added to [${T.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);K.name="MaxListenersExceededWarning",K.emitter=T,K.type=Y,K.count=G.length,console.warn(K)}function uI(T,Y,...G){this.removeListener(T,Y),Y.apply(this,G)}function bI(T,Y,G){var K=G?.signal;if(nI(K,"options.signal"),K?.aborted)throw new HX(void 0,{cause:K?.reason});let{resolve:L,reject:W,promise:O}=$newPromiseCapability(Promise),z=(C)=>{if(T.removeListener(Y,q),K!=null)gE(K,"abort",D);W(C)},q=(...C)=>{if(typeof T.removeListener==="function")T.removeListener("error",z);if(K!=null)gE(K,"abort",D);L(C)};if(yI(T,Y,q,{once:!0}),Y!=="error"&&typeof T.once==="function")T.once("error",z);function D(){gE(T,Y,q),gE(T,"error",z),W(new HX(void 0,{cause:K?.reason}))}if(K!=null)yI(K,"abort",D,{once:!0});return O}function dI(T,Y){return T.listeners(Y)}function lI(T,...Y){CX(T,"setMaxListeners",0);var G;if(Y&&(G=Y.length))for(let K=0;KK||(G!=null||K!=null)&&Number.isNaN(T))throw nZ(Y,`${G!=null?`>= ${G}`:""}${G!=null&&K!=null?" && ":""}${K!=null?`<= ${K}`:""}`,T)}function JE(T){if(typeof T!=="function")throw TypeError("The listener must be a function")}function mZ(T,Y){if(typeof T!=="boolean")throw XE(Y,"boolean",T)}function mI(T){return T?._maxListeners??sU}function sI(T,Y){if(T===void 0)throw XE("signal","AbortSignal",T);if(nI(T,"signal"),typeof Y!=="function")throw XE("listener","function",Y);let G;if(T.aborted)queueMicrotask(()=>Y());else T.addEventListener("abort",Y,{__proto__:null,once:!0}),G=()=>{T.removeEventListener("abort",Y)};return{__proto__:null,[Symbol.dispose](){G?.()}}}var RX,mU,fI,hZ,uZ,gI,cI,wI,sU=10,uU=function(T){if(this._events===void 0||this._events===this.__proto__._events)this._events={__proto__:null},this._eventsCount=0;if(this._maxListeners??=void 0,this[mU]=T?.captureRejections?Boolean(T?.captureRejections):l0[mU])this.emit=oZ},l0,lZ=function(T,...Y){if(T==="error")return pI(this,Y);var{_events:G}=this;if(G===void 0)return!1;var K=G[T];if(K===void 0)return!1;let L=K.length>1?K.slice():K;for(let W=0,{length:O}=L;W1?K.slice():K;for(let W=0,{length:O}=L;W{RX=Symbol.for,mU=Symbol("kCapture"),fI=RX("events.errorMonitor"),hZ=Symbol("events.maxEventTargetListeners"),uZ=Symbol("events.maxEventTargetListenersWarned"),gI=RX("nodejs.rejection"),cI=RX("nodejs.rejection"),wI=Array.prototype.slice,l0=uU.prototype={};l0._events=void 0;l0._eventsCount=0;l0._maxListeners=void 0;l0.setMaxListeners=function(T){return CX(T,"setMaxListeners",0),this._maxListeners=T,this};l0.constructor=uU;l0.getMaxListeners=function(){return this?._maxListeners??sU};l0.emit=lZ;l0.addListener=function(T,Y){JE(Y);var G=this._events;if(!G)G=this._events={__proto__:null},this._eventsCount=0;else if(G.newListener)this.emit("newListener",T,Y.listener??Y);var K=G[T];if(!K)G[T]=[Y],this._eventsCount++;else{K.push(Y);var L=this._maxListeners??sU;if(L>0&&K.length>L&&!K.warned)hI(this,T,K)}return this};l0.on=l0.addListener;l0.prependListener=function(T,Y){JE(Y);var G=this._events;if(!G)G=this._events={__proto__:null},this._eventsCount=0;else if(G.newListener)this.emit("newListener",T,Y.listener??Y);var K=G[T];if(!K)G[T]=[Y],this._eventsCount++;else{K.unshift(Y);var L=this._maxListeners??sU;if(L>0&&K.length>L&&!K.warned)hI(this,T,K)}return this};l0.once=function(T,Y){JE(Y);let G=uI.bind(this,T,Y);return G.listener=Y,this.addListener(T,G),this};l0.prependOnceListener=function(T,Y){JE(Y);let G=uI.bind(this,T,Y);return G.listener=Y,this.prependListener(T,G),this};l0.removeListener=function(T,Y){JE(Y);var{_events:G}=this;if(!G)return this;var K=G[T];if(!K)return this;var L=K.length;let W=-1;for(let O=L-1;O>=0;O--)if(K[O]===Y||K[O].listener===Y){W=O;break}if(W<0)return this;if(W===0)K.shift();else K.splice(W,1);if(K.length===0)delete G[T],this._eventsCount--;return this};l0.off=l0.removeListener;l0.removeAllListeners=function(T){var{_events:Y}=this;if(T&&Y){if(Y[T])delete Y[T],this._eventsCount--}else this._events={__proto__:null};return this};l0.listeners=function(T){var{_events:Y}=this;if(!Y)return[];var G=Y[T];if(!G)return[];return G.map((K)=>K.listener??K)};l0.rawListeners=function(T){var{_events:Y}=this;if(!Y)return[];var G=Y[T];if(!G)return[];return G.slice()};l0.listenerCount=function(T){var{_events:Y}=this;if(!Y)return 0;return Y[T]?.length??0};l0.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};l0[mU]=!1;HX=class HX extends Error{constructor(T="The operation was aborted",Y=void 0){if(Y!==void 0&&typeof Y!=="object")throw XE("options","Object",Y);super(T,Y);this.code="ABORT_ERR",this.name="AbortError"}};Object.defineProperties(uU,{captureRejections:{get(){return l0[mU]},set(T){mZ(T,"EventEmitter.captureRejections"),l0[mU]=T},enumerable:!0},defaultMaxListeners:{enumerable:!0,get:()=>{return sU},set:(T)=>{CX(T,"defaultMaxListeners",0),sU=T}},kMaxEventTargetListeners:{value:hZ,enumerable:!1,configurable:!1,writable:!1},kMaxEventTargetListenersWarned:{value:uZ,enumerable:!1,configurable:!1,writable:!1}});Object.assign(uU,{once:bI,getEventListeners:dI,getMaxListeners:mI,setMaxListeners:lI,EventEmitter:uU,usingDomains:!1,captureRejectionSymbol:cI,errorMonitor:fI,addAbortListener:sI,init:uU,listenerCount:oI});sZ=uU});var MX=gY((KV,XT)=>{var u0=(T,Y)=>()=>(Y||T((Y={exports:{}}).exports,Y),Y.exports),o0=u0((T,Y)=>{class G extends Error{constructor(K){if(!Array.isArray(K))throw TypeError(`Expected input to be an Array, got ${typeof K}`);let L="";for(let W=0;W{Y.exports={format(G,...K){return G.replace(/%([sdifj])/g,function(...[L,W]){let O=K.shift();if(W==="f")return O.toFixed(6);else if(W==="j")return JSON.stringify(O);else if(W==="s"&&typeof O==="object")return`${O.constructor!==Object?O.constructor.name:""} {}`.trim();else return O.toString()})},inspect(G){switch(typeof G){case"string":if(G.includes("'")){if(!G.includes('"'))return`"${G}"`;else if(!G.includes("`")&&!G.includes("${"))return`\`${G}\``}return`'${G}'`;case"number":if(isNaN(G))return"NaN";else if(Object.is(G,-0))return String(G);return G;case"bigint":return`${String(G)}n`;case"boolean":case"undefined":return String(G);case"object":return"{}"}}}}),zU=u0((T,Y)=>{var{format:G,inspect:K}=rI(),{AggregateError:L}=o0(),W=globalThis.AggregateError||L,O=Symbol("kIsNodeError"),z=["string","function","number","object","Function","Object","boolean","bigint","symbol"],q=/^([A-Z][a-z0-9]*)+$/,D={};function C(N,v){if(!N)throw new D.ERR_INTERNAL_ASSERTION(v)}function F(N){let v="",B=N.length,g=N[0]==="-"?1:0;for(;B>=g+4;B-=3)v=`_${N.slice(B-3,B)}${v}`;return`${N.slice(0,B)}${v}`}function R(N,v,B){if(typeof v==="function")return C(v.length<=B.length,`Code: ${N}; The provided arguments length (${B.length}) does not match the required ones (${v.length}).`),v(...B);let g=(v.match(/%[dfijoOs]/g)||[]).length;if(C(g===B.length,`Code: ${N}; The provided arguments length (${B.length}) does not match the required ones (${g}).`),B.length===0)return v;return G(v,...B)}function M(N,v,B){if(!B)B=Error;class g extends B{constructor(...y){super(R(N,v,y))}toString(){return`${this.name} [${N}]: ${this.message}`}}Object.defineProperties(g.prototype,{name:{value:B.name,writable:!0,enumerable:!1,configurable:!0},toString:{value(){return`${this.name} [${N}]: ${this.message}`},writable:!0,enumerable:!1,configurable:!0}}),g.prototype.code=N,g.prototype[O]=!0,D[N]=g}function P(N){let v="__node_internal_"+N.name;return Object.defineProperty(N,"name",{value:v}),N}function k(N,v){if(N&&v&&N!==v){if(Array.isArray(v.errors))return v.errors.push(N),v;let B=new W([v,N],v.message);return B.code=v.code,B}return N||v}class _ extends Error{constructor(N="The operation was aborted",v=void 0){if(v!==void 0&&typeof v!=="object")throw new D.ERR_INVALID_ARG_TYPE("options","Object",v);super(N,v);this.code="ABORT_ERR",this.name="AbortError"}}M("ERR_ASSERTION","%s",Error),M("ERR_INVALID_ARG_TYPE",(N,v,B)=>{if(C(typeof N==="string","'name' must be a string"),!Array.isArray(v))v=[v];let g="The ";if(N.endsWith(" argument"))g+=`${N} `;else g+=`"${N}" ${N.includes(".")?"property":"argument"} `;g+="must be ";let y=[],l=[],Y0=[];for(let Z0 of v)if(C(typeof Z0==="string","All expected entries have to be of type string"),z.includes(Z0))y.push(Z0.toLowerCase());else if(q.test(Z0))l.push(Z0);else C(Z0!=="object",'The value "object" should be written as "Object"'),Y0.push(Z0);if(l.length>0){let Z0=y.indexOf("object");if(Z0!==-1)y.splice(y,Z0,1),l.push("Object")}if(y.length>0){switch(y.length){case 1:g+=`of type ${y[0]}`;break;case 2:g+=`one of type ${y[0]} or ${y[1]}`;break;default:{let Z0=y.pop();g+=`one of type ${y.join(", ")}, or ${Z0}`}}if(l.length>0||Y0.length>0)g+=" or "}if(l.length>0){switch(l.length){case 1:g+=`an instance of ${l[0]}`;break;case 2:g+=`an instance of ${l[0]} or ${l[1]}`;break;default:{let Z0=l.pop();g+=`an instance of ${l.join(", ")}, or ${Z0}`}}if(Y0.length>0)g+=" or "}switch(Y0.length){case 0:break;case 1:if(Y0[0].toLowerCase()!==Y0[0])g+="an ";g+=`${Y0[0]}`;break;case 2:g+=`one of ${Y0[0]} or ${Y0[1]}`;break;default:{let Z0=Y0.pop();g+=`one of ${Y0.join(", ")}, or ${Z0}`}}if(B==null)g+=`. Received ${B}`;else if(typeof B==="function"&&B.name)g+=`. Received function ${B.name}`;else if(typeof B==="object"){var O0;if((O0=B.constructor)!==null&&O0!==void 0&&O0.name)g+=`. Received an instance of ${B.constructor.name}`;else{let Z0=K(B,{depth:-1});g+=`. Received ${Z0}`}}else{let Z0=K(B,{colors:!1});if(Z0.length>25)Z0=`${Z0.slice(0,25)}...`;g+=`. Received type ${typeof B} (${Z0})`}return g},TypeError),M("ERR_INVALID_ARG_VALUE",(N,v,B="is invalid")=>{let g=K(v);if(g.length>128)g=g.slice(0,128)+"...";return`The ${N.includes(".")?"property":"argument"} '${N}' ${B}. Received ${g}`},TypeError),M("ERR_INVALID_RETURN_VALUE",(N,v,B)=>{var g;let y=B!==null&&B!==void 0&&(g=B.constructor)!==null&&g!==void 0&&g.name?`instance of ${B.constructor.name}`:`type ${typeof B}`;return`Expected ${N} to be returned from the "${v}" function but got ${y}.`},TypeError),M("ERR_MISSING_ARGS",(...N)=>{C(N.length>0,"At least one arg needs to be specified");let v,B=N.length;switch(N=(Array.isArray(N)?N:[N]).map((g)=>`"${g}"`).join(" or "),B){case 1:v+=`The ${N[0]} argument`;break;case 2:v+=`The ${N[0]} and ${N[1]} arguments`;break;default:{let g=N.pop();v+=`The ${N.join(", ")}, and ${g} arguments`}break}return`${v} must be specified`},TypeError),M("ERR_OUT_OF_RANGE",(N,v,B)=>{C(v,'Missing "range" argument');let g;if(Number.isInteger(B)&&Math.abs(B)>4294967296)g=F(String(B));else if(typeof B==="bigint"){g=String(B);let y=BigInt(2)**BigInt(32);if(B>y||B<-y)g=F(g);g+="n"}else g=K(B);return`The value of "${N}" is out of range. It must be ${v}. Received ${g}`},RangeError),M("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error),M("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error),M("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error),M("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error),M("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error),M("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),M("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error),M("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error),M("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error),M("ERR_STREAM_WRITE_AFTER_END","write after end",Error),M("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError),Y.exports={AbortError:_,aggregateTwoErrors:P(k),hideStackFrames:P,codes:D}}),rZ=u0((T,Y)=>{Object.defineProperty(T,"__esModule",{value:!0});var G=new WeakMap,K=new WeakMap;function L(u){let i=G.get(u);return console.assert(i!=null,"'this' is expected an Event object, but got",u),i}function W(u){if(u.passiveListener!=null){if(typeof console<"u"&&typeof console.error==="function")console.error("Unable to preventDefault inside passive event listener invocation.",u.passiveListener);return}if(!u.event.cancelable)return;if(u.canceled=!0,typeof u.event.preventDefault==="function")u.event.preventDefault()}function O(u,i){G.set(this,{eventTarget:u,event:i,eventPhase:2,currentTarget:u,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:i.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let U=Object.keys(i);for(let I=0;I0){let u=Array(arguments.length);for(let i=0;i{Object.defineProperty(T,"__esModule",{value:!0});var G=rZ();class K extends G.EventTarget{constructor(){super();throw TypeError("AbortSignal cannot be constructed directly")}get aborted(){let C=O.get(this);if(typeof C!=="boolean")throw TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this===null?"null":typeof this}`);return C}}G.defineEventAttribute(K.prototype,"abort");function L(){let C=Object.create(K.prototype);return G.EventTarget.call(C),O.set(C,!1),C}function W(C){if(O.get(C)!==!1)return;O.set(C,!0),C.dispatchEvent({type:"abort"})}var O=new WeakMap;if(Object.defineProperties(K.prototype,{aborted:{enumerable:!0}}),typeof Symbol==="function"&&typeof Symbol.toStringTag==="symbol")Object.defineProperty(K.prototype,Symbol.toStringTag,{configurable:!0,value:"AbortSignal"});class z{constructor(){q.set(this,L())}get signal(){return D(this)}abort(){W(D(this))}}var q=new WeakMap;function D(C){let F=q.get(C);if(F==null)throw TypeError(`Expected 'this' to be an 'AbortController' object, but got ${C===null?"null":typeof C}`);return F}if(Object.defineProperties(z.prototype,{signal:{enumerable:!0},abort:{enumerable:!0}}),typeof Symbol==="function"&&typeof Symbol.toStringTag==="symbol")Object.defineProperty(z.prototype,Symbol.toStringTag,{configurable:!0,value:"AbortController"});T.AbortController=z,T.AbortSignal=K,T.default=z,Y.exports=z,Y.exports.AbortController=Y.exports.default=z,Y.exports.AbortSignal=K}),qU=u0((T,Y)=>{var G=(FU(),h0(KU)),{format:K,inspect:L}=rI(),{codes:{ERR_INVALID_ARG_TYPE:W}}=zU(),{kResistStopPropagation:O,AggregateError:z,SymbolDispose:q}=o0(),D=globalThis.AbortSignal||AE().AbortSignal,C=globalThis.AbortController||AE().AbortController,F=Object.getPrototypeOf(async function(){}).constructor,R=globalThis.Blob||G.Blob,M=typeof R<"u"?function(_){return _ instanceof R}:function(_){return!1},P=(_,N)=>{if(_!==void 0&&(_===null||typeof _!=="object"||!("aborted"in _)))throw new W(N,"AbortSignal",_)},k=(_,N)=>{if(typeof _!=="function")throw new W(N,"Function",_)};Y.exports={AggregateError:z,kEmptyObject:Object.freeze({}),once(_){let N=!1;return function(...v){if(N)return;N=!0,_.apply(this,v)}},createDeferredPromise:function(){let _,N;return{promise:new Promise((v,B)=>{_=v,N=B}),resolve:_,reject:N}},promisify(_){return new Promise((N,v)=>{_((B,...g)=>{if(B)return v(B);return N(...g)})})},debuglog(){return function(){}},format:K,inspect:L,types:{isAsyncFunction(_){return _ instanceof F},isArrayBufferView(_){return ArrayBuffer.isView(_)}},isBlob:M,deprecate(_,N){return _},addAbortListener:(VE(),h0(GE)).addAbortListener||function(_,N){if(_===void 0)throw new W("signal","AbortSignal",_);P(_,"signal"),k(N,"listener");let v;if(_.aborted)queueMicrotask(()=>N());else _.addEventListener("abort",N,{__proto__:null,once:!0,[O]:!0}),v=()=>{_.removeEventListener("abort",N)};return{__proto__:null,[q](){var B;(B=v)===null||B===void 0||B()}}},AbortSignalAny:D.any||function(_){if(_.length===1)return _[0];let N=new C,v=()=>N.abort();return _.forEach((B)=>{P(B,"signals"),B.addEventListener("abort",v,{once:!0})}),N.signal.addEventListener("abort",()=>{_.forEach((B)=>B.removeEventListener("abort",v))},{once:!0}),N.signal}},Y.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")}),LE=u0((T,Y)=>{var{ArrayIsArray:G,ArrayPrototypeIncludes:K,ArrayPrototypeJoin:L,ArrayPrototypeMap:W,NumberIsInteger:O,NumberIsNaN:z,NumberMAX_SAFE_INTEGER:q,NumberMIN_SAFE_INTEGER:D,NumberParseInt:C,ObjectPrototypeHasOwnProperty:F,RegExpPrototypeExec:R,String:M,StringPrototypeToUpperCase:P,StringPrototypeTrim:k}=o0(),{hideStackFrames:_,codes:{ERR_SOCKET_BAD_PORT:N,ERR_INVALID_ARG_TYPE:v,ERR_INVALID_ARG_VALUE:B,ERR_OUT_OF_RANGE:g,ERR_UNKNOWN_SIGNAL:y}}=zU(),{normalizeEncoding:l}=qU(),{isAsyncFunction:Y0,isArrayBufferView:O0}=qU().types,Z0={};function u(c){return c===(c|0)}function i(c){return c===c>>>0}var U=/^[0-7]+$/,I="must be a 32-bit unsigned integer or an octal string";function Q(c,o,x0){if(typeof c>"u")c=x0;if(typeof c==="string"){if(R(U,c)===null)throw new B(o,c,I);c=C(c,8)}return A(c,o),c}var X=_((c,o,x0=D,s=q)=>{if(typeof c!=="number")throw new v(o,"number",c);if(!O(c))throw new g(o,"an integer",c);if(cs)throw new g(o,`>= ${x0} && <= ${s}`,c)}),Z=_((c,o,x0=-2147483648,s=2147483647)=>{if(typeof c!=="number")throw new v(o,"number",c);if(!O(c))throw new g(o,"an integer",c);if(cs)throw new g(o,`>= ${x0} && <= ${s}`,c)}),A=_((c,o,x0=!1)=>{if(typeof c!=="number")throw new v(o,"number",c);if(!O(c))throw new g(o,"an integer",c);let s=x0?1:0,X0=4294967295;if(cX0)throw new g(o,`>= ${s} && <= ${X0}`,c)});function $(c,o){if(typeof c!=="string")throw new v(o,"string",c)}function J(c,o,x0=void 0,s){if(typeof c!=="number")throw new v(o,"number",c);if(x0!=null&&cs||(x0!=null||s!=null)&&z(c))throw new g(o,`${x0!=null?`>= ${x0}`:""}${x0!=null&&s!=null?" && ":""}${s!=null?`<= ${s}`:""}`,c)}var E=_((c,o,x0)=>{if(!K(x0,c)){let s="must be one of: "+L(W(x0,(X0)=>typeof X0==="string"?`'${X0}'`:M(X0)),", ");throw new B(o,c,s)}});function V(c,o){if(typeof c!=="boolean")throw new v(o,"boolean",c)}function S(c,o,x0){return c==null||!F(c,o)?x0:c[o]}var H=_((c,o,x0=null)=>{let s=S(x0,"allowArray",!1),X0=S(x0,"allowFunction",!1);if(!S(x0,"nullable",!1)&&c===null||!s&&G(c)||typeof c!=="object"&&(!X0||typeof c!=="function"))throw new v(o,"Object",c)}),j=_((c,o)=>{if(c!=null&&typeof c!=="object"&&typeof c!=="function")throw new v(o,"a dictionary",c)}),w=_((c,o,x0=0)=>{if(!G(c))throw new v(o,"Array",c);if(c.length{if(!O0(c))throw new v(o,["Buffer","TypedArray","DataView"],c)});function I0(c,o){let x0=l(o),s=c.length;if(x0==="hex"&&s%2!==0)throw new B("encoding",o,`is invalid for data of length ${s}`)}function m(c,o="Port",x0=!0){if(typeof c!=="number"&&typeof c!=="string"||typeof c==="string"&&k(c).length===0||+c!==+c>>>0||c>65535||c===0&&!x0)throw new N(o,c,x0);return c|0}var U0=_((c,o)=>{if(c!==void 0&&(c===null||typeof c!=="object"||!("aborted"in c)))throw new v(o,"AbortSignal",c)}),g0=_((c,o)=>{if(typeof c!=="function")throw new v(o,"Function",c)}),f=_((c,o)=>{if(typeof c!=="function"||Y0(c))throw new v(o,"Function",c)}),h=_((c,o)=>{if(c!==void 0)throw new v(o,"undefined",c)});function T0(c,o,x0){if(!K(x0,c))throw new v(o,`('${L(x0,"|")}')`,c)}var r=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function e(c,o){if(typeof c>"u"||!R(r,c))throw new B(o,c,'must be an array or string of format "; rel=preload; as=style"')}function C0(c){if(typeof c==="string")return e(c,"hints"),c;else if(G(c)){let o=c.length,x0="";if(o===0)return x0;for(let s=0;s; rel=preload; as=style"')}Y.exports={isInt32:u,isUint32:i,parseFileMode:Q,validateArray:w,validateStringArray:p,validateBooleanArray:n,validateAbortSignalArray:G0,validateBoolean:V,validateBuffer:d,validateDictionary:j,validateEncoding:I0,validateFunction:g0,validateInt32:Z,validateInteger:X,validateNumber:J,validateObject:H,validateOneOf:E,validatePlainFunction:f,validatePort:m,validateSignalName:t,validateString:$,validateUint32:A,validateUndefined:h,validateUnion:T0,validateAbortSignal:U0,validateLinkHeaderValue:C0}}),rU=u0((T,Y)=>{Y.exports=globalThis.process}),fU=u0((T,Y)=>{var{SymbolAsyncIterator:G,SymbolIterator:K,SymbolFor:L}=o0(),W=L("nodejs.stream.destroyed"),O=L("nodejs.stream.errored"),z=L("nodejs.stream.readable"),q=L("nodejs.stream.writable"),D=L("nodejs.stream.disturbed"),C=L("nodejs.webstream.isClosedPromise"),F=L("nodejs.webstream.controllerErrorFunction");function R(S,H=!1){var j;return!!(S&&typeof S.pipe==="function"&&typeof S.on==="function"&&(!H||typeof S.pause==="function"&&typeof S.resume==="function")&&(!S._writableState||((j=S._readableState)===null||j===void 0?void 0:j.readable)!==!1)&&(!S._writableState||S._readableState))}function M(S){var H;return!!(S&&typeof S.write==="function"&&typeof S.on==="function"&&(!S._readableState||((H=S._writableState)===null||H===void 0?void 0:H.writable)!==!1))}function P(S){return!!(S&&typeof S.pipe==="function"&&S._readableState&&typeof S.on==="function"&&typeof S.write==="function")}function k(S){return S&&(S._readableState||S._writableState||typeof S.write==="function"&&typeof S.on==="function"||typeof S.pipe==="function"&&typeof S.on==="function")}function _(S){return!!(S&&!k(S)&&typeof S.pipeThrough==="function"&&typeof S.getReader==="function"&&typeof S.cancel==="function")}function N(S){return!!(S&&!k(S)&&typeof S.getWriter==="function"&&typeof S.abort==="function")}function v(S){return!!(S&&!k(S)&&typeof S.readable==="object"&&typeof S.writable==="object")}function B(S){return _(S)||N(S)||v(S)}function g(S,H){if(S==null)return!1;if(H===!0)return typeof S[G]==="function";if(H===!1)return typeof S[K]==="function";return typeof S[G]==="function"||typeof S[K]==="function"}function y(S){if(!k(S))return null;let{_writableState:H,_readableState:j}=S,w=H||j;return!!(S.destroyed||S[W]||w!==null&&w!==void 0&&w.destroyed)}function l(S){if(!M(S))return null;if(S.writableEnded===!0)return!0;let H=S._writableState;if(H!==null&&H!==void 0&&H.errored)return!1;if(typeof(H===null||H===void 0?void 0:H.ended)!=="boolean")return null;return H.ended}function Y0(S,H){if(!M(S))return null;if(S.writableFinished===!0)return!0;let j=S._writableState;if(j!==null&&j!==void 0&&j.errored)return!1;if(typeof(j===null||j===void 0?void 0:j.finished)!=="boolean")return null;return!!(j.finished||H===!1&&j.ended===!0&&j.length===0)}function O0(S){if(!R(S))return null;if(S.readableEnded===!0)return!0;let H=S._readableState;if(!H||H.errored)return!1;if(typeof(H===null||H===void 0?void 0:H.ended)!=="boolean")return null;return H.ended}function Z0(S,H){if(!R(S))return null;let j=S._readableState;if(j!==null&&j!==void 0&&j.errored)return!1;if(typeof(j===null||j===void 0?void 0:j.endEmitted)!=="boolean")return null;return!!(j.endEmitted||H===!1&&j.ended===!0&&j.length===0)}function u(S){if(S&&S[z]!=null)return S[z];if(typeof(S===null||S===void 0?void 0:S.readable)!=="boolean")return null;if(y(S))return!1;return R(S)&&S.readable&&!Z0(S)}function i(S){if(S&&S[q]!=null)return S[q];if(typeof(S===null||S===void 0?void 0:S.writable)!=="boolean")return null;if(y(S))return!1;return M(S)&&S.writable&&!l(S)}function U(S,H){if(!k(S))return null;if(y(S))return!0;if((H===null||H===void 0?void 0:H.readable)!==!1&&u(S))return!1;if((H===null||H===void 0?void 0:H.writable)!==!1&&i(S))return!1;return!0}function I(S){var H,j;if(!k(S))return null;if(S.writableErrored)return S.writableErrored;return(H=(j=S._writableState)===null||j===void 0?void 0:j.errored)!==null&&H!==void 0?H:null}function Q(S){var H,j;if(!k(S))return null;if(S.readableErrored)return S.readableErrored;return(H=(j=S._readableState)===null||j===void 0?void 0:j.errored)!==null&&H!==void 0?H:null}function X(S){if(!k(S))return null;if(typeof S.closed==="boolean")return S.closed;let{_writableState:H,_readableState:j}=S;if(typeof(H===null||H===void 0?void 0:H.closed)==="boolean"||typeof(j===null||j===void 0?void 0:j.closed)==="boolean")return(H===null||H===void 0?void 0:H.closed)||(j===null||j===void 0?void 0:j.closed);if(typeof S._closed==="boolean"&&Z(S))return S._closed;return null}function Z(S){return typeof S._closed==="boolean"&&typeof S._defaultKeepAlive==="boolean"&&typeof S._removedConnection==="boolean"&&typeof S._removedContLen==="boolean"}function A(S){return typeof S._sent100==="boolean"&&Z(S)}function $(S){var H;return typeof S._consuming==="boolean"&&typeof S._dumped==="boolean"&&((H=S.req)===null||H===void 0?void 0:H.upgradeOrConnect)===void 0}function J(S){if(!k(S))return null;let{_writableState:H,_readableState:j}=S,w=H||j;return!w&&A(S)||!!(w&&w.autoDestroy&&w.emitClose&&w.closed===!1)}function E(S){var H;return!!(S&&((H=S[D])!==null&&H!==void 0?H:S.readableDidRead||S.readableAborted))}function V(S){var H,j,w,p,n,G0,t,d,I0,m;return!!(S&&((H=(j=(w=(p=(n=(G0=S[O])!==null&&G0!==void 0?G0:S.readableErrored)!==null&&n!==void 0?n:S.writableErrored)!==null&&p!==void 0?p:(t=S._readableState)===null||t===void 0?void 0:t.errorEmitted)!==null&&w!==void 0?w:(d=S._writableState)===null||d===void 0?void 0:d.errorEmitted)!==null&&j!==void 0?j:(I0=S._readableState)===null||I0===void 0?void 0:I0.errored)!==null&&H!==void 0?H:(m=S._writableState)===null||m===void 0?void 0:m.errored))}Y.exports={isDestroyed:y,kIsDestroyed:W,isDisturbed:E,kIsDisturbed:D,isErrored:V,kIsErrored:O,isReadable:u,kIsReadable:z,kIsClosedPromise:C,kControllerErrorFunction:F,kIsWritable:q,isClosed:X,isDuplexNodeStream:P,isFinished:U,isIterable:g,isReadableNodeStream:R,isReadableStream:_,isReadableEnded:O0,isReadableFinished:Z0,isReadableErrored:Q,isNodeStream:k,isWebStream:B,isWritable:i,isWritableNodeStream:M,isWritableStream:N,isWritableEnded:l,isWritableFinished:Y0,isWritableErrored:I,isServerRequest:$,isServerResponse:A,willEmitClose:J,isTransformStream:v}}),bU=u0((T,Y)=>{var G=rU(),{AbortError:K,codes:L}=zU(),{ERR_INVALID_ARG_TYPE:W,ERR_STREAM_PREMATURE_CLOSE:O}=L,{kEmptyObject:z,once:q}=qU(),{validateAbortSignal:D,validateFunction:C,validateObject:F,validateBoolean:R}=LE(),{Promise:M,PromisePrototypeThen:P,SymbolDispose:k}=o0(),{isClosed:_,isReadable:N,isReadableNodeStream:v,isReadableStream:B,isReadableFinished:g,isReadableErrored:y,isWritable:l,isWritableNodeStream:Y0,isWritableStream:O0,isWritableFinished:Z0,isWritableErrored:u,isNodeStream:i,willEmitClose:U,kIsClosedPromise:I}=fU(),Q;function X(E){return E.setHeader&&typeof E.abort==="function"}var Z=()=>{};function A(E,V,S){var H,j;if(arguments.length===2)S=V,V=z;else if(V==null)V=z;else F(V,"options");if(C(S,"callback"),D(V.signal,"options.signal"),S=q(S),B(E)||O0(E))return $(E,V,S);if(!i(E))throw new W("stream",["ReadableStream","WritableStream","Stream"],E);let w=(H=V.readable)!==null&&H!==void 0?H:v(E),p=(j=V.writable)!==null&&j!==void 0?j:Y0(E),n=E._writableState,G0=E._readableState,t=()=>{if(!E.writable)m()},d=U(E)&&v(E)===w&&Y0(E)===p,I0=Z0(E,!1),m=()=>{if(I0=!0,E.destroyed)d=!1;if(d&&(!E.readable||w))return;if(!w||U0)S.call(E)},U0=g(E,!1),g0=()=>{if(U0=!0,E.destroyed)d=!1;if(d&&(!E.writable||p))return;if(!p||I0)S.call(E)},f=(c)=>{S.call(E,c)},h=_(E),T0=()=>{h=!0;let c=u(E)||y(E);if(c&&typeof c!=="boolean")return S.call(E,c);if(w&&!U0&&v(E,!0)){if(!g(E,!1))return S.call(E,new O)}if(p&&!I0){if(!Z0(E,!1))return S.call(E,new O)}S.call(E)},r=()=>{h=!0;let c=u(E)||y(E);if(c&&typeof c!=="boolean")return S.call(E,c);S.call(E)},e=()=>{E.req.on("finish",m)};if(X(E)){if(E.on("complete",m),!d)E.on("abort",T0);if(E.req)e();else E.on("request",e)}else if(p&&!n)E.on("end",t),E.on("close",t);if(!d&&typeof E.aborted==="boolean")E.on("aborted",T0);if(E.on("end",g0),E.on("finish",m),V.error!==!1)E.on("error",f);if(E.on("close",T0),h)G.nextTick(T0);else if(n!==null&&n!==void 0&&n.errorEmitted||G0!==null&&G0!==void 0&&G0.errorEmitted){if(!d)G.nextTick(r)}else if(!w&&(!d||N(E))&&(I0||l(E)===!1))G.nextTick(r);else if(!p&&(!d||l(E))&&(U0||N(E)===!1))G.nextTick(r);else if(G0&&E.req&&E.aborted)G.nextTick(r);let C0=()=>{if(S=Z,E.removeListener("aborted",T0),E.removeListener("complete",m),E.removeListener("abort",T0),E.removeListener("request",e),E.req)E.req.removeListener("finish",m);E.removeListener("end",t),E.removeListener("close",t),E.removeListener("finish",m),E.removeListener("end",g0),E.removeListener("error",f),E.removeListener("close",T0)};if(V.signal&&!h){let c=()=>{let o=S;C0(),o.call(E,new K(void 0,{cause:V.signal.reason}))};if(V.signal.aborted)G.nextTick(c);else{Q=Q||qU().addAbortListener;let o=Q(V.signal,c),x0=S;S=q((...s)=>{o[k](),x0.apply(E,s)})}}return C0}function $(E,V,S){let H=!1,j=Z;if(V.signal)if(j=()=>{H=!0,S.call(E,new K(void 0,{cause:V.signal.reason}))},V.signal.aborted)G.nextTick(j);else{Q=Q||qU().addAbortListener;let p=Q(V.signal,j),n=S;S=q((...G0)=>{p[k](),n.apply(E,G0)})}let w=(...p)=>{if(!H)G.nextTick(()=>S.apply(E,p))};return P(E[I].promise,w,w),Z}function J(E,V){var S;let H=!1;if(V===null)V=z;if((S=V)!==null&&S!==void 0&&S.cleanup)R(V.cleanup,"cleanup"),H=V.cleanup;return new M((j,w)=>{let p=A(E,V,(n)=>{if(H)p();if(n)w(n);else j()})})}Y.exports=A,Y.exports.finished=J}),IE=u0((T,Y)=>{var G=rU(),{aggregateTwoErrors:K,codes:{ERR_MULTIPLE_CALLBACK:L},AbortError:W}=zU(),{Symbol:O}=o0(),{kIsDestroyed:z,isDestroyed:q,isFinished:D,isServerRequest:C}=fU(),F=O("kDestroy"),R=O("kConstruct");function M(U,I,Q){if(U){if(U.stack,I&&!I.errored)I.errored=U;if(Q&&!Q.errored)Q.errored=U}}function P(U,I){let Q=this._readableState,X=this._writableState,Z=X||Q;if(X!==null&&X!==void 0&&X.destroyed||Q!==null&&Q!==void 0&&Q.destroyed){if(typeof I==="function")I();return this}if(M(U,X,Q),X)X.destroyed=!0;if(Q)Q.destroyed=!0;if(!Z.constructed)this.once(F,function(A){k(this,K(A,U),I)});else k(this,U,I);return this}function k(U,I,Q){let X=!1;function Z(A){if(X)return;X=!0;let{_readableState:$,_writableState:J}=U;if(M(A,J,$),J)J.closed=!0;if($)$.closed=!0;if(typeof Q==="function")Q(A);if(A)G.nextTick(_,U,A);else G.nextTick(N,U)}try{U._destroy(I||null,Z)}catch(A){Z(A)}}function _(U,I){v(U,I),N(U)}function N(U){let{_readableState:I,_writableState:Q}=U;if(Q)Q.closeEmitted=!0;if(I)I.closeEmitted=!0;if(Q!==null&&Q!==void 0&&Q.emitClose||I!==null&&I!==void 0&&I.emitClose)U.emit("close")}function v(U,I){let{_readableState:Q,_writableState:X}=U;if(X!==null&&X!==void 0&&X.errorEmitted||Q!==null&&Q!==void 0&&Q.errorEmitted)return;if(X)X.errorEmitted=!0;if(Q)Q.errorEmitted=!0;U.emit("error",I)}function B(){let U=this._readableState,I=this._writableState;if(U)U.constructed=!0,U.closed=!1,U.closeEmitted=!1,U.destroyed=!1,U.errored=null,U.errorEmitted=!1,U.reading=!1,U.ended=U.readable===!1,U.endEmitted=U.readable===!1;if(I)I.constructed=!0,I.destroyed=!1,I.closed=!1,I.closeEmitted=!1,I.errored=null,I.errorEmitted=!1,I.finalCalled=!1,I.prefinished=!1,I.ended=I.writable===!1,I.ending=I.writable===!1,I.finished=I.writable===!1}function g(U,I,Q){let{_readableState:X,_writableState:Z}=U;if(Z!==null&&Z!==void 0&&Z.destroyed||X!==null&&X!==void 0&&X.destroyed)return this;if(X!==null&&X!==void 0&&X.autoDestroy||Z!==null&&Z!==void 0&&Z.autoDestroy)U.destroy(I);else if(I){if(I.stack,Z&&!Z.errored)Z.errored=I;if(X&&!X.errored)X.errored=I;if(Q)G.nextTick(v,U,I);else v(U,I)}}function y(U,I){if(typeof U._construct!=="function")return;let{_readableState:Q,_writableState:X}=U;if(Q)Q.constructed=!1;if(X)X.constructed=!1;if(U.once(R,I),U.listenerCount(R)>1)return;G.nextTick(l,U)}function l(U){let I=!1;function Q(X){if(I){g(U,X!==null&&X!==void 0?X:new L);return}I=!0;let{_readableState:Z,_writableState:A}=U,$=A||Z;if(Z)Z.constructed=!0;if(A)A.constructed=!0;if($.destroyed)U.emit(F,X);else if(X)g(U,X,!0);else G.nextTick(Y0,U)}try{U._construct((X)=>{G.nextTick(Q,X)})}catch(X){G.nextTick(Q,X)}}function Y0(U){U.emit(R)}function O0(U){return(U===null||U===void 0?void 0:U.setHeader)&&typeof U.abort==="function"}function Z0(U){U.emit("close")}function u(U,I){U.emit("error",I),G.nextTick(Z0,U)}function i(U,I){if(!U||q(U))return;if(!I&&!D(U))I=new W;if(C(U))U.socket=null,U.destroy(I);else if(O0(U))U.abort();else if(O0(U.req))U.req.abort();else if(typeof U.destroy==="function")U.destroy(I);else if(typeof U.close==="function")U.close();else if(I)G.nextTick(u,U,I);else G.nextTick(Z0,U);if(!U.destroyed)U[z]=!0}Y.exports={construct:y,destroyer:i,destroy:P,undestroy:B,errorOrDestroy:g}}),DX=u0((T,Y)=>{var{ArrayIsArray:G,ObjectSetPrototypeOf:K}=o0(),{EventEmitter:L}=(VE(),h0(GE));function W(z){L.call(this,z)}K(W.prototype,L.prototype),K(W,L),W.prototype.pipe=function(z,q){let D=this;function C(N){if(z.writable&&z.write(N)===!1&&D.pause)D.pause()}D.on("data",C);function F(){if(D.readable&&D.resume)D.resume()}if(z.on("drain",F),!z._isStdio&&(!q||q.end!==!1))D.on("end",M),D.on("close",P);let R=!1;function M(){if(R)return;R=!0,z.end()}function P(){if(R)return;if(R=!0,typeof z.destroy==="function")z.destroy()}function k(N){if(_(),L.listenerCount(this,"error")===0)this.emit("error",N)}O(D,"error",k),O(z,"error",k);function _(){D.removeListener("data",C),z.removeListener("drain",F),D.removeListener("end",M),D.removeListener("close",P),D.removeListener("error",k),z.removeListener("error",k),D.removeListener("end",_),D.removeListener("close",_),z.removeListener("close",_)}return D.on("end",_),D.on("close",_),z.on("close",_),z.emit("pipe",D),z};function O(z,q,D){if(typeof z.prependListener==="function")return z.prependListener(q,D);if(!z._events||!z._events[q])z.on(q,D);else if(G(z._events[q]))z._events[q].unshift(D);else z._events[q]=[D,z._events[q]]}Y.exports={Stream:W,prependListener:O}}),wE=u0((T,Y)=>{var{SymbolDispose:G}=o0(),{AbortError:K,codes:L}=zU(),{isNodeStream:W,isWebStream:O,kControllerErrorFunction:z}=fU(),q=bU(),{ERR_INVALID_ARG_TYPE:D}=L,C,F=(R,M)=>{if(typeof R!=="object"||!("aborted"in R))throw new D(M,"AbortSignal",R)};Y.exports.addAbortSignal=function(R,M){if(F(R,"signal"),!W(M)&&!O(M))throw new D("stream",["ReadableStream","WritableStream","Stream"],M);return Y.exports.addAbortSignalNoValidate(R,M)},Y.exports.addAbortSignalNoValidate=function(R,M){if(typeof R!=="object"||!("aborted"in R))return M;let P=W(M)?()=>{M.destroy(new K(void 0,{cause:R.reason}))}:()=>{M[z](new K(void 0,{cause:R.reason}))};if(R.aborted)P();else{C=C||qU().addAbortListener;let k=C(R,P);q(M,k[G])}return M}}),tZ=u0((T,Y)=>{var{StringPrototypeSlice:G,SymbolIterator:K,TypedArrayPrototypeSet:L,Uint8Array:W}=o0(),{Buffer:O}=(FU(),h0(KU)),{inspect:z}=qU();Y.exports=class{constructor(){this.head=null,this.tail=null,this.length=0}push(q){let D={data:q,next:null};if(this.length>0)this.tail.next=D;else this.head=D;this.tail=D,++this.length}unshift(q){let D={data:q,next:this.head};if(this.length===0)this.tail=D;this.head=D,++this.length}shift(){if(this.length===0)return;let q=this.head.data;if(this.length===1)this.head=this.tail=null;else this.head=this.head.next;return--this.length,q}clear(){this.head=this.tail=null,this.length=0}join(q){if(this.length===0)return"";let D=this.head,C=""+D.data;while((D=D.next)!==null)C+=q+D.data;return C}concat(q){if(this.length===0)return O.alloc(0);let D=O.allocUnsafe(q>>>0),C=this.head,F=0;while(C)L(D,C.data,F),F+=C.data.length,C=C.next;return D}consume(q,D){let C=this.head.data;if(qR.length)D+=R,q-=R.length;else{if(q===R.length)if(D+=R,++F,C.next)this.head=C.next;else this.head=this.tail=null;else D+=G(R,0,q),this.head=C,C.data=G(R,q);break}++F}while((C=C.next)!==null);return this.length-=F,D}_getBuffer(q){let D=O.allocUnsafe(q),C=q,F=this.head,R=0;do{let M=F.data;if(q>M.length)L(D,M,C-q),q-=M.length;else{if(q===M.length)if(L(D,M,C-q),++R,F.next)this.head=F.next;else this.head=this.tail=null;else L(D,new W(M.buffer,M.byteOffset,q),C-q),this.head=F,F.data=M.slice(q);break}++R}while((F=F.next)!==null);return this.length-=R,D}[Symbol.for("nodejs.util.inspect.custom")](q,D){return z(this,{...D,depth:0,customInspect:!1})}}}),yE=u0((T,Y)=>{var{MathFloor:G,NumberIsInteger:K}=o0(),{validateInteger:L}=LE(),{ERR_INVALID_ARG_VALUE:W}=zU().codes,O=16384,z=16;function q(R,M,P){return R.highWaterMark!=null?R.highWaterMark:M?R[P]:null}function D(R){return R?z:O}function C(R,M){if(L(M,"value",0),R)z=M;else O=M}function F(R,M,P,k){let _=q(M,k,P);if(_!=null){if(!K(_)||_<0){let N=k?`options.${P}`:"options.highWaterMark";throw new W(N,_)}return G(_)}return D(R.objectMode)}Y.exports={getHighWaterMark:F,getDefaultHighWaterMark:D,setDefaultHighWaterMark:C}}),aZ=u0((T,Y)=>{/*! safe-buffer. MIT License. Feross Aboukhadijeh */var G=(FU(),h0(KU)),K=G.Buffer;function L(O,z){for(var q in O)z[q]=O[q]}if(K.from&&K.alloc&&K.allocUnsafe&&K.allocUnsafeSlow)Y.exports=G;else L(G,T),T.Buffer=W;function W(O,z,q){return K(O,z,q)}W.prototype=Object.create(K.prototype),L(K,W),W.from=function(O,z,q){if(typeof O==="number")throw TypeError("Argument must not be a number");return K(O,z,q)},W.alloc=function(O,z,q){if(typeof O!=="number")throw TypeError("Argument must be a number");var D=K(O);if(z!==void 0)if(typeof q==="string")D.fill(z,q);else D.fill(z);else D.fill(0);return D},W.allocUnsafe=function(O){if(typeof O!=="number")throw TypeError("Argument must be a number");return K(O)},W.allocUnsafeSlow=function(O){if(typeof O!=="number")throw TypeError("Argument must be a number");return G.SlowBuffer(O)}}),eZ=u0((T)=>{var Y=aZ().Buffer,G=Y.isEncoding||function(v){switch(v=""+v,v&&v.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function K(v){if(!v)return"utf8";var B;while(!0)switch(v){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return v;default:if(B)return;v=(""+v).toLowerCase(),B=!0}}function L(v){var B=K(v);if(typeof B!=="string"&&(Y.isEncoding===G||!G(v)))throw Error("Unknown encoding: "+v);return B||v}T.StringDecoder=W;function W(v){this.encoding=L(v);var B;switch(this.encoding){case"utf16le":this.text=R,this.end=M,B=4;break;case"utf8":this.fillLast=D,B=4;break;case"base64":this.text=P,this.end=k,B=3;break;default:this.write=_,this.end=N;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Y.allocUnsafe(B)}W.prototype.write=function(v){if(v.length===0)return"";var B,g;if(this.lastNeed){if(B=this.fillLast(v),B===void 0)return"";g=this.lastNeed,this.lastNeed=0}else g=0;if(g>5===6)return 2;else if(v>>4===14)return 3;else if(v>>3===30)return 4;return v>>6===2?-1:-2}function z(v,B,g){var y=B.length-1;if(y=0){if(l>0)v.lastNeed=l-1;return l}if(--y=0){if(l>0)v.lastNeed=l-2;return l}if(--y=0){if(l>0)if(l===2)l=0;else v.lastNeed=l-3;return l}return 0}function q(v,B,g){if((B[0]&192)!==128)return v.lastNeed=0,"�";if(v.lastNeed>1&&B.length>1){if((B[1]&192)!==128)return v.lastNeed=1,"�";if(v.lastNeed>2&&B.length>2){if((B[2]&192)!==128)return v.lastNeed=2,"�"}}}function D(v){var B=this.lastTotal-this.lastNeed,g=q(this,v,B);if(g!==void 0)return g;if(this.lastNeed<=v.length)return v.copy(this.lastChar,B,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);v.copy(this.lastChar,B,0,v.length),this.lastNeed-=v.length}function C(v,B){var g=z(this,v,B);if(!this.lastNeed)return v.toString("utf8",B);this.lastTotal=g;var y=v.length-(g-this.lastNeed);return v.copy(this.lastChar,0,y),v.toString("utf8",B,y)}function F(v){var B=v&&v.length?this.write(v):"";if(this.lastNeed)return B+"�";return B}function R(v,B){if((v.length-B)%2===0){var g=v.toString("utf16le",B);if(g){var y=g.charCodeAt(g.length-1);if(y>=55296&&y<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=v[v.length-2],this.lastChar[1]=v[v.length-1],g.slice(0,-1)}return g}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=v[v.length-1],v.toString("utf16le",B,v.length-1)}function M(v){var B=v&&v.length?this.write(v):"";if(this.lastNeed){var g=this.lastTotal-this.lastNeed;return B+this.lastChar.toString("utf16le",0,g)}return B}function P(v,B){var g=(v.length-B)%3;if(g===0)return v.toString("base64",B);if(this.lastNeed=3-g,this.lastTotal=3,g===1)this.lastChar[0]=v[v.length-1];else this.lastChar[0]=v[v.length-2],this.lastChar[1]=v[v.length-1];return v.toString("base64",B,v.length-g)}function k(v){var B=v&&v.length?this.write(v):"";if(this.lastNeed)return B+this.lastChar.toString("base64",0,3-this.lastNeed);return B}function _(v){return v.toString(this.encoding)}function N(v){return v&&v.length?this.write(v):""}}),tI=u0((T,Y)=>{var G=rU(),{PromisePrototypeThen:K,SymbolAsyncIterator:L,SymbolIterator:W}=o0(),{Buffer:O}=(FU(),h0(KU)),{ERR_INVALID_ARG_TYPE:z,ERR_STREAM_NULL_VALUES:q}=zU().codes;function D(C,F,R){let M;if(typeof F==="string"||F instanceof O)return new C({objectMode:!0,...R,read(){this.push(F),this.push(null)}});let P;if(F&&F[L])P=!0,M=F[L]();else if(F&&F[W])P=!1,M=F[W]();else throw new z("iterable",["Iterable"],F);let k=new C({objectMode:!0,highWaterMark:1,...R}),_=!1;k._read=function(){if(!_)_=!0,v()},k._destroy=function(B,g){K(N(B),()=>G.nextTick(g,B),(y)=>G.nextTick(g,y||B))};async function N(B){let g=B!==void 0&&B!==null,y=typeof M.throw==="function";if(g&&y){let{value:l,done:Y0}=await M.throw(B);if(await l,Y0)return}if(typeof M.return==="function"){let{value:l}=await M.return();await l}}async function v(){for(;;){try{let{value:B,done:g}=P?await M.next():M.next();if(g)k.push(null);else{let y=B&&typeof B.then==="function"?await B:B;if(y===null)throw _=!1,new q;else if(k.push(y))continue;else _=!1}}catch(B){k.destroy(B)}break}}return k}Y.exports=D}),fE=u0((T,Y)=>{var G=rU(),{ArrayPrototypeIndexOf:K,NumberIsInteger:L,NumberIsNaN:W,NumberParseInt:O,ObjectDefineProperties:z,ObjectKeys:q,ObjectSetPrototypeOf:D,Promise:C,SafeSet:F,SymbolAsyncDispose:R,SymbolAsyncIterator:M,Symbol:P}=o0();Y.exports=s,s.ReadableState=x0;var{EventEmitter:k}=(VE(),h0(GE)),{Stream:_,prependListener:N}=DX(),{Buffer:v}=(FU(),h0(KU)),{addAbortSignal:B}=wE(),g=bU(),y=qU().debuglog("stream",(x)=>{y=x}),l=tZ(),Y0=IE(),{getHighWaterMark:O0,getDefaultHighWaterMark:Z0}=yE(),{aggregateTwoErrors:u,codes:{ERR_INVALID_ARG_TYPE:i,ERR_METHOD_NOT_IMPLEMENTED:U,ERR_OUT_OF_RANGE:I,ERR_STREAM_PUSH_AFTER_EOF:Q,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:X},AbortError:Z}=zU(),{validateObject:A}=LE(),$=P("kPaused"),{StringDecoder:J}=eZ(),E=tI();D(s.prototype,_.prototype),D(s,_);var V=()=>{},{errorOrDestroy:S}=Y0,H=1,j=2,w=4,p=8,n=16,G0=32,t=64,d=128,I0=256,m=512,U0=1024,g0=2048,f=4096,h=8192,T0=16384,r=32768,e=65536,C0=131072,c=262144;function o(x){return{enumerable:!1,get(){return(this.state&x)!==0},set(b){if(b)this.state|=x;else this.state&=~x}}}z(x0.prototype,{objectMode:o(H),ended:o(j),endEmitted:o(w),reading:o(p),constructed:o(n),sync:o(G0),needReadable:o(t),emittedReadable:o(d),readableListening:o(I0),resumeScheduled:o(m),errorEmitted:o(U0),emitClose:o(g0),autoDestroy:o(f),destroyed:o(h),closed:o(T0),closeEmitted:o(r),multiAwaitDrain:o(e),readingMore:o(C0),dataEmitted:o(c)});function x0(x,b,a){if(typeof a!=="boolean")a=b instanceof yU();if(this.state=g0|f|n|G0,x&&x.objectMode)this.state|=H;if(a&&x&&x.readableObjectMode)this.state|=H;if(this.highWaterMark=x?O0(this,x,"readableHighWaterMark",a):Z0(!1),this.buffer=new l,this.length=0,this.pipes=[],this.flowing=null,this[$]=null,x&&x.emitClose===!1)this.state&=~g0;if(x&&x.autoDestroy===!1)this.state&=~f;if(this.errored=null,this.defaultEncoding=x&&x.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,x&&x.encoding)this.decoder=new J(x.encoding),this.encoding=x.encoding}function s(x){if(!(this instanceof s))return new s(x);let b=this instanceof yU();if(this._readableState=new x0(x,this,b),x){if(typeof x.read==="function")this._read=x.read;if(typeof x.destroy==="function")this._destroy=x.destroy;if(typeof x.construct==="function")this._construct=x.construct;if(x.signal&&!b)B(x.signal,this)}_.call(this,x),Y0.construct(this,()=>{if(this._readableState.needReadable)H0(this,this._readableState)})}s.prototype.destroy=Y0.destroy,s.prototype._undestroy=Y0.undestroy,s.prototype._destroy=function(x,b){b(x)},s.prototype[k.captureRejectionSymbol]=function(x){this.destroy(x)},s.prototype[R]=function(){let x;if(!this.destroyed)x=this.readableEnded?null:new Z,this.destroy(x);return new C((b,a)=>g(this,(E0)=>E0&&E0!==x?a(E0):b(null)))},s.prototype.push=function(x,b){return X0(this,x,b,!1)},s.prototype.unshift=function(x,b){return X0(this,x,b,!0)};function X0(x,b,a,E0){y("readableAddChunk",b);let w0=x._readableState,A0;if((w0.state&H)===0){if(typeof b==="string"){if(a=a||w0.defaultEncoding,w0.encoding!==a)if(E0&&w0.encoding)b=v.from(b,a).toString(w0.encoding);else b=v.from(b,a),a=""}else if(b instanceof v)a="";else if(_._isUint8Array(b))b=_._uint8ArrayToBuffer(b),a="";else if(b!=null)A0=new i("chunk",["string","Buffer","Uint8Array"],b)}if(A0)S(x,A0);else if(b===null)w0.state&=~p,V0(x,w0);else if((w0.state&H)!==0||b&&b.length>0)if(E0)if((w0.state&w)!==0)S(x,new X);else if(w0.destroyed||w0.errored)return!1;else y0(x,w0,b,!0);else if(w0.ended)S(x,new Q);else if(w0.destroyed||w0.errored)return!1;else if(w0.state&=~p,w0.decoder&&!a)if(b=w0.decoder.write(b),w0.objectMode||b.length!==0)y0(x,w0,b,!1);else H0(x,w0);else y0(x,w0,b,!1);else if(!E0)w0.state&=~p,H0(x,w0);return!w0.ended&&(w0.length0){if((b.state&e)!==0)b.awaitDrainWriters.clear();else b.awaitDrainWriters=null;b.dataEmitted=!0,x.emit("data",a)}else{if(b.length+=b.objectMode?1:a.length,E0)b.buffer.unshift(a);else b.buffer.push(a);if((b.state&t)!==0)K0(x)}H0(x,b)}s.prototype.isPaused=function(){let x=this._readableState;return x[$]===!0||x.flowing===!1},s.prototype.setEncoding=function(x){let b=new J(x);this._readableState.decoder=b,this._readableState.encoding=this._readableState.decoder.encoding;let a=this._readableState.buffer,E0="";for(let w0 of a)E0+=b.write(w0);if(a.clear(),E0!=="")a.push(E0);return this._readableState.length=E0.length,this};var L0=1073741824;function $0(x){if(x>L0)throw new I("size","<= 1GiB",x);else x--,x|=x>>>1,x|=x>>>2,x|=x>>>4,x|=x>>>8,x|=x>>>16,x++;return x}function n0(x,b){if(x<=0||b.length===0&&b.ended)return 0;if((b.state&H)!==0)return 1;if(W(x)){if(b.flowing&&b.length)return b.buffer.first().length;return b.length}if(x<=b.length)return x;return b.ended?b.length:0}s.prototype.read=function(x){if(y("read",x),x===void 0)x=NaN;else if(!L(x))x=O(x,10);let b=this._readableState,a=x;if(x>b.highWaterMark)b.highWaterMark=$0(x);if(x!==0)b.state&=~d;if(x===0&&b.needReadable&&((b.highWaterMark!==0?b.length>=b.highWaterMark:b.length>0)||b.ended)){if(y("read: emitReadable",b.length,b.ended),b.length===0&&b.ended)AU(this);else K0(this);return null}if(x=n0(x,b),x===0&&b.ended){if(b.length===0)AU(this);return null}let E0=(b.state&t)!==0;if(y("need readable",E0),b.length===0||b.length-x0)w0=S0(x,b);else w0=null;if(w0===null)b.needReadable=b.length<=b.highWaterMark,x=0;else if(b.length-=x,b.multiAwaitDrain)b.awaitDrainWriters.clear();else b.awaitDrainWriters=null;if(b.length===0){if(!b.ended)b.needReadable=!0;if(a!==x&&b.ended)AU(this)}if(w0!==null&&!b.errorEmitted&&!b.closeEmitted)b.dataEmitted=!0,this.emit("data",w0);return w0};function V0(x,b){if(y("onEofChunk"),b.ended)return;if(b.decoder){let a=b.decoder.end();if(a&&a.length)b.buffer.push(a),b.length+=b.objectMode?1:a.length}if(b.ended=!0,b.sync)K0(x);else b.needReadable=!1,b.emittedReadable=!0,r0(x)}function K0(x){let b=x._readableState;if(y("emitReadable",b.needReadable,b.emittedReadable),b.needReadable=!1,!b.emittedReadable)y("emitReadable",b.flowing),b.emittedReadable=!0,G.nextTick(r0,x)}function r0(x){let b=x._readableState;if(y("emitReadable_",b.destroyed,b.length,b.ended),!b.destroyed&&!b.errored&&(b.length||b.ended))x.emit("readable"),b.emittedReadable=!1;b.needReadable=!b.flowing&&!b.ended&&b.length<=b.highWaterMark,z0(x)}function H0(x,b){if(!b.readingMore&&b.constructed)b.readingMore=!0,G.nextTick(W0,x,b)}function W0(x,b){while(!b.reading&&!b.ended&&(b.length1&&E0.pipes.includes(x))y("false write response, pause",E0.awaitDrainWriters.size),E0.awaitDrainWriters.add(x);a.pause()}if(!m0)m0=RU(a,x),x.on("drain",m0)}a.on("data",P0);function P0(d0){y("ondata");let b0=x.write(d0);if(y("dest.write",b0),b0===!1)HU()}function R0(d0){if(y("onerror",d0),f0(),x.removeListener("error",R0),x.listenerCount("error")===0){let b0=x._writableState||x._readableState;if(b0&&!b0.errorEmitted)S(x,d0);else x.emit("error",d0)}}N(x,"error",R0);function s0(){x.removeListener("finish",c0),f0()}x.once("close",s0);function c0(){y("onfinish"),x.removeListener("close",s0),f0()}x.once("finish",c0);function f0(){y("unpipe"),a.unpipe(x)}if(x.emit("pipe",a),x.writableNeedDrain===!0)HU();else if(!E0.flowing)y("pipe resume"),a.resume();return x};function RU(x,b){return function(){let a=x._readableState;if(a.awaitDrainWriters===b)y("pipeOnDrain",1),a.awaitDrainWriters=null;else if(a.multiAwaitDrain)y("pipeOnDrain",a.awaitDrainWriters.size),a.awaitDrainWriters.delete(b);if((!a.awaitDrainWriters||a.awaitDrainWriters.size===0)&&x.listenerCount("data"))x.resume()}}s.prototype.unpipe=function(x){let b=this._readableState,a={hasUnpiped:!1};if(b.pipes.length===0)return this;if(!x){let w0=b.pipes;b.pipes=[],this.pause();for(let A0=0;A00,E0.flowing!==!1)this.resume()}else if(x==="readable"){if(!E0.endEmitted&&!E0.readableListening){if(E0.readableListening=E0.needReadable=!0,E0.flowing=!1,E0.emittedReadable=!1,y("on readable",E0.length,E0.reading),E0.length)K0(this);else if(!E0.reading)G.nextTick(_0,this)}}return a},s.prototype.addListener=s.prototype.on,s.prototype.removeListener=function(x,b){let a=_.prototype.removeListener.call(this,x,b);if(x==="readable")G.nextTick(D0,this);return a},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(x){let b=_.prototype.removeAllListeners.apply(this,arguments);if(x==="readable"||x===void 0)G.nextTick(D0,this);return b};function D0(x){let b=x._readableState;if(b.readableListening=x.listenerCount("readable")>0,b.resumeScheduled&&b[$]===!1)b.flowing=!0;else if(x.listenerCount("data")>0)x.resume();else if(!b.readableListening)b.flowing=null}function _0(x){y("readable nexttick read 0"),x.read(0)}s.prototype.resume=function(){let x=this._readableState;if(!x.flowing)y("resume"),x.flowing=!x.readableListening,CU(this,x);return x[$]=!1,this};function CU(x,b){if(!b.resumeScheduled)b.resumeScheduled=!0,G.nextTick(k0,x,b)}function k0(x,b){if(y("resume",b.reading),!b.reading)x.read(0);if(b.resumeScheduled=!1,x.emit("resume"),z0(x),b.flowing&&!b.reading)x.read(0)}s.prototype.pause=function(){if(y("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1)y("pause"),this._readableState.flowing=!1,this.emit("pause");return this._readableState[$]=!0,this};function z0(x){let b=x._readableState;y("flow",b.flowing);while(b.flowing&&x.read()!==null);}s.prototype.wrap=function(x){let b=!1;x.on("data",(E0)=>{if(!this.push(E0)&&x.pause)b=!0,x.pause()}),x.on("end",()=>{this.push(null)}),x.on("error",(E0)=>{S(this,E0)}),x.on("close",()=>{this.destroy()}),x.on("destroy",()=>{this.destroy()}),this._read=()=>{if(b&&x.resume)b=!1,x.resume()};let a=q(x);for(let E0=1;E0{w0=F0?u(w0,F0):null,a(),a=V});try{while(!0){let F0=x.destroyed?null:x.read();if(F0!==null)yield F0;else if(w0)throw w0;else if(w0===null)return;else await new C(E0)}}catch(F0){throw w0=u(w0,F0),w0}finally{if((w0||(b===null||b===void 0?void 0:b.destroyOnReturn)!==!1)&&(w0===void 0||x._readableState.autoDestroy))Y0.destroyer(x,null);else x.off("readable",E0),A0()}}z(s.prototype,{readable:{__proto__:null,get(){let x=this._readableState;return!!x&&x.readable!==!1&&!x.destroyed&&!x.errorEmitted&&!x.endEmitted},set(x){if(this._readableState)this._readableState.readable=!!x}},readableDidRead:{__proto__:null,enumerable:!1,get:function(){return this._readableState.dataEmitted}},readableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._readableState.readable!==!1&&(this._readableState.destroyed||this._readableState.errored)&&!this._readableState.endEmitted)}},readableHighWaterMark:{__proto__:null,enumerable:!1,get:function(){return this._readableState.highWaterMark}},readableBuffer:{__proto__:null,enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}},readableFlowing:{__proto__:null,enumerable:!1,get:function(){return this._readableState.flowing},set:function(x){if(this._readableState)this._readableState.flowing=x}},readableLength:{__proto__:null,enumerable:!1,get(){return this._readableState.length}},readableObjectMode:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.objectMode:!1}},readableEncoding:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.encoding:null}},errored:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.errored:null}},closed:{__proto__:null,get(){return this._readableState?this._readableState.closed:!1}},destroyed:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.destroyed:!1},set(x){if(!this._readableState)return;this._readableState.destroyed=x}},readableEnded:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.endEmitted:!1}}}),z(x0.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return this[$]!==!1},set(x){this[$]=!!x}}}),s._fromList=S0;function S0(x,b){if(b.length===0)return null;let a;if(b.objectMode)a=b.buffer.shift();else if(!x||x>=b.length){if(b.decoder)a=b.buffer.join("");else if(b.buffer.length===1)a=b.buffer.first();else a=b.buffer.concat(b.length);b.buffer.clear()}else a=b.buffer.consume(x,b.decoder);return a}function AU(x){let b=x._readableState;if(y("endReadable",b.endEmitted),!b.endEmitted)b.ended=!0,G.nextTick(j0,b,x)}function j0(x,b){if(y("endReadableNT",x.endEmitted,x.length),!x.errored&&!x.closeEmitted&&!x.endEmitted&&x.length===0){if(x.endEmitted=!0,b.emit("end"),b.writable&&b.allowHalfOpen===!1)G.nextTick(N0,b);else if(x.autoDestroy){let a=b._writableState;if(!a||a.autoDestroy&&(a.finished||a.writable===!1))b.destroy()}}}function N0(x){if(x.writable&&!x.writableEnded&&!x.destroyed)x.end()}s.from=function(x,b){return E(s,x,b)};var LU;function M0(){if(LU===void 0)LU={};return LU}s.fromWeb=function(x,b){return M0().newStreamReadableFromReadableStream(x,b)},s.toWeb=function(x,b){return M0().newReadableStreamFromStreamReadable(x,b)},s.wrap=function(x,b){var a,E0;return new s({objectMode:(a=(E0=x.readableObjectMode)!==null&&E0!==void 0?E0:x.objectMode)!==null&&a!==void 0?a:!0,...b,destroy(w0,A0){Y0.destroyer(x,w0),A0(w0)}}).wrap(x)}}),zX=u0((T,Y)=>{var G=rU(),{ArrayPrototypeSlice:K,Error:L,FunctionPrototypeSymbolHasInstance:W,ObjectDefineProperty:O,ObjectDefineProperties:z,ObjectSetPrototypeOf:q,StringPrototypeToLowerCase:D,Symbol:C,SymbolHasInstance:F}=o0();Y.exports=A,A.WritableState=X;var{EventEmitter:R}=(VE(),h0(GE)),M=DX().Stream,{Buffer:P}=(FU(),h0(KU)),k=IE(),{addAbortSignal:_}=wE(),{getHighWaterMark:N,getDefaultHighWaterMark:v}=yE(),{ERR_INVALID_ARG_TYPE:B,ERR_METHOD_NOT_IMPLEMENTED:g,ERR_MULTIPLE_CALLBACK:y,ERR_STREAM_CANNOT_PIPE:l,ERR_STREAM_DESTROYED:Y0,ERR_STREAM_ALREADY_FINISHED:O0,ERR_STREAM_NULL_VALUES:Z0,ERR_STREAM_WRITE_AFTER_END:u,ERR_UNKNOWN_ENCODING:i}=zU().codes,{errorOrDestroy:U}=k;q(A.prototype,M.prototype),q(A,M);function I(){}var Q=C("kOnFinished");function X(f,h,T0){if(typeof T0!=="boolean")T0=h instanceof yU();if(this.objectMode=!!(f&&f.objectMode),T0)this.objectMode=this.objectMode||!!(f&&f.writableObjectMode);this.highWaterMark=f?N(this,f,"writableHighWaterMark",T0):v(!1),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;let r=!!(f&&f.decodeStrings===!1);this.decodeStrings=!r,this.defaultEncoding=f&&f.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=S.bind(void 0,h),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,Z(this),this.pendingcb=0,this.constructed=!0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!f||f.emitClose!==!1,this.autoDestroy=!f||f.autoDestroy!==!1,this.errored=null,this.closed=!1,this.closeEmitted=!1,this[Q]=[]}function Z(f){f.buffered=[],f.bufferedIndex=0,f.allBuffers=!0,f.allNoop=!0}X.prototype.getBuffer=function(){return K(this.buffered,this.bufferedIndex)},O(X.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}});function A(f){let h=this instanceof yU();if(!h&&!W(A,this))return new A(f);if(this._writableState=new X(f,this,h),f){if(typeof f.write==="function")this._write=f.write;if(typeof f.writev==="function")this._writev=f.writev;if(typeof f.destroy==="function")this._destroy=f.destroy;if(typeof f.final==="function")this._final=f.final;if(typeof f.construct==="function")this._construct=f.construct;if(f.signal)_(f.signal,this)}M.call(this,f),k.construct(this,()=>{let T0=this._writableState;if(!T0.writing)p(this,T0);d(this,T0)})}O(A,F,{__proto__:null,value:function(f){if(W(this,f))return!0;if(this!==A)return!1;return f&&f._writableState instanceof X}}),A.prototype.pipe=function(){U(this,new l)};function $(f,h,T0,r){let e=f._writableState;if(typeof T0==="function")r=T0,T0=e.defaultEncoding;else{if(!T0)T0=e.defaultEncoding;else if(T0!=="buffer"&&!P.isEncoding(T0))throw new i(T0);if(typeof r!=="function")r=I}if(h===null)throw new Z0;else if(!e.objectMode)if(typeof h==="string"){if(e.decodeStrings!==!1)h=P.from(h,T0),T0="buffer"}else if(h instanceof P)T0="buffer";else if(M._isUint8Array(h))h=M._uint8ArrayToBuffer(h),T0="buffer";else throw new B("chunk",["string","Buffer","Uint8Array"],h);let C0;if(e.ending)C0=new u;else if(e.destroyed)C0=new Y0("write");if(C0)return G.nextTick(r,C0),U(f,C0,!0),C0;return e.pendingcb++,J(f,e,h,T0,r)}A.prototype.write=function(f,h,T0){return $(this,f,h,T0)===!0},A.prototype.cork=function(){this._writableState.corked++},A.prototype.uncork=function(){let f=this._writableState;if(f.corked){if(f.corked--,!f.writing)p(this,f)}},A.prototype.setDefaultEncoding=function(f){if(typeof f==="string")f=D(f);if(!P.isEncoding(f))throw new i(f);return this._writableState.defaultEncoding=f,this};function J(f,h,T0,r,e){let C0=h.objectMode?1:T0.length;h.length+=C0;let c=h.lengthT0.bufferedIndex)p(f,T0);if(r)if(T0.afterWriteTickInfo!==null&&T0.afterWriteTickInfo.cb===e)T0.afterWriteTickInfo.count++;else T0.afterWriteTickInfo={count:1,cb:e,stream:f,state:T0},G.nextTick(H,T0.afterWriteTickInfo);else j(f,T0,1,e)}}function H({stream:f,state:h,count:T0,cb:r}){return h.afterWriteTickInfo=null,j(f,h,T0,r)}function j(f,h,T0,r){if(!h.ending&&!f.destroyed&&h.length===0&&h.needDrain)h.needDrain=!1,f.emit("drain");while(T0-- >0)h.pendingcb--,r();if(h.destroyed)w(h);d(f,h)}function w(f){if(f.writing)return;for(let e=f.bufferedIndex;e1&&f._writev){h.pendingcb-=C0-1;let o=h.allNoop?I:(s)=>{for(let X0=c;X0256)T0.splice(0,c),h.bufferedIndex=0;else h.bufferedIndex=c}h.bufferProcessing=!1}A.prototype._write=function(f,h,T0){if(this._writev)this._writev([{chunk:f,encoding:h}],T0);else throw new g("_write()")},A.prototype._writev=null,A.prototype.end=function(f,h,T0){let r=this._writableState;if(typeof f==="function")T0=f,f=null,h=null;else if(typeof h==="function")T0=h,h=null;let e;if(f!==null&&f!==void 0){let C0=$(this,f,h);if(C0 instanceof L)e=C0}if(r.corked)r.corked=1,this.uncork();if(e);else if(!r.errored&&!r.ending)r.ending=!0,d(this,r,!0),r.ended=!0;else if(r.finished)e=new O0("end");else if(r.destroyed)e=new Y0("end");if(typeof T0==="function")if(e||r.finished)G.nextTick(T0,e);else r[Q].push(T0);return this};function n(f){return f.ending&&!f.destroyed&&f.constructed&&f.length===0&&!f.errored&&f.buffered.length===0&&!f.finished&&!f.writing&&!f.errorEmitted&&!f.closeEmitted}function G0(f,h){let T0=!1;function r(e){if(T0){U(f,e!==null&&e!==void 0?e:y());return}if(T0=!0,h.pendingcb--,e){let C0=h[Q].splice(0);for(let c=0;c{if(n(e))I0(r,e);else e.pendingcb--},f,h);else if(n(h))h.pendingcb++,I0(f,h)}}}function I0(f,h){h.pendingcb--,h.finished=!0;let T0=h[Q].splice(0);for(let r=0;r{var G=rU(),K=(FU(),h0(KU)),{isReadable:L,isWritable:W,isIterable:O,isNodeStream:z,isReadableNodeStream:q,isWritableNodeStream:D,isDuplexNodeStream:C,isReadableStream:F,isWritableStream:R}=fU(),M=bU(),{AbortError:P,codes:{ERR_INVALID_ARG_TYPE:k,ERR_INVALID_RETURN_VALUE:_}}=zU(),{destroyer:N}=IE(),v=yU(),B=fE(),g=zX(),{createDeferredPromise:y}=qU(),l=tI(),Y0=globalThis.Blob||K.Blob,O0=typeof Y0<"u"?function(Q){return Q instanceof Y0}:function(Q){return!1},Z0=globalThis.AbortController||AE().AbortController,{FunctionPrototypeCall:u}=o0();class i extends v{constructor(Q){super(Q);if((Q===null||Q===void 0?void 0:Q.readable)===!1)this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0;if((Q===null||Q===void 0?void 0:Q.writable)===!1)this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0}}Y.exports=function Q(X,Z){if(C(X))return X;if(q(X))return I({readable:X});if(D(X))return I({writable:X});if(z(X))return I({writable:!1,readable:!1});if(F(X))return I({readable:B.fromWeb(X)});if(R(X))return I({writable:g.fromWeb(X)});if(typeof X==="function"){let{value:$,write:J,final:E,destroy:V}=U(X);if(O($))return l(i,$,{objectMode:!0,write:J,final:E,destroy:V});let S=$===null||$===void 0?void 0:$.then;if(typeof S==="function"){let H,j=u(S,$,(w)=>{if(w!=null)throw new _("nully","body",w)},(w)=>{N(H,w)});return H=new i({objectMode:!0,readable:!1,write:J,final(w){E(async()=>{try{await j,G.nextTick(w,null)}catch(p){G.nextTick(w,p)}})},destroy:V})}throw new _("Iterable, AsyncIterable or AsyncFunction",Z,$)}if(O0(X))return Q(X.arrayBuffer());if(O(X))return l(i,X,{objectMode:!0,writable:!1});if(F(X===null||X===void 0?void 0:X.readable)&&R(X===null||X===void 0?void 0:X.writable))return i.fromWeb(X);if(typeof(X===null||X===void 0?void 0:X.writable)==="object"||typeof(X===null||X===void 0?void 0:X.readable)==="object"){let $=X!==null&&X!==void 0&&X.readable?q(X===null||X===void 0?void 0:X.readable)?X===null||X===void 0?void 0:X.readable:Q(X.readable):void 0,J=X!==null&&X!==void 0&&X.writable?D(X===null||X===void 0?void 0:X.writable)?X===null||X===void 0?void 0:X.writable:Q(X.writable):void 0;return I({readable:$,writable:J})}let A=X===null||X===void 0?void 0:X.then;if(typeof A==="function"){let $;return u(A,X,(J)=>{if(J!=null)$.push(J);$.push(null)},(J)=>{N($,J)}),$=new i({objectMode:!0,writable:!1,read(){}})}throw new k(Z,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],X)};function U(Q){let{promise:X,resolve:Z}=y(),A=new Z0,$=A.signal;return{value:Q(async function*(){while(!0){let J=X;X=null;let{chunk:E,done:V,cb:S}=await J;if(G.nextTick(S),V)return;if($.aborted)throw new P(void 0,{cause:$.reason});({promise:X,resolve:Z}=y()),yield E}}(),{signal:$}),write(J,E,V){let S=Z;Z=null,S({chunk:J,done:!1,cb:V})},final(J){let E=Z;Z=null,E({done:!0,cb:J})},destroy(J,E){A.abort(),E(J)}}}function I(Q){let X=Q.readable&&typeof Q.readable.read!=="function"?B.wrap(Q.readable):Q.readable,Z=Q.writable,A=!!L(X),$=!!W(Z),J,E,V,S,H;function j(w){let p=S;if(S=null,p)p(w);else if(w)H.destroy(w)}if(H=new i({readableObjectMode:!!(X!==null&&X!==void 0&&X.readableObjectMode),writableObjectMode:!!(Z!==null&&Z!==void 0&&Z.writableObjectMode),readable:A,writable:$}),$)M(Z,(w)=>{if($=!1,w)N(X,w);j(w)}),H._write=function(w,p,n){if(Z.write(w,p))n();else J=n},H._final=function(w){Z.end(),E=w},Z.on("drain",function(){if(J){let w=J;J=null,w()}}),Z.on("finish",function(){if(E){let w=E;E=null,w()}});if(A)M(X,(w)=>{if(A=!1,w)N(X,w);j(w)}),X.on("readable",function(){if(V){let w=V;V=null,w()}}),X.on("end",function(){H.push(null)}),H._read=function(){while(!0){let w=X.read();if(w===null){V=H._read;return}if(!H.push(w))return}};return H._destroy=function(w,p){if(!w&&S!==null)w=new P;if(V=null,J=null,E=null,S===null)p(w);else S=p,N(Z,w),N(X,w)},H}}),yU=u0((T,Y)=>{var{ObjectDefineProperties:G,ObjectGetOwnPropertyDescriptor:K,ObjectKeys:L,ObjectSetPrototypeOf:W}=o0();Y.exports=q;var O=fE(),z=zX();W(q.prototype,O.prototype),W(q,O);{let R=L(z.prototype);for(let M=0;M{var{ObjectSetPrototypeOf:G,Symbol:K}=o0();Y.exports=q;var{ERR_METHOD_NOT_IMPLEMENTED:L}=zU().codes,W=yU(),{getHighWaterMark:O}=yE();G(q.prototype,W.prototype),G(q,W);var z=K("kCallback");function q(F){if(!(this instanceof q))return new q(F);let R=F?O(this,F,"readableHighWaterMark",!0):null;if(R===0)F={...F,highWaterMark:null,readableHighWaterMark:R,writableHighWaterMark:F.writableHighWaterMark||0};if(W.call(this,F),this._readableState.sync=!1,this[z]=null,F){if(typeof F.transform==="function")this._transform=F.transform;if(typeof F.flush==="function")this._flush=F.flush}this.on("prefinish",C)}function D(F){if(typeof this._flush==="function"&&!this.destroyed)this._flush((R,M)=>{if(R){if(F)F(R);else this.destroy(R);return}if(M!=null)this.push(M);if(this.push(null),F)F()});else if(this.push(null),F)F()}function C(){if(this._final!==D)D.call(this)}q.prototype._final=D,q.prototype._transform=function(F,R,M){throw new L("_transform()")},q.prototype._write=function(F,R,M){let P=this._readableState,k=this._writableState,_=P.length;this._transform(F,R,(N,v)=>{if(N){M(N);return}if(v!=null)this.push(v);if(k.ended||_===P.length||P.length{var{ObjectSetPrototypeOf:G}=o0();Y.exports=L;var K=aI();G(L.prototype,K.prototype),G(L,K);function L(W){if(!(this instanceof L))return new L(W);K.call(this,W)}L.prototype._transform=function(W,O,z){z(null,W)}}),SX=u0((T,Y)=>{var G=rU(),{ArrayIsArray:K,Promise:L,SymbolAsyncIterator:W,SymbolDispose:O}=o0(),z=bU(),{once:q}=qU(),D=IE(),C=yU(),{aggregateTwoErrors:F,codes:{ERR_INVALID_ARG_TYPE:R,ERR_INVALID_RETURN_VALUE:M,ERR_MISSING_ARGS:P,ERR_STREAM_DESTROYED:k,ERR_STREAM_PREMATURE_CLOSE:_},AbortError:N}=zU(),{validateFunction:v,validateAbortSignal:B}=LE(),{isIterable:g,isReadable:y,isReadableNodeStream:l,isNodeStream:Y0,isTransformStream:O0,isWebStream:Z0,isReadableStream:u,isReadableFinished:i}=fU(),U=globalThis.AbortController||AE().AbortController,I,Q,X;function Z(w,p,n){let G0=!1;w.on("close",()=>{G0=!0});let t=z(w,{readable:p,writable:n},(d)=>{G0=!d});return{destroy:(d)=>{if(G0)return;G0=!0,D.destroyer(w,d||new k("pipe"))},cleanup:t}}function A(w){return v(w[w.length-1],"streams[stream.length - 1]"),w.pop()}function $(w){if(g(w))return w;else if(l(w))return J(w);throw new R("val",["Readable","Iterable","AsyncIterable"],w)}async function*J(w){if(!Q)Q=fE();yield*Q.prototype[W].call(w)}async function E(w,p,n,{end:G0}){let t,d=null,I0=(g0)=>{if(g0)t=g0;if(d){let f=d;d=null,f()}},m=()=>new L((g0,f)=>{if(t)f(t);else d=()=>{if(t)f(t);else g0()}});p.on("drain",I0);let U0=z(p,{readable:!1},I0);try{if(p.writableNeedDrain)await m();for await(let g0 of w)if(!p.write(g0))await m();if(G0)p.end(),await m();n()}catch(g0){n(t!==g0?F(t,g0):g0)}finally{U0(),p.off("drain",I0)}}async function V(w,p,n,{end:G0}){if(O0(p))p=p.writable;let t=p.getWriter();try{for await(let d of w)await t.ready,t.write(d).catch(()=>{});if(await t.ready,G0)await t.close();n()}catch(d){try{await t.abort(d),n(d)}catch(I0){n(I0)}}}function S(...w){return H(w,q(A(w)))}function H(w,p,n){if(w.length===1&&K(w[0]))w=w[0];if(w.length<2)throw new P("streams");let G0=new U,t=G0.signal,d=n===null||n===void 0?void 0:n.signal,I0=[];B(d,"options.signal");function m(){e(new N)}X=X||qU().addAbortListener;let U0;if(d)U0=X(d,m);let g0,f,h=[],T0=0;function r(s){e(s,--T0===0)}function e(s,X0){var y0;if(s&&(!g0||g0.code==="ERR_STREAM_PREMATURE_CLOSE"))g0=s;if(!g0&&!X0)return;while(h.length)h.shift()(g0);if((y0=U0)===null||y0===void 0||y0[O](),G0.abort(),X0){if(!g0)I0.forEach((L0)=>L0());G.nextTick(p,g0,f)}}let C0;for(let s=0;s0,$0=y0||(n===null||n===void 0?void 0:n.end)!==!1,n0=s===w.length-1;if(Y0(X0)){let V0=function(K0){if(K0&&K0.name!=="AbortError"&&K0.code!=="ERR_STREAM_PREMATURE_CLOSE")r(K0)};var c=V0;if($0){let{destroy:K0,cleanup:r0}=Z(X0,y0,L0);if(h.push(K0),y(X0)&&n0)I0.push(r0)}if(X0.on("error",V0),y(X0)&&n0)I0.push(()=>{X0.removeListener("error",V0)})}if(s===0)if(typeof X0==="function"){if(C0=X0({signal:t}),!g(C0))throw new M("Iterable, AsyncIterable or Stream","source",C0)}else if(g(X0)||l(X0)||O0(X0))C0=X0;else C0=C.from(X0);else if(typeof X0==="function"){if(O0(C0)){var o;C0=$((o=C0)===null||o===void 0?void 0:o.readable)}else C0=$(C0);if(C0=X0(C0,{signal:t}),y0){if(!g(C0,!0))throw new M("AsyncIterable",`transform[${s-1}]`,C0)}else{var x0;if(!I)I=eI();let V0=new I({objectMode:!0}),K0=(x0=C0)===null||x0===void 0?void 0:x0.then;if(typeof K0==="function")T0++,K0.call(C0,(W0)=>{if(f=W0,W0!=null)V0.write(W0);if($0)V0.end();G.nextTick(r)},(W0)=>{V0.destroy(W0),G.nextTick(r,W0)});else if(g(C0,!0))T0++,E(C0,V0,r,{end:$0});else if(u(C0)||O0(C0)){let W0=C0.readable||C0;T0++,E(W0,V0,r,{end:$0})}else throw new M("AsyncIterable or Promise","destination",C0);C0=V0;let{destroy:r0,cleanup:H0}=Z(C0,!1,!0);if(h.push(r0),n0)I0.push(H0)}}else if(Y0(X0)){if(l(C0)){T0+=2;let V0=j(C0,X0,r,{end:$0});if(y(X0)&&n0)I0.push(V0)}else if(O0(C0)||u(C0)){let V0=C0.readable||C0;T0++,E(V0,X0,r,{end:$0})}else if(g(C0))T0++,E(C0,X0,r,{end:$0});else throw new R("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],C0);C0=X0}else if(Z0(X0)){if(l(C0))T0++,V($(C0),X0,r,{end:$0});else if(u(C0)||g(C0))T0++,V(C0,X0,r,{end:$0});else if(O0(C0))T0++,V(C0.readable,X0,r,{end:$0});else throw new R("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],C0);C0=X0}else C0=C.from(X0)}if(t!==null&&t!==void 0&&t.aborted||d!==null&&d!==void 0&&d.aborted)G.nextTick(m);return C0}function j(w,p,n,{end:G0}){let t=!1;if(p.on("close",()=>{if(!t)n(new _)}),w.pipe(p,{end:!1}),G0){let I0=function(){t=!0,p.end()};var d=I0;if(i(w))G.nextTick(I0);else w.once("end",I0)}else n();return z(w,{readable:!0,writable:!1},(I0)=>{let m=w._readableState;if(I0&&I0.code==="ERR_STREAM_PREMATURE_CLOSE"&&m&&m.ended&&!m.errored&&!m.errorEmitted)w.once("end",n).once("error",n);else n(I0)}),z(p,{readable:!1,writable:!0},n)}Y.exports={pipelineImpl:H,pipeline:S}}),iI=u0((T,Y)=>{var{pipeline:G}=SX(),K=yU(),{destroyer:L}=IE(),{isNodeStream:W,isReadable:O,isWritable:z,isWebStream:q,isTransformStream:D,isWritableStream:C,isReadableStream:F}=fU(),{AbortError:R,codes:{ERR_INVALID_ARG_VALUE:M,ERR_MISSING_ARGS:P}}=zU(),k=bU();Y.exports=function(..._){if(_.length===0)throw new P("streams");if(_.length===1)return K.from(_[0]);let N=[..._];if(typeof _[0]==="function")_[0]=K.from(_[0]);if(typeof _[_.length-1]==="function"){let U=_.length-1;_[U]=K.from(_[U])}for(let U=0;U<_.length;++U){if(!W(_[U])&&!q(_[U]))continue;if(U<_.length-1&&!(O(_[U])||F(_[U])||D(_[U])))throw new M(`streams[${U}]`,N[U],"must be readable");if(U>0&&!(z(_[U])||C(_[U])||D(_[U])))throw new M(`streams[${U}]`,N[U],"must be writable")}let v,B,g,y,l;function Y0(U){let I=y;if(y=null,I)I(U);else if(U)l.destroy(U);else if(!i&&!u)l.destroy()}let O0=_[0],Z0=G(_,Y0),u=!!(z(O0)||C(O0)||D(O0)),i=!!(O(Z0)||F(Z0)||D(Z0));if(l=new K({writableObjectMode:!!(O0!==null&&O0!==void 0&&O0.writableObjectMode),readableObjectMode:!!(Z0!==null&&Z0!==void 0&&Z0.readableObjectMode),writable:u,readable:i}),u){if(W(O0))l._write=function(I,Q,X){if(O0.write(I,Q))X();else v=X},l._final=function(I){O0.end(),B=I},O0.on("drain",function(){if(v){let I=v;v=null,I()}});else if(q(O0)){let I=(D(O0)?O0.writable:O0).getWriter();l._write=async function(Q,X,Z){try{await I.ready,I.write(Q).catch(()=>{}),Z()}catch(A){Z(A)}},l._final=async function(Q){try{await I.ready,I.close().catch(()=>{}),B=Q}catch(X){Q(X)}}}let U=D(Z0)?Z0.readable:Z0;k(U,()=>{if(B){let I=B;B=null,I()}})}if(i){if(W(Z0))Z0.on("readable",function(){if(g){let U=g;g=null,U()}}),Z0.on("end",function(){l.push(null)}),l._read=function(){while(!0){let U=Z0.read();if(U===null){g=l._read;return}if(!l.push(U))return}};else if(q(Z0)){let U=(D(Z0)?Z0.readable:Z0).getReader();l._read=async function(){while(!0)try{let{value:I,done:Q}=await U.read();if(!l.push(I))return;if(Q){l.push(null);return}}catch{return}}}}return l._destroy=function(U,I){if(!U&&y!==null)U=new R;if(g=null,v=null,B=null,y===null)I(U);else if(y=I,W(Z0))L(Z0,U)},l}}),UO=u0((T,Y)=>{var G=globalThis.AbortController||AE().AbortController,{codes:{ERR_INVALID_ARG_VALUE:K,ERR_INVALID_ARG_TYPE:L,ERR_MISSING_ARGS:W,ERR_OUT_OF_RANGE:O},AbortError:z}=zU(),{validateAbortSignal:q,validateInteger:D,validateObject:C}=LE(),F=o0().Symbol("kWeak"),R=o0().Symbol("kResistStopPropagation"),{finished:M}=bU(),P=iI(),{addAbortSignalNoValidate:k}=wE(),{isWritable:_,isNodeStream:N}=fU(),{deprecate:v}=qU(),{ArrayPrototypePush:B,Boolean:g,MathFloor:y,Number:l,NumberIsNaN:Y0,Promise:O0,PromiseReject:Z0,PromiseResolve:u,PromisePrototypeThen:i,Symbol:U}=o0(),I=U("kEmpty"),Q=U("kEof");function X(d,I0){if(I0!=null)C(I0,"options");if((I0===null||I0===void 0?void 0:I0.signal)!=null)q(I0.signal,"options.signal");if(N(d)&&!_(d))throw new K("stream",d,"must be writable");let m=P(this,d);if(I0!==null&&I0!==void 0&&I0.signal)k(I0.signal,m);return m}function Z(d,I0){if(typeof d!=="function")throw new L("fn",["Function","AsyncFunction"],d);if(I0!=null)C(I0,"options");if((I0===null||I0===void 0?void 0:I0.signal)!=null)q(I0.signal,"options.signal");let m=1;if((I0===null||I0===void 0?void 0:I0.concurrency)!=null)m=y(I0.concurrency);let U0=m-1;if((I0===null||I0===void 0?void 0:I0.highWaterMark)!=null)U0=y(I0.highWaterMark);return D(m,"options.concurrency",1),D(U0,"options.highWaterMark",0),U0+=m,async function*(){let g0=qU().AbortSignalAny([I0===null||I0===void 0?void 0:I0.signal].filter(g)),f=this,h=[],T0={signal:g0},r,e,C0=!1,c=0;function o(){C0=!0,x0()}function x0(){c-=1,s()}function s(){if(e&&!C0&&c=U0||c>=m))await new O0((L0)=>{e=L0})}h.push(Q)}catch(y0){let L0=Z0(y0);i(L0,x0,o),h.push(L0)}finally{if(C0=!0,r)r(),r=null}}X0();try{while(!0){while(h.length>0){let y0=await h[0];if(y0===Q)return;if(g0.aborted)throw new z;if(y0!==I)yield y0;h.shift(),s()}await new O0((y0)=>{r=y0})}}finally{if(C0=!0,e)e(),e=null}}.call(this)}function A(d=void 0){if(d!=null)C(d,"options");if((d===null||d===void 0?void 0:d.signal)!=null)q(d.signal,"options.signal");return async function*(){let I0=0;for await(let U0 of this){var m;if(d!==null&&d!==void 0&&(m=d.signal)!==null&&m!==void 0&&m.aborted)throw new z({cause:d.signal.reason});yield[I0++,U0]}}.call(this)}async function $(d,I0=void 0){for await(let m of S.call(this,d,I0))return!0;return!1}async function J(d,I0=void 0){if(typeof d!=="function")throw new L("fn",["Function","AsyncFunction"],d);return!await $.call(this,async(...m)=>{return!await d(...m)},I0)}async function E(d,I0){for await(let m of S.call(this,d,I0))return m;return}async function V(d,I0){if(typeof d!=="function")throw new L("fn",["Function","AsyncFunction"],d);async function m(U0,g0){return await d(U0,g0),I}for await(let U0 of Z.call(this,m,I0));}function S(d,I0){if(typeof d!=="function")throw new L("fn",["Function","AsyncFunction"],d);async function m(U0,g0){if(await d(U0,g0))return U0;return I}return Z.call(this,m,I0)}class H extends W{constructor(){super("reduce");this.message="Reduce of an empty stream requires an initial value"}}async function j(d,I0,m){var U0;if(typeof d!=="function")throw new L("reducer",["Function","AsyncFunction"],d);if(m!=null)C(m,"options");if((m===null||m===void 0?void 0:m.signal)!=null)q(m.signal,"options.signal");let g0=arguments.length>1;if(m!==null&&m!==void 0&&(U0=m.signal)!==null&&U0!==void 0&&U0.aborted){let e=new z(void 0,{cause:m.signal.reason});throw this.once("error",()=>{}),await M(this.destroy(e)),e}let f=new G,h=f.signal;if(m!==null&&m!==void 0&&m.signal){let e={once:!0,[F]:this,[R]:!0};m.signal.addEventListener("abort",()=>f.abort(),e)}let T0=!1;try{for await(let e of this){var r;if(T0=!0,m!==null&&m!==void 0&&(r=m.signal)!==null&&r!==void 0&&r.aborted)throw new z;if(!g0)I0=e,g0=!0;else I0=await d(I0,e,{signal:h})}if(!T0&&!g0)throw new H}finally{f.abort()}return I0}async function w(d){if(d!=null)C(d,"options");if((d===null||d===void 0?void 0:d.signal)!=null)q(d.signal,"options.signal");let I0=[];for await(let U0 of this){var m;if(d!==null&&d!==void 0&&(m=d.signal)!==null&&m!==void 0&&m.aborted)throw new z(void 0,{cause:d.signal.reason});B(I0,U0)}return I0}function p(d,I0){let m=Z.call(this,d,I0);return async function*(){for await(let U0 of m)yield*U0}.call(this)}function n(d){if(d=l(d),Y0(d))return 0;if(d<0)throw new O("number",">= 0",d);return d}function G0(d,I0=void 0){if(I0!=null)C(I0,"options");if((I0===null||I0===void 0?void 0:I0.signal)!=null)q(I0.signal,"options.signal");return d=n(d),async function*(){var m;if(I0!==null&&I0!==void 0&&(m=I0.signal)!==null&&m!==void 0&&m.aborted)throw new z;for await(let g0 of this){var U0;if(I0!==null&&I0!==void 0&&(U0=I0.signal)!==null&&U0!==void 0&&U0.aborted)throw new z;if(d--<=0)yield g0}}.call(this)}function t(d,I0=void 0){if(I0!=null)C(I0,"options");if((I0===null||I0===void 0?void 0:I0.signal)!=null)q(I0.signal,"options.signal");return d=n(d),async function*(){var m;if(I0!==null&&I0!==void 0&&(m=I0.signal)!==null&&m!==void 0&&m.aborted)throw new z;for await(let g0 of this){var U0;if(I0!==null&&I0!==void 0&&(U0=I0.signal)!==null&&U0!==void 0&&U0.aborted)throw new z;if(d-- >0)yield g0;if(d<=0)return}}.call(this)}Y.exports.streamReturningOperators={asIndexedPairs:v(A,"readable.asIndexedPairs will be removed in a future version."),drop:G0,filter:S,flatMap:p,map:Z,take:t,compose:X},Y.exports.promiseReturningOperators={every:J,forEach:V,reduce:j,toArray:w,some:$,find:E}}),UT=u0((T,Y)=>{var{ArrayPrototypePop:G,Promise:K}=o0(),{isIterable:L,isNodeStream:W,isWebStream:O}=fU(),{pipelineImpl:z}=SX(),{finished:q}=bU();ET();function D(...C){return new K((F,R)=>{let M,P,k=C[C.length-1];if(k&&typeof k==="object"&&!W(k)&&!L(k)&&!O(k)){let _=G(C);M=_.signal,P=_.end}z(C,(_,N)=>{if(_)R(_);else F(N)},{signal:M,end:P})})}Y.exports={finished:q,pipeline:D}}),ET=u0((T,Y)=>{var{Buffer:G}=(FU(),h0(KU)),{ObjectDefineProperty:K,ObjectKeys:L,ReflectApply:W}=o0(),{promisify:{custom:O}}=qU(),{streamReturningOperators:z,promiseReturningOperators:q}=UO(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:D}}=zU(),C=iI(),{setDefaultHighWaterMark:F,getDefaultHighWaterMark:R}=yE(),{pipeline:M}=SX(),{destroyer:P}=IE(),k=bU(),_=UT(),N=fU(),v=Y.exports=DX().Stream;v.isDestroyed=N.isDestroyed,v.isDisturbed=N.isDisturbed,v.isErrored=N.isErrored,v.isReadable=N.isReadable,v.isWritable=N.isWritable,v.Readable=fE();for(let g of L(z)){let y=function(...Y0){if(new.target)throw D();return v.Readable.from(W(l,this,Y0))},l=z[g];K(y,"name",{__proto__:null,value:l.name}),K(y,"length",{__proto__:null,value:l.length}),K(v.Readable.prototype,g,{__proto__:null,value:y,enumerable:!1,configurable:!0,writable:!0})}for(let g of L(q)){let y=function(...Y0){if(new.target)throw D();return W(l,this,Y0)},l=q[g];K(y,"name",{__proto__:null,value:l.name}),K(y,"length",{__proto__:null,value:l.length}),K(v.Readable.prototype,g,{__proto__:null,value:y,enumerable:!1,configurable:!0,writable:!0})}v.Writable=zX(),v.Duplex=yU(),v.Transform=aI(),v.PassThrough=eI(),v.pipeline=M;var{addAbortSignal:B}=wE();v.addAbortSignal=B,v.finished=k,v.destroy=P,v.compose=C,v.setDefaultHighWaterMark=F,v.getDefaultHighWaterMark=R,K(v,"promises",{__proto__:null,configurable:!0,enumerable:!0,get(){return _}}),K(M,O,{__proto__:null,enumerable:!0,get(){return _.pipeline}}),K(k,O,{__proto__:null,enumerable:!0,get(){return _.finished}}),v.Stream=v,v._isUint8Array=function(g){return g instanceof Uint8Array},v._uint8ArrayToBuffer=function(g){return G.from(g.buffer,g.byteOffset,g.byteLength)}}),EO=u0((T,Y)=>{var G=MX();{let K=ET(),L=UT(),W=K.Readable.destroy;Y.exports=K.Readable,Y.exports._uint8ArrayToBuffer=K._uint8ArrayToBuffer,Y.exports._isUint8Array=K._isUint8Array,Y.exports.isDisturbed=K.isDisturbed,Y.exports.isErrored=K.isErrored,Y.exports.isReadable=K.isReadable,Y.exports.Readable=K.Readable,Y.exports.Writable=K.Writable,Y.exports.Duplex=K.Duplex,Y.exports.Transform=K.Transform,Y.exports.PassThrough=K.PassThrough,Y.exports.addAbortSignal=K.addAbortSignal,Y.exports.finished=K.finished,Y.exports.destroy=K.destroy,Y.exports.destroy=W,Y.exports.pipeline=K.pipeline,Y.exports.compose=K.compose,Object.defineProperty(K,"promises",{configurable:!0,enumerable:!0,get(){return L}}),Y.exports.Stream=K.Stream}Y.exports.default=Y.exports});XT.exports=EO()});var PU={};jU(PU,{webcrypto:()=>_J,rng:()=>hQ,randomUUID:()=>MJ,randomFillSync:()=>RJ,randomFill:()=>HJ,randomBytes:()=>uQ,publicEncrypt:()=>$J,publicDecrypt:()=>FJ,pseudoRandomBytes:()=>pQ,prng:()=>cQ,privateEncrypt:()=>KJ,privateDecrypt:()=>WJ,pbkdf2Sync:()=>mQ,pbkdf2:()=>nQ,listCiphers:()=>IJ,getRandomValues:()=>SJ,getHashes:()=>oQ,getDiffieHellman:()=>ZJ,getCurves:()=>PJ,getCiphers:()=>XJ,default:()=>kJ,createVerify:()=>VJ,createSign:()=>JJ,createHmac:()=>lQ,createHash:()=>CE,createECDH:()=>LJ,createDiffieHellmanGroup:()=>YJ,createDiffieHellman:()=>OJ,createDecipheriv:()=>EJ,createDecipher:()=>iQ,createCredentials:()=>CJ,createCipheriv:()=>aQ,createCipher:()=>rQ,constants:()=>DJ,Verify:()=>AJ,Sign:()=>GJ,Hmac:()=>dQ,Hash:()=>bQ,DiffieHellmanGroup:()=>TJ,DiffieHellman:()=>QJ,Decipheriv:()=>UJ,Decipher:()=>eQ,DEFAULT_ENCODING:()=>zJ,Cipheriv:()=>tQ,Cipher:()=>sQ});function PJ(){return qJ}var XO,IO,IT,TO,YO,ZO=(T,Y,G)=>{G=T!=null?XO(IO(T)):{};let K=Y||!T||!T.__esModule?IT(G,"default",{value:T,enumerable:!0}):G;for(let L of TO(T))if(!YO.call(K,L))IT(K,L,{get:()=>T[L],enumerable:!0});return K},Q0=(T,Y)=>()=>(Y||T((Y={exports:{}}).exports,Y),Y.exports),cE,pE,YT,OO,PX,_X,SU,QO,KE,ZT,JO,GO,VO,AO,OT,LO,$O,KO,FO,WO,HO,RO,CO,DO,zO,FE,hE,QT,SO,JT,GT,MO,WE,kX,vX,qO,VT,jX,PO,AT,_O,LT,$T,kO,vO,jO,NO,BO,xO,gO,wO,yO,fO,cO,pO,hO,uO,NX,KT,bO,FT,dO,lO,oO,nO,cU,dU,WT,vU,HT,uE,mO,_U,sO,rO,tO,RT,xU,HE,CT,aO,DT,eO,zT,iO,UQ,EQ,XQ,BX,IQ,xX,TQ,YQ,ZQ,OQ,QQ,JQ,GQ,VQ,AQ,LQ,$Q,KQ,FQ,WQ,TT,HQ,$E,RQ,ST,MT,CQ,DQ,qT,zQ,SQ,RE,MQ,qQ,PQ,_Q,kQ,vQ,PT,jQ,_T,kT,vT,gX,jT,NQ,NT,BQ,xQ,qX,gQ,wQ,yQ,fQ,p0,cQ,pQ,hQ,uQ,bQ,CE,dQ,lQ,oQ,nQ,mQ,sQ,rQ,tQ,aQ,eQ,iQ,UJ,EJ,XJ,IJ,TJ,YJ,ZJ,OJ,QJ,JJ,GJ,VJ,AJ,LJ,$J,KJ,FJ,WJ,HJ,RJ,CJ,DJ,zJ="buffer",SJ=(T)=>{return crypto.getRandomValues(T)},MJ=()=>{return crypto.randomUUID()},qJ,_J,kJ;var DU=GU(()=>{XO=Object.create,{getPrototypeOf:IO,defineProperty:IT,getOwnPropertyNames:TO}=Object,YO=Object.prototype.hasOwnProperty,cE=Q0((T,Y)=>{Y.exports=(DU(),h0(PU)).randomBytes}),pE=Q0((T,Y)=>{Y.exports=(DU(),h0(PU)).createHash}),YT=Q0((T,Y)=>{Y.exports=(DU(),h0(PU)).createHmac}),OO=Q0((T,Y)=>{Y.exports={sha224WithRSAEncryption:{sign:"rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},"RSA-SHA224":{sign:"ecdsa/rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},sha256WithRSAEncryption:{sign:"rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},"RSA-SHA256":{sign:"ecdsa/rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},sha384WithRSAEncryption:{sign:"rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},"RSA-SHA384":{sign:"ecdsa/rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},sha512WithRSAEncryption:{sign:"rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA512":{sign:"ecdsa/rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA1":{sign:"rsa",hash:"sha1",id:"3021300906052b0e03021a05000414"},"ecdsa-with-SHA1":{sign:"ecdsa",hash:"sha1",id:""},sha256:{sign:"ecdsa",hash:"sha256",id:""},sha224:{sign:"ecdsa",hash:"sha224",id:""},sha384:{sign:"ecdsa",hash:"sha384",id:""},sha512:{sign:"ecdsa",hash:"sha512",id:""},"DSA-SHA":{sign:"dsa",hash:"sha1",id:""},"DSA-SHA1":{sign:"dsa",hash:"sha1",id:""},DSA:{sign:"dsa",hash:"sha1",id:""},"DSA-WITH-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-WITH-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-WITH-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-WITH-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-RIPEMD160":{sign:"dsa",hash:"rmd160",id:""},ripemd160WithRSA:{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},"RSA-RIPEMD160":{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},md5WithRSAEncryption:{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"},"RSA-MD5":{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"}}}),PX=Q0((T,Y)=>{var G=isFinite,K=Math.pow(2,30)-1;Y.exports=function(L,W){if(typeof L!=="number")throw TypeError("Iterations not a number");if(L<0||!G(L))throw TypeError("Bad iterations");if(typeof W!=="number")throw TypeError("Key length not a number");if(W<0||W>K||W!==W)throw TypeError("Bad key length")}}),_X=Q0((T,Y)=>{var G;if(globalThis.process&&globalThis.process.browser)G="utf-8";else if(globalThis.process&&globalThis.process.version)K=parseInt(process.version.split(".")[0].slice(1),10),G=K>=6?"utf-8":"binary";else G="utf-8";var K;Y.exports=G}),SU=Q0((T,Y)=>{/*! safe-buffer. MIT License. Feross Aboukhadijeh */var G=(FU(),h0(KU)),K=G.Buffer;function L(O,z){for(var q in O)z[q]=O[q]}if(K.from&&K.alloc&&K.allocUnsafe&&K.allocUnsafeSlow)Y.exports=G;else L(G,T),T.Buffer=W;function W(O,z,q){return K(O,z,q)}W.prototype=Object.create(K.prototype),L(K,W),W.from=function(O,z,q){if(typeof O==="number")throw TypeError("Argument must not be a number");return K(O,z,q)},W.alloc=function(O,z,q){if(typeof O!=="number")throw TypeError("Argument must be a number");var D=K(O);if(z!==void 0)if(typeof q==="string")D.fill(z,q);else D.fill(z);else D.fill(0);return D},W.allocUnsafe=function(O){if(typeof O!=="number")throw TypeError("Argument must be a number");return K(O)},W.allocUnsafeSlow=function(O){if(typeof O!=="number")throw TypeError("Argument must be a number");return G.SlowBuffer(O)}}),QO=Q0((T,Y)=>{var G={}.toString;Y.exports=Array.isArray||function(K){return G.call(K)=="[object Array]"}}),KE=Q0((T,Y)=>{Y.exports=TypeError}),ZT=Q0((T,Y)=>{Y.exports=Object}),JO=Q0((T,Y)=>{Y.exports=Error}),GO=Q0((T,Y)=>{Y.exports=EvalError}),VO=Q0((T,Y)=>{Y.exports=RangeError}),AO=Q0((T,Y)=>{Y.exports=ReferenceError}),OT=Q0((T,Y)=>{Y.exports=SyntaxError}),LO=Q0((T,Y)=>{Y.exports=URIError}),$O=Q0((T,Y)=>{Y.exports=Math.abs}),KO=Q0((T,Y)=>{Y.exports=Math.floor}),FO=Q0((T,Y)=>{Y.exports=Math.max}),WO=Q0((T,Y)=>{Y.exports=Math.min}),HO=Q0((T,Y)=>{Y.exports=Math.pow}),RO=Q0((T,Y)=>{Y.exports=Math.round}),CO=Q0((T,Y)=>{Y.exports=Number.isNaN||function(G){return G!==G}}),DO=Q0((T,Y)=>{var G=CO();Y.exports=function(K){if(G(K)||K===0)return K;return K<0?-1:1}}),zO=Q0((T,Y)=>{Y.exports=Object.getOwnPropertyDescriptor}),FE=Q0((T,Y)=>{var G=zO();if(G)try{G([],"length")}catch(K){G=null}Y.exports=G}),hE=Q0((T,Y)=>{var G=Object.defineProperty||!1;if(G)try{G({},"a",{value:1})}catch(K){G=!1}Y.exports=G}),QT=Q0((T,Y)=>{Y.exports=function(){if(typeof Symbol!=="function"||typeof Object.getOwnPropertySymbols!=="function")return!1;if(typeof Symbol.iterator==="symbol")return!0;var G={},K=Symbol("test"),L=Object(K);if(typeof K==="string")return!1;if(Object.prototype.toString.call(K)!=="[object Symbol]")return!1;if(Object.prototype.toString.call(L)!=="[object Symbol]")return!1;var W=42;G[K]=W;for(var O in G)return!1;if(typeof Object.keys==="function"&&Object.keys(G).length!==0)return!1;if(typeof Object.getOwnPropertyNames==="function"&&Object.getOwnPropertyNames(G).length!==0)return!1;var z=Object.getOwnPropertySymbols(G);if(z.length!==1||z[0]!==K)return!1;if(!Object.prototype.propertyIsEnumerable.call(G,K))return!1;if(typeof Object.getOwnPropertyDescriptor==="function"){var q=Object.getOwnPropertyDescriptor(G,K);if(q.value!==W||q.enumerable!==!0)return!1}return!0}}),SO=Q0((T,Y)=>{var G=typeof Symbol<"u"&&Symbol,K=QT();Y.exports=function(){if(typeof G!=="function")return!1;if(typeof Symbol!=="function")return!1;if(typeof G("foo")!=="symbol")return!1;if(typeof Symbol("bar")!=="symbol")return!1;return K()}}),JT=Q0((T,Y)=>{Y.exports=typeof Reflect<"u"&&Reflect.getPrototypeOf||null}),GT=Q0((T,Y)=>{var G=ZT();Y.exports=G.getPrototypeOf||null}),MO=Q0((T,Y)=>{var G="Function.prototype.bind called on incompatible ",K=Object.prototype.toString,L=Math.max,W="[object Function]",O=function(D,C){var F=[];for(var R=0;R{var G=MO();Y.exports=Function.prototype.bind||G}),kX=Q0((T,Y)=>{Y.exports=Function.prototype.call}),vX=Q0((T,Y)=>{Y.exports=Function.prototype.apply}),qO=Q0((T,Y)=>{Y.exports=typeof Reflect<"u"&&Reflect&&Reflect.apply}),VT=Q0((T,Y)=>{var G=WE(),K=vX(),L=kX(),W=qO();Y.exports=W||G.call(L,K)}),jX=Q0((T,Y)=>{var G=WE(),K=KE(),L=kX(),W=VT();Y.exports=function(O){if(O.length<1||typeof O[0]!=="function")throw new K("a function is required");return W(G,L,O)}}),PO=Q0((T,Y)=>{var G=jX(),K=FE(),L;try{L=[].__proto__===Array.prototype}catch(q){if(!q||typeof q!=="object"||!("code"in q)||q.code!=="ERR_PROTO_ACCESS")throw q}var W=!!L&&K&&K(Object.prototype,"__proto__"),O=Object,z=O.getPrototypeOf;Y.exports=W&&typeof W.get==="function"?G([W.get]):typeof z==="function"?function(q){return z(q==null?q:O(q))}:!1}),AT=Q0((T,Y)=>{var G=JT(),K=GT(),L=PO();Y.exports=G?function(W){return G(W)}:K?function(W){if(!W||typeof W!=="object"&&typeof W!=="function")throw TypeError("getProto: not an object");return K(W)}:L?function(W){return L(W)}:null}),_O=Q0((T,Y)=>{var G=Function.prototype.call,K=Object.prototype.hasOwnProperty,L=WE();Y.exports=L.call(G,K)}),LT=Q0((T,Y)=>{var G,K=ZT(),L=JO(),W=GO(),O=VO(),z=AO(),q=OT(),D=KE(),C=LO(),F=$O(),R=KO(),M=FO(),P=WO(),k=HO(),_=RO(),N=DO(),v=Function,B=function(I0){try{return v('"use strict"; return ('+I0+").constructor;")()}catch(m){}},g=FE(),y=hE(),l=function(){throw new D},Y0=g?function(){try{return arguments.callee,l}catch(I0){try{return g(arguments,"callee").get}catch(m){return l}}}():l,O0=SO()(),Z0=AT(),u=GT(),i=JT(),U=vX(),I=kX(),Q={},X=typeof Uint8Array>"u"||!Z0?G:Z0(Uint8Array),Z={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?G:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?G:ArrayBuffer,"%ArrayIteratorPrototype%":O0&&Z0?Z0([][Symbol.iterator]()):G,"%AsyncFromSyncIteratorPrototype%":G,"%AsyncFunction%":Q,"%AsyncGenerator%":Q,"%AsyncGeneratorFunction%":Q,"%AsyncIteratorPrototype%":Q,"%Atomics%":typeof Atomics>"u"?G:Atomics,"%BigInt%":typeof BigInt>"u"?G:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?G:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?G:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?G:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":L,"%eval%":eval,"%EvalError%":W,"%Float16Array%":typeof Float16Array>"u"?G:Float16Array,"%Float32Array%":typeof Float32Array>"u"?G:Float32Array,"%Float64Array%":typeof Float64Array>"u"?G:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?G:FinalizationRegistry,"%Function%":v,"%GeneratorFunction%":Q,"%Int8Array%":typeof Int8Array>"u"?G:Int8Array,"%Int16Array%":typeof Int16Array>"u"?G:Int16Array,"%Int32Array%":typeof Int32Array>"u"?G:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":O0&&Z0?Z0(Z0([][Symbol.iterator]())):G,"%JSON%":typeof JSON==="object"?JSON:G,"%Map%":typeof Map>"u"?G:Map,"%MapIteratorPrototype%":typeof Map>"u"||!O0||!Z0?G:Z0(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":K,"%Object.getOwnPropertyDescriptor%":g,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?G:Promise,"%Proxy%":typeof Proxy>"u"?G:Proxy,"%RangeError%":O,"%ReferenceError%":z,"%Reflect%":typeof Reflect>"u"?G:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?G:Set,"%SetIteratorPrototype%":typeof Set>"u"||!O0||!Z0?G:Z0(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?G:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":O0&&Z0?Z0(""[Symbol.iterator]()):G,"%Symbol%":O0?Symbol:G,"%SyntaxError%":q,"%ThrowTypeError%":Y0,"%TypedArray%":X,"%TypeError%":D,"%Uint8Array%":typeof Uint8Array>"u"?G:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?G:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?G:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?G:Uint32Array,"%URIError%":C,"%WeakMap%":typeof WeakMap>"u"?G:WeakMap,"%WeakRef%":typeof WeakRef>"u"?G:WeakRef,"%WeakSet%":typeof WeakSet>"u"?G:WeakSet,"%Function.prototype.call%":I,"%Function.prototype.apply%":U,"%Object.defineProperty%":y,"%Object.getPrototypeOf%":u,"%Math.abs%":F,"%Math.floor%":R,"%Math.max%":M,"%Math.min%":P,"%Math.pow%":k,"%Math.round%":_,"%Math.sign%":N,"%Reflect.getPrototypeOf%":i};if(Z0)try{null.error}catch(I0){A=Z0(Z0(I0)),Z["%Error.prototype%"]=A}var A,$=function I0(m){var U0;if(m==="%AsyncFunction%")U0=B("async function () {}");else if(m==="%GeneratorFunction%")U0=B("function* () {}");else if(m==="%AsyncGeneratorFunction%")U0=B("async function* () {}");else if(m==="%AsyncGenerator%"){var g0=I0("%AsyncGeneratorFunction%");if(g0)U0=g0.prototype}else if(m==="%AsyncIteratorPrototype%"){var f=I0("%AsyncGenerator%");if(f&&Z0)U0=Z0(f.prototype)}return Z[m]=U0,U0},J={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},E=WE(),V=_O(),S=E.call(I,Array.prototype.concat),H=E.call(U,Array.prototype.splice),j=E.call(I,String.prototype.replace),w=E.call(I,String.prototype.slice),p=E.call(I,RegExp.prototype.exec),n=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,G0=/\\(\\)?/g,t=function(I0){var m=w(I0,0,1),U0=w(I0,-1);if(m==="%"&&U0!=="%")throw new q("invalid intrinsic syntax, expected closing `%`");else if(U0==="%"&&m!=="%")throw new q("invalid intrinsic syntax, expected opening `%`");var g0=[];return j(I0,n,function(f,h,T0,r){g0[g0.length]=T0?j(r,G0,"$1"):h||f}),g0},d=function(I0,m){var U0=I0,g0;if(V(J,U0))g0=J[U0],U0="%"+g0[0]+"%";if(V(Z,U0)){var f=Z[U0];if(f===Q)f=$(U0);if(typeof f>"u"&&!m)throw new D("intrinsic "+I0+" exists, but is not available. Please file an issue!");return{alias:g0,name:U0,value:f}}throw new q("intrinsic "+I0+" does not exist!")};Y.exports=function(I0,m){if(typeof I0!=="string"||I0.length===0)throw new D("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof m!=="boolean")throw new D('"allowMissing" argument must be a boolean');if(p(/^%?[^%]*%?$/,I0)===null)throw new q("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var U0=t(I0),g0=U0.length>0?U0[0]:"",f=d("%"+g0+"%",m),h=f.name,T0=f.value,r=!1,e=f.alias;if(e)g0=e[0],H(U0,S([0,1],e));for(var C0=1,c=!0;C0=U0.length){var X0=g(T0,o);if(c=!!X0,c&&"get"in X0&&!("originalValue"in X0.get))T0=X0.get;else T0=T0[o]}else c=V(T0,o),T0=T0[o];if(c&&!r)Z[h]=T0}}return T0}}),$T=Q0((T,Y)=>{var G=LT(),K=jX(),L=K([G("%String.prototype.indexOf%")]);Y.exports=function(W,O){var z=G(W,!!O);if(typeof z==="function"&&L(W,".prototype.")>-1)return K([z]);return z}}),kO=Q0((T,Y)=>{var G=Function.prototype.toString,K=typeof Reflect==="object"&&Reflect!==null&&Reflect.apply,L,W;if(typeof K==="function"&&typeof Object.defineProperty==="function")try{L=Object.defineProperty({},"length",{get:function(){throw W}}),W={},K(function(){throw 42},null,L)}catch(g){if(g!==W)K=null}else K=null;var O=/^\s*class\b/,z=function(g){try{var y=G.call(g);return O.test(y)}catch(l){return!1}},q=function(g){try{if(z(g))return!1;return G.call(g),!0}catch(y){return!1}},D=Object.prototype.toString,C="[object Object]",F="[object Function]",R="[object GeneratorFunction]",M="[object HTMLAllCollection]",P="[object HTML document.all class]",k="[object HTMLCollection]",_=typeof Symbol==="function"&&!!Symbol.toStringTag,N=!(0 in[,]),v=function(){return!1};if(typeof document==="object"){if(B=document.all,D.call(B)===D.call(document.all))v=function(g){if((N||!g)&&(typeof g>"u"||typeof g==="object"))try{var y=D.call(g);return(y===M||y===P||y===k||y===C)&&g("")==null}catch(l){}return!1}}var B;Y.exports=K?function(g){if(v(g))return!0;if(!g)return!1;if(typeof g!=="function"&&typeof g!=="object")return!1;try{K(g,null,L)}catch(y){if(y!==W)return!1}return!z(g)&&q(g)}:function(g){if(v(g))return!0;if(!g)return!1;if(typeof g!=="function"&&typeof g!=="object")return!1;if(_)return q(g);if(z(g))return!1;var y=D.call(g);if(y!==F&&y!==R&&!/^\[object HTML/.test(y))return!1;return q(g)}}),vO=Q0((T,Y)=>{var G=kO(),K=Object.prototype.toString,L=Object.prototype.hasOwnProperty,W=function(D,C,F){for(var R=0,M=D.length;R=3)R=F;if(q(D))W(D,C,R);else if(typeof D==="string")O(D,C,R);else z(D,C,R)}}),jO=Q0((T,Y)=>{Y.exports=["Float16Array","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array"]}),NO=Q0((T,Y)=>{var G=jO(),K=typeof globalThis>"u"?globalThis:globalThis;Y.exports=function(){var L=[];for(var W=0;W{var G=hE(),K=OT(),L=KE(),W=FE();Y.exports=function(O,z,q){if(!O||typeof O!=="object"&&typeof O!=="function")throw new L("`obj` must be an object or a function`");if(typeof z!=="string"&&typeof z!=="symbol")throw new L("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!=="boolean"&&arguments[3]!==null)throw new L("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!=="boolean"&&arguments[4]!==null)throw new L("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!=="boolean"&&arguments[5]!==null)throw new L("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!=="boolean")throw new L("`loose`, if provided, must be a boolean");var D=arguments.length>3?arguments[3]:null,C=arguments.length>4?arguments[4]:null,F=arguments.length>5?arguments[5]:null,R=arguments.length>6?arguments[6]:!1,M=!!W&&W(O,z);if(G)G(O,z,{configurable:F===null&&M?M.configurable:!F,enumerable:D===null&&M?M.enumerable:!D,value:q,writable:C===null&&M?M.writable:!C});else if(R||!D&&!C&&!F)O[z]=q;else throw new K("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")}}),xO=Q0((T,Y)=>{var G=hE(),K=function(){return!!G};K.hasArrayLengthDefineBug=function(){if(!G)return null;try{return G([],"length",{value:1}).length!==1}catch(L){return!0}},Y.exports=K}),gO=Q0((T,Y)=>{var G=LT(),K=BO(),L=xO()(),W=FE(),O=KE(),z=G("%Math.floor%");Y.exports=function(q,D){if(typeof q!=="function")throw new O("`fn` is not a function");if(typeof D!=="number"||D<0||D>4294967295||z(D)!==D)throw new O("`length` must be a positive 32-bit integer");var C=arguments.length>2&&!!arguments[2],F=!0,R=!0;if("length"in q&&W){var M=W(q,"length");if(M&&!M.configurable)F=!1;if(M&&!M.writable)R=!1}if(F||R||!C)if(L)K(q,"length",D,!0,!0);else K(q,"length",D);return q}}),wO=Q0((T,Y)=>{var G=WE(),K=vX(),L=VT();Y.exports=function(){return L(G,K,arguments)}}),yO=Q0((T,Y)=>{var G=gO(),K=hE(),L=jX(),W=wO();if(Y.exports=function(O){var z=L(arguments),q=O.length-(arguments.length-1);return G(z,1+(q>0?q:0),!0)},K)K(Y.exports,"apply",{value:W});else Y.exports.apply=W}),fO=Q0((T,Y)=>{var G=QT();Y.exports=function(){return G()&&!!Symbol.toStringTag}}),cO=Q0((T,Y)=>{var G=vO(),K=NO(),L=yO(),W=$T(),O=FE(),z=AT(),q=W("Object.prototype.toString"),D=fO()(),C=typeof globalThis>"u"?globalThis:globalThis,F=K(),R=W("String.prototype.slice"),M=W("Array.prototype.indexOf",!0)||function(N,v){for(var B=0;B-1)return v;if(v!=="Object")return!1;return _(N)}if(!O)return null;return k(N)}}),pO=Q0((T,Y)=>{var G=cO();Y.exports=function(K){return!!G(K)}}),hO=Q0((T,Y)=>{var G=KE(),K=$T(),L=K("TypedArray.prototype.buffer",!0),W=pO();Y.exports=L||function(O){if(!W(O))throw new G("Not a Typed Array");return O.buffer}}),uO=Q0((T,Y)=>{var G=SU().Buffer,K=QO(),L=hO(),W=ArrayBuffer.isView||function(D){try{return L(D),!0}catch(C){return!1}},O=typeof Uint8Array<"u",z=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",q=z&&(G.prototype instanceof Uint8Array||G.TYPED_ARRAY_SUPPORT);Y.exports=function(D,C){if(G.isBuffer(D)){if(D.constructor&&!("isBuffer"in D))return G.from(D);return D}if(typeof D==="string")return G.from(D,C);if(z&&W(D)){if(D.byteLength===0)return G.alloc(0);if(q){var F=G.from(D.buffer,D.byteOffset,D.byteLength);if(F.byteLength===D.byteLength)return F}var R=D instanceof Uint8Array?D:new Uint8Array(D.buffer,D.byteOffset,D.byteLength),M=G.from(R);if(M.length===D.byteLength)return M}if(O&&D instanceof Uint8Array)return G.from(D);var P=K(D);if(P)for(var k=0;k255||~~_!==_)throw RangeError("Array items must be numbers in the range 0-255.")}if(P||G.isBuffer(D)&&D.constructor&&typeof D.constructor.isBuffer==="function"&&D.constructor.isBuffer(D))return G.from(D);throw TypeError('The "data" argument must be a string, an Array, a Buffer, a Uint8Array, or a DataView.')}}),NX=Q0((T,Y)=>{var G=SU().Buffer,K=uO(),L=typeof Uint8Array<"u",W=L&&typeof ArrayBuffer<"u",O=W&&ArrayBuffer.isView;Y.exports=function(z,q,D){if(typeof z==="string"||G.isBuffer(z)||L&&z instanceof Uint8Array||O&&O(z))return K(z,q);throw TypeError(D+" must be a string, a Buffer, a Uint8Array, or a DataView")}}),KT=Q0((T,Y)=>{var G={__proto__:null,md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,"sha512-256":32,rmd160:20,ripemd160:20},K={__proto__:null,"sha-1":"sha1","sha-224":"sha224","sha-256":"sha256","sha-384":"sha384","sha-512":"sha512","ripemd-160":"ripemd160"},L=YT(),W=SU().Buffer,O=PX(),z=_X(),q=NX();function D(C,F,R,M,P){O(R,M),C=q(C,z,"Password"),F=q(F,z,"Salt");var k=(P||"sha1").toLowerCase(),_=K[k]||k,N=G[_];if(typeof N!=="number"||!N)throw TypeError("Digest algorithm not supported: "+P);var v=W.allocUnsafe(M),B=W.allocUnsafe(F.length+4);F.copy(B,0,0,F.length);var g=0,y=N,l=Math.ceil(M/y);for(var Y0=1;Y0<=l;Y0++){B.writeUInt32BE(Y0,F.length);var O0=L(_,C).update(B).digest(),Z0=O0;for(var u=1;u{var G=SU().Buffer,K=PX(),L=_X(),W=KT(),O=NX(),z,q=globalThis.crypto&&globalThis.crypto.subtle,D={sha:"SHA-1","sha-1":"SHA-1",sha1:"SHA-1",sha256:"SHA-256","sha-256":"SHA-256",sha384:"SHA-384","sha-384":"SHA-384","sha-512":"SHA-512",sha512:"SHA-512"},C=[],F;function R(){if(F)return F;if(globalThis.process&&globalThis.process.nextTick)F=globalThis.process.nextTick;else if(globalThis.queueMicrotask)F=globalThis.queueMicrotask;else if(globalThis.setImmediate)F=globalThis.setImmediate;else F=globalThis.setTimeout;return F}function M(_,N,v,B,g){return q.importKey("raw",_,{name:"PBKDF2"},!1,["deriveBits"]).then(function(y){return q.deriveBits({name:"PBKDF2",salt:N,iterations:v,hash:{name:g}},y,B<<3)}).then(function(y){return G.from(y)})}function P(_){if(globalThis.process&&!globalThis.process.browser)return Promise.resolve(!1);if(!q||!q.importKey||!q.deriveBits)return Promise.resolve(!1);if(C[_]!==void 0)return C[_];z=z||G.alloc(8);var N=M(z,z,10,128,_).then(function(){return!0},function(){return!1});return C[_]=N,N}function k(_,N){_.then(function(v){R()(function(){N(null,v)})},function(v){R()(function(){N(v)})})}Y.exports=function(_,N,v,B,g,y){if(typeof g==="function")y=g,g=void 0;if(K(v,B),_=O(_,L,"Password"),N=O(N,L,"Salt"),typeof y!=="function")throw Error("No callback provided to pbkdf2");g=g||"sha1";var l=D[g.toLowerCase()];if(!l||typeof globalThis.Promise!=="function"){R()(function(){var Y0;try{Y0=W(_,N,v,B,g)}catch(O0){y(O0);return}y(null,Y0)});return}k(P(l).then(function(Y0){if(Y0)return M(_,N,v,B,l);return W(_,N,v,B,g)}),y)}}),FT=Q0((T)=>{var Y=(DU(),h0(PU)),G=PX(),K=_X(),L=NX();function W(z,q,D,C,F,R){if(G(D,C),z=L(z,K,"Password"),q=L(q,K,"Salt"),typeof F==="function")R=F,F="sha1";if(typeof R!=="function")throw Error("No callback provided to pbkdf2");return Y.pbkdf2(z,q,D,C,F,R)}function O(z,q,D,C,F){return G(D,C),z=L(z,K,"Password"),q=L(q,K,"Salt"),F=F||"sha1",Y.pbkdf2Sync(z,q,D,C,F)}if(!Y.pbkdf2Sync||Y.pbkdf2Sync.toString().indexOf("keylen, digest")===-1)T.pbkdf2Sync=KT(),T.pbkdf2=bO();else T.pbkdf2Sync=O,T.pbkdf2=W}),dO=Q0((T)=>{var Y=(DU(),h0(PU));T.createCipher=T.Cipher=Y.createCipher,T.createCipheriv=T.Cipheriv=Y.createCipheriv,T.createDecipher=T.Decipher=Y.createDecipher,T.createDecipheriv=T.Decipheriv=Y.createDecipheriv,T.listCiphers=T.getCiphers=Y.getCiphers}),lO=Q0((T)=>{var Y=(DU(),h0(PU));T.DiffieHellmanGroup=Y.DiffieHellmanGroup,T.createDiffieHellmanGroup=Y.createDiffieHellmanGroup,T.getDiffieHellman=Y.getDiffieHellman,T.createDiffieHellman=Y.createDiffieHellman,T.DiffieHellman=Y.DiffieHellman}),oO=Q0((T)=>{var Y=(DU(),h0(PU));T.createSign=Y.createSign,T.Sign=Y.Sign,T.createVerify=Y.createVerify,T.Verify=Y.Verify}),nO=Q0((T,Y)=>{Y.exports={name:"elliptic",version:"6.6.1",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{lint:"eslint lib test","lint:fix":"npm run lint -- --fix",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^2.0.2",coveralls:"^3.1.0",eslint:"^7.6.0",grunt:"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.5",mocha:"^8.0.1"},dependencies:{"bn.js":"^4.11.9",brorand:"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1",inherits:"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}}),cU=Q0((T,Y)=>{(function(G,K){function L(U,I){if(!U)throw Error(I||"Assertion failed")}function W(U,I){U.super_=I;var Q=function(){};Q.prototype=I.prototype,U.prototype=new Q,U.prototype.constructor=U}function O(U,I,Q){if(O.isBN(U))return U;if(this.negative=0,this.words=null,this.length=0,this.red=null,U!==null){if(I==="le"||I==="be")Q=I,I=10;this._init(U||0,I||10,Q||"be")}}if(typeof G==="object")G.exports=O;else K.BN=O;O.BN=O,O.wordSize=26;var z;try{if(typeof window<"u"&&typeof window.Buffer<"u")z=window.Buffer;else z=(FU(),h0(KU)).Buffer}catch(U){}O.isBN=function(U){if(U instanceof O)return!0;return U!==null&&typeof U==="object"&&U.constructor.wordSize===O.wordSize&&Array.isArray(U.words)},O.max=function(U,I){if(U.cmp(I)>0)return U;return I},O.min=function(U,I){if(U.cmp(I)<0)return U;return I},O.prototype._init=function(U,I,Q){if(typeof U==="number")return this._initNumber(U,I,Q);if(typeof U==="object")return this._initArray(U,I,Q);if(I==="hex")I=16;L(I===(I|0)&&I>=2&&I<=36),U=U.toString().replace(/\s+/g,"");var X=0;if(U[0]==="-")X++,this.negative=1;if(X=0;X-=3)if(A=U[X]|U[X-1]<<8|U[X-2]<<16,this.words[Z]|=A<<$&67108863,this.words[Z+1]=A>>>26-$&67108863,$+=24,$>=26)$-=26,Z++}else if(Q==="le"){for(X=0,Z=0;X>>26-$&67108863,$+=24,$>=26)$-=26,Z++}return this.strip()};function q(U,I){var Q=U.charCodeAt(I);if(Q>=65&&Q<=70)return Q-55;else if(Q>=97&&Q<=102)return Q-87;else return Q-48&15}function D(U,I,Q){var X=q(U,Q);if(Q-1>=I)X|=q(U,Q-1)<<4;return X}O.prototype._parseHex=function(U,I,Q){this.length=Math.ceil((U.length-I)/6),this.words=Array(this.length);for(var X=0;X=I;X-=2)if($=D(U,I,X)<=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8;else{var J=U.length-I;for(X=J%2===0?I+1:I;X=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8}this.strip()};function C(U,I,Q,X){var Z=0,A=Math.min(U.length,Q);for(var $=I;$=49)Z+=J-49+10;else if(J>=17)Z+=J-17+10;else Z+=J}return Z}O.prototype._parseBase=function(U,I,Q){this.words=[0],this.length=1;for(var X=0,Z=1;Z<=67108863;Z*=I)X++;X--,Z=Z/I|0;var A=U.length-Q,$=A%X,J=Math.min(A,A-$)+Q,E=0;for(var V=Q;V1&&this.words[this.length-1]===0)this.length--;return this._normSign()},O.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},O.prototype.inspect=function(){return(this.red?""};var F=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],R=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],M=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(O.prototype.toString=function(U,I){U=U||10,I=I|0||1;var Q;if(U===16||U==="hex"){Q="";var X=0,Z=0;for(var A=0;A>>24-X&16777215,X+=2,X>=26)X-=26,A--;if(Z!==0||A!==this.length-1)Q=F[6-J.length]+J+Q;else Q=J+Q}if(Z!==0)Q=Z.toString(16)+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}if(U===(U|0)&&U>=2&&U<=36){var E=R[U],V=M[U];Q="";var S=this.clone();S.negative=0;while(!S.isZero()){var H=S.modn(V).toString(U);if(S=S.idivn(V),!S.isZero())Q=F[E-H.length]+H+Q;else Q=H+Q}if(this.isZero())Q="0"+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}L(!1,"Base should be between 2 and 36")},O.prototype.toNumber=function(){var U=this.words[0];if(this.length===2)U+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)U+=4503599627370496+this.words[1]*67108864;else if(this.length>2)L(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-U:U},O.prototype.toJSON=function(){return this.toString(16)},O.prototype.toBuffer=function(U,I){return L(typeof z<"u"),this.toArrayLike(z,U,I)},O.prototype.toArray=function(U,I){return this.toArrayLike(Array,U,I)},O.prototype.toArrayLike=function(U,I,Q){var X=this.byteLength(),Z=Q||Math.max(1,X);L(X<=Z,"byte array longer than desired length"),L(Z>0,"Requested array length <= 0"),this.strip();var A=I==="le",$=new U(Z),J,E,V=this.clone();if(!A){for(E=0;E=4096)Q+=13,I>>>=13;if(I>=64)Q+=7,I>>>=7;if(I>=8)Q+=4,I>>>=4;if(I>=2)Q+=2,I>>>=2;return Q+I};O.prototype._zeroBits=function(U){if(U===0)return 26;var I=U,Q=0;if((I&8191)===0)Q+=13,I>>>=13;if((I&127)===0)Q+=7,I>>>=7;if((I&15)===0)Q+=4,I>>>=4;if((I&3)===0)Q+=2,I>>>=2;if((I&1)===0)Q++;return Q},O.prototype.bitLength=function(){var U=this.words[this.length-1],I=this._countBits(U);return(this.length-1)*26+I};function P(U){var I=Array(U.bitLength());for(var Q=0;Q>>Z}return I}O.prototype.zeroBits=function(){if(this.isZero())return 0;var U=0;for(var I=0;IU.length)return this.clone().ior(U);return U.clone().ior(this)},O.prototype.uor=function(U){if(this.length>U.length)return this.clone().iuor(U);return U.clone().iuor(this)},O.prototype.iuand=function(U){var I;if(this.length>U.length)I=U;else I=this;for(var Q=0;QU.length)return this.clone().iand(U);return U.clone().iand(this)},O.prototype.uand=function(U){if(this.length>U.length)return this.clone().iuand(U);return U.clone().iuand(this)},O.prototype.iuxor=function(U){var I,Q;if(this.length>U.length)I=this,Q=U;else I=U,Q=this;for(var X=0;XU.length)return this.clone().ixor(U);return U.clone().ixor(this)},O.prototype.uxor=function(U){if(this.length>U.length)return this.clone().iuxor(U);return U.clone().iuxor(this)},O.prototype.inotn=function(U){L(typeof U==="number"&&U>=0);var I=Math.ceil(U/26)|0,Q=U%26;if(this._expand(I),Q>0)I--;for(var X=0;X0)this.words[X]=~this.words[X]&67108863>>26-Q;return this.strip()},O.prototype.notn=function(U){return this.clone().inotn(U)},O.prototype.setn=function(U,I){L(typeof U==="number"&&U>=0);var Q=U/26|0,X=U%26;if(this._expand(Q+1),I)this.words[Q]=this.words[Q]|1<U.length)Q=this,X=U;else Q=U,X=this;var Z=0;for(var A=0;A>>26;for(;Z!==0&&A>>26;if(this.length=Q.length,Z!==0)this.words[this.length]=Z,this.length++;else if(Q!==this)for(;AU.length)return this.clone().iadd(U);return U.clone().iadd(this)},O.prototype.isub=function(U){if(U.negative!==0){U.negative=0;var I=this.iadd(U);return U.negative=1,I._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(U),this.negative=1,this._normSign();var Q=this.cmp(U);if(Q===0)return this.negative=0,this.length=1,this.words[0]=0,this;var X,Z;if(Q>0)X=this,Z=U;else X=U,Z=this;var A=0;for(var $=0;$>26,this.words[$]=I&67108863;for(;A!==0&&$>26,this.words[$]=I&67108863;if(A===0&&$>>26,H=E&67108863,j=Math.min(V,I.length-1);for(var w=Math.max(0,V-U.length+1);w<=j;w++){var p=V-w|0;Z=U.words[p]|0,A=I.words[w]|0,$=Z*A+H,S+=$/67108864|0,H=$&67108863}Q.words[V]=H|0,E=S|0}if(E!==0)Q.words[V]=E|0;else Q.length--;return Q.strip()}var _=function(U,I,Q){var X=U.words,Z=I.words,A=Q.words,$=0,J,E,V,S=X[0]|0,H=S&8191,j=S>>>13,w=X[1]|0,p=w&8191,n=w>>>13,G0=X[2]|0,t=G0&8191,d=G0>>>13,I0=X[3]|0,m=I0&8191,U0=I0>>>13,g0=X[4]|0,f=g0&8191,h=g0>>>13,T0=X[5]|0,r=T0&8191,e=T0>>>13,C0=X[6]|0,c=C0&8191,o=C0>>>13,x0=X[7]|0,s=x0&8191,X0=x0>>>13,y0=X[8]|0,L0=y0&8191,$0=y0>>>13,n0=X[9]|0,V0=n0&8191,K0=n0>>>13,r0=Z[0]|0,H0=r0&8191,W0=r0>>>13,RU=Z[1]|0,D0=RU&8191,_0=RU>>>13,CU=Z[2]|0,k0=CU&8191,z0=CU>>>13,WU=Z[3]|0,v0=WU&8191,S0=WU>>>13,AU=Z[4]|0,j0=AU&8191,N0=AU>>>13,LU=Z[5]|0,M0=LU&8191,x=LU>>>13,b=Z[6]|0,a=b&8191,E0=b>>>13,w0=Z[7]|0,A0=w0&8191,F0=w0>>>13,m0=Z[8]|0,q0=m0&8191,B0=m0>>>13,HU=Z[9]|0,P0=HU&8191,R0=HU>>>13;Q.negative=U.negative^I.negative,Q.length=19,J=Math.imul(H,H0),E=Math.imul(H,W0),E=E+Math.imul(j,H0)|0,V=Math.imul(j,W0);var s0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(s0>>>26)|0,s0&=67108863,J=Math.imul(p,H0),E=Math.imul(p,W0),E=E+Math.imul(n,H0)|0,V=Math.imul(n,W0),J=J+Math.imul(H,D0)|0,E=E+Math.imul(H,_0)|0,E=E+Math.imul(j,D0)|0,V=V+Math.imul(j,_0)|0;var c0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(c0>>>26)|0,c0&=67108863,J=Math.imul(t,H0),E=Math.imul(t,W0),E=E+Math.imul(d,H0)|0,V=Math.imul(d,W0),J=J+Math.imul(p,D0)|0,E=E+Math.imul(p,_0)|0,E=E+Math.imul(n,D0)|0,V=V+Math.imul(n,_0)|0,J=J+Math.imul(H,k0)|0,E=E+Math.imul(H,z0)|0,E=E+Math.imul(j,k0)|0,V=V+Math.imul(j,z0)|0;var f0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(f0>>>26)|0,f0&=67108863,J=Math.imul(m,H0),E=Math.imul(m,W0),E=E+Math.imul(U0,H0)|0,V=Math.imul(U0,W0),J=J+Math.imul(t,D0)|0,E=E+Math.imul(t,_0)|0,E=E+Math.imul(d,D0)|0,V=V+Math.imul(d,_0)|0,J=J+Math.imul(p,k0)|0,E=E+Math.imul(p,z0)|0,E=E+Math.imul(n,k0)|0,V=V+Math.imul(n,z0)|0,J=J+Math.imul(H,v0)|0,E=E+Math.imul(H,S0)|0,E=E+Math.imul(j,v0)|0,V=V+Math.imul(j,S0)|0;var d0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(d0>>>26)|0,d0&=67108863,J=Math.imul(f,H0),E=Math.imul(f,W0),E=E+Math.imul(h,H0)|0,V=Math.imul(h,W0),J=J+Math.imul(m,D0)|0,E=E+Math.imul(m,_0)|0,E=E+Math.imul(U0,D0)|0,V=V+Math.imul(U0,_0)|0,J=J+Math.imul(t,k0)|0,E=E+Math.imul(t,z0)|0,E=E+Math.imul(d,k0)|0,V=V+Math.imul(d,z0)|0,J=J+Math.imul(p,v0)|0,E=E+Math.imul(p,S0)|0,E=E+Math.imul(n,v0)|0,V=V+Math.imul(n,S0)|0,J=J+Math.imul(H,j0)|0,E=E+Math.imul(H,N0)|0,E=E+Math.imul(j,j0)|0,V=V+Math.imul(j,N0)|0;var b0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(b0>>>26)|0,b0&=67108863,J=Math.imul(r,H0),E=Math.imul(r,W0),E=E+Math.imul(e,H0)|0,V=Math.imul(e,W0),J=J+Math.imul(f,D0)|0,E=E+Math.imul(f,_0)|0,E=E+Math.imul(h,D0)|0,V=V+Math.imul(h,_0)|0,J=J+Math.imul(m,k0)|0,E=E+Math.imul(m,z0)|0,E=E+Math.imul(U0,k0)|0,V=V+Math.imul(U0,z0)|0,J=J+Math.imul(t,v0)|0,E=E+Math.imul(t,S0)|0,E=E+Math.imul(d,v0)|0,V=V+Math.imul(d,S0)|0,J=J+Math.imul(p,j0)|0,E=E+Math.imul(p,N0)|0,E=E+Math.imul(n,j0)|0,V=V+Math.imul(n,N0)|0,J=J+Math.imul(H,M0)|0,E=E+Math.imul(H,x)|0,E=E+Math.imul(j,M0)|0,V=V+Math.imul(j,x)|0;var t0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(t0>>>26)|0,t0&=67108863,J=Math.imul(c,H0),E=Math.imul(c,W0),E=E+Math.imul(o,H0)|0,V=Math.imul(o,W0),J=J+Math.imul(r,D0)|0,E=E+Math.imul(r,_0)|0,E=E+Math.imul(e,D0)|0,V=V+Math.imul(e,_0)|0,J=J+Math.imul(f,k0)|0,E=E+Math.imul(f,z0)|0,E=E+Math.imul(h,k0)|0,V=V+Math.imul(h,z0)|0,J=J+Math.imul(m,v0)|0,E=E+Math.imul(m,S0)|0,E=E+Math.imul(U0,v0)|0,V=V+Math.imul(U0,S0)|0,J=J+Math.imul(t,j0)|0,E=E+Math.imul(t,N0)|0,E=E+Math.imul(d,j0)|0,V=V+Math.imul(d,N0)|0,J=J+Math.imul(p,M0)|0,E=E+Math.imul(p,x)|0,E=E+Math.imul(n,M0)|0,V=V+Math.imul(n,x)|0,J=J+Math.imul(H,a)|0,E=E+Math.imul(H,E0)|0,E=E+Math.imul(j,a)|0,V=V+Math.imul(j,E0)|0;var a0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(a0>>>26)|0,a0&=67108863,J=Math.imul(s,H0),E=Math.imul(s,W0),E=E+Math.imul(X0,H0)|0,V=Math.imul(X0,W0),J=J+Math.imul(c,D0)|0,E=E+Math.imul(c,_0)|0,E=E+Math.imul(o,D0)|0,V=V+Math.imul(o,_0)|0,J=J+Math.imul(r,k0)|0,E=E+Math.imul(r,z0)|0,E=E+Math.imul(e,k0)|0,V=V+Math.imul(e,z0)|0,J=J+Math.imul(f,v0)|0,E=E+Math.imul(f,S0)|0,E=E+Math.imul(h,v0)|0,V=V+Math.imul(h,S0)|0,J=J+Math.imul(m,j0)|0,E=E+Math.imul(m,N0)|0,E=E+Math.imul(U0,j0)|0,V=V+Math.imul(U0,N0)|0,J=J+Math.imul(t,M0)|0,E=E+Math.imul(t,x)|0,E=E+Math.imul(d,M0)|0,V=V+Math.imul(d,x)|0,J=J+Math.imul(p,a)|0,E=E+Math.imul(p,E0)|0,E=E+Math.imul(n,a)|0,V=V+Math.imul(n,E0)|0,J=J+Math.imul(H,A0)|0,E=E+Math.imul(H,F0)|0,E=E+Math.imul(j,A0)|0,V=V+Math.imul(j,F0)|0;var e0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(e0>>>26)|0,e0&=67108863,J=Math.imul(L0,H0),E=Math.imul(L0,W0),E=E+Math.imul($0,H0)|0,V=Math.imul($0,W0),J=J+Math.imul(s,D0)|0,E=E+Math.imul(s,_0)|0,E=E+Math.imul(X0,D0)|0,V=V+Math.imul(X0,_0)|0,J=J+Math.imul(c,k0)|0,E=E+Math.imul(c,z0)|0,E=E+Math.imul(o,k0)|0,V=V+Math.imul(o,z0)|0,J=J+Math.imul(r,v0)|0,E=E+Math.imul(r,S0)|0,E=E+Math.imul(e,v0)|0,V=V+Math.imul(e,S0)|0,J=J+Math.imul(f,j0)|0,E=E+Math.imul(f,N0)|0,E=E+Math.imul(h,j0)|0,V=V+Math.imul(h,N0)|0,J=J+Math.imul(m,M0)|0,E=E+Math.imul(m,x)|0,E=E+Math.imul(U0,M0)|0,V=V+Math.imul(U0,x)|0,J=J+Math.imul(t,a)|0,E=E+Math.imul(t,E0)|0,E=E+Math.imul(d,a)|0,V=V+Math.imul(d,E0)|0,J=J+Math.imul(p,A0)|0,E=E+Math.imul(p,F0)|0,E=E+Math.imul(n,A0)|0,V=V+Math.imul(n,F0)|0,J=J+Math.imul(H,q0)|0,E=E+Math.imul(H,B0)|0,E=E+Math.imul(j,q0)|0,V=V+Math.imul(j,B0)|0;var i0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(i0>>>26)|0,i0&=67108863,J=Math.imul(V0,H0),E=Math.imul(V0,W0),E=E+Math.imul(K0,H0)|0,V=Math.imul(K0,W0),J=J+Math.imul(L0,D0)|0,E=E+Math.imul(L0,_0)|0,E=E+Math.imul($0,D0)|0,V=V+Math.imul($0,_0)|0,J=J+Math.imul(s,k0)|0,E=E+Math.imul(s,z0)|0,E=E+Math.imul(X0,k0)|0,V=V+Math.imul(X0,z0)|0,J=J+Math.imul(c,v0)|0,E=E+Math.imul(c,S0)|0,E=E+Math.imul(o,v0)|0,V=V+Math.imul(o,S0)|0,J=J+Math.imul(r,j0)|0,E=E+Math.imul(r,N0)|0,E=E+Math.imul(e,j0)|0,V=V+Math.imul(e,N0)|0,J=J+Math.imul(f,M0)|0,E=E+Math.imul(f,x)|0,E=E+Math.imul(h,M0)|0,V=V+Math.imul(h,x)|0,J=J+Math.imul(m,a)|0,E=E+Math.imul(m,E0)|0,E=E+Math.imul(U0,a)|0,V=V+Math.imul(U0,E0)|0,J=J+Math.imul(t,A0)|0,E=E+Math.imul(t,F0)|0,E=E+Math.imul(d,A0)|0,V=V+Math.imul(d,F0)|0,J=J+Math.imul(p,q0)|0,E=E+Math.imul(p,B0)|0,E=E+Math.imul(n,q0)|0,V=V+Math.imul(n,B0)|0,J=J+Math.imul(H,P0)|0,E=E+Math.imul(H,R0)|0,E=E+Math.imul(j,P0)|0,V=V+Math.imul(j,R0)|0;var UU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(UU>>>26)|0,UU&=67108863,J=Math.imul(V0,D0),E=Math.imul(V0,_0),E=E+Math.imul(K0,D0)|0,V=Math.imul(K0,_0),J=J+Math.imul(L0,k0)|0,E=E+Math.imul(L0,z0)|0,E=E+Math.imul($0,k0)|0,V=V+Math.imul($0,z0)|0,J=J+Math.imul(s,v0)|0,E=E+Math.imul(s,S0)|0,E=E+Math.imul(X0,v0)|0,V=V+Math.imul(X0,S0)|0,J=J+Math.imul(c,j0)|0,E=E+Math.imul(c,N0)|0,E=E+Math.imul(o,j0)|0,V=V+Math.imul(o,N0)|0,J=J+Math.imul(r,M0)|0,E=E+Math.imul(r,x)|0,E=E+Math.imul(e,M0)|0,V=V+Math.imul(e,x)|0,J=J+Math.imul(f,a)|0,E=E+Math.imul(f,E0)|0,E=E+Math.imul(h,a)|0,V=V+Math.imul(h,E0)|0,J=J+Math.imul(m,A0)|0,E=E+Math.imul(m,F0)|0,E=E+Math.imul(U0,A0)|0,V=V+Math.imul(U0,F0)|0,J=J+Math.imul(t,q0)|0,E=E+Math.imul(t,B0)|0,E=E+Math.imul(d,q0)|0,V=V+Math.imul(d,B0)|0,J=J+Math.imul(p,P0)|0,E=E+Math.imul(p,R0)|0,E=E+Math.imul(n,P0)|0,V=V+Math.imul(n,R0)|0;var EU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(EU>>>26)|0,EU&=67108863,J=Math.imul(V0,k0),E=Math.imul(V0,z0),E=E+Math.imul(K0,k0)|0,V=Math.imul(K0,z0),J=J+Math.imul(L0,v0)|0,E=E+Math.imul(L0,S0)|0,E=E+Math.imul($0,v0)|0,V=V+Math.imul($0,S0)|0,J=J+Math.imul(s,j0)|0,E=E+Math.imul(s,N0)|0,E=E+Math.imul(X0,j0)|0,V=V+Math.imul(X0,N0)|0,J=J+Math.imul(c,M0)|0,E=E+Math.imul(c,x)|0,E=E+Math.imul(o,M0)|0,V=V+Math.imul(o,x)|0,J=J+Math.imul(r,a)|0,E=E+Math.imul(r,E0)|0,E=E+Math.imul(e,a)|0,V=V+Math.imul(e,E0)|0,J=J+Math.imul(f,A0)|0,E=E+Math.imul(f,F0)|0,E=E+Math.imul(h,A0)|0,V=V+Math.imul(h,F0)|0,J=J+Math.imul(m,q0)|0,E=E+Math.imul(m,B0)|0,E=E+Math.imul(U0,q0)|0,V=V+Math.imul(U0,B0)|0,J=J+Math.imul(t,P0)|0,E=E+Math.imul(t,R0)|0,E=E+Math.imul(d,P0)|0,V=V+Math.imul(d,R0)|0;var XU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(XU>>>26)|0,XU&=67108863,J=Math.imul(V0,v0),E=Math.imul(V0,S0),E=E+Math.imul(K0,v0)|0,V=Math.imul(K0,S0),J=J+Math.imul(L0,j0)|0,E=E+Math.imul(L0,N0)|0,E=E+Math.imul($0,j0)|0,V=V+Math.imul($0,N0)|0,J=J+Math.imul(s,M0)|0,E=E+Math.imul(s,x)|0,E=E+Math.imul(X0,M0)|0,V=V+Math.imul(X0,x)|0,J=J+Math.imul(c,a)|0,E=E+Math.imul(c,E0)|0,E=E+Math.imul(o,a)|0,V=V+Math.imul(o,E0)|0,J=J+Math.imul(r,A0)|0,E=E+Math.imul(r,F0)|0,E=E+Math.imul(e,A0)|0,V=V+Math.imul(e,F0)|0,J=J+Math.imul(f,q0)|0,E=E+Math.imul(f,B0)|0,E=E+Math.imul(h,q0)|0,V=V+Math.imul(h,B0)|0,J=J+Math.imul(m,P0)|0,E=E+Math.imul(m,R0)|0,E=E+Math.imul(U0,P0)|0,V=V+Math.imul(U0,R0)|0;var IU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(IU>>>26)|0,IU&=67108863,J=Math.imul(V0,j0),E=Math.imul(V0,N0),E=E+Math.imul(K0,j0)|0,V=Math.imul(K0,N0),J=J+Math.imul(L0,M0)|0,E=E+Math.imul(L0,x)|0,E=E+Math.imul($0,M0)|0,V=V+Math.imul($0,x)|0,J=J+Math.imul(s,a)|0,E=E+Math.imul(s,E0)|0,E=E+Math.imul(X0,a)|0,V=V+Math.imul(X0,E0)|0,J=J+Math.imul(c,A0)|0,E=E+Math.imul(c,F0)|0,E=E+Math.imul(o,A0)|0,V=V+Math.imul(o,F0)|0,J=J+Math.imul(r,q0)|0,E=E+Math.imul(r,B0)|0,E=E+Math.imul(e,q0)|0,V=V+Math.imul(e,B0)|0,J=J+Math.imul(f,P0)|0,E=E+Math.imul(f,R0)|0,E=E+Math.imul(h,P0)|0,V=V+Math.imul(h,R0)|0;var TU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(TU>>>26)|0,TU&=67108863,J=Math.imul(V0,M0),E=Math.imul(V0,x),E=E+Math.imul(K0,M0)|0,V=Math.imul(K0,x),J=J+Math.imul(L0,a)|0,E=E+Math.imul(L0,E0)|0,E=E+Math.imul($0,a)|0,V=V+Math.imul($0,E0)|0,J=J+Math.imul(s,A0)|0,E=E+Math.imul(s,F0)|0,E=E+Math.imul(X0,A0)|0,V=V+Math.imul(X0,F0)|0,J=J+Math.imul(c,q0)|0,E=E+Math.imul(c,B0)|0,E=E+Math.imul(o,q0)|0,V=V+Math.imul(o,B0)|0,J=J+Math.imul(r,P0)|0,E=E+Math.imul(r,R0)|0,E=E+Math.imul(e,P0)|0,V=V+Math.imul(e,R0)|0;var YU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(YU>>>26)|0,YU&=67108863,J=Math.imul(V0,a),E=Math.imul(V0,E0),E=E+Math.imul(K0,a)|0,V=Math.imul(K0,E0),J=J+Math.imul(L0,A0)|0,E=E+Math.imul(L0,F0)|0,E=E+Math.imul($0,A0)|0,V=V+Math.imul($0,F0)|0,J=J+Math.imul(s,q0)|0,E=E+Math.imul(s,B0)|0,E=E+Math.imul(X0,q0)|0,V=V+Math.imul(X0,B0)|0,J=J+Math.imul(c,P0)|0,E=E+Math.imul(c,R0)|0,E=E+Math.imul(o,P0)|0,V=V+Math.imul(o,R0)|0;var ZU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(ZU>>>26)|0,ZU&=67108863,J=Math.imul(V0,A0),E=Math.imul(V0,F0),E=E+Math.imul(K0,A0)|0,V=Math.imul(K0,F0),J=J+Math.imul(L0,q0)|0,E=E+Math.imul(L0,B0)|0,E=E+Math.imul($0,q0)|0,V=V+Math.imul($0,B0)|0,J=J+Math.imul(s,P0)|0,E=E+Math.imul(s,R0)|0,E=E+Math.imul(X0,P0)|0,V=V+Math.imul(X0,R0)|0;var OU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(OU>>>26)|0,OU&=67108863,J=Math.imul(V0,q0),E=Math.imul(V0,B0),E=E+Math.imul(K0,q0)|0,V=Math.imul(K0,B0),J=J+Math.imul(L0,P0)|0,E=E+Math.imul(L0,R0)|0,E=E+Math.imul($0,P0)|0,V=V+Math.imul($0,R0)|0;var QU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(QU>>>26)|0,QU&=67108863,J=Math.imul(V0,P0),E=Math.imul(V0,R0),E=E+Math.imul(K0,P0)|0,V=Math.imul(K0,R0);var JU=($+J|0)+((E&8191)<<13)|0;if($=(V+(E>>>13)|0)+(JU>>>26)|0,JU&=67108863,A[0]=s0,A[1]=c0,A[2]=f0,A[3]=d0,A[4]=b0,A[5]=t0,A[6]=a0,A[7]=e0,A[8]=i0,A[9]=UU,A[10]=EU,A[11]=XU,A[12]=IU,A[13]=TU,A[14]=YU,A[15]=ZU,A[16]=OU,A[17]=QU,A[18]=JU,$!==0)A[19]=$,Q.length++;return Q};if(!Math.imul)_=k;function N(U,I,Q){Q.negative=I.negative^U.negative,Q.length=U.length+I.length;var X=0,Z=0;for(var A=0;A>>26)|0,Z+=$>>>26,$&=67108863}Q.words[A]=J,X=$,$=Z}if(X!==0)Q.words[A]=X;else Q.length--;return Q.strip()}function v(U,I,Q){var X=new B;return X.mulp(U,I,Q)}O.prototype.mulTo=function(U,I){var Q,X=this.length+U.length;if(this.length===10&&U.length===10)Q=_(this,U,I);else if(X<63)Q=k(this,U,I);else if(X<1024)Q=N(this,U,I);else Q=v(this,U,I);return Q};function B(U,I){this.x=U,this.y=I}B.prototype.makeRBT=function(U){var I=Array(U),Q=O.prototype._countBits(U)-1;for(var X=0;X>=1;return X},B.prototype.permute=function(U,I,Q,X,Z,A){for(var $=0;$>>1)Z++;return 1<>>13,Q[2*A+1]=Z&8191,Z=Z>>>13;for(A=2*I;A>=26,I+=X/67108864|0,I+=Z>>>26,this.words[Q]=Z&67108863}if(I!==0)this.words[Q]=I,this.length++;return this.length=U===0?1:this.length,this},O.prototype.muln=function(U){return this.clone().imuln(U)},O.prototype.sqr=function(){return this.mul(this)},O.prototype.isqr=function(){return this.imul(this.clone())},O.prototype.pow=function(U){var I=P(U);if(I.length===0)return new O(1);var Q=this;for(var X=0;X=0);var I=U%26,Q=(U-I)/26,X=67108863>>>26-I<<26-I,Z;if(I!==0){var A=0;for(Z=0;Z>>26-I}if(A)this.words[Z]=A,this.length++}if(Q!==0){for(Z=this.length-1;Z>=0;Z--)this.words[Z+Q]=this.words[Z];for(Z=0;Z=0);var X;if(I)X=(I-I%26)/26;else X=0;var Z=U%26,A=Math.min((U-Z)/26,this.length),$=67108863^67108863>>>Z<A){this.length-=A;for(E=0;E=0&&(V!==0||E>=X);E--){var S=this.words[E]|0;this.words[E]=V<<26-Z|S>>>Z,V=S&$}if(J&&V!==0)J.words[J.length++]=V;if(this.length===0)this.words[0]=0,this.length=1;return this.strip()},O.prototype.ishrn=function(U,I,Q){return L(this.negative===0),this.iushrn(U,I,Q)},O.prototype.shln=function(U){return this.clone().ishln(U)},O.prototype.ushln=function(U){return this.clone().iushln(U)},O.prototype.shrn=function(U){return this.clone().ishrn(U)},O.prototype.ushrn=function(U){return this.clone().iushrn(U)},O.prototype.testn=function(U){L(typeof U==="number"&&U>=0);var I=U%26,Q=(U-I)/26,X=1<=0);var I=U%26,Q=(U-I)/26;if(L(this.negative===0,"imaskn works only with positive numbers"),this.length<=Q)return this;if(I!==0)Q++;if(this.length=Math.min(Q,this.length),I!==0){var X=67108863^67108863>>>I<=67108864;I++)if(this.words[I]-=67108864,I===this.length-1)this.words[I+1]=1;else this.words[I+1]++;return this.length=Math.max(this.length,I+1),this},O.prototype.isubn=function(U){if(L(typeof U==="number"),L(U<67108864),U<0)return this.iaddn(-U);if(this.negative!==0)return this.negative=0,this.iaddn(U),this.negative=1,this;if(this.words[0]-=U,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var I=0;I>26)-(J/67108864|0),this.words[Z+Q]=A&67108863}for(;Z>26,this.words[Z+Q]=A&67108863;if($===0)return this.strip();L($===-1),$=0;for(Z=0;Z>26,this.words[Z]=A&67108863;return this.negative=1,this.strip()},O.prototype._wordDiv=function(U,I){var Q=this.length-U.length,X=this.clone(),Z=U,A=Z.words[Z.length-1]|0,$=this._countBits(A);if(Q=26-$,Q!==0)Z=Z.ushln(Q),X.iushln(Q),A=Z.words[Z.length-1]|0;var J=X.length-Z.length,E;if(I!=="mod"){E=new O(null),E.length=J+1,E.words=Array(E.length);for(var V=0;V=0;H--){var j=(X.words[Z.length+H]|0)*67108864+(X.words[Z.length+H-1]|0);j=Math.min(j/A|0,67108863),X._ishlnsubmul(Z,j,H);while(X.negative!==0)if(j--,X.negative=0,X._ishlnsubmul(Z,1,H),!X.isZero())X.negative^=1;if(E)E.words[H]=j}if(E)E.strip();if(X.strip(),I!=="div"&&Q!==0)X.iushrn(Q);return{div:E||null,mod:X}},O.prototype.divmod=function(U,I,Q){if(L(!U.isZero()),this.isZero())return{div:new O(0),mod:new O(0)};var X,Z,A;if(this.negative!==0&&U.negative===0){if(A=this.neg().divmod(U,I),I!=="mod")X=A.div.neg();if(I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.iadd(U)}return{div:X,mod:Z}}if(this.negative===0&&U.negative!==0){if(A=this.divmod(U.neg(),I),I!=="mod")X=A.div.neg();return{div:X,mod:A.mod}}if((this.negative&U.negative)!==0){if(A=this.neg().divmod(U.neg(),I),I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.isub(U)}return{div:A.div,mod:Z}}if(U.length>this.length||this.cmp(U)<0)return{div:new O(0),mod:this};if(U.length===1){if(I==="div")return{div:this.divn(U.words[0]),mod:null};if(I==="mod")return{div:null,mod:new O(this.modn(U.words[0]))};return{div:this.divn(U.words[0]),mod:new O(this.modn(U.words[0]))}}return this._wordDiv(U,I)},O.prototype.div=function(U){return this.divmod(U,"div",!1).div},O.prototype.mod=function(U){return this.divmod(U,"mod",!1).mod},O.prototype.umod=function(U){return this.divmod(U,"mod",!0).mod},O.prototype.divRound=function(U){var I=this.divmod(U);if(I.mod.isZero())return I.div;var Q=I.div.negative!==0?I.mod.isub(U):I.mod,X=U.ushrn(1),Z=U.andln(1),A=Q.cmp(X);if(A<0||Z===1&&A===0)return I.div;return I.div.negative!==0?I.div.isubn(1):I.div.iaddn(1)},O.prototype.modn=function(U){L(U<=67108863);var I=67108864%U,Q=0;for(var X=this.length-1;X>=0;X--)Q=(I*Q+(this.words[X]|0))%U;return Q},O.prototype.idivn=function(U){L(U<=67108863);var I=0;for(var Q=this.length-1;Q>=0;Q--){var X=(this.words[Q]|0)+I*67108864;this.words[Q]=X/U|0,I=X%U}return this.strip()},O.prototype.divn=function(U){return this.clone().idivn(U)},O.prototype.egcd=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=new O(0),$=new O(1),J=0;while(I.isEven()&&Q.isEven())I.iushrn(1),Q.iushrn(1),++J;var E=Q.clone(),V=I.clone();while(!I.isZero()){for(var S=0,H=1;(I.words[0]&H)===0&&S<26;++S,H<<=1);if(S>0){I.iushrn(S);while(S-- >0){if(X.isOdd()||Z.isOdd())X.iadd(E),Z.isub(V);X.iushrn(1),Z.iushrn(1)}}for(var j=0,w=1;(Q.words[0]&w)===0&&j<26;++j,w<<=1);if(j>0){Q.iushrn(j);while(j-- >0){if(A.isOdd()||$.isOdd())A.iadd(E),$.isub(V);A.iushrn(1),$.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(A),Z.isub($);else Q.isub(I),A.isub(X),$.isub(Z)}return{a:A,b:$,gcd:Q.iushln(J)}},O.prototype._invmp=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=Q.clone();while(I.cmpn(1)>0&&Q.cmpn(1)>0){for(var $=0,J=1;(I.words[0]&J)===0&&$<26;++$,J<<=1);if($>0){I.iushrn($);while($-- >0){if(X.isOdd())X.iadd(A);X.iushrn(1)}}for(var E=0,V=1;(Q.words[0]&V)===0&&E<26;++E,V<<=1);if(E>0){Q.iushrn(E);while(E-- >0){if(Z.isOdd())Z.iadd(A);Z.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(Z);else Q.isub(I),Z.isub(X)}var S;if(I.cmpn(1)===0)S=X;else S=Z;if(S.cmpn(0)<0)S.iadd(U);return S},O.prototype.gcd=function(U){if(this.isZero())return U.abs();if(U.isZero())return this.abs();var I=this.clone(),Q=U.clone();I.negative=0,Q.negative=0;for(var X=0;I.isEven()&&Q.isEven();X++)I.iushrn(1),Q.iushrn(1);do{while(I.isEven())I.iushrn(1);while(Q.isEven())Q.iushrn(1);var Z=I.cmp(Q);if(Z<0){var A=I;I=Q,Q=A}else if(Z===0||Q.cmpn(1)===0)break;I.isub(Q)}while(!0);return Q.iushln(X)},O.prototype.invm=function(U){return this.egcd(U).a.umod(U)},O.prototype.isEven=function(){return(this.words[0]&1)===0},O.prototype.isOdd=function(){return(this.words[0]&1)===1},O.prototype.andln=function(U){return this.words[0]&U},O.prototype.bincn=function(U){L(typeof U==="number");var I=U%26,Q=(U-I)/26,X=1<>>26,$&=67108863,this.words[A]=$}if(Z!==0)this.words[A]=Z,this.length++;return this},O.prototype.isZero=function(){return this.length===1&&this.words[0]===0},O.prototype.cmpn=function(U){var I=U<0;if(this.negative!==0&&!I)return-1;if(this.negative===0&&I)return 1;this.strip();var Q;if(this.length>1)Q=1;else{if(I)U=-U;L(U<=67108863,"Number is too big");var X=this.words[0]|0;Q=X===U?0:XU.length)return 1;if(this.length=0;Q--){var X=this.words[Q]|0,Z=U.words[Q]|0;if(X===Z)continue;if(XZ)I=1;break}return I},O.prototype.gtn=function(U){return this.cmpn(U)===1},O.prototype.gt=function(U){return this.cmp(U)===1},O.prototype.gten=function(U){return this.cmpn(U)>=0},O.prototype.gte=function(U){return this.cmp(U)>=0},O.prototype.ltn=function(U){return this.cmpn(U)===-1},O.prototype.lt=function(U){return this.cmp(U)===-1},O.prototype.lten=function(U){return this.cmpn(U)<=0},O.prototype.lte=function(U){return this.cmp(U)<=0},O.prototype.eqn=function(U){return this.cmpn(U)===0},O.prototype.eq=function(U){return this.cmp(U)===0},O.red=function(U){return new u(U)},O.prototype.toRed=function(U){return L(!this.red,"Already a number in reduction context"),L(this.negative===0,"red works only with positives"),U.convertTo(this)._forceRed(U)},O.prototype.fromRed=function(){return L(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},O.prototype._forceRed=function(U){return this.red=U,this},O.prototype.forceRed=function(U){return L(!this.red,"Already a number in reduction context"),this._forceRed(U)},O.prototype.redAdd=function(U){return L(this.red,"redAdd works only with red numbers"),this.red.add(this,U)},O.prototype.redIAdd=function(U){return L(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,U)},O.prototype.redSub=function(U){return L(this.red,"redSub works only with red numbers"),this.red.sub(this,U)},O.prototype.redISub=function(U){return L(this.red,"redISub works only with red numbers"),this.red.isub(this,U)},O.prototype.redShl=function(U){return L(this.red,"redShl works only with red numbers"),this.red.shl(this,U)},O.prototype.redMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.mul(this,U)},O.prototype.redIMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.imul(this,U)},O.prototype.redSqr=function(){return L(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},O.prototype.redISqr=function(){return L(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},O.prototype.redSqrt=function(){return L(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},O.prototype.redInvm=function(){return L(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},O.prototype.redNeg=function(){return L(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},O.prototype.redPow=function(U){return L(this.red&&!U.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,U)};var g={k256:null,p224:null,p192:null,p25519:null};function y(U,I){this.name=U,this.p=new O(I,16),this.n=this.p.bitLength(),this.k=new O(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}y.prototype._tmp=function(){var U=new O(null);return U.words=Array(Math.ceil(this.n/13)),U},y.prototype.ireduce=function(U){var I=U,Q;do this.split(I,this.tmp),I=this.imulK(I),I=I.iadd(this.tmp),Q=I.bitLength();while(Q>this.n);var X=Q0)I.isub(this.p);else if(I.strip!==void 0)I.strip();else I._strip();return I},y.prototype.split=function(U,I){U.iushrn(this.n,0,I)},y.prototype.imulK=function(U){return U.imul(this.k)};function l(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}W(l,y),l.prototype.split=function(U,I){var Q=4194303,X=Math.min(U.length,9);for(var Z=0;Z>>22,A=$}if(A>>>=22,U.words[Z-10]=A,A===0&&U.length>10)U.length-=10;else U.length-=9},l.prototype.imulK=function(U){U.words[U.length]=0,U.words[U.length+1]=0,U.length+=2;var I=0;for(var Q=0;Q>>=26,U.words[Q]=Z,I=X}if(I!==0)U.words[U.length++]=I;return U},O._prime=function(U){if(g[U])return g[U];var I;if(U==="k256")I=new l;else if(U==="p224")I=new Y0;else if(U==="p192")I=new O0;else if(U==="p25519")I=new Z0;else throw Error("Unknown prime "+U);return g[U]=I,I};function u(U){if(typeof U==="string"){var I=O._prime(U);this.m=I.p,this.prime=I}else L(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}u.prototype._verify1=function(U){L(U.negative===0,"red works only with positives"),L(U.red,"red works only with red numbers")},u.prototype._verify2=function(U,I){L((U.negative|I.negative)===0,"red works only with positives"),L(U.red&&U.red===I.red,"red works only with red numbers")},u.prototype.imod=function(U){if(this.prime)return this.prime.ireduce(U)._forceRed(this);return U.umod(this.m)._forceRed(this)},u.prototype.neg=function(U){if(U.isZero())return U.clone();return this.m.sub(U)._forceRed(this)},u.prototype.add=function(U,I){this._verify2(U,I);var Q=U.add(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q._forceRed(this)},u.prototype.iadd=function(U,I){this._verify2(U,I);var Q=U.iadd(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q},u.prototype.sub=function(U,I){this._verify2(U,I);var Q=U.sub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q._forceRed(this)},u.prototype.isub=function(U,I){this._verify2(U,I);var Q=U.isub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q},u.prototype.shl=function(U,I){return this._verify1(U),this.imod(U.ushln(I))},u.prototype.imul=function(U,I){return this._verify2(U,I),this.imod(U.imul(I))},u.prototype.mul=function(U,I){return this._verify2(U,I),this.imod(U.mul(I))},u.prototype.isqr=function(U){return this.imul(U,U.clone())},u.prototype.sqr=function(U){return this.mul(U,U)},u.prototype.sqrt=function(U){if(U.isZero())return U.clone();var I=this.m.andln(3);if(L(I%2===1),I===3){var Q=this.m.add(new O(1)).iushrn(2);return this.pow(U,Q)}var X=this.m.subn(1),Z=0;while(!X.isZero()&&X.andln(1)===0)Z++,X.iushrn(1);L(!X.isZero());var A=new O(1).toRed(this),$=A.redNeg(),J=this.m.subn(1).iushrn(1),E=this.m.bitLength();E=new O(2*E*E).toRed(this);while(this.pow(E,J).cmp($)!==0)E.redIAdd($);var V=this.pow(E,X),S=this.pow(U,X.addn(1).iushrn(1)),H=this.pow(U,X),j=Z;while(H.cmp(A)!==0){var w=H;for(var p=0;w.cmp(A)!==0;p++)w=w.redSqr();L(p=0;Z--){var V=I.words[Z];for(var S=E-1;S>=0;S--){var H=V>>S&1;if(A!==X[0])A=this.sqr(A);if(H===0&&$===0){J=0;continue}if($<<=1,$|=H,J++,J!==Q&&(Z!==0||S!==0))continue;A=this.mul(A,X[$]),J=0,$=0}E=26}return A},u.prototype.convertTo=function(U){var I=U.umod(this.m);return I===U?I.clone():I},u.prototype.convertFrom=function(U){var I=U.clone();return I.red=null,I},O.mont=function(U){return new i(U)};function i(U){if(u.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new O(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}W(i,u),i.prototype.convertTo=function(U){return this.imod(U.ushln(this.shift))},i.prototype.convertFrom=function(U){var I=this.imod(U.mul(this.rinv));return I.red=null,I},i.prototype.imul=function(U,I){if(U.isZero()||I.isZero())return U.words[0]=0,U.length=1,U;var Q=U.imul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.mul=function(U,I){if(U.isZero()||I.isZero())return new O(0)._forceRed(this);var Q=U.mul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.invm=function(U){var I=this.imod(U._invmp(this.m).mul(this.r2));return I._forceRed(this)}})(typeof Y>"u"||Y,T)}),dU=Q0((T,Y)=>{Y.exports=G;function G(K,L){if(!K)throw Error(L||"Assertion failed")}G.equal=function(K,L,W){if(K!=L)throw Error(W||"Assertion failed: "+K+" != "+L)}}),WT=Q0((T)=>{var Y=T;function G(W,O){if(Array.isArray(W))return W.slice();if(!W)return[];var z=[];if(typeof W!=="string"){for(var q=0;q>8,F=D&255;if(C)z.push(C,F);else z.push(F)}return z}Y.toArray=G;function K(W){if(W.length===1)return"0"+W;else return W}Y.zero2=K;function L(W){var O="";for(var z=0;z{var Y=T,G=cU(),K=dU(),L=WT();Y.assert=K,Y.toArray=L.toArray,Y.zero2=L.zero2,Y.toHex=L.toHex,Y.encode=L.encode;function W(C,F,R){var M=Array(Math.max(C.bitLength(),R)+1),P;for(P=0;P(k>>1)-1)N=(k>>1)-v;else N=v;_.isubn(N)}else N=0;M[P]=N,_.iushrn(1)}return M}Y.getNAF=W;function O(C,F){var R=[[],[]];C=C.clone(),F=F.clone();var M=0,P=0,k;while(C.cmpn(-M)>0||F.cmpn(-P)>0){var _=C.andln(3)+M&3,N=F.andln(3)+P&3;if(_===3)_=-1;if(N===3)N=-1;var v;if((_&1)===0)v=0;else if(k=C.andln(7)+M&7,(k===3||k===5)&&N===2)v=-_;else v=_;R[0].push(v);var B;if((N&1)===0)B=0;else if(k=F.andln(7)+P&7,(k===3||k===5)&&_===2)B=-N;else B=N;if(R[1].push(B),2*M===v+1)M=1-M;if(2*P===B+1)P=1-P;C.iushrn(1),F.iushrn(1)}return R}Y.getJSF=O;function z(C,F,R){var M="_"+F;C.prototype[F]=function(){return this[M]!==void 0?this[M]:this[M]=R.call(this)}}Y.cachedProperty=z;function q(C){return typeof C==="string"?Y.toArray(C,"hex"):C}Y.parseBytes=q;function D(C){return new G(C,"hex","le")}Y.intFromLE=D}),HT=Q0((T,Y)=>{var G;Y.exports=function(W){if(!G)G=new K(null);return G.generate(W)};function K(W){this.rand=W}if(Y.exports.Rand=K,K.prototype.generate=function(W){return this._rand(W)},K.prototype._rand=function(W){if(this.rand.getBytes)return this.rand.getBytes(W);var O=new Uint8Array(W);for(var z=0;z{var G=cU(),K=vU(),L=K.getNAF,W=K.getJSF,O=K.assert;function z(D,C){this.type=D,this.p=new G(C.p,16),this.red=C.prime?G.red(C.prime):G.mont(this.p),this.zero=new G(0).toRed(this.red),this.one=new G(1).toRed(this.red),this.two=new G(2).toRed(this.red),this.n=C.n&&new G(C.n,16),this.g=C.g&&this.pointFromJSON(C.g,C.gRed),this._wnafT1=[,,,,],this._wnafT2=[,,,,],this._wnafT3=[,,,,],this._wnafT4=[,,,,],this._bitLength=this.n?this.n.bitLength():0;var F=this.n&&this.p.div(this.n);if(!F||F.cmpn(100)>0)this.redN=null;else this._maxwellTrick=!0,this.redN=this.n.toRed(this.red)}Y.exports=z,z.prototype.point=function(){throw Error("Not implemented")},z.prototype.validate=function(){throw Error("Not implemented")},z.prototype._fixedNafMul=function(D,C){O(D.precomputed);var F=D._getDoubles(),R=L(C,1,this._bitLength),M=(1<=k;N--)_=(_<<1)+R[N];P.push(_)}var v=this.jpoint(null,null,null),B=this.jpoint(null,null,null);for(var g=M;g>0;g--){for(k=0;k=0;_--){for(var N=0;_>=0&&P[_]===0;_--)N++;if(_>=0)N++;if(k=k.dblp(N),_<0)break;var v=P[_];if(O(v!==0),D.type==="affine")if(v>0)k=k.mixedAdd(M[v-1>>1]);else k=k.mixedAdd(M[-v-1>>1].neg());else if(v>0)k=k.add(M[v-1>>1]);else k=k.add(M[-v-1>>1].neg())}return D.type==="affine"?k.toP():k},z.prototype._wnafMulAdd=function(D,C,F,R,M){var P=this._wnafT1,k=this._wnafT2,_=this._wnafT3,N=0,v,B,g;for(v=0;v=1;v-=2){var l=v-1,Y0=v;if(P[l]!==1||P[Y0]!==1){_[l]=L(F[l],P[l],this._bitLength),_[Y0]=L(F[Y0],P[Y0],this._bitLength),N=Math.max(_[l].length,N),N=Math.max(_[Y0].length,N);continue}var O0=[C[l],null,null,C[Y0]];if(C[l].y.cmp(C[Y0].y)===0)O0[1]=C[l].add(C[Y0]),O0[2]=C[l].toJ().mixedAdd(C[Y0].neg());else if(C[l].y.cmp(C[Y0].y.redNeg())===0)O0[1]=C[l].toJ().mixedAdd(C[Y0]),O0[2]=C[l].add(C[Y0].neg());else O0[1]=C[l].toJ().mixedAdd(C[Y0]),O0[2]=C[l].toJ().mixedAdd(C[Y0].neg());var Z0=[-3,-1,-5,-7,0,7,5,1,3],u=W(F[l],F[Y0]);N=Math.max(u[0].length,N),_[l]=Array(N),_[Y0]=Array(N);for(B=0;B=0;v--){var X=0;while(v>=0){var Z=!0;for(B=0;B=0)X++;if(I=I.dblp(X),v<0)break;for(B=0;B0)g=k[B][A-1>>1];else if(A<0)g=k[B][-A-1>>1].neg();if(g.type==="affine")I=I.mixedAdd(g);else I=I.add(g)}}for(v=0;v=Math.ceil((D.bitLength()+1)/C.step)},q.prototype._getDoubles=function(D,C){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;var F=[this],R=this;for(var M=0;M{if(typeof Object.create==="function")Y.exports=function(G,K){if(K)G.super_=K,G.prototype=Object.create(K.prototype,{constructor:{value:G,enumerable:!1,writable:!0,configurable:!0}})};else Y.exports=function(G,K){if(K){G.super_=K;var L=function(){};L.prototype=K.prototype,G.prototype=new L,G.prototype.constructor=G}}}),_U=Q0((T,Y)=>{try{if(G=(xI(),h0(BI)),typeof G.inherits!=="function")throw"";Y.exports=G.inherits}catch(K){Y.exports=mO()}var G}),sO=Q0((T,Y)=>{var G=vU(),K=cU(),L=_U(),W=uE(),O=G.assert;function z(C){W.call(this,"short",C),this.a=new K(C.a,16).toRed(this.red),this.b=new K(C.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=this.a.fromRed().cmpn(0)===0,this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0,this.endo=this._getEndomorphism(C),this._endoWnafT1=[,,,,],this._endoWnafT2=[,,,,]}L(z,W),Y.exports=z,z.prototype._getEndomorphism=function(C){if(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)return;var F,R;if(C.beta)F=new K(C.beta,16).toRed(this.red);else{var M=this._getEndoRoots(this.p);F=M[0].cmp(M[1])<0?M[0]:M[1],F=F.toRed(this.red)}if(C.lambda)R=new K(C.lambda,16);else{var P=this._getEndoRoots(this.n);if(this.g.mul(P[0]).x.cmp(this.g.x.redMul(F))===0)R=P[0];else R=P[1],O(this.g.mul(R).x.cmp(this.g.x.redMul(F))===0)}var k;if(C.basis)k=C.basis.map(function(_){return{a:new K(_.a,16),b:new K(_.b,16)}});else k=this._getEndoBasis(R);return{beta:F,lambda:R,basis:k}},z.prototype._getEndoRoots=function(C){var F=C===this.p?this.red:K.mont(C),R=new K(2).toRed(F).redInvm(),M=R.redNeg(),P=new K(3).toRed(F).redNeg().redSqrt().redMul(R),k=M.redAdd(P).fromRed(),_=M.redSub(P).fromRed();return[k,_]},z.prototype._getEndoBasis=function(C){var F=this.n.ushrn(Math.floor(this.n.bitLength()/2)),R=C,M=this.n.clone(),P=new K(1),k=new K(0),_=new K(0),N=new K(1),v,B,g,y,l,Y0,O0,Z0=0,u,i;while(R.cmpn(0)!==0){var U=M.div(R);u=M.sub(U.mul(R)),i=_.sub(U.mul(P));var I=N.sub(U.mul(k));if(!g&&u.cmp(F)<0)v=O0.neg(),B=P,g=u.neg(),y=i;else if(g&&++Z0===2)break;O0=u,M=R,R=u,_=P,P=i,N=k,k=I}l=u.neg(),Y0=i;var Q=g.sqr().add(y.sqr()),X=l.sqr().add(Y0.sqr());if(X.cmp(Q)>=0)l=v,Y0=B;if(g.negative)g=g.neg(),y=y.neg();if(l.negative)l=l.neg(),Y0=Y0.neg();return[{a:g,b:y},{a:l,b:Y0}]},z.prototype._endoSplit=function(C){var F=this.endo.basis,R=F[0],M=F[1],P=M.b.mul(C).divRound(this.n),k=R.b.neg().mul(C).divRound(this.n),_=P.mul(R.a),N=k.mul(M.a),v=P.mul(R.b),B=k.mul(M.b),g=C.sub(_).sub(N),y=v.add(B).neg();return{k1:g,k2:y}},z.prototype.pointFromX=function(C,F){if(C=new K(C,16),!C.red)C=C.toRed(this.red);var R=C.redSqr().redMul(C).redIAdd(C.redMul(this.a)).redIAdd(this.b),M=R.redSqrt();if(M.redSqr().redSub(R).cmp(this.zero)!==0)throw Error("invalid point");var P=M.fromRed().isOdd();if(F&&!P||!F&&P)M=M.redNeg();return this.point(C,M)},z.prototype.validate=function(C){if(C.inf)return!0;var{x:F,y:R}=C,M=this.a.redMul(F),P=F.redSqr().redMul(F).redIAdd(M).redIAdd(this.b);return R.redSqr().redISub(P).cmpn(0)===0},z.prototype._endoWnafMulAdd=function(C,F,R){var M=this._endoWnafT1,P=this._endoWnafT2;for(var k=0;k";return""},q.prototype.isInfinity=function(){return this.inf},q.prototype.add=function(C){if(this.inf)return C;if(C.inf)return this;if(this.eq(C))return this.dbl();if(this.neg().eq(C))return this.curve.point(null,null);if(this.x.cmp(C.x)===0)return this.curve.point(null,null);var F=this.y.redSub(C.y);if(F.cmpn(0)!==0)F=F.redMul(this.x.redSub(C.x).redInvm());var R=F.redSqr().redISub(this.x).redISub(C.x),M=F.redMul(this.x.redSub(R)).redISub(this.y);return this.curve.point(R,M)},q.prototype.dbl=function(){if(this.inf)return this;var C=this.y.redAdd(this.y);if(C.cmpn(0)===0)return this.curve.point(null,null);var F=this.curve.a,R=this.x.redSqr(),M=C.redInvm(),P=R.redAdd(R).redIAdd(R).redIAdd(F).redMul(M),k=P.redSqr().redISub(this.x.redAdd(this.x)),_=P.redMul(this.x.redSub(k)).redISub(this.y);return this.curve.point(k,_)},q.prototype.getX=function(){return this.x.fromRed()},q.prototype.getY=function(){return this.y.fromRed()},q.prototype.mul=function(C){if(C=new K(C,16),this.isInfinity())return this;else if(this._hasDoubles(C))return this.curve._fixedNafMul(this,C);else if(this.curve.endo)return this.curve._endoWnafMulAdd([this],[C]);else return this.curve._wnafMul(this,C)},q.prototype.mulAdd=function(C,F,R){var M=[this,F],P=[C,R];if(this.curve.endo)return this.curve._endoWnafMulAdd(M,P);else return this.curve._wnafMulAdd(1,M,P,2)},q.prototype.jmulAdd=function(C,F,R){var M=[this,F],P=[C,R];if(this.curve.endo)return this.curve._endoWnafMulAdd(M,P,!0);else return this.curve._wnafMulAdd(1,M,P,2,!0)},q.prototype.eq=function(C){return this===C||this.inf===C.inf&&(this.inf||this.x.cmp(C.x)===0&&this.y.cmp(C.y)===0)},q.prototype.neg=function(C){if(this.inf)return this;var F=this.curve.point(this.x,this.y.redNeg());if(C&&this.precomputed){var R=this.precomputed,M=function(P){return P.neg()};F.precomputed={naf:R.naf&&{wnd:R.naf.wnd,points:R.naf.points.map(M)},doubles:R.doubles&&{step:R.doubles.step,points:R.doubles.points.map(M)}}}return F},q.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);var C=this.curve.jpoint(this.x,this.y,this.curve.one);return C};function D(C,F,R,M){if(W.BasePoint.call(this,C,"jacobian"),F===null&&R===null&&M===null)this.x=this.curve.one,this.y=this.curve.one,this.z=new K(0);else this.x=new K(F,16),this.y=new K(R,16),this.z=new K(M,16);if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);this.zOne=this.z===this.curve.one}L(D,W.BasePoint),z.prototype.jpoint=function(C,F,R){return new D(this,C,F,R)},D.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var C=this.z.redInvm(),F=C.redSqr(),R=this.x.redMul(F),M=this.y.redMul(F).redMul(C);return this.curve.point(R,M)},D.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},D.prototype.add=function(C){if(this.isInfinity())return C;if(C.isInfinity())return this;var F=C.z.redSqr(),R=this.z.redSqr(),M=this.x.redMul(F),P=C.x.redMul(R),k=this.y.redMul(F.redMul(C.z)),_=C.y.redMul(R.redMul(this.z)),N=M.redSub(P),v=k.redSub(_);if(N.cmpn(0)===0)if(v.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl();var B=N.redSqr(),g=B.redMul(N),y=M.redMul(B),l=v.redSqr().redIAdd(g).redISub(y).redISub(y),Y0=v.redMul(y.redISub(l)).redISub(k.redMul(g)),O0=this.z.redMul(C.z).redMul(N);return this.curve.jpoint(l,Y0,O0)},D.prototype.mixedAdd=function(C){if(this.isInfinity())return C.toJ();if(C.isInfinity())return this;var F=this.z.redSqr(),R=this.x,M=C.x.redMul(F),P=this.y,k=C.y.redMul(F).redMul(this.z),_=R.redSub(M),N=P.redSub(k);if(_.cmpn(0)===0)if(N.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl();var v=_.redSqr(),B=v.redMul(_),g=R.redMul(v),y=N.redSqr().redIAdd(B).redISub(g).redISub(g),l=N.redMul(g.redISub(y)).redISub(P.redMul(B)),Y0=this.z.redMul(_);return this.curve.jpoint(y,l,Y0)},D.prototype.dblp=function(C){if(C===0)return this;if(this.isInfinity())return this;if(!C)return this.dbl();var F;if(this.curve.zeroA||this.curve.threeA){var R=this;for(F=0;F=0)return!1;if(R.redIAdd(P),this.x.cmp(R)===0)return!0}},D.prototype.inspect=function(){if(this.isInfinity())return"";return""},D.prototype.isInfinity=function(){return this.z.cmpn(0)===0}}),rO=Q0((T,Y)=>{var G=cU(),K=_U(),L=uE(),W=vU();function O(q){L.call(this,"mont",q),this.a=new G(q.a,16).toRed(this.red),this.b=new G(q.b,16).toRed(this.red),this.i4=new G(4).toRed(this.red).redInvm(),this.two=new G(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}K(O,L),Y.exports=O,O.prototype.validate=function(q){var D=q.normalize().x,C=D.redSqr(),F=C.redMul(D).redAdd(C.redMul(this.a)).redAdd(D),R=F.redSqrt();return R.redSqr().cmp(F)===0};function z(q,D,C){if(L.BasePoint.call(this,q,"projective"),D===null&&C===null)this.x=this.curve.one,this.z=this.curve.zero;else{if(this.x=new G(D,16),this.z=new G(C,16),!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red)}}K(z,L.BasePoint),O.prototype.decodePoint=function(q,D){return this.point(W.toArray(q,D),1)},O.prototype.point=function(q,D){return new z(this,q,D)},O.prototype.pointFromJSON=function(q){return z.fromJSON(this,q)},z.prototype.precompute=function(){},z.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},z.fromJSON=function(q,D){return new z(q,D[0],D[1]||q.one)},z.prototype.inspect=function(){if(this.isInfinity())return"";return""},z.prototype.isInfinity=function(){return this.z.cmpn(0)===0},z.prototype.dbl=function(){var q=this.x.redAdd(this.z),D=q.redSqr(),C=this.x.redSub(this.z),F=C.redSqr(),R=D.redSub(F),M=D.redMul(F),P=R.redMul(F.redAdd(this.curve.a24.redMul(R)));return this.curve.point(M,P)},z.prototype.add=function(){throw Error("Not supported on Montgomery curve")},z.prototype.diffAdd=function(q,D){var C=this.x.redAdd(this.z),F=this.x.redSub(this.z),R=q.x.redAdd(q.z),M=q.x.redSub(q.z),P=M.redMul(C),k=R.redMul(F),_=D.z.redMul(P.redAdd(k).redSqr()),N=D.x.redMul(P.redISub(k).redSqr());return this.curve.point(_,N)},z.prototype.mul=function(q){var D=q.clone(),C=this,F=this.curve.point(null,null),R=this;for(var M=[];D.cmpn(0)!==0;D.iushrn(1))M.push(D.andln(1));for(var P=M.length-1;P>=0;P--)if(M[P]===0)C=C.diffAdd(F,R),F=F.dbl();else F=C.diffAdd(F,R),C=C.dbl();return F},z.prototype.mulAdd=function(){throw Error("Not supported on Montgomery curve")},z.prototype.jumlAdd=function(){throw Error("Not supported on Montgomery curve")},z.prototype.eq=function(q){return this.getX().cmp(q.getX())===0},z.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},z.prototype.getX=function(){return this.normalize(),this.x.fromRed()}}),tO=Q0((T,Y)=>{var G=vU(),K=cU(),L=_U(),W=uE(),O=G.assert;function z(D){this.twisted=(D.a|0)!==1,this.mOneA=this.twisted&&(D.a|0)===-1,this.extended=this.mOneA,W.call(this,"edwards",D),this.a=new K(D.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new K(D.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new K(D.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),O(!this.twisted||this.c.fromRed().cmpn(1)===0),this.oneC=(D.c|0)===1}L(z,W),Y.exports=z,z.prototype._mulA=function(D){if(this.mOneA)return D.redNeg();else return this.a.redMul(D)},z.prototype._mulC=function(D){if(this.oneC)return D;else return this.c.redMul(D)},z.prototype.jpoint=function(D,C,F,R){return this.point(D,C,F,R)},z.prototype.pointFromX=function(D,C){if(D=new K(D,16),!D.red)D=D.toRed(this.red);var F=D.redSqr(),R=this.c2.redSub(this.a.redMul(F)),M=this.one.redSub(this.c2.redMul(this.d).redMul(F)),P=R.redMul(M.redInvm()),k=P.redSqrt();if(k.redSqr().redSub(P).cmp(this.zero)!==0)throw Error("invalid point");var _=k.fromRed().isOdd();if(C&&!_||!C&&_)k=k.redNeg();return this.point(D,k)},z.prototype.pointFromY=function(D,C){if(D=new K(D,16),!D.red)D=D.toRed(this.red);var F=D.redSqr(),R=F.redSub(this.c2),M=F.redMul(this.d).redMul(this.c2).redSub(this.a),P=R.redMul(M.redInvm());if(P.cmp(this.zero)===0)if(C)throw Error("invalid point");else return this.point(this.zero,D);var k=P.redSqrt();if(k.redSqr().redSub(P).cmp(this.zero)!==0)throw Error("invalid point");if(k.fromRed().isOdd()!==C)k=k.redNeg();return this.point(k,D)},z.prototype.validate=function(D){if(D.isInfinity())return!0;D.normalize();var C=D.x.redSqr(),F=D.y.redSqr(),R=C.redMul(this.a).redAdd(F),M=this.c2.redMul(this.one.redAdd(this.d.redMul(C).redMul(F)));return R.cmp(M)===0};function q(D,C,F,R,M){if(W.BasePoint.call(this,D,"projective"),C===null&&F===null&&R===null)this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0;else{if(this.x=new K(C,16),this.y=new K(F,16),this.z=R?new K(R,16):this.curve.one,this.t=M&&new K(M,16),!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);if(this.t&&!this.t.red)this.t=this.t.toRed(this.curve.red);if(this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t){if(this.t=this.x.redMul(this.y),!this.zOne)this.t=this.t.redMul(this.z.redInvm())}}}L(q,W.BasePoint),z.prototype.pointFromJSON=function(D){return q.fromJSON(this,D)},z.prototype.point=function(D,C,F,R){return new q(this,D,C,F,R)},q.fromJSON=function(D,C){return new q(D,C[0],C[1],C[2])},q.prototype.inspect=function(){if(this.isInfinity())return"";return""},q.prototype.isInfinity=function(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)},q.prototype._extDbl=function(){var D=this.x.redSqr(),C=this.y.redSqr(),F=this.z.redSqr();F=F.redIAdd(F);var R=this.curve._mulA(D),M=this.x.redAdd(this.y).redSqr().redISub(D).redISub(C),P=R.redAdd(C),k=P.redSub(F),_=R.redSub(C),N=M.redMul(k),v=P.redMul(_),B=M.redMul(_),g=k.redMul(P);return this.curve.point(N,v,g,B)},q.prototype._projDbl=function(){var D=this.x.redAdd(this.y).redSqr(),C=this.x.redSqr(),F=this.y.redSqr(),R,M,P,k,_,N;if(this.curve.twisted){k=this.curve._mulA(C);var v=k.redAdd(F);if(this.zOne)R=D.redSub(C).redSub(F).redMul(v.redSub(this.curve.two)),M=v.redMul(k.redSub(F)),P=v.redSqr().redSub(v).redSub(v);else _=this.z.redSqr(),N=v.redSub(_).redISub(_),R=D.redSub(C).redISub(F).redMul(N),M=v.redMul(k.redSub(F)),P=v.redMul(N)}else k=C.redAdd(F),_=this.curve._mulC(this.z).redSqr(),N=k.redSub(_).redSub(_),R=this.curve._mulC(D.redISub(k)).redMul(N),M=this.curve._mulC(k).redMul(C.redISub(F)),P=k.redMul(N);return this.curve.point(R,M,P)},q.prototype.dbl=function(){if(this.isInfinity())return this;if(this.curve.extended)return this._extDbl();else return this._projDbl()},q.prototype._extAdd=function(D){var C=this.y.redSub(this.x).redMul(D.y.redSub(D.x)),F=this.y.redAdd(this.x).redMul(D.y.redAdd(D.x)),R=this.t.redMul(this.curve.dd).redMul(D.t),M=this.z.redMul(D.z.redAdd(D.z)),P=F.redSub(C),k=M.redSub(R),_=M.redAdd(R),N=F.redAdd(C),v=P.redMul(k),B=_.redMul(N),g=P.redMul(N),y=k.redMul(_);return this.curve.point(v,B,y,g)},q.prototype._projAdd=function(D){var C=this.z.redMul(D.z),F=C.redSqr(),R=this.x.redMul(D.x),M=this.y.redMul(D.y),P=this.curve.d.redMul(R).redMul(M),k=F.redSub(P),_=F.redAdd(P),N=this.x.redAdd(this.y).redMul(D.x.redAdd(D.y)).redISub(R).redISub(M),v=C.redMul(k).redMul(N),B,g;if(this.curve.twisted)B=C.redMul(_).redMul(M.redSub(this.curve._mulA(R))),g=k.redMul(_);else B=C.redMul(_).redMul(M.redSub(R)),g=this.curve._mulC(k).redMul(_);return this.curve.point(v,B,g)},q.prototype.add=function(D){if(this.isInfinity())return D;if(D.isInfinity())return this;if(this.curve.extended)return this._extAdd(D);else return this._projAdd(D)},q.prototype.mul=function(D){if(this._hasDoubles(D))return this.curve._fixedNafMul(this,D);else return this.curve._wnafMul(this,D)},q.prototype.mulAdd=function(D,C,F){return this.curve._wnafMulAdd(1,[this,C],[D,F],2,!1)},q.prototype.jmulAdd=function(D,C,F){return this.curve._wnafMulAdd(1,[this,C],[D,F],2,!0)},q.prototype.normalize=function(){if(this.zOne)return this;var D=this.z.redInvm();if(this.x=this.x.redMul(D),this.y=this.y.redMul(D),this.t)this.t=this.t.redMul(D);return this.z=this.curve.one,this.zOne=!0,this},q.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},q.prototype.getX=function(){return this.normalize(),this.x.fromRed()},q.prototype.getY=function(){return this.normalize(),this.y.fromRed()},q.prototype.eq=function(D){return this===D||this.getX().cmp(D.getX())===0&&this.getY().cmp(D.getY())===0},q.prototype.eqXToP=function(D){var C=D.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(C)===0)return!0;var F=D.clone(),R=this.curve.redN.redMul(this.z);for(;;){if(F.iadd(this.curve.n),F.cmp(this.curve.p)>=0)return!1;if(C.redIAdd(R),this.x.cmp(C)===0)return!0}},q.prototype.toP=q.prototype.normalize,q.prototype.mixedAdd=q.prototype.add}),RT=Q0((T)=>{var Y=T;Y.base=uE(),Y.short=sO(),Y.mont=rO(),Y.edwards=tO()}),xU=Q0((T)=>{var Y=dU(),G=_U();T.inherits=G;function K(I,Q){if((I.charCodeAt(Q)&64512)!==55296)return!1;if(Q<0||Q+1>=I.length)return!1;return(I.charCodeAt(Q+1)&64512)===56320}function L(I,Q){if(Array.isArray(I))return I.slice();if(!I)return[];var X=[];if(typeof I==="string"){if(!Q){var Z=0;for(var A=0;A>6|192,X[Z++]=$&63|128;else if(K(I,A))$=65536+(($&1023)<<10)+(I.charCodeAt(++A)&1023),X[Z++]=$>>18|240,X[Z++]=$>>12&63|128,X[Z++]=$>>6&63|128,X[Z++]=$&63|128;else X[Z++]=$>>12|224,X[Z++]=$>>6&63|128,X[Z++]=$&63|128}}else if(Q==="hex"){if(I=I.replace(/[^a-z0-9]+/ig,""),I.length%2!==0)I="0"+I;for(A=0;A>>24|I>>>8&65280|I<<8&16711680|(I&255)<<24;return Q>>>0}T.htonl=O;function z(I,Q){var X="";for(var Z=0;Z>>0}return $}T.join32=C;function F(I,Q){var X=Array(I.length*4);for(var Z=0,A=0;Z>>24,X[A+1]=$>>>16&255,X[A+2]=$>>>8&255,X[A+3]=$&255;else X[A+3]=$>>>24,X[A+2]=$>>>16&255,X[A+1]=$>>>8&255,X[A]=$&255}return X}T.split32=F;function R(I,Q){return I>>>Q|I<<32-Q}T.rotr32=R;function M(I,Q){return I<>>32-Q}T.rotl32=M;function P(I,Q){return I+Q>>>0}T.sum32=P;function k(I,Q,X){return I+Q+X>>>0}T.sum32_3=k;function _(I,Q,X,Z){return I+Q+X+Z>>>0}T.sum32_4=_;function N(I,Q,X,Z,A){return I+Q+X+Z+A>>>0}T.sum32_5=N;function v(I,Q,X,Z){var A=I[Q],$=I[Q+1],J=Z+$>>>0,E=(J>>0,I[Q+1]=J}T.sum64=v;function B(I,Q,X,Z){var A=Q+Z>>>0,$=(A>>0}T.sum64_hi=B;function g(I,Q,X,Z){var A=Q+Z;return A>>>0}T.sum64_lo=g;function y(I,Q,X,Z,A,$,J,E){var V=0,S=Q;S=S+Z>>>0,V+=S>>0,V+=S<$?1:0,S=S+E>>>0,V+=S>>0}T.sum64_4_hi=y;function l(I,Q,X,Z,A,$,J,E){var V=Q+Z+$+E;return V>>>0}T.sum64_4_lo=l;function Y0(I,Q,X,Z,A,$,J,E,V,S){var H=0,j=Q;j=j+Z>>>0,H+=j>>0,H+=j<$?1:0,j=j+E>>>0,H+=j>>0,H+=j>>0}T.sum64_5_hi=Y0;function O0(I,Q,X,Z,A,$,J,E,V,S){var H=Q+Z+$+E+S;return H>>>0}T.sum64_5_lo=O0;function Z0(I,Q,X){var Z=Q<<32-X|I>>>X;return Z>>>0}T.rotr64_hi=Z0;function u(I,Q,X){var Z=I<<32-X|Q>>>X;return Z>>>0}T.rotr64_lo=u;function i(I,Q,X){return I>>>X}T.shr64_hi=i;function U(I,Q,X){var Z=I<<32-X|Q>>>X;return Z>>>0}T.shr64_lo=U}),HE=Q0((T)=>{var Y=xU(),G=dU();function K(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}T.BlockHash=K,K.prototype.update=function(L,W){if(L=Y.toArray(L,W),!this.pending)this.pending=L;else this.pending=this.pending.concat(L);if(this.pendingTotal+=L.length,this.pending.length>=this._delta8){L=this.pending;var O=L.length%this._delta8;if(this.pending=L.slice(L.length-O,L.length),this.pending.length===0)this.pending=null;L=Y.join32(L,0,L.length-O,this.endian);for(var z=0;z>>24&255,z[q++]=L>>>16&255,z[q++]=L>>>8&255,z[q++]=L&255}else{z[q++]=L&255,z[q++]=L>>>8&255,z[q++]=L>>>16&255,z[q++]=L>>>24&255,z[q++]=0,z[q++]=0,z[q++]=0,z[q++]=0;for(D=8;D{var Y=xU(),G=Y.rotr32;function K(F,R,M,P){if(F===0)return L(R,M,P);if(F===1||F===3)return O(R,M,P);if(F===2)return W(R,M,P)}T.ft_1=K;function L(F,R,M){return F&R^~F&M}T.ch32=L;function W(F,R,M){return F&R^F&M^R&M}T.maj32=W;function O(F,R,M){return F^R^M}T.p32=O;function z(F){return G(F,2)^G(F,13)^G(F,22)}T.s0_256=z;function q(F){return G(F,6)^G(F,11)^G(F,25)}T.s1_256=q;function D(F){return G(F,7)^G(F,18)^F>>>3}T.g0_256=D;function C(F){return G(F,17)^G(F,19)^F>>>10}T.g1_256=C}),aO=Q0((T,Y)=>{var G=xU(),K=HE(),L=CT(),W=G.rotl32,O=G.sum32,z=G.sum32_5,q=L.ft_1,D=K.BlockHash,C=[1518500249,1859775393,2400959708,3395469782];function F(){if(!(this instanceof F))return new F;D.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=Array(80)}G.inherits(F,D),Y.exports=F,F.blockSize=512,F.outSize=160,F.hmacStrength=80,F.padLength=64,F.prototype._update=function(R,M){var P=this.W;for(var k=0;k<16;k++)P[k]=R[M+k];for(;k{var G=xU(),K=HE(),L=CT(),W=dU(),O=G.sum32,z=G.sum32_4,q=G.sum32_5,D=L.ch32,C=L.maj32,F=L.s0_256,R=L.s1_256,M=L.g0_256,P=L.g1_256,k=K.BlockHash,_=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function N(){if(!(this instanceof N))return new N;k.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=_,this.W=Array(64)}G.inherits(N,k),Y.exports=N,N.blockSize=512,N.outSize=256,N.hmacStrength=192,N.padLength=64,N.prototype._update=function(v,B){var g=this.W;for(var y=0;y<16;y++)g[y]=v[B+y];for(;y{var G=xU(),K=DT();function L(){if(!(this instanceof L))return new L;K.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}G.inherits(L,K),Y.exports=L,L.blockSize=512,L.outSize=224,L.hmacStrength=192,L.padLength=64,L.prototype._digest=function(W){if(W==="hex")return G.toHex32(this.h.slice(0,7),"big");else return G.split32(this.h.slice(0,7),"big")}}),zT=Q0((T,Y)=>{var G=xU(),K=HE(),L=dU(),W=G.rotr64_hi,O=G.rotr64_lo,z=G.shr64_hi,q=G.shr64_lo,D=G.sum64,C=G.sum64_hi,F=G.sum64_lo,R=G.sum64_4_hi,M=G.sum64_4_lo,P=G.sum64_5_hi,k=G.sum64_5_lo,_=K.BlockHash,N=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function v(){if(!(this instanceof v))return new v;_.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=N,this.W=Array(160)}G.inherits(v,_),Y.exports=v,v.blockSize=1024,v.outSize=512,v.hmacStrength=192,v.padLength=128,v.prototype._prepareBlock=function(X,Z){var A=this.W;for(var $=0;$<32;$++)A[$]=X[Z+$];for(;${var G=xU(),K=zT();function L(){if(!(this instanceof L))return new L;K.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}G.inherits(L,K),Y.exports=L,L.blockSize=1024,L.outSize=384,L.hmacStrength=192,L.padLength=128,L.prototype._digest=function(W){if(W==="hex")return G.toHex32(this.h.slice(0,12),"big");else return G.split32(this.h.slice(0,12),"big")}}),UQ=Q0((T)=>{T.sha1=aO(),T.sha224=eO(),T.sha256=DT(),T.sha384=iO(),T.sha512=zT()}),EQ=Q0((T)=>{var Y=xU(),G=HE(),K=Y.rotl32,L=Y.sum32,W=Y.sum32_3,O=Y.sum32_4,z=G.BlockHash;function q(){if(!(this instanceof q))return new q;z.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}Y.inherits(q,z),T.ripemd160=q,q.blockSize=512,q.outSize=160,q.hmacStrength=192,q.padLength=64,q.prototype._update=function(_,N){var v=this.h[0],B=this.h[1],g=this.h[2],y=this.h[3],l=this.h[4],Y0=v,O0=B,Z0=g,u=y,i=l;for(var U=0;U<80;U++){var I=L(K(O(v,D(U,B,g,y),_[R[U]+N],C(U)),P[U]),l);v=l,l=y,y=K(g,10),g=B,B=I,I=L(K(O(Y0,D(79-U,O0,Z0,u),_[M[U]+N],F(U)),k[U]),i),Y0=i,i=u,u=K(Z0,10),Z0=O0,O0=I}I=W(this.h[1],g,u),this.h[1]=W(this.h[2],y,i),this.h[2]=W(this.h[3],l,Y0),this.h[3]=W(this.h[4],v,O0),this.h[4]=W(this.h[0],B,Z0),this.h[0]=I},q.prototype._digest=function(_){if(_==="hex")return Y.toHex32(this.h,"little");else return Y.split32(this.h,"little")};function D(_,N,v,B){if(_<=15)return N^v^B;else if(_<=31)return N&v|~N&B;else if(_<=47)return(N|~v)^B;else if(_<=63)return N&B|v&~B;else return N^(v|~B)}function C(_){if(_<=15)return 0;else if(_<=31)return 1518500249;else if(_<=47)return 1859775393;else if(_<=63)return 2400959708;else return 2840853838}function F(_){if(_<=15)return 1352829926;else if(_<=31)return 1548603684;else if(_<=47)return 1836072691;else if(_<=63)return 2053994217;else return 0}var R=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],M=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],P=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],k=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]}),XQ=Q0((T,Y)=>{var G=xU(),K=dU();function L(W,O,z){if(!(this instanceof L))return new L(W,O,z);this.Hash=W,this.blockSize=W.blockSize/8,this.outSize=W.outSize/8,this.inner=null,this.outer=null,this._init(G.toArray(O,z))}Y.exports=L,L.prototype._init=function(W){if(W.length>this.blockSize)W=new this.Hash().update(W).digest();K(W.length<=this.blockSize);for(var O=W.length;O{var Y=T;Y.utils=xU(),Y.common=HE(),Y.sha=UQ(),Y.ripemd=EQ(),Y.hmac=XQ(),Y.sha1=Y.sha.sha1,Y.sha256=Y.sha.sha256,Y.sha224=Y.sha.sha224,Y.sha384=Y.sha.sha384,Y.sha512=Y.sha.sha512,Y.ripemd160=Y.ripemd.ripemd160}),IQ=Q0((T,Y)=>{Y.exports={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d","e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"],["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1","9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"],["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0","5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"],["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047","10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"],["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862","283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"],["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7","7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"],["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd","56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"],["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83","7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"],["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a","53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"],["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8","bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"],["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d","4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"],["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725","7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"],["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754","4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"],["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c","17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"],["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6","6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"],["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39","c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"],["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891","893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"],["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b","febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"],["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03","2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"],["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d","eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"],["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070","7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"],["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4","e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"],["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da","662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"],["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11","1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"],["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e","efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"],["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41","2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"],["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef","67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"],["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8","db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"],["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d","648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"],["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96","35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"],["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd","ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"],["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5","9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"],["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266","40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"],["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71","34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"],["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac","c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"],["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751","1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"],["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e","493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"],["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241","c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"],["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3","be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"],["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f","4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"],["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19","aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"],["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be","b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"],["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9","6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"],["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2","8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"],["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13","7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"],["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c","ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"],["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba","2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"],["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151","e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"],["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073","d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"],["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458","38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"],["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b","69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"],["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366","d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"],["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa","40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"],["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0","620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"],["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787","7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"],["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e","ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]]},naf:{wnd:7,points:[["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9","388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"],["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4","d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"],["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc","6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"],["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe","cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"],["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb","d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"],["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8","ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"],["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e","581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"],["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34","4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"],["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c","85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"],["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5","321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"],["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"],["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714","73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"],["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729","a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"],["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db","2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"],["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4","e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"],["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5","b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"],["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479","2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"],["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d","80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"],["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f","1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"],["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb","d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"],["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9","eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"],["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963","758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"],["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74","958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"],["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530","e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"],["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b","5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"],["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247","cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"],["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1","cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"],["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120","4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"],["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435","91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"],["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18","673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"],["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8","59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"],["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb","3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"],["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f","55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"],["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143","efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"],["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba","e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"],["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45","f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"],["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a","744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"],["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e","c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"],["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8","e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"],["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c","30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"],["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519","e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"],["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab","100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"],["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca","ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"],["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf","8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"],["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610","68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"],["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4","f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"],["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c","d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"],["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940","edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"],["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980","a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"],["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3","66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"],["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf","9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"],["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63","4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"],["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448","fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"],["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf","5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"],["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5","8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"],["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6","8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"],["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5","5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"],["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99","f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"],["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51","f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"],["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5","42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"],["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5","204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"],["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997","4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"],["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881","73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"],["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5","39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"],["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66","d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"],["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726","ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"],["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede","6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"],["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94","60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"],["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31","3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"],["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51","b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"],["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252","ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"],["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5","cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"],["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b","6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"],["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4","322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"],["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f","6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"],["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889","2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"],["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246","b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"],["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984","998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"],["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a","b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"],["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030","bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"],["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197","6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"],["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593","c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"],["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef","21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"],["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38","60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"],["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a","49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"],["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111","5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"],["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502","7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"],["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea","be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"],["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26","8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"],["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986","39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"],["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e","62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"],["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4","25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"],["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda","ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"],["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859","cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"],["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f","f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"],["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c","6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"],["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942","fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"],["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a","1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"],["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80","5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"],["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d","438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"],["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1","cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"],["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63","c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"],["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352","6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"],["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193","ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"],["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00","9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"],["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58","ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"],["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7","d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"],["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8","c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"],["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e","67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"],["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d","cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"],["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b","299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"],["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f","f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"],["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6","462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"],["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297","62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"],["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a","7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"],["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c","ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"],["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52","4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"],["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb","bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"],["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065","bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"],["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917","603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"],["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9","cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"],["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3","553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"],["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57","712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"],["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66","ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"],["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8","9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"],["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721","9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"],["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180","4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]]}}}),xX=Q0((T)=>{var Y=T,G=BX(),K=RT(),L=vU(),W=L.assert;function O(D){if(D.type==="short")this.curve=new K.short(D);else if(D.type==="edwards")this.curve=new K.edwards(D);else this.curve=new K.mont(D);this.g=this.curve.g,this.n=this.curve.n,this.hash=D.hash,W(this.g.validate(),"Invalid curve"),W(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}Y.PresetCurve=O;function z(D,C){Object.defineProperty(Y,D,{configurable:!0,enumerable:!0,get:function(){var F=new O(C);return Object.defineProperty(Y,D,{configurable:!0,enumerable:!0,value:F}),F}})}z("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:G.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),z("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:G.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),z("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:G.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),z("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:G.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),z("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:G.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),z("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:G.sha256,gRed:!1,g:["9"]}),z("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:G.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var q;try{q=IQ()}catch(D){q=void 0}z("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:G.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",q]})}),TQ=Q0((T,Y)=>{var G=BX(),K=WT(),L=dU();function W(O){if(!(this instanceof W))return new W(O);this.hash=O.hash,this.predResist=!!O.predResist,this.outLen=this.hash.outSize,this.minEntropy=O.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var z=K.toArray(O.entropy,O.entropyEnc||"hex"),q=K.toArray(O.nonce,O.nonceEnc||"hex"),D=K.toArray(O.pers,O.persEnc||"hex");L(z.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(z,q,D)}Y.exports=W,W.prototype._init=function(O,z,q){var D=O.concat(z).concat(q);this.K=Array(this.outLen/8),this.V=Array(this.outLen/8);for(var C=0;C=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(O.concat(q||[])),this._reseed=1},W.prototype.generate=function(O,z,q,D){if(this._reseed>this.reseedInterval)throw Error("Reseed is required");if(typeof z!=="string")D=q,q=z,z=null;if(q)q=K.toArray(q,D||"hex"),this._update(q);var C=[];while(C.length{var G=cU(),K=vU(),L=K.assert;function W(O,z){if(this.ec=O,this.priv=null,this.pub=null,z.priv)this._importPrivate(z.priv,z.privEnc);if(z.pub)this._importPublic(z.pub,z.pubEnc)}Y.exports=W,W.fromPublic=function(O,z,q){if(z instanceof W)return z;return new W(O,{pub:z,pubEnc:q})},W.fromPrivate=function(O,z,q){if(z instanceof W)return z;return new W(O,{priv:z,privEnc:q})},W.prototype.validate=function(){var O=this.getPublic();if(O.isInfinity())return{result:!1,reason:"Invalid public key"};if(!O.validate())return{result:!1,reason:"Public key is not a point"};if(!O.mul(this.ec.curve.n).isInfinity())return{result:!1,reason:"Public key * N != O"};return{result:!0,reason:null}},W.prototype.getPublic=function(O,z){if(typeof O==="string")z=O,O=null;if(!this.pub)this.pub=this.ec.g.mul(this.priv);if(!z)return this.pub;return this.pub.encode(z,O)},W.prototype.getPrivate=function(O){if(O==="hex")return this.priv.toString(16,2);else return this.priv},W.prototype._importPrivate=function(O,z){this.priv=new G(O,z||16),this.priv=this.priv.umod(this.ec.curve.n)},W.prototype._importPublic=function(O,z){if(O.x||O.y){if(this.ec.curve.type==="mont")L(O.x,"Need x coordinate");else if(this.ec.curve.type==="short"||this.ec.curve.type==="edwards")L(O.x&&O.y,"Need both x and y coordinate");this.pub=this.ec.curve.point(O.x,O.y);return}this.pub=this.ec.curve.decodePoint(O,z)},W.prototype.derive=function(O){if(!O.validate())L(O.validate(),"public point not validated");return O.mul(this.priv).getX()},W.prototype.sign=function(O,z,q){return this.ec.sign(O,this,z,q)},W.prototype.verify=function(O,z,q){return this.ec.verify(O,z,this,void 0,q)},W.prototype.inspect=function(){return""}}),ZQ=Q0((T,Y)=>{var G=cU(),K=vU(),L=K.assert;function W(C,F){if(C instanceof W)return C;if(this._importDER(C,F))return;if(L(C.r&&C.s,"Signature without r or s"),this.r=new G(C.r,16),this.s=new G(C.s,16),C.recoveryParam===void 0)this.recoveryParam=null;else this.recoveryParam=C.recoveryParam}Y.exports=W;function O(){this.place=0}function z(C,F){var R=C[F.place++];if(!(R&128))return R;var M=R&15;if(M===0||M>4)return!1;if(C[F.place]===0)return!1;var P=0;for(var k=0,_=F.place;k>>=0;if(P<=127)return!1;return F.place=_,P}function q(C){var F=0,R=C.length-1;while(!C[F]&&!(C[F+1]&128)&&F>>3);C.push(R|128);while(--R)C.push(F>>>(R<<3)&255);C.push(F)}W.prototype.toDER=function(C){var F=this.r.toArray(),R=this.s.toArray();if(F[0]&128)F=[0].concat(F);if(R[0]&128)R=[0].concat(R);F=q(F),R=q(R);while(!R[0]&&!(R[1]&128))R=R.slice(1);var M=[2];D(M,F.length),M=M.concat(F),M.push(2),D(M,R.length);var P=M.concat(R),k=[48];return D(k,P.length),k=k.concat(P),K.encode(k,C)}}),OQ=Q0((T,Y)=>{var G=cU(),K=TQ(),L=vU(),W=xX(),O=HT(),z=L.assert,q=YQ(),D=ZQ();function C(F){if(!(this instanceof C))return new C(F);if(typeof F==="string")z(Object.prototype.hasOwnProperty.call(W,F),"Unknown curve "+F),F=W[F];if(F instanceof W.PresetCurve)F={curve:F};this.curve=F.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=F.curve.g,this.g.precompute(F.curve.n.bitLength()+1),this.hash=F.hash||F.curve.hash}Y.exports=C,C.prototype.keyPair=function(F){return new q(this,F)},C.prototype.keyFromPrivate=function(F,R){return q.fromPrivate(this,F,R)},C.prototype.keyFromPublic=function(F,R){return q.fromPublic(this,F,R)},C.prototype.genKeyPair=function(F){if(!F)F={};var R=new K({hash:this.hash,pers:F.pers,persEnc:F.persEnc||"utf8",entropy:F.entropy||O(this.hash.hmacStrength),entropyEnc:F.entropy&&F.entropyEnc||"utf8",nonce:this.n.toArray()}),M=this.n.byteLength(),P=this.n.sub(new G(2));for(;;){var k=new G(R.generate(M));if(k.cmp(P)>0)continue;return k.iaddn(1),this.keyFromPrivate(k)}},C.prototype._truncateToN=function(F,R,M){var P;if(G.isBN(F)||typeof F==="number")F=new G(F,16),P=F.byteLength();else if(typeof F==="object")P=F.length,F=new G(F,16);else{var k=F.toString();P=k.length+1>>>1,F=new G(k,16)}if(typeof M!=="number")M=P*8;var _=M-this.n.bitLength();if(_>0)F=F.ushrn(_);if(!R&&F.cmp(this.n)>=0)return F.sub(this.n);else return F},C.prototype.sign=function(F,R,M,P){if(typeof M==="object")P=M,M=null;if(!P)P={};if(typeof F!=="string"&&typeof F!=="number"&&!G.isBN(F)){z(typeof F==="object"&&F&&typeof F.length==="number","Expected message to be an array-like, a hex string, or a BN instance"),z(F.length>>>0===F.length);for(var k=0;k=0)continue;var Y0=this.g.mul(l);if(Y0.isInfinity())continue;var O0=Y0.getX(),Z0=O0.umod(this.n);if(Z0.cmpn(0)===0)continue;var u=l.invm(this.n).mul(Z0.mul(R.getPrivate()).iadd(F));if(u=u.umod(this.n),u.cmpn(0)===0)continue;var i=(Y0.getY().isOdd()?1:0)|(O0.cmp(Z0)!==0?2:0);if(P.canonical&&u.cmp(this.nh)>0)u=this.n.sub(u),i^=1;return new D({r:Z0,s:u,recoveryParam:i})}},C.prototype.verify=function(F,R,M,P,k){if(!k)k={};F=this._truncateToN(F,!1,k.msgBitLength),M=this.keyFromPublic(M,P),R=new D(R,"hex");var{r:_,s:N}=R;if(_.cmpn(1)<0||_.cmp(this.n)>=0)return!1;if(N.cmpn(1)<0||N.cmp(this.n)>=0)return!1;var v=N.invm(this.n),B=v.mul(F).umod(this.n),g=v.mul(_).umod(this.n),y;if(!this.curve._maxwellTrick){if(y=this.g.mulAdd(B,M.getPublic(),g),y.isInfinity())return!1;return y.getX().umod(this.n).cmp(_)===0}if(y=this.g.jmulAdd(B,M.getPublic(),g),y.isInfinity())return!1;return y.eqXToP(_)},C.prototype.recoverPubKey=function(F,R,M,P){z((3&M)===M,"The recovery param is more than two bits"),R=new D(R,P);var k=this.n,_=new G(F),N=R.r,v=R.s,B=M&1,g=M>>1;if(N.cmp(this.curve.p.umod(this.curve.n))>=0&&g)throw Error("Unable to find sencond key candinate");if(g)N=this.curve.pointFromX(N.add(this.curve.n),B);else N=this.curve.pointFromX(N,B);var y=R.r.invm(k),l=k.sub(_).mul(y).umod(k),Y0=v.mul(y).umod(k);return this.g.mulAdd(l,N,Y0)},C.prototype.getKeyRecoveryParam=function(F,R,M,P){if(R=new D(R,P),R.recoveryParam!==null)return R.recoveryParam;for(var k=0;k<4;k++){var _;try{_=this.recoverPubKey(F,R,k)}catch(N){continue}if(_.eq(M))return k}throw Error("Unable to find valid recovery factor")}}),QQ=Q0((T,Y)=>{var G=vU(),K=G.assert,L=G.parseBytes,W=G.cachedProperty;function O(z,q){if(this.eddsa=z,this._secret=L(q.secret),z.isPoint(q.pub))this._pub=q.pub;else this._pubBytes=L(q.pub)}O.fromPublic=function(z,q){if(q instanceof O)return q;return new O(z,{pub:q})},O.fromSecret=function(z,q){if(q instanceof O)return q;return new O(z,{secret:q})},O.prototype.secret=function(){return this._secret},W(O,"pubBytes",function(){return this.eddsa.encodePoint(this.pub())}),W(O,"pub",function(){if(this._pubBytes)return this.eddsa.decodePoint(this._pubBytes);return this.eddsa.g.mul(this.priv())}),W(O,"privBytes",function(){var z=this.eddsa,q=this.hash(),D=z.encodingLength-1,C=q.slice(0,z.encodingLength);return C[0]&=248,C[D]&=127,C[D]|=64,C}),W(O,"priv",function(){return this.eddsa.decodeInt(this.privBytes())}),W(O,"hash",function(){return this.eddsa.hash().update(this.secret()).digest()}),W(O,"messagePrefix",function(){return this.hash().slice(this.eddsa.encodingLength)}),O.prototype.sign=function(z){return K(this._secret,"KeyPair can only verify"),this.eddsa.sign(z,this)},O.prototype.verify=function(z,q){return this.eddsa.verify(z,q,this)},O.prototype.getSecret=function(z){return K(this._secret,"KeyPair is public only"),G.encode(this.secret(),z)},O.prototype.getPublic=function(z){return G.encode(this.pubBytes(),z)},Y.exports=O}),JQ=Q0((T,Y)=>{var G=cU(),K=vU(),L=K.assert,W=K.cachedProperty,O=K.parseBytes;function z(q,D){if(this.eddsa=q,typeof D!=="object")D=O(D);if(Array.isArray(D))L(D.length===q.encodingLength*2,"Signature has invalid size"),D={R:D.slice(0,q.encodingLength),S:D.slice(q.encodingLength)};if(L(D.R&&D.S,"Signature without R or S"),q.isPoint(D.R))this._R=D.R;if(D.S instanceof G)this._S=D.S;this._Rencoded=Array.isArray(D.R)?D.R:D.Rencoded,this._Sencoded=Array.isArray(D.S)?D.S:D.Sencoded}W(z,"S",function(){return this.eddsa.decodeInt(this.Sencoded())}),W(z,"R",function(){return this.eddsa.decodePoint(this.Rencoded())}),W(z,"Rencoded",function(){return this.eddsa.encodePoint(this.R())}),W(z,"Sencoded",function(){return this.eddsa.encodeInt(this.S())}),z.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},z.prototype.toHex=function(){return K.encode(this.toBytes(),"hex").toUpperCase()},Y.exports=z}),GQ=Q0((T,Y)=>{var G=BX(),K=xX(),L=vU(),W=L.assert,O=L.parseBytes,z=QQ(),q=JQ();function D(C){if(W(C==="ed25519","only tested with ed25519 so far"),!(this instanceof D))return new D(C);C=K[C].curve,this.curve=C,this.g=C.g,this.g.precompute(C.n.bitLength()+1),this.pointClass=C.point().constructor,this.encodingLength=Math.ceil(C.n.bitLength()/8),this.hash=G.sha512}Y.exports=D,D.prototype.sign=function(C,F){C=O(C);var R=this.keyFromSecret(F),M=this.hashInt(R.messagePrefix(),C),P=this.g.mul(M),k=this.encodePoint(P),_=this.hashInt(k,R.pubBytes(),C).mul(R.priv()),N=M.add(_).umod(this.curve.n);return this.makeSignature({R:P,S:N,Rencoded:k})},D.prototype.verify=function(C,F,R){if(C=O(C),F=this.makeSignature(F),F.S().gte(F.eddsa.curve.n)||F.S().isNeg())return!1;var M=this.keyFromPublic(R),P=this.hashInt(F.Rencoded(),M.pubBytes(),C),k=this.g.mul(F.S()),_=F.R().add(M.pub().mul(P));return _.eq(k)},D.prototype.hashInt=function(){var C=this.hash();for(var F=0;F{var Y=T;Y.version=nO().version,Y.utils=vU(),Y.rand=HT(),Y.curve=RT(),Y.curves=xX(),Y.ec=OQ(),Y.eddsa=GQ()}),AQ=Q0((T,Y)=>{(function(G,K){function L(U,I){if(!U)throw Error(I||"Assertion failed")}function W(U,I){U.super_=I;var Q=function(){};Q.prototype=I.prototype,U.prototype=new Q,U.prototype.constructor=U}function O(U,I,Q){if(O.isBN(U))return U;if(this.negative=0,this.words=null,this.length=0,this.red=null,U!==null){if(I==="le"||I==="be")Q=I,I=10;this._init(U||0,I||10,Q||"be")}}if(typeof G==="object")G.exports=O;else K.BN=O;O.BN=O,O.wordSize=26;var z;try{if(typeof window<"u"&&typeof window.Buffer<"u")z=window.Buffer;else z=(FU(),h0(KU)).Buffer}catch(U){}O.isBN=function(U){if(U instanceof O)return!0;return U!==null&&typeof U==="object"&&U.constructor.wordSize===O.wordSize&&Array.isArray(U.words)},O.max=function(U,I){if(U.cmp(I)>0)return U;return I},O.min=function(U,I){if(U.cmp(I)<0)return U;return I},O.prototype._init=function(U,I,Q){if(typeof U==="number")return this._initNumber(U,I,Q);if(typeof U==="object")return this._initArray(U,I,Q);if(I==="hex")I=16;L(I===(I|0)&&I>=2&&I<=36),U=U.toString().replace(/\s+/g,"");var X=0;if(U[0]==="-")X++,this.negative=1;if(X=0;X-=3)if(A=U[X]|U[X-1]<<8|U[X-2]<<16,this.words[Z]|=A<<$&67108863,this.words[Z+1]=A>>>26-$&67108863,$+=24,$>=26)$-=26,Z++}else if(Q==="le"){for(X=0,Z=0;X>>26-$&67108863,$+=24,$>=26)$-=26,Z++}return this.strip()};function q(U,I){var Q=U.charCodeAt(I);if(Q>=65&&Q<=70)return Q-55;else if(Q>=97&&Q<=102)return Q-87;else return Q-48&15}function D(U,I,Q){var X=q(U,Q);if(Q-1>=I)X|=q(U,Q-1)<<4;return X}O.prototype._parseHex=function(U,I,Q){this.length=Math.ceil((U.length-I)/6),this.words=Array(this.length);for(var X=0;X=I;X-=2)if($=D(U,I,X)<=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8;else{var J=U.length-I;for(X=J%2===0?I+1:I;X=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8}this.strip()};function C(U,I,Q,X){var Z=0,A=Math.min(U.length,Q);for(var $=I;$=49)Z+=J-49+10;else if(J>=17)Z+=J-17+10;else Z+=J}return Z}O.prototype._parseBase=function(U,I,Q){this.words=[0],this.length=1;for(var X=0,Z=1;Z<=67108863;Z*=I)X++;X--,Z=Z/I|0;var A=U.length-Q,$=A%X,J=Math.min(A,A-$)+Q,E=0;for(var V=Q;V1&&this.words[this.length-1]===0)this.length--;return this._normSign()},O.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},O.prototype.inspect=function(){return(this.red?""};var F=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],R=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],M=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(O.prototype.toString=function(U,I){U=U||10,I=I|0||1;var Q;if(U===16||U==="hex"){Q="";var X=0,Z=0;for(var A=0;A>>24-X&16777215,X+=2,X>=26)X-=26,A--;if(Z!==0||A!==this.length-1)Q=F[6-J.length]+J+Q;else Q=J+Q}if(Z!==0)Q=Z.toString(16)+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}if(U===(U|0)&&U>=2&&U<=36){var E=R[U],V=M[U];Q="";var S=this.clone();S.negative=0;while(!S.isZero()){var H=S.modn(V).toString(U);if(S=S.idivn(V),!S.isZero())Q=F[E-H.length]+H+Q;else Q=H+Q}if(this.isZero())Q="0"+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}L(!1,"Base should be between 2 and 36")},O.prototype.toNumber=function(){var U=this.words[0];if(this.length===2)U+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)U+=4503599627370496+this.words[1]*67108864;else if(this.length>2)L(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-U:U},O.prototype.toJSON=function(){return this.toString(16)},O.prototype.toBuffer=function(U,I){return L(typeof z<"u"),this.toArrayLike(z,U,I)},O.prototype.toArray=function(U,I){return this.toArrayLike(Array,U,I)},O.prototype.toArrayLike=function(U,I,Q){var X=this.byteLength(),Z=Q||Math.max(1,X);L(X<=Z,"byte array longer than desired length"),L(Z>0,"Requested array length <= 0"),this.strip();var A=I==="le",$=new U(Z),J,E,V=this.clone();if(!A){for(E=0;E=4096)Q+=13,I>>>=13;if(I>=64)Q+=7,I>>>=7;if(I>=8)Q+=4,I>>>=4;if(I>=2)Q+=2,I>>>=2;return Q+I};O.prototype._zeroBits=function(U){if(U===0)return 26;var I=U,Q=0;if((I&8191)===0)Q+=13,I>>>=13;if((I&127)===0)Q+=7,I>>>=7;if((I&15)===0)Q+=4,I>>>=4;if((I&3)===0)Q+=2,I>>>=2;if((I&1)===0)Q++;return Q},O.prototype.bitLength=function(){var U=this.words[this.length-1],I=this._countBits(U);return(this.length-1)*26+I};function P(U){var I=Array(U.bitLength());for(var Q=0;Q>>Z}return I}O.prototype.zeroBits=function(){if(this.isZero())return 0;var U=0;for(var I=0;IU.length)return this.clone().ior(U);return U.clone().ior(this)},O.prototype.uor=function(U){if(this.length>U.length)return this.clone().iuor(U);return U.clone().iuor(this)},O.prototype.iuand=function(U){var I;if(this.length>U.length)I=U;else I=this;for(var Q=0;QU.length)return this.clone().iand(U);return U.clone().iand(this)},O.prototype.uand=function(U){if(this.length>U.length)return this.clone().iuand(U);return U.clone().iuand(this)},O.prototype.iuxor=function(U){var I,Q;if(this.length>U.length)I=this,Q=U;else I=U,Q=this;for(var X=0;XU.length)return this.clone().ixor(U);return U.clone().ixor(this)},O.prototype.uxor=function(U){if(this.length>U.length)return this.clone().iuxor(U);return U.clone().iuxor(this)},O.prototype.inotn=function(U){L(typeof U==="number"&&U>=0);var I=Math.ceil(U/26)|0,Q=U%26;if(this._expand(I),Q>0)I--;for(var X=0;X0)this.words[X]=~this.words[X]&67108863>>26-Q;return this.strip()},O.prototype.notn=function(U){return this.clone().inotn(U)},O.prototype.setn=function(U,I){L(typeof U==="number"&&U>=0);var Q=U/26|0,X=U%26;if(this._expand(Q+1),I)this.words[Q]=this.words[Q]|1<U.length)Q=this,X=U;else Q=U,X=this;var Z=0;for(var A=0;A>>26;for(;Z!==0&&A>>26;if(this.length=Q.length,Z!==0)this.words[this.length]=Z,this.length++;else if(Q!==this)for(;AU.length)return this.clone().iadd(U);return U.clone().iadd(this)},O.prototype.isub=function(U){if(U.negative!==0){U.negative=0;var I=this.iadd(U);return U.negative=1,I._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(U),this.negative=1,this._normSign();var Q=this.cmp(U);if(Q===0)return this.negative=0,this.length=1,this.words[0]=0,this;var X,Z;if(Q>0)X=this,Z=U;else X=U,Z=this;var A=0;for(var $=0;$>26,this.words[$]=I&67108863;for(;A!==0&&$>26,this.words[$]=I&67108863;if(A===0&&$>>26,H=E&67108863,j=Math.min(V,I.length-1);for(var w=Math.max(0,V-U.length+1);w<=j;w++){var p=V-w|0;Z=U.words[p]|0,A=I.words[w]|0,$=Z*A+H,S+=$/67108864|0,H=$&67108863}Q.words[V]=H|0,E=S|0}if(E!==0)Q.words[V]=E|0;else Q.length--;return Q.strip()}var _=function(U,I,Q){var X=U.words,Z=I.words,A=Q.words,$=0,J,E,V,S=X[0]|0,H=S&8191,j=S>>>13,w=X[1]|0,p=w&8191,n=w>>>13,G0=X[2]|0,t=G0&8191,d=G0>>>13,I0=X[3]|0,m=I0&8191,U0=I0>>>13,g0=X[4]|0,f=g0&8191,h=g0>>>13,T0=X[5]|0,r=T0&8191,e=T0>>>13,C0=X[6]|0,c=C0&8191,o=C0>>>13,x0=X[7]|0,s=x0&8191,X0=x0>>>13,y0=X[8]|0,L0=y0&8191,$0=y0>>>13,n0=X[9]|0,V0=n0&8191,K0=n0>>>13,r0=Z[0]|0,H0=r0&8191,W0=r0>>>13,RU=Z[1]|0,D0=RU&8191,_0=RU>>>13,CU=Z[2]|0,k0=CU&8191,z0=CU>>>13,WU=Z[3]|0,v0=WU&8191,S0=WU>>>13,AU=Z[4]|0,j0=AU&8191,N0=AU>>>13,LU=Z[5]|0,M0=LU&8191,x=LU>>>13,b=Z[6]|0,a=b&8191,E0=b>>>13,w0=Z[7]|0,A0=w0&8191,F0=w0>>>13,m0=Z[8]|0,q0=m0&8191,B0=m0>>>13,HU=Z[9]|0,P0=HU&8191,R0=HU>>>13;Q.negative=U.negative^I.negative,Q.length=19,J=Math.imul(H,H0),E=Math.imul(H,W0),E=E+Math.imul(j,H0)|0,V=Math.imul(j,W0);var s0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(s0>>>26)|0,s0&=67108863,J=Math.imul(p,H0),E=Math.imul(p,W0),E=E+Math.imul(n,H0)|0,V=Math.imul(n,W0),J=J+Math.imul(H,D0)|0,E=E+Math.imul(H,_0)|0,E=E+Math.imul(j,D0)|0,V=V+Math.imul(j,_0)|0;var c0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(c0>>>26)|0,c0&=67108863,J=Math.imul(t,H0),E=Math.imul(t,W0),E=E+Math.imul(d,H0)|0,V=Math.imul(d,W0),J=J+Math.imul(p,D0)|0,E=E+Math.imul(p,_0)|0,E=E+Math.imul(n,D0)|0,V=V+Math.imul(n,_0)|0,J=J+Math.imul(H,k0)|0,E=E+Math.imul(H,z0)|0,E=E+Math.imul(j,k0)|0,V=V+Math.imul(j,z0)|0;var f0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(f0>>>26)|0,f0&=67108863,J=Math.imul(m,H0),E=Math.imul(m,W0),E=E+Math.imul(U0,H0)|0,V=Math.imul(U0,W0),J=J+Math.imul(t,D0)|0,E=E+Math.imul(t,_0)|0,E=E+Math.imul(d,D0)|0,V=V+Math.imul(d,_0)|0,J=J+Math.imul(p,k0)|0,E=E+Math.imul(p,z0)|0,E=E+Math.imul(n,k0)|0,V=V+Math.imul(n,z0)|0,J=J+Math.imul(H,v0)|0,E=E+Math.imul(H,S0)|0,E=E+Math.imul(j,v0)|0,V=V+Math.imul(j,S0)|0;var d0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(d0>>>26)|0,d0&=67108863,J=Math.imul(f,H0),E=Math.imul(f,W0),E=E+Math.imul(h,H0)|0,V=Math.imul(h,W0),J=J+Math.imul(m,D0)|0,E=E+Math.imul(m,_0)|0,E=E+Math.imul(U0,D0)|0,V=V+Math.imul(U0,_0)|0,J=J+Math.imul(t,k0)|0,E=E+Math.imul(t,z0)|0,E=E+Math.imul(d,k0)|0,V=V+Math.imul(d,z0)|0,J=J+Math.imul(p,v0)|0,E=E+Math.imul(p,S0)|0,E=E+Math.imul(n,v0)|0,V=V+Math.imul(n,S0)|0,J=J+Math.imul(H,j0)|0,E=E+Math.imul(H,N0)|0,E=E+Math.imul(j,j0)|0,V=V+Math.imul(j,N0)|0;var b0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(b0>>>26)|0,b0&=67108863,J=Math.imul(r,H0),E=Math.imul(r,W0),E=E+Math.imul(e,H0)|0,V=Math.imul(e,W0),J=J+Math.imul(f,D0)|0,E=E+Math.imul(f,_0)|0,E=E+Math.imul(h,D0)|0,V=V+Math.imul(h,_0)|0,J=J+Math.imul(m,k0)|0,E=E+Math.imul(m,z0)|0,E=E+Math.imul(U0,k0)|0,V=V+Math.imul(U0,z0)|0,J=J+Math.imul(t,v0)|0,E=E+Math.imul(t,S0)|0,E=E+Math.imul(d,v0)|0,V=V+Math.imul(d,S0)|0,J=J+Math.imul(p,j0)|0,E=E+Math.imul(p,N0)|0,E=E+Math.imul(n,j0)|0,V=V+Math.imul(n,N0)|0,J=J+Math.imul(H,M0)|0,E=E+Math.imul(H,x)|0,E=E+Math.imul(j,M0)|0,V=V+Math.imul(j,x)|0;var t0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(t0>>>26)|0,t0&=67108863,J=Math.imul(c,H0),E=Math.imul(c,W0),E=E+Math.imul(o,H0)|0,V=Math.imul(o,W0),J=J+Math.imul(r,D0)|0,E=E+Math.imul(r,_0)|0,E=E+Math.imul(e,D0)|0,V=V+Math.imul(e,_0)|0,J=J+Math.imul(f,k0)|0,E=E+Math.imul(f,z0)|0,E=E+Math.imul(h,k0)|0,V=V+Math.imul(h,z0)|0,J=J+Math.imul(m,v0)|0,E=E+Math.imul(m,S0)|0,E=E+Math.imul(U0,v0)|0,V=V+Math.imul(U0,S0)|0,J=J+Math.imul(t,j0)|0,E=E+Math.imul(t,N0)|0,E=E+Math.imul(d,j0)|0,V=V+Math.imul(d,N0)|0,J=J+Math.imul(p,M0)|0,E=E+Math.imul(p,x)|0,E=E+Math.imul(n,M0)|0,V=V+Math.imul(n,x)|0,J=J+Math.imul(H,a)|0,E=E+Math.imul(H,E0)|0,E=E+Math.imul(j,a)|0,V=V+Math.imul(j,E0)|0;var a0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(a0>>>26)|0,a0&=67108863,J=Math.imul(s,H0),E=Math.imul(s,W0),E=E+Math.imul(X0,H0)|0,V=Math.imul(X0,W0),J=J+Math.imul(c,D0)|0,E=E+Math.imul(c,_0)|0,E=E+Math.imul(o,D0)|0,V=V+Math.imul(o,_0)|0,J=J+Math.imul(r,k0)|0,E=E+Math.imul(r,z0)|0,E=E+Math.imul(e,k0)|0,V=V+Math.imul(e,z0)|0,J=J+Math.imul(f,v0)|0,E=E+Math.imul(f,S0)|0,E=E+Math.imul(h,v0)|0,V=V+Math.imul(h,S0)|0,J=J+Math.imul(m,j0)|0,E=E+Math.imul(m,N0)|0,E=E+Math.imul(U0,j0)|0,V=V+Math.imul(U0,N0)|0,J=J+Math.imul(t,M0)|0,E=E+Math.imul(t,x)|0,E=E+Math.imul(d,M0)|0,V=V+Math.imul(d,x)|0,J=J+Math.imul(p,a)|0,E=E+Math.imul(p,E0)|0,E=E+Math.imul(n,a)|0,V=V+Math.imul(n,E0)|0,J=J+Math.imul(H,A0)|0,E=E+Math.imul(H,F0)|0,E=E+Math.imul(j,A0)|0,V=V+Math.imul(j,F0)|0;var e0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(e0>>>26)|0,e0&=67108863,J=Math.imul(L0,H0),E=Math.imul(L0,W0),E=E+Math.imul($0,H0)|0,V=Math.imul($0,W0),J=J+Math.imul(s,D0)|0,E=E+Math.imul(s,_0)|0,E=E+Math.imul(X0,D0)|0,V=V+Math.imul(X0,_0)|0,J=J+Math.imul(c,k0)|0,E=E+Math.imul(c,z0)|0,E=E+Math.imul(o,k0)|0,V=V+Math.imul(o,z0)|0,J=J+Math.imul(r,v0)|0,E=E+Math.imul(r,S0)|0,E=E+Math.imul(e,v0)|0,V=V+Math.imul(e,S0)|0,J=J+Math.imul(f,j0)|0,E=E+Math.imul(f,N0)|0,E=E+Math.imul(h,j0)|0,V=V+Math.imul(h,N0)|0,J=J+Math.imul(m,M0)|0,E=E+Math.imul(m,x)|0,E=E+Math.imul(U0,M0)|0,V=V+Math.imul(U0,x)|0,J=J+Math.imul(t,a)|0,E=E+Math.imul(t,E0)|0,E=E+Math.imul(d,a)|0,V=V+Math.imul(d,E0)|0,J=J+Math.imul(p,A0)|0,E=E+Math.imul(p,F0)|0,E=E+Math.imul(n,A0)|0,V=V+Math.imul(n,F0)|0,J=J+Math.imul(H,q0)|0,E=E+Math.imul(H,B0)|0,E=E+Math.imul(j,q0)|0,V=V+Math.imul(j,B0)|0;var i0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(i0>>>26)|0,i0&=67108863,J=Math.imul(V0,H0),E=Math.imul(V0,W0),E=E+Math.imul(K0,H0)|0,V=Math.imul(K0,W0),J=J+Math.imul(L0,D0)|0,E=E+Math.imul(L0,_0)|0,E=E+Math.imul($0,D0)|0,V=V+Math.imul($0,_0)|0,J=J+Math.imul(s,k0)|0,E=E+Math.imul(s,z0)|0,E=E+Math.imul(X0,k0)|0,V=V+Math.imul(X0,z0)|0,J=J+Math.imul(c,v0)|0,E=E+Math.imul(c,S0)|0,E=E+Math.imul(o,v0)|0,V=V+Math.imul(o,S0)|0,J=J+Math.imul(r,j0)|0,E=E+Math.imul(r,N0)|0,E=E+Math.imul(e,j0)|0,V=V+Math.imul(e,N0)|0,J=J+Math.imul(f,M0)|0,E=E+Math.imul(f,x)|0,E=E+Math.imul(h,M0)|0,V=V+Math.imul(h,x)|0,J=J+Math.imul(m,a)|0,E=E+Math.imul(m,E0)|0,E=E+Math.imul(U0,a)|0,V=V+Math.imul(U0,E0)|0,J=J+Math.imul(t,A0)|0,E=E+Math.imul(t,F0)|0,E=E+Math.imul(d,A0)|0,V=V+Math.imul(d,F0)|0,J=J+Math.imul(p,q0)|0,E=E+Math.imul(p,B0)|0,E=E+Math.imul(n,q0)|0,V=V+Math.imul(n,B0)|0,J=J+Math.imul(H,P0)|0,E=E+Math.imul(H,R0)|0,E=E+Math.imul(j,P0)|0,V=V+Math.imul(j,R0)|0;var UU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(UU>>>26)|0,UU&=67108863,J=Math.imul(V0,D0),E=Math.imul(V0,_0),E=E+Math.imul(K0,D0)|0,V=Math.imul(K0,_0),J=J+Math.imul(L0,k0)|0,E=E+Math.imul(L0,z0)|0,E=E+Math.imul($0,k0)|0,V=V+Math.imul($0,z0)|0,J=J+Math.imul(s,v0)|0,E=E+Math.imul(s,S0)|0,E=E+Math.imul(X0,v0)|0,V=V+Math.imul(X0,S0)|0,J=J+Math.imul(c,j0)|0,E=E+Math.imul(c,N0)|0,E=E+Math.imul(o,j0)|0,V=V+Math.imul(o,N0)|0,J=J+Math.imul(r,M0)|0,E=E+Math.imul(r,x)|0,E=E+Math.imul(e,M0)|0,V=V+Math.imul(e,x)|0,J=J+Math.imul(f,a)|0,E=E+Math.imul(f,E0)|0,E=E+Math.imul(h,a)|0,V=V+Math.imul(h,E0)|0,J=J+Math.imul(m,A0)|0,E=E+Math.imul(m,F0)|0,E=E+Math.imul(U0,A0)|0,V=V+Math.imul(U0,F0)|0,J=J+Math.imul(t,q0)|0,E=E+Math.imul(t,B0)|0,E=E+Math.imul(d,q0)|0,V=V+Math.imul(d,B0)|0,J=J+Math.imul(p,P0)|0,E=E+Math.imul(p,R0)|0,E=E+Math.imul(n,P0)|0,V=V+Math.imul(n,R0)|0;var EU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(EU>>>26)|0,EU&=67108863,J=Math.imul(V0,k0),E=Math.imul(V0,z0),E=E+Math.imul(K0,k0)|0,V=Math.imul(K0,z0),J=J+Math.imul(L0,v0)|0,E=E+Math.imul(L0,S0)|0,E=E+Math.imul($0,v0)|0,V=V+Math.imul($0,S0)|0,J=J+Math.imul(s,j0)|0,E=E+Math.imul(s,N0)|0,E=E+Math.imul(X0,j0)|0,V=V+Math.imul(X0,N0)|0,J=J+Math.imul(c,M0)|0,E=E+Math.imul(c,x)|0,E=E+Math.imul(o,M0)|0,V=V+Math.imul(o,x)|0,J=J+Math.imul(r,a)|0,E=E+Math.imul(r,E0)|0,E=E+Math.imul(e,a)|0,V=V+Math.imul(e,E0)|0,J=J+Math.imul(f,A0)|0,E=E+Math.imul(f,F0)|0,E=E+Math.imul(h,A0)|0,V=V+Math.imul(h,F0)|0,J=J+Math.imul(m,q0)|0,E=E+Math.imul(m,B0)|0,E=E+Math.imul(U0,q0)|0,V=V+Math.imul(U0,B0)|0,J=J+Math.imul(t,P0)|0,E=E+Math.imul(t,R0)|0,E=E+Math.imul(d,P0)|0,V=V+Math.imul(d,R0)|0;var XU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(XU>>>26)|0,XU&=67108863,J=Math.imul(V0,v0),E=Math.imul(V0,S0),E=E+Math.imul(K0,v0)|0,V=Math.imul(K0,S0),J=J+Math.imul(L0,j0)|0,E=E+Math.imul(L0,N0)|0,E=E+Math.imul($0,j0)|0,V=V+Math.imul($0,N0)|0,J=J+Math.imul(s,M0)|0,E=E+Math.imul(s,x)|0,E=E+Math.imul(X0,M0)|0,V=V+Math.imul(X0,x)|0,J=J+Math.imul(c,a)|0,E=E+Math.imul(c,E0)|0,E=E+Math.imul(o,a)|0,V=V+Math.imul(o,E0)|0,J=J+Math.imul(r,A0)|0,E=E+Math.imul(r,F0)|0,E=E+Math.imul(e,A0)|0,V=V+Math.imul(e,F0)|0,J=J+Math.imul(f,q0)|0,E=E+Math.imul(f,B0)|0,E=E+Math.imul(h,q0)|0,V=V+Math.imul(h,B0)|0,J=J+Math.imul(m,P0)|0,E=E+Math.imul(m,R0)|0,E=E+Math.imul(U0,P0)|0,V=V+Math.imul(U0,R0)|0;var IU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(IU>>>26)|0,IU&=67108863,J=Math.imul(V0,j0),E=Math.imul(V0,N0),E=E+Math.imul(K0,j0)|0,V=Math.imul(K0,N0),J=J+Math.imul(L0,M0)|0,E=E+Math.imul(L0,x)|0,E=E+Math.imul($0,M0)|0,V=V+Math.imul($0,x)|0,J=J+Math.imul(s,a)|0,E=E+Math.imul(s,E0)|0,E=E+Math.imul(X0,a)|0,V=V+Math.imul(X0,E0)|0,J=J+Math.imul(c,A0)|0,E=E+Math.imul(c,F0)|0,E=E+Math.imul(o,A0)|0,V=V+Math.imul(o,F0)|0,J=J+Math.imul(r,q0)|0,E=E+Math.imul(r,B0)|0,E=E+Math.imul(e,q0)|0,V=V+Math.imul(e,B0)|0,J=J+Math.imul(f,P0)|0,E=E+Math.imul(f,R0)|0,E=E+Math.imul(h,P0)|0,V=V+Math.imul(h,R0)|0;var TU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(TU>>>26)|0,TU&=67108863,J=Math.imul(V0,M0),E=Math.imul(V0,x),E=E+Math.imul(K0,M0)|0,V=Math.imul(K0,x),J=J+Math.imul(L0,a)|0,E=E+Math.imul(L0,E0)|0,E=E+Math.imul($0,a)|0,V=V+Math.imul($0,E0)|0,J=J+Math.imul(s,A0)|0,E=E+Math.imul(s,F0)|0,E=E+Math.imul(X0,A0)|0,V=V+Math.imul(X0,F0)|0,J=J+Math.imul(c,q0)|0,E=E+Math.imul(c,B0)|0,E=E+Math.imul(o,q0)|0,V=V+Math.imul(o,B0)|0,J=J+Math.imul(r,P0)|0,E=E+Math.imul(r,R0)|0,E=E+Math.imul(e,P0)|0,V=V+Math.imul(e,R0)|0;var YU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(YU>>>26)|0,YU&=67108863,J=Math.imul(V0,a),E=Math.imul(V0,E0),E=E+Math.imul(K0,a)|0,V=Math.imul(K0,E0),J=J+Math.imul(L0,A0)|0,E=E+Math.imul(L0,F0)|0,E=E+Math.imul($0,A0)|0,V=V+Math.imul($0,F0)|0,J=J+Math.imul(s,q0)|0,E=E+Math.imul(s,B0)|0,E=E+Math.imul(X0,q0)|0,V=V+Math.imul(X0,B0)|0,J=J+Math.imul(c,P0)|0,E=E+Math.imul(c,R0)|0,E=E+Math.imul(o,P0)|0,V=V+Math.imul(o,R0)|0;var ZU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(ZU>>>26)|0,ZU&=67108863,J=Math.imul(V0,A0),E=Math.imul(V0,F0),E=E+Math.imul(K0,A0)|0,V=Math.imul(K0,F0),J=J+Math.imul(L0,q0)|0,E=E+Math.imul(L0,B0)|0,E=E+Math.imul($0,q0)|0,V=V+Math.imul($0,B0)|0,J=J+Math.imul(s,P0)|0,E=E+Math.imul(s,R0)|0,E=E+Math.imul(X0,P0)|0,V=V+Math.imul(X0,R0)|0;var OU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(OU>>>26)|0,OU&=67108863,J=Math.imul(V0,q0),E=Math.imul(V0,B0),E=E+Math.imul(K0,q0)|0,V=Math.imul(K0,B0),J=J+Math.imul(L0,P0)|0,E=E+Math.imul(L0,R0)|0,E=E+Math.imul($0,P0)|0,V=V+Math.imul($0,R0)|0;var QU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(QU>>>26)|0,QU&=67108863,J=Math.imul(V0,P0),E=Math.imul(V0,R0),E=E+Math.imul(K0,P0)|0,V=Math.imul(K0,R0);var JU=($+J|0)+((E&8191)<<13)|0;if($=(V+(E>>>13)|0)+(JU>>>26)|0,JU&=67108863,A[0]=s0,A[1]=c0,A[2]=f0,A[3]=d0,A[4]=b0,A[5]=t0,A[6]=a0,A[7]=e0,A[8]=i0,A[9]=UU,A[10]=EU,A[11]=XU,A[12]=IU,A[13]=TU,A[14]=YU,A[15]=ZU,A[16]=OU,A[17]=QU,A[18]=JU,$!==0)A[19]=$,Q.length++;return Q};if(!Math.imul)_=k;function N(U,I,Q){Q.negative=I.negative^U.negative,Q.length=U.length+I.length;var X=0,Z=0;for(var A=0;A>>26)|0,Z+=$>>>26,$&=67108863}Q.words[A]=J,X=$,$=Z}if(X!==0)Q.words[A]=X;else Q.length--;return Q.strip()}function v(U,I,Q){var X=new B;return X.mulp(U,I,Q)}O.prototype.mulTo=function(U,I){var Q,X=this.length+U.length;if(this.length===10&&U.length===10)Q=_(this,U,I);else if(X<63)Q=k(this,U,I);else if(X<1024)Q=N(this,U,I);else Q=v(this,U,I);return Q};function B(U,I){this.x=U,this.y=I}B.prototype.makeRBT=function(U){var I=Array(U),Q=O.prototype._countBits(U)-1;for(var X=0;X>=1;return X},B.prototype.permute=function(U,I,Q,X,Z,A){for(var $=0;$>>1)Z++;return 1<>>13,Q[2*A+1]=Z&8191,Z=Z>>>13;for(A=2*I;A>=26,I+=X/67108864|0,I+=Z>>>26,this.words[Q]=Z&67108863}if(I!==0)this.words[Q]=I,this.length++;return this.length=U===0?1:this.length,this},O.prototype.muln=function(U){return this.clone().imuln(U)},O.prototype.sqr=function(){return this.mul(this)},O.prototype.isqr=function(){return this.imul(this.clone())},O.prototype.pow=function(U){var I=P(U);if(I.length===0)return new O(1);var Q=this;for(var X=0;X=0);var I=U%26,Q=(U-I)/26,X=67108863>>>26-I<<26-I,Z;if(I!==0){var A=0;for(Z=0;Z>>26-I}if(A)this.words[Z]=A,this.length++}if(Q!==0){for(Z=this.length-1;Z>=0;Z--)this.words[Z+Q]=this.words[Z];for(Z=0;Z=0);var X;if(I)X=(I-I%26)/26;else X=0;var Z=U%26,A=Math.min((U-Z)/26,this.length),$=67108863^67108863>>>Z<A){this.length-=A;for(E=0;E=0&&(V!==0||E>=X);E--){var S=this.words[E]|0;this.words[E]=V<<26-Z|S>>>Z,V=S&$}if(J&&V!==0)J.words[J.length++]=V;if(this.length===0)this.words[0]=0,this.length=1;return this.strip()},O.prototype.ishrn=function(U,I,Q){return L(this.negative===0),this.iushrn(U,I,Q)},O.prototype.shln=function(U){return this.clone().ishln(U)},O.prototype.ushln=function(U){return this.clone().iushln(U)},O.prototype.shrn=function(U){return this.clone().ishrn(U)},O.prototype.ushrn=function(U){return this.clone().iushrn(U)},O.prototype.testn=function(U){L(typeof U==="number"&&U>=0);var I=U%26,Q=(U-I)/26,X=1<=0);var I=U%26,Q=(U-I)/26;if(L(this.negative===0,"imaskn works only with positive numbers"),this.length<=Q)return this;if(I!==0)Q++;if(this.length=Math.min(Q,this.length),I!==0){var X=67108863^67108863>>>I<=67108864;I++)if(this.words[I]-=67108864,I===this.length-1)this.words[I+1]=1;else this.words[I+1]++;return this.length=Math.max(this.length,I+1),this},O.prototype.isubn=function(U){if(L(typeof U==="number"),L(U<67108864),U<0)return this.iaddn(-U);if(this.negative!==0)return this.negative=0,this.iaddn(U),this.negative=1,this;if(this.words[0]-=U,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var I=0;I>26)-(J/67108864|0),this.words[Z+Q]=A&67108863}for(;Z>26,this.words[Z+Q]=A&67108863;if($===0)return this.strip();L($===-1),$=0;for(Z=0;Z>26,this.words[Z]=A&67108863;return this.negative=1,this.strip()},O.prototype._wordDiv=function(U,I){var Q=this.length-U.length,X=this.clone(),Z=U,A=Z.words[Z.length-1]|0,$=this._countBits(A);if(Q=26-$,Q!==0)Z=Z.ushln(Q),X.iushln(Q),A=Z.words[Z.length-1]|0;var J=X.length-Z.length,E;if(I!=="mod"){E=new O(null),E.length=J+1,E.words=Array(E.length);for(var V=0;V=0;H--){var j=(X.words[Z.length+H]|0)*67108864+(X.words[Z.length+H-1]|0);j=Math.min(j/A|0,67108863),X._ishlnsubmul(Z,j,H);while(X.negative!==0)if(j--,X.negative=0,X._ishlnsubmul(Z,1,H),!X.isZero())X.negative^=1;if(E)E.words[H]=j}if(E)E.strip();if(X.strip(),I!=="div"&&Q!==0)X.iushrn(Q);return{div:E||null,mod:X}},O.prototype.divmod=function(U,I,Q){if(L(!U.isZero()),this.isZero())return{div:new O(0),mod:new O(0)};var X,Z,A;if(this.negative!==0&&U.negative===0){if(A=this.neg().divmod(U,I),I!=="mod")X=A.div.neg();if(I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.iadd(U)}return{div:X,mod:Z}}if(this.negative===0&&U.negative!==0){if(A=this.divmod(U.neg(),I),I!=="mod")X=A.div.neg();return{div:X,mod:A.mod}}if((this.negative&U.negative)!==0){if(A=this.neg().divmod(U.neg(),I),I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.isub(U)}return{div:A.div,mod:Z}}if(U.length>this.length||this.cmp(U)<0)return{div:new O(0),mod:this};if(U.length===1){if(I==="div")return{div:this.divn(U.words[0]),mod:null};if(I==="mod")return{div:null,mod:new O(this.modn(U.words[0]))};return{div:this.divn(U.words[0]),mod:new O(this.modn(U.words[0]))}}return this._wordDiv(U,I)},O.prototype.div=function(U){return this.divmod(U,"div",!1).div},O.prototype.mod=function(U){return this.divmod(U,"mod",!1).mod},O.prototype.umod=function(U){return this.divmod(U,"mod",!0).mod},O.prototype.divRound=function(U){var I=this.divmod(U);if(I.mod.isZero())return I.div;var Q=I.div.negative!==0?I.mod.isub(U):I.mod,X=U.ushrn(1),Z=U.andln(1),A=Q.cmp(X);if(A<0||Z===1&&A===0)return I.div;return I.div.negative!==0?I.div.isubn(1):I.div.iaddn(1)},O.prototype.modn=function(U){L(U<=67108863);var I=67108864%U,Q=0;for(var X=this.length-1;X>=0;X--)Q=(I*Q+(this.words[X]|0))%U;return Q},O.prototype.idivn=function(U){L(U<=67108863);var I=0;for(var Q=this.length-1;Q>=0;Q--){var X=(this.words[Q]|0)+I*67108864;this.words[Q]=X/U|0,I=X%U}return this.strip()},O.prototype.divn=function(U){return this.clone().idivn(U)},O.prototype.egcd=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=new O(0),$=new O(1),J=0;while(I.isEven()&&Q.isEven())I.iushrn(1),Q.iushrn(1),++J;var E=Q.clone(),V=I.clone();while(!I.isZero()){for(var S=0,H=1;(I.words[0]&H)===0&&S<26;++S,H<<=1);if(S>0){I.iushrn(S);while(S-- >0){if(X.isOdd()||Z.isOdd())X.iadd(E),Z.isub(V);X.iushrn(1),Z.iushrn(1)}}for(var j=0,w=1;(Q.words[0]&w)===0&&j<26;++j,w<<=1);if(j>0){Q.iushrn(j);while(j-- >0){if(A.isOdd()||$.isOdd())A.iadd(E),$.isub(V);A.iushrn(1),$.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(A),Z.isub($);else Q.isub(I),A.isub(X),$.isub(Z)}return{a:A,b:$,gcd:Q.iushln(J)}},O.prototype._invmp=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=Q.clone();while(I.cmpn(1)>0&&Q.cmpn(1)>0){for(var $=0,J=1;(I.words[0]&J)===0&&$<26;++$,J<<=1);if($>0){I.iushrn($);while($-- >0){if(X.isOdd())X.iadd(A);X.iushrn(1)}}for(var E=0,V=1;(Q.words[0]&V)===0&&E<26;++E,V<<=1);if(E>0){Q.iushrn(E);while(E-- >0){if(Z.isOdd())Z.iadd(A);Z.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(Z);else Q.isub(I),Z.isub(X)}var S;if(I.cmpn(1)===0)S=X;else S=Z;if(S.cmpn(0)<0)S.iadd(U);return S},O.prototype.gcd=function(U){if(this.isZero())return U.abs();if(U.isZero())return this.abs();var I=this.clone(),Q=U.clone();I.negative=0,Q.negative=0;for(var X=0;I.isEven()&&Q.isEven();X++)I.iushrn(1),Q.iushrn(1);do{while(I.isEven())I.iushrn(1);while(Q.isEven())Q.iushrn(1);var Z=I.cmp(Q);if(Z<0){var A=I;I=Q,Q=A}else if(Z===0||Q.cmpn(1)===0)break;I.isub(Q)}while(!0);return Q.iushln(X)},O.prototype.invm=function(U){return this.egcd(U).a.umod(U)},O.prototype.isEven=function(){return(this.words[0]&1)===0},O.prototype.isOdd=function(){return(this.words[0]&1)===1},O.prototype.andln=function(U){return this.words[0]&U},O.prototype.bincn=function(U){L(typeof U==="number");var I=U%26,Q=(U-I)/26,X=1<>>26,$&=67108863,this.words[A]=$}if(Z!==0)this.words[A]=Z,this.length++;return this},O.prototype.isZero=function(){return this.length===1&&this.words[0]===0},O.prototype.cmpn=function(U){var I=U<0;if(this.negative!==0&&!I)return-1;if(this.negative===0&&I)return 1;this.strip();var Q;if(this.length>1)Q=1;else{if(I)U=-U;L(U<=67108863,"Number is too big");var X=this.words[0]|0;Q=X===U?0:XU.length)return 1;if(this.length=0;Q--){var X=this.words[Q]|0,Z=U.words[Q]|0;if(X===Z)continue;if(XZ)I=1;break}return I},O.prototype.gtn=function(U){return this.cmpn(U)===1},O.prototype.gt=function(U){return this.cmp(U)===1},O.prototype.gten=function(U){return this.cmpn(U)>=0},O.prototype.gte=function(U){return this.cmp(U)>=0},O.prototype.ltn=function(U){return this.cmpn(U)===-1},O.prototype.lt=function(U){return this.cmp(U)===-1},O.prototype.lten=function(U){return this.cmpn(U)<=0},O.prototype.lte=function(U){return this.cmp(U)<=0},O.prototype.eqn=function(U){return this.cmpn(U)===0},O.prototype.eq=function(U){return this.cmp(U)===0},O.red=function(U){return new u(U)},O.prototype.toRed=function(U){return L(!this.red,"Already a number in reduction context"),L(this.negative===0,"red works only with positives"),U.convertTo(this)._forceRed(U)},O.prototype.fromRed=function(){return L(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},O.prototype._forceRed=function(U){return this.red=U,this},O.prototype.forceRed=function(U){return L(!this.red,"Already a number in reduction context"),this._forceRed(U)},O.prototype.redAdd=function(U){return L(this.red,"redAdd works only with red numbers"),this.red.add(this,U)},O.prototype.redIAdd=function(U){return L(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,U)},O.prototype.redSub=function(U){return L(this.red,"redSub works only with red numbers"),this.red.sub(this,U)},O.prototype.redISub=function(U){return L(this.red,"redISub works only with red numbers"),this.red.isub(this,U)},O.prototype.redShl=function(U){return L(this.red,"redShl works only with red numbers"),this.red.shl(this,U)},O.prototype.redMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.mul(this,U)},O.prototype.redIMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.imul(this,U)},O.prototype.redSqr=function(){return L(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},O.prototype.redISqr=function(){return L(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},O.prototype.redSqrt=function(){return L(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},O.prototype.redInvm=function(){return L(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},O.prototype.redNeg=function(){return L(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},O.prototype.redPow=function(U){return L(this.red&&!U.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,U)};var g={k256:null,p224:null,p192:null,p25519:null};function y(U,I){this.name=U,this.p=new O(I,16),this.n=this.p.bitLength(),this.k=new O(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}y.prototype._tmp=function(){var U=new O(null);return U.words=Array(Math.ceil(this.n/13)),U},y.prototype.ireduce=function(U){var I=U,Q;do this.split(I,this.tmp),I=this.imulK(I),I=I.iadd(this.tmp),Q=I.bitLength();while(Q>this.n);var X=Q0)I.isub(this.p);else if(I.strip!==void 0)I.strip();else I._strip();return I},y.prototype.split=function(U,I){U.iushrn(this.n,0,I)},y.prototype.imulK=function(U){return U.imul(this.k)};function l(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}W(l,y),l.prototype.split=function(U,I){var Q=4194303,X=Math.min(U.length,9);for(var Z=0;Z>>22,A=$}if(A>>>=22,U.words[Z-10]=A,A===0&&U.length>10)U.length-=10;else U.length-=9},l.prototype.imulK=function(U){U.words[U.length]=0,U.words[U.length+1]=0,U.length+=2;var I=0;for(var Q=0;Q>>=26,U.words[Q]=Z,I=X}if(I!==0)U.words[U.length++]=I;return U},O._prime=function(U){if(g[U])return g[U];var I;if(U==="k256")I=new l;else if(U==="p224")I=new Y0;else if(U==="p192")I=new O0;else if(U==="p25519")I=new Z0;else throw Error("Unknown prime "+U);return g[U]=I,I};function u(U){if(typeof U==="string"){var I=O._prime(U);this.m=I.p,this.prime=I}else L(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}u.prototype._verify1=function(U){L(U.negative===0,"red works only with positives"),L(U.red,"red works only with red numbers")},u.prototype._verify2=function(U,I){L((U.negative|I.negative)===0,"red works only with positives"),L(U.red&&U.red===I.red,"red works only with red numbers")},u.prototype.imod=function(U){if(this.prime)return this.prime.ireduce(U)._forceRed(this);return U.umod(this.m)._forceRed(this)},u.prototype.neg=function(U){if(U.isZero())return U.clone();return this.m.sub(U)._forceRed(this)},u.prototype.add=function(U,I){this._verify2(U,I);var Q=U.add(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q._forceRed(this)},u.prototype.iadd=function(U,I){this._verify2(U,I);var Q=U.iadd(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q},u.prototype.sub=function(U,I){this._verify2(U,I);var Q=U.sub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q._forceRed(this)},u.prototype.isub=function(U,I){this._verify2(U,I);var Q=U.isub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q},u.prototype.shl=function(U,I){return this._verify1(U),this.imod(U.ushln(I))},u.prototype.imul=function(U,I){return this._verify2(U,I),this.imod(U.imul(I))},u.prototype.mul=function(U,I){return this._verify2(U,I),this.imod(U.mul(I))},u.prototype.isqr=function(U){return this.imul(U,U.clone())},u.prototype.sqr=function(U){return this.mul(U,U)},u.prototype.sqrt=function(U){if(U.isZero())return U.clone();var I=this.m.andln(3);if(L(I%2===1),I===3){var Q=this.m.add(new O(1)).iushrn(2);return this.pow(U,Q)}var X=this.m.subn(1),Z=0;while(!X.isZero()&&X.andln(1)===0)Z++,X.iushrn(1);L(!X.isZero());var A=new O(1).toRed(this),$=A.redNeg(),J=this.m.subn(1).iushrn(1),E=this.m.bitLength();E=new O(2*E*E).toRed(this);while(this.pow(E,J).cmp($)!==0)E.redIAdd($);var V=this.pow(E,X),S=this.pow(U,X.addn(1).iushrn(1)),H=this.pow(U,X),j=Z;while(H.cmp(A)!==0){var w=H;for(var p=0;w.cmp(A)!==0;p++)w=w.redSqr();L(p=0;Z--){var V=I.words[Z];for(var S=E-1;S>=0;S--){var H=V>>S&1;if(A!==X[0])A=this.sqr(A);if(H===0&&$===0){J=0;continue}if($<<=1,$|=H,J++,J!==Q&&(Z!==0||S!==0))continue;A=this.mul(A,X[$]),J=0,$=0}E=26}return A},u.prototype.convertTo=function(U){var I=U.umod(this.m);return I===U?I.clone():I},u.prototype.convertFrom=function(U){var I=U.clone();return I.red=null,I},O.mont=function(U){return new i(U)};function i(U){if(u.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new O(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}W(i,u),i.prototype.convertTo=function(U){return this.imod(U.ushln(this.shift))},i.prototype.convertFrom=function(U){var I=this.imod(U.mul(this.rinv));return I.red=null,I},i.prototype.imul=function(U,I){if(U.isZero()||I.isZero())return U.words[0]=0,U.length=1,U;var Q=U.imul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.mul=function(U,I){if(U.isZero()||I.isZero())return new O(0)._forceRed(this);var Q=U.mul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.invm=function(U){var I=this.imod(U._invmp(this.m).mul(this.r2));return I._forceRed(this)}})(typeof Y>"u"||Y,T)}),LQ=Q0((T,Y)=>{var G=VQ(),K=AQ();Y.exports=function(z){return new W(z)};var L={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};L.p224=L.secp224r1,L.p256=L.secp256r1=L.prime256v1,L.p192=L.secp192r1=L.prime192v1,L.p384=L.secp384r1,L.p521=L.secp521r1;function W(z){if(this.curveType=L[z],!this.curveType)this.curveType={name:z};this.curve=new G.ec(this.curveType.name),this.keys=void 0}W.prototype.generateKeys=function(z,q){return this.keys=this.curve.genKeyPair(),this.getPublicKey(z,q)},W.prototype.computeSecret=function(z,q,D){if(q=q||"utf8",!Buffer.isBuffer(z))z=new Buffer(z,q);var C=this.curve.keyFromPublic(z).getPublic(),F=C.mul(this.keys.getPrivate()).getX();return O(F,D,this.curveType.byteLength)},W.prototype.getPublicKey=function(z,q){var D=this.keys.getPublic(q==="compressed",!0);if(q==="hybrid")if(D[D.length-1]%2)D[0]=7;else D[0]=6;return O(D,z)},W.prototype.getPrivateKey=function(z){return O(this.keys.getPrivate(),z)},W.prototype.setPublicKey=function(z,q){if(q=q||"utf8",!Buffer.isBuffer(z))z=new Buffer(z,q);return this.keys._importPublic(z),this},W.prototype.setPrivateKey=function(z,q){if(q=q||"utf8",!Buffer.isBuffer(z))z=new Buffer(z,q);var D=new K(z);return D=D.toString(16),this.keys=this.curve.genKeyPair(),this.keys._importPrivate(D),this};function O(z,q,D){if(!Array.isArray(z))z=z.toArray();var C=new Buffer(z);if(D&&C.length{var G=(DU(),h0(PU)).createECDH;Y.exports=G||LQ()}),KQ=Q0((T,Y)=>{(function(G,K){function L(U,I){if(!U)throw Error(I||"Assertion failed")}function W(U,I){U.super_=I;var Q=function(){};Q.prototype=I.prototype,U.prototype=new Q,U.prototype.constructor=U}function O(U,I,Q){if(O.isBN(U))return U;if(this.negative=0,this.words=null,this.length=0,this.red=null,U!==null){if(I==="le"||I==="be")Q=I,I=10;this._init(U||0,I||10,Q||"be")}}if(typeof G==="object")G.exports=O;else K.BN=O;O.BN=O,O.wordSize=26;var z;try{if(typeof window<"u"&&typeof window.Buffer<"u")z=window.Buffer;else z=(FU(),h0(KU)).Buffer}catch(U){}O.isBN=function(U){if(U instanceof O)return!0;return U!==null&&typeof U==="object"&&U.constructor.wordSize===O.wordSize&&Array.isArray(U.words)},O.max=function(U,I){if(U.cmp(I)>0)return U;return I},O.min=function(U,I){if(U.cmp(I)<0)return U;return I},O.prototype._init=function(U,I,Q){if(typeof U==="number")return this._initNumber(U,I,Q);if(typeof U==="object")return this._initArray(U,I,Q);if(I==="hex")I=16;L(I===(I|0)&&I>=2&&I<=36),U=U.toString().replace(/\s+/g,"");var X=0;if(U[0]==="-")X++,this.negative=1;if(X=0;X-=3)if(A=U[X]|U[X-1]<<8|U[X-2]<<16,this.words[Z]|=A<<$&67108863,this.words[Z+1]=A>>>26-$&67108863,$+=24,$>=26)$-=26,Z++}else if(Q==="le"){for(X=0,Z=0;X>>26-$&67108863,$+=24,$>=26)$-=26,Z++}return this.strip()};function q(U,I){var Q=U.charCodeAt(I);if(Q>=65&&Q<=70)return Q-55;else if(Q>=97&&Q<=102)return Q-87;else return Q-48&15}function D(U,I,Q){var X=q(U,Q);if(Q-1>=I)X|=q(U,Q-1)<<4;return X}O.prototype._parseHex=function(U,I,Q){this.length=Math.ceil((U.length-I)/6),this.words=Array(this.length);for(var X=0;X=I;X-=2)if($=D(U,I,X)<=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8;else{var J=U.length-I;for(X=J%2===0?I+1:I;X=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8}this.strip()};function C(U,I,Q,X){var Z=0,A=Math.min(U.length,Q);for(var $=I;$=49)Z+=J-49+10;else if(J>=17)Z+=J-17+10;else Z+=J}return Z}O.prototype._parseBase=function(U,I,Q){this.words=[0],this.length=1;for(var X=0,Z=1;Z<=67108863;Z*=I)X++;X--,Z=Z/I|0;var A=U.length-Q,$=A%X,J=Math.min(A,A-$)+Q,E=0;for(var V=Q;V1&&this.words[this.length-1]===0)this.length--;return this._normSign()},O.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},O.prototype.inspect=function(){return(this.red?""};var F=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],R=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],M=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(O.prototype.toString=function(U,I){U=U||10,I=I|0||1;var Q;if(U===16||U==="hex"){Q="";var X=0,Z=0;for(var A=0;A>>24-X&16777215,X+=2,X>=26)X-=26,A--;if(Z!==0||A!==this.length-1)Q=F[6-J.length]+J+Q;else Q=J+Q}if(Z!==0)Q=Z.toString(16)+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}if(U===(U|0)&&U>=2&&U<=36){var E=R[U],V=M[U];Q="";var S=this.clone();S.negative=0;while(!S.isZero()){var H=S.modn(V).toString(U);if(S=S.idivn(V),!S.isZero())Q=F[E-H.length]+H+Q;else Q=H+Q}if(this.isZero())Q="0"+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}L(!1,"Base should be between 2 and 36")},O.prototype.toNumber=function(){var U=this.words[0];if(this.length===2)U+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)U+=4503599627370496+this.words[1]*67108864;else if(this.length>2)L(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-U:U},O.prototype.toJSON=function(){return this.toString(16)},O.prototype.toBuffer=function(U,I){return L(typeof z<"u"),this.toArrayLike(z,U,I)},O.prototype.toArray=function(U,I){return this.toArrayLike(Array,U,I)},O.prototype.toArrayLike=function(U,I,Q){var X=this.byteLength(),Z=Q||Math.max(1,X);L(X<=Z,"byte array longer than desired length"),L(Z>0,"Requested array length <= 0"),this.strip();var A=I==="le",$=new U(Z),J,E,V=this.clone();if(!A){for(E=0;E=4096)Q+=13,I>>>=13;if(I>=64)Q+=7,I>>>=7;if(I>=8)Q+=4,I>>>=4;if(I>=2)Q+=2,I>>>=2;return Q+I};O.prototype._zeroBits=function(U){if(U===0)return 26;var I=U,Q=0;if((I&8191)===0)Q+=13,I>>>=13;if((I&127)===0)Q+=7,I>>>=7;if((I&15)===0)Q+=4,I>>>=4;if((I&3)===0)Q+=2,I>>>=2;if((I&1)===0)Q++;return Q},O.prototype.bitLength=function(){var U=this.words[this.length-1],I=this._countBits(U);return(this.length-1)*26+I};function P(U){var I=Array(U.bitLength());for(var Q=0;Q>>Z}return I}O.prototype.zeroBits=function(){if(this.isZero())return 0;var U=0;for(var I=0;IU.length)return this.clone().ior(U);return U.clone().ior(this)},O.prototype.uor=function(U){if(this.length>U.length)return this.clone().iuor(U);return U.clone().iuor(this)},O.prototype.iuand=function(U){var I;if(this.length>U.length)I=U;else I=this;for(var Q=0;QU.length)return this.clone().iand(U);return U.clone().iand(this)},O.prototype.uand=function(U){if(this.length>U.length)return this.clone().iuand(U);return U.clone().iuand(this)},O.prototype.iuxor=function(U){var I,Q;if(this.length>U.length)I=this,Q=U;else I=U,Q=this;for(var X=0;XU.length)return this.clone().ixor(U);return U.clone().ixor(this)},O.prototype.uxor=function(U){if(this.length>U.length)return this.clone().iuxor(U);return U.clone().iuxor(this)},O.prototype.inotn=function(U){L(typeof U==="number"&&U>=0);var I=Math.ceil(U/26)|0,Q=U%26;if(this._expand(I),Q>0)I--;for(var X=0;X0)this.words[X]=~this.words[X]&67108863>>26-Q;return this.strip()},O.prototype.notn=function(U){return this.clone().inotn(U)},O.prototype.setn=function(U,I){L(typeof U==="number"&&U>=0);var Q=U/26|0,X=U%26;if(this._expand(Q+1),I)this.words[Q]=this.words[Q]|1<U.length)Q=this,X=U;else Q=U,X=this;var Z=0;for(var A=0;A>>26;for(;Z!==0&&A>>26;if(this.length=Q.length,Z!==0)this.words[this.length]=Z,this.length++;else if(Q!==this)for(;AU.length)return this.clone().iadd(U);return U.clone().iadd(this)},O.prototype.isub=function(U){if(U.negative!==0){U.negative=0;var I=this.iadd(U);return U.negative=1,I._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(U),this.negative=1,this._normSign();var Q=this.cmp(U);if(Q===0)return this.negative=0,this.length=1,this.words[0]=0,this;var X,Z;if(Q>0)X=this,Z=U;else X=U,Z=this;var A=0;for(var $=0;$>26,this.words[$]=I&67108863;for(;A!==0&&$>26,this.words[$]=I&67108863;if(A===0&&$>>26,H=E&67108863,j=Math.min(V,I.length-1);for(var w=Math.max(0,V-U.length+1);w<=j;w++){var p=V-w|0;Z=U.words[p]|0,A=I.words[w]|0,$=Z*A+H,S+=$/67108864|0,H=$&67108863}Q.words[V]=H|0,E=S|0}if(E!==0)Q.words[V]=E|0;else Q.length--;return Q.strip()}var _=function(U,I,Q){var X=U.words,Z=I.words,A=Q.words,$=0,J,E,V,S=X[0]|0,H=S&8191,j=S>>>13,w=X[1]|0,p=w&8191,n=w>>>13,G0=X[2]|0,t=G0&8191,d=G0>>>13,I0=X[3]|0,m=I0&8191,U0=I0>>>13,g0=X[4]|0,f=g0&8191,h=g0>>>13,T0=X[5]|0,r=T0&8191,e=T0>>>13,C0=X[6]|0,c=C0&8191,o=C0>>>13,x0=X[7]|0,s=x0&8191,X0=x0>>>13,y0=X[8]|0,L0=y0&8191,$0=y0>>>13,n0=X[9]|0,V0=n0&8191,K0=n0>>>13,r0=Z[0]|0,H0=r0&8191,W0=r0>>>13,RU=Z[1]|0,D0=RU&8191,_0=RU>>>13,CU=Z[2]|0,k0=CU&8191,z0=CU>>>13,WU=Z[3]|0,v0=WU&8191,S0=WU>>>13,AU=Z[4]|0,j0=AU&8191,N0=AU>>>13,LU=Z[5]|0,M0=LU&8191,x=LU>>>13,b=Z[6]|0,a=b&8191,E0=b>>>13,w0=Z[7]|0,A0=w0&8191,F0=w0>>>13,m0=Z[8]|0,q0=m0&8191,B0=m0>>>13,HU=Z[9]|0,P0=HU&8191,R0=HU>>>13;Q.negative=U.negative^I.negative,Q.length=19,J=Math.imul(H,H0),E=Math.imul(H,W0),E=E+Math.imul(j,H0)|0,V=Math.imul(j,W0);var s0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(s0>>>26)|0,s0&=67108863,J=Math.imul(p,H0),E=Math.imul(p,W0),E=E+Math.imul(n,H0)|0,V=Math.imul(n,W0),J=J+Math.imul(H,D0)|0,E=E+Math.imul(H,_0)|0,E=E+Math.imul(j,D0)|0,V=V+Math.imul(j,_0)|0;var c0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(c0>>>26)|0,c0&=67108863,J=Math.imul(t,H0),E=Math.imul(t,W0),E=E+Math.imul(d,H0)|0,V=Math.imul(d,W0),J=J+Math.imul(p,D0)|0,E=E+Math.imul(p,_0)|0,E=E+Math.imul(n,D0)|0,V=V+Math.imul(n,_0)|0,J=J+Math.imul(H,k0)|0,E=E+Math.imul(H,z0)|0,E=E+Math.imul(j,k0)|0,V=V+Math.imul(j,z0)|0;var f0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(f0>>>26)|0,f0&=67108863,J=Math.imul(m,H0),E=Math.imul(m,W0),E=E+Math.imul(U0,H0)|0,V=Math.imul(U0,W0),J=J+Math.imul(t,D0)|0,E=E+Math.imul(t,_0)|0,E=E+Math.imul(d,D0)|0,V=V+Math.imul(d,_0)|0,J=J+Math.imul(p,k0)|0,E=E+Math.imul(p,z0)|0,E=E+Math.imul(n,k0)|0,V=V+Math.imul(n,z0)|0,J=J+Math.imul(H,v0)|0,E=E+Math.imul(H,S0)|0,E=E+Math.imul(j,v0)|0,V=V+Math.imul(j,S0)|0;var d0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(d0>>>26)|0,d0&=67108863,J=Math.imul(f,H0),E=Math.imul(f,W0),E=E+Math.imul(h,H0)|0,V=Math.imul(h,W0),J=J+Math.imul(m,D0)|0,E=E+Math.imul(m,_0)|0,E=E+Math.imul(U0,D0)|0,V=V+Math.imul(U0,_0)|0,J=J+Math.imul(t,k0)|0,E=E+Math.imul(t,z0)|0,E=E+Math.imul(d,k0)|0,V=V+Math.imul(d,z0)|0,J=J+Math.imul(p,v0)|0,E=E+Math.imul(p,S0)|0,E=E+Math.imul(n,v0)|0,V=V+Math.imul(n,S0)|0,J=J+Math.imul(H,j0)|0,E=E+Math.imul(H,N0)|0,E=E+Math.imul(j,j0)|0,V=V+Math.imul(j,N0)|0;var b0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(b0>>>26)|0,b0&=67108863,J=Math.imul(r,H0),E=Math.imul(r,W0),E=E+Math.imul(e,H0)|0,V=Math.imul(e,W0),J=J+Math.imul(f,D0)|0,E=E+Math.imul(f,_0)|0,E=E+Math.imul(h,D0)|0,V=V+Math.imul(h,_0)|0,J=J+Math.imul(m,k0)|0,E=E+Math.imul(m,z0)|0,E=E+Math.imul(U0,k0)|0,V=V+Math.imul(U0,z0)|0,J=J+Math.imul(t,v0)|0,E=E+Math.imul(t,S0)|0,E=E+Math.imul(d,v0)|0,V=V+Math.imul(d,S0)|0,J=J+Math.imul(p,j0)|0,E=E+Math.imul(p,N0)|0,E=E+Math.imul(n,j0)|0,V=V+Math.imul(n,N0)|0,J=J+Math.imul(H,M0)|0,E=E+Math.imul(H,x)|0,E=E+Math.imul(j,M0)|0,V=V+Math.imul(j,x)|0;var t0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(t0>>>26)|0,t0&=67108863,J=Math.imul(c,H0),E=Math.imul(c,W0),E=E+Math.imul(o,H0)|0,V=Math.imul(o,W0),J=J+Math.imul(r,D0)|0,E=E+Math.imul(r,_0)|0,E=E+Math.imul(e,D0)|0,V=V+Math.imul(e,_0)|0,J=J+Math.imul(f,k0)|0,E=E+Math.imul(f,z0)|0,E=E+Math.imul(h,k0)|0,V=V+Math.imul(h,z0)|0,J=J+Math.imul(m,v0)|0,E=E+Math.imul(m,S0)|0,E=E+Math.imul(U0,v0)|0,V=V+Math.imul(U0,S0)|0,J=J+Math.imul(t,j0)|0,E=E+Math.imul(t,N0)|0,E=E+Math.imul(d,j0)|0,V=V+Math.imul(d,N0)|0,J=J+Math.imul(p,M0)|0,E=E+Math.imul(p,x)|0,E=E+Math.imul(n,M0)|0,V=V+Math.imul(n,x)|0,J=J+Math.imul(H,a)|0,E=E+Math.imul(H,E0)|0,E=E+Math.imul(j,a)|0,V=V+Math.imul(j,E0)|0;var a0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(a0>>>26)|0,a0&=67108863,J=Math.imul(s,H0),E=Math.imul(s,W0),E=E+Math.imul(X0,H0)|0,V=Math.imul(X0,W0),J=J+Math.imul(c,D0)|0,E=E+Math.imul(c,_0)|0,E=E+Math.imul(o,D0)|0,V=V+Math.imul(o,_0)|0,J=J+Math.imul(r,k0)|0,E=E+Math.imul(r,z0)|0,E=E+Math.imul(e,k0)|0,V=V+Math.imul(e,z0)|0,J=J+Math.imul(f,v0)|0,E=E+Math.imul(f,S0)|0,E=E+Math.imul(h,v0)|0,V=V+Math.imul(h,S0)|0,J=J+Math.imul(m,j0)|0,E=E+Math.imul(m,N0)|0,E=E+Math.imul(U0,j0)|0,V=V+Math.imul(U0,N0)|0,J=J+Math.imul(t,M0)|0,E=E+Math.imul(t,x)|0,E=E+Math.imul(d,M0)|0,V=V+Math.imul(d,x)|0,J=J+Math.imul(p,a)|0,E=E+Math.imul(p,E0)|0,E=E+Math.imul(n,a)|0,V=V+Math.imul(n,E0)|0,J=J+Math.imul(H,A0)|0,E=E+Math.imul(H,F0)|0,E=E+Math.imul(j,A0)|0,V=V+Math.imul(j,F0)|0;var e0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(e0>>>26)|0,e0&=67108863,J=Math.imul(L0,H0),E=Math.imul(L0,W0),E=E+Math.imul($0,H0)|0,V=Math.imul($0,W0),J=J+Math.imul(s,D0)|0,E=E+Math.imul(s,_0)|0,E=E+Math.imul(X0,D0)|0,V=V+Math.imul(X0,_0)|0,J=J+Math.imul(c,k0)|0,E=E+Math.imul(c,z0)|0,E=E+Math.imul(o,k0)|0,V=V+Math.imul(o,z0)|0,J=J+Math.imul(r,v0)|0,E=E+Math.imul(r,S0)|0,E=E+Math.imul(e,v0)|0,V=V+Math.imul(e,S0)|0,J=J+Math.imul(f,j0)|0,E=E+Math.imul(f,N0)|0,E=E+Math.imul(h,j0)|0,V=V+Math.imul(h,N0)|0,J=J+Math.imul(m,M0)|0,E=E+Math.imul(m,x)|0,E=E+Math.imul(U0,M0)|0,V=V+Math.imul(U0,x)|0,J=J+Math.imul(t,a)|0,E=E+Math.imul(t,E0)|0,E=E+Math.imul(d,a)|0,V=V+Math.imul(d,E0)|0,J=J+Math.imul(p,A0)|0,E=E+Math.imul(p,F0)|0,E=E+Math.imul(n,A0)|0,V=V+Math.imul(n,F0)|0,J=J+Math.imul(H,q0)|0,E=E+Math.imul(H,B0)|0,E=E+Math.imul(j,q0)|0,V=V+Math.imul(j,B0)|0;var i0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(i0>>>26)|0,i0&=67108863,J=Math.imul(V0,H0),E=Math.imul(V0,W0),E=E+Math.imul(K0,H0)|0,V=Math.imul(K0,W0),J=J+Math.imul(L0,D0)|0,E=E+Math.imul(L0,_0)|0,E=E+Math.imul($0,D0)|0,V=V+Math.imul($0,_0)|0,J=J+Math.imul(s,k0)|0,E=E+Math.imul(s,z0)|0,E=E+Math.imul(X0,k0)|0,V=V+Math.imul(X0,z0)|0,J=J+Math.imul(c,v0)|0,E=E+Math.imul(c,S0)|0,E=E+Math.imul(o,v0)|0,V=V+Math.imul(o,S0)|0,J=J+Math.imul(r,j0)|0,E=E+Math.imul(r,N0)|0,E=E+Math.imul(e,j0)|0,V=V+Math.imul(e,N0)|0,J=J+Math.imul(f,M0)|0,E=E+Math.imul(f,x)|0,E=E+Math.imul(h,M0)|0,V=V+Math.imul(h,x)|0,J=J+Math.imul(m,a)|0,E=E+Math.imul(m,E0)|0,E=E+Math.imul(U0,a)|0,V=V+Math.imul(U0,E0)|0,J=J+Math.imul(t,A0)|0,E=E+Math.imul(t,F0)|0,E=E+Math.imul(d,A0)|0,V=V+Math.imul(d,F0)|0,J=J+Math.imul(p,q0)|0,E=E+Math.imul(p,B0)|0,E=E+Math.imul(n,q0)|0,V=V+Math.imul(n,B0)|0,J=J+Math.imul(H,P0)|0,E=E+Math.imul(H,R0)|0,E=E+Math.imul(j,P0)|0,V=V+Math.imul(j,R0)|0;var UU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(UU>>>26)|0,UU&=67108863,J=Math.imul(V0,D0),E=Math.imul(V0,_0),E=E+Math.imul(K0,D0)|0,V=Math.imul(K0,_0),J=J+Math.imul(L0,k0)|0,E=E+Math.imul(L0,z0)|0,E=E+Math.imul($0,k0)|0,V=V+Math.imul($0,z0)|0,J=J+Math.imul(s,v0)|0,E=E+Math.imul(s,S0)|0,E=E+Math.imul(X0,v0)|0,V=V+Math.imul(X0,S0)|0,J=J+Math.imul(c,j0)|0,E=E+Math.imul(c,N0)|0,E=E+Math.imul(o,j0)|0,V=V+Math.imul(o,N0)|0,J=J+Math.imul(r,M0)|0,E=E+Math.imul(r,x)|0,E=E+Math.imul(e,M0)|0,V=V+Math.imul(e,x)|0,J=J+Math.imul(f,a)|0,E=E+Math.imul(f,E0)|0,E=E+Math.imul(h,a)|0,V=V+Math.imul(h,E0)|0,J=J+Math.imul(m,A0)|0,E=E+Math.imul(m,F0)|0,E=E+Math.imul(U0,A0)|0,V=V+Math.imul(U0,F0)|0,J=J+Math.imul(t,q0)|0,E=E+Math.imul(t,B0)|0,E=E+Math.imul(d,q0)|0,V=V+Math.imul(d,B0)|0,J=J+Math.imul(p,P0)|0,E=E+Math.imul(p,R0)|0,E=E+Math.imul(n,P0)|0,V=V+Math.imul(n,R0)|0;var EU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(EU>>>26)|0,EU&=67108863,J=Math.imul(V0,k0),E=Math.imul(V0,z0),E=E+Math.imul(K0,k0)|0,V=Math.imul(K0,z0),J=J+Math.imul(L0,v0)|0,E=E+Math.imul(L0,S0)|0,E=E+Math.imul($0,v0)|0,V=V+Math.imul($0,S0)|0,J=J+Math.imul(s,j0)|0,E=E+Math.imul(s,N0)|0,E=E+Math.imul(X0,j0)|0,V=V+Math.imul(X0,N0)|0,J=J+Math.imul(c,M0)|0,E=E+Math.imul(c,x)|0,E=E+Math.imul(o,M0)|0,V=V+Math.imul(o,x)|0,J=J+Math.imul(r,a)|0,E=E+Math.imul(r,E0)|0,E=E+Math.imul(e,a)|0,V=V+Math.imul(e,E0)|0,J=J+Math.imul(f,A0)|0,E=E+Math.imul(f,F0)|0,E=E+Math.imul(h,A0)|0,V=V+Math.imul(h,F0)|0,J=J+Math.imul(m,q0)|0,E=E+Math.imul(m,B0)|0,E=E+Math.imul(U0,q0)|0,V=V+Math.imul(U0,B0)|0,J=J+Math.imul(t,P0)|0,E=E+Math.imul(t,R0)|0,E=E+Math.imul(d,P0)|0,V=V+Math.imul(d,R0)|0;var XU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(XU>>>26)|0,XU&=67108863,J=Math.imul(V0,v0),E=Math.imul(V0,S0),E=E+Math.imul(K0,v0)|0,V=Math.imul(K0,S0),J=J+Math.imul(L0,j0)|0,E=E+Math.imul(L0,N0)|0,E=E+Math.imul($0,j0)|0,V=V+Math.imul($0,N0)|0,J=J+Math.imul(s,M0)|0,E=E+Math.imul(s,x)|0,E=E+Math.imul(X0,M0)|0,V=V+Math.imul(X0,x)|0,J=J+Math.imul(c,a)|0,E=E+Math.imul(c,E0)|0,E=E+Math.imul(o,a)|0,V=V+Math.imul(o,E0)|0,J=J+Math.imul(r,A0)|0,E=E+Math.imul(r,F0)|0,E=E+Math.imul(e,A0)|0,V=V+Math.imul(e,F0)|0,J=J+Math.imul(f,q0)|0,E=E+Math.imul(f,B0)|0,E=E+Math.imul(h,q0)|0,V=V+Math.imul(h,B0)|0,J=J+Math.imul(m,P0)|0,E=E+Math.imul(m,R0)|0,E=E+Math.imul(U0,P0)|0,V=V+Math.imul(U0,R0)|0;var IU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(IU>>>26)|0,IU&=67108863,J=Math.imul(V0,j0),E=Math.imul(V0,N0),E=E+Math.imul(K0,j0)|0,V=Math.imul(K0,N0),J=J+Math.imul(L0,M0)|0,E=E+Math.imul(L0,x)|0,E=E+Math.imul($0,M0)|0,V=V+Math.imul($0,x)|0,J=J+Math.imul(s,a)|0,E=E+Math.imul(s,E0)|0,E=E+Math.imul(X0,a)|0,V=V+Math.imul(X0,E0)|0,J=J+Math.imul(c,A0)|0,E=E+Math.imul(c,F0)|0,E=E+Math.imul(o,A0)|0,V=V+Math.imul(o,F0)|0,J=J+Math.imul(r,q0)|0,E=E+Math.imul(r,B0)|0,E=E+Math.imul(e,q0)|0,V=V+Math.imul(e,B0)|0,J=J+Math.imul(f,P0)|0,E=E+Math.imul(f,R0)|0,E=E+Math.imul(h,P0)|0,V=V+Math.imul(h,R0)|0;var TU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(TU>>>26)|0,TU&=67108863,J=Math.imul(V0,M0),E=Math.imul(V0,x),E=E+Math.imul(K0,M0)|0,V=Math.imul(K0,x),J=J+Math.imul(L0,a)|0,E=E+Math.imul(L0,E0)|0,E=E+Math.imul($0,a)|0,V=V+Math.imul($0,E0)|0,J=J+Math.imul(s,A0)|0,E=E+Math.imul(s,F0)|0,E=E+Math.imul(X0,A0)|0,V=V+Math.imul(X0,F0)|0,J=J+Math.imul(c,q0)|0,E=E+Math.imul(c,B0)|0,E=E+Math.imul(o,q0)|0,V=V+Math.imul(o,B0)|0,J=J+Math.imul(r,P0)|0,E=E+Math.imul(r,R0)|0,E=E+Math.imul(e,P0)|0,V=V+Math.imul(e,R0)|0;var YU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(YU>>>26)|0,YU&=67108863,J=Math.imul(V0,a),E=Math.imul(V0,E0),E=E+Math.imul(K0,a)|0,V=Math.imul(K0,E0),J=J+Math.imul(L0,A0)|0,E=E+Math.imul(L0,F0)|0,E=E+Math.imul($0,A0)|0,V=V+Math.imul($0,F0)|0,J=J+Math.imul(s,q0)|0,E=E+Math.imul(s,B0)|0,E=E+Math.imul(X0,q0)|0,V=V+Math.imul(X0,B0)|0,J=J+Math.imul(c,P0)|0,E=E+Math.imul(c,R0)|0,E=E+Math.imul(o,P0)|0,V=V+Math.imul(o,R0)|0;var ZU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(ZU>>>26)|0,ZU&=67108863,J=Math.imul(V0,A0),E=Math.imul(V0,F0),E=E+Math.imul(K0,A0)|0,V=Math.imul(K0,F0),J=J+Math.imul(L0,q0)|0,E=E+Math.imul(L0,B0)|0,E=E+Math.imul($0,q0)|0,V=V+Math.imul($0,B0)|0,J=J+Math.imul(s,P0)|0,E=E+Math.imul(s,R0)|0,E=E+Math.imul(X0,P0)|0,V=V+Math.imul(X0,R0)|0;var OU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(OU>>>26)|0,OU&=67108863,J=Math.imul(V0,q0),E=Math.imul(V0,B0),E=E+Math.imul(K0,q0)|0,V=Math.imul(K0,B0),J=J+Math.imul(L0,P0)|0,E=E+Math.imul(L0,R0)|0,E=E+Math.imul($0,P0)|0,V=V+Math.imul($0,R0)|0;var QU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(QU>>>26)|0,QU&=67108863,J=Math.imul(V0,P0),E=Math.imul(V0,R0),E=E+Math.imul(K0,P0)|0,V=Math.imul(K0,R0);var JU=($+J|0)+((E&8191)<<13)|0;if($=(V+(E>>>13)|0)+(JU>>>26)|0,JU&=67108863,A[0]=s0,A[1]=c0,A[2]=f0,A[3]=d0,A[4]=b0,A[5]=t0,A[6]=a0,A[7]=e0,A[8]=i0,A[9]=UU,A[10]=EU,A[11]=XU,A[12]=IU,A[13]=TU,A[14]=YU,A[15]=ZU,A[16]=OU,A[17]=QU,A[18]=JU,$!==0)A[19]=$,Q.length++;return Q};if(!Math.imul)_=k;function N(U,I,Q){Q.negative=I.negative^U.negative,Q.length=U.length+I.length;var X=0,Z=0;for(var A=0;A>>26)|0,Z+=$>>>26,$&=67108863}Q.words[A]=J,X=$,$=Z}if(X!==0)Q.words[A]=X;else Q.length--;return Q.strip()}function v(U,I,Q){var X=new B;return X.mulp(U,I,Q)}O.prototype.mulTo=function(U,I){var Q,X=this.length+U.length;if(this.length===10&&U.length===10)Q=_(this,U,I);else if(X<63)Q=k(this,U,I);else if(X<1024)Q=N(this,U,I);else Q=v(this,U,I);return Q};function B(U,I){this.x=U,this.y=I}B.prototype.makeRBT=function(U){var I=Array(U),Q=O.prototype._countBits(U)-1;for(var X=0;X>=1;return X},B.prototype.permute=function(U,I,Q,X,Z,A){for(var $=0;$>>1)Z++;return 1<>>13,Q[2*A+1]=Z&8191,Z=Z>>>13;for(A=2*I;A>=26,I+=X/67108864|0,I+=Z>>>26,this.words[Q]=Z&67108863}if(I!==0)this.words[Q]=I,this.length++;return this.length=U===0?1:this.length,this},O.prototype.muln=function(U){return this.clone().imuln(U)},O.prototype.sqr=function(){return this.mul(this)},O.prototype.isqr=function(){return this.imul(this.clone())},O.prototype.pow=function(U){var I=P(U);if(I.length===0)return new O(1);var Q=this;for(var X=0;X=0);var I=U%26,Q=(U-I)/26,X=67108863>>>26-I<<26-I,Z;if(I!==0){var A=0;for(Z=0;Z>>26-I}if(A)this.words[Z]=A,this.length++}if(Q!==0){for(Z=this.length-1;Z>=0;Z--)this.words[Z+Q]=this.words[Z];for(Z=0;Z=0);var X;if(I)X=(I-I%26)/26;else X=0;var Z=U%26,A=Math.min((U-Z)/26,this.length),$=67108863^67108863>>>Z<A){this.length-=A;for(E=0;E=0&&(V!==0||E>=X);E--){var S=this.words[E]|0;this.words[E]=V<<26-Z|S>>>Z,V=S&$}if(J&&V!==0)J.words[J.length++]=V;if(this.length===0)this.words[0]=0,this.length=1;return this.strip()},O.prototype.ishrn=function(U,I,Q){return L(this.negative===0),this.iushrn(U,I,Q)},O.prototype.shln=function(U){return this.clone().ishln(U)},O.prototype.ushln=function(U){return this.clone().iushln(U)},O.prototype.shrn=function(U){return this.clone().ishrn(U)},O.prototype.ushrn=function(U){return this.clone().iushrn(U)},O.prototype.testn=function(U){L(typeof U==="number"&&U>=0);var I=U%26,Q=(U-I)/26,X=1<=0);var I=U%26,Q=(U-I)/26;if(L(this.negative===0,"imaskn works only with positive numbers"),this.length<=Q)return this;if(I!==0)Q++;if(this.length=Math.min(Q,this.length),I!==0){var X=67108863^67108863>>>I<=67108864;I++)if(this.words[I]-=67108864,I===this.length-1)this.words[I+1]=1;else this.words[I+1]++;return this.length=Math.max(this.length,I+1),this},O.prototype.isubn=function(U){if(L(typeof U==="number"),L(U<67108864),U<0)return this.iaddn(-U);if(this.negative!==0)return this.negative=0,this.iaddn(U),this.negative=1,this;if(this.words[0]-=U,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var I=0;I>26)-(J/67108864|0),this.words[Z+Q]=A&67108863}for(;Z>26,this.words[Z+Q]=A&67108863;if($===0)return this.strip();L($===-1),$=0;for(Z=0;Z>26,this.words[Z]=A&67108863;return this.negative=1,this.strip()},O.prototype._wordDiv=function(U,I){var Q=this.length-U.length,X=this.clone(),Z=U,A=Z.words[Z.length-1]|0,$=this._countBits(A);if(Q=26-$,Q!==0)Z=Z.ushln(Q),X.iushln(Q),A=Z.words[Z.length-1]|0;var J=X.length-Z.length,E;if(I!=="mod"){E=new O(null),E.length=J+1,E.words=Array(E.length);for(var V=0;V=0;H--){var j=(X.words[Z.length+H]|0)*67108864+(X.words[Z.length+H-1]|0);j=Math.min(j/A|0,67108863),X._ishlnsubmul(Z,j,H);while(X.negative!==0)if(j--,X.negative=0,X._ishlnsubmul(Z,1,H),!X.isZero())X.negative^=1;if(E)E.words[H]=j}if(E)E.strip();if(X.strip(),I!=="div"&&Q!==0)X.iushrn(Q);return{div:E||null,mod:X}},O.prototype.divmod=function(U,I,Q){if(L(!U.isZero()),this.isZero())return{div:new O(0),mod:new O(0)};var X,Z,A;if(this.negative!==0&&U.negative===0){if(A=this.neg().divmod(U,I),I!=="mod")X=A.div.neg();if(I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.iadd(U)}return{div:X,mod:Z}}if(this.negative===0&&U.negative!==0){if(A=this.divmod(U.neg(),I),I!=="mod")X=A.div.neg();return{div:X,mod:A.mod}}if((this.negative&U.negative)!==0){if(A=this.neg().divmod(U.neg(),I),I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.isub(U)}return{div:A.div,mod:Z}}if(U.length>this.length||this.cmp(U)<0)return{div:new O(0),mod:this};if(U.length===1){if(I==="div")return{div:this.divn(U.words[0]),mod:null};if(I==="mod")return{div:null,mod:new O(this.modn(U.words[0]))};return{div:this.divn(U.words[0]),mod:new O(this.modn(U.words[0]))}}return this._wordDiv(U,I)},O.prototype.div=function(U){return this.divmod(U,"div",!1).div},O.prototype.mod=function(U){return this.divmod(U,"mod",!1).mod},O.prototype.umod=function(U){return this.divmod(U,"mod",!0).mod},O.prototype.divRound=function(U){var I=this.divmod(U);if(I.mod.isZero())return I.div;var Q=I.div.negative!==0?I.mod.isub(U):I.mod,X=U.ushrn(1),Z=U.andln(1),A=Q.cmp(X);if(A<0||Z===1&&A===0)return I.div;return I.div.negative!==0?I.div.isubn(1):I.div.iaddn(1)},O.prototype.modn=function(U){L(U<=67108863);var I=67108864%U,Q=0;for(var X=this.length-1;X>=0;X--)Q=(I*Q+(this.words[X]|0))%U;return Q},O.prototype.idivn=function(U){L(U<=67108863);var I=0;for(var Q=this.length-1;Q>=0;Q--){var X=(this.words[Q]|0)+I*67108864;this.words[Q]=X/U|0,I=X%U}return this.strip()},O.prototype.divn=function(U){return this.clone().idivn(U)},O.prototype.egcd=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=new O(0),$=new O(1),J=0;while(I.isEven()&&Q.isEven())I.iushrn(1),Q.iushrn(1),++J;var E=Q.clone(),V=I.clone();while(!I.isZero()){for(var S=0,H=1;(I.words[0]&H)===0&&S<26;++S,H<<=1);if(S>0){I.iushrn(S);while(S-- >0){if(X.isOdd()||Z.isOdd())X.iadd(E),Z.isub(V);X.iushrn(1),Z.iushrn(1)}}for(var j=0,w=1;(Q.words[0]&w)===0&&j<26;++j,w<<=1);if(j>0){Q.iushrn(j);while(j-- >0){if(A.isOdd()||$.isOdd())A.iadd(E),$.isub(V);A.iushrn(1),$.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(A),Z.isub($);else Q.isub(I),A.isub(X),$.isub(Z)}return{a:A,b:$,gcd:Q.iushln(J)}},O.prototype._invmp=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=Q.clone();while(I.cmpn(1)>0&&Q.cmpn(1)>0){for(var $=0,J=1;(I.words[0]&J)===0&&$<26;++$,J<<=1);if($>0){I.iushrn($);while($-- >0){if(X.isOdd())X.iadd(A);X.iushrn(1)}}for(var E=0,V=1;(Q.words[0]&V)===0&&E<26;++E,V<<=1);if(E>0){Q.iushrn(E);while(E-- >0){if(Z.isOdd())Z.iadd(A);Z.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(Z);else Q.isub(I),Z.isub(X)}var S;if(I.cmpn(1)===0)S=X;else S=Z;if(S.cmpn(0)<0)S.iadd(U);return S},O.prototype.gcd=function(U){if(this.isZero())return U.abs();if(U.isZero())return this.abs();var I=this.clone(),Q=U.clone();I.negative=0,Q.negative=0;for(var X=0;I.isEven()&&Q.isEven();X++)I.iushrn(1),Q.iushrn(1);do{while(I.isEven())I.iushrn(1);while(Q.isEven())Q.iushrn(1);var Z=I.cmp(Q);if(Z<0){var A=I;I=Q,Q=A}else if(Z===0||Q.cmpn(1)===0)break;I.isub(Q)}while(!0);return Q.iushln(X)},O.prototype.invm=function(U){return this.egcd(U).a.umod(U)},O.prototype.isEven=function(){return(this.words[0]&1)===0},O.prototype.isOdd=function(){return(this.words[0]&1)===1},O.prototype.andln=function(U){return this.words[0]&U},O.prototype.bincn=function(U){L(typeof U==="number");var I=U%26,Q=(U-I)/26,X=1<>>26,$&=67108863,this.words[A]=$}if(Z!==0)this.words[A]=Z,this.length++;return this},O.prototype.isZero=function(){return this.length===1&&this.words[0]===0},O.prototype.cmpn=function(U){var I=U<0;if(this.negative!==0&&!I)return-1;if(this.negative===0&&I)return 1;this.strip();var Q;if(this.length>1)Q=1;else{if(I)U=-U;L(U<=67108863,"Number is too big");var X=this.words[0]|0;Q=X===U?0:XU.length)return 1;if(this.length=0;Q--){var X=this.words[Q]|0,Z=U.words[Q]|0;if(X===Z)continue;if(XZ)I=1;break}return I},O.prototype.gtn=function(U){return this.cmpn(U)===1},O.prototype.gt=function(U){return this.cmp(U)===1},O.prototype.gten=function(U){return this.cmpn(U)>=0},O.prototype.gte=function(U){return this.cmp(U)>=0},O.prototype.ltn=function(U){return this.cmpn(U)===-1},O.prototype.lt=function(U){return this.cmp(U)===-1},O.prototype.lten=function(U){return this.cmpn(U)<=0},O.prototype.lte=function(U){return this.cmp(U)<=0},O.prototype.eqn=function(U){return this.cmpn(U)===0},O.prototype.eq=function(U){return this.cmp(U)===0},O.red=function(U){return new u(U)},O.prototype.toRed=function(U){return L(!this.red,"Already a number in reduction context"),L(this.negative===0,"red works only with positives"),U.convertTo(this)._forceRed(U)},O.prototype.fromRed=function(){return L(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},O.prototype._forceRed=function(U){return this.red=U,this},O.prototype.forceRed=function(U){return L(!this.red,"Already a number in reduction context"),this._forceRed(U)},O.prototype.redAdd=function(U){return L(this.red,"redAdd works only with red numbers"),this.red.add(this,U)},O.prototype.redIAdd=function(U){return L(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,U)},O.prototype.redSub=function(U){return L(this.red,"redSub works only with red numbers"),this.red.sub(this,U)},O.prototype.redISub=function(U){return L(this.red,"redISub works only with red numbers"),this.red.isub(this,U)},O.prototype.redShl=function(U){return L(this.red,"redShl works only with red numbers"),this.red.shl(this,U)},O.prototype.redMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.mul(this,U)},O.prototype.redIMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.imul(this,U)},O.prototype.redSqr=function(){return L(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},O.prototype.redISqr=function(){return L(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},O.prototype.redSqrt=function(){return L(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},O.prototype.redInvm=function(){return L(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},O.prototype.redNeg=function(){return L(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},O.prototype.redPow=function(U){return L(this.red&&!U.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,U)};var g={k256:null,p224:null,p192:null,p25519:null};function y(U,I){this.name=U,this.p=new O(I,16),this.n=this.p.bitLength(),this.k=new O(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}y.prototype._tmp=function(){var U=new O(null);return U.words=Array(Math.ceil(this.n/13)),U},y.prototype.ireduce=function(U){var I=U,Q;do this.split(I,this.tmp),I=this.imulK(I),I=I.iadd(this.tmp),Q=I.bitLength();while(Q>this.n);var X=Q0)I.isub(this.p);else if(I.strip!==void 0)I.strip();else I._strip();return I},y.prototype.split=function(U,I){U.iushrn(this.n,0,I)},y.prototype.imulK=function(U){return U.imul(this.k)};function l(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}W(l,y),l.prototype.split=function(U,I){var Q=4194303,X=Math.min(U.length,9);for(var Z=0;Z>>22,A=$}if(A>>>=22,U.words[Z-10]=A,A===0&&U.length>10)U.length-=10;else U.length-=9},l.prototype.imulK=function(U){U.words[U.length]=0,U.words[U.length+1]=0,U.length+=2;var I=0;for(var Q=0;Q>>=26,U.words[Q]=Z,I=X}if(I!==0)U.words[U.length++]=I;return U},O._prime=function(U){if(g[U])return g[U];var I;if(U==="k256")I=new l;else if(U==="p224")I=new Y0;else if(U==="p192")I=new O0;else if(U==="p25519")I=new Z0;else throw Error("Unknown prime "+U);return g[U]=I,I};function u(U){if(typeof U==="string"){var I=O._prime(U);this.m=I.p,this.prime=I}else L(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}u.prototype._verify1=function(U){L(U.negative===0,"red works only with positives"),L(U.red,"red works only with red numbers")},u.prototype._verify2=function(U,I){L((U.negative|I.negative)===0,"red works only with positives"),L(U.red&&U.red===I.red,"red works only with red numbers")},u.prototype.imod=function(U){if(this.prime)return this.prime.ireduce(U)._forceRed(this);return U.umod(this.m)._forceRed(this)},u.prototype.neg=function(U){if(U.isZero())return U.clone();return this.m.sub(U)._forceRed(this)},u.prototype.add=function(U,I){this._verify2(U,I);var Q=U.add(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q._forceRed(this)},u.prototype.iadd=function(U,I){this._verify2(U,I);var Q=U.iadd(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q},u.prototype.sub=function(U,I){this._verify2(U,I);var Q=U.sub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q._forceRed(this)},u.prototype.isub=function(U,I){this._verify2(U,I);var Q=U.isub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q},u.prototype.shl=function(U,I){return this._verify1(U),this.imod(U.ushln(I))},u.prototype.imul=function(U,I){return this._verify2(U,I),this.imod(U.imul(I))},u.prototype.mul=function(U,I){return this._verify2(U,I),this.imod(U.mul(I))},u.prototype.isqr=function(U){return this.imul(U,U.clone())},u.prototype.sqr=function(U){return this.mul(U,U)},u.prototype.sqrt=function(U){if(U.isZero())return U.clone();var I=this.m.andln(3);if(L(I%2===1),I===3){var Q=this.m.add(new O(1)).iushrn(2);return this.pow(U,Q)}var X=this.m.subn(1),Z=0;while(!X.isZero()&&X.andln(1)===0)Z++,X.iushrn(1);L(!X.isZero());var A=new O(1).toRed(this),$=A.redNeg(),J=this.m.subn(1).iushrn(1),E=this.m.bitLength();E=new O(2*E*E).toRed(this);while(this.pow(E,J).cmp($)!==0)E.redIAdd($);var V=this.pow(E,X),S=this.pow(U,X.addn(1).iushrn(1)),H=this.pow(U,X),j=Z;while(H.cmp(A)!==0){var w=H;for(var p=0;w.cmp(A)!==0;p++)w=w.redSqr();L(p=0;Z--){var V=I.words[Z];for(var S=E-1;S>=0;S--){var H=V>>S&1;if(A!==X[0])A=this.sqr(A);if(H===0&&$===0){J=0;continue}if($<<=1,$|=H,J++,J!==Q&&(Z!==0||S!==0))continue;A=this.mul(A,X[$]),J=0,$=0}E=26}return A},u.prototype.convertTo=function(U){var I=U.umod(this.m);return I===U?I.clone():I},u.prototype.convertFrom=function(U){var I=U.clone();return I.red=null,I},O.mont=function(U){return new i(U)};function i(U){if(u.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new O(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}W(i,u),i.prototype.convertTo=function(U){return this.imod(U.ushln(this.shift))},i.prototype.convertFrom=function(U){var I=this.imod(U.mul(this.rinv));return I.red=null,I},i.prototype.imul=function(U,I){if(U.isZero()||I.isZero())return U.words[0]=0,U.length=1,U;var Q=U.imul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.mul=function(U,I){if(U.isZero()||I.isZero())return new O(0)._forceRed(this);var Q=U.mul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.invm=function(U){var I=this.imod(U._invmp(this.m).mul(this.r2));return I._forceRed(this)}})(typeof Y>"u"||Y,T)}),FQ=Q0((T)=>{var Y=RE(),G=_U(),K=T;K.define=function(W,O){return new L(W,O)};function L(W,O){this.name=W,this.body=O,this.decoders={},this.encoders={}}L.prototype._createNamed=function(W){var O;try{O=(()=>{throw new Error("Cannot require module "+"vm");})().runInThisContext("(function "+this.name+`(entity) { + this._initNamed(entity); +})`)}catch(z){O=function(q){this._initNamed(q)}}return G(O,W),O.prototype._initNamed=function(z){W.call(this,z)},new O(this)},L.prototype._getDecoder=function(W){if(W=W||"der",!this.decoders.hasOwnProperty(W))this.decoders[W]=this._createNamed(Y.decoders[W]);return this.decoders[W]},L.prototype.decode=function(W,O,z){return this._getDecoder(O).decode(W,z)},L.prototype._getEncoder=function(W){if(W=W||"der",!this.encoders.hasOwnProperty(W))this.encoders[W]=this._createNamed(Y.encoders[W]);return this.encoders[W]},L.prototype.encode=function(W,O,z){return this._getEncoder(O).encode(W,z)}}),WQ=Q0((T)=>{var Y=_U();function G(L){this._reporterState={obj:null,path:[],options:L||{},errors:[]}}T.Reporter=G,G.prototype.isError=function(L){return L instanceof K},G.prototype.save=function(){var L=this._reporterState;return{obj:L.obj,pathLen:L.path.length}},G.prototype.restore=function(L){var W=this._reporterState;W.obj=L.obj,W.path=W.path.slice(0,L.pathLen)},G.prototype.enterKey=function(L){return this._reporterState.path.push(L)},G.prototype.exitKey=function(L){var W=this._reporterState;W.path=W.path.slice(0,L-1)},G.prototype.leaveKey=function(L,W,O){var z=this._reporterState;if(this.exitKey(L),z.obj!==null)z.obj[W]=O},G.prototype.path=function(){return this._reporterState.path.join("/")},G.prototype.enterObject=function(){var L=this._reporterState,W=L.obj;return L.obj={},W},G.prototype.leaveObject=function(L){var W=this._reporterState,O=W.obj;return W.obj=L,O},G.prototype.error=function(L){var W,O=this._reporterState,z=L instanceof K;if(z)W=L;else W=new K(O.path.map(function(q){return"["+JSON.stringify(q)+"]"}).join(""),L.message||L,L.stack);if(!O.options.partial)throw W;if(!z)O.errors.push(W);return W},G.prototype.wrapResult=function(L){var W=this._reporterState;if(!W.options.partial)return L;return{result:this.isError(L)?null:L,errors:W.errors}};function K(L,W){this.path=L,this.rethrow(W)}Y(K,Error),K.prototype.rethrow=function(L){if(this.message=L+" at: "+(this.path||"(shallow)"),Error.captureStackTrace)Error.captureStackTrace(this,K);if(!this.stack)try{throw Error(this.message)}catch(W){this.stack=W.stack}return this}}),TT=Q0((T)=>{var Y=_U(),G=$E().Reporter,K=(FU(),h0(KU)).Buffer;function L(O,z){if(G.call(this,z),!K.isBuffer(O)){this.error("Input not Buffer");return}this.base=O,this.offset=0,this.length=O.length}Y(L,G),T.DecoderBuffer=L,L.prototype.save=function(){return{offset:this.offset,reporter:G.prototype.save.call(this)}},L.prototype.restore=function(O){var z=new L(this.base);return z.offset=O.offset,z.length=this.offset,this.offset=O.offset,G.prototype.restore.call(this,O.reporter),z},L.prototype.isEmpty=function(){return this.offset===this.length},L.prototype.readUInt8=function(O){if(this.offset+1<=this.length)return this.base.readUInt8(this.offset++,!0);else return this.error(O||"DecoderBuffer overrun")},L.prototype.skip=function(O,z){if(!(this.offset+O<=this.length))return this.error(z||"DecoderBuffer overrun");var q=new L(this.base);return q._reporterState=this._reporterState,q.offset=this.offset,q.length=this.offset+O,this.offset+=O,q},L.prototype.raw=function(O){return this.base.slice(O?O.offset:this.offset,this.length)};function W(O,z){if(Array.isArray(O))this.length=0,this.value=O.map(function(q){if(!(q instanceof W))q=new W(q,z);return this.length+=q.length,q},this);else if(typeof O==="number"){if(!(0<=O&&O<=255))return z.error("non-byte EncoderBuffer value");this.value=O,this.length=1}else if(typeof O==="string")this.value=O,this.length=K.byteLength(O);else if(K.isBuffer(O))this.value=O,this.length=O.length;else return z.error("Unsupported type: "+typeof O)}T.EncoderBuffer=W,W.prototype.join=function(O,z){if(!O)O=new K(this.length);if(!z)z=0;if(this.length===0)return O;if(Array.isArray(this.value))this.value.forEach(function(q){q.join(O,z),z+=q.length});else{if(typeof this.value==="number")O[z]=this.value;else if(typeof this.value==="string")O.write(this.value,z);else if(K.isBuffer(this.value))this.value.copy(O,z);z+=this.length}return O}}),HQ=Q0((T,Y)=>{var G=$E().Reporter,K=$E().EncoderBuffer,L=$E().DecoderBuffer,W=dU(),O=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],z=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(O),q=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function D(F,R){var M={};if(this._baseState=M,M.enc=F,M.parent=R||null,M.children=null,M.tag=null,M.args=null,M.reverseArgs=null,M.choice=null,M.optional=!1,M.any=!1,M.obj=!1,M.use=null,M.useDecoder=null,M.key=null,M.default=null,M.explicit=null,M.implicit=null,M.contains=null,!M.parent)M.children=[],this._wrap()}Y.exports=D;var C=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];D.prototype.clone=function(){var F=this._baseState,R={};C.forEach(function(P){R[P]=F[P]});var M=new this.constructor(R.parent);return M._baseState=R,M},D.prototype._wrap=function(){var F=this._baseState;z.forEach(function(R){this[R]=function(){var M=new this.constructor(this);return F.children.push(M),M[R].apply(M,arguments)}},this)},D.prototype._init=function(F){var R=this._baseState;W(R.parent===null),F.call(this),R.children=R.children.filter(function(M){return M._baseState.parent===this},this),W.equal(R.children.length,1,"Root node can have only one child")},D.prototype._useArgs=function(F){var R=this._baseState,M=F.filter(function(P){return P instanceof this.constructor},this);if(F=F.filter(function(P){return!(P instanceof this.constructor)},this),M.length!==0)W(R.children===null),R.children=M,M.forEach(function(P){P._baseState.parent=this},this);if(F.length!==0)W(R.args===null),R.args=F,R.reverseArgs=F.map(function(P){if(typeof P!=="object"||P.constructor!==Object)return P;var k={};return Object.keys(P).forEach(function(_){if(_==(_|0))_|=0;var N=P[_];k[N]=_}),k})},q.forEach(function(F){D.prototype[F]=function(){var R=this._baseState;throw Error(F+" not implemented for encoding: "+R.enc)}}),O.forEach(function(F){D.prototype[F]=function(){var R=this._baseState,M=Array.prototype.slice.call(arguments);return W(R.tag===null),R.tag=F,this._useArgs(M),this}}),D.prototype.use=function(F){W(F);var R=this._baseState;return W(R.use===null),R.use=F,this},D.prototype.optional=function(){var F=this._baseState;return F.optional=!0,this},D.prototype.def=function(F){var R=this._baseState;return W(R.default===null),R.default=F,R.optional=!0,this},D.prototype.explicit=function(F){var R=this._baseState;return W(R.explicit===null&&R.implicit===null),R.explicit=F,this},D.prototype.implicit=function(F){var R=this._baseState;return W(R.explicit===null&&R.implicit===null),R.implicit=F,this},D.prototype.obj=function(){var F=this._baseState,R=Array.prototype.slice.call(arguments);if(F.obj=!0,R.length!==0)this._useArgs(R);return this},D.prototype.key=function(F){var R=this._baseState;return W(R.key===null),R.key=F,this},D.prototype.any=function(){var F=this._baseState;return F.any=!0,this},D.prototype.choice=function(F){var R=this._baseState;return W(R.choice===null),R.choice=F,this._useArgs(Object.keys(F).map(function(M){return F[M]})),this},D.prototype.contains=function(F){var R=this._baseState;return W(R.use===null),R.contains=F,this},D.prototype._decode=function(F,R){var M=this._baseState;if(M.parent===null)return F.wrapResult(M.children[0]._decode(F,R));var P=M.default,k=!0,_=null;if(M.key!==null)_=F.enterKey(M.key);if(M.optional){var N=null;if(M.explicit!==null)N=M.explicit;else if(M.implicit!==null)N=M.implicit;else if(M.tag!==null)N=M.tag;if(N===null&&!M.any){var v=F.save();try{if(M.choice===null)this._decodeGeneric(M.tag,F,R);else this._decodeChoice(F,R);k=!0}catch(O0){k=!1}F.restore(v)}else if(k=this._peekTag(F,N,M.any),F.isError(k))return k}var B;if(M.obj&&k)B=F.enterObject();if(k){if(M.explicit!==null){var g=this._decodeTag(F,M.explicit);if(F.isError(g))return g;F=g}var y=F.offset;if(M.use===null&&M.choice===null){if(M.any)var v=F.save();var l=this._decodeTag(F,M.implicit!==null?M.implicit:M.tag,M.any);if(F.isError(l))return l;if(M.any)P=F.raw(v);else F=l}if(R&&R.track&&M.tag!==null)R.track(F.path(),y,F.length,"tagged");if(R&&R.track&&M.tag!==null)R.track(F.path(),F.offset,F.length,"content");if(M.any)P=P;else if(M.choice===null)P=this._decodeGeneric(M.tag,F,R);else P=this._decodeChoice(F,R);if(F.isError(P))return P;if(!M.any&&M.choice===null&&M.children!==null)M.children.forEach(function(O0){O0._decode(F,R)});if(M.contains&&(M.tag==="octstr"||M.tag==="bitstr")){var Y0=new L(P);P=this._getUse(M.contains,F._reporterState.obj)._decode(Y0,R)}}if(M.obj&&k)P=F.leaveObject(B);if(M.key!==null&&(P!==null||k===!0))F.leaveKey(_,M.key,P);else if(_!==null)F.exitKey(_);return P},D.prototype._decodeGeneric=function(F,R,M){var P=this._baseState;if(F==="seq"||F==="set")return null;if(F==="seqof"||F==="setof")return this._decodeList(R,F,P.args[0],M);else if(/str$/.test(F))return this._decodeStr(R,F,M);else if(F==="objid"&&P.args)return this._decodeObjid(R,P.args[0],P.args[1],M);else if(F==="objid")return this._decodeObjid(R,null,null,M);else if(F==="gentime"||F==="utctime")return this._decodeTime(R,F,M);else if(F==="null_")return this._decodeNull(R,M);else if(F==="bool")return this._decodeBool(R,M);else if(F==="objDesc")return this._decodeStr(R,F,M);else if(F==="int"||F==="enum")return this._decodeInt(R,P.args&&P.args[0],M);if(P.use!==null)return this._getUse(P.use,R._reporterState.obj)._decode(R,M);else return R.error("unknown tag: "+F)},D.prototype._getUse=function(F,R){var M=this._baseState;if(M.useDecoder=this._use(F,R),W(M.useDecoder._baseState.parent===null),M.useDecoder=M.useDecoder._baseState.children[0],M.implicit!==M.useDecoder._baseState.implicit)M.useDecoder=M.useDecoder.clone(),M.useDecoder._baseState.implicit=M.implicit;return M.useDecoder},D.prototype._decodeChoice=function(F,R){var M=this._baseState,P=null,k=!1;if(Object.keys(M.choice).some(function(_){var N=F.save(),v=M.choice[_];try{var B=v._decode(F,R);if(F.isError(B))return!1;P={type:_,value:B},k=!0}catch(g){return F.restore(N),!1}return!0},this),!k)return F.error("Choice not matched");return P},D.prototype._createEncoderBuffer=function(F){return new K(F,this.reporter)},D.prototype._encode=function(F,R,M){var P=this._baseState;if(P.default!==null&&P.default===F)return;var k=this._encodeValue(F,R,M);if(k===void 0)return;if(this._skipDefault(k,R,M))return;return k},D.prototype._encodeValue=function(F,R,M){var P=this._baseState;if(P.parent===null)return P.children[0]._encode(F,R||new G);var v=null;if(this.reporter=R,P.optional&&F===void 0)if(P.default!==null)F=P.default;else return;var k=null,_=!1;if(P.any)v=this._createEncoderBuffer(F);else if(P.choice)v=this._encodeChoice(F,R);else if(P.contains)k=this._getUse(P.contains,M)._encode(F,R),_=!0;else if(P.children)k=P.children.map(function(y){if(y._baseState.tag==="null_")return y._encode(null,R,F);if(y._baseState.key===null)return R.error("Child should have a key");var l=R.enterKey(y._baseState.key);if(typeof F!=="object")return R.error("Child expected, but input is not object");var Y0=y._encode(F[y._baseState.key],R,F);return R.leaveKey(l),Y0},this).filter(function(y){return y}),k=this._createEncoderBuffer(k);else if(P.tag==="seqof"||P.tag==="setof"){if(!(P.args&&P.args.length===1))return R.error("Too many args for : "+P.tag);if(!Array.isArray(F))return R.error("seqof/setof, but data is not Array");var N=this.clone();N._baseState.implicit=null,k=this._createEncoderBuffer(F.map(function(y){var l=this._baseState;return this._getUse(l.args[0],F)._encode(y,R)},N))}else if(P.use!==null)v=this._getUse(P.use,M)._encode(F,R);else k=this._encodePrimitive(P.tag,F),_=!0;var v;if(!P.any&&P.choice===null){var B=P.implicit!==null?P.implicit:P.tag,g=P.implicit===null?"universal":"context";if(B===null){if(P.use===null)R.error("Tag could be omitted only for .use()")}else if(P.use===null)v=this._encodeComposite(B,_,g,k)}if(P.explicit!==null)v=this._encodeComposite(P.explicit,!1,"context",v);return v},D.prototype._encodeChoice=function(F,R){var M=this._baseState,P=M.choice[F.type];if(!P)W(!1,F.type+" not found in "+JSON.stringify(Object.keys(M.choice)));return P._encode(F.value,R)},D.prototype._encodePrimitive=function(F,R){var M=this._baseState;if(/str$/.test(F))return this._encodeStr(R,F);else if(F==="objid"&&M.args)return this._encodeObjid(R,M.reverseArgs[0],M.args[1]);else if(F==="objid")return this._encodeObjid(R,null,null);else if(F==="gentime"||F==="utctime")return this._encodeTime(R,F);else if(F==="null_")return this._encodeNull();else if(F==="int"||F==="enum")return this._encodeInt(R,M.args&&M.reverseArgs[0]);else if(F==="bool")return this._encodeBool(R);else if(F==="objDesc")return this._encodeStr(R,F);else throw Error("Unsupported tag: "+F)},D.prototype._isNumstr=function(F){return/^[0-9 ]*$/.test(F)},D.prototype._isPrintstr=function(F){return/^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(F)}}),$E=Q0((T)=>{var Y=T;Y.Reporter=WQ().Reporter,Y.DecoderBuffer=TT().DecoderBuffer,Y.EncoderBuffer=TT().EncoderBuffer,Y.Node=HQ()}),RQ=Q0((T)=>{var Y=ST();T.tagClass={0:"universal",1:"application",2:"context",3:"private"},T.tagClassByName=Y._reverse(T.tagClass),T.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},T.tagByName=Y._reverse(T.tag)}),ST=Q0((T)=>{var Y=T;Y._reverse=function(G){var K={};return Object.keys(G).forEach(function(L){if((L|0)==L)L=L|0;var W=G[L];K[W]=L}),K},Y.der=RQ()}),MT=Q0((T,Y)=>{var G=_U(),K=RE(),L=K.base,W=K.bignum,O=K.constants.der;function z(F){this.enc="der",this.name=F.name,this.entity=F,this.tree=new q,this.tree._init(F.body)}Y.exports=z,z.prototype.decode=function(F,R){if(!(F instanceof L.DecoderBuffer))F=new L.DecoderBuffer(F,R);return this.tree._decode(F,R)};function q(F){L.Node.call(this,"der",F)}G(q,L.Node),q.prototype._peekTag=function(F,R,M){if(F.isEmpty())return!1;var P=F.save(),k=D(F,'Failed to peek tag: "'+R+'"');if(F.isError(k))return k;return F.restore(P),k.tag===R||k.tagStr===R||k.tagStr+"of"===R||M},q.prototype._decodeTag=function(F,R,M){var P=D(F,'Failed to decode tag of "'+R+'"');if(F.isError(P))return P;var k=C(F,P.primitive,'Failed to get length of "'+R+'"');if(F.isError(k))return k;if(!M&&P.tag!==R&&P.tagStr!==R&&P.tagStr+"of"!==R)return F.error('Failed to match tag: "'+R+'"');if(P.primitive||k!==null)return F.skip(k,'Failed to match body of: "'+R+'"');var _=F.save(),N=this._skipUntilEnd(F,'Failed to skip indefinite length body: "'+this.tag+'"');if(F.isError(N))return N;return k=F.offset-_.offset,F.restore(_),F.skip(k,'Failed to match body of: "'+R+'"')},q.prototype._skipUntilEnd=function(F,R){while(!0){var M=D(F,R);if(F.isError(M))return M;var P=C(F,M.primitive,R);if(F.isError(P))return P;var k;if(M.primitive||P!==null)k=F.skip(P);else k=this._skipUntilEnd(F,R);if(F.isError(k))return k;if(M.tagStr==="end")break}},q.prototype._decodeList=function(F,R,M,P){var k=[];while(!F.isEmpty()){var _=this._peekTag(F,"end");if(F.isError(_))return _;var N=M.decode(F,"der",P);if(F.isError(N)&&_)break;k.push(N)}return k},q.prototype._decodeStr=function(F,R){if(R==="bitstr"){var M=F.readUInt8();if(F.isError(M))return M;return{unused:M,data:F.raw()}}else if(R==="bmpstr"){var P=F.raw();if(P.length%2===1)return F.error("Decoding of string type: bmpstr length mismatch");var k="";for(var _=0;_>6],k=(M&32)===0;if((M&31)===31){var _=M;M=0;while((_&128)===128){if(_=F.readUInt8(R),F.isError(_))return _;M<<=7,M|=_&127}}else M&=31;var N=O.tag[M];return{cls:P,primitive:k,tag:M,tagStr:N}}function C(F,R,M){var P=F.readUInt8(M);if(F.isError(P))return P;if(!R&&P===128)return null;if((P&128)===0)return P;var k=P&127;if(k>4)return F.error("length octect is too long");P=0;for(var _=0;_{var G=_U(),K=(FU(),h0(KU)).Buffer,L=MT();function W(O){L.call(this,O),this.enc="pem"}G(W,L),Y.exports=W,W.prototype.decode=function(O,z){var q=O.toString().split(/[\r\n]+/g),D=z.label.toUpperCase(),C=/^-----(BEGIN|END) ([^-]+)-----$/,F=-1,R=-1;for(var M=0;M{var Y=T;Y.der=MT(),Y.pem=CQ()}),qT=Q0((T,Y)=>{var G=_U(),K=(FU(),h0(KU)).Buffer,L=RE(),W=L.base,O=L.constants.der;function z(F){this.enc="der",this.name=F.name,this.entity=F,this.tree=new q,this.tree._init(F.body)}Y.exports=z,z.prototype.encode=function(F,R){return this.tree._encode(F,R).join()};function q(F){W.Node.call(this,"der",F)}G(q,W.Node),q.prototype._encodeComposite=function(F,R,M,P){var k=C(F,R,M,this.reporter);if(P.length<128){var v=new K(2);return v[0]=k,v[1]=P.length,this._createEncoderBuffer([v,P])}var _=1;for(var N=P.length;N>=256;N>>=8)_++;var v=new K(2+_);v[0]=k,v[1]=128|_;for(var N=1+_,B=P.length;B>0;N--,B>>=8)v[N]=B&255;return this._createEncoderBuffer([v,P])},q.prototype._encodeStr=function(F,R){if(R==="bitstr")return this._createEncoderBuffer([F.unused|0,F.data]);else if(R==="bmpstr"){var M=new K(F.length*2);for(var P=0;P=40)return this.reporter.error("Second objid identifier OOB");F.splice(0,2,F[0]*40+F[1])}var k=0;for(var P=0;P=128;_>>=7)k++}var N=new K(k),v=N.length-1;for(var P=F.length-1;P>=0;P--){var _=F[P];N[v--]=_&127;while((_>>=7)>0)N[v--]=128|_&127}return this._createEncoderBuffer(N)};function D(F){if(F<10)return"0"+F;else return F}q.prototype._encodeTime=function(F,R){var M,P=new Date(F);if(R==="gentime")M=[D(P.getFullYear()),D(P.getUTCMonth()+1),D(P.getUTCDate()),D(P.getUTCHours()),D(P.getUTCMinutes()),D(P.getUTCSeconds()),"Z"].join("");else if(R==="utctime")M=[D(P.getFullYear()%100),D(P.getUTCMonth()+1),D(P.getUTCDate()),D(P.getUTCHours()),D(P.getUTCMinutes()),D(P.getUTCSeconds()),"Z"].join("");else this.reporter.error("Encoding "+R+" time is not supported yet");return this._encodeStr(M,"octstr")},q.prototype._encodeNull=function(){return this._createEncoderBuffer("")},q.prototype._encodeInt=function(F,R){if(typeof F==="string"){if(!R)return this.reporter.error("String int or enum given, but no values map");if(!R.hasOwnProperty(F))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(F));F=R[F]}if(typeof F!=="number"&&!K.isBuffer(F)){var M=F.toArray();if(!F.sign&&M[0]&128)M.unshift(0);F=new K(M)}if(K.isBuffer(F)){var P=F.length;if(F.length===0)P++;var _=new K(P);if(F.copy(_),F.length===0)_[0]=0;return this._createEncoderBuffer(_)}if(F<128)return this._createEncoderBuffer(F);if(F<256)return this._createEncoderBuffer([0,F]);var P=1;for(var k=F;k>=256;k>>=8)P++;var _=Array(P);for(var k=_.length-1;k>=0;k--)_[k]=F&255,F>>=8;if(_[0]&128)_.unshift(0);return this._createEncoderBuffer(new K(_))},q.prototype._encodeBool=function(F){return this._createEncoderBuffer(F?255:0)},q.prototype._use=function(F,R){if(typeof F==="function")F=F(R);return F._getEncoder("der").tree},q.prototype._skipDefault=function(F,R,M){var P=this._baseState,k;if(P.default===null)return!1;var _=F.join();if(P.defaultBuffer===void 0)P.defaultBuffer=this._encodeValue(P.default,R,M).join();if(_.length!==P.defaultBuffer.length)return!1;for(k=0;k<_.length;k++)if(_[k]!==P.defaultBuffer[k])return!1;return!0};function C(F,R,M,P){var k;if(F==="seqof")F="seq";else if(F==="setof")F="set";if(O.tagByName.hasOwnProperty(F))k=O.tagByName[F];else if(typeof F==="number"&&(F|0)===F)k=F;else return P.error("Unknown tag: "+F);if(k>=31)return P.error("Multi-octet tag encoding unsupported");if(!R)k|=32;return k|=O.tagClassByName[M||"universal"]<<6,k}}),zQ=Q0((T,Y)=>{var G=_U(),K=qT();function L(W){K.call(this,W),this.enc="pem"}G(L,K),Y.exports=L,L.prototype.encode=function(W,O){var z=K.prototype.encode.call(this,W),q=z.toString("base64"),D=["-----BEGIN "+O.label+"-----"];for(var C=0;C{var Y=T;Y.der=qT(),Y.pem=zQ()}),RE=Q0((T)=>{var Y=T;Y.bignum=KQ(),Y.define=FQ().define,Y.base=$E(),Y.constants=ST(),Y.decoders=DQ(),Y.encoders=SQ()}),MQ=Q0((T,Y)=>{var G=RE(),K=G.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),L=G.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),W=G.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),O=G.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(W),this.key("subjectPublicKey").bitstr())}),z=G.define("RelativeDistinguishedName",function(){this.setof(L)}),q=G.define("RDNSequence",function(){this.seqof(z)}),D=G.define("Name",function(){this.choice({rdnSequence:this.use(q)})}),C=G.define("Validity",function(){this.seq().obj(this.key("notBefore").use(K),this.key("notAfter").use(K))}),F=G.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),R=G.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(W),this.key("issuer").use(D),this.key("validity").use(C),this.key("subject").use(D),this.key("subjectPublicKeyInfo").use(O),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(F).optional())}),M=G.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(R),this.key("signatureAlgorithm").use(W),this.key("signatureValue").bitstr())});Y.exports=M}),qQ=Q0((T)=>{var Y=RE();T.certificate=MQ();var G=Y.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("modulus").int(),this.key("publicExponent").int(),this.key("privateExponent").int(),this.key("prime1").int(),this.key("prime2").int(),this.key("exponent1").int(),this.key("exponent2").int(),this.key("coefficient").int())});T.RSAPrivateKey=G;var K=Y.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});T.RSAPublicKey=K;var L=Y.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("none").null_().optional(),this.key("curve").objid().optional(),this.key("params").seq().obj(this.key("p").int(),this.key("q").int(),this.key("g").int()).optional())}),W=Y.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(L),this.key("subjectPublicKey").bitstr())});T.PublicKey=W;var O=Y.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(L),this.key("subjectPrivateKey").octstr())});T.PrivateKey=O;var z=Y.define("EncryptedPrivateKeyInfo",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(),this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(),this.key("kdeparams").seq().obj(this.key("salt").octstr(),this.key("iters").int())),this.key("cipher").seq().obj(this.key("algo").objid(),this.key("iv").octstr()))),this.key("subjectPrivateKey").octstr())});T.EncryptedPrivateKey=z;var q=Y.define("DSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("p").int(),this.key("q").int(),this.key("g").int(),this.key("pub_key").int(),this.key("priv_key").int())});T.DSAPrivateKey=q,T.DSAparam=Y.define("DSAparam",function(){this.int()});var D=Y.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),C=Y.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(D),this.key("publicKey").optional().explicit(1).bitstr())});T.ECPrivateKey=C,T.signature=Y.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())})}),PQ=Q0((T,Y)=>{Y.exports={"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"}}),_Q=Q0((T,Y)=>{var G=SU().Buffer,K=MX().Transform,L=_U();function W(D){K.call(this),this._block=G.allocUnsafe(D),this._blockSize=D,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}L(W,K),W.prototype._transform=function(D,C,F){var R=null;try{this.update(D,C)}catch(M){R=M}F(R)},W.prototype._flush=function(D){var C=null;try{this.push(this.digest())}catch(F){C=F}D(C)};var O=typeof Uint8Array<"u",z=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u"&&ArrayBuffer.isView&&(G.prototype instanceof Uint8Array||G.TYPED_ARRAY_SUPPORT);function q(D,C){if(D instanceof G)return D;if(typeof D==="string")return G.from(D,C);if(z&&ArrayBuffer.isView(D)){if(D.byteLength===0)return G.alloc(0);var F=G.from(D.buffer,D.byteOffset,D.byteLength);if(F.byteLength===D.byteLength)return F}if(O&&D instanceof Uint8Array)return G.from(D);if(G.isBuffer(D)&&D.constructor&&typeof D.constructor.isBuffer==="function"&&D.constructor.isBuffer(D))return G.from(D);throw TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')}W.prototype.update=function(D,C){if(this._finalized)throw Error("Digest already called");D=q(D,C);var F=this._block,R=0;while(this._blockOffset+D.length-R>=this._blockSize){for(var M=this._blockOffset;M0;++P)if(this._length[P]+=k,k=this._length[P]/4294967296|0,k>0)this._length[P]-=4294967296*k;return this},W.prototype._update=function(){throw Error("_update is not implemented")},W.prototype.digest=function(D){if(this._finalized)throw Error("Digest already called");this._finalized=!0;var C=this._digest();if(D!==void 0)C=C.toString(D);this._block.fill(0),this._blockOffset=0;for(var F=0;F<4;++F)this._length[F]=0;return C},W.prototype._digest=function(){throw Error("_digest is not implemented")},Y.exports=W}),kQ=Q0((T,Y)=>{var G=_U(),K=_Q(),L=SU().Buffer,W=Array(16);function O(){K.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}G(O,K),O.prototype._update=function(){var R=W;for(var M=0;M<16;++M)R[M]=this._block.readInt32LE(M*4);var P=this._a,k=this._b,_=this._c,N=this._d;P=q(P,k,_,N,R[0],3614090360,7),N=q(N,P,k,_,R[1],3905402710,12),_=q(_,N,P,k,R[2],606105819,17),k=q(k,_,N,P,R[3],3250441966,22),P=q(P,k,_,N,R[4],4118548399,7),N=q(N,P,k,_,R[5],1200080426,12),_=q(_,N,P,k,R[6],2821735955,17),k=q(k,_,N,P,R[7],4249261313,22),P=q(P,k,_,N,R[8],1770035416,7),N=q(N,P,k,_,R[9],2336552879,12),_=q(_,N,P,k,R[10],4294925233,17),k=q(k,_,N,P,R[11],2304563134,22),P=q(P,k,_,N,R[12],1804603682,7),N=q(N,P,k,_,R[13],4254626195,12),_=q(_,N,P,k,R[14],2792965006,17),k=q(k,_,N,P,R[15],1236535329,22),P=D(P,k,_,N,R[1],4129170786,5),N=D(N,P,k,_,R[6],3225465664,9),_=D(_,N,P,k,R[11],643717713,14),k=D(k,_,N,P,R[0],3921069994,20),P=D(P,k,_,N,R[5],3593408605,5),N=D(N,P,k,_,R[10],38016083,9),_=D(_,N,P,k,R[15],3634488961,14),k=D(k,_,N,P,R[4],3889429448,20),P=D(P,k,_,N,R[9],568446438,5),N=D(N,P,k,_,R[14],3275163606,9),_=D(_,N,P,k,R[3],4107603335,14),k=D(k,_,N,P,R[8],1163531501,20),P=D(P,k,_,N,R[13],2850285829,5),N=D(N,P,k,_,R[2],4243563512,9),_=D(_,N,P,k,R[7],1735328473,14),k=D(k,_,N,P,R[12],2368359562,20),P=C(P,k,_,N,R[5],4294588738,4),N=C(N,P,k,_,R[8],2272392833,11),_=C(_,N,P,k,R[11],1839030562,16),k=C(k,_,N,P,R[14],4259657740,23),P=C(P,k,_,N,R[1],2763975236,4),N=C(N,P,k,_,R[4],1272893353,11),_=C(_,N,P,k,R[7],4139469664,16),k=C(k,_,N,P,R[10],3200236656,23),P=C(P,k,_,N,R[13],681279174,4),N=C(N,P,k,_,R[0],3936430074,11),_=C(_,N,P,k,R[3],3572445317,16),k=C(k,_,N,P,R[6],76029189,23),P=C(P,k,_,N,R[9],3654602809,4),N=C(N,P,k,_,R[12],3873151461,11),_=C(_,N,P,k,R[15],530742520,16),k=C(k,_,N,P,R[2],3299628645,23),P=F(P,k,_,N,R[0],4096336452,6),N=F(N,P,k,_,R[7],1126891415,10),_=F(_,N,P,k,R[14],2878612391,15),k=F(k,_,N,P,R[5],4237533241,21),P=F(P,k,_,N,R[12],1700485571,6),N=F(N,P,k,_,R[3],2399980690,10),_=F(_,N,P,k,R[10],4293915773,15),k=F(k,_,N,P,R[1],2240044497,21),P=F(P,k,_,N,R[8],1873313359,6),N=F(N,P,k,_,R[15],4264355552,10),_=F(_,N,P,k,R[6],2734768916,15),k=F(k,_,N,P,R[13],1309151649,21),P=F(P,k,_,N,R[4],4149444226,6),N=F(N,P,k,_,R[11],3174756917,10),_=F(_,N,P,k,R[2],718787259,15),k=F(k,_,N,P,R[9],3951481745,21),this._a=this._a+P|0,this._b=this._b+k|0,this._c=this._c+_|0,this._d=this._d+N|0},O.prototype._digest=function(){if(this._block[this._blockOffset++]=128,this._blockOffset>56)this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0;this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var R=L.allocUnsafe(16);return R.writeInt32LE(this._a,0),R.writeInt32LE(this._b,4),R.writeInt32LE(this._c,8),R.writeInt32LE(this._d,12),R};function z(R,M){return R<>>32-M}function q(R,M,P,k,_,N,v){return z(R+(M&P|~M&k)+_+N|0,v)+M|0}function D(R,M,P,k,_,N,v){return z(R+(M&k|P&~k)+_+N|0,v)+M|0}function C(R,M,P,k,_,N,v){return z(R+(M^P^k)+_+N|0,v)+M|0}function F(R,M,P,k,_,N,v){return z(R+(P^(M|~k))+_+N|0,v)+M|0}Y.exports=O}),vQ=Q0((T,Y)=>{var G=SU().Buffer,K=kQ();function L(W,O,z,q){if(!G.isBuffer(W))W=G.from(W,"binary");if(O){if(!G.isBuffer(O))O=G.from(O,"binary");if(O.length!==8)throw RangeError("salt should be Buffer with 8 byte length")}var D=z/8,C=G.alloc(D),F=G.alloc(q||0),R=G.alloc(0);while(D>0||q>0){var M=new K;if(M.update(R),M.update(W),O)M.update(O);R=M.digest();var P=0;if(D>0){var k=C.length-D;P=Math.min(D,R.length),R.copy(C,k,0,P),D-=P}if(P0){var _=F.length-q,N=Math.min(q,R.length-P);R.copy(F,_,P,P+N),q-=N}}return R.fill(0),{key:C,iv:F}}Y.exports=L}),PT=Q0((T)=>{var Y=(DU(),h0(PU));T.createCipher=T.Cipher=Y.createCipher,T.createCipheriv=T.Cipheriv=Y.createCipheriv,T.createDecipher=T.Decipher=Y.createDecipher,T.createDecipheriv=T.Decipheriv=Y.createDecipheriv,T.listCiphers=T.getCiphers=Y.getCiphers}),jQ=Q0((T,Y)=>{var G=/Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m,K=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,L=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,W=vQ(),O=PT(),z=SU().Buffer;Y.exports=function(q,D){var C=q.toString(),F=C.match(G),R;if(!F){var M=C.match(L);R=z.from(M[2].replace(/[\r\n]/g,""),"base64")}else{var P="aes"+F[1],k=z.from(F[2],"hex"),_=z.from(F[3].replace(/[\r\n]/g,""),"base64"),N=W(D,k.slice(0,8),parseInt(F[1],10)).key,v=[],B=O.createDecipheriv(P,N,k);v.push(B.update(_)),v.push(B.final()),R=z.concat(v)}var g=C.match(K)[1];return{tag:g,data:R}}}),_T=Q0((T,Y)=>{var G=qQ(),K=PQ(),L=jQ(),W=PT(),O=FT().pbkdf2Sync,z=SU().Buffer;function q(C,F){var R=C.algorithm.decrypt.kde.kdeparams.salt,M=parseInt(C.algorithm.decrypt.kde.kdeparams.iters.toString(),10),P=K[C.algorithm.decrypt.cipher.algo.join(".")],k=C.algorithm.decrypt.cipher.iv,_=C.subjectPrivateKey,N=parseInt(P.split("-")[1],10)/8,v=O(F,R,M,N,"sha1"),B=W.createDecipheriv(P,v,k),g=[];return g.push(B.update(_)),g.push(B.final()),z.concat(g)}function D(C){var F;if(typeof C==="object"&&!z.isBuffer(C))F=C.passphrase,C=C.key;if(typeof C==="string")C=z.from(C);var R=L(C,F),M=R.tag,P=R.data,k,_;switch(M){case"CERTIFICATE":_=G.certificate.decode(P,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":if(!_)_=G.PublicKey.decode(P,"der");switch(k=_.algorithm.algorithm.join("."),k){case"1.2.840.113549.1.1.1":return G.RSAPublicKey.decode(_.subjectPublicKey.data,"der");case"1.2.840.10045.2.1":return _.subjectPrivateKey=_.subjectPublicKey,{type:"ec",data:_};case"1.2.840.10040.4.1":return _.algorithm.params.pub_key=G.DSAparam.decode(_.subjectPublicKey.data,"der"),{type:"dsa",data:_.algorithm.params};default:throw Error("unknown key id "+k)}case"ENCRYPTED PRIVATE KEY":P=G.EncryptedPrivateKey.decode(P,"der"),P=q(P,F);case"PRIVATE KEY":switch(_=G.PrivateKey.decode(P,"der"),k=_.algorithm.algorithm.join("."),k){case"1.2.840.113549.1.1.1":return G.RSAPrivateKey.decode(_.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:_.algorithm.curve,privateKey:G.ECPrivateKey.decode(_.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return _.algorithm.params.priv_key=G.DSAparam.decode(_.subjectPrivateKey,"der"),{type:"dsa",params:_.algorithm.params};default:throw Error("unknown key id "+k)}case"RSA PUBLIC KEY":return G.RSAPublicKey.decode(P,"der");case"RSA PRIVATE KEY":return G.RSAPrivateKey.decode(P,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:G.DSAPrivateKey.decode(P,"der")};case"EC PRIVATE KEY":return P=G.ECPrivateKey.decode(P,"der"),{curve:P.parameters.value,privateKey:P.privateKey};default:throw Error("unknown key type "+M)}}D.signature=G.signature,Y.exports=D}),kT=Q0((T,Y)=>{var G=pE(),K=SU().Buffer;Y.exports=function(W,O){var z=K.alloc(0),q=0,D;while(z.length{Y.exports=function(G,K){var L=G.length,W=-1;while(++W{(function(G,K){function L(U,I){if(!U)throw Error(I||"Assertion failed")}function W(U,I){U.super_=I;var Q=function(){};Q.prototype=I.prototype,U.prototype=new Q,U.prototype.constructor=U}function O(U,I,Q){if(O.isBN(U))return U;if(this.negative=0,this.words=null,this.length=0,this.red=null,U!==null){if(I==="le"||I==="be")Q=I,I=10;this._init(U||0,I||10,Q||"be")}}if(typeof G==="object")G.exports=O;else K.BN=O;O.BN=O,O.wordSize=26;var z;try{if(typeof window<"u"&&typeof window.Buffer<"u")z=window.Buffer;else z=(FU(),h0(KU)).Buffer}catch(U){}O.isBN=function(U){if(U instanceof O)return!0;return U!==null&&typeof U==="object"&&U.constructor.wordSize===O.wordSize&&Array.isArray(U.words)},O.max=function(U,I){if(U.cmp(I)>0)return U;return I},O.min=function(U,I){if(U.cmp(I)<0)return U;return I},O.prototype._init=function(U,I,Q){if(typeof U==="number")return this._initNumber(U,I,Q);if(typeof U==="object")return this._initArray(U,I,Q);if(I==="hex")I=16;L(I===(I|0)&&I>=2&&I<=36),U=U.toString().replace(/\s+/g,"");var X=0;if(U[0]==="-")X++,this.negative=1;if(X=0;X-=3)if(A=U[X]|U[X-1]<<8|U[X-2]<<16,this.words[Z]|=A<<$&67108863,this.words[Z+1]=A>>>26-$&67108863,$+=24,$>=26)$-=26,Z++}else if(Q==="le"){for(X=0,Z=0;X>>26-$&67108863,$+=24,$>=26)$-=26,Z++}return this.strip()};function q(U,I){var Q=U.charCodeAt(I);if(Q>=65&&Q<=70)return Q-55;else if(Q>=97&&Q<=102)return Q-87;else return Q-48&15}function D(U,I,Q){var X=q(U,Q);if(Q-1>=I)X|=q(U,Q-1)<<4;return X}O.prototype._parseHex=function(U,I,Q){this.length=Math.ceil((U.length-I)/6),this.words=Array(this.length);for(var X=0;X=I;X-=2)if($=D(U,I,X)<=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8;else{var J=U.length-I;for(X=J%2===0?I+1:I;X=18)Z-=18,A+=1,this.words[A]|=$>>>26;else Z+=8}this.strip()};function C(U,I,Q,X){var Z=0,A=Math.min(U.length,Q);for(var $=I;$=49)Z+=J-49+10;else if(J>=17)Z+=J-17+10;else Z+=J}return Z}O.prototype._parseBase=function(U,I,Q){this.words=[0],this.length=1;for(var X=0,Z=1;Z<=67108863;Z*=I)X++;X--,Z=Z/I|0;var A=U.length-Q,$=A%X,J=Math.min(A,A-$)+Q,E=0;for(var V=Q;V1&&this.words[this.length-1]===0)this.length--;return this._normSign()},O.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},O.prototype.inspect=function(){return(this.red?""};var F=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],R=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],M=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(O.prototype.toString=function(U,I){U=U||10,I=I|0||1;var Q;if(U===16||U==="hex"){Q="";var X=0,Z=0;for(var A=0;A>>24-X&16777215,X+=2,X>=26)X-=26,A--;if(Z!==0||A!==this.length-1)Q=F[6-J.length]+J+Q;else Q=J+Q}if(Z!==0)Q=Z.toString(16)+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}if(U===(U|0)&&U>=2&&U<=36){var E=R[U],V=M[U];Q="";var S=this.clone();S.negative=0;while(!S.isZero()){var H=S.modn(V).toString(U);if(S=S.idivn(V),!S.isZero())Q=F[E-H.length]+H+Q;else Q=H+Q}if(this.isZero())Q="0"+Q;while(Q.length%I!==0)Q="0"+Q;if(this.negative!==0)Q="-"+Q;return Q}L(!1,"Base should be between 2 and 36")},O.prototype.toNumber=function(){var U=this.words[0];if(this.length===2)U+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)U+=4503599627370496+this.words[1]*67108864;else if(this.length>2)L(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-U:U},O.prototype.toJSON=function(){return this.toString(16)},O.prototype.toBuffer=function(U,I){return L(typeof z<"u"),this.toArrayLike(z,U,I)},O.prototype.toArray=function(U,I){return this.toArrayLike(Array,U,I)},O.prototype.toArrayLike=function(U,I,Q){var X=this.byteLength(),Z=Q||Math.max(1,X);L(X<=Z,"byte array longer than desired length"),L(Z>0,"Requested array length <= 0"),this.strip();var A=I==="le",$=new U(Z),J,E,V=this.clone();if(!A){for(E=0;E=4096)Q+=13,I>>>=13;if(I>=64)Q+=7,I>>>=7;if(I>=8)Q+=4,I>>>=4;if(I>=2)Q+=2,I>>>=2;return Q+I};O.prototype._zeroBits=function(U){if(U===0)return 26;var I=U,Q=0;if((I&8191)===0)Q+=13,I>>>=13;if((I&127)===0)Q+=7,I>>>=7;if((I&15)===0)Q+=4,I>>>=4;if((I&3)===0)Q+=2,I>>>=2;if((I&1)===0)Q++;return Q},O.prototype.bitLength=function(){var U=this.words[this.length-1],I=this._countBits(U);return(this.length-1)*26+I};function P(U){var I=Array(U.bitLength());for(var Q=0;Q>>Z}return I}O.prototype.zeroBits=function(){if(this.isZero())return 0;var U=0;for(var I=0;IU.length)return this.clone().ior(U);return U.clone().ior(this)},O.prototype.uor=function(U){if(this.length>U.length)return this.clone().iuor(U);return U.clone().iuor(this)},O.prototype.iuand=function(U){var I;if(this.length>U.length)I=U;else I=this;for(var Q=0;QU.length)return this.clone().iand(U);return U.clone().iand(this)},O.prototype.uand=function(U){if(this.length>U.length)return this.clone().iuand(U);return U.clone().iuand(this)},O.prototype.iuxor=function(U){var I,Q;if(this.length>U.length)I=this,Q=U;else I=U,Q=this;for(var X=0;XU.length)return this.clone().ixor(U);return U.clone().ixor(this)},O.prototype.uxor=function(U){if(this.length>U.length)return this.clone().iuxor(U);return U.clone().iuxor(this)},O.prototype.inotn=function(U){L(typeof U==="number"&&U>=0);var I=Math.ceil(U/26)|0,Q=U%26;if(this._expand(I),Q>0)I--;for(var X=0;X0)this.words[X]=~this.words[X]&67108863>>26-Q;return this.strip()},O.prototype.notn=function(U){return this.clone().inotn(U)},O.prototype.setn=function(U,I){L(typeof U==="number"&&U>=0);var Q=U/26|0,X=U%26;if(this._expand(Q+1),I)this.words[Q]=this.words[Q]|1<U.length)Q=this,X=U;else Q=U,X=this;var Z=0;for(var A=0;A>>26;for(;Z!==0&&A>>26;if(this.length=Q.length,Z!==0)this.words[this.length]=Z,this.length++;else if(Q!==this)for(;AU.length)return this.clone().iadd(U);return U.clone().iadd(this)},O.prototype.isub=function(U){if(U.negative!==0){U.negative=0;var I=this.iadd(U);return U.negative=1,I._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(U),this.negative=1,this._normSign();var Q=this.cmp(U);if(Q===0)return this.negative=0,this.length=1,this.words[0]=0,this;var X,Z;if(Q>0)X=this,Z=U;else X=U,Z=this;var A=0;for(var $=0;$>26,this.words[$]=I&67108863;for(;A!==0&&$>26,this.words[$]=I&67108863;if(A===0&&$>>26,H=E&67108863,j=Math.min(V,I.length-1);for(var w=Math.max(0,V-U.length+1);w<=j;w++){var p=V-w|0;Z=U.words[p]|0,A=I.words[w]|0,$=Z*A+H,S+=$/67108864|0,H=$&67108863}Q.words[V]=H|0,E=S|0}if(E!==0)Q.words[V]=E|0;else Q.length--;return Q.strip()}var _=function(U,I,Q){var X=U.words,Z=I.words,A=Q.words,$=0,J,E,V,S=X[0]|0,H=S&8191,j=S>>>13,w=X[1]|0,p=w&8191,n=w>>>13,G0=X[2]|0,t=G0&8191,d=G0>>>13,I0=X[3]|0,m=I0&8191,U0=I0>>>13,g0=X[4]|0,f=g0&8191,h=g0>>>13,T0=X[5]|0,r=T0&8191,e=T0>>>13,C0=X[6]|0,c=C0&8191,o=C0>>>13,x0=X[7]|0,s=x0&8191,X0=x0>>>13,y0=X[8]|0,L0=y0&8191,$0=y0>>>13,n0=X[9]|0,V0=n0&8191,K0=n0>>>13,r0=Z[0]|0,H0=r0&8191,W0=r0>>>13,RU=Z[1]|0,D0=RU&8191,_0=RU>>>13,CU=Z[2]|0,k0=CU&8191,z0=CU>>>13,WU=Z[3]|0,v0=WU&8191,S0=WU>>>13,AU=Z[4]|0,j0=AU&8191,N0=AU>>>13,LU=Z[5]|0,M0=LU&8191,x=LU>>>13,b=Z[6]|0,a=b&8191,E0=b>>>13,w0=Z[7]|0,A0=w0&8191,F0=w0>>>13,m0=Z[8]|0,q0=m0&8191,B0=m0>>>13,HU=Z[9]|0,P0=HU&8191,R0=HU>>>13;Q.negative=U.negative^I.negative,Q.length=19,J=Math.imul(H,H0),E=Math.imul(H,W0),E=E+Math.imul(j,H0)|0,V=Math.imul(j,W0);var s0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(s0>>>26)|0,s0&=67108863,J=Math.imul(p,H0),E=Math.imul(p,W0),E=E+Math.imul(n,H0)|0,V=Math.imul(n,W0),J=J+Math.imul(H,D0)|0,E=E+Math.imul(H,_0)|0,E=E+Math.imul(j,D0)|0,V=V+Math.imul(j,_0)|0;var c0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(c0>>>26)|0,c0&=67108863,J=Math.imul(t,H0),E=Math.imul(t,W0),E=E+Math.imul(d,H0)|0,V=Math.imul(d,W0),J=J+Math.imul(p,D0)|0,E=E+Math.imul(p,_0)|0,E=E+Math.imul(n,D0)|0,V=V+Math.imul(n,_0)|0,J=J+Math.imul(H,k0)|0,E=E+Math.imul(H,z0)|0,E=E+Math.imul(j,k0)|0,V=V+Math.imul(j,z0)|0;var f0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(f0>>>26)|0,f0&=67108863,J=Math.imul(m,H0),E=Math.imul(m,W0),E=E+Math.imul(U0,H0)|0,V=Math.imul(U0,W0),J=J+Math.imul(t,D0)|0,E=E+Math.imul(t,_0)|0,E=E+Math.imul(d,D0)|0,V=V+Math.imul(d,_0)|0,J=J+Math.imul(p,k0)|0,E=E+Math.imul(p,z0)|0,E=E+Math.imul(n,k0)|0,V=V+Math.imul(n,z0)|0,J=J+Math.imul(H,v0)|0,E=E+Math.imul(H,S0)|0,E=E+Math.imul(j,v0)|0,V=V+Math.imul(j,S0)|0;var d0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(d0>>>26)|0,d0&=67108863,J=Math.imul(f,H0),E=Math.imul(f,W0),E=E+Math.imul(h,H0)|0,V=Math.imul(h,W0),J=J+Math.imul(m,D0)|0,E=E+Math.imul(m,_0)|0,E=E+Math.imul(U0,D0)|0,V=V+Math.imul(U0,_0)|0,J=J+Math.imul(t,k0)|0,E=E+Math.imul(t,z0)|0,E=E+Math.imul(d,k0)|0,V=V+Math.imul(d,z0)|0,J=J+Math.imul(p,v0)|0,E=E+Math.imul(p,S0)|0,E=E+Math.imul(n,v0)|0,V=V+Math.imul(n,S0)|0,J=J+Math.imul(H,j0)|0,E=E+Math.imul(H,N0)|0,E=E+Math.imul(j,j0)|0,V=V+Math.imul(j,N0)|0;var b0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(b0>>>26)|0,b0&=67108863,J=Math.imul(r,H0),E=Math.imul(r,W0),E=E+Math.imul(e,H0)|0,V=Math.imul(e,W0),J=J+Math.imul(f,D0)|0,E=E+Math.imul(f,_0)|0,E=E+Math.imul(h,D0)|0,V=V+Math.imul(h,_0)|0,J=J+Math.imul(m,k0)|0,E=E+Math.imul(m,z0)|0,E=E+Math.imul(U0,k0)|0,V=V+Math.imul(U0,z0)|0,J=J+Math.imul(t,v0)|0,E=E+Math.imul(t,S0)|0,E=E+Math.imul(d,v0)|0,V=V+Math.imul(d,S0)|0,J=J+Math.imul(p,j0)|0,E=E+Math.imul(p,N0)|0,E=E+Math.imul(n,j0)|0,V=V+Math.imul(n,N0)|0,J=J+Math.imul(H,M0)|0,E=E+Math.imul(H,x)|0,E=E+Math.imul(j,M0)|0,V=V+Math.imul(j,x)|0;var t0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(t0>>>26)|0,t0&=67108863,J=Math.imul(c,H0),E=Math.imul(c,W0),E=E+Math.imul(o,H0)|0,V=Math.imul(o,W0),J=J+Math.imul(r,D0)|0,E=E+Math.imul(r,_0)|0,E=E+Math.imul(e,D0)|0,V=V+Math.imul(e,_0)|0,J=J+Math.imul(f,k0)|0,E=E+Math.imul(f,z0)|0,E=E+Math.imul(h,k0)|0,V=V+Math.imul(h,z0)|0,J=J+Math.imul(m,v0)|0,E=E+Math.imul(m,S0)|0,E=E+Math.imul(U0,v0)|0,V=V+Math.imul(U0,S0)|0,J=J+Math.imul(t,j0)|0,E=E+Math.imul(t,N0)|0,E=E+Math.imul(d,j0)|0,V=V+Math.imul(d,N0)|0,J=J+Math.imul(p,M0)|0,E=E+Math.imul(p,x)|0,E=E+Math.imul(n,M0)|0,V=V+Math.imul(n,x)|0,J=J+Math.imul(H,a)|0,E=E+Math.imul(H,E0)|0,E=E+Math.imul(j,a)|0,V=V+Math.imul(j,E0)|0;var a0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(a0>>>26)|0,a0&=67108863,J=Math.imul(s,H0),E=Math.imul(s,W0),E=E+Math.imul(X0,H0)|0,V=Math.imul(X0,W0),J=J+Math.imul(c,D0)|0,E=E+Math.imul(c,_0)|0,E=E+Math.imul(o,D0)|0,V=V+Math.imul(o,_0)|0,J=J+Math.imul(r,k0)|0,E=E+Math.imul(r,z0)|0,E=E+Math.imul(e,k0)|0,V=V+Math.imul(e,z0)|0,J=J+Math.imul(f,v0)|0,E=E+Math.imul(f,S0)|0,E=E+Math.imul(h,v0)|0,V=V+Math.imul(h,S0)|0,J=J+Math.imul(m,j0)|0,E=E+Math.imul(m,N0)|0,E=E+Math.imul(U0,j0)|0,V=V+Math.imul(U0,N0)|0,J=J+Math.imul(t,M0)|0,E=E+Math.imul(t,x)|0,E=E+Math.imul(d,M0)|0,V=V+Math.imul(d,x)|0,J=J+Math.imul(p,a)|0,E=E+Math.imul(p,E0)|0,E=E+Math.imul(n,a)|0,V=V+Math.imul(n,E0)|0,J=J+Math.imul(H,A0)|0,E=E+Math.imul(H,F0)|0,E=E+Math.imul(j,A0)|0,V=V+Math.imul(j,F0)|0;var e0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(e0>>>26)|0,e0&=67108863,J=Math.imul(L0,H0),E=Math.imul(L0,W0),E=E+Math.imul($0,H0)|0,V=Math.imul($0,W0),J=J+Math.imul(s,D0)|0,E=E+Math.imul(s,_0)|0,E=E+Math.imul(X0,D0)|0,V=V+Math.imul(X0,_0)|0,J=J+Math.imul(c,k0)|0,E=E+Math.imul(c,z0)|0,E=E+Math.imul(o,k0)|0,V=V+Math.imul(o,z0)|0,J=J+Math.imul(r,v0)|0,E=E+Math.imul(r,S0)|0,E=E+Math.imul(e,v0)|0,V=V+Math.imul(e,S0)|0,J=J+Math.imul(f,j0)|0,E=E+Math.imul(f,N0)|0,E=E+Math.imul(h,j0)|0,V=V+Math.imul(h,N0)|0,J=J+Math.imul(m,M0)|0,E=E+Math.imul(m,x)|0,E=E+Math.imul(U0,M0)|0,V=V+Math.imul(U0,x)|0,J=J+Math.imul(t,a)|0,E=E+Math.imul(t,E0)|0,E=E+Math.imul(d,a)|0,V=V+Math.imul(d,E0)|0,J=J+Math.imul(p,A0)|0,E=E+Math.imul(p,F0)|0,E=E+Math.imul(n,A0)|0,V=V+Math.imul(n,F0)|0,J=J+Math.imul(H,q0)|0,E=E+Math.imul(H,B0)|0,E=E+Math.imul(j,q0)|0,V=V+Math.imul(j,B0)|0;var i0=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(i0>>>26)|0,i0&=67108863,J=Math.imul(V0,H0),E=Math.imul(V0,W0),E=E+Math.imul(K0,H0)|0,V=Math.imul(K0,W0),J=J+Math.imul(L0,D0)|0,E=E+Math.imul(L0,_0)|0,E=E+Math.imul($0,D0)|0,V=V+Math.imul($0,_0)|0,J=J+Math.imul(s,k0)|0,E=E+Math.imul(s,z0)|0,E=E+Math.imul(X0,k0)|0,V=V+Math.imul(X0,z0)|0,J=J+Math.imul(c,v0)|0,E=E+Math.imul(c,S0)|0,E=E+Math.imul(o,v0)|0,V=V+Math.imul(o,S0)|0,J=J+Math.imul(r,j0)|0,E=E+Math.imul(r,N0)|0,E=E+Math.imul(e,j0)|0,V=V+Math.imul(e,N0)|0,J=J+Math.imul(f,M0)|0,E=E+Math.imul(f,x)|0,E=E+Math.imul(h,M0)|0,V=V+Math.imul(h,x)|0,J=J+Math.imul(m,a)|0,E=E+Math.imul(m,E0)|0,E=E+Math.imul(U0,a)|0,V=V+Math.imul(U0,E0)|0,J=J+Math.imul(t,A0)|0,E=E+Math.imul(t,F0)|0,E=E+Math.imul(d,A0)|0,V=V+Math.imul(d,F0)|0,J=J+Math.imul(p,q0)|0,E=E+Math.imul(p,B0)|0,E=E+Math.imul(n,q0)|0,V=V+Math.imul(n,B0)|0,J=J+Math.imul(H,P0)|0,E=E+Math.imul(H,R0)|0,E=E+Math.imul(j,P0)|0,V=V+Math.imul(j,R0)|0;var UU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(UU>>>26)|0,UU&=67108863,J=Math.imul(V0,D0),E=Math.imul(V0,_0),E=E+Math.imul(K0,D0)|0,V=Math.imul(K0,_0),J=J+Math.imul(L0,k0)|0,E=E+Math.imul(L0,z0)|0,E=E+Math.imul($0,k0)|0,V=V+Math.imul($0,z0)|0,J=J+Math.imul(s,v0)|0,E=E+Math.imul(s,S0)|0,E=E+Math.imul(X0,v0)|0,V=V+Math.imul(X0,S0)|0,J=J+Math.imul(c,j0)|0,E=E+Math.imul(c,N0)|0,E=E+Math.imul(o,j0)|0,V=V+Math.imul(o,N0)|0,J=J+Math.imul(r,M0)|0,E=E+Math.imul(r,x)|0,E=E+Math.imul(e,M0)|0,V=V+Math.imul(e,x)|0,J=J+Math.imul(f,a)|0,E=E+Math.imul(f,E0)|0,E=E+Math.imul(h,a)|0,V=V+Math.imul(h,E0)|0,J=J+Math.imul(m,A0)|0,E=E+Math.imul(m,F0)|0,E=E+Math.imul(U0,A0)|0,V=V+Math.imul(U0,F0)|0,J=J+Math.imul(t,q0)|0,E=E+Math.imul(t,B0)|0,E=E+Math.imul(d,q0)|0,V=V+Math.imul(d,B0)|0,J=J+Math.imul(p,P0)|0,E=E+Math.imul(p,R0)|0,E=E+Math.imul(n,P0)|0,V=V+Math.imul(n,R0)|0;var EU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(EU>>>26)|0,EU&=67108863,J=Math.imul(V0,k0),E=Math.imul(V0,z0),E=E+Math.imul(K0,k0)|0,V=Math.imul(K0,z0),J=J+Math.imul(L0,v0)|0,E=E+Math.imul(L0,S0)|0,E=E+Math.imul($0,v0)|0,V=V+Math.imul($0,S0)|0,J=J+Math.imul(s,j0)|0,E=E+Math.imul(s,N0)|0,E=E+Math.imul(X0,j0)|0,V=V+Math.imul(X0,N0)|0,J=J+Math.imul(c,M0)|0,E=E+Math.imul(c,x)|0,E=E+Math.imul(o,M0)|0,V=V+Math.imul(o,x)|0,J=J+Math.imul(r,a)|0,E=E+Math.imul(r,E0)|0,E=E+Math.imul(e,a)|0,V=V+Math.imul(e,E0)|0,J=J+Math.imul(f,A0)|0,E=E+Math.imul(f,F0)|0,E=E+Math.imul(h,A0)|0,V=V+Math.imul(h,F0)|0,J=J+Math.imul(m,q0)|0,E=E+Math.imul(m,B0)|0,E=E+Math.imul(U0,q0)|0,V=V+Math.imul(U0,B0)|0,J=J+Math.imul(t,P0)|0,E=E+Math.imul(t,R0)|0,E=E+Math.imul(d,P0)|0,V=V+Math.imul(d,R0)|0;var XU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(XU>>>26)|0,XU&=67108863,J=Math.imul(V0,v0),E=Math.imul(V0,S0),E=E+Math.imul(K0,v0)|0,V=Math.imul(K0,S0),J=J+Math.imul(L0,j0)|0,E=E+Math.imul(L0,N0)|0,E=E+Math.imul($0,j0)|0,V=V+Math.imul($0,N0)|0,J=J+Math.imul(s,M0)|0,E=E+Math.imul(s,x)|0,E=E+Math.imul(X0,M0)|0,V=V+Math.imul(X0,x)|0,J=J+Math.imul(c,a)|0,E=E+Math.imul(c,E0)|0,E=E+Math.imul(o,a)|0,V=V+Math.imul(o,E0)|0,J=J+Math.imul(r,A0)|0,E=E+Math.imul(r,F0)|0,E=E+Math.imul(e,A0)|0,V=V+Math.imul(e,F0)|0,J=J+Math.imul(f,q0)|0,E=E+Math.imul(f,B0)|0,E=E+Math.imul(h,q0)|0,V=V+Math.imul(h,B0)|0,J=J+Math.imul(m,P0)|0,E=E+Math.imul(m,R0)|0,E=E+Math.imul(U0,P0)|0,V=V+Math.imul(U0,R0)|0;var IU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(IU>>>26)|0,IU&=67108863,J=Math.imul(V0,j0),E=Math.imul(V0,N0),E=E+Math.imul(K0,j0)|0,V=Math.imul(K0,N0),J=J+Math.imul(L0,M0)|0,E=E+Math.imul(L0,x)|0,E=E+Math.imul($0,M0)|0,V=V+Math.imul($0,x)|0,J=J+Math.imul(s,a)|0,E=E+Math.imul(s,E0)|0,E=E+Math.imul(X0,a)|0,V=V+Math.imul(X0,E0)|0,J=J+Math.imul(c,A0)|0,E=E+Math.imul(c,F0)|0,E=E+Math.imul(o,A0)|0,V=V+Math.imul(o,F0)|0,J=J+Math.imul(r,q0)|0,E=E+Math.imul(r,B0)|0,E=E+Math.imul(e,q0)|0,V=V+Math.imul(e,B0)|0,J=J+Math.imul(f,P0)|0,E=E+Math.imul(f,R0)|0,E=E+Math.imul(h,P0)|0,V=V+Math.imul(h,R0)|0;var TU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(TU>>>26)|0,TU&=67108863,J=Math.imul(V0,M0),E=Math.imul(V0,x),E=E+Math.imul(K0,M0)|0,V=Math.imul(K0,x),J=J+Math.imul(L0,a)|0,E=E+Math.imul(L0,E0)|0,E=E+Math.imul($0,a)|0,V=V+Math.imul($0,E0)|0,J=J+Math.imul(s,A0)|0,E=E+Math.imul(s,F0)|0,E=E+Math.imul(X0,A0)|0,V=V+Math.imul(X0,F0)|0,J=J+Math.imul(c,q0)|0,E=E+Math.imul(c,B0)|0,E=E+Math.imul(o,q0)|0,V=V+Math.imul(o,B0)|0,J=J+Math.imul(r,P0)|0,E=E+Math.imul(r,R0)|0,E=E+Math.imul(e,P0)|0,V=V+Math.imul(e,R0)|0;var YU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(YU>>>26)|0,YU&=67108863,J=Math.imul(V0,a),E=Math.imul(V0,E0),E=E+Math.imul(K0,a)|0,V=Math.imul(K0,E0),J=J+Math.imul(L0,A0)|0,E=E+Math.imul(L0,F0)|0,E=E+Math.imul($0,A0)|0,V=V+Math.imul($0,F0)|0,J=J+Math.imul(s,q0)|0,E=E+Math.imul(s,B0)|0,E=E+Math.imul(X0,q0)|0,V=V+Math.imul(X0,B0)|0,J=J+Math.imul(c,P0)|0,E=E+Math.imul(c,R0)|0,E=E+Math.imul(o,P0)|0,V=V+Math.imul(o,R0)|0;var ZU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(ZU>>>26)|0,ZU&=67108863,J=Math.imul(V0,A0),E=Math.imul(V0,F0),E=E+Math.imul(K0,A0)|0,V=Math.imul(K0,F0),J=J+Math.imul(L0,q0)|0,E=E+Math.imul(L0,B0)|0,E=E+Math.imul($0,q0)|0,V=V+Math.imul($0,B0)|0,J=J+Math.imul(s,P0)|0,E=E+Math.imul(s,R0)|0,E=E+Math.imul(X0,P0)|0,V=V+Math.imul(X0,R0)|0;var OU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(OU>>>26)|0,OU&=67108863,J=Math.imul(V0,q0),E=Math.imul(V0,B0),E=E+Math.imul(K0,q0)|0,V=Math.imul(K0,B0),J=J+Math.imul(L0,P0)|0,E=E+Math.imul(L0,R0)|0,E=E+Math.imul($0,P0)|0,V=V+Math.imul($0,R0)|0;var QU=($+J|0)+((E&8191)<<13)|0;$=(V+(E>>>13)|0)+(QU>>>26)|0,QU&=67108863,J=Math.imul(V0,P0),E=Math.imul(V0,R0),E=E+Math.imul(K0,P0)|0,V=Math.imul(K0,R0);var JU=($+J|0)+((E&8191)<<13)|0;if($=(V+(E>>>13)|0)+(JU>>>26)|0,JU&=67108863,A[0]=s0,A[1]=c0,A[2]=f0,A[3]=d0,A[4]=b0,A[5]=t0,A[6]=a0,A[7]=e0,A[8]=i0,A[9]=UU,A[10]=EU,A[11]=XU,A[12]=IU,A[13]=TU,A[14]=YU,A[15]=ZU,A[16]=OU,A[17]=QU,A[18]=JU,$!==0)A[19]=$,Q.length++;return Q};if(!Math.imul)_=k;function N(U,I,Q){Q.negative=I.negative^U.negative,Q.length=U.length+I.length;var X=0,Z=0;for(var A=0;A>>26)|0,Z+=$>>>26,$&=67108863}Q.words[A]=J,X=$,$=Z}if(X!==0)Q.words[A]=X;else Q.length--;return Q.strip()}function v(U,I,Q){var X=new B;return X.mulp(U,I,Q)}O.prototype.mulTo=function(U,I){var Q,X=this.length+U.length;if(this.length===10&&U.length===10)Q=_(this,U,I);else if(X<63)Q=k(this,U,I);else if(X<1024)Q=N(this,U,I);else Q=v(this,U,I);return Q};function B(U,I){this.x=U,this.y=I}B.prototype.makeRBT=function(U){var I=Array(U),Q=O.prototype._countBits(U)-1;for(var X=0;X>=1;return X},B.prototype.permute=function(U,I,Q,X,Z,A){for(var $=0;$>>1)Z++;return 1<>>13,Q[2*A+1]=Z&8191,Z=Z>>>13;for(A=2*I;A>=26,I+=X/67108864|0,I+=Z>>>26,this.words[Q]=Z&67108863}if(I!==0)this.words[Q]=I,this.length++;return this.length=U===0?1:this.length,this},O.prototype.muln=function(U){return this.clone().imuln(U)},O.prototype.sqr=function(){return this.mul(this)},O.prototype.isqr=function(){return this.imul(this.clone())},O.prototype.pow=function(U){var I=P(U);if(I.length===0)return new O(1);var Q=this;for(var X=0;X=0);var I=U%26,Q=(U-I)/26,X=67108863>>>26-I<<26-I,Z;if(I!==0){var A=0;for(Z=0;Z>>26-I}if(A)this.words[Z]=A,this.length++}if(Q!==0){for(Z=this.length-1;Z>=0;Z--)this.words[Z+Q]=this.words[Z];for(Z=0;Z=0);var X;if(I)X=(I-I%26)/26;else X=0;var Z=U%26,A=Math.min((U-Z)/26,this.length),$=67108863^67108863>>>Z<A){this.length-=A;for(E=0;E=0&&(V!==0||E>=X);E--){var S=this.words[E]|0;this.words[E]=V<<26-Z|S>>>Z,V=S&$}if(J&&V!==0)J.words[J.length++]=V;if(this.length===0)this.words[0]=0,this.length=1;return this.strip()},O.prototype.ishrn=function(U,I,Q){return L(this.negative===0),this.iushrn(U,I,Q)},O.prototype.shln=function(U){return this.clone().ishln(U)},O.prototype.ushln=function(U){return this.clone().iushln(U)},O.prototype.shrn=function(U){return this.clone().ishrn(U)},O.prototype.ushrn=function(U){return this.clone().iushrn(U)},O.prototype.testn=function(U){L(typeof U==="number"&&U>=0);var I=U%26,Q=(U-I)/26,X=1<=0);var I=U%26,Q=(U-I)/26;if(L(this.negative===0,"imaskn works only with positive numbers"),this.length<=Q)return this;if(I!==0)Q++;if(this.length=Math.min(Q,this.length),I!==0){var X=67108863^67108863>>>I<=67108864;I++)if(this.words[I]-=67108864,I===this.length-1)this.words[I+1]=1;else this.words[I+1]++;return this.length=Math.max(this.length,I+1),this},O.prototype.isubn=function(U){if(L(typeof U==="number"),L(U<67108864),U<0)return this.iaddn(-U);if(this.negative!==0)return this.negative=0,this.iaddn(U),this.negative=1,this;if(this.words[0]-=U,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var I=0;I>26)-(J/67108864|0),this.words[Z+Q]=A&67108863}for(;Z>26,this.words[Z+Q]=A&67108863;if($===0)return this.strip();L($===-1),$=0;for(Z=0;Z>26,this.words[Z]=A&67108863;return this.negative=1,this.strip()},O.prototype._wordDiv=function(U,I){var Q=this.length-U.length,X=this.clone(),Z=U,A=Z.words[Z.length-1]|0,$=this._countBits(A);if(Q=26-$,Q!==0)Z=Z.ushln(Q),X.iushln(Q),A=Z.words[Z.length-1]|0;var J=X.length-Z.length,E;if(I!=="mod"){E=new O(null),E.length=J+1,E.words=Array(E.length);for(var V=0;V=0;H--){var j=(X.words[Z.length+H]|0)*67108864+(X.words[Z.length+H-1]|0);j=Math.min(j/A|0,67108863),X._ishlnsubmul(Z,j,H);while(X.negative!==0)if(j--,X.negative=0,X._ishlnsubmul(Z,1,H),!X.isZero())X.negative^=1;if(E)E.words[H]=j}if(E)E.strip();if(X.strip(),I!=="div"&&Q!==0)X.iushrn(Q);return{div:E||null,mod:X}},O.prototype.divmod=function(U,I,Q){if(L(!U.isZero()),this.isZero())return{div:new O(0),mod:new O(0)};var X,Z,A;if(this.negative!==0&&U.negative===0){if(A=this.neg().divmod(U,I),I!=="mod")X=A.div.neg();if(I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.iadd(U)}return{div:X,mod:Z}}if(this.negative===0&&U.negative!==0){if(A=this.divmod(U.neg(),I),I!=="mod")X=A.div.neg();return{div:X,mod:A.mod}}if((this.negative&U.negative)!==0){if(A=this.neg().divmod(U.neg(),I),I!=="div"){if(Z=A.mod.neg(),Q&&Z.negative!==0)Z.isub(U)}return{div:A.div,mod:Z}}if(U.length>this.length||this.cmp(U)<0)return{div:new O(0),mod:this};if(U.length===1){if(I==="div")return{div:this.divn(U.words[0]),mod:null};if(I==="mod")return{div:null,mod:new O(this.modn(U.words[0]))};return{div:this.divn(U.words[0]),mod:new O(this.modn(U.words[0]))}}return this._wordDiv(U,I)},O.prototype.div=function(U){return this.divmod(U,"div",!1).div},O.prototype.mod=function(U){return this.divmod(U,"mod",!1).mod},O.prototype.umod=function(U){return this.divmod(U,"mod",!0).mod},O.prototype.divRound=function(U){var I=this.divmod(U);if(I.mod.isZero())return I.div;var Q=I.div.negative!==0?I.mod.isub(U):I.mod,X=U.ushrn(1),Z=U.andln(1),A=Q.cmp(X);if(A<0||Z===1&&A===0)return I.div;return I.div.negative!==0?I.div.isubn(1):I.div.iaddn(1)},O.prototype.modn=function(U){L(U<=67108863);var I=67108864%U,Q=0;for(var X=this.length-1;X>=0;X--)Q=(I*Q+(this.words[X]|0))%U;return Q},O.prototype.idivn=function(U){L(U<=67108863);var I=0;for(var Q=this.length-1;Q>=0;Q--){var X=(this.words[Q]|0)+I*67108864;this.words[Q]=X/U|0,I=X%U}return this.strip()},O.prototype.divn=function(U){return this.clone().idivn(U)},O.prototype.egcd=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=new O(0),$=new O(1),J=0;while(I.isEven()&&Q.isEven())I.iushrn(1),Q.iushrn(1),++J;var E=Q.clone(),V=I.clone();while(!I.isZero()){for(var S=0,H=1;(I.words[0]&H)===0&&S<26;++S,H<<=1);if(S>0){I.iushrn(S);while(S-- >0){if(X.isOdd()||Z.isOdd())X.iadd(E),Z.isub(V);X.iushrn(1),Z.iushrn(1)}}for(var j=0,w=1;(Q.words[0]&w)===0&&j<26;++j,w<<=1);if(j>0){Q.iushrn(j);while(j-- >0){if(A.isOdd()||$.isOdd())A.iadd(E),$.isub(V);A.iushrn(1),$.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(A),Z.isub($);else Q.isub(I),A.isub(X),$.isub(Z)}return{a:A,b:$,gcd:Q.iushln(J)}},O.prototype._invmp=function(U){L(U.negative===0),L(!U.isZero());var I=this,Q=U.clone();if(I.negative!==0)I=I.umod(U);else I=I.clone();var X=new O(1),Z=new O(0),A=Q.clone();while(I.cmpn(1)>0&&Q.cmpn(1)>0){for(var $=0,J=1;(I.words[0]&J)===0&&$<26;++$,J<<=1);if($>0){I.iushrn($);while($-- >0){if(X.isOdd())X.iadd(A);X.iushrn(1)}}for(var E=0,V=1;(Q.words[0]&V)===0&&E<26;++E,V<<=1);if(E>0){Q.iushrn(E);while(E-- >0){if(Z.isOdd())Z.iadd(A);Z.iushrn(1)}}if(I.cmp(Q)>=0)I.isub(Q),X.isub(Z);else Q.isub(I),Z.isub(X)}var S;if(I.cmpn(1)===0)S=X;else S=Z;if(S.cmpn(0)<0)S.iadd(U);return S},O.prototype.gcd=function(U){if(this.isZero())return U.abs();if(U.isZero())return this.abs();var I=this.clone(),Q=U.clone();I.negative=0,Q.negative=0;for(var X=0;I.isEven()&&Q.isEven();X++)I.iushrn(1),Q.iushrn(1);do{while(I.isEven())I.iushrn(1);while(Q.isEven())Q.iushrn(1);var Z=I.cmp(Q);if(Z<0){var A=I;I=Q,Q=A}else if(Z===0||Q.cmpn(1)===0)break;I.isub(Q)}while(!0);return Q.iushln(X)},O.prototype.invm=function(U){return this.egcd(U).a.umod(U)},O.prototype.isEven=function(){return(this.words[0]&1)===0},O.prototype.isOdd=function(){return(this.words[0]&1)===1},O.prototype.andln=function(U){return this.words[0]&U},O.prototype.bincn=function(U){L(typeof U==="number");var I=U%26,Q=(U-I)/26,X=1<>>26,$&=67108863,this.words[A]=$}if(Z!==0)this.words[A]=Z,this.length++;return this},O.prototype.isZero=function(){return this.length===1&&this.words[0]===0},O.prototype.cmpn=function(U){var I=U<0;if(this.negative!==0&&!I)return-1;if(this.negative===0&&I)return 1;this.strip();var Q;if(this.length>1)Q=1;else{if(I)U=-U;L(U<=67108863,"Number is too big");var X=this.words[0]|0;Q=X===U?0:XU.length)return 1;if(this.length=0;Q--){var X=this.words[Q]|0,Z=U.words[Q]|0;if(X===Z)continue;if(XZ)I=1;break}return I},O.prototype.gtn=function(U){return this.cmpn(U)===1},O.prototype.gt=function(U){return this.cmp(U)===1},O.prototype.gten=function(U){return this.cmpn(U)>=0},O.prototype.gte=function(U){return this.cmp(U)>=0},O.prototype.ltn=function(U){return this.cmpn(U)===-1},O.prototype.lt=function(U){return this.cmp(U)===-1},O.prototype.lten=function(U){return this.cmpn(U)<=0},O.prototype.lte=function(U){return this.cmp(U)<=0},O.prototype.eqn=function(U){return this.cmpn(U)===0},O.prototype.eq=function(U){return this.cmp(U)===0},O.red=function(U){return new u(U)},O.prototype.toRed=function(U){return L(!this.red,"Already a number in reduction context"),L(this.negative===0,"red works only with positives"),U.convertTo(this)._forceRed(U)},O.prototype.fromRed=function(){return L(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},O.prototype._forceRed=function(U){return this.red=U,this},O.prototype.forceRed=function(U){return L(!this.red,"Already a number in reduction context"),this._forceRed(U)},O.prototype.redAdd=function(U){return L(this.red,"redAdd works only with red numbers"),this.red.add(this,U)},O.prototype.redIAdd=function(U){return L(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,U)},O.prototype.redSub=function(U){return L(this.red,"redSub works only with red numbers"),this.red.sub(this,U)},O.prototype.redISub=function(U){return L(this.red,"redISub works only with red numbers"),this.red.isub(this,U)},O.prototype.redShl=function(U){return L(this.red,"redShl works only with red numbers"),this.red.shl(this,U)},O.prototype.redMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.mul(this,U)},O.prototype.redIMul=function(U){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,U),this.red.imul(this,U)},O.prototype.redSqr=function(){return L(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},O.prototype.redISqr=function(){return L(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},O.prototype.redSqrt=function(){return L(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},O.prototype.redInvm=function(){return L(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},O.prototype.redNeg=function(){return L(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},O.prototype.redPow=function(U){return L(this.red&&!U.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,U)};var g={k256:null,p224:null,p192:null,p25519:null};function y(U,I){this.name=U,this.p=new O(I,16),this.n=this.p.bitLength(),this.k=new O(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}y.prototype._tmp=function(){var U=new O(null);return U.words=Array(Math.ceil(this.n/13)),U},y.prototype.ireduce=function(U){var I=U,Q;do this.split(I,this.tmp),I=this.imulK(I),I=I.iadd(this.tmp),Q=I.bitLength();while(Q>this.n);var X=Q0)I.isub(this.p);else if(I.strip!==void 0)I.strip();else I._strip();return I},y.prototype.split=function(U,I){U.iushrn(this.n,0,I)},y.prototype.imulK=function(U){return U.imul(this.k)};function l(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}W(l,y),l.prototype.split=function(U,I){var Q=4194303,X=Math.min(U.length,9);for(var Z=0;Z>>22,A=$}if(A>>>=22,U.words[Z-10]=A,A===0&&U.length>10)U.length-=10;else U.length-=9},l.prototype.imulK=function(U){U.words[U.length]=0,U.words[U.length+1]=0,U.length+=2;var I=0;for(var Q=0;Q>>=26,U.words[Q]=Z,I=X}if(I!==0)U.words[U.length++]=I;return U},O._prime=function(U){if(g[U])return g[U];var I;if(U==="k256")I=new l;else if(U==="p224")I=new Y0;else if(U==="p192")I=new O0;else if(U==="p25519")I=new Z0;else throw Error("Unknown prime "+U);return g[U]=I,I};function u(U){if(typeof U==="string"){var I=O._prime(U);this.m=I.p,this.prime=I}else L(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}u.prototype._verify1=function(U){L(U.negative===0,"red works only with positives"),L(U.red,"red works only with red numbers")},u.prototype._verify2=function(U,I){L((U.negative|I.negative)===0,"red works only with positives"),L(U.red&&U.red===I.red,"red works only with red numbers")},u.prototype.imod=function(U){if(this.prime)return this.prime.ireduce(U)._forceRed(this);return U.umod(this.m)._forceRed(this)},u.prototype.neg=function(U){if(U.isZero())return U.clone();return this.m.sub(U)._forceRed(this)},u.prototype.add=function(U,I){this._verify2(U,I);var Q=U.add(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q._forceRed(this)},u.prototype.iadd=function(U,I){this._verify2(U,I);var Q=U.iadd(I);if(Q.cmp(this.m)>=0)Q.isub(this.m);return Q},u.prototype.sub=function(U,I){this._verify2(U,I);var Q=U.sub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q._forceRed(this)},u.prototype.isub=function(U,I){this._verify2(U,I);var Q=U.isub(I);if(Q.cmpn(0)<0)Q.iadd(this.m);return Q},u.prototype.shl=function(U,I){return this._verify1(U),this.imod(U.ushln(I))},u.prototype.imul=function(U,I){return this._verify2(U,I),this.imod(U.imul(I))},u.prototype.mul=function(U,I){return this._verify2(U,I),this.imod(U.mul(I))},u.prototype.isqr=function(U){return this.imul(U,U.clone())},u.prototype.sqr=function(U){return this.mul(U,U)},u.prototype.sqrt=function(U){if(U.isZero())return U.clone();var I=this.m.andln(3);if(L(I%2===1),I===3){var Q=this.m.add(new O(1)).iushrn(2);return this.pow(U,Q)}var X=this.m.subn(1),Z=0;while(!X.isZero()&&X.andln(1)===0)Z++,X.iushrn(1);L(!X.isZero());var A=new O(1).toRed(this),$=A.redNeg(),J=this.m.subn(1).iushrn(1),E=this.m.bitLength();E=new O(2*E*E).toRed(this);while(this.pow(E,J).cmp($)!==0)E.redIAdd($);var V=this.pow(E,X),S=this.pow(U,X.addn(1).iushrn(1)),H=this.pow(U,X),j=Z;while(H.cmp(A)!==0){var w=H;for(var p=0;w.cmp(A)!==0;p++)w=w.redSqr();L(p=0;Z--){var V=I.words[Z];for(var S=E-1;S>=0;S--){var H=V>>S&1;if(A!==X[0])A=this.sqr(A);if(H===0&&$===0){J=0;continue}if($<<=1,$|=H,J++,J!==Q&&(Z!==0||S!==0))continue;A=this.mul(A,X[$]),J=0,$=0}E=26}return A},u.prototype.convertTo=function(U){var I=U.umod(this.m);return I===U?I.clone():I},u.prototype.convertFrom=function(U){var I=U.clone();return I.red=null,I},O.mont=function(U){return new i(U)};function i(U){if(u.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new O(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}W(i,u),i.prototype.convertTo=function(U){return this.imod(U.ushln(this.shift))},i.prototype.convertFrom=function(U){var I=this.imod(U.mul(this.rinv));return I.red=null,I},i.prototype.imul=function(U,I){if(U.isZero()||I.isZero())return U.words[0]=0,U.length=1,U;var Q=U.imul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.mul=function(U,I){if(U.isZero()||I.isZero())return new O(0)._forceRed(this);var Q=U.mul(I),X=Q.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),Z=Q.isub(X).iushrn(this.shift),A=Z;if(Z.cmp(this.m)>=0)A=Z.isub(this.m);else if(Z.cmpn(0)<0)A=Z.iadd(this.m);return A._forceRed(this)},i.prototype.invm=function(U){var I=this.imod(U._invmp(this.m).mul(this.r2));return I._forceRed(this)}})(typeof Y>"u"||Y,T)}),jT=Q0((T,Y)=>{var G=gX(),K=SU().Buffer;function L(W,O){return K.from(W.toRed(G.mont(O.modulus)).redPow(new G(O.publicExponent)).fromRed().toArray())}Y.exports=L}),NQ=Q0((T,Y)=>{(function(G,K){function L(X,Z){if(!X)throw Error(Z||"Assertion failed")}function W(X,Z){X.super_=Z;var A=function(){};A.prototype=Z.prototype,X.prototype=new A,X.prototype.constructor=X}function O(X,Z,A){if(O.isBN(X))return X;if(this.negative=0,this.words=null,this.length=0,this.red=null,X!==null){if(Z==="le"||Z==="be")A=Z,Z=10;this._init(X||0,Z||10,A||"be")}}if(typeof G==="object")G.exports=O;else K.BN=O;O.BN=O,O.wordSize=26;var z;try{if(typeof window<"u"&&typeof window.Buffer<"u")z=window.Buffer;else z=(FU(),h0(KU)).Buffer}catch(X){}O.isBN=function(X){if(X instanceof O)return!0;return X!==null&&typeof X==="object"&&X.constructor.wordSize===O.wordSize&&Array.isArray(X.words)},O.max=function(X,Z){if(X.cmp(Z)>0)return X;return Z},O.min=function(X,Z){if(X.cmp(Z)<0)return X;return Z},O.prototype._init=function(X,Z,A){if(typeof X==="number")return this._initNumber(X,Z,A);if(typeof X==="object")return this._initArray(X,Z,A);if(Z==="hex")Z=16;L(Z===(Z|0)&&Z>=2&&Z<=36),X=X.toString().replace(/\s+/g,"");var $=0;if(X[0]==="-")$++,this.negative=1;if($=0;$-=3)if(E=X[$]|X[$-1]<<8|X[$-2]<<16,this.words[J]|=E<>>26-V&67108863,V+=24,V>=26)V-=26,J++}else if(A==="le"){for($=0,J=0;$>>26-V&67108863,V+=24,V>=26)V-=26,J++}return this._strip()};function q(X,Z){var A=X.charCodeAt(Z);if(A>=48&&A<=57)return A-48;else if(A>=65&&A<=70)return A-55;else if(A>=97&&A<=102)return A-87;else L(!1,"Invalid character in "+X)}function D(X,Z,A){var $=q(X,A);if(A-1>=Z)$|=q(X,A-1)<<4;return $}O.prototype._parseHex=function(X,Z,A){this.length=Math.ceil((X.length-Z)/6),this.words=Array(this.length);for(var $=0;$=Z;$-=2)if(V=D(X,Z,$)<=18)J-=18,E+=1,this.words[E]|=V>>>26;else J+=8;else{var S=X.length-Z;for($=S%2===0?Z+1:Z;$=18)J-=18,E+=1,this.words[E]|=V>>>26;else J+=8}this._strip()};function C(X,Z,A,$){var J=0,E=0,V=Math.min(X.length,A);for(var S=Z;S=49)E=H-49+10;else if(H>=17)E=H-17+10;else E=H;L(H>=0&&E<$,"Invalid character"),J+=E}return J}O.prototype._parseBase=function(X,Z,A){this.words=[0],this.length=1;for(var $=0,J=1;J<=67108863;J*=Z)$++;$--,J=J/Z|0;var E=X.length-A,V=E%$,S=Math.min(E,E-V)+A,H=0;for(var j=A;j1&&this.words[this.length-1]===0)this.length--;return this._normSign()},O.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},typeof Symbol<"u"&&typeof Symbol.for==="function")try{O.prototype[Symbol.for("nodejs.util.inspect.custom")]=R}catch(X){O.prototype.inspect=R}else O.prototype.inspect=R;function R(){return(this.red?""}var M=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],P=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(O.prototype.toString=function(X,Z){X=X||10,Z=Z|0||1;var A;if(X===16||X==="hex"){A="";var $=0,J=0;for(var E=0;E>>24-$&16777215,$+=2,$>=26)$-=26,E--;if(J!==0||E!==this.length-1)A=M[6-S.length]+S+A;else A=S+A}if(J!==0)A=J.toString(16)+A;while(A.length%Z!==0)A="0"+A;if(this.negative!==0)A="-"+A;return A}if(X===(X|0)&&X>=2&&X<=36){var H=P[X],j=k[X];A="";var w=this.clone();w.negative=0;while(!w.isZero()){var p=w.modrn(j).toString(X);if(w=w.idivn(j),!w.isZero())A=M[H-p.length]+p+A;else A=p+A}if(this.isZero())A="0"+A;while(A.length%Z!==0)A="0"+A;if(this.negative!==0)A="-"+A;return A}L(!1,"Base should be between 2 and 36")},O.prototype.toNumber=function(){var X=this.words[0];if(this.length===2)X+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)X+=4503599627370496+this.words[1]*67108864;else if(this.length>2)L(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-X:X},O.prototype.toJSON=function(){return this.toString(16,2)},z)O.prototype.toBuffer=function(X,Z){return this.toArrayLike(z,X,Z)};O.prototype.toArray=function(X,Z){return this.toArrayLike(Array,X,Z)};var _=function(X,Z){if(X.allocUnsafe)return X.allocUnsafe(Z);return new X(Z)};if(O.prototype.toArrayLike=function(X,Z,A){this._strip();var $=this.byteLength(),J=A||Math.max(1,$);L($<=J,"byte array longer than desired length"),L(J>0,"Requested array length <= 0");var E=_(X,J),V=Z==="le"?"LE":"BE";return this["_toArrayLike"+V](E,$),E},O.prototype._toArrayLikeLE=function(X,Z){var A=0,$=0;for(var J=0,E=0;J>8&255;if(A>16&255;if(E===6){if(A>24&255;$=0,E=0}else $=V>>>24,E+=2}if(A=0)X[A--]=V>>8&255;if(A>=0)X[A--]=V>>16&255;if(E===6){if(A>=0)X[A--]=V>>24&255;$=0,E=0}else $=V>>>24,E+=2}if(A>=0){X[A--]=$;while(A>=0)X[A--]=0}},Math.clz32)O.prototype._countBits=function(X){return 32-Math.clz32(X)};else O.prototype._countBits=function(X){var Z=X,A=0;if(Z>=4096)A+=13,Z>>>=13;if(Z>=64)A+=7,Z>>>=7;if(Z>=8)A+=4,Z>>>=4;if(Z>=2)A+=2,Z>>>=2;return A+Z};O.prototype._zeroBits=function(X){if(X===0)return 26;var Z=X,A=0;if((Z&8191)===0)A+=13,Z>>>=13;if((Z&127)===0)A+=7,Z>>>=7;if((Z&15)===0)A+=4,Z>>>=4;if((Z&3)===0)A+=2,Z>>>=2;if((Z&1)===0)A++;return A},O.prototype.bitLength=function(){var X=this.words[this.length-1],Z=this._countBits(X);return(this.length-1)*26+Z};function N(X){var Z=Array(X.bitLength());for(var A=0;A>>J&1}return Z}O.prototype.zeroBits=function(){if(this.isZero())return 0;var X=0;for(var Z=0;ZX.length)return this.clone().ior(X);return X.clone().ior(this)},O.prototype.uor=function(X){if(this.length>X.length)return this.clone().iuor(X);return X.clone().iuor(this)},O.prototype.iuand=function(X){var Z;if(this.length>X.length)Z=X;else Z=this;for(var A=0;AX.length)return this.clone().iand(X);return X.clone().iand(this)},O.prototype.uand=function(X){if(this.length>X.length)return this.clone().iuand(X);return X.clone().iuand(this)},O.prototype.iuxor=function(X){var Z,A;if(this.length>X.length)Z=this,A=X;else Z=X,A=this;for(var $=0;$X.length)return this.clone().ixor(X);return X.clone().ixor(this)},O.prototype.uxor=function(X){if(this.length>X.length)return this.clone().iuxor(X);return X.clone().iuxor(this)},O.prototype.inotn=function(X){L(typeof X==="number"&&X>=0);var Z=Math.ceil(X/26)|0,A=X%26;if(this._expand(Z),A>0)Z--;for(var $=0;$0)this.words[$]=~this.words[$]&67108863>>26-A;return this._strip()},O.prototype.notn=function(X){return this.clone().inotn(X)},O.prototype.setn=function(X,Z){L(typeof X==="number"&&X>=0);var A=X/26|0,$=X%26;if(this._expand(A+1),Z)this.words[A]=this.words[A]|1<<$;else this.words[A]=this.words[A]&~(1<<$);return this._strip()},O.prototype.iadd=function(X){var Z;if(this.negative!==0&&X.negative===0)return this.negative=0,Z=this.isub(X),this.negative^=1,this._normSign();else if(this.negative===0&&X.negative!==0)return X.negative=0,Z=this.isub(X),X.negative=1,Z._normSign();var A,$;if(this.length>X.length)A=this,$=X;else A=X,$=this;var J=0;for(var E=0;E<$.length;E++)Z=(A.words[E]|0)+($.words[E]|0)+J,this.words[E]=Z&67108863,J=Z>>>26;for(;J!==0&&E>>26;if(this.length=A.length,J!==0)this.words[this.length]=J,this.length++;else if(A!==this)for(;EX.length)return this.clone().iadd(X);return X.clone().iadd(this)},O.prototype.isub=function(X){if(X.negative!==0){X.negative=0;var Z=this.iadd(X);return X.negative=1,Z._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(X),this.negative=1,this._normSign();var A=this.cmp(X);if(A===0)return this.negative=0,this.length=1,this.words[0]=0,this;var $,J;if(A>0)$=this,J=X;else $=X,J=this;var E=0;for(var V=0;V>26,this.words[V]=Z&67108863;for(;E!==0&&V<$.length;V++)Z=($.words[V]|0)+E,E=Z>>26,this.words[V]=Z&67108863;if(E===0&&V<$.length&&$!==this)for(;V<$.length;V++)this.words[V]=$.words[V];if(this.length=Math.max(this.length,V),$!==this)this.negative=1;return this._strip()},O.prototype.sub=function(X){return this.clone().isub(X)};function v(X,Z,A){A.negative=Z.negative^X.negative;var $=X.length+Z.length|0;A.length=$,$=$-1|0;var J=X.words[0]|0,E=Z.words[0]|0,V=J*E,S=V&67108863,H=V/67108864|0;A.words[0]=S;for(var j=1;j<$;j++){var w=H>>>26,p=H&67108863,n=Math.min(j,Z.length-1);for(var G0=Math.max(0,j-X.length+1);G0<=n;G0++){var t=j-G0|0;J=X.words[t]|0,E=Z.words[G0]|0,V=J*E+p,w+=V/67108864|0,p=V&67108863}A.words[j]=p|0,H=w|0}if(H!==0)A.words[j]=H|0;else A.length--;return A._strip()}var B=function(X,Z,A){var $=X.words,J=Z.words,E=A.words,V=0,S,H,j,w=$[0]|0,p=w&8191,n=w>>>13,G0=$[1]|0,t=G0&8191,d=G0>>>13,I0=$[2]|0,m=I0&8191,U0=I0>>>13,g0=$[3]|0,f=g0&8191,h=g0>>>13,T0=$[4]|0,r=T0&8191,e=T0>>>13,C0=$[5]|0,c=C0&8191,o=C0>>>13,x0=$[6]|0,s=x0&8191,X0=x0>>>13,y0=$[7]|0,L0=y0&8191,$0=y0>>>13,n0=$[8]|0,V0=n0&8191,K0=n0>>>13,r0=$[9]|0,H0=r0&8191,W0=r0>>>13,RU=J[0]|0,D0=RU&8191,_0=RU>>>13,CU=J[1]|0,k0=CU&8191,z0=CU>>>13,WU=J[2]|0,v0=WU&8191,S0=WU>>>13,AU=J[3]|0,j0=AU&8191,N0=AU>>>13,LU=J[4]|0,M0=LU&8191,x=LU>>>13,b=J[5]|0,a=b&8191,E0=b>>>13,w0=J[6]|0,A0=w0&8191,F0=w0>>>13,m0=J[7]|0,q0=m0&8191,B0=m0>>>13,HU=J[8]|0,P0=HU&8191,R0=HU>>>13,s0=J[9]|0,c0=s0&8191,f0=s0>>>13;A.negative=X.negative^Z.negative,A.length=19,S=Math.imul(p,D0),H=Math.imul(p,_0),H=H+Math.imul(n,D0)|0,j=Math.imul(n,_0);var d0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(d0>>>26)|0,d0&=67108863,S=Math.imul(t,D0),H=Math.imul(t,_0),H=H+Math.imul(d,D0)|0,j=Math.imul(d,_0),S=S+Math.imul(p,k0)|0,H=H+Math.imul(p,z0)|0,H=H+Math.imul(n,k0)|0,j=j+Math.imul(n,z0)|0;var b0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(b0>>>26)|0,b0&=67108863,S=Math.imul(m,D0),H=Math.imul(m,_0),H=H+Math.imul(U0,D0)|0,j=Math.imul(U0,_0),S=S+Math.imul(t,k0)|0,H=H+Math.imul(t,z0)|0,H=H+Math.imul(d,k0)|0,j=j+Math.imul(d,z0)|0,S=S+Math.imul(p,v0)|0,H=H+Math.imul(p,S0)|0,H=H+Math.imul(n,v0)|0,j=j+Math.imul(n,S0)|0;var t0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(t0>>>26)|0,t0&=67108863,S=Math.imul(f,D0),H=Math.imul(f,_0),H=H+Math.imul(h,D0)|0,j=Math.imul(h,_0),S=S+Math.imul(m,k0)|0,H=H+Math.imul(m,z0)|0,H=H+Math.imul(U0,k0)|0,j=j+Math.imul(U0,z0)|0,S=S+Math.imul(t,v0)|0,H=H+Math.imul(t,S0)|0,H=H+Math.imul(d,v0)|0,j=j+Math.imul(d,S0)|0,S=S+Math.imul(p,j0)|0,H=H+Math.imul(p,N0)|0,H=H+Math.imul(n,j0)|0,j=j+Math.imul(n,N0)|0;var a0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(a0>>>26)|0,a0&=67108863,S=Math.imul(r,D0),H=Math.imul(r,_0),H=H+Math.imul(e,D0)|0,j=Math.imul(e,_0),S=S+Math.imul(f,k0)|0,H=H+Math.imul(f,z0)|0,H=H+Math.imul(h,k0)|0,j=j+Math.imul(h,z0)|0,S=S+Math.imul(m,v0)|0,H=H+Math.imul(m,S0)|0,H=H+Math.imul(U0,v0)|0,j=j+Math.imul(U0,S0)|0,S=S+Math.imul(t,j0)|0,H=H+Math.imul(t,N0)|0,H=H+Math.imul(d,j0)|0,j=j+Math.imul(d,N0)|0,S=S+Math.imul(p,M0)|0,H=H+Math.imul(p,x)|0,H=H+Math.imul(n,M0)|0,j=j+Math.imul(n,x)|0;var e0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(e0>>>26)|0,e0&=67108863,S=Math.imul(c,D0),H=Math.imul(c,_0),H=H+Math.imul(o,D0)|0,j=Math.imul(o,_0),S=S+Math.imul(r,k0)|0,H=H+Math.imul(r,z0)|0,H=H+Math.imul(e,k0)|0,j=j+Math.imul(e,z0)|0,S=S+Math.imul(f,v0)|0,H=H+Math.imul(f,S0)|0,H=H+Math.imul(h,v0)|0,j=j+Math.imul(h,S0)|0,S=S+Math.imul(m,j0)|0,H=H+Math.imul(m,N0)|0,H=H+Math.imul(U0,j0)|0,j=j+Math.imul(U0,N0)|0,S=S+Math.imul(t,M0)|0,H=H+Math.imul(t,x)|0,H=H+Math.imul(d,M0)|0,j=j+Math.imul(d,x)|0,S=S+Math.imul(p,a)|0,H=H+Math.imul(p,E0)|0,H=H+Math.imul(n,a)|0,j=j+Math.imul(n,E0)|0;var i0=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(i0>>>26)|0,i0&=67108863,S=Math.imul(s,D0),H=Math.imul(s,_0),H=H+Math.imul(X0,D0)|0,j=Math.imul(X0,_0),S=S+Math.imul(c,k0)|0,H=H+Math.imul(c,z0)|0,H=H+Math.imul(o,k0)|0,j=j+Math.imul(o,z0)|0,S=S+Math.imul(r,v0)|0,H=H+Math.imul(r,S0)|0,H=H+Math.imul(e,v0)|0,j=j+Math.imul(e,S0)|0,S=S+Math.imul(f,j0)|0,H=H+Math.imul(f,N0)|0,H=H+Math.imul(h,j0)|0,j=j+Math.imul(h,N0)|0,S=S+Math.imul(m,M0)|0,H=H+Math.imul(m,x)|0,H=H+Math.imul(U0,M0)|0,j=j+Math.imul(U0,x)|0,S=S+Math.imul(t,a)|0,H=H+Math.imul(t,E0)|0,H=H+Math.imul(d,a)|0,j=j+Math.imul(d,E0)|0,S=S+Math.imul(p,A0)|0,H=H+Math.imul(p,F0)|0,H=H+Math.imul(n,A0)|0,j=j+Math.imul(n,F0)|0;var UU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(UU>>>26)|0,UU&=67108863,S=Math.imul(L0,D0),H=Math.imul(L0,_0),H=H+Math.imul($0,D0)|0,j=Math.imul($0,_0),S=S+Math.imul(s,k0)|0,H=H+Math.imul(s,z0)|0,H=H+Math.imul(X0,k0)|0,j=j+Math.imul(X0,z0)|0,S=S+Math.imul(c,v0)|0,H=H+Math.imul(c,S0)|0,H=H+Math.imul(o,v0)|0,j=j+Math.imul(o,S0)|0,S=S+Math.imul(r,j0)|0,H=H+Math.imul(r,N0)|0,H=H+Math.imul(e,j0)|0,j=j+Math.imul(e,N0)|0,S=S+Math.imul(f,M0)|0,H=H+Math.imul(f,x)|0,H=H+Math.imul(h,M0)|0,j=j+Math.imul(h,x)|0,S=S+Math.imul(m,a)|0,H=H+Math.imul(m,E0)|0,H=H+Math.imul(U0,a)|0,j=j+Math.imul(U0,E0)|0,S=S+Math.imul(t,A0)|0,H=H+Math.imul(t,F0)|0,H=H+Math.imul(d,A0)|0,j=j+Math.imul(d,F0)|0,S=S+Math.imul(p,q0)|0,H=H+Math.imul(p,B0)|0,H=H+Math.imul(n,q0)|0,j=j+Math.imul(n,B0)|0;var EU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(EU>>>26)|0,EU&=67108863,S=Math.imul(V0,D0),H=Math.imul(V0,_0),H=H+Math.imul(K0,D0)|0,j=Math.imul(K0,_0),S=S+Math.imul(L0,k0)|0,H=H+Math.imul(L0,z0)|0,H=H+Math.imul($0,k0)|0,j=j+Math.imul($0,z0)|0,S=S+Math.imul(s,v0)|0,H=H+Math.imul(s,S0)|0,H=H+Math.imul(X0,v0)|0,j=j+Math.imul(X0,S0)|0,S=S+Math.imul(c,j0)|0,H=H+Math.imul(c,N0)|0,H=H+Math.imul(o,j0)|0,j=j+Math.imul(o,N0)|0,S=S+Math.imul(r,M0)|0,H=H+Math.imul(r,x)|0,H=H+Math.imul(e,M0)|0,j=j+Math.imul(e,x)|0,S=S+Math.imul(f,a)|0,H=H+Math.imul(f,E0)|0,H=H+Math.imul(h,a)|0,j=j+Math.imul(h,E0)|0,S=S+Math.imul(m,A0)|0,H=H+Math.imul(m,F0)|0,H=H+Math.imul(U0,A0)|0,j=j+Math.imul(U0,F0)|0,S=S+Math.imul(t,q0)|0,H=H+Math.imul(t,B0)|0,H=H+Math.imul(d,q0)|0,j=j+Math.imul(d,B0)|0,S=S+Math.imul(p,P0)|0,H=H+Math.imul(p,R0)|0,H=H+Math.imul(n,P0)|0,j=j+Math.imul(n,R0)|0;var XU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(XU>>>26)|0,XU&=67108863,S=Math.imul(H0,D0),H=Math.imul(H0,_0),H=H+Math.imul(W0,D0)|0,j=Math.imul(W0,_0),S=S+Math.imul(V0,k0)|0,H=H+Math.imul(V0,z0)|0,H=H+Math.imul(K0,k0)|0,j=j+Math.imul(K0,z0)|0,S=S+Math.imul(L0,v0)|0,H=H+Math.imul(L0,S0)|0,H=H+Math.imul($0,v0)|0,j=j+Math.imul($0,S0)|0,S=S+Math.imul(s,j0)|0,H=H+Math.imul(s,N0)|0,H=H+Math.imul(X0,j0)|0,j=j+Math.imul(X0,N0)|0,S=S+Math.imul(c,M0)|0,H=H+Math.imul(c,x)|0,H=H+Math.imul(o,M0)|0,j=j+Math.imul(o,x)|0,S=S+Math.imul(r,a)|0,H=H+Math.imul(r,E0)|0,H=H+Math.imul(e,a)|0,j=j+Math.imul(e,E0)|0,S=S+Math.imul(f,A0)|0,H=H+Math.imul(f,F0)|0,H=H+Math.imul(h,A0)|0,j=j+Math.imul(h,F0)|0,S=S+Math.imul(m,q0)|0,H=H+Math.imul(m,B0)|0,H=H+Math.imul(U0,q0)|0,j=j+Math.imul(U0,B0)|0,S=S+Math.imul(t,P0)|0,H=H+Math.imul(t,R0)|0,H=H+Math.imul(d,P0)|0,j=j+Math.imul(d,R0)|0,S=S+Math.imul(p,c0)|0,H=H+Math.imul(p,f0)|0,H=H+Math.imul(n,c0)|0,j=j+Math.imul(n,f0)|0;var IU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(IU>>>26)|0,IU&=67108863,S=Math.imul(H0,k0),H=Math.imul(H0,z0),H=H+Math.imul(W0,k0)|0,j=Math.imul(W0,z0),S=S+Math.imul(V0,v0)|0,H=H+Math.imul(V0,S0)|0,H=H+Math.imul(K0,v0)|0,j=j+Math.imul(K0,S0)|0,S=S+Math.imul(L0,j0)|0,H=H+Math.imul(L0,N0)|0,H=H+Math.imul($0,j0)|0,j=j+Math.imul($0,N0)|0,S=S+Math.imul(s,M0)|0,H=H+Math.imul(s,x)|0,H=H+Math.imul(X0,M0)|0,j=j+Math.imul(X0,x)|0,S=S+Math.imul(c,a)|0,H=H+Math.imul(c,E0)|0,H=H+Math.imul(o,a)|0,j=j+Math.imul(o,E0)|0,S=S+Math.imul(r,A0)|0,H=H+Math.imul(r,F0)|0,H=H+Math.imul(e,A0)|0,j=j+Math.imul(e,F0)|0,S=S+Math.imul(f,q0)|0,H=H+Math.imul(f,B0)|0,H=H+Math.imul(h,q0)|0,j=j+Math.imul(h,B0)|0,S=S+Math.imul(m,P0)|0,H=H+Math.imul(m,R0)|0,H=H+Math.imul(U0,P0)|0,j=j+Math.imul(U0,R0)|0,S=S+Math.imul(t,c0)|0,H=H+Math.imul(t,f0)|0,H=H+Math.imul(d,c0)|0,j=j+Math.imul(d,f0)|0;var TU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(TU>>>26)|0,TU&=67108863,S=Math.imul(H0,v0),H=Math.imul(H0,S0),H=H+Math.imul(W0,v0)|0,j=Math.imul(W0,S0),S=S+Math.imul(V0,j0)|0,H=H+Math.imul(V0,N0)|0,H=H+Math.imul(K0,j0)|0,j=j+Math.imul(K0,N0)|0,S=S+Math.imul(L0,M0)|0,H=H+Math.imul(L0,x)|0,H=H+Math.imul($0,M0)|0,j=j+Math.imul($0,x)|0,S=S+Math.imul(s,a)|0,H=H+Math.imul(s,E0)|0,H=H+Math.imul(X0,a)|0,j=j+Math.imul(X0,E0)|0,S=S+Math.imul(c,A0)|0,H=H+Math.imul(c,F0)|0,H=H+Math.imul(o,A0)|0,j=j+Math.imul(o,F0)|0,S=S+Math.imul(r,q0)|0,H=H+Math.imul(r,B0)|0,H=H+Math.imul(e,q0)|0,j=j+Math.imul(e,B0)|0,S=S+Math.imul(f,P0)|0,H=H+Math.imul(f,R0)|0,H=H+Math.imul(h,P0)|0,j=j+Math.imul(h,R0)|0,S=S+Math.imul(m,c0)|0,H=H+Math.imul(m,f0)|0,H=H+Math.imul(U0,c0)|0,j=j+Math.imul(U0,f0)|0;var YU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(YU>>>26)|0,YU&=67108863,S=Math.imul(H0,j0),H=Math.imul(H0,N0),H=H+Math.imul(W0,j0)|0,j=Math.imul(W0,N0),S=S+Math.imul(V0,M0)|0,H=H+Math.imul(V0,x)|0,H=H+Math.imul(K0,M0)|0,j=j+Math.imul(K0,x)|0,S=S+Math.imul(L0,a)|0,H=H+Math.imul(L0,E0)|0,H=H+Math.imul($0,a)|0,j=j+Math.imul($0,E0)|0,S=S+Math.imul(s,A0)|0,H=H+Math.imul(s,F0)|0,H=H+Math.imul(X0,A0)|0,j=j+Math.imul(X0,F0)|0,S=S+Math.imul(c,q0)|0,H=H+Math.imul(c,B0)|0,H=H+Math.imul(o,q0)|0,j=j+Math.imul(o,B0)|0,S=S+Math.imul(r,P0)|0,H=H+Math.imul(r,R0)|0,H=H+Math.imul(e,P0)|0,j=j+Math.imul(e,R0)|0,S=S+Math.imul(f,c0)|0,H=H+Math.imul(f,f0)|0,H=H+Math.imul(h,c0)|0,j=j+Math.imul(h,f0)|0;var ZU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(ZU>>>26)|0,ZU&=67108863,S=Math.imul(H0,M0),H=Math.imul(H0,x),H=H+Math.imul(W0,M0)|0,j=Math.imul(W0,x),S=S+Math.imul(V0,a)|0,H=H+Math.imul(V0,E0)|0,H=H+Math.imul(K0,a)|0,j=j+Math.imul(K0,E0)|0,S=S+Math.imul(L0,A0)|0,H=H+Math.imul(L0,F0)|0,H=H+Math.imul($0,A0)|0,j=j+Math.imul($0,F0)|0,S=S+Math.imul(s,q0)|0,H=H+Math.imul(s,B0)|0,H=H+Math.imul(X0,q0)|0,j=j+Math.imul(X0,B0)|0,S=S+Math.imul(c,P0)|0,H=H+Math.imul(c,R0)|0,H=H+Math.imul(o,P0)|0,j=j+Math.imul(o,R0)|0,S=S+Math.imul(r,c0)|0,H=H+Math.imul(r,f0)|0,H=H+Math.imul(e,c0)|0,j=j+Math.imul(e,f0)|0;var OU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(OU>>>26)|0,OU&=67108863,S=Math.imul(H0,a),H=Math.imul(H0,E0),H=H+Math.imul(W0,a)|0,j=Math.imul(W0,E0),S=S+Math.imul(V0,A0)|0,H=H+Math.imul(V0,F0)|0,H=H+Math.imul(K0,A0)|0,j=j+Math.imul(K0,F0)|0,S=S+Math.imul(L0,q0)|0,H=H+Math.imul(L0,B0)|0,H=H+Math.imul($0,q0)|0,j=j+Math.imul($0,B0)|0,S=S+Math.imul(s,P0)|0,H=H+Math.imul(s,R0)|0,H=H+Math.imul(X0,P0)|0,j=j+Math.imul(X0,R0)|0,S=S+Math.imul(c,c0)|0,H=H+Math.imul(c,f0)|0,H=H+Math.imul(o,c0)|0,j=j+Math.imul(o,f0)|0;var QU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(QU>>>26)|0,QU&=67108863,S=Math.imul(H0,A0),H=Math.imul(H0,F0),H=H+Math.imul(W0,A0)|0,j=Math.imul(W0,F0),S=S+Math.imul(V0,q0)|0,H=H+Math.imul(V0,B0)|0,H=H+Math.imul(K0,q0)|0,j=j+Math.imul(K0,B0)|0,S=S+Math.imul(L0,P0)|0,H=H+Math.imul(L0,R0)|0,H=H+Math.imul($0,P0)|0,j=j+Math.imul($0,R0)|0,S=S+Math.imul(s,c0)|0,H=H+Math.imul(s,f0)|0,H=H+Math.imul(X0,c0)|0,j=j+Math.imul(X0,f0)|0;var JU=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(JU>>>26)|0,JU&=67108863,S=Math.imul(H0,q0),H=Math.imul(H0,B0),H=H+Math.imul(W0,q0)|0,j=Math.imul(W0,B0),S=S+Math.imul(V0,P0)|0,H=H+Math.imul(V0,R0)|0,H=H+Math.imul(K0,P0)|0,j=j+Math.imul(K0,R0)|0,S=S+Math.imul(L0,c0)|0,H=H+Math.imul(L0,f0)|0,H=H+Math.imul($0,c0)|0,j=j+Math.imul($0,f0)|0;var rE=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(rE>>>26)|0,rE&=67108863,S=Math.imul(H0,P0),H=Math.imul(H0,R0),H=H+Math.imul(W0,P0)|0,j=Math.imul(W0,R0),S=S+Math.imul(V0,c0)|0,H=H+Math.imul(V0,f0)|0,H=H+Math.imul(K0,c0)|0,j=j+Math.imul(K0,f0)|0;var tE=(V+S|0)+((H&8191)<<13)|0;V=(j+(H>>>13)|0)+(tE>>>26)|0,tE&=67108863,S=Math.imul(H0,c0),H=Math.imul(H0,f0),H=H+Math.imul(W0,c0)|0,j=Math.imul(W0,f0);var aE=(V+S|0)+((H&8191)<<13)|0;if(V=(j+(H>>>13)|0)+(aE>>>26)|0,aE&=67108863,E[0]=d0,E[1]=b0,E[2]=t0,E[3]=a0,E[4]=e0,E[5]=i0,E[6]=UU,E[7]=EU,E[8]=XU,E[9]=IU,E[10]=TU,E[11]=YU,E[12]=ZU,E[13]=OU,E[14]=QU,E[15]=JU,E[16]=rE,E[17]=tE,E[18]=aE,V!==0)E[19]=V,A.length++;return A};if(!Math.imul)B=v;function g(X,Z,A){A.negative=Z.negative^X.negative,A.length=X.length+Z.length;var $=0,J=0;for(var E=0;E>>26)|0,J+=V>>>26,V&=67108863}A.words[E]=S,$=V,V=J}if($!==0)A.words[E]=$;else A.length--;return A._strip()}function y(X,Z,A){return g(X,Z,A)}O.prototype.mulTo=function(X,Z){var A,$=this.length+X.length;if(this.length===10&&X.length===10)A=B(this,X,Z);else if($<63)A=v(this,X,Z);else if($<1024)A=g(this,X,Z);else A=y(this,X,Z);return A};function l(X,Z){this.x=X,this.y=Z}l.prototype.makeRBT=function(X){var Z=Array(X),A=O.prototype._countBits(X)-1;for(var $=0;$>=1;return $},l.prototype.permute=function(X,Z,A,$,J,E){for(var V=0;V>>1)J++;return 1<>>13,A[2*E+1]=J&8191,J=J>>>13;for(E=2*Z;E<$;++E)A[E]=0;L(J===0),L((J&-8192)===0)},l.prototype.stub=function(X){var Z=Array(X);for(var A=0;A>=26,A+=J/67108864|0,A+=E>>>26,this.words[$]=E&67108863}if(A!==0)this.words[$]=A,this.length++;return this.length=X===0?1:this.length,Z?this.ineg():this},O.prototype.muln=function(X){return this.clone().imuln(X)},O.prototype.sqr=function(){return this.mul(this)},O.prototype.isqr=function(){return this.imul(this.clone())},O.prototype.pow=function(X){var Z=N(X);if(Z.length===0)return new O(1);var A=this;for(var $=0;$=0);var Z=X%26,A=(X-Z)/26,$=67108863>>>26-Z<<26-Z,J;if(Z!==0){var E=0;for(J=0;J>>26-Z}if(E)this.words[J]=E,this.length++}if(A!==0){for(J=this.length-1;J>=0;J--)this.words[J+A]=this.words[J];for(J=0;J=0);var $;if(Z)$=(Z-Z%26)/26;else $=0;var J=X%26,E=Math.min((X-J)/26,this.length),V=67108863^67108863>>>J<E){this.length-=E;for(H=0;H=0&&(j!==0||H>=$);H--){var w=this.words[H]|0;this.words[H]=j<<26-J|w>>>J,j=w&V}if(S&&j!==0)S.words[S.length++]=j;if(this.length===0)this.words[0]=0,this.length=1;return this._strip()},O.prototype.ishrn=function(X,Z,A){return L(this.negative===0),this.iushrn(X,Z,A)},O.prototype.shln=function(X){return this.clone().ishln(X)},O.prototype.ushln=function(X){return this.clone().iushln(X)},O.prototype.shrn=function(X){return this.clone().ishrn(X)},O.prototype.ushrn=function(X){return this.clone().iushrn(X)},O.prototype.testn=function(X){L(typeof X==="number"&&X>=0);var Z=X%26,A=(X-Z)/26,$=1<=0);var Z=X%26,A=(X-Z)/26;if(L(this.negative===0,"imaskn works only with positive numbers"),this.length<=A)return this;if(Z!==0)A++;if(this.length=Math.min(A,this.length),Z!==0){var $=67108863^67108863>>>Z<=67108864;Z++)if(this.words[Z]-=67108864,Z===this.length-1)this.words[Z+1]=1;else this.words[Z+1]++;return this.length=Math.max(this.length,Z+1),this},O.prototype.isubn=function(X){if(L(typeof X==="number"),L(X<67108864),X<0)return this.iaddn(-X);if(this.negative!==0)return this.negative=0,this.iaddn(X),this.negative=1,this;if(this.words[0]-=X,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var Z=0;Z>26)-(S/67108864|0),this.words[J+A]=E&67108863}for(;J>26,this.words[J+A]=E&67108863;if(V===0)return this._strip();L(V===-1),V=0;for(J=0;J>26,this.words[J]=E&67108863;return this.negative=1,this._strip()},O.prototype._wordDiv=function(X,Z){var A=this.length-X.length,$=this.clone(),J=X,E=J.words[J.length-1]|0,V=this._countBits(E);if(A=26-V,A!==0)J=J.ushln(A),$.iushln(A),E=J.words[J.length-1]|0;var S=$.length-J.length,H;if(Z!=="mod"){H=new O(null),H.length=S+1,H.words=Array(H.length);for(var j=0;j=0;p--){var n=($.words[J.length+p]|0)*67108864+($.words[J.length+p-1]|0);n=Math.min(n/E|0,67108863),$._ishlnsubmul(J,n,p);while($.negative!==0)if(n--,$.negative=0,$._ishlnsubmul(J,1,p),!$.isZero())$.negative^=1;if(H)H.words[p]=n}if(H)H._strip();if($._strip(),Z!=="div"&&A!==0)$.iushrn(A);return{div:H||null,mod:$}},O.prototype.divmod=function(X,Z,A){if(L(!X.isZero()),this.isZero())return{div:new O(0),mod:new O(0)};var $,J,E;if(this.negative!==0&&X.negative===0){if(E=this.neg().divmod(X,Z),Z!=="mod")$=E.div.neg();if(Z!=="div"){if(J=E.mod.neg(),A&&J.negative!==0)J.iadd(X)}return{div:$,mod:J}}if(this.negative===0&&X.negative!==0){if(E=this.divmod(X.neg(),Z),Z!=="mod")$=E.div.neg();return{div:$,mod:E.mod}}if((this.negative&X.negative)!==0){if(E=this.neg().divmod(X.neg(),Z),Z!=="div"){if(J=E.mod.neg(),A&&J.negative!==0)J.isub(X)}return{div:E.div,mod:J}}if(X.length>this.length||this.cmp(X)<0)return{div:new O(0),mod:this};if(X.length===1){if(Z==="div")return{div:this.divn(X.words[0]),mod:null};if(Z==="mod")return{div:null,mod:new O(this.modrn(X.words[0]))};return{div:this.divn(X.words[0]),mod:new O(this.modrn(X.words[0]))}}return this._wordDiv(X,Z)},O.prototype.div=function(X){return this.divmod(X,"div",!1).div},O.prototype.mod=function(X){return this.divmod(X,"mod",!1).mod},O.prototype.umod=function(X){return this.divmod(X,"mod",!0).mod},O.prototype.divRound=function(X){var Z=this.divmod(X);if(Z.mod.isZero())return Z.div;var A=Z.div.negative!==0?Z.mod.isub(X):Z.mod,$=X.ushrn(1),J=X.andln(1),E=A.cmp($);if(E<0||J===1&&E===0)return Z.div;return Z.div.negative!==0?Z.div.isubn(1):Z.div.iaddn(1)},O.prototype.modrn=function(X){var Z=X<0;if(Z)X=-X;L(X<=67108863);var A=67108864%X,$=0;for(var J=this.length-1;J>=0;J--)$=(A*$+(this.words[J]|0))%X;return Z?-$:$},O.prototype.modn=function(X){return this.modrn(X)},O.prototype.idivn=function(X){var Z=X<0;if(Z)X=-X;L(X<=67108863);var A=0;for(var $=this.length-1;$>=0;$--){var J=(this.words[$]|0)+A*67108864;this.words[$]=J/X|0,A=J%X}return this._strip(),Z?this.ineg():this},O.prototype.divn=function(X){return this.clone().idivn(X)},O.prototype.egcd=function(X){L(X.negative===0),L(!X.isZero());var Z=this,A=X.clone();if(Z.negative!==0)Z=Z.umod(X);else Z=Z.clone();var $=new O(1),J=new O(0),E=new O(0),V=new O(1),S=0;while(Z.isEven()&&A.isEven())Z.iushrn(1),A.iushrn(1),++S;var H=A.clone(),j=Z.clone();while(!Z.isZero()){for(var w=0,p=1;(Z.words[0]&p)===0&&w<26;++w,p<<=1);if(w>0){Z.iushrn(w);while(w-- >0){if($.isOdd()||J.isOdd())$.iadd(H),J.isub(j);$.iushrn(1),J.iushrn(1)}}for(var n=0,G0=1;(A.words[0]&G0)===0&&n<26;++n,G0<<=1);if(n>0){A.iushrn(n);while(n-- >0){if(E.isOdd()||V.isOdd())E.iadd(H),V.isub(j);E.iushrn(1),V.iushrn(1)}}if(Z.cmp(A)>=0)Z.isub(A),$.isub(E),J.isub(V);else A.isub(Z),E.isub($),V.isub(J)}return{a:E,b:V,gcd:A.iushln(S)}},O.prototype._invmp=function(X){L(X.negative===0),L(!X.isZero());var Z=this,A=X.clone();if(Z.negative!==0)Z=Z.umod(X);else Z=Z.clone();var $=new O(1),J=new O(0),E=A.clone();while(Z.cmpn(1)>0&&A.cmpn(1)>0){for(var V=0,S=1;(Z.words[0]&S)===0&&V<26;++V,S<<=1);if(V>0){Z.iushrn(V);while(V-- >0){if($.isOdd())$.iadd(E);$.iushrn(1)}}for(var H=0,j=1;(A.words[0]&j)===0&&H<26;++H,j<<=1);if(H>0){A.iushrn(H);while(H-- >0){if(J.isOdd())J.iadd(E);J.iushrn(1)}}if(Z.cmp(A)>=0)Z.isub(A),$.isub(J);else A.isub(Z),J.isub($)}var w;if(Z.cmpn(1)===0)w=$;else w=J;if(w.cmpn(0)<0)w.iadd(X);return w},O.prototype.gcd=function(X){if(this.isZero())return X.abs();if(X.isZero())return this.abs();var Z=this.clone(),A=X.clone();Z.negative=0,A.negative=0;for(var $=0;Z.isEven()&&A.isEven();$++)Z.iushrn(1),A.iushrn(1);do{while(Z.isEven())Z.iushrn(1);while(A.isEven())A.iushrn(1);var J=Z.cmp(A);if(J<0){var E=Z;Z=A,A=E}else if(J===0||A.cmpn(1)===0)break;Z.isub(A)}while(!0);return A.iushln($)},O.prototype.invm=function(X){return this.egcd(X).a.umod(X)},O.prototype.isEven=function(){return(this.words[0]&1)===0},O.prototype.isOdd=function(){return(this.words[0]&1)===1},O.prototype.andln=function(X){return this.words[0]&X},O.prototype.bincn=function(X){L(typeof X==="number");var Z=X%26,A=(X-Z)/26,$=1<>>26,V&=67108863,this.words[E]=V}if(J!==0)this.words[E]=J,this.length++;return this},O.prototype.isZero=function(){return this.length===1&&this.words[0]===0},O.prototype.cmpn=function(X){var Z=X<0;if(this.negative!==0&&!Z)return-1;if(this.negative===0&&Z)return 1;this._strip();var A;if(this.length>1)A=1;else{if(Z)X=-X;L(X<=67108863,"Number is too big");var $=this.words[0]|0;A=$===X?0:$X.length)return 1;if(this.length=0;A--){var $=this.words[A]|0,J=X.words[A]|0;if($===J)continue;if($J)Z=1;break}return Z},O.prototype.gtn=function(X){return this.cmpn(X)===1},O.prototype.gt=function(X){return this.cmp(X)===1},O.prototype.gten=function(X){return this.cmpn(X)>=0},O.prototype.gte=function(X){return this.cmp(X)>=0},O.prototype.ltn=function(X){return this.cmpn(X)===-1},O.prototype.lt=function(X){return this.cmp(X)===-1},O.prototype.lten=function(X){return this.cmpn(X)<=0},O.prototype.lte=function(X){return this.cmp(X)<=0},O.prototype.eqn=function(X){return this.cmpn(X)===0},O.prototype.eq=function(X){return this.cmp(X)===0},O.red=function(X){return new I(X)},O.prototype.toRed=function(X){return L(!this.red,"Already a number in reduction context"),L(this.negative===0,"red works only with positives"),X.convertTo(this)._forceRed(X)},O.prototype.fromRed=function(){return L(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},O.prototype._forceRed=function(X){return this.red=X,this},O.prototype.forceRed=function(X){return L(!this.red,"Already a number in reduction context"),this._forceRed(X)},O.prototype.redAdd=function(X){return L(this.red,"redAdd works only with red numbers"),this.red.add(this,X)},O.prototype.redIAdd=function(X){return L(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,X)},O.prototype.redSub=function(X){return L(this.red,"redSub works only with red numbers"),this.red.sub(this,X)},O.prototype.redISub=function(X){return L(this.red,"redISub works only with red numbers"),this.red.isub(this,X)},O.prototype.redShl=function(X){return L(this.red,"redShl works only with red numbers"),this.red.shl(this,X)},O.prototype.redMul=function(X){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,X),this.red.mul(this,X)},O.prototype.redIMul=function(X){return L(this.red,"redMul works only with red numbers"),this.red._verify2(this,X),this.red.imul(this,X)},O.prototype.redSqr=function(){return L(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},O.prototype.redISqr=function(){return L(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},O.prototype.redSqrt=function(){return L(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},O.prototype.redInvm=function(){return L(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},O.prototype.redNeg=function(){return L(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},O.prototype.redPow=function(X){return L(this.red&&!X.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,X)};var Y0={k256:null,p224:null,p192:null,p25519:null};function O0(X,Z){this.name=X,this.p=new O(Z,16),this.n=this.p.bitLength(),this.k=new O(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}O0.prototype._tmp=function(){var X=new O(null);return X.words=Array(Math.ceil(this.n/13)),X},O0.prototype.ireduce=function(X){var Z=X,A;do this.split(Z,this.tmp),Z=this.imulK(Z),Z=Z.iadd(this.tmp),A=Z.bitLength();while(A>this.n);var $=A0)Z.isub(this.p);else if(Z.strip!==void 0)Z.strip();else Z._strip();return Z},O0.prototype.split=function(X,Z){X.iushrn(this.n,0,Z)},O0.prototype.imulK=function(X){return X.imul(this.k)};function Z0(){O0.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}W(Z0,O0),Z0.prototype.split=function(X,Z){var A=4194303,$=Math.min(X.length,9);for(var J=0;J<$;J++)Z.words[J]=X.words[J];if(Z.length=$,X.length<=9){X.words[0]=0,X.length=1;return}var E=X.words[9];Z.words[Z.length++]=E&A;for(J=10;J>>22,E=V}if(E>>>=22,X.words[J-10]=E,E===0&&X.length>10)X.length-=10;else X.length-=9},Z0.prototype.imulK=function(X){X.words[X.length]=0,X.words[X.length+1]=0,X.length+=2;var Z=0;for(var A=0;A>>=26,X.words[A]=J,Z=$}if(Z!==0)X.words[X.length++]=Z;return X},O._prime=function(X){if(Y0[X])return Y0[X];var Z;if(X==="k256")Z=new Z0;else if(X==="p224")Z=new u;else if(X==="p192")Z=new i;else if(X==="p25519")Z=new U;else throw Error("Unknown prime "+X);return Y0[X]=Z,Z};function I(X){if(typeof X==="string"){var Z=O._prime(X);this.m=Z.p,this.prime=Z}else L(X.gtn(1),"modulus must be greater than 1"),this.m=X,this.prime=null}I.prototype._verify1=function(X){L(X.negative===0,"red works only with positives"),L(X.red,"red works only with red numbers")},I.prototype._verify2=function(X,Z){L((X.negative|Z.negative)===0,"red works only with positives"),L(X.red&&X.red===Z.red,"red works only with red numbers")},I.prototype.imod=function(X){if(this.prime)return this.prime.ireduce(X)._forceRed(this);return F(X,X.umod(this.m)._forceRed(this)),X},I.prototype.neg=function(X){if(X.isZero())return X.clone();return this.m.sub(X)._forceRed(this)},I.prototype.add=function(X,Z){this._verify2(X,Z);var A=X.add(Z);if(A.cmp(this.m)>=0)A.isub(this.m);return A._forceRed(this)},I.prototype.iadd=function(X,Z){this._verify2(X,Z);var A=X.iadd(Z);if(A.cmp(this.m)>=0)A.isub(this.m);return A},I.prototype.sub=function(X,Z){this._verify2(X,Z);var A=X.sub(Z);if(A.cmpn(0)<0)A.iadd(this.m);return A._forceRed(this)},I.prototype.isub=function(X,Z){this._verify2(X,Z);var A=X.isub(Z);if(A.cmpn(0)<0)A.iadd(this.m);return A},I.prototype.shl=function(X,Z){return this._verify1(X),this.imod(X.ushln(Z))},I.prototype.imul=function(X,Z){return this._verify2(X,Z),this.imod(X.imul(Z))},I.prototype.mul=function(X,Z){return this._verify2(X,Z),this.imod(X.mul(Z))},I.prototype.isqr=function(X){return this.imul(X,X.clone())},I.prototype.sqr=function(X){return this.mul(X,X)},I.prototype.sqrt=function(X){if(X.isZero())return X.clone();var Z=this.m.andln(3);if(L(Z%2===1),Z===3){var A=this.m.add(new O(1)).iushrn(2);return this.pow(X,A)}var $=this.m.subn(1),J=0;while(!$.isZero()&&$.andln(1)===0)J++,$.iushrn(1);L(!$.isZero());var E=new O(1).toRed(this),V=E.redNeg(),S=this.m.subn(1).iushrn(1),H=this.m.bitLength();H=new O(2*H*H).toRed(this);while(this.pow(H,S).cmp(V)!==0)H.redIAdd(V);var j=this.pow(H,$),w=this.pow(X,$.addn(1).iushrn(1)),p=this.pow(X,$),n=J;while(p.cmp(E)!==0){var G0=p;for(var t=0;G0.cmp(E)!==0;t++)G0=G0.redSqr();L(t=0;J--){var j=Z.words[J];for(var w=H-1;w>=0;w--){var p=j>>w&1;if(E!==$[0])E=this.sqr(E);if(p===0&&V===0){S=0;continue}if(V<<=1,V|=p,S++,S!==A&&(J!==0||w!==0))continue;E=this.mul(E,$[V]),S=0,V=0}H=26}return E},I.prototype.convertTo=function(X){var Z=X.umod(this.m);return Z===X?Z.clone():Z},I.prototype.convertFrom=function(X){var Z=X.clone();return Z.red=null,Z},O.mont=function(X){return new Q(X)};function Q(X){if(I.call(this,X),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new O(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}W(Q,I),Q.prototype.convertTo=function(X){return this.imod(X.ushln(this.shift))},Q.prototype.convertFrom=function(X){var Z=this.imod(X.mul(this.rinv));return Z.red=null,Z},Q.prototype.imul=function(X,Z){if(X.isZero()||Z.isZero())return X.words[0]=0,X.length=1,X;var A=X.imul(Z),$=A.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),J=A.isub($).iushrn(this.shift),E=J;if(J.cmp(this.m)>=0)E=J.isub(this.m);else if(J.cmpn(0)<0)E=J.iadd(this.m);return E._forceRed(this)},Q.prototype.mul=function(X,Z){if(X.isZero()||Z.isZero())return new O(0)._forceRed(this);var A=X.mul(Z),$=A.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),J=A.isub($).iushrn(this.shift),E=J;if(J.cmp(this.m)>=0)E=J.isub(this.m);else if(J.cmpn(0)<0)E=J.iadd(this.m);return E._forceRed(this)},Q.prototype.invm=function(X){var Z=this.imod(X._invmp(this.m).mul(this.r2));return Z._forceRed(this)}})(typeof Y>"u"||Y,T)}),NT=Q0((T,Y)=>{var G=NQ(),K=cE(),L=SU().Buffer;function W(q){var D=q.modulus.byteLength(),C;do C=new G(K(D));while(C.cmp(q.modulus)>=0||!C.umod(q.prime1)||!C.umod(q.prime2));return C}function O(q){var D=W(q),C=D.toRed(G.mont(q.modulus)).redPow(new G(q.publicExponent)).fromRed();return{blinder:C,unblinder:D.invm(q.modulus)}}function z(q,D){var C=O(D),F=D.modulus.byteLength(),R=new G(q).mul(C.blinder).umod(D.modulus),M=R.toRed(G.mont(D.prime1)),P=R.toRed(G.mont(D.prime2)),k=D.coefficient,_=D.prime1,N=D.prime2,v=M.redPow(D.exponent1).fromRed(),B=P.redPow(D.exponent2).fromRed(),g=v.isub(B).imul(k).umod(_).imul(N);return B.iadd(g).imul(C.unblinder).umod(D.modulus).toArrayLike(L,"be",F)}z.getr=W,Y.exports=z}),BQ=Q0((T,Y)=>{var G=_T(),K=cE(),L=pE(),W=kT(),O=vT(),z=gX(),q=jT(),D=NT(),C=SU().Buffer;Y.exports=function(P,k,_){var N;if(P.padding)N=P.padding;else if(_)N=1;else N=4;var v=G(P),B;if(N===4)B=F(v,k);else if(N===1)B=R(v,k,_);else if(N===3){if(B=new z(k),B.cmp(v.modulus)>=0)throw Error("data too long for modulus")}else throw Error("unknown padding");if(_)return D(B,v);else return q(B,v)};function F(P,k){var _=P.modulus.byteLength(),N=k.length,v=L("sha1").update(C.alloc(0)).digest(),B=v.length,g=2*B;if(N>_-g-2)throw Error("message too long");var y=C.alloc(_-N-g-2),l=_-B-1,Y0=K(B),O0=O(C.concat([v,y,C.alloc(1,1),k],l),W(Y0,l)),Z0=O(Y0,W(O0,B));return new z(C.concat([C.alloc(1),Z0,O0],_))}function R(P,k,_){var N=k.length,v=P.modulus.byteLength();if(N>v-11)throw Error("message too long");var B;if(_)B=C.alloc(v-N-3,255);else B=M(v-N-3);return new z(C.concat([C.from([0,_?1:2]),B,C.alloc(1),k],v))}function M(P){var k=C.allocUnsafe(P),_=0,N=K(P*2),v=0,B;while(_{var G=_T(),K=kT(),L=vT(),W=gX(),O=NT(),z=pE(),q=jT(),D=SU().Buffer;Y.exports=function(M,P,k){var _;if(M.padding)_=M.padding;else if(k)_=1;else _=4;var N=G(M),v=N.modulus.byteLength();if(P.length>v||new W(P).cmp(N.modulus)>=0)throw Error("decryption error");var B;if(k)B=q(new W(P),N);else B=O(P,N);var g=D.alloc(v-B.length);if(B=D.concat([g,B],v),_===4)return C(N,B);else if(_===1)return F(N,B,k);else if(_===3)return B;else throw Error("unknown padding")};function C(M,P){var k=M.modulus.byteLength(),_=z("sha1").update(D.alloc(0)).digest(),N=_.length;if(P[0]!==0)throw Error("decryption error");var v=P.slice(1,N+1),B=P.slice(N+1),g=L(v,K(B,N)),y=L(B,K(g,k-N-1));if(R(_,y.slice(0,N)))throw Error("decryption error");var l=N;while(y[l]===0)l++;if(y[l++]!==1)throw Error("decryption error");return y.slice(l)}function F(M,P,k){var _=P.slice(0,2),N=2,v=0;while(P[N++]!==0)if(N>=P.length){v++;break}var B=P.slice(2,N-1);if(_.toString("hex")!=="0002"&&!k||_.toString("hex")!=="0001"&&k)v++;if(B.length<8)v++;if(v)throw Error("decryption error");return P.slice(N)}function R(M,P){M=D.from(M),P=D.from(P);var k=0,_=M.length;if(M.length!==P.length)k++,_=Math.min(M.length,P.length);var N=-1;while(++N<_)k+=M[N]^P[N];return k}}),qX=Q0((T)=>{T.publicEncrypt=BQ(),T.privateDecrypt=xQ(),T.privateEncrypt=function(Y,G){return T.publicEncrypt(Y,G,!0)},T.publicDecrypt=function(Y,G){return T.privateDecrypt(Y,G,!0)}}),gQ=Q0((T)=>{var Y=(DU(),h0(PU));if(typeof Y.publicEncrypt!=="function")Y=qX();if(T.publicEncrypt=Y.publicEncrypt,T.privateDecrypt=Y.privateDecrypt,typeof Y.privateEncrypt!=="function")T.privateEncrypt=qX().privateEncrypt;else T.privateEncrypt=Y.privateEncrypt;if(typeof Y.publicDecrypt!=="function")T.publicDecrypt=qX().publicDecrypt;else T.publicDecrypt=Y.publicDecrypt}),wQ=Q0((T)=>{var Y=SU(),G=cE(),K=Y.Buffer,L=Y.kMaxLength,W=globalThis.crypto||globalThis.msCrypto,O=Math.pow(2,32)-1;function z(R,M){if(typeof R!=="number"||R!==R)throw TypeError("offset must be a number");if(R>O||R<0)throw TypeError("offset must be a uint32");if(R>L||R>M)throw RangeError("offset out of range")}function q(R,M,P){if(typeof R!=="number"||R!==R)throw TypeError("size must be a number");if(R>O||R<0)throw TypeError("size must be a uint32");if(R+M>P||R>L)throw RangeError("buffer too small")}W&&W.getRandomValues,T.randomFill=D,T.randomFillSync=F;function D(R,M,P,k){if(!K.isBuffer(R)&&!(R instanceof globalThis.Uint8Array))throw TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof M==="function")k=M,M=0,P=R.length;else if(typeof P==="function")k=P,P=R.length-M;else if(typeof k!=="function")throw TypeError('"cb" argument must be a function');return z(M,R.length),q(P,M,R.length),C(R,M,P,k)}function C(R,M,P,k){if(!1)var _,N;if(k){G(P,function(B,g){if(B)return k(B);g.copy(R,M),k(null,R)});return}var v=G(P);return v.copy(R,M),R}function F(R,M,P){if(typeof M>"u")M=0;if(!K.isBuffer(R)&&!(R instanceof globalThis.Uint8Array))throw TypeError('"buf" argument must be a Buffer or Uint8Array');if(z(M,R.length),P===void 0)P=R.length-M;return q(P,M,R.length),C(R,M,P)}}),yQ=Q0((T,Y)=>{var G=(DU(),h0(PU));if(typeof G.randomFill==="function"&&typeof G.randomFillSync==="function")T.randomFill=G.randomFill,T.randomFillSync=G.randomFillSync;else Y.exports=wQ()}),fQ=Q0((T)=>{T.randomBytes=T.rng=T.pseudoRandomBytes=T.prng=cE(),T.createHash=T.Hash=pE(),T.createHmac=T.Hmac=YT();var Y=OO(),G=Object.keys(Y),K=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(G);T.getHashes=function(){return K};var L=FT();T.pbkdf2=L.pbkdf2,T.pbkdf2Sync=L.pbkdf2Sync;var W=dO();T.Cipher=W.Cipher,T.createCipher=W.createCipher,T.Cipheriv=W.Cipheriv,T.createCipheriv=W.createCipheriv,T.Decipher=W.Decipher,T.createDecipher=W.createDecipher,T.Decipheriv=W.Decipheriv,T.createDecipheriv=W.createDecipheriv,T.getCiphers=W.getCiphers,T.listCiphers=W.listCiphers;var O=lO();T.DiffieHellmanGroup=O.DiffieHellmanGroup,T.createDiffieHellmanGroup=O.createDiffieHellmanGroup,T.getDiffieHellman=O.getDiffieHellman,T.createDiffieHellman=O.createDiffieHellman,T.DiffieHellman=O.DiffieHellman;var z=oO();T.createSign=z.createSign,T.Sign=z.Sign,T.createVerify=z.createVerify,T.Verify=z.Verify,T.createECDH=$Q();var q=gQ();T.publicEncrypt=q.publicEncrypt,T.privateEncrypt=q.privateEncrypt,T.publicDecrypt=q.publicDecrypt,T.privateDecrypt=q.privateDecrypt;var D=yQ();T.randomFill=D.randomFill,T.randomFillSync=D.randomFillSync,T.createCredentials=function(){throw Error(`sorry, createCredentials is not implemented yet +we accept pull requests +https://github.com/browserify/crypto-browserify`)},T.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}}),p0=ZO(fQ(),1),cQ=p0.prng,pQ=p0.pseudoRandomBytes,hQ=p0.rng,uQ=p0.randomBytes,bQ=p0.Hash,CE=p0.createHash,dQ=p0.Hmac,lQ=p0.createHmac,oQ=p0.getHashes,nQ=p0.pbkdf2,mQ=p0.pbkdf2Sync,sQ=p0.Cipher,rQ=p0.createCipher,tQ=p0.Cipheriv,aQ=p0.createCipheriv,eQ=p0.Decipher,iQ=p0.createDecipher,UJ=p0.Decipheriv,EJ=p0.createDecipheriv,XJ=p0.getCiphers,IJ=p0.listCiphers,TJ=p0.DiffieHellmanGroup,YJ=p0.createDiffieHellmanGroup,ZJ=p0.getDiffieHellman,OJ=p0.createDiffieHellman,QJ=p0.DiffieHellman,JJ=p0.createSign,GJ=p0.Sign,VJ=p0.createVerify,AJ=p0.Verify,LJ=p0.createECDH,$J=p0.publicEncrypt,KJ=p0.privateEncrypt,FJ=p0.publicDecrypt,WJ=p0.privateDecrypt,HJ=p0.randomFill,RJ=p0.randomFillSync,CJ=p0.createCredentials,DJ=p0.constants,qJ=["p192","p224","p256","p384","p521","curve25519","ed25519","secp256k1","secp224r1","prime256v1","prime192v1","ed25519","secp384r1","secp521r1"];_J=crypto,kJ=crypto});import vJ from"gray-matter";function wX(T,Y){let{data:G,content:K}=vJ(T),{compiled_truth:L,timeline:W}=jJ(K),O=G.type||NJ(Y),z=G.title||BJ(Y),q=gJ(G),D=G.slug||xJ(Y),C={...G};return delete C.type,delete C.title,delete C.tags,delete C.slug,{frontmatter:C,compiled_truth:L.trim(),timeline:W.trim(),slug:D,type:O,title:z,tags:q}}function jJ(T){let Y=T.split(` +`),G=-1;for(let W=0;W0){G=W;break}}if(G===-1)return{compiled_truth:T,timeline:""};let K=Y.slice(0,G).join(` +`),L=Y.slice(G+1).join(` +`);return{compiled_truth:K,timeline:L}}function NJ(T){if(!T)return"concept";let Y=("/"+T).toLowerCase();if(Y.includes("/people/")||Y.includes("/person/"))return"person";if(Y.includes("/companies/")||Y.includes("/company/"))return"company";if(Y.includes("/deals/")||Y.includes("/deal/"))return"deal";if(Y.includes("/yc/"))return"yc";if(Y.includes("/civic/"))return"civic";if(Y.includes("/projects/")||Y.includes("/project/"))return"project";if(Y.includes("/sources/")||Y.includes("/source/"))return"source";if(Y.includes("/media/"))return"media";return"concept"}function BJ(T){if(!T)return"Untitled";let Y=T.split("/");return(Y[Y.length-1]?.replace(/\.md$/i,"")||"Untitled").replace(/[-_]/g," ").replace(/\b\w/g,(K)=>K.toUpperCase())}function xJ(T){if(!T)return"untitled";let Y=T.replace(/\.md$/i,"").replace(/\\/g,"/");if(Y.startsWith("./"))Y=Y.slice(2);return Y.toLowerCase()}function gJ(T){let Y=T.tags;if(!Y)return[];if(Array.isArray(Y))return Y.map(String);if(typeof Y==="string")return Y.split(",").map((G)=>G.trim()).filter(Boolean);return[]}var BT=()=>{};function fX(T,Y){let G=Y?.chunkSize||300,K=Y?.chunkOverlap||50;if(!T||T.trim().length===0)return[];if(cX(T)<=G)return[{text:T.trim(),index:0}];let W=yX(T,0,G),O=yJ(W,G);return fJ(O,K).map((q,D)=>({text:q.trim(),index:D}))}function yX(T,Y,G){if(Y>=xT.length)return gT(T,G);let K=xT[Y];if(K.length===0)return gT(T,G);let L=wJ(T,K);if(L.length<=1)return yX(T,Y+1,G);let W=[];for(let O of L)if(cX(O)>G)W.push(...yX(O,Y+1,G));else W.push(O);return W}function wJ(T,Y){let G=[],K=T;while(K.length>0){let L=-1,W="";for(let z of Y){let q=K.indexOf(z);if(q!==-1&&(L===-1||q0)G.push(O);K=K.slice(L+W.length)}if(K.trim().length>0&&!G.includes(K));return G.filter((L)=>L.trim().length>0)}function gT(T,Y){let G=T.match(/\S+\s*/g)||[];if(G.length===0)return[];let K=[];for(let L=0;L0)K.push(W)}return K}function yJ(T,Y){if(T.length===0)return[];let G=[],K=T[0];for(let L=1;L0)G.push(K);return G}function fJ(T,Y){if(T.length<=1||Y<=0)return T;let G=[T[0]];for(let K=1;K0)return W}return K}function cX(T){return(T.match(/\S+/g)||[]).length}var xT;var wT=GU(()=>{xT=[[` + +`],[` +`],[". ","! ","? ",`. +`,`! +`,`? +`],["; ",": ",", "],[]]});import cT from"openai";function dJ(){if(!pX)pX=new cT;return pX}async function hT(T){let Y=T.slice(0,pT);return(await hX([Y]))[0]}async function hX(T){let Y=T.map((K)=>K.slice(0,pT)),G=[];for(let K=0;KL.index-W.index).map((L)=>new Float32Array(L.embedding))}catch(G){if(Y===yT-1)throw G;let K=oJ(Y);if(G instanceof cT.APIError&&G.status===429){let L=G.headers?.["retry-after"];if(L){let W=parseInt(L,10);if(!isNaN(W))K=W*1000}}await nJ(K)}throw Error("Embedding failed after all retries")}function oJ(T){let Y=uJ*Math.pow(2,T);return Math.min(Y,bJ)}function nJ(T){return new Promise((Y)=>setTimeout(Y,T))}var pJ="text-embedding-3-large",hJ=1536,pT=8000,yT=5,uJ=4000,bJ=120000,fT=100,pX=null;var uX=()=>{};var{readFileSync:mJ,statSync:sJ}=(()=>({}));async function bX(T,Y,G,K={}){let L=wX(G,Y+".md"),W=CE("sha256").update(JSON.stringify({title:L.title,type:L.type,compiled_truth:L.compiled_truth,timeline:L.timeline,frontmatter:L.frontmatter,tags:L.tags.sort()})).digest("hex"),O=await T.getPage(Y);if(O?.content_hash===W)return{slug:Y,status:"skipped",chunks:0};let z=[];if(L.compiled_truth.trim())for(let q of fX(L.compiled_truth))z.push({chunk_index:z.length,chunk_text:q.text,chunk_source:"compiled_truth"});if(L.timeline?.trim())for(let q of fX(L.timeline))z.push({chunk_index:z.length,chunk_text:q.text,chunk_source:"timeline"});if(!K.noEmbed&&z.length>0)try{let q=await hX(z.map((D)=>D.chunk_text));for(let D=0;D{if(O)await q.createVersion(Y);await q.putPage(Y,{type:L.type,title:L.title,compiled_truth:L.compiled_truth,timeline:L.timeline||"",frontmatter:L.frontmatter,content_hash:W});let D=await q.getTags(Y),C=new Set(L.tags);for(let F of D)if(!C.has(F))await q.removeTag(Y,F);for(let F of L.tags)await q.addTag(Y,F);if(z.length>0)await q.upsertChunks(Y,z)}),{slug:Y,status:"imported",chunks:z.length}}async function tJ(T,Y,G,K={}){let L=sJ(Y);if(L.size>rJ)return{slug:G,status:"skipped",chunks:0,error:`File too large (${L.size} bytes)`};let W=mJ(Y,"utf-8"),O=wX(W,G);return bX(T,O.slug,W,K)}var rJ=5000000,DE;var bE=GU(()=>{DU();BT();wT();uX();DE=tJ});var tU;var dE=GU(()=>{tU=class tU extends Error{problem;cause_description;fix;docs_url;constructor(T,Y,G,K){super(`${T}: ${Y}. Fix: ${G}`);this.problem=T;this.cause_description=Y;this.fix=G;this.docs_url=K;this.name="GBrainError"}}});var lX=` +-- GBrain Postgres + pgvector schema + +CREATE EXTENSION IF NOT EXISTS vector; +CREATE EXTENSION IF NOT EXISTS pg_trgm; + +-- ============================================================ +-- pages: the core content table +-- ============================================================ +CREATE TABLE IF NOT EXISTS pages ( + id SERIAL PRIMARY KEY, + slug TEXT NOT NULL UNIQUE, + type TEXT NOT NULL, + title TEXT NOT NULL, + compiled_truth TEXT NOT NULL DEFAULT '', + timeline TEXT NOT NULL DEFAULT '', + frontmatter JSONB NOT NULL DEFAULT '{}', + content_hash TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_pages_type ON pages(type); +CREATE INDEX IF NOT EXISTS idx_pages_frontmatter ON pages USING GIN(frontmatter); +CREATE INDEX IF NOT EXISTS idx_pages_trgm ON pages USING GIN(title gin_trgm_ops); + +-- ============================================================ +-- content_chunks: chunked content with embeddings +-- ============================================================ +CREATE TABLE IF NOT EXISTS content_chunks ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + chunk_index INTEGER NOT NULL, + chunk_text TEXT NOT NULL, + chunk_source TEXT NOT NULL DEFAULT 'compiled_truth', + embedding vector(1536), + model TEXT NOT NULL DEFAULT 'text-embedding-3-large', + token_count INTEGER, + embedded_at TIMESTAMPTZ, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_page_index ON content_chunks(page_id, chunk_index); +CREATE INDEX IF NOT EXISTS idx_chunks_page ON content_chunks(page_id); +CREATE INDEX IF NOT EXISTS idx_chunks_embedding ON content_chunks USING hnsw (embedding vector_cosine_ops); + +-- ============================================================ +-- links: cross-references between pages +-- ============================================================ +CREATE TABLE IF NOT EXISTS links ( + id SERIAL PRIMARY KEY, + from_page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + to_page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + link_type TEXT NOT NULL DEFAULT '', + context TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(from_page_id, to_page_id) +); + +CREATE INDEX IF NOT EXISTS idx_links_from ON links(from_page_id); +CREATE INDEX IF NOT EXISTS idx_links_to ON links(to_page_id); + +-- ============================================================ +-- tags +-- ============================================================ +CREATE TABLE IF NOT EXISTS tags ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + tag TEXT NOT NULL, + UNIQUE(page_id, tag) +); + +CREATE INDEX IF NOT EXISTS idx_tags_tag ON tags(tag); +CREATE INDEX IF NOT EXISTS idx_tags_page_id ON tags(page_id); + +-- ============================================================ +-- raw_data: sidecar data (replaces .raw/ JSON files) +-- ============================================================ +CREATE TABLE IF NOT EXISTS raw_data ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + source TEXT NOT NULL, + data JSONB NOT NULL, + fetched_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(page_id, source) +); + +CREATE INDEX IF NOT EXISTS idx_raw_data_page ON raw_data(page_id); + +-- ============================================================ +-- timeline_entries: structured timeline +-- ============================================================ +CREATE TABLE IF NOT EXISTS timeline_entries ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + date DATE NOT NULL, + source TEXT NOT NULL DEFAULT '', + summary TEXT NOT NULL, + detail TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_timeline_page ON timeline_entries(page_id); +CREATE INDEX IF NOT EXISTS idx_timeline_date ON timeline_entries(date); + +-- ============================================================ +-- page_versions: snapshot history for compiled_truth +-- ============================================================ +CREATE TABLE IF NOT EXISTS page_versions ( + id SERIAL PRIMARY KEY, + page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE, + compiled_truth TEXT NOT NULL, + frontmatter JSONB NOT NULL DEFAULT '{}', + snapshot_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_versions_page ON page_versions(page_id); + +-- ============================================================ +-- ingest_log +-- ============================================================ +CREATE TABLE IF NOT EXISTS ingest_log ( + id SERIAL PRIMARY KEY, + source_type TEXT NOT NULL, + source_ref TEXT NOT NULL, + pages_updated JSONB NOT NULL DEFAULT '[]', + summary TEXT NOT NULL DEFAULT '', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +-- ============================================================ +-- config: brain-level settings +-- ============================================================ +CREATE TABLE IF NOT EXISTS config ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL +); + +INSERT INTO config (key, value) VALUES + ('version', '1'), + ('embedding_model', 'text-embedding-3-large'), + ('embedding_dimensions', '1536'), + ('chunk_strategy', 'semantic') +ON CONFLICT (key) DO NOTHING; + +-- ============================================================ +-- files: binary attachments stored in Supabase Storage +-- ============================================================ +CREATE TABLE IF NOT EXISTS files ( + id SERIAL PRIMARY KEY, + page_slug TEXT REFERENCES pages(slug) ON DELETE SET NULL ON UPDATE CASCADE, + filename TEXT NOT NULL, + storage_path TEXT NOT NULL, + mime_type TEXT, + size_bytes BIGINT, + content_hash TEXT NOT NULL, + metadata JSONB NOT NULL DEFAULT '{}', + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + UNIQUE(storage_path) +); + +-- Migration: drop storage_url if it exists (renamed to storage_path only) +ALTER TABLE files DROP COLUMN IF EXISTS storage_url; + +CREATE INDEX IF NOT EXISTS idx_files_page ON files(page_slug); +CREATE INDEX IF NOT EXISTS idx_files_hash ON files(content_hash); + +-- ============================================================ +-- Trigger-based search_vector (spans pages + timeline_entries) +-- ============================================================ +ALTER TABLE pages ADD COLUMN IF NOT EXISTS search_vector tsvector; + +CREATE INDEX IF NOT EXISTS idx_pages_search ON pages USING GIN(search_vector); + +-- Function to rebuild search_vector for a page +CREATE OR REPLACE FUNCTION update_page_search_vector() RETURNS trigger AS $$ +DECLARE + timeline_text TEXT; +BEGIN + -- Gather timeline_entries text for this page + SELECT coalesce(string_agg(summary || ' ' || detail, ' '), '') + INTO timeline_text + FROM timeline_entries + WHERE page_id = NEW.id; + + -- Build weighted tsvector + NEW.search_vector := + setweight(to_tsvector('english', coalesce(NEW.title, '')), 'A') || + setweight(to_tsvector('english', coalesce(NEW.compiled_truth, '')), 'B') || + setweight(to_tsvector('english', coalesce(NEW.timeline, '')), 'C') || + setweight(to_tsvector('english', coalesce(timeline_text, '')), 'C'); + + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS trg_pages_search_vector ON pages; +CREATE TRIGGER trg_pages_search_vector + BEFORE INSERT OR UPDATE ON pages + FOR EACH ROW + EXECUTE FUNCTION update_page_search_vector(); + +-- When timeline_entries change, update the parent page's search_vector +CREATE OR REPLACE FUNCTION update_page_search_vector_from_timeline() RETURNS trigger AS $$ +DECLARE + page_row pages%ROWTYPE; +BEGIN + -- Touch the page to re-fire its trigger + UPDATE pages SET updated_at = now() + WHERE id = coalesce(NEW.page_id, OLD.page_id); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS trg_timeline_search_vector ON timeline_entries; +CREATE TRIGGER trg_timeline_search_vector + AFTER INSERT OR UPDATE OR DELETE ON timeline_entries + FOR EACH ROW + EXECUTE FUNCTION update_page_search_vector_from_timeline(); + +-- ============================================================ +-- Row Level Security: block anon access, postgres role bypasses +-- ============================================================ +-- The postgres role (used by gbrain via pooler) has BYPASSRLS. +-- Enabling RLS with no policies means the anon key can't read anything. +-- Only enable if the current role actually has BYPASSRLS privilege, +-- otherwise we'd lock ourselves out. +DO $$ +DECLARE + has_bypass BOOLEAN; +BEGIN + SELECT rolbypassrls INTO has_bypass FROM pg_roles WHERE rolname = current_user; + IF has_bypass THEN + ALTER TABLE pages ENABLE ROW LEVEL SECURITY; + ALTER TABLE content_chunks ENABLE ROW LEVEL SECURITY; + ALTER TABLE links ENABLE ROW LEVEL SECURITY; + ALTER TABLE tags ENABLE ROW LEVEL SECURITY; + ALTER TABLE raw_data ENABLE ROW LEVEL SECURITY; + ALTER TABLE timeline_entries ENABLE ROW LEVEL SECURITY; + ALTER TABLE page_versions ENABLE ROW LEVEL SECURITY; + ALTER TABLE ingest_log ENABLE ROW LEVEL SECURITY; + ALTER TABLE config ENABLE ROW LEVEL SECURITY; + ALTER TABLE files ENABLE ROW LEVEL SECURITY; + RAISE NOTICE 'RLS enabled on all tables (role % has BYPASSRLS)', current_user; + ELSE + RAISE WARNING 'Skipping RLS: role % does not have BYPASSRLS privilege. Run as postgres role to enable.', current_user; + END IF; +END $$; +`;import lT from"postgres";function eU(){if(!pU)throw new tU("No database connection","connect() has not been called","Run gbrain init --supabase or gbrain init --url ");return pU}async function oT(T){if(pU)return;let Y=T.database_url;if(!Y)throw new tU("No database URL","database_url is missing from config","Run gbrain init --supabase or gbrain init --url ");try{pU=lT(Y,{max:10,idle_timeout:20,connect_timeout:10,types:{bigint:lT.BigInt}}),await pU`SELECT 1`}catch(G){pU=null;let K=G instanceof Error?G.message:String(G);throw new tU("Cannot connect to database",K,"Check your connection URL in ~/.gbrain/config.json")}}async function nT(){if(pU)await pU.end(),pU=null}var pU=null;var oX=GU(()=>{dE()});var TY={};jU(TY,{sep:()=>EY,resolve:()=>lE,relative:()=>oE,posix:()=>IY,parse:()=>UY,normalize:()=>nX,join:()=>VU,isAbsolute:()=>rT,format:()=>iT,extname:()=>eT,dirname:()=>nE,delimiter:()=>XY,default:()=>JG,basename:()=>aT,_makeLong:()=>tT});function gU(T){if(typeof T!=="string")throw TypeError("Path must be a string. Received "+JSON.stringify(T))}function sT(T,Y){var G="",K=0,L=-1,W=0,O;for(var z=0;z<=T.length;++z){if(z2){var q=G.lastIndexOf("/");if(q!==G.length-1){if(q===-1)G="",K=0;else G=G.slice(0,q),K=G.length-1-G.lastIndexOf("/");L=z,W=0;continue}}else if(G.length===2||G.length===1){G="",K=0,L=z,W=0;continue}}if(Y){if(G.length>0)G+="/..";else G="..";K=2}}else{if(G.length>0)G+="/"+T.slice(L+1,z);else G=T.slice(L+1,z);K=z-L-1}L=z,W=0}else if(O===46&&W!==-1)++W;else W=-1}return G}function QG(T,Y){var G=Y.dir||Y.root,K=Y.base||(Y.name||"")+(Y.ext||"");if(!G)return K;if(G===Y.root)return G+K;return G+T+K}function lE(){var T="",Y=!1,G;for(var K=arguments.length-1;K>=-1&&!Y;K--){var L;if(K>=0)L=arguments[K];else{if(G===void 0)G=process.cwd();L=G}if(gU(L),L.length===0)continue;T=L+"/"+T,Y=L.charCodeAt(0)===47}if(T=sT(T,!Y),Y)if(T.length>0)return"/"+T;else return"/";else if(T.length>0)return T;else return"."}function nX(T){if(gU(T),T.length===0)return".";var Y=T.charCodeAt(0)===47,G=T.charCodeAt(T.length-1)===47;if(T=sT(T,!Y),T.length===0&&!Y)T=".";if(T.length>0&&G)T+="/";if(Y)return"/"+T;return T}function rT(T){return gU(T),T.length>0&&T.charCodeAt(0)===47}function VU(){if(arguments.length===0)return".";var T;for(var Y=0;Y0)if(T===void 0)T=G;else T+="/"+G}if(T===void 0)return".";return nX(T)}function oE(T,Y){if(gU(T),gU(Y),T===Y)return"";if(T=lE(T),Y=lE(Y),T===Y)return"";var G=1;for(;Gq){if(Y.charCodeAt(W+C)===47)return Y.slice(W+C+1);else if(C===0)return Y.slice(W+C)}else if(L>q){if(T.charCodeAt(G+C)===47)D=C;else if(C===0)D=0}break}var F=T.charCodeAt(G+C),R=Y.charCodeAt(W+C);if(F!==R)break;else if(F===47)D=C}var M="";for(C=G+D+1;C<=K;++C)if(C===K||T.charCodeAt(C)===47)if(M.length===0)M+="..";else M+="/..";if(M.length>0)return M+Y.slice(W+D);else{if(W+=D,Y.charCodeAt(W)===47)++W;return Y.slice(W)}}function tT(T){return T}function nE(T){if(gU(T),T.length===0)return".";var Y=T.charCodeAt(0),G=Y===47,K=-1,L=!0;for(var W=T.length-1;W>=1;--W)if(Y=T.charCodeAt(W),Y===47){if(!L){K=W;break}}else L=!1;if(K===-1)return G?"/":".";if(G&&K===1)return"//";return T.slice(0,K)}function aT(T,Y){if(Y!==void 0&&typeof Y!=="string")throw TypeError('"ext" argument must be a string');gU(T);var G=0,K=-1,L=!0,W;if(Y!==void 0&&Y.length>0&&Y.length<=T.length){if(Y.length===T.length&&Y===T)return"";var O=Y.length-1,z=-1;for(W=T.length-1;W>=0;--W){var q=T.charCodeAt(W);if(q===47){if(!L){G=W+1;break}}else{if(z===-1)L=!1,z=W+1;if(O>=0)if(q===Y.charCodeAt(O)){if(--O===-1)K=W}else O=-1,K=z}}if(G===K)K=z;else if(K===-1)K=T.length;return T.slice(G,K)}else{for(W=T.length-1;W>=0;--W)if(T.charCodeAt(W)===47){if(!L){G=W+1;break}}else if(K===-1)L=!1,K=W+1;if(K===-1)return"";return T.slice(G,K)}}function eT(T){gU(T);var Y=-1,G=0,K=-1,L=!0,W=0;for(var O=T.length-1;O>=0;--O){var z=T.charCodeAt(O);if(z===47){if(!L){G=O+1;break}continue}if(K===-1)L=!1,K=O+1;if(z===46){if(Y===-1)Y=O;else if(W!==1)W=1}else if(Y!==-1)W=-1}if(Y===-1||K===-1||W===0||W===1&&Y===K-1&&Y===G+1)return"";return T.slice(Y,K)}function iT(T){if(T===null||typeof T!=="object")throw TypeError('The "pathObject" argument must be of type Object. Received type '+typeof T);return QG("/",T)}function UY(T){gU(T);var Y={root:"",dir:"",base:"",ext:"",name:""};if(T.length===0)return Y;var G=T.charCodeAt(0),K=G===47,L;if(K)Y.root="/",L=1;else L=0;var W=-1,O=0,z=-1,q=!0,D=T.length-1,C=0;for(;D>=L;--D){if(G=T.charCodeAt(D),G===47){if(!q){O=D+1;break}continue}if(z===-1)q=!1,z=D+1;if(G===46){if(W===-1)W=D;else if(C!==1)C=1}else if(W!==-1)C=-1}if(W===-1||z===-1||C===0||C===1&&W===z-1&&W===O+1){if(z!==-1)if(O===0&&K)Y.base=Y.name=T.slice(1,z);else Y.base=Y.name=T.slice(O,z)}else{if(O===0&&K)Y.name=T.slice(1,W),Y.base=T.slice(1,z);else Y.name=T.slice(O,W),Y.base=T.slice(O,z);Y.ext=T.slice(W,z)}if(O>0)Y.dir=T.slice(0,O-1);else if(K)Y.dir="/";return Y}var EY="/",XY=":",IY,JG;var TE=GU(()=>{IY=((T)=>(T.posix=T,T))({resolve:lE,normalize:nX,isAbsolute:rT,join:VU,relative:oE,_makeLong:tT,dirname:nE,basename:aT,extname:eT,format:iT,parse:UY,sep:EY,delimiter:XY,win32:null,posix:null}),JG=IY});function YY(T){let Y={added:[],modified:[],deleted:[],renamed:[]},G=T.split(` +`);for(let K of G){let L=K.trim();if(!L)continue;let W=L.split("\t");if(W.length<2)continue;let O=W[0],z=W[W.length===3?2:1];if(O==="A")Y.added.push(z);else if(O==="M")Y.modified.push(z);else if(O==="D")Y.deleted.push(W[1]);else if(O.startsWith("R")){let q=W[1],D=W[2];if(q&&D)Y.renamed.push({from:q,to:D})}}return Y}function YE(T){if(!T.endsWith(".md"))return!1;if(T.split("/").some((K)=>K.startsWith(".")))return!1;if(T.includes(".raw/"))return!1;let Y=["schema.md","index.md","log.md","README.md"],G=T.split("/").pop()||"";if(Y.includes(G))return!1;if(T.startsWith("ops/"))return!1;return!0}function zE(T,Y){let G=T.replace(/\.md$/,"");if(G=G.replace(/\\/g,"/"),G=G.replace(/^\//,""),Y)G=`${Y}/${G}`;return G.toLowerCase()}var mX=function(){return"/"};var sX=()=>{};async function ZY(T){let Y=await T.getConfig("version"),G=parseInt(Y||"1",10),K=0;for(let L of ZE)if(L.version>G)await T.transaction(async(W)=>{let O=W,z=O.sql||O._sql;if(z)await z.unsafe(L.sql),await z`UPDATE config SET value = ${String(L.version)} WHERE key = 'version'`}),console.log(` Migration ${L.version} applied: ${L.name}`),K++;return{applied:K,current:K>0?ZE[ZE.length-1].version:G}}var ZE,uV;var OY=GU(()=>{ZE=[{version:2,name:"unique_chunk_index",sql:` + -- Deduplicate any existing duplicate (page_id, chunk_index) rows before adding constraint + DELETE FROM content_chunks a USING content_chunks b + WHERE a.page_id = b.page_id AND a.chunk_index = b.chunk_index AND a.id > b.id; + CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_page_index ON content_chunks(page_id, chunk_index); + `},{version:3,name:"access_tokens_and_mcp_log",sql:` + CREATE TABLE IF NOT EXISTS access_tokens ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + token_hash TEXT NOT NULL UNIQUE, + scopes TEXT[], + created_at TIMESTAMPTZ DEFAULT now(), + last_used_at TIMESTAMPTZ, + revoked_at TIMESTAMPTZ + ); + CREATE INDEX IF NOT EXISTS idx_access_tokens_hash ON access_tokens (token_hash) WHERE revoked_at IS NULL; + CREATE TABLE IF NOT EXISTS mcp_request_log ( + id SERIAL PRIMARY KEY, + token_name TEXT, + operation TEXT NOT NULL, + latency_ms INTEGER, + status TEXT NOT NULL DEFAULT 'success', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() + ); + `}],uV=ZE.length>0?ZE[ZE.length-1].version:1});import QY from"postgres";class mE{_sql=null;get sql(){if(this._sql)return this._sql;return eU()}async connect(T){if(T.poolSize){let Y=T.database_url;if(!Y)throw new tU("No database URL","database_url is missing","Provide --url");this._sql=QY(Y,{max:T.poolSize,idle_timeout:20,connect_timeout:10,types:{bigint:QY.BigInt}}),await this._sql`SELECT 1`}else await oT(T)}async disconnect(){if(this._sql)await this._sql.end(),this._sql=null;else await nT()}async initSchema(){await this.sql.unsafe(lX);let{applied:Y}=await ZY(this);if(Y>0)console.log(` ${Y} migration(s) applied`)}async transaction(T){return(this._sql||eU()).begin(async(G)=>{let K=Object.create(this);return Object.defineProperty(K,"sql",{get:()=>G}),Object.defineProperty(K,"_sql",{value:G,writable:!1}),T(K)})}async getPage(T){let G=await this.sql` + SELECT id, slug, type, title, compiled_truth, timeline, frontmatter, content_hash, created_at, updated_at + FROM pages WHERE slug = ${T} + `;if(G.length===0)return null;return rX(G[0])}async putPage(T,Y){T=JY(T);let G=this.sql,K=Y.content_hash||GG(Y.compiled_truth,Y.timeline||""),L=Y.frontmatter||{},W=await G` + INSERT INTO pages (slug, type, title, compiled_truth, timeline, frontmatter, content_hash, updated_at) + VALUES (${T}, ${Y.type}, ${Y.title}, ${Y.compiled_truth}, ${Y.timeline||""}, ${JSON.stringify(L)}::jsonb, ${K}, now()) + ON CONFLICT (slug) DO UPDATE SET + type = EXCLUDED.type, + title = EXCLUDED.title, + compiled_truth = EXCLUDED.compiled_truth, + timeline = EXCLUDED.timeline, + frontmatter = EXCLUDED.frontmatter, + content_hash = EXCLUDED.content_hash, + updated_at = now() + RETURNING id, slug, type, title, compiled_truth, timeline, frontmatter, content_hash, created_at, updated_at + `;return rX(W[0])}async deletePage(T){await this.sql`DELETE FROM pages WHERE slug = ${T}`}async listPages(T){let Y=this.sql,G=T?.limit||100,K=T?.offset||0,L;if(T?.type&&T?.tag)L=await Y` + SELECT p.* FROM pages p + JOIN tags t ON t.page_id = p.id + WHERE p.type = ${T.type} AND t.tag = ${T.tag} + ORDER BY p.updated_at DESC LIMIT ${G} OFFSET ${K} + `;else if(T?.type)L=await Y` + SELECT * FROM pages WHERE type = ${T.type} + ORDER BY updated_at DESC LIMIT ${G} OFFSET ${K} + `;else if(T?.tag)L=await Y` + SELECT p.* FROM pages p + JOIN tags t ON t.page_id = p.id + WHERE t.tag = ${T.tag} + ORDER BY p.updated_at DESC LIMIT ${G} OFFSET ${K} + `;else L=await Y` + SELECT * FROM pages + ORDER BY updated_at DESC LIMIT ${G} OFFSET ${K} + `;return L.map(rX)}async resolveSlugs(T){let Y=this.sql,G=await Y`SELECT slug FROM pages WHERE slug = ${T}`;if(G.length>0)return[G[0].slug];return(await Y` + SELECT slug, similarity(title, ${T}) AS sim + FROM pages + WHERE title % ${T} OR slug ILIKE ${"%"+T+"%"} + ORDER BY sim DESC + LIMIT 5 + `).map((L)=>L.slug)}async searchKeyword(T,Y){let G=this.sql,K=Y?.limit||20,L=await G` + SELECT DISTINCT ON (p.slug) + p.slug, p.id as page_id, p.title, p.type, + cc.chunk_text, cc.chunk_source, + ts_rank(p.search_vector, websearch_to_tsquery('english', ${T})) AS score, + CASE WHEN p.updated_at < ( + SELECT MAX(te.created_at) FROM timeline_entries te WHERE te.page_id = p.id + ) THEN true ELSE false END AS stale + FROM pages p + JOIN content_chunks cc ON cc.page_id = p.id + WHERE p.search_vector @@ websearch_to_tsquery('english', ${T}) + ORDER BY p.slug, score DESC + `;return L.sort((W,O)=>O.score-W.score),L.splice(K),L.map(GY)}async searchVector(T,Y){let G=this.sql,K=Y?.limit||20,L="["+Array.from(T).join(",")+"]";return(await G` + SELECT + p.slug, p.id as page_id, p.title, p.type, + cc.chunk_text, cc.chunk_source, + 1 - (cc.embedding <=> ${L}::vector) AS score, + CASE WHEN p.updated_at < ( + SELECT MAX(te.created_at) FROM timeline_entries te WHERE te.page_id = p.id + ) THEN true ELSE false END AS stale + FROM content_chunks cc + JOIN pages p ON p.id = cc.page_id + WHERE cc.embedding IS NOT NULL + ORDER BY cc.embedding <=> ${L}::vector + LIMIT ${K} + `).map(GY)}async upsertChunks(T,Y){let G=this.sql,K=await G`SELECT id FROM pages WHERE slug = ${T}`;if(K.length===0)throw Error(`Page not found: ${T}`);let L=K[0].id,W=Y.map((O)=>O.chunk_index);if(W.length>0)await G`DELETE FROM content_chunks WHERE page_id = ${L} AND chunk_index != ALL(${W})`;else{await G`DELETE FROM content_chunks WHERE page_id = ${L}`;return}for(let O of Y){let z=O.embedding?"["+Array.from(O.embedding).join(",")+"]":null;if(z)await G.unsafe(`INSERT INTO content_chunks (page_id, chunk_index, chunk_text, chunk_source, embedding, model, token_count, embedded_at) + VALUES ($1, $2, $3, $4, $5::vector, $6, $7, now()) + ON CONFLICT (page_id, chunk_index) DO UPDATE SET + chunk_text = EXCLUDED.chunk_text, + chunk_source = EXCLUDED.chunk_source, + embedding = EXCLUDED.embedding, + model = EXCLUDED.model, + token_count = EXCLUDED.token_count, + embedded_at = EXCLUDED.embedded_at`,[L,O.chunk_index,O.chunk_text,O.chunk_source,z,O.model||"text-embedding-3-large",O.token_count||null]);else await G.unsafe(`INSERT INTO content_chunks (page_id, chunk_index, chunk_text, chunk_source, embedding, model, token_count, embedded_at) + VALUES ($1, $2, $3, $4, NULL, $5, $6, NULL) + ON CONFLICT (page_id, chunk_index) DO UPDATE SET + chunk_text = EXCLUDED.chunk_text, + chunk_source = EXCLUDED.chunk_source, + embedding = COALESCE(content_chunks.embedding, EXCLUDED.embedding), + model = COALESCE(content_chunks.model, EXCLUDED.model), + token_count = EXCLUDED.token_count, + embedded_at = COALESCE(content_chunks.embedded_at, EXCLUDED.embedded_at)`,[L,O.chunk_index,O.chunk_text,O.chunk_source,O.model||"text-embedding-3-large",O.token_count||null])}}async getChunks(T){return(await this.sql` + SELECT cc.* FROM content_chunks cc + JOIN pages p ON p.id = cc.page_id + WHERE p.slug = ${T} + ORDER BY cc.chunk_index + `).map(VG)}async deleteChunks(T){await this.sql` + DELETE FROM content_chunks + WHERE page_id = (SELECT id FROM pages WHERE slug = ${T}) + `}async addLink(T,Y,G,K){await this.sql` + INSERT INTO links (from_page_id, to_page_id, link_type, context) + SELECT f.id, t.id, ${K||""}, ${G||""} + FROM pages f, pages t + WHERE f.slug = ${T} AND t.slug = ${Y} + ON CONFLICT (from_page_id, to_page_id) DO UPDATE SET + link_type = EXCLUDED.link_type, + context = EXCLUDED.context + `}async removeLink(T,Y){await this.sql` + DELETE FROM links + WHERE from_page_id = (SELECT id FROM pages WHERE slug = ${T}) + AND to_page_id = (SELECT id FROM pages WHERE slug = ${Y}) + `}async getLinks(T){return await this.sql` + SELECT f.slug as from_slug, t.slug as to_slug, l.link_type, l.context + FROM links l + JOIN pages f ON f.id = l.from_page_id + JOIN pages t ON t.id = l.to_page_id + WHERE f.slug = ${T} + `}async getBacklinks(T){return await this.sql` + SELECT f.slug as from_slug, t.slug as to_slug, l.link_type, l.context + FROM links l + JOIN pages f ON f.id = l.from_page_id + JOIN pages t ON t.id = l.to_page_id + WHERE t.slug = ${T} + `}async traverseGraph(T,Y=5){return(await this.sql` + WITH RECURSIVE graph AS ( + SELECT p.id, p.slug, p.title, p.type, 0 as depth + FROM pages p WHERE p.slug = ${T} + + UNION + + SELECT p2.id, p2.slug, p2.title, p2.type, g.depth + 1 + FROM graph g + JOIN links l ON l.from_page_id = g.id + JOIN pages p2 ON p2.id = l.to_page_id + WHERE g.depth < ${Y} + ) + SELECT DISTINCT g.slug, g.title, g.type, g.depth, + coalesce( + (SELECT jsonb_agg(jsonb_build_object('to_slug', p3.slug, 'link_type', l2.link_type)) + FROM links l2 + JOIN pages p3 ON p3.id = l2.to_page_id + WHERE l2.from_page_id = g.id), + '[]'::jsonb + ) as links + FROM graph g + ORDER BY g.depth, g.slug + `).map((L)=>({slug:L.slug,title:L.title,type:L.type,depth:L.depth,links:typeof L.links==="string"?JSON.parse(L.links):L.links}))}async addTag(T,Y){await this.sql` + INSERT INTO tags (page_id, tag) + SELECT id, ${Y} FROM pages WHERE slug = ${T} + ON CONFLICT (page_id, tag) DO NOTHING + `}async removeTag(T,Y){await this.sql` + DELETE FROM tags + WHERE page_id = (SELECT id FROM pages WHERE slug = ${T}) + AND tag = ${Y} + `}async getTags(T){return(await this.sql` + SELECT tag FROM tags + WHERE page_id = (SELECT id FROM pages WHERE slug = ${T}) + ORDER BY tag + `).map((K)=>K.tag)}async addTimelineEntry(T,Y){await this.sql` + INSERT INTO timeline_entries (page_id, date, source, summary, detail) + SELECT id, ${Y.date}::date, ${Y.source||""}, ${Y.summary}, ${Y.detail||""} + FROM pages WHERE slug = ${T} + `}async getTimeline(T,Y){let G=this.sql,K=Y?.limit||100,L;if(Y?.after&&Y?.before)L=await G` + SELECT te.* FROM timeline_entries te + JOIN pages p ON p.id = te.page_id + WHERE p.slug = ${T} AND te.date >= ${Y.after}::date AND te.date <= ${Y.before}::date + ORDER BY te.date DESC LIMIT ${K} + `;else if(Y?.after)L=await G` + SELECT te.* FROM timeline_entries te + JOIN pages p ON p.id = te.page_id + WHERE p.slug = ${T} AND te.date >= ${Y.after}::date + ORDER BY te.date DESC LIMIT ${K} + `;else L=await G` + SELECT te.* FROM timeline_entries te + JOIN pages p ON p.id = te.page_id + WHERE p.slug = ${T} + ORDER BY te.date DESC LIMIT ${K} + `;return L}async putRawData(T,Y,G){await this.sql` + INSERT INTO raw_data (page_id, source, data) + SELECT id, ${Y}, ${JSON.stringify(G)}::jsonb + FROM pages WHERE slug = ${T} + ON CONFLICT (page_id, source) DO UPDATE SET + data = EXCLUDED.data, + fetched_at = now() + `}async getRawData(T,Y){let G=this.sql,K;if(Y)K=await G` + SELECT rd.source, rd.data, rd.fetched_at FROM raw_data rd + JOIN pages p ON p.id = rd.page_id + WHERE p.slug = ${T} AND rd.source = ${Y} + `;else K=await G` + SELECT rd.source, rd.data, rd.fetched_at FROM raw_data rd + JOIN pages p ON p.id = rd.page_id + WHERE p.slug = ${T} + `;return K}async createVersion(T){return(await this.sql` + INSERT INTO page_versions (page_id, compiled_truth, frontmatter) + SELECT id, compiled_truth, frontmatter + FROM pages WHERE slug = ${T} + RETURNING * + `)[0]}async getVersions(T){return await this.sql` + SELECT pv.* FROM page_versions pv + JOIN pages p ON p.id = pv.page_id + WHERE p.slug = ${T} + ORDER BY pv.snapshot_at DESC + `}async revertToVersion(T,Y){await this.sql` + UPDATE pages SET + compiled_truth = pv.compiled_truth, + frontmatter = pv.frontmatter, + updated_at = now() + FROM page_versions pv + WHERE pages.slug = ${T} AND pv.id = ${Y} AND pv.page_id = pages.id + `}async getStats(){let T=this.sql,[Y]=await T` + SELECT + (SELECT count(*) FROM pages) as page_count, + (SELECT count(*) FROM content_chunks) as chunk_count, + (SELECT count(*) FROM content_chunks WHERE embedded_at IS NOT NULL) as embedded_count, + (SELECT count(*) FROM links) as link_count, + (SELECT count(DISTINCT tag) FROM tags) as tag_count, + (SELECT count(*) FROM timeline_entries) as timeline_entry_count + `,G=await T` + SELECT type, count(*)::int as count FROM pages GROUP BY type ORDER BY count DESC + `,K={};for(let L of G)K[L.type]=L.count;return{page_count:Number(Y.page_count),chunk_count:Number(Y.chunk_count),embedded_count:Number(Y.embedded_count),link_count:Number(Y.link_count),tag_count:Number(Y.tag_count),timeline_entry_count:Number(Y.timeline_entry_count),pages_by_type:K}}async getHealth(){let T=this.sql,[Y]=await T` + SELECT + (SELECT count(*) FROM pages) as page_count, + (SELECT count(*) FROM content_chunks WHERE embedded_at IS NOT NULL)::float / + GREATEST((SELECT count(*) FROM content_chunks), 1)::float as embed_coverage, + (SELECT count(*) FROM pages p + WHERE p.updated_at < (SELECT MAX(te.created_at) FROM timeline_entries te WHERE te.page_id = p.id) + ) as stale_pages, + (SELECT count(*) FROM pages p + WHERE NOT EXISTS (SELECT 1 FROM links l WHERE l.to_page_id = p.id) + ) as orphan_pages, + (SELECT count(*) FROM links l + WHERE NOT EXISTS (SELECT 1 FROM pages p WHERE p.id = l.to_page_id) + ) as dead_links, + (SELECT count(*) FROM content_chunks WHERE embedded_at IS NULL) as missing_embeddings + `;return{page_count:Number(Y.page_count),embed_coverage:Number(Y.embed_coverage),stale_pages:Number(Y.stale_pages),orphan_pages:Number(Y.orphan_pages),dead_links:Number(Y.dead_links),missing_embeddings:Number(Y.missing_embeddings)}}async logIngest(T){await this.sql` + INSERT INTO ingest_log (source_type, source_ref, pages_updated, summary) + VALUES (${T.source_type}, ${T.source_ref}, ${JSON.stringify(T.pages_updated)}::jsonb, ${T.summary}) + `}async getIngestLog(T){let Y=this.sql,G=T?.limit||50;return await Y` + SELECT * FROM ingest_log ORDER BY created_at DESC LIMIT ${G} + `}async updateSlug(T,Y){Y=JY(Y),await this.sql`UPDATE pages SET slug = ${Y}, updated_at = now() WHERE slug = ${T}`}async rewriteLinks(T,Y){}async getConfig(T){let G=await this.sql`SELECT value FROM config WHERE key = ${T}`;return G.length>0?G[0].value:null}async setConfig(T,Y){await this.sql` + INSERT INTO config (key, value) VALUES (${T}, ${Y}) + ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value + `}}function JY(T){if(!T||/\.\./.test(T)||/^\//.test(T))throw Error(`Invalid slug: "${T}". Slugs cannot be empty, start with /, or contain path traversal.`);return T.toLowerCase()}function GG(T,Y){return CE("sha256").update(T+` +--- +`+Y).digest("hex")}function rX(T){return{id:T.id,slug:T.slug,type:T.type,title:T.title,compiled_truth:T.compiled_truth,timeline:T.timeline,frontmatter:typeof T.frontmatter==="string"?JSON.parse(T.frontmatter):T.frontmatter,content_hash:T.content_hash,created_at:new Date(T.created_at),updated_at:new Date(T.updated_at)}}function VG(T){return{id:T.id,page_id:T.page_id,chunk_index:T.chunk_index,chunk_text:T.chunk_text,chunk_source:T.chunk_source,embedding:null,model:T.model,token_count:T.token_count,embedded_at:T.embedded_at?new Date(T.embedded_at):null}}function GY(T){return{slug:T.slug,page_id:T.page_id,title:T.title,type:T.type,chunk_text:T.chunk_text,chunk_source:T.chunk_source,score:Number(T.score),stale:Boolean(T.stale)}}var tX=GU(()=>{DU();OY();dE();oX()});var{readFileSync:AG,writeFileSync:tV,mkdirSync:aV,chmodSync:eV}=(()=>({}));function VY(){let T=null;try{let G=AG(AY(),"utf-8");T=JSON.parse(G)}catch{}let Y=process.env.GBRAIN_DATABASE_URL||process.env.DATABASE_URL;if(!T&&!Y)return null;return{engine:"postgres",...T,...Y?{database_url:Y}:{},...process.env.OPENAI_API_KEY?{openai_api_key:process.env.OPENAI_API_KEY}:{}}}function AY(){return AY()}var LY=GU(()=>{TE();sX()});var $Y={};jU($Y,{runImport:()=>RG});var{readdirSync:LG,statSync:$G,existsSync:SE,writeFileSync:KG,readFileSync:FG,unlinkSync:WG}=(()=>({}));import{execFileSync as HG}from"child_process";async function RG(T,Y){let G=Y.includes("--no-embed"),K=Y.includes("--fresh"),L=Y.includes("--json"),W=Y.indexOf("--workers"),O=W!==-1?Y[W+1]:null,z=O?parseInt(O,10):1,q=new Set;if(W!==-1)q.add(W+1);let D=Y.find((u,i)=>!u.startsWith("--")&&!q.has(i));if(!D)console.error("Usage: gbrain import [--no-embed] [--workers N] [--fresh] [--json]"),process.exit(1);let C=CG(D);console.log(`Found ${C.length} markdown files`);let F=VU(mX(),".gbrain","import-checkpoint.json"),R=C,M=0;if(!K&&SE(F))try{let u=JSON.parse(FG(F,"utf-8"));if(u.dir===D&&u.totalFiles===C.length)M=u.processedIndex,R=C.slice(M),console.log(`Resuming from checkpoint: skipping ${M} already-processed files`)}catch{}let P=z>1?z:1;if(P>1)console.log(`Using ${P} parallel workers`);let k=0,_=0,N=0,v=0,B=0,g=[],y={},l=Date.now();function Y0(){let u=(Date.now()-l)/1000,i=u>0?Math.round(v/u):0,U=i>0?Math.round((R.length-v)/i):0,I=Math.round(v/R.length*100);console.log(`[gbrain import] ${v}/${R.length} (${I}%) | ${i} files/sec | imported: ${k} | skipped: ${_} | errors: ${N} | ETA: ${U}s`)}async function O0(u,i){let U=oE(D,i);try{let I=await DE(u,i,U,{noEmbed:G});if(I.status==="imported")k++,B+=I.chunks,g.push(I.slug);else if(_++,I.error&&I.error!=="unchanged")console.error(` Skipped ${U}: ${I.error}`)}catch(I){let Q=I instanceof Error?I.message:String(I),X=Q.replace(/"[^"]*"/g,'""');if(y[X]=(y[X]||0)+1,y[X]<=5)console.error(` Warning: skipped ${U}: ${Q}`);else if(y[X]===6)console.error(` (suppressing further "${X.slice(0,60)}..." errors)`);N++,_++}if(v++,v%100===0||v===R.length){if(Y0(),v%100===0)try{let I=VU(mX(),".gbrain");if(!SE(I)){let{mkdirSync:Q}=await import("fs");Q(I,{recursive:!0})}KG(F,JSON.stringify({dir:D,totalFiles:C.length,processedIndex:M+v,completedFiles:g.length+_,timestamp:new Date().toISOString()}))}catch{}}}if(P>1){let u=VY(),i=await Promise.all(Array.from({length:P},async()=>{let I=new mE;return await I.connect({database_url:u.database_url,poolSize:2}),I})),U=0;await Promise.all(i.map(async(I)=>{while(!0){let Q=U++;if(Q>=R.length)break;await O0(I,R[Q])}})),await Promise.all(i.map((I)=>I.disconnect()))}else for(let u of R)await O0(T,u);for(let[u,i]of Object.entries(y))if(i>5)console.error(` ${i} files failed: ${u.slice(0,100)}`);if(N===0&&SE(F))try{WG(F)}catch{}else if(N>0&&SE(F))console.log(` Checkpoint preserved (${N} errors). Run again to retry failed files.`);let Z0=((Date.now()-l)/1000).toFixed(1);if(L)console.log(JSON.stringify({status:"success",duration_s:parseFloat(Z0),imported:k,skipped:_,errors:N,chunks:B,total_files:C.length}));else console.log(` +Import complete (${Z0}s):`),console.log(` ${k} pages imported`),console.log(` ${_} pages skipped (${_-N} unchanged, ${N} errors)`),console.log(` ${B} chunks created`);await T.logIngest({source_type:"directory",source_ref:D,pages_updated:g,summary:`Imported ${k} pages, ${_} skipped, ${B} chunks`});try{if(SE(VU(D,".git"))){let u=HG("git",["-C",D,"rev-parse","HEAD"],{encoding:"utf-8"}).trim();await T.setConfig("sync.last_commit",u),await T.setConfig("sync.last_run",new Date().toISOString()),await T.setConfig("sync.repo_path",D)}}catch{}}function CG(T){let Y=[];function G(K){for(let L of LG(K)){if(L.startsWith("."))continue;let W=VU(K,L);if($G(W).isDirectory())G(W);else if(L.endsWith(".md"))Y.push(W)}}return G(T),Y.sort()}var KY=GU(()=>{TE();sX();tX();bE();LY()});var FY={};jU(FY,{runSync:()=>zG,performSync:()=>iX});var{existsSync:aX}=(()=>({}));import{execFileSync as DG}from"child_process";function ME(T,...Y){return DG("git",["-C",T,...Y],{encoding:"utf-8",timeout:30000}).trim()}async function iX(T,Y){let G=Y.repoPath||await T.getConfig("sync.repo_path");if(!G)throw Error("No repo path specified. Use --repo or run gbrain init with --repo first.");if(!aX(VU(G,".git")))throw Error(`Not a git repository: ${G}. GBrain sync requires a git-initialized repo.`);if(!Y.noPull)try{ME(G,"pull","--ff-only")}catch(N){let v=N instanceof Error?N.message:String(N);if(v.includes("non-fast-forward")||v.includes("diverged"))console.error("Warning: git pull failed (remote diverged). Syncing from local state.");else console.error(`Warning: git pull failed: ${v.slice(0,100)}`)}let K;try{K=ME(G,"rev-parse","HEAD")}catch{throw Error(`No commits in repo ${G}. Make at least one commit before syncing.`)}let L=Y.full?null:await T.getConfig("sync.last_commit");if(L){try{ME(G,"cat-file","-t",L)}catch{return console.error(`Sync anchor commit ${L.slice(0,8)} missing (force push?). Running full reimport.`),eX(T,G,K,Y)}try{ME(G,"merge-base","--is-ancestor",L,K)}catch{return console.error(`Sync anchor ${L.slice(0,8)} is not an ancestor of HEAD. Running full reimport.`),eX(T,G,K,Y)}}if(!L)return eX(T,G,K,Y);if(L===K)return{status:"up_to_date",fromCommit:L,toCommit:K,added:0,modified:0,deleted:0,renamed:0,chunksCreated:0,pagesAffected:[]};let W=ME(G,"diff","--name-status","-M",`${L}..${K}`),O=YY(W),z={added:O.added.filter((N)=>YE(N)),modified:O.modified.filter((N)=>YE(N)),deleted:O.deleted.filter((N)=>YE(N)),renamed:O.renamed.filter((N)=>YE(N.to))},q=O.modified.filter((N)=>!YE(N));for(let N of q){let v=zE(N);try{if(await T.getPage(v))await T.deletePage(v),console.log(` Deleted un-syncable page: ${v}`)}catch{}}let D=z.added.length+z.modified.length+z.deleted.length+z.renamed.length;if(Y.dryRun){if(console.log(`Sync dry run: ${L.slice(0,8)}..${K.slice(0,8)}`),z.added.length)console.log(` Added: ${z.added.join(", ")}`);if(z.modified.length)console.log(` Modified: ${z.modified.join(", ")}`);if(z.deleted.length)console.log(` Deleted: ${z.deleted.join(", ")}`);if(z.renamed.length)console.log(` Renamed: ${z.renamed.map((N)=>`${N.from} -> ${N.to}`).join(", ")}`);if(D===0)console.log(" No syncable changes.");return{status:"dry_run",fromCommit:L,toCommit:K,added:z.added.length,modified:z.modified.length,deleted:z.deleted.length,renamed:z.renamed.length,chunksCreated:0,pagesAffected:[]}}if(D===0)return await T.setConfig("sync.last_commit",K),await T.setConfig("sync.last_run",new Date().toISOString()),{status:"up_to_date",fromCommit:L,toCommit:K,added:0,modified:0,deleted:0,renamed:0,chunksCreated:0,pagesAffected:[]};let C=Y.noEmbed||D>100;if(D>100)console.log(`Large sync (${D} files). Importing text, deferring embeddings.`);let F=[],R=0,M=Date.now();for(let N of z.deleted){let v=zE(N);await T.deletePage(v),F.push(v)}for(let{from:N,to:v}of z.renamed){let B=zE(N),g=zE(v);try{await T.updateSlug(B,g)}catch{}let y=VU(G,v);if(aX(y)){let l=await DE(T,y,v,{noEmbed:C});if(l.status==="imported")R+=l.chunks}F.push(g)}let P=z.added.length+z.modified.length>10,k=async()=>{for(let N of[...z.added,...z.modified]){let v=VU(G,N);if(!aX(v))continue;try{let B=await DE(T,v,N,{noEmbed:C});if(B.status==="imported")R+=B.chunks,F.push(B.slug)}catch(B){let g=B instanceof Error?B.message:String(B);console.error(` Warning: skipped ${N}: ${g}`)}}};if(P)await T.transaction(async()=>{await k()});else await k();let _=Date.now()-M;if(await T.setConfig("sync.last_commit",K),await T.setConfig("sync.last_run",new Date().toISOString()),await T.setConfig("sync.repo_path",G),await T.logIngest({source_type:"git_sync",source_ref:`${G} @ ${K.slice(0,8)}`,pages_updated:F,summary:`Sync: +${z.added.length} ~${z.modified.length} -${z.deleted.length} R${z.renamed.length}, ${R} chunks, ${_}ms`}),C&&D>100)console.log("Text imported. Run 'gbrain embed --stale' to generate embeddings.");return{status:"synced",fromCommit:L,toCommit:K,added:z.added.length,modified:z.modified.length,deleted:z.deleted.length,renamed:z.renamed.length,chunksCreated:R,pagesAffected:F}}async function eX(T,Y,G,K){console.log(`Running full import of ${Y}...`);let{runImport:L}=await Promise.resolve().then(() => (KY(),$Y)),W=[Y];if(K.noEmbed)W.push("--no-embed");return await L(T,W),{status:"first_sync",fromCommit:null,toCommit:G,added:0,modified:0,deleted:0,renamed:0,chunksCreated:0,pagesAffected:[]}}async function zG(T,Y){let G=Y.find((R,M)=>Y[M-1]==="--repo")||void 0,K=Y.includes("--watch"),L=Y.find((R,M)=>Y[M-1]==="--interval"),W=L?parseInt(L,10):60,O=Y.includes("--dry-run"),z=Y.includes("--full"),q=Y.includes("--no-pull"),D=Y.includes("--no-embed"),C={repoPath:G,dryRun:O,full:z,noPull:q,noEmbed:D};if(!K){let R=await iX(T,C);SG(R);return}let F=0;console.log(`Watching for changes every ${W}s... (Ctrl+C to stop)`);while(!0){try{let R=await iX(T,{...C,full:!1});if(F=0,R.status==="synced"){let M=new Date().toISOString().slice(11,19);console.log(`[${M}] Synced: +${R.added} ~${R.modified} -${R.deleted} R${R.renamed}`)}}catch(R){F++;let M=R instanceof Error?R.message:String(R);if(console.error(`[${new Date().toISOString().slice(11,19)}] Sync error (${F}/5): ${M}`),F>=5)console.error("5 consecutive sync failures. Stopping watch."),process.exit(1)}await new Promise((R)=>setTimeout(R,W*1000))}}function SG(T){switch(T.status){case"up_to_date":console.log("Already up to date.");break;case"synced":console.log(`Synced ${T.fromCommit?.slice(0,8)}..${T.toCommit.slice(0,8)}:`),console.log(` +${T.added} added, ~${T.modified} modified, -${T.deleted} deleted, R${T.renamed} renamed`),console.log(` ${T.chunksCreated} chunks created`);break;case"first_sync":console.log(`First sync complete. Checkpoint: ${T.toCommit.slice(0,8)}`);break;case"dry_run":break}}var WY=GU(()=>{TE();bE()});var CY={};jU(CY,{S3Storage:()=>RY});import{S3Client as MG,PutObjectCommand as qG,GetObjectCommand as PG,DeleteObjectCommand as _G,HeadObjectCommand as HY,ListObjectsV2Command as kG}from"@aws-sdk/client-s3";class RY{client;bucket;constructor(T){this.bucket=T.bucket;let Y=T.region||"us-east-1";if(!T.accessKeyId||!T.secretAccessKey)throw Error("S3 storage requires accessKeyId and secretAccessKey in config");this.client=new MG({region:Y,...T.endpoint?{endpoint:T.endpoint,forcePathStyle:!0}:{},credentials:{accessKeyId:T.accessKeyId,secretAccessKey:T.secretAccessKey}})}async upload(T,Y,G){await this.client.send(new qG({Bucket:this.bucket,Key:T,Body:Y,ContentType:G||"application/octet-stream"}))}async download(T){let Y=await this.client.send(new PG({Bucket:this.bucket,Key:T}));if(!Y.Body)throw Error(`S3 download returned empty body: ${T}`);return Buffer.from(await Y.Body.transformToByteArray())}async delete(T){await this.client.send(new _G({Bucket:this.bucket,Key:T}))}async exists(T){try{return await this.client.send(new HY({Bucket:this.bucket,Key:T})),!0}catch(Y){if(Y.name==="NotFound"||Y.$metadata?.httpStatusCode===404)return!1;throw Y}}async list(T){return((await this.client.send(new kG({Bucket:this.bucket,Prefix:T}))).Contents||[]).map((G)=>G.Key).filter(Boolean)}async getUrl(T){let Y=this.client.config.endpoint;if(Y)return`${typeof Y==="function"?(await Y()).url.toString():Y}/${this.bucket}/${T}`;let G=await this.client.config.region();return`https://${this.bucket}.s3.${G}.amazonaws.com/${T}`}async getContentHash(T){try{return(await this.client.send(new HY({Bucket:this.bucket,Key:T}))).ETag?.replace(/"/g,"")||null}catch{return null}}}var DY=()=>{};var SY={};jU(SY,{SupabaseStorage:()=>zY});class zY{projectUrl;serviceRoleKey;bucket;constructor(T){if(this.projectUrl=T.projectUrl||"",this.serviceRoleKey=T.serviceRoleKey||"",this.bucket=T.bucket,!this.projectUrl||!this.serviceRoleKey)throw Error("Supabase storage requires projectUrl and serviceRoleKey in config")}url(T){return`${this.projectUrl}/storage/v1/object/${this.bucket}/${T}`}headers(){return{Authorization:`Bearer ${this.serviceRoleKey}`,apikey:this.serviceRoleKey}}async upload(T,Y,G){let K=await fetch(this.url(T),{method:"POST",headers:{...this.headers(),"Content-Type":G||"application/octet-stream","x-upsert":"true"},body:Y});if(!K.ok){let L=await K.text();throw Error(`Supabase upload failed: ${K.status} ${L}`)}}async download(T){let Y=await fetch(this.url(T),{headers:this.headers()});if(!Y.ok)throw Error(`Supabase download failed: ${Y.status}`);return Buffer.from(await Y.arrayBuffer())}async delete(T){let Y=await fetch(`${this.projectUrl}/storage/v1/object/${this.bucket}`,{method:"DELETE",headers:{...this.headers(),"Content-Type":"application/json"},body:JSON.stringify({prefixes:[T]})});if(!Y.ok&&Y.status!==404)throw Error(`Supabase delete failed: ${Y.status}`)}async exists(T){return(await fetch(this.url(T),{method:"HEAD",headers:this.headers()})).ok}async list(T){let Y=await fetch(`${this.projectUrl}/storage/v1/object/list/${this.bucket}`,{method:"POST",headers:{...this.headers(),"Content-Type":"application/json"},body:JSON.stringify({prefix:T,limit:1000})});if(!Y.ok)throw Error(`Supabase list failed: ${Y.status}`);return(await Y.json()).map((K)=>`${T}/${K.name}`)}async getUrl(T){return`${this.projectUrl}/storage/v1/object/public/${this.bucket}/${T}`}}var PY={};jU(PY,{LocalStorage:()=>qY});var{readFileSync:vG,writeFileSync:jG,unlinkSync:NG,existsSync:sE,mkdirSync:MY,readdirSync:BG}=(()=>({}));class qY{basePath;constructor(T){this.basePath=T;MY(T,{recursive:!0})}async upload(T,Y,G){let K=VU(this.basePath,T);MY(nE(K),{recursive:!0}),jG(K,Y)}async download(T){let Y=VU(this.basePath,T);if(!sE(Y))throw Error(`File not found in storage: ${T}`);return vG(Y)}async delete(T){let Y=VU(this.basePath,T);if(sE(Y))NG(Y)}async exists(T){return sE(VU(this.basePath,T))}async list(T){let Y=VU(this.basePath,T);if(!sE(Y))return[];let G=[];function K(L,W){for(let O of BG(L,{withFileTypes:!0})){let z=W?`${W}/${O.name}`:O.name;if(O.isDirectory())K(VU(L,O.name),z);else G.push(`${T}/${z}`)}}return K(Y,""),G}async getUrl(T){return`file://${VU(this.basePath,T)}`}}var _Y=GU(()=>{TE()});var UI={};jU(UI,{createStorage:()=>xG});async function xG(T){switch(T.backend){case"s3":{let{S3Storage:Y}=await Promise.resolve().then(() => (DY(),CY));return new Y(T)}case"supabase":{let{SupabaseStorage:Y}=await Promise.resolve().then(() => SY);return new Y(T)}case"local":{let{LocalStorage:Y}=await Promise.resolve().then(() => (_Y(),PY));return new Y(T.localPath||"/tmp/gbrain-storage")}default:throw Error(`Unknown storage backend: ${T.backend}`)}}bE();uX();function uT(T,Y){let G=Y?.cosineThreshold??0.85,K=Y?.maxTypeRatio??0.6,L=Y?.maxPerPage??2,W=T;return W=aJ(W),W=eJ(W,G),W=iJ(W,K),W=UG(W,L),W}function aJ(T){let Y=new Map;for(let K of T){let L=Y.get(K.slug)||[];L.push(K),Y.set(K.slug,L)}let G=[];for(let K of Y.values())K.sort((L,W)=>W.score-L.score),G.push(...K.slice(0,3));return G.sort((K,L)=>L.score-K.score)}function eJ(T,Y){let G=[];for(let K of T){let L=new Set(K.chunk_text.toLowerCase().split(/\s+/)),W=!1;for(let O of G){let z=new Set(O.chunk_text.toLowerCase().split(/\s+/)),q=new Set([...L].filter((F)=>z.has(F))),D=new Set([...L,...z]);if(q.size/D.size>Y){W=!0;break}}if(!W)G.push(K)}return G}function iJ(T,Y){let G=Math.max(1,Math.ceil(T.length*Y)),K=new Map,L=[];for(let W of T){let O=K.get(W.type)||0;if(OhT(F))),O=await Promise.all(W.map((F)=>T.searchVector(F,{limit:K*2}))),z=await T.searchKeyword(Y,{limit:K*2}),q=[...O,z],D=XG(q);return uT(D).slice(0,K)}function XG(T){let Y=new Map;for(let G of T)for(let K=0;KK.score-G.score).map(({result:G,score:K})=>({...G,score:K}))}import IG from"@anthropic-ai/sdk";var TG=3,YG=3,dX=null;function ZG(){if(!dX)dX=new IG;return dX}async function dT(T){if((T.match(/\S+/g)||[]).lengthW.toLowerCase().trim()))].slice(0,TG).map((W)=>K.find((O)=>O.toLowerCase().trim()===W)||W)}catch{return[T]}}async function OG(T){let Y=await ZG().messages.create({model:"claude-haiku-4-5-20251001",max_tokens:300,tools:[{name:"expand_query",description:"Generate alternative phrasings of a search query to improve recall",input_schema:{type:"object",properties:{alternative_queries:{type:"array",items:{type:"string"},description:"2 alternative phrasings of the original query, each approaching the topic from a different angle"}},required:["alternative_queries"]}}],tool_choice:{type:"tool",name:"expand_query"},messages:[{role:"user",content:`Generate 2 alternative search queries that would find relevant results for this question. Each alternative should approach the topic from a different angle or use different terminology. + +Original query: "${T}"`}]});for(let G of Y.content)if(G.type==="tool_use"&&G.name==="expand_query"){let L=G.input.alternative_queries;if(Array.isArray(L))return L.map(String).slice(0,2)}return[]}oX();class qE extends Error{code;suggestion;docs;constructor(T,Y,G,K){super(Y);this.code=T;this.suggestion=G;this.docs=K;this.name="OperationError"}toJSON(){return{error:this.code,message:this.message,suggestion:this.suggestion,docs:this.docs}}}var gG={name:"get_page",description:"Read a page by slug (supports optional fuzzy matching)",params:{slug:{type:"string",required:!0,description:"Page slug"},fuzzy:{type:"boolean",description:"Enable fuzzy slug resolution (default: false)"}},handler:async(T,Y)=>{let G=Y.slug,K=Y.fuzzy||!1,L=await T.engine.getPage(G),W;if(!L&&K){let z=await T.engine.resolveSlugs(G);if(z.length===1)L=await T.engine.getPage(z[0]),W=z[0];else if(z.length>1)return{error:"ambiguous_slug",candidates:z}}if(!L)throw new qE("page_not_found",`Page not found: ${G}`,"Check the slug or use fuzzy: true");let O=await T.engine.getTags(L.slug);return{...L,tags:O,...W?{resolved_slug:W}:{}}},cliHints:{name:"get",positional:["slug"]}},wG={name:"put_page",description:"Write/update a page (markdown with frontmatter). Chunks, embeds, and reconciles tags.",params:{slug:{type:"string",required:!0,description:"Page slug"},content:{type:"string",required:!0,description:"Full markdown content with YAML frontmatter"}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"put_page",slug:Y.slug};let G=await bX(T.engine,Y.slug,Y.content);return{slug:G.slug,status:G.status==="imported"?"created_or_updated":G.status,chunks:G.chunks}},cliHints:{name:"put",positional:["slug"],stdin:"content"}},yG={name:"delete_page",description:"Delete a page",params:{slug:{type:"string",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"delete_page",slug:Y.slug};return await T.engine.deletePage(Y.slug),{status:"deleted"}},cliHints:{name:"delete",positional:["slug"]}},fG={name:"list_pages",description:"List pages with optional filters",params:{type:{type:"string",description:"Filter by page type"},tag:{type:"string",description:"Filter by tag"},limit:{type:"number",description:"Max results (default 50)"}},handler:async(T,Y)=>{return(await T.engine.listPages({type:Y.type,tag:Y.tag,limit:Y.limit||50})).map((K)=>({slug:K.slug,type:K.type,title:K.title,updated_at:K.updated_at}))},cliHints:{name:"list"}},cG={name:"search",description:"Keyword search using full-text search",params:{query:{type:"string",required:!0},limit:{type:"number",description:"Max results (default 20)"}},handler:async(T,Y)=>{return T.engine.searchKeyword(Y.query,{limit:Y.limit||20})},cliHints:{name:"search",positional:["query"]}},pG={name:"query",description:"Hybrid search with vector + keyword + multi-query expansion",params:{query:{type:"string",required:!0},limit:{type:"number",description:"Max results (default 20)"},expand:{type:"boolean",description:"Enable multi-query expansion (default: true)"}},handler:async(T,Y)=>{let G=Y.expand!==!1;return bT(T.engine,Y.query,{limit:Y.limit||20,expansion:G,expandFn:G?dT:void 0})},cliHints:{name:"query",positional:["query"]}},hG={name:"add_tag",description:"Add tag to page",params:{slug:{type:"string",required:!0},tag:{type:"string",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"add_tag",slug:Y.slug,tag:Y.tag};return await T.engine.addTag(Y.slug,Y.tag),{status:"ok"}},cliHints:{name:"tag",positional:["slug","tag"]}},uG={name:"remove_tag",description:"Remove tag from page",params:{slug:{type:"string",required:!0},tag:{type:"string",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"remove_tag",slug:Y.slug,tag:Y.tag};return await T.engine.removeTag(Y.slug,Y.tag),{status:"ok"}},cliHints:{name:"untag",positional:["slug","tag"]}},bG={name:"get_tags",description:"List tags for a page",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getTags(Y.slug)},cliHints:{name:"tags",positional:["slug"]}},dG={name:"add_link",description:"Create link between pages",params:{from:{type:"string",required:!0},to:{type:"string",required:!0},link_type:{type:"string",description:"Link type (e.g., invested_in, works_at)"},context:{type:"string",description:"Context for the link"}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"add_link",from:Y.from,to:Y.to};return await T.engine.addLink(Y.from,Y.to,Y.context||"",Y.link_type||""),{status:"ok"}},cliHints:{name:"link",positional:["from","to"]}},lG={name:"remove_link",description:"Remove link between pages",params:{from:{type:"string",required:!0},to:{type:"string",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"remove_link",from:Y.from,to:Y.to};return await T.engine.removeLink(Y.from,Y.to),{status:"ok"}},cliHints:{name:"unlink",positional:["from","to"]}},oG={name:"get_links",description:"List outgoing links from a page",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getLinks(Y.slug)}},nG={name:"get_backlinks",description:"List incoming links to a page",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getBacklinks(Y.slug)},cliHints:{name:"backlinks",positional:["slug"]}},mG={name:"traverse_graph",description:"Traverse link graph from a page",params:{slug:{type:"string",required:!0},depth:{type:"number",description:"Max traversal depth (default 5)"}},handler:async(T,Y)=>{return T.engine.traverseGraph(Y.slug,Y.depth||5)},cliHints:{name:"graph",positional:["slug"]}},sG={name:"add_timeline_entry",description:"Add timeline entry to a page",params:{slug:{type:"string",required:!0},date:{type:"string",required:!0},summary:{type:"string",required:!0},detail:{type:"string"},source:{type:"string"}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"add_timeline_entry",slug:Y.slug};return await T.engine.addTimelineEntry(Y.slug,{date:Y.date,source:Y.source||"",summary:Y.summary,detail:Y.detail||""}),{status:"ok"}},cliHints:{name:"timeline-add",positional:["slug","date","summary"]}},rG={name:"get_timeline",description:"Get timeline entries for a page",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getTimeline(Y.slug)},cliHints:{name:"timeline",positional:["slug"]}},tG={name:"get_stats",description:"Brain statistics (page count, chunk count, etc.)",params:{},handler:async(T)=>{return T.engine.getStats()},cliHints:{name:"stats"}},aG={name:"get_health",description:"Brain health dashboard (embed coverage, stale pages, orphans)",params:{},handler:async(T)=>{return T.engine.getHealth()},cliHints:{name:"health"}},eG={name:"get_versions",description:"Page version history",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getVersions(Y.slug)},cliHints:{name:"history",positional:["slug"]}},iG={name:"revert_version",description:"Revert page to a previous version",params:{slug:{type:"string",required:!0},version_id:{type:"number",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"revert_version",slug:Y.slug,version_id:Y.version_id};return await T.engine.createVersion(Y.slug),await T.engine.revertToVersion(Y.slug,Y.version_id),{status:"reverted"}},cliHints:{name:"revert",positional:["slug","version_id"]}},UV={name:"sync_brain",description:"Sync git repo to brain (incremental)",params:{repo:{type:"string",description:"Path to git repo (optional if configured)"},dry_run:{type:"boolean",description:"Preview changes without applying"},full:{type:"boolean",description:"Full re-sync (ignore checkpoint)"},no_pull:{type:"boolean",description:"Skip git pull"},no_embed:{type:"boolean",description:"Skip embedding generation"}},mutating:!0,handler:async(T,Y)=>{let{performSync:G}=await Promise.resolve().then(() => (WY(),FY));return G(T.engine,{repoPath:Y.repo,dryRun:T.dryRun||Y.dry_run||!1,noEmbed:Y.no_embed||!1,noPull:Y.no_pull||!1,full:Y.full||!1})},cliHints:{name:"sync"}},EV={name:"put_raw_data",description:"Store raw API response data for a page",params:{slug:{type:"string",required:!0},source:{type:"string",required:!0,description:"Data source (e.g., crustdata, happenstance)"},data:{type:"object",required:!0,description:"Raw data object"}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"put_raw_data",slug:Y.slug,source:Y.source};return await T.engine.putRawData(Y.slug,Y.source,Y.data),{status:"ok"}}},XV={name:"get_raw_data",description:"Retrieve raw data for a page",params:{slug:{type:"string",required:!0},source:{type:"string",description:"Filter by source"}},handler:async(T,Y)=>{return T.engine.getRawData(Y.slug,Y.source)}},IV={name:"resolve_slugs",description:"Fuzzy-resolve a partial slug to matching page slugs",params:{partial:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.resolveSlugs(Y.partial)}},TV={name:"get_chunks",description:"Get content chunks for a page",params:{slug:{type:"string",required:!0}},handler:async(T,Y)=>{return T.engine.getChunks(Y.slug)}},YV={name:"log_ingest",description:"Log an ingestion event",params:{source_type:{type:"string",required:!0},source_ref:{type:"string",required:!0},pages_updated:{type:"array",required:!0,items:{type:"string"}},summary:{type:"string",required:!0}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"log_ingest"};return await T.engine.logIngest({source_type:Y.source_type,source_ref:Y.source_ref,pages_updated:Y.pages_updated,summary:Y.summary}),{status:"ok"}}},ZV={name:"get_ingest_log",description:"Get recent ingestion log entries",params:{limit:{type:"number",description:"Max entries (default 20)"}},handler:async(T,Y)=>{return T.engine.getIngestLog({limit:Y.limit||20})}},OV={name:"file_list",description:"List stored files",params:{slug:{type:"string",description:"Filter by page slug"}},handler:async(T,Y)=>{let G=eU(),K=Y.slug;if(K)return G`SELECT id, page_slug, filename, storage_path, mime_type, size_bytes, content_hash, created_at FROM files WHERE page_slug = ${K} ORDER BY filename`;return G`SELECT id, page_slug, filename, storage_path, mime_type, size_bytes, content_hash, created_at FROM files ORDER BY page_slug, filename LIMIT 100`}},QV={name:"file_upload",description:"Upload a file to storage",params:{path:{type:"string",required:!0,description:"Local file path"},page_slug:{type:"string",description:"Associate with page"}},mutating:!0,handler:async(T,Y)=>{if(T.dryRun)return{dry_run:!0,action:"file_upload",path:Y.path};let{readFileSync:G,statSync:K}=await import("fs"),{basename:L,extname:W}=await Promise.resolve().then(() => (TE(),TY)),{createHash:O}=await Promise.resolve().then(() => (DU(),PU)),z=Y.path,q=Y.page_slug||null,D=K(z),C=G(z),F=O("sha256").update(C).digest("hex"),R=L(z),M=q?`${q}/${R}`:`unsorted/${F.slice(0,8)}-${R}`,k={".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".pdf":"application/pdf",".mp4":"video/mp4",".mp3":"audio/mpeg"}[W(z).toLowerCase()]||null,_=eU();if((await _`SELECT id FROM files WHERE content_hash = ${F} AND storage_path = ${M}`).length>0)return{status:"already_exists",storage_path:M};if(T.config.storage){let{createStorage:v}=await Promise.resolve().then(() => UI),B=await v(T.config.storage);try{await B.upload(M,C,k||void 0)}catch(g){throw new qE("storage_error",`Upload failed: ${g instanceof Error?g.message:String(g)}`)}}try{await _` + INSERT INTO files (page_slug, filename, storage_path, mime_type, size_bytes, content_hash, metadata) + VALUES (${q}, ${R}, ${M}, ${k}, ${D.size}, ${F}, ${"{}"}::jsonb) + ON CONFLICT (storage_path) DO UPDATE SET + content_hash = EXCLUDED.content_hash, + size_bytes = EXCLUDED.size_bytes, + mime_type = EXCLUDED.mime_type + `}catch(v){if(T.config.storage)try{let{createStorage:B}=await Promise.resolve().then(() => UI);await(await B(T.config.storage)).delete(M)}catch{}throw v}return{status:"uploaded",storage_path:M,size_bytes:D.size}}},JV={name:"file_url",description:"Get a URL for a stored file",params:{storage_path:{type:"string",required:!0}},handler:async(T,Y)=>{let K=await eU()`SELECT storage_path, mime_type, size_bytes FROM files WHERE storage_path = ${Y.storage_path}`;if(K.length===0)throw new qE("storage_error",`File not found: ${Y.storage_path}`);return{storage_path:K[0].storage_path,url:`gbrain:files/${K[0].storage_path}`}}},kY=[gG,wG,yG,fG,cG,pG,hG,uG,bG,dG,lG,oG,nG,mG,sG,rG,tG,aG,eG,iG,UV,EV,XV,IV,TV,YV,ZV,OV,QV,JV],GV=Object.fromEntries(kY.map((T)=>[T.name,T]));tX();dE();var vY={name:"gbrain",version:"0.4.1",description:"Postgres-native personal knowledge brain with hybrid RAG search",type:"module",main:"src/core/index.ts",bin:{gbrain:"src/cli.ts"},exports:{".":"./src/core/index.ts","./engine":"./src/core/engine.ts","./types":"./src/core/types.ts","./operations":"./src/core/operations.ts"},scripts:{dev:"bun run src/cli.ts",build:"bun build --compile --outfile bin/gbrain src/cli.ts","build:all":"bun build --compile --target=bun-darwin-arm64 --outfile bin/gbrain-darwin-arm64 src/cli.ts && bun build --compile --target=bun-linux-x64 --outfile bin/gbrain-linux-x64 src/cli.ts","build:schema":"bash scripts/build-schema.sh","build:edge":"bun run build:schema && bun build src/edge-entry.ts --format=esm --outfile=supabase/functions/gbrain-mcp/gbrain-core.js --external=postgres --external=openai --external=fs --external=os --external=path --external=crypto --external=child_process --external=@aws-sdk/client-s3 --external=@anthropic-ai/sdk --external=gray-matter --minify",test:"bun test","test:e2e":"bun test test/e2e/","prepublish:clawhub":"bun run build:all","publish:clawhub":"clawhub package publish . --family bundle-plugin"},openclaw:{compat:{pluginApi:">=2026.4.0"}},dependencies:{"@anthropic-ai/sdk":"^0.30.0","@aws-sdk/client-s3":"^3.1028.0","@modelcontextprotocol/sdk":"^1.0.0","gray-matter":"^4.0.3",openai:"^4.0.0",pgvector:"^0.2.0",postgres:"^3.4.0"},devDependencies:{"@types/bun":"latest"},license:"MIT"};var AV=vY.version;export{GV as operationsByName,kY as operations,AV as VERSION,mE as PostgresEngine,qE as OperationError,tU as GBrainError}; diff --git a/supabase/functions/gbrain-mcp/index.ts b/supabase/functions/gbrain-mcp/index.ts new file mode 100644 index 000000000..4c0c61784 --- /dev/null +++ b/supabase/functions/gbrain-mcp/index.ts @@ -0,0 +1,288 @@ +/** + * GBrain Remote MCP Server — Supabase Edge Function + * + * Exposes GBrain operations as remote MCP tools via Streamable HTTP transport. + * Auth via bearer tokens stored in access_tokens table (SHA-256 hashed). + * + * Deploy: supabase functions deploy gbrain-mcp --no-verify-jwt + * URL: https://.supabase.co/functions/v1/gbrain-mcp/mcp + */ +import { Hono } from 'hono'; +import { cors } from 'hono/cors'; +import { Server } from '@modelcontextprotocol/sdk/server/index.js'; +import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js'; +import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; +import postgres from 'postgres'; +import { createHash } from 'crypto'; +import { operations, OperationError, PostgresEngine, VERSION } from './gbrain-core.js'; +import type { OperationContext } from './gbrain-core.js'; + +// Operations excluded from remote (may exceed 60s Edge Function timeout) +const REMOTE_EXCLUDED = new Set(['sync_brain', 'file_upload']); +const remoteOps = operations.filter((op: any) => !REMOTE_EXCLUDED.has(op.name)); + +// Database connection (lazy, one per isolate) +let engine: PostgresEngine | null = null; +let sql: ReturnType | null = null; + +function getDbUrl(): string { + // @ts-ignore: Deno env + return Deno.env.get('SUPABASE_DB_URL') || Deno.env.get('DATABASE_URL') || ''; +} + +function getOpenAiKey(): string { + // @ts-ignore: Deno env + return Deno.env.get('OPENAI_API_KEY') || ''; +} + +async function getEngine(): Promise { + if (!engine) { + engine = new PostgresEngine(); + await engine.connect({ database_url: getDbUrl(), poolSize: 1 }); + } + return engine; +} + +function getDirectSql(): ReturnType { + if (!sql) { + sql = postgres(getDbUrl(), { max: 1 }); + } + return sql; +} + +// Auth: check bearer token against access_tokens table +async function authenticateToken(authHeader: string | null): Promise<{ valid: boolean; name?: string; error?: string; status?: number }> { + if (!authHeader || !authHeader.startsWith('Bearer ')) { + return { + valid: false, + error: JSON.stringify({ + error: 'missing_auth', + message: "Authorization header required. Use 'Bearer ' format.", + docs: 'docs/mcp/DEPLOY.md#authentication', + }), + status: 401, + }; + } + + const token = authHeader.slice(7); + const hash = createHash('sha256').update(token).digest('hex'); + + try { + const conn = getDirectSql(); + const rows = await conn` + SELECT name, revoked_at FROM access_tokens + WHERE token_hash = ${hash} + `; + + if (rows.length === 0) { + return { + valid: false, + error: JSON.stringify({ + error: 'invalid_token', + message: "Token not recognized. Run 'bun run src/commands/auth.ts list' to see active tokens.", + docs: 'docs/mcp/DEPLOY.md#troubleshooting', + }), + status: 401, + }; + } + + if (rows[0].revoked_at) { + const revokedDate = new Date(rows[0].revoked_at as string).toISOString().slice(0, 10); + return { + valid: false, + error: JSON.stringify({ + error: 'token_revoked', + message: `This token was revoked on ${revokedDate}. Create a new one with 'bun run src/commands/auth.ts create '.`, + docs: 'docs/mcp/DEPLOY.md#token-management', + }), + status: 403, + }; + } + + // Update last_used_at + const conn2 = getDirectSql(); + await conn2`UPDATE access_tokens SET last_used_at = now() WHERE token_hash = ${hash}`; + + return { valid: true, name: rows[0].name as string }; + } catch { + return { + valid: false, + error: JSON.stringify({ + error: 'service_unavailable', + message: 'Database connection failed. Check Supabase dashboard for status.', + docs: 'docs/mcp/DEPLOY.md#troubleshooting', + }), + status: 503, + }; + } +} + +// Log MCP request for auditing +async function logRequest(tokenName: string, operation: string, latencyMs: number, status: string) { + try { + const conn = getDirectSql(); + await conn` + INSERT INTO mcp_request_log (token_name, operation, latency_ms, status) + VALUES (${tokenName}, ${operation}, ${latencyMs}, ${status}) + `; + } catch { + // Best effort, don't crash on log failure + console.error('[gbrain-mcp] Failed to log request'); + } +} + +// Create MCP Server with tool handlers +function createMcpServer(eng: PostgresEngine): Server { + const server = new Server( + { name: 'gbrain', version: VERSION }, + { capabilities: { tools: {} } }, + ); + + server.setRequestHandler(ListToolsRequestSchema, async () => ({ + tools: remoteOps.map((op: any) => ({ + name: op.name, + description: op.description, + inputSchema: { + type: 'object' as const, + properties: Object.fromEntries( + Object.entries(op.params).map(([k, v]: [string, any]) => [k, { + type: v.type === 'array' ? 'array' : v.type, + ...(v.description ? { description: v.description } : {}), + ...(v.enum ? { enum: v.enum } : {}), + ...(v.items ? { items: { type: v.items.type } } : {}), + }]), + ), + required: Object.entries(op.params) + .filter(([, v]: [string, any]) => v.required) + .map(([k]: [string, any]) => k), + }, + })), + })); + + server.setRequestHandler(CallToolRequestSchema, async (request: any) => { + const { name, arguments: params } = request.params; + const op = remoteOps.find((o: any) => o.name === name); + if (!op) { + return { content: [{ type: 'text', text: `Error: Unknown tool: ${name}` }], isError: true }; + } + + const ctx: OperationContext = { + engine: eng, + config: { + engine: 'postgres', + database_url: getDbUrl(), + openai_api_key: getOpenAiKey(), + }, + logger: { + info: (msg: string) => console.log(`[info] ${msg}`), + warn: (msg: string) => console.warn(`[warn] ${msg}`), + error: (msg: string) => console.error(`[error] ${msg}`), + }, + dryRun: !!(params?.dry_run), + }; + + try { + const result = await op.handler(ctx, params || {}); + return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; + } catch (e: unknown) { + if (e instanceof OperationError) { + return { content: [{ type: 'text', text: JSON.stringify(e.toJSON(), null, 2) }], isError: true }; + } + const msg = e instanceof Error ? e.message : String(e); + return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true }; + } + }); + + return server; +} + +// Hono app — routes: /mcp (MCP transport), /health (monitoring) +const app = new Hono().basePath('/gbrain-mcp'); + +app.use('/*', cors({ + origin: '*', + allowMethods: ['GET', 'POST', 'DELETE', 'OPTIONS'], + allowHeaders: ['Content-Type', 'Authorization', 'Mcp-Session-Id', 'Mcp-Protocol-Version', 'Last-Event-ID'], + exposeHeaders: ['Mcp-Session-Id'], +})); + +// Health check +app.get('/health', async (c) => { + const authHeader = c.req.header('Authorization'); + + // Unauth: minimal response + if (!authHeader) { + try { + const conn = getDirectSql(); + await conn`SELECT 1`; + return c.json({ status: 'ok', version: VERSION }); + } catch { + return c.json({ status: 'error' }, 503); + } + } + + // Auth: detailed checks + const auth = await authenticateToken(authHeader); + if (!auth.valid) return c.json({ status: 'error' }, auth.status); + + const checks: Record = {}; + try { + const conn = getDirectSql(); + await conn`SELECT 1`; + checks.postgres = 'ok'; + } catch { + checks.postgres = 'error'; + } + + try { + const conn = getDirectSql(); + const ext = await conn`SELECT extname FROM pg_extension WHERE extname = 'vector'`; + checks.pgvector = ext.length > 0 ? 'ok' : 'missing'; + } catch { + checks.pgvector = 'error'; + } + + checks.openai = getOpenAiKey() ? 'configured' : 'missing'; + + const status = Object.values(checks).every(v => v === 'ok' || v === 'configured') ? 'ok' : 'degraded'; + return c.json({ status, version: VERSION, checks }); +}); + +// MCP endpoint +app.all('/mcp', async (c) => { + // Auth check + const auth = await authenticateToken(c.req.header('Authorization') || null); + if (!auth.valid) { + return new Response(auth.error, { + status: auth.status || 401, + headers: { 'Content-Type': 'application/json' }, + }); + } + + const startTime = Date.now(); + const eng = await getEngine(); + const server = createMcpServer(eng); + + const transport = new WebStandardStreamableHTTPServerTransport({ + // Stateless mode — no sessions needed for single-user personal brain + }); + + await server.connect(transport); + + try { + const response = await transport.handleRequest(c.req.raw); + + // Log the request (await to ensure it completes before isolate dies) + const latency = Date.now() - startTime; + await logRequest(auth.name || 'unknown', 'mcp_request', latency, 'success'); + + return response; + } catch (e) { + const latency = Date.now() - startTime; + await logRequest(auth.name || 'unknown', 'mcp_request', latency, 'error'); + throw e; + } +}); + +// @ts-ignore: Deno.serve +Deno.serve(app.fetch); diff --git a/test/e2e/mechanical.test.ts b/test/e2e/mechanical.test.ts index 64c7155cb..b5a634e64 100644 --- a/test/e2e/mechanical.test.ts +++ b/test/e2e/mechanical.test.ts @@ -524,7 +524,7 @@ describeE2E('E2E: Setup Journey', () => { const stdout = new TextDecoder().decode(result.stdout); expect(result.exitCode).toBe(0); expect(stdout).toContain('Brain ready'); - }); + }, 30_000); test('gbrain import imports fixtures via CLI', () => { const result = Bun.spawnSync({ @@ -536,7 +536,7 @@ describeE2E('E2E: Setup Journey', () => { const stdout = new TextDecoder().decode(result.stdout); expect(result.exitCode).toBe(0); expect(stdout).toContain('imported'); - }); + }, 60_000); test('gbrain search returns results via CLI', () => { const result = Bun.spawnSync({ @@ -548,7 +548,7 @@ describeE2E('E2E: Setup Journey', () => { const stdout = new TextDecoder().decode(result.stdout); expect(result.exitCode).toBe(0); expect(stdout.length).toBeGreaterThan(0); - }); + }, 30_000); test('gbrain stats shows page count via CLI', () => { const result = Bun.spawnSync({ @@ -558,7 +558,7 @@ describeE2E('E2E: Setup Journey', () => { timeout: 15_000, }); expect(result.exitCode).toBe(0); - }); + }, 30_000); test('gbrain health runs via CLI', () => { const result = Bun.spawnSync({ @@ -568,7 +568,7 @@ describeE2E('E2E: Setup Journey', () => { timeout: 15_000, }); expect(result.exitCode).toBe(0); - }); + }, 30_000); }); // ───────────────────────────────────────────────────────────────── @@ -787,7 +787,7 @@ describeE2E('E2E: Doctor Command', () => { timeout: 15_000, }); expect(result.exitCode).toBe(0); - }); + }, 60_000); test('gbrain doctor --json produces valid JSON', () => { const result = Bun.spawnSync({ @@ -806,7 +806,7 @@ describeE2E('E2E: Doctor Command', () => { expect(typeof check.name).toBe('string'); expect(typeof check.message).toBe('string'); } - }); + }, 30_000); }); // ───────────────────────────────────────────────────────────────── @@ -851,7 +851,7 @@ describeE2E('E2E: Parallel Import', () => { expect(seqPageCount).toBeGreaterThan(0); expect(seqChunkCount).toBeGreaterThan(0); - }); + }, 60_000); test('parallel import with --workers 2 matches sequential page count', async () => { await setupDB(); @@ -866,7 +866,7 @@ describeE2E('E2E: Parallel Import', () => { const stats = await callOp('get_stats') as any; expect(stats.page_count).toBe(seqPageCount); - }); + }, 60_000); test('parallel import has same chunk count (no duplicates)', async () => { const stats = await callOp('get_stats') as any; @@ -912,7 +912,7 @@ describeE2E('E2E: Parallel Import', () => { const stats = await callOp('get_stats') as any; expect(stats.page_count).toBe(seqPageCount); expect(stats.chunk_count).toBe(seqChunkCount); - }); + }, 60_000); test('re-import with workers is idempotent', async () => { // Import again on top of existing data @@ -927,7 +927,7 @@ describeE2E('E2E: Parallel Import', () => { const stats = await callOp('get_stats') as any; expect(stats.page_count).toBe(seqPageCount); expect(stats.chunk_count).toBe(seqChunkCount); - }); + }, 60_000); }); // ───────────────────────────────────────────────────────────────── diff --git a/test/sync.test.ts b/test/sync.test.ts index a10b3571c..270cc8714 100644 --- a/test/sync.test.ts +++ b/test/sync.test.ts @@ -94,7 +94,7 @@ describe('pathToSlug', () => { expect(pathToSlug('people/pedro-franceschi.md')).toBe('people/pedro-franceschi'); }); - test('lowercases uppercase paths', () => { + test('normalizes to lowercase', () => { expect(pathToSlug('People/Pedro-Franceschi.md')).toBe('people/pedro-franceschi'); });