{"name":"@peculiar/x509","version":"1.0.8","keywords":["x509","certificate","csr","pkcs10","pkcs7","cms","rsa","ec"],"author":{"name":"Peculiar Ventures LLC"},"license":"MIT","_id":"@peculiar/x509@1.0.8","maintainers":[{"name":"donskov","email":"donskovdmitriyv@gmail.com"},{"name":"apilguk","email":"apilguk@gmail.com"},{"name":"peculiarventures","email":"info@peculiarventures.com"},{"name":"yury.strozhevsky","email":"yury@strozhevsky.com"},{"name":"microshine","email":"microshine@mail.ru"},{"name":"rmhrisk","email":"ryan_hurst@hotmail.com"}],"contributors":[{"name":"Miroshin Stepan","email":"microshine@mail.ru"}],"homepage":"https://github.com/PeculiarVentures/x509#readme","bugs":{"url":"https://github.com/PeculiarVentures/x509/issues"},"nyc":{"exclude":["**/*.d.ts"],"include":["src/**/*.ts"],"reporter":["lcov","text-summary","html"],"extension":[".ts",".tsx"]},"dist":{"shasum":"47beced3bbf6218a972823c1eff8742dcf974ff0","tarball":"http://registry-npm.ywwl.com/@peculiar/x509/download/@peculiar/x509-1.0.8.tgz","fileCount":37,"integrity":"sha512-ulZ+Og7krZHacQYH058qm2mvBoT4xGm6a8VtBBQ2EpYZX6AjFoTINskoXgASa+YfWbyi8H6kk/U0HTelQaj4Fg==","signatures":[{"sig":"MEUCIBrGKmG4RO03RL+dO1H44Cyaeu2De6OO0JplrU3fbnbaAiEA1KY99AcQ0tJ7crNWMNUz6Cpz6kZElpCOo0JgfI0ZV14=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":304081,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfvVFsCRA9TVsSAnZWagAA76oP/j17N1aH7+NIPmFGuLEr\nvmP6oPIwQhj2/OPpozTsDFGw0N4Gh9ZP4dGNE11Yiw3GfcF4MNJOnxiwrUQt\nw6EQFfEgtbzbzWpyrN13u3akk1urbl3OnucXZAc/er18Iv19r4zV04RmnD+H\nGVxc35YlWExbG343Egf0mZlzRN3LkgO2dSQm9A4L9bkI1FeZ8P5YF9O9RrRh\n5tqaQcrKGgnKtxTGiRP8JI4IXKxSVhT7LC1exuAyidcEfp9VZx0V8Zjwtj2M\ngvX4d5C5RIFTcmmgwYoR1e7vG7DbF5oye6wwTPwsqIWU9PpUs70Y9H0xvrK9\n+k+61M6COc4H0MnQPP3j3deS5PQZTjsbp1CpuoYmS7gtFeN5JSdnR8j8eyW1\nBJCGcAAXj268B8ksbvAUOLin4/nhtlcmD17NJHay9jRyGxScLtY6KDUbOCMM\nDEiIhkVThdewhZMb1QUe1jQi5amrT5TBnawRJobuuEVIsacVDvwrRRAccZGr\n76sfLp1+02qLI75fMtHTs5CljPhI7vjWOvhL8aJwbf7Hr63MMrJWEfyHcnC2\n/4I9LZRY8zVUtoM/qXkOlLVPmHB/e7sI0y+eE5cL3S4rRsTHodX144G9Ydm0\nB1vQt/v0ILu3ARkGXQlP+IIhgP1xXcF160bGOpmd8uN5X5XlH3QdsgZpjioc\nSBCm\r\n=7Ghy\r\n-----END PGP SIGNATURE-----\r\n","size":65008,"noattachment":false,"key":"/@peculiar/x509/-/@peculiar/x509-1.0.8.tgz"},"main":"build/x509.cjs.js","mocha":{"spec":["test/**"],"require":["ts-node/register"],"timeout":5000,"extension":["ts"]},"types":"build/types/index.d.ts","module":"build/x509.es.js","browser":"build/x509.js","gitHead":"fc6c060c8b04ba9cacd920ea451b47e3b9e664fc","scripts":{"pub":"npm run pub:patch","docs":"typedoc","lint":"eslint . --ext .ts","test":"mocha","build":"npm run build:module && npm run build:types","clear":"rimraf build/* docs","rebuild":"npm run clear && npm run build","coverage":"nyc npm test","git:push":"git push --follow-tags","lint:fix":"eslint --fix . --ext .ts","coveralls":"nyc report --reporter=text-lcov | coveralls","pub:major":"npm version major && npm run git:push","pub:minor":"npm version minor && npm run git:push","pub:patch":"npm version patch && npm run git:push","build:types":"tsc -p tsconfig.json --outDir build/types --declaration --emitDeclarationOnly","build:module":"rollup -c","prebuild:types":"rimraf build/types"},"_npmUser":{"name":"microshine","email":"microshine@mail.ru"},"repository":{"url":"git+https://github.com/PeculiarVentures/x509.git","type":"git"},"_npmVersion":"6.14.8","description":"@peculiar/x509 is an easy to use TypeScript/Javascript library based on @peculiar/asn1-schema that makes generating X.509 Certificates and Certificate Requests as well as validating certificate chains easy","directories":{},"_nodeVersion":"12.19.0","dependencies":{"tslib":"^2.0.3","tsyringe":"^4.4.0","pvtsutils":"^1.1.1","reflect-metadata":"^0.1.13","@peculiar/asn1-cms":"^2.0.26","@peculiar/asn1-csr":"^2.0.26","@peculiar/asn1-ecc":"^2.0.26","@peculiar/asn1-rsa":"^2.0.26","@peculiar/asn1-x509":"^2.0.26","@peculiar/asn1-pkcs9":"^2.0.26","@peculiar/asn1-schema":"^2.0.26"},"eslintConfig":{"root":true,"rules":{"newline-before-return":1,"@typescript-eslint/semi":1,"@typescript-eslint/quotes":["warn","double"],"@typescript-eslint/no-explicit-any":0,"@typescript-eslint/explicit-module-boundary-types":0},"parser":"@typescript-eslint/parser","extends":["eslint:recommended","plugin:@typescript-eslint/recommended"],"plugins":["@typescript-eslint"]},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","mocha":"^8.2.1","eslint":"^7.14.0","rimraf":"^3.0.2","rollup":"^2.33.3","ts-node":"^9.0.0","typedoc":"^0.19.2","coveralls":"^3.1.0","typescript":"^4.1.2","@babel/core":"^7.12.8","@types/node":"^14.14.9","@types/mocha":"^8.0.4","@babel/preset-env":"^7.12.7","@peculiar/webcrypto":"^1.1.3","@rollup/plugin-babel":"^5.2.1","rollup-plugin-terser":"^7.0.2","@rollup/plugin-commonjs":"^15.1.0","@typescript-eslint/parser":"^4.8.2","rollup-plugin-typescript2":"^0.27.3","@rollup/plugin-node-resolve":"^9.0.0","@typescript-eslint/eslint-plugin":"^4.8.2"},"_npmOperationalInternal":{"tmp":"tmp/x509_1.0.8_1606242667405_0.5702174022654676","host":"s3://npm-registry-packages"},"readme":"<h1 align=\"center\">\n  @peculiar/x509\n</h1>\n\n<div align=\"center\">\n\n![NPM License](https://img.shields.io/npm/l/@peculiar/x509)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/PeculiarVentures/x509/test.yml?label=test)\n[![npm version](https://img.shields.io/npm/v/@peculiar/x509.svg)](https://www.npmjs.com/package/@peculiar/x509)\n![Coveralls](https://img.shields.io/coverallsCoverage/github/PeculiarVentures/x509)\n[![npm downloads](https://img.shields.io/npm/dm/@peculiar/x509.svg)](https://www.npmjs.com/package/@peculiar/x509)\n\n</div>\n\n- [About](#about)\n- [⚠️ Reflect Polyfill Required](#-reflect-polyfill-required)\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [Usage](#usage)\n  - [Browser](#browser)\n  - [Set crypto provider for Node.js](#set-crypto-provider-for-nodejs)\n  - [Create a self-signed certificate](#create-a-self-signed-certificate)\n  - [Parse a X509 certificate](#parse-a-x509-certificate)\n  - [Create a PKCS#10 certificate request](#create-a-pkcs10-certificate-request)\n  - [Decoded X509 certificate](#decoded-x509-certificate)\n  - [Build a certificate chain](#build-a-certificate-chain)\n  - [Export a list of X509 certificates to PKCS#7 format](#export-a-list-of-x509-certificates-to-pkcs7-format)\n\n## About\n\n`@peculiar/x509` is an easy to use TypeScript/Javascript library based on `@peculiar/asn1-schema` that makes generating X.509 Certificates and Certificate Requests as well as validating certificate chains easy.\n\n## ⚠️ Reflect Polyfill Required\n\n**This library requires a Reflect API polyfill.** You must install one of the following and import it at the top of your entry point:\n\n- [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)\n- [core-js](https://www.npmjs.com/package/core-js) (`core-js/full/reflect`)\n- [@abraham/reflection](https://www.npmjs.com/package/@abraham/reflection)\n\n**Example with reflect-metadata:**\n\n```js\nimport \"reflect-metadata\";\nimport * as x509 from \"@peculiar/x509\";\n// ...\n```\n\nIf you see the error **\"tsyringe requires a reflect polyfill. Please add 'import \"reflect-metadata\"' to the top of your entry point.\"** — install one of the polyfills above and add the import before any `@peculiar/x509` imports.\n\n## Installation\n\n```\nnpm install @peculiar/x509\n```\n\n## Documentation\n\n[https://peculiarventures.github.io/x509/](https://peculiarventures.github.io/x509/)\n\n## Usage\n\n### Browser\n\nEvery release of `@peculiar/x509` will have new build of `./build/x509.js` for use in the browser. To get access to module classes use `x509` global variable.\n\n> WARN: We recommend hosting and controlling your own copy for security reasons\n\n```html\n<script src=\"https://unpkg.com/@peculiar/x509\"></script>\n```\n\nA simple web application examples\n  - [Generate X509 certificate](https://codesandbox.io/s/generate-cert-fjwfh)\n  - [Generate PKCS#10 certificate request](https://codesandbox.io/s/generate-csr-0qhed)\n\n### Set crypto provider for Node.js\n\nIn some cases you may want to use a different cryptographic implementation, for example when you want to work with an object that supports a cryptographic algorithm not supported by the platform you are on.\n\nIn these cases you can set a custom provider, these providers need to be compatible with the WebCrypto API, for example on NodeJS you can use `@peculiar/webcrypto` to allow `@peculiar/x509` to work the same as it does in browser!\n\n```js\nimport * as x509 from \"@peculiar/x509\";\nimport { Crypto } from \"@peculiar/webcrypto\";\n\nconst crypto = new Crypto();\nx509.cryptoProvider.set(crypto);\n```\n\n### Create a self-signed certificate\n```js\nconst alg = {\n  name: \"RSASSA-PKCS1-v1_5\",\n  hash: \"SHA-256\",\n  publicExponent: new Uint8Array([1, 0, 1]),\n  modulusLength: 2048,\n};\nconst keys = await crypto.subtle.generateKey(alg, false, [\"sign\", \"verify\"]);\nconst cert = await x509.X509CertificateGenerator.createSelfSigned({\n  serialNumber: \"01\",\n  name: \"CN=Test\",\n  notBefore: new Date(\"2020/01/01\"),\n  notAfter: new Date(\"2020/01/02\"),\n  signingAlgorithm: alg,\n  keys,\n  extensions: [\n    new x509.BasicConstraintsExtension(true, 2, true),\n    new x509.ExtendedKeyUsageExtension([\"1.2.3.4.5.6.7\", \"2.3.4.5.6.7.8\"], true),\n    new x509.KeyUsagesExtension(x509.KeyUsageFlags.keyCertSign | x509.KeyUsageFlags.cRLSign, true),\n    await x509.SubjectKeyIdentifierExtension.create(keys.publicKey),\n  ]\n});\n\nconsole.log(cert.toString(\"pem\")); // Certificate in PEM format\n```\n\n### Parse a x509 certificate\n```js\nconst base64 = \"MIIDljCCAn6gAwIBAgIOSETcxtRwD...S+kAFXIwugUGYEnTWp0m5bAn5NlD314IEOg4mnS8Q==\";\n\nconst cert = new x509.X509Certificate(base64);\nconsole.log(cert.subject); // CN=Test, O=PeculiarVentures LLC\n```\n\n### Create a PKCS#10 certificate request\n```js\nconst alg = {\n  name: \"ECDSA\",\n  namedCurve: \"P-384\",\n  hash: \"SHA-384\",\n}\nconst keys = await crypto.subtle.generateKey(alg, false, [\"sign\", \"verify\"]);\nconst csr = await x509.Pkcs10CertificateRequestGenerator.create({\n  name: \"CN=Test\",\n  keys,\n  signingAlgorithm: alg,\n  extensions: [\n    new x509.KeyUsagesExtension(x509.KeyUsageFlags.digitalSignature | x509.KeyUsageFlags.keyEncipherment),\n  ],\n  attributes: [\n    new x509.ChallengePasswordAttribute(\"password\"),\n  ]\n});\n\nconsole.log(csr.toString(\"base64\")); // Certificate request in Base64 format\n```\n\n### Decoded X509 certificate\n```js\nX509Certificate {\n  rawData: ArrayBuffer {\n    [Uint8Contents]: <30 82 02 fc 30 82 01 e4 a0 03 02 01 02 02 01 01 30 0d 06 09 2a 86 48 86 f7 0d 01 01 0b 05 00 30 0f 31 0d 30 0b 06 03 55 04 03 13 04 54 65 73 74 30 1e 17 0d 31 39 31 32 33 31 32 31 30 30 30 30 5a 17 0d 32 30 30 31 30 31 32 31 30 30 30 30 5a 30 0f 31 0d 30 0b 06 03 55 04 03 13 04 54 65 73 74 30 82 01 ... 668 more bytes>,\n    byteLength: 768\n  },\n  tbs: ArrayBuffer {\n    [Uint8Contents]: <30 82 01 e4 a0 03 02 01 02 02 01 01 30 0d 06 09 2a 86 48 86 f7 0d 01 01 0b 05 00 30 0f 31 0d 30 0b 06 03 55 04 03 13 04 54 65 73 74 30 1e 17 0d 31 39 31 32 33 31 32 31 30 30 30 30 5a 17 0d 32 30 30 31 30 31 32 31 30 30 30 30 5a 30 0f 31 0d 30 0b 06 03 55 04 03 13 04 54 65 73 74 30 82 01 22 30 0d 06 ... 388 more bytes>,\n    byteLength: 488\n  },\n  serialNumber: '01',\n  subject: 'CN=Test',\n  issuer: 'CN=Test',\n  signatureAlgorithm: { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } },\n  signature: ArrayBuffer {\n    [Uint8Contents]: <2e 78 fb 4b f6 c8 a1 9d b4 d1 8b 22 80 20 c1 68 46 39 a6 11 d1 a9 7a 13 03 8d 1e 0e 5e 87 b5 33 2a ba 44 1b 96 6d 91 e7 fd c0 ce b7 93 fe e4 df d3 d0 57 7c 9a eb 7e 3e 8b ed c6 07 ad 80 df fd 8f f7 ce 26 07 db 0e 9f af e6 cb 70 02 2d 17 9f f5 c1 0d ef d6 cf 1d ec 78 a0 dd 5d 46 2a 60 08 71 74 2c 26 ... 156 more bytes>,\n    byteLength: 256\n  },\n  notBefore: 2019-12-31T21:00:00.000Z,\n  notAfter: 2020-01-01T21:00:00.000Z,\n  extensions: Extensions(4) [\n    BasicConstraintsExtension {\n      rawData: [ArrayBuffer],\n      type: '2.5.29.19',\n      critical: true,\n      value: [ArrayBuffer],\n      ca: true,\n      pathLength: 2\n    },\n    ExtendedKeyUsageExtension {\n      rawData: [ArrayBuffer],\n      type: '2.5.29.37',\n      critical: true,\n      value: [ArrayBuffer],\n      usages: [ExtendedKeyUsage]\n    },\n    KeyUsagesExtension {\n      rawData: [ArrayBuffer],\n      type: '2.5.29.15',\n      critical: true,\n      value: [ArrayBuffer],\n      usages: 96\n    },\n    SubjectKeyIdentifierExtension {\n      rawData: [ArrayBuffer],\n      type: '2.5.29.14',\n      critical: false,\n      value: [ArrayBuffer],\n      keyId: 'f525754650a3dee83f8bd777ee3b53ecc2c8d726'\n    }\n  ],\n  publicKey: PublicKey {\n    rawData: ArrayBuffer {\n      [Uint8Contents]: <30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 b6 f4 f1 cf dd 26 a1 23 45 b6 6e 4e ec 3e 20 8a 3f 90 ec 84 46 49 87 a2 05 c5 eb da ac 84 37 eb a3 bf 46 b5 8e 82 75 25 8a 80 19 10 79 13 c0 13 6c 29 df 56 44 1c ec f8 7b 34 0a f2 13 41 b5 53 98 e1 f5 ... 194 more bytes>,\n      byteLength: 294\n    },\n    algorithm: {\n      name: 'RSASSA-PKCS1-v1_5',\n      publicExponent: [Uint8Array],\n      modulusLength: 2048\n    }\n  }\n}\n```\n\n### Build a certificate chain\n```js\nconst chain = new x509.X509ChainBuilder({\n  certificates: [\n    new x509.X509Certificate(raw1),\n    new x509.X509Certificate(raw2),\n    // ...\n    new x509.X509Certificate(rawN),\n  ],\n});\n\nconst cert = x509.X509Certificate(raw);\nconst items = await chain.build(cert);\nconsole.log(items); // [ X509Certificate, X509Certificate, X509Certificate ]\n```\n\n### Export a list of X509 certificates to PKCS#7 format\n```js\nconst certs = new x509.X509Certificates([\n  new x509.X509Certificate(\"MIIDljCCAn6gAwIBAgIOSETcxtRwD...S+kAFXIwugUGYEnTWp0m5bAn5NlD314IEOg4mnS8Q==\"),\n  new x509.X509Certificate(\"MIIDljCCAn6gAwIBAgIOSETcxtRwD...w8Y/o+hk3QzNBVa3ZUvzDhVAmamQflvw3lXMm/JG4U=\"),\n]);\n\nconsole.log(certs.export(\"base64\")); // \"MIICTAYJKoZIhvcNAQcCoIICPTCCAjkCAQAxADACBgCgggIq...F7EZPNo3pjbfznpIilRMRrmwf5dkgCdSKDdE94xAA==\");\n```\n","publish_time":1606242667625,"_cnpm_publish_time":1606242667625,"dist-tags":{"beta":"1.3.3-beta.0","latest":"3.1.0"}}