{"id":30684240,"url":"https://github.com/eclipse-biscuit/biscuit-swift","last_synced_at":"2025-09-01T20:15:15.037Z","repository":{"id":311888854,"uuid":"964725194","full_name":"eclipse-biscuit/biscuit-swift","owner":"eclipse-biscuit","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-27T12:54:24.000Z","size":117,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-27T17:06:14.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/eclipse-biscuit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-11T17:21:58.000Z","updated_at":"2025-08-27T15:11:02.000Z","dependencies_parsed_at":"2025-08-27T17:06:21.231Z","dependency_job_id":"5c255412-0d3f-48a5-adc5-5c7af918d691","html_url":"https://github.com/eclipse-biscuit/biscuit-swift","commit_stats":null,"previous_names":["eclipse-biscuit/biscuit-swift"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/eclipse-biscuit/biscuit-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-biscuit%2Fbiscuit-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-biscuit%2Fbiscuit-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-biscuit%2Fbiscuit-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-biscuit%2Fbiscuit-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eclipse-biscuit","download_url":"https://codeload.github.com/eclipse-biscuit/biscuit-swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-biscuit%2Fbiscuit-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273183235,"owners_count":25059813,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-09-01T20:15:12.386Z","updated_at":"2025-09-01T20:15:15.005Z","avatar_url":"https://github.com/eclipse-biscuit.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Swift implementation of biscuits\n\nBiscuits is a specification for authorization tokens designed to support decentralized validation\nand offline attenuation. This library provides an implementation of biscuits in Swift. In additiona\nto specifying a binary representation and cryptographic primitives, Biscuits specifies a Datalog\nvariant for describing the rights and restrictions on a biscuit. More information about biscuits can\nbe found at https://www.biscuitsec.org\n\n## Tutorial\n\nThe central type of the Biscuits library is the `Biscuit` type, which represents a biscuit token.\nSuch tokens can be constructed, attenuated, authorized, serialized, deserialized and so on.\n\nThe library exposes protocols for valid public and private keys; these protocols are implemented by\nthe `Curve25519`, `P256` and `SecureEnclave.P256` types from [swift-crypto][swift-crypto]; users may\nalso add implementations for alternative implementats of ed25519 and secp256r1 if they desire.\n\nThe Datalog contents of a biscuit token can be encoded in two ways: either as a string, which will be\nparsed at runtime, or using a DSL provided by the library which is type safe and avoids the risk\nof injection attacks and syntax errors.\n\nFor example:\n\n```swift\nimport Biscuits\nimport Crypto\nimport Foundation\n\nlet issuerPrivateKey = Curve25519.Signing.PrivateKey()\n// Or, if secp256r1 is more your style...\n// let issuerPrivateKey = P256.Signing.PrivateKey()\n\n// Construct a biscuit for a user with specific userID:\nlet userToken = try Biscuit(rootKey: issuerPrivateKey) {\n    Check.checkIf {\n        Predicate(\"user\", userID)\n    }\n    // This is a convenience for defining an expiration check based on the time fact:\n    Check.tokenExpires(at: expirationDate)\n}\n```\n\nIn addition to using that biscuit as a bearer token themselves, that user would be able to attenuate\nit to give a third party service read-only access to resoures under the `/foo` directory:\n\n```swift\nlet readOnlyFooToken = try userToken.attenuated() {\n    // equivalent to: check if operation(\"read\"), resource($path), $path.starts_with(\"/foo\");\n    Check.checkIf {\n        Predicate(\"operation\", \"read\")\n        Predicate(\"resource\", Term(variable: \"path\"))\n        Term(variable: \"path\").startsWith(\"/foo\")\n    }\n}\n```\n\nFinally, the relying party could authorize a request to access the source at \"/foo/bar\" as that user\nusing an authorizer like this:\n\n```swift\ntry readOnlyFooToken.authorize() {\n    Fact(\"user\", userID)\n    Fact(\"operation\", \"read\")\n    Fact(\"resource\", \"/foo/bar\")\n    Fact(\"time\", Date.now)\n}\n```\n\n### Datalog DSL\n\nThe Datalog DSL has two [resultBuilder][resultBuilder]-based entry points: `DatalogBlock` and\n`Authorizer`. `DatalogBlock` is used for constructing and attenuating biscuits, whereas `Authorizer`\nis used for authorizing them.\n\nEach contain a series of datalog statements of these types: `Fact`, `Rule`, `Check`, and, in the\ncase of `Authorizer`, `Policy`. Facts are simple statements, consisting of the name of that fact and\na series of values passed to that fact. Rules, checks, and policies are compound statements\nconsisting of a series of predicates and expressions.\n\nA `Predicate` is similar to `Fact`, but it can also take variables (which are written\n`Term(variable: \"name\")`), not only literal values. When authorizing the biscuit, these predicates\nwill be supported by finding facts that match their name and values.\n\nExpressions can be built using a fluent method-based expression builder API, supported on\n`Expression`, `Value` and `Term`. For example:\n\n```swift\n// equivalent to $foo\nlet foo = Term(variable: \"foo\")\n// $foo \u003e 0 \u0026\u0026 $foo \u003c 100\nfoo.greaterThan(0).and(foo.lessThan(100))\n```\n\n## Building and testing\n\nThis package is built using Swift 6. Tests are written using XCTest, which is distributed with\nxcode.\n\n## License\n\nLicensed under Apache License, Version 2.0, ([LICENSE-APACHE][license] or http://www.apache.org/licenses/LICENSE-2.0)\n\n\n[swift-crypto]: https://github.com/apple/swift-crypto\n[resultBuilder]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/advancedoperators/#Result-Builders\n[license]: ./LICENSE-APACHE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-biscuit%2Fbiscuit-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feclipse-biscuit%2Fbiscuit-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-biscuit%2Fbiscuit-swift/lists"}