{"id":23184179,"url":"https://github.com/tierratelematics/cfsign","last_synced_at":"2025-08-18T15:32:09.289Z","repository":{"id":57196392,"uuid":"154293419","full_name":"tierratelematics/cfsign","owner":"tierratelematics","description":"A Typescript/Javascript lib for working with CloudFront signatures in NodeJs","archived":false,"fork":false,"pushed_at":"2018-11-29T17:00:21.000Z","size":30,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-09T03:03:46.201Z","etag":null,"topics":["aws","cloudfront","nodejs","signature","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tierratelematics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-23T08:42:36.000Z","updated_at":"2020-05-15T22:16:48.000Z","dependencies_parsed_at":"2022-09-16T13:10:50.859Z","dependency_job_id":null,"html_url":"https://github.com/tierratelematics/cfsign","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tierratelematics/cfsign","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tierratelematics%2Fcfsign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tierratelematics%2Fcfsign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tierratelematics%2Fcfsign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tierratelematics%2Fcfsign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tierratelematics","download_url":"https://codeload.github.com/tierratelematics/cfsign/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tierratelematics%2Fcfsign/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269687408,"owners_count":24459381,"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-08-10T02:00:08.965Z","response_time":71,"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":["aws","cloudfront","nodejs","signature","typescript"],"created_at":"2024-12-18T09:17:54.170Z","updated_at":"2025-08-18T15:32:09.018Z","avatar_url":"https://github.com/tierratelematics.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cfsign\n\nA Typescript/Javascript lib for working with CloudFront signatures in NodeJs.\n\n## Getting started\n\nInstall `cfsign` from [npm](https://www.npmjs.com/package/cfsign).\n\nInstantiate a signer with your key configuration:\n\n```javascript\nimport { Signer } from \"cfsign\";\nconst signer = new Signer({\n    id: \"APKAXXXXXXXXXXXXXXXX\", \n    privateKeyPem: \"-----BEGIN RSA PRIVATE KEY-----\\nXXXX...\"\n});\n```\n\nAs per [AWS documentation](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html),\n`cfsign` supports short-ish URLs, signed using a \"canned\" policy. In this\ncase a URL and an expiration date will do:\n\n```javascript\nconst expiration = new Date(new Date().getTime() + 10*60*1000);\nconst signedUrl = signer.signUrl(`https://xyz.cloudfront.net/example/path`, expiration);\n```\n\nTo sign a more complex policy, just build one and then get the resulting\ncookies or query parameters.\n\n```javascript\nconst policy = {\n    Statement: [{\n        Condition: {\n            DateGreaterThan: { \"AWS:EpochTime\": 0 },\n            DateLessThan: { \"AWS:EpochTime\": 1 },\n            IpAddress: { \"AWS:SourceIp\": \"1.1.1.0/24\" }\n        },\n        Resource: \"http://test.com/folder/*\"\n    }]\n};\nconst signature = sut.sign(policy);\n\nconst cookies = signature.toCookies();\nconst signedUrl = signature.addToUrl(\"http://test.com/folder/file\");\n```\n\nIn typescript the `Policy` type will help you to write a correct policy.\n\n## Extra utils\n\nIf you prefer to set the key via a single line string, rather than a PEM,\nthere's `pemFormat()`:\n\n```javascript\nimport { pemFormat } from \"cfsign/lib/keyUtils\";\nconst signer = new Signer({\n    id: \"APKAXXXXXXXXXXXXXXXX\", \n    privateKeyPem: pemFormat(\"XXXX\")\n});\n```\n\nRefer to typedocs or tests for further details and examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftierratelematics%2Fcfsign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftierratelematics%2Fcfsign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftierratelematics%2Fcfsign/lists"}