{"id":15447900,"url":"https://github.com/hazae41/berith","last_synced_at":"2026-03-05T22:31:12.970Z","repository":{"id":60787852,"uuid":"337172654","full_name":"hazae41/berith","owner":"hazae41","description":"WebAssembly port of Ed25519 signatures and X25519 key exchange","archived":false,"fork":false,"pushed_at":"2025-05-25T06:02:20.000Z","size":2458,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-21T04:09:17.216Z","etag":null,"topics":["browser","csprng","curve25519","deno","diffie-hellman","ecdh","ecdsa","ed25519","eddsa","javascript","prng","rust","signature","typescript","wasm","web","webassembly","webcrypto","x25519"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hazae41.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-08T18:35:39.000Z","updated_at":"2025-05-25T06:02:24.000Z","dependencies_parsed_at":"2024-06-20T00:15:00.084Z","dependency_job_id":"8d7c77b1-281f-4ce5-bbd9-27053990398d","html_url":"https://github.com/hazae41/berith","commit_stats":{"total_commits":102,"total_committers":3,"mean_commits":34.0,"dds":0.07843137254901966,"last_synced_commit":"953e178e033c22523859b5025107ecc478293280"},"previous_names":["hazae41/ed25519-dalek-wasm"],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/hazae41/berith","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazae41%2Fberith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazae41%2Fberith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazae41%2Fberith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazae41%2Fberith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hazae41","download_url":"https://codeload.github.com/hazae41/berith/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazae41%2Fberith/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30152840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T21:15:50.531Z","status":"ssl_error","status_checked_at":"2026-03-05T21:15:11.173Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","csprng","curve25519","deno","diffie-hellman","ecdh","ecdsa","ed25519","eddsa","javascript","prng","rust","signature","typescript","wasm","web","webassembly","webcrypto","x25519"],"created_at":"2024-10-01T20:20:56.600Z","updated_at":"2026-03-05T22:31:12.797Z","avatar_url":"https://github.com/hazae41.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\n  \u003cimg align=\"right\" width=\"128\" src=\"https://user-images.githubusercontent.com/4405263/216624164-ee65f3ea-0857-40ad-8423-fff8014202c1.png\"/\u003e\n  \u003cp\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n# Berith\n\nWebAssembly port of Ed25519 signatures and X25519 key exchange\n\n```bash\nnpm i @hazae41/berith\n```\n\n[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/berith) • [**Deno Module 🦖**](https://deno.land/x/berith) • [**Next.js CodeSandbox 🪣**](https://codesandbox.io/p/github/hazae41/berith-example-next)\n\n## Algorithms\n- Ed25519 from Dalek (ed25519-dalek)\n- X25519 from Dalek (ed25519-dalek)\n\n## Features\n- Reproducible building\n- Pre-bundled and streamed\n- Zero-copy memory slices\n\n## Benchmark\n\n### Deno\n\n```bash\ngit clone https://github.com/hazae41/berith \u0026\u0026 cd berith \u0026\u0026 npm i \u0026\u0026 npm run bench:deno\n```\n\n```\ncpu: Apple M1 Max\nruntime: deno 1.30.3 (aarch64-apple-darwin)\n\nfile:///src/deno/bench/mod.bench.ts\nbenchmark                           time (avg)             (min … max)       p75       p99      p995\n---------------------------------------------------------------------- -----------------------------\n@hazae41/berith (unserialized)  325.78 µs/iter (316.04 µs … 491.04 µs) 326.21 µs 348.62 µs 364.54 µs\n@hazae41/berith (serialized)     368.3 µs/iter (359.12 µs … 537.71 µs) 368.79 µs 399.92 µs 406.54 µs\n@noble/curves 0.7.0                1.9 ms/iter      (1.73 ms … 2.3 ms)   1.96 ms   2.26 ms   2.28 ms\n\nsummary\n  @hazae41/berith (unserialized)\n   1.13x faster than @hazae41/berith (serialized)\n   5.85x faster than @noble/curves 0.7.0\n```\n\n### Node\n\n```bash\ngit clone https://github.com/hazae41/berith \u0026\u0026 cd berith \u0026\u0026 npm i \u0026\u0026 npm run bench:node\n```\n\n```\ncpu: Apple M1 Max\nruntime: node v18.12.1 (aarch64-apple-darwin)\n\n┌────────────────────────────────┬──────────────────┬─────────────┬─────────────┐\n│            (index)             │     average      │   minimum   │   maximum   │\n├────────────────────────────────┼──────────────────┼─────────────┼─────────────┤\n│ @hazae41/berith (unserialized) │ '281.68 μs/iter' │ '273.83 μs' │ '875.92 μs' │\n│  @hazae41/berith (serialized)  │ '318.67 μs/iter' │ '311.29 μs' │ '938.87 μs' │\n│      @noble/curves 0.7.0       │  '1.99 ms/iter'  │  '1.82 ms'  │  '5.91 ms'  │\n│      supercop.wasm 5.0.1       │ '187.96 μs/iter' │ '179.21 μs' │ '734.29 μs' │\n│   node:crypto (unserialized)   │ '152.67 μs/iter' │ '144.96 μs' │  '2.86 ms'  │\n│    node:crypto (serialized)    │ '555.61 μs/iter' │ '549.42 μs' │  '1.20 ms'  │\n└────────────────────────────────┴──────────────────┴─────────────┴─────────────┘\n\nSummary\n- @hazae41/berith (unserialized) is 1.13x faster than @hazae41/berith (serialized)\n- @hazae41/berith (unserialized) is 7.06x faster than @noble/curves 0.7.0\n- @hazae41/berith (unserialized) is 0.67x faster than supercop.wasm 5.0.1\n- @hazae41/berith (unserialized) is 0.54x faster than node:crypto (unserialized)\n- @hazae41/berith (unserialized) is 1.97x faster than node:crypto (serialized)\n```\n\n## Usage\n\n### Ed25519 (EdDSA over Curve25519)\n\n```ts\nimport { Berith, Ed25519SigningKey } from \"@hazae41/berith\"\n// import { Berith, Ed25519SigningKey } from \"https://deno.land/x/berith/src/deno/mod.ts\"\n\n// Wait for WASM to load\nawait Berith.initBundledOnce();\n\n// Generate random private key\nusing privateKey = Ed25519SigningKey.random() // Ed25519SigningKey\n\n// Get public key\nusing publicKey = privateKey.public() // Ed25519VerifyingKey\n\n// Encode some message to sign as UTF-8\nconst data = new TextEncoder().encode(\"hello world\") // Uint8Array\n\n// Put data in memory\nusing mdata = new Berith.Memory(data) // Berith.Memory\n\n// Sign data with private key\nusing signature = privateKey.sign(mdata) // Ed25519Signature\n\n// Verify signature with public key\nconst verified = publicKey.verify(mdata, signature) // boolean\n```\n\n### X25519 (ECDH over Curve25519)\n\n```ts\nimport { Berith, X25519StaticSecret } from \"@hazae41/berith\"\n// import { Berith, X25519StaticSecret } from \"https://deno.land/x/berith/src/deno/mod.ts\"\n\n// Wait for WASM to load\nawait Berith.initBundledOnce()\n\n// Generate Alice's random private key\nusing alicePrivateKey = new X25519StaticSecret()\n\n// Get Alice's public key\nusing alicePublicKey = alicePrivateKey.to_public()\n\n// Generate Bob's random private key\nusing bobPrivateKey = new X25519StaticSecret()\n\n// Get Bob's public key\nusing bobPublicKey = bobPrivateKey.to_public()\n\n// Derive Alice's shared key from Bob's public key\nusing aliceSharedKey = alicePrivateKey.diffie_hellman(bobPublicKey)\n\n// Derive Bob's shared key from Alice's public key\nusing bobSharedKey = bobPrivateKey.diffie_hellman(alicePublicKey)\n```\n\n### Memory\n\nYou have to wrap Uint8Array into Memory in order to pass them to WebAssembly\n\n```typescript\nfunction exampleFromBytes(bytes: Uint8Array) {\n  using memory = new Berith.Memory(bytes)\n  Berith.example(memory)\n}\n```\n\nYou have to get Uint8Array from Memory via either copy or view\n\n```typescript\nfunction exampleWithCopy() {\n  const bytes = Berith.example().copyAndDispose() // Uint8Array\n}\n```\n\n```typescript\nfunction exampleWithView() {\n  using memory = Berith.example() // X.Memory\n  const bytes = memory.bytes // Uint8Array\n}\n```\n\nDon't forget to free memory with `using` keyword, `.free()` method, or `.freeNextTick()` method\n\n```typescript\nfunction exampleWithUsing() {\n  using memory = Berith.example()\n\n  // Do stuff with `memory` or `memory.bytes`\n  ...\n\n  // Memory is automatically freed by `using` keyword\n}\n```\n\n```typescript\nfunction exampleWithFree() {\n  const memory = Berith.example()\n\n  // Do stuff with `memory` or `memory.bytes`\n  ...\n\n  memory.free()\n}\n```\n\n```typescript\nfunction exampleWithFreeNextTick() {\n  const memory = Berith.example().freeNextTick()\n\n  // Do synchronous stuff with `memory` or `memory.bytes`\n  ...\n\n  // Memory is automatically freed by `.freeNextTick()` method\n}\n```\n\n### Serialization\n\nYou can serialize and deserialize almost any type to and from Memory (and Uint8Array)\n\n```typescript\n// Generate a private key\nusing privateKey = Ed25519SigningKey.random()\n\n// Extract private key into Memory bytes\nusing privateKeyMemory = privateKey.to_bytes() // Berith.Memory\n\n...\n\n// Get back private key from Memory bytes\nusing privateKey2 = Ed25519SigningKey.from_bytes(privateKeyMemory)\n```\n\n```typescript\n// Generate a private key\nusing privateKey = Ed25519SigningKey.random()\n\n// Extract private key into JavaScript bytes\nconst privateKeyBytes = privateKey.to_bytes().copyAndDispose()\n\n...\n\n// Wrap JavaScript bytes into Memory bytes\nusing privateKeyMemory = new Berith.Memory(privateKeyBytes)\n\n// Get back private key from Memory bytes\nusing privateKey2 = Ed25519SigningKey.from_bytes(privateKeyMemory)\n```\n\n## Building\n\n### Unreproducible building\n\nYou need to install [Rust](https://www.rust-lang.org/tools/install)\n\nThen, install [wasm-pack](https://github.com/rustwasm/wasm-pack)\n\n```bash\ncargo install wasm-pack\n```\n\nFinally, do a clean install and build\n\n```bash\nnpm ci \u0026\u0026 npm run build\n```\n\n### Reproducible building\n\nYou can build the exact same bytecode using Docker, just be sure you're on a `linux/amd64` host\n\n```bash\ndocker compose up --build\n```\n\nThen check that all the files are the same using `git status`\n\n```bash\ngit status --porcelain\n```\n\nIf the output is empty then the bytecode is the same as the one I commited\n\n### Automated checks\n\nEach time I commit to the repository, the GitHub's CI does the following:\n- Clone the repository\n- Reproduce the build using `docker compose up --build`\n- Throw an error if the `git status --porcelain` output is not empty\n\nEach time I release a new version tag on GitHub, the GitHub's CI does the following:\n- Clone the repository\n- Do not reproduce the build, as it's already checked by the task above\n- Throw an error if there is a `npm diff` between the cloned repository and the same version tag on NPM\n\nIf a version is present on NPM but not on GitHub, do not use!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazae41%2Fberith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazae41%2Fberith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazae41%2Fberith/lists"}