{"id":13632884,"url":"https://github.com/ChainSafe/bls","last_synced_at":"2025-04-18T05:33:30.378Z","repository":{"id":40307074,"uuid":"241972396","full_name":"ChainSafe/bls","owner":"ChainSafe","description":"💻 Javascript Implementation of Boneh-Lynn-Shacham Signatures","archived":false,"fork":false,"pushed_at":"2024-09-16T02:26:18.000Z","size":1498,"stargazers_count":101,"open_issues_count":14,"forks_count":19,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-04T10:44:24.754Z","etag":null,"topics":["bls","bls-signatures","bls12-381","eth2","eth2-beacon-chain","wasm"],"latest_commit_sha":null,"homepage":"https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#bls-signatures","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChainSafe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://etherscan.io/address/0xb4da52336092db22fe8e036866d59c6488604f89"}},"created_at":"2020-02-20T19:33:41.000Z","updated_at":"2024-10-30T07:49:55.000Z","dependencies_parsed_at":"2024-01-14T07:18:10.105Z","dependency_job_id":"08fdce7e-1468-485b-9d7b-bc3cb503fd36","html_url":"https://github.com/ChainSafe/bls","commit_stats":{"total_commits":374,"total_committers":21,"mean_commits":17.80952380952381,"dds":0.7032085561497325,"last_synced_commit":"648c9a07c404d57e375ae91f71016505c9ef249c"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChainSafe%2Fbls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChainSafe%2Fbls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChainSafe%2Fbls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChainSafe%2Fbls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChainSafe","download_url":"https://codeload.github.com/ChainSafe/bls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223775291,"owners_count":17200487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bls","bls-signatures","bls12-381","eth2","eth2-beacon-chain","wasm"],"created_at":"2024-08-01T22:03:21.753Z","updated_at":"2024-11-09T01:30:58.263Z","avatar_url":"https://github.com/ChainSafe.png","language":"TypeScript","funding_links":["https://etherscan.io/address/0xb4da52336092db22fe8e036866d59c6488604f89"],"categories":["TypeScript"],"sub_categories":[],"readme":"# bls\n\n[![codecov](https://codecov.io/gh/ChainSafe/lodestar/branch/master/graph/badge.svg)](https://codecov.io/gh/ChainSafe/lodestar)\n![ETH2.0_Spec_Version 1.0.0](https://img.shields.io/badge/ETH2.0_Spec_Version-1.0.0-2e86c1.svg)\n![ES Version](https://img.shields.io/badge/ES-2022-yellow)\n![Node Version](https://img.shields.io/badge/node-18-green)\n\nJavascript library for BLS (Boneh-Lynn-Shacham) signatures and signature aggregation, tailored for use in Eth2.\n\n## Usage\n\n```bash\nyarn add @chainsafe/bls\n```\n\nTo use native bindings you must install peer dependency `@chainsafe/blst`\n\n```bash\nyarn add @chainsafe/bls @chainsafe/blst\n```\n\nBy default, native bindings will be used if in NodeJS and they are installed. A WASM implementation (\"herumi\") is used as a fallback in case any error occurs.\n\nThe `blst-native` implementation offers a multi-threaded approach to verification and utilizes the libuv worker pool to verification.  It is a more performant options synchronously and FAR better when utilized asynchronously.  All verification functions provide sync and async versions.  Both the `blst-native` and `herumi` implementations offer verification functions with `async` prefixes as free functions and also on their respective classes. This was done to preserve the isomorphic architecture of this library. In reality however, only the `blst-native` bindings have the ability to implement a promise based approach. In the `herumi` version the async version just proxies to the sync version under the hood.\n\n```ts\nimport bls from \"@chainsafe/bls\";\n\n(async () =\u003e {\n    // class-based interface\n    const secretKey = bls.SecretKey.fromKeygen();\n    const publicKey = secretKey.toPublicKey();\n    const message = new Uint8Array(32);\n\n    const signature = secretKey.sign(message);\n    console.log(\"Is valid: \", signature.verify(publicKey, message));\n\n    // functional interface\n    const sk = secretKey.toBytes();\n    const pk = bls.secretKeyToPublicKey(sk);\n    const sig = bls.sign(sk, message);\n    console.log(\"Is valid: \", bls.verify(pk, message, sig));\n})();\n```\n\n### Browser\n\nIf you are in the browser, import from `/herumi` to explicitly import the WASM version\n\n```ts\nimport bls from \"@chainsafe/bls/herumi\";\n```\n\n### Native bindings only\n\nIf you are in NodeJS, import from `/blst-native` to explicitly import the native bindings. Also install peer dependency `@chainsafe/blst` which has the native bindings\n\n```bash\nyarn add @chainsafe/bls @chainsafe/blst\n```\n\n```ts\nimport bls from \"@chainsafe/bls/blst-native\";\n```\n\n### Get implementation at runtime\n\nIf you need to get a bls implementation at runtime, import from `/getImplementation`.\n\n```ts\nimport {getImplementation} from \"@chainsafe/bls/getImplementation\";\n\nconst bls = await getImplementation(\"herumi\");\n```\n\n### Switchable singleton\n\nIf you need a singleton that is switchable at runtime (the default behavior in \u003c=v6), import from `/switchable`.\n\n```ts\nimport bls, {init} from \"@chainsafe/bls/switchable\";\n\n// here `bls` is uninitialized\nawait init(\"herumi\");\n// here `bls` is initialized\n// now other modules can `import bls from \"@chainsafe/bls/switchable\"` and it will be initialized\n```\n\nThe API is identical for all implementations.\n\n## Benchmarks\n\n- `blst`: [src/blst-native](src/blst-native) (node.js-only, bindings to C via node-gyp)\n- `herumi`: [src/herumi](src/herumi) (node.js \u0026 browser, wasm)\n- `noble`: [noble-bls12-381](https://github.com/paulmillr/noble-bls12-381) (node.js \u0026 browser, pure JS)\n\nResults are in `ops/sec (x times slower)`, where `x times slower` = times slower than fastest implementation (`blst`).\n\n| Function - `ops/sec`             | `blst` |   `herumi`   |   `noble`   |\n| -------------------------------- | :----: | :----------: | :-----------: |\n| `verify`                         | 326.38 | 47.674 (x7)  | 17.906 (x18)  |\n| `verifyAggregate` (30)           | 453.29 | 51.151 (x9)  | 18.372 (x25)  |\n| `verifyMultiple` (30)            | 34.497 | 3.5233 (x10) | 2.0286 (x17)  |\n| `verifyMultipleSignatures` (30)  | 26.381 | 3.1633 (x8)  | -             |\n| `aggregate` (pubkeys, 30)        | 15686  | 2898.9 (x5)  | 1875.0 (x8)   |\n| `aggregate` (sigs, 30)           | 6373.4 | 1033.0 (x6)  | 526.25 (x12)  |\n| `sign`                           | 925.49 | 108.81 (x9)  | 10.246 (x90)  |\n\n\\* `blst` and `herumi` performed 100 runs each, `noble` 10 runs.\n\nResults from CI run \u003chttps://github.com/ChainSafe/bls/runs/1513710175?check_suite_focus=true#step:12:13\u003e\n\n## Spec versioning\n\n| Version | Bls spec hash-to-curve version |\n| ------- | :----------------------------: |\n| 5.x.x   |            draft #9            |\n| 2.x.x   |            draft #7            |\n| 1.x.x   |            draft #6            |\n| 0.3.x   |        initial version         |\n\n\u003e [spec](https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#bls-signatures)\n\n\u003e [test vectors](https://github.com/ethereum/eth2.0-spec-tests/tree/master/tests/bls)\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChainSafe%2Fbls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChainSafe%2Fbls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChainSafe%2Fbls/lists"}